1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218
|
# This Source Code Form is subject to the terms of the Mozilla Public
# License, v. 2.0. If a copy of the MPL was not distributed with this
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
from marionette_driver import Wait
from marionette_harness import MarionetteTestCase
default_visible_pref = "sidebar.revamp.defaultLauncherVisible"
initial_prefs = {
"sidebar.revamp": False,
default_visible_pref: False,
# Set browser restore previous session pref
# we'll need to examine behavior using restored sidebar properties
"browser.startup.page": 3,
}
class TestDefaultLauncherVisible(MarionetteTestCase):
def tearDown(self):
try:
# Make sure subsequent tests get a clean profile
self.marionette.restart(in_app=False, clean=True)
finally:
super().tearDown()
def _close_last_tab(self):
# "self.marionette.close" cannot be used because it doesn't
# allow closing the very last tab.
self.marionette.execute_script("window.close()")
def restart_with_prefs(self, prefs):
# set the prefs then restart the browser
self.marionette.set_prefs(prefs)
self.marionette.restart()
# Restore the context as used before the restart
self.marionette.set_context("chrome")
self.wait_for_startup_idle_promise()
def is_launcher_visible(self):
hidden = self.marionette.execute_script(
"""
const window = BrowserWindowTracker.getTopWindow();
return window.SidebarController.sidebarContainer.hidden;
"""
)
return not hidden
def is_button_visible(self):
visible = self.marionette.execute_script(
"""
const window = BrowserWindowTracker.getTopWindow();
const placement = window.CustomizableUI.getPlacementOfWidget('sidebar-button');
if (!placement) {
return false;
}
const node = window.document.getElementById("sidebar-button");
return node && !node.hidden;
"""
)
return visible
def click_toolbar_button(self):
# Click the button to show the launcher
self.marionette.execute_script(
"""
const window = BrowserWindowTracker.getTopWindow();
return window.document.getElementById("sidebar-button").click()
"""
)
def wait_for_startup_idle_promise(self):
self.marionette.set_context("chrome")
self.marionette.execute_async_script(
"""
let resolve = arguments[0];
let { BrowserInitState } = ChromeUtils.importESModule("resource:///modules/BrowserGlue.sys.mjs");
BrowserInitState.startupIdleTaskPromise.then(resolve);
"""
)
def test_first_use_default_visible_pref_false(self):
# We flip sidebar.revamp to true, with defaultLauncherVisible=false for a profile
# that has never enabled or seen the sidebar launcher.
self.wait_for_startup_idle_promise()
self.assertFalse(
self.is_launcher_visible(),
"Sidebar launcher is hidden",
)
self.assertFalse(
self.is_button_visible(),
"Sidebar toolbar button is hidden",
)
# Mimic an update which enables sidebar.revamp for the first time
# ,with defaultLauncherVisible false
self.restart_with_prefs(
{
"sidebar.revamp": True,
"browser.startup.page": 3,
default_visible_pref: False,
}
)
Wait(self.marionette).until(
lambda _: self.is_button_visible(),
message="Sidebar button should be visible",
)
self.assertFalse(
self.is_launcher_visible(),
"Sidebar launcher remains hidden because defaultLauncherVisible=false",
)
# Click the button and verify that sticks
self.click_toolbar_button()
Wait(self.marionette).until(
lambda _: self.is_launcher_visible(),
message="Sidebar button should be visible",
)
self.marionette.restart()
self.marionette.set_context("chrome")
self.wait_for_startup_idle_promise()
self.assertTrue(
self.is_launcher_visible(),
"Sidebar launcher remains visible because user un-hid it in the resumed session",
)
def test_new_sidebar_enabled_default_visible_pref_false(self):
# Set up the profile with session restore and new sidebar enabled
self.restart_with_prefs(
{
"sidebar.revamp": True,
"browser.startup.page": 3,
default_visible_pref: False,
}
)
self.assertFalse(
self.is_launcher_visible(),
"Sidebar launcher is hidden",
)
self.assertTrue(
self.is_button_visible(),
"Sidebar toolbar button is visible",
)
# Mimic an update which enables sidebar.revamp with defaultLauncherVisible true
# The restart with session restore enabled while the launcher is visible should persist
# the launcherVisible=true and we don't want to override that
self.restart_with_prefs(
{
"sidebar.revamp": True,
"browser.startup.page": 3,
default_visible_pref: True,
}
)
Wait(self.marionette).until(
lambda _: self.is_button_visible(),
message="Sidebar button is still visible",
)
self.assertTrue(
self.is_launcher_visible(),
"Sidebar launcher is still visible",
)
# Click the button and verify that sticks
self.click_toolbar_button()
Wait(self.marionette).until(
lambda _: not self.is_launcher_visible(),
message="Sidebar launcher should be hidden",
)
self.marionette.restart()
self.marionette.set_context("chrome")
self.wait_for_startup_idle_promise()
self.assertFalse(
self.is_launcher_visible(),
"Sidebar launcher remains hidden on restart",
)
def test_vertical_tabs_default_hidden(self):
# Verify that starting with verticalTabs enabled and default visibility false results in a visible
# launcher with the vertical tabstrip
self.restart_with_prefs(
{
"sidebar.revamp": True,
"sidebar.verticalTabs": True,
default_visible_pref: False,
}
)
Wait(self.marionette).until(
lambda _: self.is_launcher_visible(),
message="Sidebar launcher should be initially visible",
)
tabsWidth = self.marionette.execute_script(
"""
const window = BrowserWindowTracker.getTopWindow();
return document.getElementById("vertical-tabs").getBoundingClientRect().width;
"""
)
self.assertGreater(tabsWidth, 0, "#vertical-tabs element has width")
# switch to 'hide-sidebar' visibility mode and confirm the launcher becomes hidden
self.marionette.set_pref("sidebar.visibility", "hide-sidebar")
Wait(self.marionette).until(
lambda _: not self.is_launcher_visible(),
message="Sidebar launcher should become hidden when hide-sidebar visibility is set and defaultLauncherVisible is false",
)
|