browser_inspector_portrait_mode.js (2568B)
1 /* This Source Code Form is subject to the terms of the Mozilla Public 2 * License, v. 2.0. If a copy of the MPL was not distributed with this 3 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ 4 5 "use strict"; 6 7 // Test that the inspector splitter is properly initialized in horizontal mode if the 8 // inspector starts in portrait mode. 9 10 add_task(async function () { 11 let { inspector, toolbox } = await openInspectorForURL( 12 "data:text/html;charset=utf-8,<h1>foo</h1><span>bar</span>", 13 "window" 14 ); 15 16 const hostWindow = toolbox.win.parent; 17 const originalWidth = hostWindow.outerWidth; 18 const originalHeight = hostWindow.outerHeight; 19 20 let splitter = inspector.panelDoc.querySelector( 21 ".inspector-sidebar-splitter" 22 ); 23 24 // If the inspector is not already in landscape mode. 25 if (!splitter.classList.contains("vert")) { 26 info("Resize toolbox window to force inspector to landscape mode"); 27 const onClassnameMutation = waitForClassMutation(splitter); 28 hostWindow.resizeTo(800, 500); 29 await onClassnameMutation; 30 31 ok(splitter.classList.contains("vert"), "Splitter is in vertical mode"); 32 } 33 34 info("Resize toolbox window to force inspector to portrait mode"); 35 const onClassnameMutation = waitForClassMutation(splitter); 36 hostWindow.resizeTo(500, 500); 37 await onClassnameMutation; 38 39 ok(splitter.classList.contains("horz"), "Splitter is in horizontal mode"); 40 41 info("Close the inspector"); 42 await toolbox.destroy(); 43 44 info("Reopen inspector"); 45 ({ inspector, toolbox } = await openInspector("window")); 46 47 // Devtools window should still be 500px * 500px, inspector should still be in portrait. 48 splitter = inspector.panelDoc.querySelector(".inspector-sidebar-splitter"); 49 ok(splitter.classList.contains("horz"), "Splitter is in horizontal mode"); 50 51 info("Restore original window size"); 52 toolbox.win.parent.resizeTo(originalWidth, originalHeight); 53 }); 54 55 /** 56 * Helper waiting for a class attribute mutation on the provided target. Returns a 57 * promise. 58 * 59 * @param {Node} target 60 * Node to observe 61 * @return {Promise} promise that will resolve upon receiving a mutation for the class 62 * attribute on the target. 63 */ 64 function waitForClassMutation(target) { 65 return new Promise(resolve => { 66 const observer = new MutationObserver(mutations => { 67 for (const mutation of mutations) { 68 if (mutation.attributeName === "class") { 69 observer.disconnect(); 70 resolve(); 71 return; 72 } 73 } 74 }); 75 observer.observe(target, { attributes: true }); 76 }); 77 }