browser_animation_fission_switch-target.js (3025B)
1 /* Any copyright is dedicated to the Public Domain. 2 http://creativecommons.org/publicdomain/zero/1.0/ */ 3 4 "use strict"; 5 6 // Test that the animation inspector works after switching targets. 7 8 const PAGE_ON_CONTENT = `data:text/html;charset=utf-8, 9 <!DOCTYPE html> 10 <style type="text/css"> 11 div { 12 opacity: 0; 13 transition-duration: 5000ms; 14 transition-property: opacity; 15 } 16 17 div:hover { 18 opacity: 1; 19 } 20 </style> 21 <div class="anim">animation</div> 22 `; 23 const PAGE_ON_MAIN = "about:networking"; 24 25 add_task(async function () { 26 await pushPref("devtools.inspector.three-pane-enabled", false); 27 28 info("Open a page that runs on the content process and has animations"); 29 const tab = await addTab(PAGE_ON_CONTENT); 30 const { animationInspector, inspector } = await openAnimationInspector(); 31 32 info("Check the length of the initial animations of the content process"); 33 is( 34 animationInspector.state.animations.length, 35 0, 36 "The length of the initial animation is correct" 37 ); 38 39 info("Check whether the mutation on content process page is worked or not"); 40 await assertAnimationsMutation(tab, "div", animationInspector, 1); 41 42 info("Load a page that runs on the main process"); 43 await navigateTo( 44 PAGE_ON_MAIN, 45 tab.linkedBrowser, 46 animationInspector, 47 inspector 48 ); 49 await waitUntil(() => animationInspector.state.animations.length === 0); 50 ok(true, "The animations are replaced"); 51 52 info("Check whether the mutation on main process page is worked or not"); 53 await assertAnimationsMutation(tab, "#category-http", animationInspector, 1); 54 55 info("Load a content process page again"); 56 await navigateTo( 57 PAGE_ON_CONTENT, 58 tab.linkedBrowser, 59 animationInspector, 60 inspector 61 ); 62 await waitUntil(() => animationInspector.state.animations.length === 0); 63 ok(true, "The animations are replaced again"); 64 65 info("Check the mutation on content process again"); 66 await assertAnimationsMutation(tab, "div", animationInspector, 1); 67 }); 68 69 async function assertAnimationsMutation( 70 tab, 71 selector, 72 animationInspector, 73 expectedAnimationCount 74 ) { 75 await hover(tab, selector); 76 await waitUntil( 77 () => animationInspector.state.animations.length === expectedAnimationCount 78 ); 79 ok(true, "Animations mutation is worked"); 80 } 81 82 async function navigateTo(uri, browser, animationInspector, inspector) { 83 const previousAnimationsFront = animationInspector.animationsFront; 84 const onReloaded = inspector.once("reloaded"); 85 const onUpdated = inspector.once("inspector-updated"); 86 BrowserTestUtils.startLoadingURIString(browser, uri); 87 await waitUntil( 88 () => previousAnimationsFront !== animationInspector.animationsFront 89 ); 90 ok(true, "Target is switched correctly"); 91 await Promise.all([onReloaded, onUpdated]); 92 } 93 94 async function hover(tab, selector) { 95 await SpecialPowers.spawn(tab.linkedBrowser, [selector], async s => { 96 const element = content.wrappedJSObject.document.querySelector(s); 97 InspectorUtils.addPseudoClassLock(element, ":hover", true); 98 }); 99 }