tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

measure_associated_with_navigation_timing.html (4009B)


      1 <!DOCTYPE html>
      2 <html>
      3 <head>
      4 <meta charset="utf-8" />
      5 <title>functionality test of window.performance.measure</title>
      6 <link rel="author" title="Intel" href="http://www.intel.com/" />
      7 <link rel="help" href="http://www.w3.org/TR/user-timing/#extensions-performance-interface"/>
      8 <script src="/resources/testharness.js"></script>
      9 <script src="/resources/testharnessreport.js"></script>
     10 <script src="/common/performance-timeline-utils.js"></script>
     11 <script src="resources/webperftestharness.js"></script>
     12 <script src="resources/webperftestharnessextension.js"></script>
     13 <script>
     14 setup({ explicit_done: true });
     15 
     16 function onload_test()
     17 {
     18    const measures_for_timing_order = [
     19        ['nav2now', 'navigationStart'],
     20        ['loadTime', 'navigationStart', 'loadEventEnd'],
     21        ['loadEventEnd2a', 'loadEventEnd', 'abc'],
     22        ['nav2a', 'navigationStart', 'abc'],
     23        ['domComplete2a', 'domComplete', 'abc'],
     24        ['negativeValue', 1, 'navigationStart'],
     25    ];
     26    const context = new PerformanceContext(window.performance);
     27 
     28    mark_names.forEach(function(name) {
     29        context.mark(name);
     30    });
     31    measures_for_timing_order.forEach(context.initialMeasures, context);
     32    test_greater_than(context.getEntriesByName('nav2now', 'measure')[0].duration, 0, 'Measure of navigationStart to now should be positive value.');
     33    test_greater_than(context.getEntriesByName('loadTime', 'measure')[0].duration, 0, 'Measure of navigationStart to loadEventEnd should be positive value.');
     34    test_greater_than(0, context.getEntriesByName('negativeValue', 'measure')[0].duration, 'Measure of current mark to navigationStart should be negative value.');
     35    test_equals(context.getEntriesByName('loadTime', 'measure')[0].duration + context.getEntriesByName('loadEventEnd2a', 'measure')[0].duration, context.getEntriesByName('nav2a', 'measure')[0].duration, 'loadTime plus loadEventEnd to a mark "a" should equal to navigationStart to "a".');
     36 
     37    // We later assert that time has passed between setting one set of marks and another set.
     38    // However, this assertion will fail if the test executes fast enough such that the marks occur
     39    // at the same clock time. This is more likely in browsers such as Firefox that reduce the
     40    // precision of the clock exposed through this API to mitigate timing attacks. To mitigate the
     41    // test failure, we sleep. Firefox may round timestamps to the nearest millisecond in either
     42    // direction - e.g. 10ms & 11.999ms may both round to 11ms - so we need to sleep at least 2ms to
     43    // avoid test failures. To be safe, we sleep 3ms.
     44    sleep_milliseconds(3);
     45 
     46    // Following cases test for scenarios that measure names are tied twice.
     47    mark_names.forEach(function(name) {
     48        context.mark(name);
     49    });
     50    measures_for_timing_order.forEach(context.initialMeasures, context);
     51 
     52    test_greater_than(context.getEntriesByName('nav2now', 'measure')[1].duration, context.getEntriesByName('nav2now', 'measure')[0].duration, 'Second measure of current mark to navigationStart should be negative value.');
     53    test_equals(context.getEntriesByName('loadTime', 'measure')[0].duration, context.getEntriesByName('loadTime', 'measure')[1].duration, 'Measures of loadTime should have same duration.');
     54    test_greater_than(context.getEntriesByName('domComplete2a', 'measure')[1].duration, context.getEntriesByName('domComplete2a', 'measure')[0].duration, 'Measure from domComplete event to most recent mark "a" should have longer duration.');
     55    test_greater_than(context.getEntriesByName('negativeValue', 'measure')[0].duration, context.getEntriesByName('negativeValue', 'measure')[1].duration, 'Measure from most recent mark to navigationStart should have longer duration.');
     56 
     57    done();
     58 }
     59 </script>
     60 </head>
     61 <body onload="setTimeout(onload_test,0)">
     62    <h1>Description</h1>
     63    <p>This test validates functionality of the interface window.performance.measure using keywords from the Navigation Timing spec.</p>
     64    <div id="log"></div>
     65 </body>
     66 </html>