11cb0ef41Sopenharmony_ci// 21cb0ef41Sopenharmony_ci// Helper functions for User Timing tests 31cb0ef41Sopenharmony_ci// 41cb0ef41Sopenharmony_ci 51cb0ef41Sopenharmony_civar timingAttributes = [ 61cb0ef41Sopenharmony_ci "navigationStart", 71cb0ef41Sopenharmony_ci "unloadEventStart", 81cb0ef41Sopenharmony_ci "unloadEventEnd", 91cb0ef41Sopenharmony_ci "redirectStart", 101cb0ef41Sopenharmony_ci "redirectEnd", 111cb0ef41Sopenharmony_ci "fetchStart", 121cb0ef41Sopenharmony_ci "domainLookupStart", 131cb0ef41Sopenharmony_ci "domainLookupEnd", 141cb0ef41Sopenharmony_ci "connectStart", 151cb0ef41Sopenharmony_ci "connectEnd", 161cb0ef41Sopenharmony_ci "secureConnectionStart", 171cb0ef41Sopenharmony_ci "requestStart", 181cb0ef41Sopenharmony_ci "responseStart", 191cb0ef41Sopenharmony_ci "responseEnd", 201cb0ef41Sopenharmony_ci "domLoading", 211cb0ef41Sopenharmony_ci "domInteractive", 221cb0ef41Sopenharmony_ci "domContentLoadedEventStart", 231cb0ef41Sopenharmony_ci "domContentLoadedEventEnd", 241cb0ef41Sopenharmony_ci "domComplete", 251cb0ef41Sopenharmony_ci "loadEventStart", 261cb0ef41Sopenharmony_ci "loadEventEnd" 271cb0ef41Sopenharmony_ci]; 281cb0ef41Sopenharmony_ci 291cb0ef41Sopenharmony_cifunction has_required_interfaces() 301cb0ef41Sopenharmony_ci{ 311cb0ef41Sopenharmony_ci if (window.performance.mark == undefined || 321cb0ef41Sopenharmony_ci window.performance.clearMarks == undefined || 331cb0ef41Sopenharmony_ci window.performance.measure == undefined || 341cb0ef41Sopenharmony_ci window.performance.clearMeasures == undefined || 351cb0ef41Sopenharmony_ci window.performance.getEntriesByName == undefined || 361cb0ef41Sopenharmony_ci window.performance.getEntriesByType == undefined || 371cb0ef41Sopenharmony_ci window.performance.getEntries == undefined) { 381cb0ef41Sopenharmony_ci return false; 391cb0ef41Sopenharmony_ci } 401cb0ef41Sopenharmony_ci 411cb0ef41Sopenharmony_ci return true; 421cb0ef41Sopenharmony_ci} 431cb0ef41Sopenharmony_ci 441cb0ef41Sopenharmony_cifunction test_namespace(child_name, skip_root) 451cb0ef41Sopenharmony_ci{ 461cb0ef41Sopenharmony_ci if (skip_root === undefined) { 471cb0ef41Sopenharmony_ci var msg = 'window.performance is defined'; 481cb0ef41Sopenharmony_ci wp_test(function () { assert_not_equals(performanceNamespace, undefined, msg); }, msg); 491cb0ef41Sopenharmony_ci } 501cb0ef41Sopenharmony_ci 511cb0ef41Sopenharmony_ci if (child_name !== undefined) { 521cb0ef41Sopenharmony_ci var msg2 = 'window.performance.' + child_name + ' is defined'; 531cb0ef41Sopenharmony_ci wp_test(function() { assert_not_equals(performanceNamespace[child_name], undefined, msg2); }, msg2); 541cb0ef41Sopenharmony_ci } 551cb0ef41Sopenharmony_ci} 561cb0ef41Sopenharmony_ci 571cb0ef41Sopenharmony_cifunction test_attribute_exists(parent_name, attribute_name, properties) 581cb0ef41Sopenharmony_ci{ 591cb0ef41Sopenharmony_ci var msg = 'window.performance.' + parent_name + '.' + attribute_name + ' is defined.'; 601cb0ef41Sopenharmony_ci wp_test(function() { assert_not_equals(performanceNamespace[parent_name][attribute_name], undefined, msg); }, msg, properties); 611cb0ef41Sopenharmony_ci} 621cb0ef41Sopenharmony_ci 631cb0ef41Sopenharmony_cifunction test_enum(parent_name, enum_name, value, properties) 641cb0ef41Sopenharmony_ci{ 651cb0ef41Sopenharmony_ci var msg = 'window.performance.' + parent_name + '.' + enum_name + ' is defined.'; 661cb0ef41Sopenharmony_ci wp_test(function() { assert_not_equals(performanceNamespace[parent_name][enum_name], undefined, msg); }, msg, properties); 671cb0ef41Sopenharmony_ci 681cb0ef41Sopenharmony_ci msg = 'window.performance.' + parent_name + '.' + enum_name + ' = ' + value; 691cb0ef41Sopenharmony_ci wp_test(function() { assert_equals(performanceNamespace[parent_name][enum_name], value, msg); }, msg, properties); 701cb0ef41Sopenharmony_ci} 711cb0ef41Sopenharmony_ci 721cb0ef41Sopenharmony_cifunction test_timing_order(attribute_name, greater_than_attribute, properties) 731cb0ef41Sopenharmony_ci{ 741cb0ef41Sopenharmony_ci // ensure it's not 0 first 751cb0ef41Sopenharmony_ci var msg = "window.performance.timing." + attribute_name + " > 0"; 761cb0ef41Sopenharmony_ci wp_test(function() { assert_true(performanceNamespace.timing[attribute_name] > 0, msg); }, msg, properties); 771cb0ef41Sopenharmony_ci 781cb0ef41Sopenharmony_ci // ensure it's in the right order 791cb0ef41Sopenharmony_ci msg = "window.performance.timing." + attribute_name + " >= window.performance.timing." + greater_than_attribute; 801cb0ef41Sopenharmony_ci wp_test(function() { assert_true(performanceNamespace.timing[attribute_name] >= performanceNamespace.timing[greater_than_attribute], msg); }, msg, properties); 811cb0ef41Sopenharmony_ci} 821cb0ef41Sopenharmony_ci 831cb0ef41Sopenharmony_cifunction test_timing_greater_than(attribute_name, greater_than, properties) 841cb0ef41Sopenharmony_ci{ 851cb0ef41Sopenharmony_ci var msg = "window.performance.timing." + attribute_name + " > " + greater_than; 861cb0ef41Sopenharmony_ci test_greater_than(performanceNamespace.timing[attribute_name], greater_than, msg, properties); 871cb0ef41Sopenharmony_ci} 881cb0ef41Sopenharmony_ci 891cb0ef41Sopenharmony_cifunction test_timing_equals(attribute_name, equals, msg, properties) 901cb0ef41Sopenharmony_ci{ 911cb0ef41Sopenharmony_ci var test_msg = msg || "window.performance.timing." + attribute_name + " == " + equals; 921cb0ef41Sopenharmony_ci test_equals(performanceNamespace.timing[attribute_name], equals, test_msg, properties); 931cb0ef41Sopenharmony_ci} 941cb0ef41Sopenharmony_ci 951cb0ef41Sopenharmony_ci// 961cb0ef41Sopenharmony_ci// Non-test related helper functions 971cb0ef41Sopenharmony_ci// 981cb0ef41Sopenharmony_ci 991cb0ef41Sopenharmony_cifunction sleep_milliseconds(n) 1001cb0ef41Sopenharmony_ci{ 1011cb0ef41Sopenharmony_ci var start = new Date().getTime(); 1021cb0ef41Sopenharmony_ci while (true) { 1031cb0ef41Sopenharmony_ci if ((new Date().getTime() - start) >= n) break; 1041cb0ef41Sopenharmony_ci } 1051cb0ef41Sopenharmony_ci} 1061cb0ef41Sopenharmony_ci 1071cb0ef41Sopenharmony_ci// 1081cb0ef41Sopenharmony_ci// Common helper functions 1091cb0ef41Sopenharmony_ci// 1101cb0ef41Sopenharmony_ci 1111cb0ef41Sopenharmony_cifunction test_greater_than(value, greater_than, msg, properties) 1121cb0ef41Sopenharmony_ci{ 1131cb0ef41Sopenharmony_ci wp_test(function () { assert_greater_than(value, greater_than, msg); }, msg, properties); 1141cb0ef41Sopenharmony_ci} 1151cb0ef41Sopenharmony_ci 1161cb0ef41Sopenharmony_cifunction test_greater_or_equals(value, greater_than, msg, properties) 1171cb0ef41Sopenharmony_ci{ 1181cb0ef41Sopenharmony_ci wp_test(function () { assert_greater_than_equal(value, greater_than, msg); }, msg, properties); 1191cb0ef41Sopenharmony_ci} 1201cb0ef41Sopenharmony_ci 1211cb0ef41Sopenharmony_cifunction test_not_equals(value, notequals, msg, properties) 1221cb0ef41Sopenharmony_ci{ 1231cb0ef41Sopenharmony_ci wp_test(function() { assert_not_equals(value, notequals, msg); }, msg, properties); 1241cb0ef41Sopenharmony_ci} 125