test_transitions_replacement_with_setKeyframes.html (2559B)
1 <!doctype html> 2 <html> 3 <!-- 4 https://bugzilla.mozilla.org/show_bug.cgi?id=1292001 5 --> 6 <head> 7 <meta charset=utf-8> 8 <title>Test for bug 1292001</title> 9 <script src="/tests/SimpleTest/SimpleTest.js"></script> 10 <script src="/tests/SimpleTest/paint_listener.js"></script> 11 <script src="animation_utils.js"></script> 12 <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"> 13 <style> 14 #target { 15 height: 100px; 16 width: 100px; 17 background: green; 18 transition: transform 100s linear; 19 } 20 </style> 21 </head> 22 <body> 23 <div id="target"></div> 24 <script> 25 'use strict'; 26 27 SimpleTest.waitForExplicitFinish(); 28 29 const OMTAPrefKey = 'layers.offmainthreadcomposition.async-animations'; 30 const omtaEnabled = 31 SpecialPowers.DOMWindowUtils.layerManagerRemote && 32 SpecialPowers.getBoolPref(OMTAPrefKey); 33 34 window.addEventListener('load', async function() { 35 if (!omtaEnabled) { 36 ok(true, 'Skipping the test since OMTA is disabled'); 37 SimpleTest.finish(); 38 return; 39 } 40 41 const div = document.getElementById('target'); 42 43 // Start first transition 44 div.style.transform = 'translateX(300px)'; 45 const firstTransition = div.getAnimations()[0]; 46 47 // But then change its keyframes to something completely different. 48 firstTransition.effect.setKeyframes({ 'opacity': ['0', '1'] }); 49 50 // Wait for the transition to start running on the main thread and 51 // compositor. 52 await firstTransition.ready; 53 await waitForPaints(); 54 await new Promise(resolve => requestAnimationFrame(resolve)); 55 56 // Start second transition 57 div.style.transform = 'translateX(600px)'; 58 const secondTransition = div.getAnimations()[0]; 59 60 const previousKeyframeValue = secondTransition.effect.getKeyframes()[0] 61 .transform; 62 63 // Tie up main thread for 300ms. In the meantime, the first transition 64 // will continue running on the compositor. If we don't update the start 65 // point of the second transition, it will appear to jump when it starts. 66 const startTime = performance.now(); 67 while (performance.now() - startTime < 300); 68 69 // Ensure that our paint process has been done. 70 // 71 // (See explanation in test_transitions_replacement_on_busy_frame.html for 72 // why we don't use requestAnimationFrame here.) 73 await waitForPaints(); 74 75 // Now check that the keyframes are NOT updated. 76 is( 77 secondTransition.effect.getKeyframes()[0].transform, 78 previousKeyframeValue, 79 'Keyframe value of transition is NOT updated since the moment when ' + 80 'it was generated' 81 ); 82 83 SimpleTest.finish(); 84 }); 85 86 </script> 87 </body> 88 </html>