diff options
Diffstat (limited to 'browser/base/content/test/tabs')
29 files changed, 448 insertions, 85 deletions
diff --git a/browser/base/content/test/tabs/browser.toml b/browser/base/content/test/tabs/browser.toml index 1b4a6900bf..fa77a8b1a4 100644 --- a/browser/base/content/test/tabs/browser.toml +++ b/browser/base/content/test/tabs/browser.toml @@ -76,6 +76,8 @@ support-files = ["tab_that_closes.html"] ["browser_hiddentab_contextmenu.js"] +["browser_lastSeenActive.js"] + ["browser_lazy_tab_browser_events.js"] ["browser_link_in_tab_title_and_url_prefilled_blank_page.js"] diff --git a/browser/base/content/test/tabs/browser_allow_process_switches_despite_related_browser.js b/browser/base/content/test/tabs/browser_allow_process_switches_despite_related_browser.js index b782c3aada..fea1de8fe0 100644 --- a/browser/base/content/test/tabs/browser_allow_process_switches_despite_related_browser.js +++ b/browser/base/content/test/tabs/browser_allow_process_switches_despite_related_browser.js @@ -13,7 +13,7 @@ add_task(async function () { }); let promiseTab = BrowserTestUtils.waitForNewTab(gBrowser, DATA_URI_SOURCE); - BrowserViewSource(tab.linkedBrowser); + BrowserCommands.viewSource(tab.linkedBrowser); let viewSourceTab = await promiseTab; registerCleanupFunction(async function () { BrowserTestUtils.removeTab(viewSourceTab); diff --git a/browser/base/content/test/tabs/browser_audioTabIcon.js b/browser/base/content/test/tabs/browser_audioTabIcon.js index 53b5140abb..c065e2b173 100644 --- a/browser/base/content/test/tabs/browser_audioTabIcon.js +++ b/browser/base/content/test/tabs/browser_audioTabIcon.js @@ -396,7 +396,7 @@ async function test_swapped_browser_while_not_playing(oldTab, newBrowser) { ); let AudioPlaybackPromise = new Promise(resolve => { - let observer = (subject, topic, data) => { + let observer = () => { ok(false, "Should not see an audio-playback notification"); }; Services.obs.addObserver(observer, "audio-playback"); @@ -443,7 +443,7 @@ async function test_swapped_browser_while_not_playing(oldTab, newBrowser) { await test_tooltip(newTab.overlayIcon, "Unmute tab", true, newTab); } -async function test_browser_swapping(tab, browser) { +async function test_browser_swapping(tab) { // First, test swapping with a playing but muted tab. await play(tab); diff --git a/browser/base/content/test/tabs/browser_e10s_about_page_triggeringprincipal.js b/browser/base/content/test/tabs/browser_e10s_about_page_triggeringprincipal.js index 4610551977..8fbee64db4 100644 --- a/browser/base/content/test/tabs/browser_e10s_about_page_triggeringprincipal.js +++ b/browser/base/content/test/tabs/browser_e10s_about_page_triggeringprincipal.js @@ -86,7 +86,7 @@ add_task(async function test_principal_ctrl_click() { await BrowserTestUtils.withNewTab( "about:test-about-principal-parent", - async function (browser) { + async function () { let loadPromise = BrowserTestUtils.waitForNewTab( gBrowser, "about:test-about-principal-child", @@ -149,7 +149,7 @@ add_task(async function test_principal_right_click_open_link_in_new_tab() { await BrowserTestUtils.withNewTab( "about:test-about-principal-parent", - async function (browser) { + async function () { let loadPromise = BrowserTestUtils.waitForNewTab( gBrowser, "about:test-about-principal-child", diff --git a/browser/base/content/test/tabs/browser_e10s_about_process.js b/browser/base/content/test/tabs/browser_e10s_about_process.js index f73e8e659c..504dfe0265 100644 --- a/browser/base/content/test/tabs/browser_e10s_about_process.js +++ b/browser/base/content/test/tabs/browser_e10s_about_process.js @@ -37,7 +37,7 @@ const TEST_MODULES = [ function AboutModule() {} AboutModule.prototype = { - newChannel(aURI, aLoadInfo) { + newChannel() { throw Components.Exception("", Cr.NS_ERROR_NOT_IMPLEMENTED); }, @@ -52,7 +52,7 @@ AboutModule.prototype = { return 0; }, - getIndexedDBOriginPostfix(aURI) { + getIndexedDBOriginPostfix() { return null; }, diff --git a/browser/base/content/test/tabs/browser_lastSeenActive.js b/browser/base/content/test/tabs/browser_lastSeenActive.js new file mode 100644 index 0000000000..d6bba57d93 --- /dev/null +++ b/browser/base/content/test/tabs/browser_lastSeenActive.js @@ -0,0 +1,260 @@ +/* Any copyright is dedicated to the Public Domain. + * http://creativecommons.org/publicdomain/zero/1.0/ */ + +const { SessionStoreTestUtils } = ChromeUtils.importESModule( + "resource://testing-common/SessionStoreTestUtils.sys.mjs" +); + +const triggeringPrincipal_base64 = E10SUtils.SERIALIZED_SYSTEMPRINCIPAL; + +SessionStoreTestUtils.init(this, window); +// take a state snapshot we can restore to after each test +const ORIG_STATE = SessionStore.getBrowserState(); + +const SECOND_MS = 1000; +const DAY_MS = 24 * 60 * 60 * 1000; +const today = new Date().getTime(); +const yesterday = new Date(Date.now() - DAY_MS).getTime(); + +function tabEntry(url, lastAccessed) { + return { + entries: [{ url, triggeringPrincipal_base64 }], + lastAccessed, + }; +} + +/** + * Make the given window focused and active + */ +async function switchToWindow(win) { + info("switchToWindow, waiting for promiseFocus"); + await SimpleTest.promiseFocus(win); + info("switchToWindow, waiting for correct Services.focus.activeWindow"); + await BrowserTestUtils.waitForCondition( + () => Services.focus.activeWindow == win + ); +} + +async function changeSizeMode(win, mode) { + let promise = BrowserTestUtils.waitForEvent(win, "sizemodechange"); + win[mode](); + await promise; +} + +async function cleanup() { + await switchToWindow(window); + await SessionStoreTestUtils.promiseBrowserState(ORIG_STATE); + is( + BrowserWindowTracker.orderedWindows.length, + 1, + "One window at the end of test cleanup" + ); + info("cleanup, browser state restored"); +} + +function deltaTime(time, expectedTime) { + return Math.abs(expectedTime - time); +} + +function getWindowUrl(win) { + return win.gBrowser.selectedBrowser?.currentURI?.spec; +} + +function getWindowByTabUrl(url) { + return BrowserWindowTracker.orderedWindows.find( + win => getWindowUrl(win) == url + ); +} + +add_task(async function restoredTabs() { + const now = Date.now(); + await SessionStoreTestUtils.promiseBrowserState({ + windows: [ + { + tabs: [ + tabEntry("data:,Window0-Tab0", yesterday), + tabEntry("data:,Window0-Tab1", yesterday), + ], + selected: 2, + }, + ], + }); + is( + gBrowser.visibleTabs[1], + gBrowser.selectedTab, + "The selected tab is the 2nd visible tab" + ); + is( + getWindowUrl(window), + "data:,Window0-Tab1", + "The expected tab is selected" + ); + Assert.greaterOrEqual( + gBrowser.selectedTab.lastSeenActive, + now, + "The selected tab's lastSeenActive is now" + ); + Assert.greaterOrEqual( + gBrowser.selectedTab.lastAccessed, + now, + "The selected tab's lastAccessed is now" + ); + + // tab restored from session but never seen or active + is( + gBrowser.visibleTabs[0].lastSeenActive, + yesterday, + "The restored tab's lastSeenActive is yesterday" + ); + await cleanup(); +}); + +add_task(async function switchingTabs() { + let now = Date.now(); + let initialTab = gBrowser.selectedTab; + let applicationStart = Services.startup.getStartupInfo().start.getTime(); + let openedTab = BrowserTestUtils.addTab(gBrowser, "data:,Tab1"); + await BrowserTestUtils.browserLoaded(openedTab.linkedBrowser); + + ok(!openedTab.selected, "The background tab we opened isn't selected"); + Assert.greaterOrEqual( + initialTab.selected && initialTab.lastSeenActive, + now, + "The initial tab is selected and last seen now" + ); + + is( + openedTab.lastSeenActive, + applicationStart, + `Background tab got default lastSeenActive value, delta: ${deltaTime( + openedTab.lastSeenActive, + applicationStart + )}` + ); + + now = Date.now(); + await BrowserTestUtils.switchTab(gBrowser, openedTab); + Assert.greaterOrEqual( + openedTab.lastSeenActive, + now, + "The tab we switched to is last seen now" + ); + + await cleanup(); +}); + +add_task(async function switchingWindows() { + info("Restoring to the test browser state"); + await SessionStoreTestUtils.promiseBrowserState({ + windows: [ + { + tabs: [tabEntry("data:,Window1-Tab0", yesterday)], + selected: 1, + sizemodeBeforeMinimized: "normal", + sizemode: "maximized", + zIndex: 1, // this will be the selected window + }, + { + tabs: [tabEntry("data:,Window2-Tab0", yesterday)], + selected: 1, + sizemodeBeforeMinimized: "normal", + sizemode: "maximized", + zIndex: 2, + }, + ], + }); + info("promiseBrowserState resolved"); + info( + `BrowserWindowTracker.pendingWindows: ${BrowserWindowTracker.pendingWindows.size}` + ); + await Promise.all( + Array.from(BrowserWindowTracker.pendingWindows.values()).map( + win => win.deferred.promise + ) + ); + info("All the pending windows are resolved"); + info("Waiting for the firstBrowserLoaded in each of the windows"); + await Promise.all( + BrowserWindowTracker.orderedWindows.map(win => { + const selectedUrl = getWindowUrl(win); + if (selectedUrl && selectedUrl !== "about:blank") { + return Promise.resolve(); + } + return BrowserTestUtils.firstBrowserLoaded(win, false); + }) + ); + let expectedTabURLs = ["data:,Window1-Tab0", "data:,Window2-Tab0"]; + let [win1, win2] = expectedTabURLs.map(url => getWindowByTabUrl(url)); + if (BrowserWindowTracker.getTopWindow() !== win1) { + info("Switch to win1 which isn't active/top after restoring session"); + // In theory the zIndex values in the session state should make win1 active + // But in practice that isn't always true. To ensure we're testing from a known state, + // ensure the first window is active before proceeding with the test + await switchToWindow(win1); + [win1, win2] = expectedTabURLs.map(url => getWindowByTabUrl(url)); + } + + let actualTabURLs = Array.from(BrowserWindowTracker.orderedWindows).map(win => + getWindowUrl(win) + ); + Assert.deepEqual( + actualTabURLs, + expectedTabURLs, + "Both windows are open with selected tab URLs in the expected order" + ); + + let lastSeenTimes = [win1, win2].map( + win => win.gBrowser.selectedTab.lastSeenActive + ); + + info("Focusing the other window"); + await switchToWindow(win2); + // wait a little so the timestamps will differ and then check again + // eslint-disable-next-line mozilla/no-arbitrary-setTimeout + await new Promise(res => setTimeout(res, 100)); + Assert.greater( + win2.gBrowser.selectedTab.lastSeenActive, + lastSeenTimes[1], + "The foreground window selected tab is last seen more recently than it was before being focused" + ); + Assert.greater( + win2.gBrowser.selectedTab.lastSeenActive, + win1.gBrowser.selectedTab.lastSeenActive, + "The foreground window selected tab is last seen more recently than the backgrounded one" + ); + + lastSeenTimes = [win1, win2].map( + win => win.gBrowser.selectedTab.lastSeenActive + ); + // minimize the foreground window and focus the other + let promiseSizeModeChange = BrowserTestUtils.waitForEvent( + win2, + "sizemodechange" + ); + win2.minimize(); + info("Waiting for the sizemodechange on minimized window"); + await promiseSizeModeChange; + await switchToWindow(win1); + + ok( + !win2.gBrowser.selectedTab.linkedBrowser.docShellIsActive, + "Docshell should be Inactive" + ); + ok(win2.document.hidden, "Minimized windows's document should be hidden"); + + // wait a little so the timestamps will differ and then check again + // eslint-disable-next-line mozilla/no-arbitrary-setTimeout + await new Promise(res => setTimeout(res, 100)); + Assert.greater( + win1.gBrowser.selectedTab.lastSeenActive, + win2.gBrowser.selectedTab.lastSeenActive, + "The foreground window selected tab is last seen more recently than the minimized one" + ); + Assert.greater( + win1.gBrowser.selectedTab.lastSeenActive, + lastSeenTimes[0], + "The foreground window selected tab is last seen more recently than it was before being focused" + ); + + await cleanup(); +}); diff --git a/browser/base/content/test/tabs/browser_lazy_tab_browser_events.js b/browser/base/content/test/tabs/browser_lazy_tab_browser_events.js index 665bdb7f69..5e09225cde 100644 --- a/browser/base/content/test/tabs/browser_lazy_tab_browser_events.js +++ b/browser/base/content/test/tabs/browser_lazy_tab_browser_events.js @@ -93,10 +93,10 @@ add_task(async function test_hidden_muted_lazy_tabs_and_swapping() { mutedTab.toggleMuteAudio(); gBrowser.hideTab(hiddenTab); - is(lazyTab.linkedPanel, "", "lazyTab is lazy"); - is(hiddenTab.linkedPanel, "", "hiddenTab is lazy"); - is(mutedTab.linkedPanel, "", "mutedTab is lazy"); - is(normalTab.linkedPanel, "", "normalTab is lazy"); + is(lazyTab.linkedPanel, null, "lazyTab is lazy"); + is(hiddenTab.linkedPanel, null, "hiddenTab is lazy"); + is(mutedTab.linkedPanel, null, "mutedTab is lazy"); + is(normalTab.linkedPanel, null, "normalTab is lazy"); ok(mutedTab.linkedBrowser.audioMuted, "mutedTab is muted"); ok(hiddenTab.hidden, "hiddenTab is hidden"); @@ -117,7 +117,7 @@ add_task(async function test_hidden_muted_lazy_tabs_and_swapping() { }); gBrowser.swapBrowsersAndCloseOther(lazyTab, mutedTab); tabEventTracker.checkExpectations(); - is(lazyTab.linkedPanel, "", "muted lazyTab is still lazy"); + is(lazyTab.linkedPanel, null, "muted lazyTab is still lazy"); ok(lazyTab.linkedBrowser.audioMuted, "muted lazyTab is now muted"); ok(!lazyTab.hidden, "muted lazyTab is not hidden"); @@ -133,7 +133,7 @@ add_task(async function test_hidden_muted_lazy_tabs_and_swapping() { }); gBrowser.swapBrowsersAndCloseOther(lazyTab, hiddenTab); tabEventTracker.checkExpectations(); - is(lazyTab.linkedPanel, "", "hidden lazyTab is still lazy"); + is(lazyTab.linkedPanel, null, "hidden lazyTab is still lazy"); ok(!lazyTab.linkedBrowser.audioMuted, "hidden lazyTab is not muted any more"); ok(lazyTab.hidden, "hidden lazyTab has been hidden"); @@ -149,7 +149,7 @@ add_task(async function test_hidden_muted_lazy_tabs_and_swapping() { }); gBrowser.swapBrowsersAndCloseOther(lazyTab, normalTab); tabEventTracker.checkExpectations(); - is(lazyTab.linkedPanel, "", "normal lazyTab is still lazy"); + is(lazyTab.linkedPanel, null, "normal lazyTab is still lazy"); ok(!lazyTab.linkedBrowser.audioMuted, "normal lazyTab is not muted any more"); ok(!lazyTab.hidden, "normal lazyTab is not hidden any more"); diff --git a/browser/base/content/test/tabs/browser_link_in_tab_title_and_url_prefilled_normal_page_blank_target.js b/browser/base/content/test/tabs/browser_link_in_tab_title_and_url_prefilled_normal_page_blank_target.js index f8773e3720..9212667a35 100644 --- a/browser/base/content/test/tabs/browser_link_in_tab_title_and_url_prefilled_normal_page_blank_target.js +++ b/browser/base/content/test/tabs/browser_link_in_tab_title_and_url_prefilled_normal_page_blank_target.js @@ -66,7 +66,7 @@ add_task(async function normal_page__foreground__abort() { tab: WAIT_A_BIT_LOADING_TITLE, urlbar: UrlbarTestUtils.trimURL(WAIT_A_BIT_URL), }, - async actionWhileLoading(onTabLoaded) { + async actionWhileLoading() { info("Abort loading"); document.getElementById("stop-button").click(); }, @@ -160,7 +160,7 @@ add_task(async function normal_page__background__abort() { tab: WAIT_A_BIT_LOADING_TITLE, urlbar: UrlbarTestUtils.trimURL(HOME_URL), }, - async actionWhileLoading(onTabLoaded) { + async actionWhileLoading() { info("Abort loading"); document.getElementById("stop-button").click(); }, diff --git a/browser/base/content/test/tabs/browser_link_in_tab_title_and_url_prefilled_normal_page_by_script.js b/browser/base/content/test/tabs/browser_link_in_tab_title_and_url_prefilled_normal_page_by_script.js index 07cf7a8ea2..57e28ca834 100644 --- a/browser/base/content/test/tabs/browser_link_in_tab_title_and_url_prefilled_normal_page_by_script.js +++ b/browser/base/content/test/tabs/browser_link_in_tab_title_and_url_prefilled_normal_page_by_script.js @@ -44,7 +44,7 @@ add_task(async function normal_page__by_script__abort() { tab: BLANK_TITLE, urlbar: UrlbarTestUtils.trimURL(BLANK_URL), }, - async actionWhileLoading(onTabLoaded) { + async actionWhileLoading() { info("Abort loading"); document.getElementById("stop-button").click(); }, diff --git a/browser/base/content/test/tabs/browser_link_in_tab_title_and_url_prefilled_normal_page_no_target.js b/browser/base/content/test/tabs/browser_link_in_tab_title_and_url_prefilled_normal_page_no_target.js index ab18d7c7e0..464a7c43de 100644 --- a/browser/base/content/test/tabs/browser_link_in_tab_title_and_url_prefilled_normal_page_no_target.js +++ b/browser/base/content/test/tabs/browser_link_in_tab_title_and_url_prefilled_normal_page_no_target.js @@ -47,7 +47,7 @@ add_task(async function normal_page__no_target__abort() { tab: HOME_TITLE, urlbar: UrlbarTestUtils.trimURL(HOME_URL), }, - async actionWhileLoading(onTabLoaded) { + async actionWhileLoading() { info("Abort loading"); document.getElementById("stop-button").click(); }, diff --git a/browser/base/content/test/tabs/browser_link_in_tab_title_and_url_prefilled_normal_page_other_target.js b/browser/base/content/test/tabs/browser_link_in_tab_title_and_url_prefilled_normal_page_other_target.js index 7dc0e8fa45..53242ca359 100644 --- a/browser/base/content/test/tabs/browser_link_in_tab_title_and_url_prefilled_normal_page_other_target.js +++ b/browser/base/content/test/tabs/browser_link_in_tab_title_and_url_prefilled_normal_page_other_target.js @@ -45,7 +45,7 @@ add_task(async function normal_page__other_target__foreground__abort() { tab: BLANK_TITLE, urlbar: UrlbarTestUtils.trimURL(BLANK_URL), }, - async actionWhileLoading(onTabLoaded) { + async actionWhileLoading() { info("Abort loading"); document.getElementById("stop-button").click(); }, @@ -117,7 +117,7 @@ add_task(async function normal_page__other_target__background__abort() { tab: WAIT_A_BIT_LOADING_TITLE, urlbar: UrlbarTestUtils.trimURL(HOME_URL), }, - async actionWhileLoading(onTabLoaded) { + async actionWhileLoading() { info("Abort loading"); document.getElementById("stop-button").click(); }, diff --git a/browser/base/content/test/tabs/browser_long_data_url_label_truncation.js b/browser/base/content/test/tabs/browser_long_data_url_label_truncation.js index db0571a2c0..89952b6c4d 100644 --- a/browser/base/content/test/tabs/browser_long_data_url_label_truncation.js +++ b/browser/base/content/test/tabs/browser_long_data_url_label_truncation.js @@ -33,7 +33,7 @@ add_task(async function test_ensure_truncation() { let fileReader = new FileReader(); const DATA_URL = await new Promise(resolve => { - fileReader.addEventListener("load", e => resolve(fileReader.result)); + fileReader.addEventListener("load", () => resolve(fileReader.result)); fileReader.readAsDataURL(new Blob([MOBY], { type: "text/html" })); }); // Substring the full URL to avoid log clutter because Assert will print diff --git a/browser/base/content/test/tabs/browser_multiselect_tabs_move_to_new_window_contextmenu.js b/browser/base/content/test/tabs/browser_multiselect_tabs_move_to_new_window_contextmenu.js index d668d21df8..f294769898 100644 --- a/browser/base/content/test/tabs/browser_multiselect_tabs_move_to_new_window_contextmenu.js +++ b/browser/base/content/test/tabs/browser_multiselect_tabs_move_to_new_window_contextmenu.js @@ -61,9 +61,9 @@ add_task(async function testLazyTabs() { await triggerClickOn(oldTabs[i], { ctrlKey: true }); } - isnot(oldTabs[0].linkedPanel, "", `Old tab 0 shouldn't be lazy`); + isnot(oldTabs[0].linkedPanel, null, `Old tab 0 shouldn't be lazy`); for (let i = 1; i < numTabs; ++i) { - is(oldTabs[i].linkedPanel, "", `Old tab ${i} should be lazy`); + is(oldTabs[i].linkedPanel, null, `Old tab ${i} should be lazy`); } is(gBrowser.multiSelectedTabsCount, numTabs, `${numTabs} multiselected tabs`); @@ -79,11 +79,11 @@ add_task(async function testLazyTabs() { if (i == 0) { isnot( oldTab.linkedPanel, - "", + null, `Old tab ${i} should continue not being lazy` ); } else if (i > 0) { - is(oldTab.linkedPanel, "", `Old tab ${i} should continue being lazy`); + is(oldTab.linkedPanel, null, `Old tab ${i} should continue being lazy`); } else { return; } @@ -101,9 +101,13 @@ add_task(async function testLazyTabs() { await tabsMoved; let newTabs = newWindow.gBrowser.tabs; - isnot(newTabs[0].linkedPanel, "", `New tab 0 should continue not being lazy`); + isnot( + newTabs[0].linkedPanel, + null, + `New tab 0 should continue not being lazy` + ); for (let i = 1; i < numTabs; ++i) { - is(newTabs[i].linkedPanel, "", `New tab ${i} should continue being lazy`); + is(newTabs[i].linkedPanel, null, `New tab ${i} should continue being lazy`); } is( diff --git a/browser/base/content/test/tabs/browser_new_tab_bookmarks_toolbar_height.js b/browser/base/content/test/tabs/browser_new_tab_bookmarks_toolbar_height.js index 66258659fd..157254142d 100644 --- a/browser/base/content/test/tabs/browser_new_tab_bookmarks_toolbar_height.js +++ b/browser/base/content/test/tabs/browser_new_tab_bookmarks_toolbar_height.js @@ -12,7 +12,7 @@ async function expectHeightChanges(tab, expectedNewHeightChanges, msg) { let contentObservedHeightChanges = await ContentTask.spawn( tab.linkedBrowser, null, - async args => { + async () => { await new Promise(resolve => content.requestAnimationFrame(resolve)); return content.document.body.innerText; } @@ -109,7 +109,7 @@ add_task(async function () { info("Opening a new tab, making the previous tab non-selected"); await expectBmToolbarVisibilityChange( () => { - BrowserOpenTab(); + BrowserCommands.openTab(); ok( !tab.selected, "non-new tab is in the background (not the selected tab)" diff --git a/browser/base/content/test/tabs/browser_new_tab_in_privilegedabout_process_pref.js b/browser/base/content/test/tabs/browser_new_tab_in_privilegedabout_process_pref.js index ec11951cb0..568510b20a 100644 --- a/browser/base/content/test/tabs/browser_new_tab_in_privilegedabout_process_pref.js +++ b/browser/base/content/test/tabs/browser_new_tab_in_privilegedabout_process_pref.js @@ -159,7 +159,7 @@ add_task(async function process_switching_through_navigation_features() { assertIsPrivilegedProcess(browser, "new tab opened from about:newtab"); // Check that reload does not break the privileged about: content process affinity. - BrowserReload(); + BrowserCommands.reload(); await BrowserTestUtils.browserLoaded(browser, false, ABOUT_NEWTAB); assertIsPrivilegedProcess(browser, "about:newtab after reload"); diff --git a/browser/base/content/test/tabs/browser_new_tab_url.js b/browser/base/content/test/tabs/browser_new_tab_url.js index 233cb4e59e..ab00560929 100644 --- a/browser/base/content/test/tabs/browser_new_tab_url.js +++ b/browser/base/content/test/tabs/browser_new_tab_url.js @@ -3,7 +3,7 @@ "use strict"; add_task(async function test_browser_open_newtab_default_url() { - BrowserOpenTab(); + BrowserCommands.openTab(); const tab = gBrowser.selectedTab; if (tab.linkedBrowser.currentURI.spec !== window.BROWSER_NEW_TAB_URL) { @@ -19,7 +19,7 @@ add_task(async function test_browser_open_newtab_default_url() { add_task(async function test_browser_open_newtab_specific_url() { const url = "https://example.com"; - BrowserOpenTab({ url }); + BrowserCommands.openTab({ url }); const tab = gBrowser.selectedTab; await BrowserTestUtils.browserLoaded(tab.linkedBrowser); diff --git a/browser/base/content/test/tabs/browser_open_newtab_start_observer_notification.js b/browser/base/content/test/tabs/browser_open_newtab_start_observer_notification.js index cb9fc3c6d7..2bc26cf667 100644 --- a/browser/base/content/test/tabs/browser_open_newtab_start_observer_notification.js +++ b/browser/base/content/test/tabs/browser_open_newtab_start_observer_notification.js @@ -9,10 +9,10 @@ add_task(async function test_browser_open_newtab_start_observer_notification() { Services.obs.addObserver(observe, "browser-open-newtab-start"); }); - // We're calling BrowserOpenTab() (rather the using BrowserTestUtils + // We're calling BrowserCommands.openTab() (rather the using BrowserTestUtils // because we want to be sure that it triggers the event to fire, since // it's very close to where various user-actions are triggered. - BrowserOpenTab(); + BrowserCommands.openTab(); const newTabCreatedPromise = await observerFiredPromise; const browser = await newTabCreatedPromise; const tab = gBrowser.selectedTab; diff --git a/browser/base/content/test/tabs/browser_pinnedTabs_closeByKeyboard.js b/browser/base/content/test/tabs/browser_pinnedTabs_closeByKeyboard.js index fbcd0bb492..4631afba42 100644 --- a/browser/base/content/test/tabs/browser_pinnedTabs_closeByKeyboard.js +++ b/browser/base/content/test/tabs/browser_pinnedTabs_closeByKeyboard.js @@ -5,14 +5,14 @@ function test() { waitForExplicitFinish(); - function testState(aPinned) { + function testState() { function elemAttr(id, attr) { return document.getElementById(id).getAttribute(attr); } is( elemAttr("key_close", "disabled"), - "", + null, "key_closed should always be enabled" ); is( diff --git a/browser/base/content/test/tabs/browser_privilegedmozilla_process_pref.js b/browser/base/content/test/tabs/browser_privilegedmozilla_process_pref.js index 9e1c1ff5cd..922f94b07c 100644 --- a/browser/base/content/test/tabs/browser_privilegedmozilla_process_pref.js +++ b/browser/base/content/test/tabs/browser_privilegedmozilla_process_pref.js @@ -140,7 +140,7 @@ add_task(async function process_switching_through_navigation_features() { ); // Check that reload does not break the privileged mozilla content process affinity. - BrowserReload(); + BrowserCommands.reload(); await BrowserTestUtils.browserLoaded(browser, false, TEST_HIGH1); is( browser.frameLoader.remoteTab.osPid, diff --git a/browser/base/content/test/tabs/browser_removeTabs_order.js b/browser/base/content/test/tabs/browser_removeTabs_order.js index 071cc03716..a993415653 100644 --- a/browser/base/content/test/tabs/browser_removeTabs_order.js +++ b/browser/base/content/test/tabs/browser_removeTabs_order.js @@ -16,7 +16,7 @@ add_task(async function () { // Add a beforeunload event listener in one of the tabs; it should be called // before closing any of the tabs. await ContentTask.spawn(tab2.linkedBrowser, null, async function () { - content.window.addEventListener("beforeunload", function (event) {}, true); + content.window.addEventListener("beforeunload", function () {}, true); }); let permitUnloadSpy = sinon.spy(tab2.linkedBrowser, "asyncPermitUnload"); diff --git a/browser/base/content/test/tabs/browser_tab_label_picture_in_picture.js b/browser/base/content/test/tabs/browser_tab_label_picture_in_picture.js index dae4ffc444..59cfd37c0d 100644 --- a/browser/base/content/test/tabs/browser_tab_label_picture_in_picture.js +++ b/browser/base/content/test/tabs/browser_tab_label_picture_in_picture.js @@ -11,7 +11,7 @@ add_task(async function test_pip_label_changes_tab() { let pipLabel = pipTab.querySelector(".tab-icon-sound-pip-label"); - await BrowserTestUtils.withNewTab("about:blank", async browser => { + await BrowserTestUtils.withNewTab("about:blank", async () => { let selectedTab = newWin.document.querySelector( ".tabbrowser-tab[selected]" ); diff --git a/browser/base/content/test/tabs/browser_tab_manager_visibility.js b/browser/base/content/test/tabs/browser_tab_manager_visibility.js index b7de777512..df6e75cd66 100644 --- a/browser/base/content/test/tabs/browser_tab_manager_visibility.js +++ b/browser/base/content/test/tabs/browser_tab_manager_visibility.js @@ -17,7 +17,7 @@ add_task(async function tab_manager_visibility_preference_on() { gBrowser: newWindow.gBrowser, url: TEST_HOSTNAME + DUMMY_PAGE_PATH, }, - async function (browser) { + async function () { await Assert.ok( BrowserTestUtils.isVisible( newWindow.document.getElementById("alltabs-button") @@ -39,7 +39,7 @@ add_task(async function tab_manager_visibility_preference_off() { gBrowser: newWindow.gBrowser, url: TEST_HOSTNAME + DUMMY_PAGE_PATH, }, - async function (browser) { + async function () { await Assert.ok( BrowserTestUtils.isHidden( newWindow.document.getElementById("alltabs-button") diff --git a/browser/base/content/test/tabs/browser_tab_preview.js b/browser/base/content/test/tabs/browser_tab_preview.js index 718afbb940..0f83b1e28c 100644 --- a/browser/base/content/test/tabs/browser_tab_preview.js +++ b/browser/base/content/test/tabs/browser_tab_preview.js @@ -4,14 +4,14 @@ "use strict"; +const { sinon } = ChromeUtils.importESModule( + "resource://testing-common/Sinon.sys.mjs" +); + async function openPreview(tab) { - const previewShown = BrowserTestUtils.waitForEvent( - document.getElementById("tabbrowser-tab-preview"), - "previewshown", - false, - e => { - return e.detail.tab === tab; - } + const previewShown = BrowserTestUtils.waitForPopupEvent( + document.getElementById("tab-preview-panel"), + "shown" ); EventUtils.synthesizeMouseAtCenter(tab, { type: "mouseover" }); return previewShown; @@ -19,9 +19,9 @@ async function openPreview(tab) { async function closePreviews() { const tabs = document.getElementById("tabbrowser-tabs"); - const previewHidden = BrowserTestUtils.waitForEvent( - document.getElementById("tabbrowser-tab-preview"), - "previewhidden" + const previewHidden = BrowserTestUtils.waitForPopupEvent( + document.getElementById("tab-preview-panel"), + "hidden" ); EventUtils.synthesizeMouse(tabs, 0, tabs.outerHeight + 1, { type: "mouseout", @@ -53,35 +53,24 @@ add_task(async function hoverTests() { const tabUrl2 = "data:text/html,<html><head><title>Second New Tab</title></head><body>Hello</body></html>"; const tab2 = await BrowserTestUtils.openNewForegroundTab(gBrowser, tabUrl2); - const previewContainer = document.getElementById("tabbrowser-tab-preview"); + const previewContainer = document.getElementById("tab-preview-panel"); await openPreview(tab1); - Assert.ok( - ["open", "showing"].includes(previewContainer.panel.state), - "tab1 preview shown" - ); Assert.equal( - previewContainer.renderRoot.querySelector(".tab-preview-title").innerText, + previewContainer.querySelector(".tab-preview-title").innerText, "First New Tab", "Preview of tab1 shows correct title" ); + await closePreviews(); await openPreview(tab2); - Assert.ok( - ["open", "showing"].includes(previewContainer.panel.state), - "tab2 preview shown" - ); Assert.equal( - previewContainer.renderRoot.querySelector(".tab-preview-title").innerText, + previewContainer.querySelector(".tab-preview-title").innerText, "Second New Tab", "Preview of tab2 shows correct title" ); await closePreviews(); - Assert.ok( - ["closed", "hiding"].includes(previewContainer.panel.state), - "preview container is now hidden" - ); BrowserTestUtils.removeTab(tab1); BrowserTestUtils.removeTab(tab2); @@ -105,29 +94,41 @@ add_task(async function thumbnailTests() { const tab1 = await BrowserTestUtils.openNewForegroundTab(gBrowser, tabUrl1); const tabUrl2 = "about:blank"; const tab2 = await BrowserTestUtils.openNewForegroundTab(gBrowser, tabUrl2); - const previewContainer = document.getElementById("tabbrowser-tab-preview"); + const previewPanel = document.getElementById("tab-preview-panel"); - const thumbnailUpdated = BrowserTestUtils.waitForEvent( - previewContainer, - "previewThumbnailUpdated" + let thumbnailUpdated = BrowserTestUtils.waitForEvent( + previewPanel, + "previewThumbnailUpdated", + false, + evt => evt.detail.thumbnail ); await openPreview(tab1); await thumbnailUpdated; Assert.ok( - previewContainer.renderRoot.querySelectorAll("img,canvas").length, + previewPanel.querySelectorAll( + ".tab-preview-thumbnail-container img, .tab-preview-thumbnail-container canvas" + ).length, "Tab1 preview contains thumbnail" ); + await closePreviews(); + thumbnailUpdated = BrowserTestUtils.waitForEvent( + previewPanel, + "previewThumbnailUpdated" + ); await openPreview(tab2); + await thumbnailUpdated; Assert.equal( - previewContainer.renderRoot.querySelectorAll("img,canvas").length, + previewPanel.querySelectorAll( + ".tab-preview-thumbnail-container img, .tab-preview-thumbnail-container canvas" + ).length, 0, "Tab2 (selected) does not contain thumbnail" ); - const previewHidden = BrowserTestUtils.waitForEvent( - document.getElementById("tabbrowser-tab-preview"), - "previewhidden" + const previewHidden = BrowserTestUtils.waitForPopupEvent( + previewPanel, + "hidden" ); BrowserTestUtils.removeTab(tab1); @@ -144,6 +145,102 @@ add_task(async function thumbnailTests() { }); /** + * make sure delay is applied when mouse leaves tabstrip + * but not when moving between tabs on the tabstrip + */ +add_task(async function delayTests() { + const tabUrl1 = + "data:text/html,<html><head><title>First New Tab</title></head><body>Hello</body></html>"; + const tab1 = await BrowserTestUtils.openNewForegroundTab(gBrowser, tabUrl1); + const tabUrl2 = + "data:text/html,<html><head><title>Second New Tab</title></head><body>Hello</body></html>"; + const tab2 = await BrowserTestUtils.openNewForegroundTab(gBrowser, tabUrl2); + const previewComponent = gBrowser.tabContainer.previewPanel; + const previewElement = document.getElementById("tab-preview-panel"); + + sinon.spy(previewComponent, "deactivate"); + + await openPreview(tab1); + + // I can't fake this like in hoverTests, need to send an updated-tab signal + //await openPreview(tab2); + + const previewHidden = BrowserTestUtils.waitForPopupEvent( + previewElement, + "hidden" + ); + Assert.ok( + !previewComponent.deactivate.called, + "Delay is not reset when moving between tabs" + ); + + EventUtils.synthesizeMouseAtCenter(document.getElementById("reload-button"), { + type: "mousemove", + }); + + await previewHidden; + + Assert.ok( + previewComponent.deactivate.called, + "Delay is reset when cursor leaves tabstrip" + ); + + BrowserTestUtils.removeTab(tab1); + BrowserTestUtils.removeTab(tab2); + sinon.restore(); +}); + +/** + * Dragging a tab should deactivate the preview + */ +add_task(async function dragTests() { + await SpecialPowers.pushPrefEnv({ + set: [["ui.tooltip.delay_ms", 1000]], + }); + const tabUrl1 = + "data:text/html,<html><head><title>First New Tab</title></head><body>Hello</body></html>"; + const tab1 = await BrowserTestUtils.openNewForegroundTab(gBrowser, tabUrl1); + const tabUrl2 = + "data:text/html,<html><head><title>Second New Tab</title></head><body>Hello</body></html>"; + const tab2 = await BrowserTestUtils.openNewForegroundTab(gBrowser, tabUrl2); + const previewComponent = gBrowser.tabContainer.previewPanel; + const previewElement = document.getElementById("tab-preview-panel"); + + sinon.spy(previewComponent, "deactivate"); + + await openPreview(tab1); + const previewHidden = BrowserTestUtils.waitForPopupEvent( + previewElement, + "hidden" + ); + let dragend = BrowserTestUtils.waitForEvent(tab1, "dragend"); + EventUtils.synthesizePlainDragAndDrop({ + srcElement: tab1, + destElement: tab2, + }); + + await previewHidden; + + Assert.ok( + previewComponent.deactivate.called, + "delay is reset after drag started" + ); + + await dragend; + + BrowserTestUtils.removeTab(tab1); + BrowserTestUtils.removeTab(tab2); + sinon.restore(); + + // Move the mouse outside of the tab strip. + EventUtils.synthesizeMouseAtCenter(document.documentElement, { + type: "mouseover", + }); + + await SpecialPowers.popPrefEnv(); +}); + +/** * Wheel events at the document-level of the window should hide the preview. */ add_task(async function wheelTests() { @@ -155,9 +252,9 @@ add_task(async function wheelTests() { await openPreview(tab1); const tabs = document.getElementById("tabbrowser-tabs"); - const previewHidden = BrowserTestUtils.waitForEvent( - document.getElementById("tabbrowser-tab-preview"), - "previewhidden" + const previewHidden = BrowserTestUtils.waitForPopupEvent( + document.getElementById("tab-preview-panel"), + "hidden" ); // Copied from apz_test_native_event_utils.js diff --git a/browser/base/content/test/tabs/browser_tab_tooltips.js b/browser/base/content/test/tabs/browser_tab_tooltips.js index ee82816bce..79be4d0a36 100644 --- a/browser/base/content/test/tabs/browser_tab_tooltips.js +++ b/browser/base/content/test/tabs/browser_tab_tooltips.js @@ -57,7 +57,7 @@ add_task(async function () { ); is( tooltip.getAttribute("position"), - "", + null, "tooltip position attribute for tab" ); diff --git a/browser/base/content/test/tabs/browser_tabswitch_select.js b/browser/base/content/test/tabs/browser_tabswitch_select.js index 3868764bed..b22a75c79c 100644 --- a/browser/base/content/test/tabs/browser_tabswitch_select.js +++ b/browser/base/content/test/tabs/browser_tabswitch_select.js @@ -35,7 +35,7 @@ add_task(async function () { let fullScreenEntered = TestUtils.waitForCondition( () => document.documentElement.getAttribute("sizemode") == "fullscreen" ); - BrowserFullScreen(); + BrowserCommands.fullScreen(); await fullScreenEntered; tab2.linkedBrowser.focus(); @@ -54,7 +54,7 @@ add_task(async function () { let fullScreenExited = TestUtils.waitForCondition( () => document.documentElement.getAttribute("sizemode") != "fullscreen" ); - BrowserFullScreen(); + BrowserCommands.fullScreen(); await fullScreenExited; BrowserTestUtils.removeTab(gBrowser.selectedTab); diff --git a/browser/base/content/test/tabs/browser_tabswitch_updatecommands.js b/browser/base/content/test/tabs/browser_tabswitch_updatecommands.js index b5d2762eec..82f9eb871b 100644 --- a/browser/base/content/test/tabs/browser_tabswitch_updatecommands.js +++ b/browser/base/content/test/tabs/browser_tabswitch_updatecommands.js @@ -8,7 +8,7 @@ add_task(async function () { let tab2 = await BrowserTestUtils.openNewForegroundTab(gBrowser, uri); let updates = []; - function countUpdates(event) { + function countUpdates() { updates.push(new Error().stack); } let updater = document.getElementById("editMenuCommandSetAll"); diff --git a/browser/base/content/test/tabs/browser_viewsource_of_data_URI_in_file_process.js b/browser/base/content/test/tabs/browser_viewsource_of_data_URI_in_file_process.js index b5ae94ce84..2c301a400d 100644 --- a/browser/base/content/test/tabs/browser_viewsource_of_data_URI_in_file_process.js +++ b/browser/base/content/test/tabs/browser_viewsource_of_data_URI_in_file_process.js @@ -33,7 +33,7 @@ add_task(async function () { // Make sure we can view-source on the data URI page. let promiseTab = BrowserTestUtils.waitForNewTab(gBrowser, DATA_URI_SOURCE); - BrowserViewSource(fileBrowser); + BrowserCommands.viewSource(fileBrowser); let viewSourceTab = await promiseTab; registerCleanupFunction(async function () { BrowserTestUtils.removeTab(viewSourceTab); diff --git a/browser/base/content/test/tabs/browser_window_open_modifiers.js b/browser/base/content/test/tabs/browser_window_open_modifiers.js index b4376d6824..2ef951efef 100644 --- a/browser/base/content/test/tabs/browser_window_open_modifiers.js +++ b/browser/base/content/test/tabs/browser_window_open_modifiers.js @@ -97,7 +97,7 @@ add_task(async function () { BrowserTestUtils.synthesizeMouseAtCenter(id, { ...event }, browser); } else { // Make sure the keyboard activates a simple button on the page. - await ContentTask.spawn(browser, id, elementId => { + await ContentTask.spawn(browser, id, () => { content.document.querySelector("#focus-result").value = ""; content.document.querySelector("#focus-check").focus(); }); diff --git a/browser/base/content/test/tabs/common_link_in_tab_title_and_url_prefilled.js b/browser/base/content/test/tabs/common_link_in_tab_title_and_url_prefilled.js index a06b982615..bff14e5ced 100644 --- a/browser/base/content/test/tabs/common_link_in_tab_title_and_url_prefilled.js +++ b/browser/base/content/test/tabs/common_link_in_tab_title_and_url_prefilled.js @@ -244,7 +244,7 @@ async function synthesizeMouse(browser, link, event) { async function waitForNewTabWithLoadRequest() { return new Promise(resolve => gBrowser.addTabsProgressListener({ - onStateChange(aBrowser, aWebProgress, aRequest, aStateFlags, aStatus) { + onStateChange(aBrowser, aWebProgress, aRequest, aStateFlags) { if (aStateFlags & Ci.nsIWebProgressListener.STATE_START) { gBrowser.removeTabsProgressListener(this); resolve(gBrowser.getTabForBrowser(aBrowser)); |