test_document-timeline.html (5883B)
1 <!doctype html> 2 <meta charset=utf-8> 3 <title>Web Animations API: DocumentTimeline tests</title> 4 <script src="/resources/testharness.js"></script> 5 <script src="/resources/testharnessreport.js"></script> 6 <script src="../testcommon.js"></script> 7 <iframe srcdoc='<html><meta charset=utf-8></html>' width="10" height="10" id="iframe"></iframe> 8 <iframe srcdoc='<html style="display:none"><meta charset=utf-8></html>' width="10" height="10" id="hidden-iframe"></iframe> 9 <div id="log"></div> 10 <script> 11 'use strict'; 12 13 test(function() { 14 assert_equals(document.timeline, document.timeline, 15 'document.timeline returns the same object every time'); 16 var iframe = document.getElementById('iframe'); 17 assert_not_equals(document.timeline, iframe.contentDocument.timeline, 18 'document.timeline returns a different object for each document'); 19 assert_not_equals(iframe.contentDocument.timeline, null, 20 'document.timeline on an iframe is not null'); 21 }, 22 'document.timeline identity tests', 23 { 24 help: 'http://dev.w3.org/fxtf/web-animations/#the-document-timeline', 25 assert: [ 'Each document has a timeline called the document timeline' ], 26 author: 'Brian Birtles' 27 }); 28 29 async_test(function(t) { 30 const { AppConstants } = SpecialPowers.ChromeUtils.importESModule( 31 "resource://gre/modules/AppConstants.sys.mjs" 32 ); 33 34 if (AppConstants.platform == "android") { 35 // Skip this test case on Android since it frequently fails on the 36 // environments. See bug 1761900. 37 t.done(); 38 } 39 40 assert_greater_than_equal(document.timeline.currentTime, 0, 41 'document.timeline.currentTime is positive or zero'); 42 // document.timeline.currentTime should be set even before document 43 // load fires. We expect this code to be run before document load and hence 44 // the above assertion is sufficient. 45 // If the following assertion fails, this test needs to be redesigned. 46 assert_true(document.readyState !== 'complete', 47 'Test is running prior to document load'); 48 49 // Test that the document timeline's current time is measured from 50 // navigationStart. 51 // 52 // We can't just compare document.timeline.currentTime to 53 // window.performance.now() because currentTime is only updated on a sample 54 // so we use requestAnimationFrame instead. 55 window.requestAnimationFrame(t.step_func(function(rafTime) { 56 assert_equals(document.timeline.currentTime, rafTime, 57 'document.timeline.currentTime matches' + 58 ' requestAnimationFrame time'); 59 t.done(); 60 })); 61 }, 62 'document.timeline.currentTime value tests', 63 { 64 help: [ 65 'http://dev.w3.org/fxtf/web-animations/#the-global-clock', 66 'http://dev.w3.org/fxtf/web-animations/#the-document-timeline' 67 ], 68 assert: [ 69 'The global clock is a source of monotonically increasing time values', 70 'The time values of the document timeline are calculated as a fixed' + 71 ' offset from the global clock', 72 'the zero time corresponds to the navigationStart moment', 73 'the time value of each document timeline must be equal to the time ' + 74 'passed to animation frame request callbacks for that browsing context' 75 ], 76 author: 'Brian Birtles' 77 }); 78 79 async_test(function(t) { 80 var valueAtStart = document.timeline.currentTime; 81 var timeAtStart = window.performance.now(); 82 while (window.performance.now() - timeAtStart < 100) { 83 // Wait 100ms 84 } 85 assert_equals(document.timeline.currentTime, valueAtStart, 86 'document.timeline.currentTime does not change within a script block'); 87 window.requestAnimationFrame(t.step_func(function() { 88 assert_true(document.timeline.currentTime > valueAtStart, 89 'document.timeline.currentTime increases between script blocks'); 90 t.done(); 91 })); 92 }, 93 'document.timeline.currentTime liveness tests', 94 { 95 help: 'http://dev.w3.org/fxtf/web-animations/#script-execution-and-live-updates-to-the-model', 96 assert: [ 'The value returned by the currentTime attribute of a' + 97 ' document timeline will not change within a script block' ], 98 author: 'Brian Birtles' 99 }); 100 101 test(function() { 102 var hiddenIFrame = document.getElementById('hidden-iframe'); 103 assert_equals(typeof hiddenIFrame.contentDocument.timeline.currentTime, 104 'number', 105 'currentTime of an initially hidden subframe\'s timeline is a number'); 106 assert_true(hiddenIFrame.contentDocument.timeline.currentTime >= 0, 107 'currentTime of an initially hidden subframe\'s timeline is >= 0'); 108 }, 'document.timeline.currentTime hidden subframe test'); 109 110 async_test(function(t) { 111 var hiddenIFrame = document.getElementById('hidden-iframe'); 112 113 // Don't run the test until after the iframe has completed loading or else the 114 // contentDocument may change. 115 var testToRunOnLoad = t.step_func(function() { 116 // Remove display:none 117 hiddenIFrame.style.display = 'block'; 118 getComputedStyle(hiddenIFrame).display; 119 120 window.requestAnimationFrame(t.step_func(function() { 121 assert_greater_than(hiddenIFrame.contentDocument.timeline.currentTime, 0, 122 'document.timeline.currentTime is positive after removing' 123 + ' display:none'); 124 var previousValue = hiddenIFrame.contentDocument.timeline.currentTime; 125 126 // Re-introduce display:none 127 hiddenIFrame.style.display = 'none'; 128 getComputedStyle(hiddenIFrame).display; 129 130 window.requestAnimationFrame(t.step_func(function() { 131 assert_true( 132 hiddenIFrame.contentDocument.timeline.currentTime >= previousValue, 133 'document.timeline.currentTime does not go backwards after' 134 + ' re-setting display:none'); 135 t.done(); 136 })); 137 })); 138 }); 139 140 if (hiddenIFrame.contentDocument.readyState === 'complete' && hiddenIFrame.contentDocument.location.href !== "about:blank") { 141 testToRunOnLoad(); 142 } else { 143 hiddenIFrame.addEventListener("load", testToRunOnLoad); 144 } 145 }, 'document.timeline.currentTime hidden subframe dynamic test'); 146 147 </script>