11cb0ef41Sopenharmony_ci<!DOCTYPE html> 21cb0ef41Sopenharmony_ci<html> 31cb0ef41Sopenharmony_ci<head> 41cb0ef41Sopenharmony_ci<meta charset="utf-8" /> 51cb0ef41Sopenharmony_ci<title>functionality test of window.performance.clearMeasures</title> 61cb0ef41Sopenharmony_ci<link rel="author" title="Intel" href="http://www.intel.com/" /> 71cb0ef41Sopenharmony_ci<link rel="help" href="http://www.w3.org/TR/user-timing/#extensions-performance-interface"/> 81cb0ef41Sopenharmony_ci<script src="/resources/testharness.js"></script> 91cb0ef41Sopenharmony_ci<script src="/resources/testharnessreport.js"></script> 101cb0ef41Sopenharmony_ci<script src="/common/performance-timeline-utils.js"></script> 111cb0ef41Sopenharmony_ci<script src="resources/webperftestharness.js"></script> 121cb0ef41Sopenharmony_ci<script src="resources/webperftestharnessextension.js"></script> 131cb0ef41Sopenharmony_ci<script> 141cb0ef41Sopenharmony_cisetup({ explicit_done: true }); 151cb0ef41Sopenharmony_ci 161cb0ef41Sopenharmony_cifunction onload_test() 171cb0ef41Sopenharmony_ci{ 181cb0ef41Sopenharmony_ci const context = new PerformanceContext(window.performance); 191cb0ef41Sopenharmony_ci const entrylist_checker = new performance_entrylist_checker('measure'); 201cb0ef41Sopenharmony_ci const measure_names = measures.map(function(x) {return x[0];}); 211cb0ef41Sopenharmony_ci 221cb0ef41Sopenharmony_ci mark_names.forEach(function(name) { 231cb0ef41Sopenharmony_ci context.mark(name); 241cb0ef41Sopenharmony_ci }); 251cb0ef41Sopenharmony_ci measures.forEach(context.initialMeasures, context); 261cb0ef41Sopenharmony_ci for (let i = 0; i < measures.length; ++i) 271cb0ef41Sopenharmony_ci { 281cb0ef41Sopenharmony_ci context.clearMeasures(measures[i][0]); 291cb0ef41Sopenharmony_ci const retained_entries = context.getEntriesByType('measure'); 301cb0ef41Sopenharmony_ci const non_retained_entries = context.getEntriesByName(measures[i][0], 'measure'); 311cb0ef41Sopenharmony_ci entrylist_checker.entrylist_check(retained_entries, measures.length - i - 1, measure_names, 321cb0ef41Sopenharmony_ci 'First loop: checking entries after removing "' + measures[i][0] + '". '); 331cb0ef41Sopenharmony_ci test_equals(non_retained_entries.length, 0, 341cb0ef41Sopenharmony_ci 'First loop: measure "' + measures[i][0] + '" should not exist anymore after we cleared it.'); 351cb0ef41Sopenharmony_ci } 361cb0ef41Sopenharmony_ci 371cb0ef41Sopenharmony_ci measures.forEach(context.initialMeasures, context); 381cb0ef41Sopenharmony_ci context.clearMeasures(); 391cb0ef41Sopenharmony_ci test_equals(context.getEntriesByType('measure').length, 0, 'No measures should exist after we clear all (after first loop).'); 401cb0ef41Sopenharmony_ci 411cb0ef41Sopenharmony_ci // Following cases test clear existed measure name that is tied twice. 421cb0ef41Sopenharmony_ci measures.forEach(context.initialMeasures, context); 431cb0ef41Sopenharmony_ci mark_names.forEach(function(name) { 441cb0ef41Sopenharmony_ci context.mark(name); 451cb0ef41Sopenharmony_ci }); 461cb0ef41Sopenharmony_ci measures.forEach(context.initialMeasures, context); 471cb0ef41Sopenharmony_ci for (let i = 0; i < measures.length; ++i) 481cb0ef41Sopenharmony_ci { 491cb0ef41Sopenharmony_ci context.clearMeasures(measures[i][0]); 501cb0ef41Sopenharmony_ci const retained_entries = context.getEntriesByType('measure'); 511cb0ef41Sopenharmony_ci const non_retained_entries = context.getEntriesByName(measures[i][0], 'measure'); 521cb0ef41Sopenharmony_ci entrylist_checker.entrylist_check(retained_entries, (measures.length - i - 1) * 2, measure_names, 531cb0ef41Sopenharmony_ci 'Second loop: checking entries after removing "' + measures[i][0] + '". '); 541cb0ef41Sopenharmony_ci test_equals(non_retained_entries.length, 0, 551cb0ef41Sopenharmony_ci 'Second loop: measure "' + measures[i][0] +'" should not exist anymore after we cleared it.'); 561cb0ef41Sopenharmony_ci } 571cb0ef41Sopenharmony_ci 581cb0ef41Sopenharmony_ci // Following cases test clear functionality when measure names are tied twice. 591cb0ef41Sopenharmony_ci measures.forEach(context.initialMeasures, context); 601cb0ef41Sopenharmony_ci measures.forEach(context.initialMeasures, context); 611cb0ef41Sopenharmony_ci const entry_number_before_useless_clear = context.getEntriesByType('measure').length; 621cb0ef41Sopenharmony_ci context.clearMeasures('NonExist'); 631cb0ef41Sopenharmony_ci const entry_number_after_useless_clear = context.getEntriesByType('measure').length; 641cb0ef41Sopenharmony_ci test_equals(entry_number_before_useless_clear, entry_number_after_useless_clear, 'Nothing should happen if we clear a non-exist measure'); 651cb0ef41Sopenharmony_ci context.clearMeasures(); 661cb0ef41Sopenharmony_ci test_equals(context.getEntriesByType('measure').length, 0, 'No measures should exist when we clear all (after second loop).'); 671cb0ef41Sopenharmony_ci 681cb0ef41Sopenharmony_ci done(); 691cb0ef41Sopenharmony_ci} 701cb0ef41Sopenharmony_ci</script> 711cb0ef41Sopenharmony_ci</head> 721cb0ef41Sopenharmony_ci<body onload=onload_test()> 731cb0ef41Sopenharmony_ci <h1>Description</h1> 741cb0ef41Sopenharmony_ci <p>This test validates functionality of the interface window.performance.clearMeasures.</p> 751cb0ef41Sopenharmony_ci <div id="log"></div> 761cb0ef41Sopenharmony_ci</body> 771cb0ef41Sopenharmony_ci</html> 78