• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1<!DOCTYPE html>
2<html>
3  <head>
4        <meta charset="utf-8" >
5        <title>window.performance.now across frames</title>
6        <link rel="author" title="Google" href="http://www.google.com/">
7        <link rel="help" href="http://www.w3.org/TR/hr-time/#sec-extenstions-performance-interface">
8
9        <script src="/resources/testharness.js"></script>
10        <script src="/resources/testharnessreport.js"></script>
11
12        <script type="text/javascript">
13            setup({explicit_done: true});
14
15            var setup_frame = async_test("Setup the frame");
16
17            function start_test() {
18              setup_frame.step_timeout(function () {
19                var iframe = document.createElement('iframe');
20                iframe.id = 'frameContext';
21                iframe.onload = finish_test;
22                iframe.src = "resources/now_frame.html";
23                document.body.appendChild(iframe);
24                setup_frame.done();
25              }, 1000);
26            }
27
28            function finish_test() {
29              var childWindow = document.getElementById('frameContext').contentWindow;
30
31              // Verify a positive number is returned for both the frame and parent.
32              test(function() { assert_true(window.performance.now() > 0); }, 'parent performance.now() > 0');
33              test(function() { assert_true(childWindow.performance.now() > 0); }, 'child performance.now() > 0');
34
35              // Verify that the test properly created the child at least a second after the parent.
36              test(function () { assert_true(childWindow.performance.timing.navigationStart > (window.performance.timing.navigationStart + 1000)); },
37                                'Child created at least 1 second after parent');
38
39              test(function () {
40                var parentNow = window.performance.now();
41                var childNow = childWindow.performance.now();
42                var childParentSkew = Math.abs(childNow - parentNow);
43                assert_true(childParentSkew > 1000, 'Child and parent\'s now()s have different bases (skewed more than 1 second)');
44
45                var childLoadTime = childWindow.performance.timing.loadEventStart - childWindow.performance.timing.navigationStart;
46                assert_true(1000 > (childNow - childLoadTime), 'Child\'s now() is based on its document\'s navigationStart');
47              }, 'Child and parent time bases are correct');
48
49              done();
50            }
51        </script>
52
53    </head>
54    <body onload="start_test()">
55        <h1>Description</h1>
56        <p>This test validates the values of the window.performance.now() are based on the current document's navigationStart.</p>
57        <div id="log"></div>
58    </body>
59</html>
60