11cb0ef41Sopenharmony_ci/* 21cb0ef41Sopenharmony_ciauthor: W3C http://www.w3.org/ 31cb0ef41Sopenharmony_cihelp: http://www.w3.org/TR/navigation-timing/#sec-window.performance-attribute 41cb0ef41Sopenharmony_ci*/ 51cb0ef41Sopenharmony_civar performanceNamespace = window.performance; 61cb0ef41Sopenharmony_civar namespace_check = false; 71cb0ef41Sopenharmony_cifunction wp_test(func, msg, properties) 81cb0ef41Sopenharmony_ci{ 91cb0ef41Sopenharmony_ci // only run the namespace check once 101cb0ef41Sopenharmony_ci if (!namespace_check) 111cb0ef41Sopenharmony_ci { 121cb0ef41Sopenharmony_ci namespace_check = true; 131cb0ef41Sopenharmony_ci 141cb0ef41Sopenharmony_ci if (performanceNamespace === undefined || performanceNamespace == null) 151cb0ef41Sopenharmony_ci { 161cb0ef41Sopenharmony_ci // show a single error that window.performance is undefined 171cb0ef41Sopenharmony_ci // The window.performance attribute provides a hosting area for performance related attributes. 181cb0ef41Sopenharmony_ci test(function() { assert_true(performanceNamespace !== undefined && performanceNamespace != null, "window.performance is defined and not null"); }, "window.performance is defined and not null."); 191cb0ef41Sopenharmony_ci } 201cb0ef41Sopenharmony_ci } 211cb0ef41Sopenharmony_ci 221cb0ef41Sopenharmony_ci test(func, msg, properties); 231cb0ef41Sopenharmony_ci} 241cb0ef41Sopenharmony_ci 251cb0ef41Sopenharmony_cifunction test_true(value, msg, properties) 261cb0ef41Sopenharmony_ci{ 271cb0ef41Sopenharmony_ci wp_test(function () { assert_true(value, msg); }, msg, properties); 281cb0ef41Sopenharmony_ci} 291cb0ef41Sopenharmony_ci 301cb0ef41Sopenharmony_cifunction test_equals(value, equals, msg, properties) 311cb0ef41Sopenharmony_ci{ 321cb0ef41Sopenharmony_ci wp_test(function () { assert_equals(value, equals, msg); }, msg, properties); 331cb0ef41Sopenharmony_ci} 341cb0ef41Sopenharmony_ci 351cb0ef41Sopenharmony_ci// assert for every entry in `expectedEntries`, there is a matching entry _somewhere_ in `actualEntries` 361cb0ef41Sopenharmony_cifunction test_entries(actualEntries, expectedEntries) { 371cb0ef41Sopenharmony_ci test_equals(actualEntries.length, expectedEntries.length) 381cb0ef41Sopenharmony_ci expectedEntries.forEach(function (expectedEntry) { 391cb0ef41Sopenharmony_ci var foundEntry = actualEntries.find(function (actualEntry) { 401cb0ef41Sopenharmony_ci return typeof Object.keys(expectedEntry).find(function (key) { 411cb0ef41Sopenharmony_ci return actualEntry[key] !== expectedEntry[key] 421cb0ef41Sopenharmony_ci }) === 'undefined' 431cb0ef41Sopenharmony_ci }) 441cb0ef41Sopenharmony_ci test_true(!!foundEntry, `Entry ${JSON.stringify(expectedEntry)} could not be found.`) 451cb0ef41Sopenharmony_ci if (foundEntry) { 461cb0ef41Sopenharmony_ci assert_object_equals(foundEntry.toJSON(), expectedEntry) 471cb0ef41Sopenharmony_ci } 481cb0ef41Sopenharmony_ci }) 491cb0ef41Sopenharmony_ci} 501cb0ef41Sopenharmony_ci 511cb0ef41Sopenharmony_cifunction delayedLoadListener(callback) { 521cb0ef41Sopenharmony_ci window.addEventListener('load', function() { 531cb0ef41Sopenharmony_ci // TODO(cvazac) Remove this setTimeout when spec enforces sync entries. 541cb0ef41Sopenharmony_ci step_timeout(callback, 0) 551cb0ef41Sopenharmony_ci }) 561cb0ef41Sopenharmony_ci} 57