browser_aiwindow_switcher.js (3569B)
1 /* Any copyright is dedicated to the Public Domain. 2 * http://creativecommons.org/publicdomain/zero/1.0/ */ 3 4 "use strict"; 5 6 // Ensure Window Switcher button is visible when AI Window is enabled in prefs 7 add_task(async function test_window_switcher_button_visibility() { 8 await SpecialPowers.pushPrefEnv({ 9 set: [["browser.aiwindow.enabled", false]], 10 }); 11 12 let button = document.getElementById("ai-window-toggle"); 13 Assert.ok( 14 button?.hidden, 15 "Window switcher button should be hidden when AI Window is disabled" 16 ); 17 18 await SpecialPowers.popPrefEnv(); 19 20 await SpecialPowers.pushPrefEnv({ 21 set: [["browser.aiwindow.enabled", true]], 22 }); 23 24 button = document.getElementById("ai-window-toggle"); 25 Assert.ok( 26 button && !button.hidden, 27 "Window switcher button should be visible when AI Window is enabled" 28 ); 29 30 await SpecialPowers.popPrefEnv(); 31 }); 32 33 // if (browser.aiwindow.enabled) Classic Window should switch to AI Window on click 34 add_task(async function test_switch_to_ai_window() { 35 await SpecialPowers.pushPrefEnv({ 36 set: [["browser.aiwindow.enabled", true]], 37 }); 38 39 if (document.documentElement.hasAttribute("ai-window")) { 40 document.documentElement.removeAttribute("ai-window"); 41 } 42 43 let button = document.getElementById("ai-window-toggle"); 44 let view = PanelMultiView.getViewNode(document, "ai-window-toggle-view"); 45 46 let viewShownPromise = BrowserTestUtils.waitForEvent(view, "ViewShown"); 47 button.click(); 48 await viewShownPromise; 49 50 let aiButton = view.querySelector("#ai-window-switch-ai"); 51 aiButton.click(); 52 53 await TestUtils.waitForCondition( 54 () => document.documentElement.hasAttribute("ai-window"), 55 "Window should have ai-window attribute after switching" 56 ); 57 58 Assert.ok( 59 document.documentElement.hasAttribute("ai-window"), 60 "Window should be in AI Window mode" 61 ); 62 63 let iconListImage = window.getComputedStyle(button)["list-style-image"]; 64 Assert.ok( 65 iconListImage.includes("ai-window.svg"), 66 "Button icon should change to AI Window icon" 67 ); 68 69 await TestUtils.waitForCondition( 70 () => PanelUI.panel.state === "closed", 71 "Panel should close after switching" 72 ); 73 74 await SpecialPowers.popPrefEnv(); 75 }); 76 77 // if (browser.aiwindow.enabled) AI Window should switch to Classic Window on click 78 add_task(async function test_switch_to_classic_window() { 79 await SpecialPowers.pushPrefEnv({ 80 set: [["browser.aiwindow.enabled", true]], 81 }); 82 83 if (!document.documentElement.hasAttribute("ai-window")) { 84 document.documentElement.setAttribute("ai-window", ""); 85 } 86 87 let button = document.getElementById("ai-window-toggle"); 88 let view = PanelMultiView.getViewNode(document, "ai-window-toggle-view"); 89 90 let viewShownPromise = BrowserTestUtils.waitForEvent(view, "ViewShown"); 91 button.click(); 92 await viewShownPromise; 93 94 let classicButton = view.querySelector("#ai-window-switch-classic"); 95 classicButton.click(); 96 97 await TestUtils.waitForCondition( 98 () => !document.documentElement.hasAttribute("ai-window"), 99 "Window should not have ai-window attribute after switching" 100 ); 101 102 Assert.ok( 103 !document.documentElement.hasAttribute("ai-window"), 104 "Window should be in Classic Window mode" 105 ); 106 107 let iconListImage = window.getComputedStyle(button)["list-style-image"]; 108 Assert.ok( 109 iconListImage.includes("icon32.png"), 110 "Button icon should change to Classic Window icon" 111 ); 112 113 await TestUtils.waitForCondition( 114 () => PanelUI.panel.state === "closed", 115 "Panel should close after switching" 116 ); 117 118 await SpecialPowers.popPrefEnv(); 119 });