From 5a59eb69024fdc446d8b72c175ee775c9d047706 Mon Sep 17 00:00:00 2001 From: "Mr. M" Date: Sat, 10 May 2025 14:15:00 +0200 Subject: [PATCH] test: Added some tests, b=(no-bug), c=tests, workspaces --- .gitattributes | 2 + src/testing/mochitest/browser-test-js.patch | 16 ++++++- src/zen/moz.build | 8 +--- src/zen/tests/.prettierignore | 1 + src/zen/tests/browser.toml | 2 - .../tests/container_essentials/browser.toml | 4 ++ .../browser_container_specific_essentials.js | 8 ++-- src/zen/tests/moz.build | 6 +++ src/zen/tests/run.sh | 9 ++-- src/zen/tests/urlbar/browser.toml | 7 +++ .../tests/urlbar/browser_floating_urlbar.js | 48 +++++++++++++++++++ src/zen/tests/urlbar/head.js | 11 +++++ src/zen/tests/workspaces/browser.toml | 1 + .../workspaces/browser_basic_workspaces.js | 1 - src/zen/workspaces/ZenWorkspaces.mjs | 4 +- 15 files changed, 109 insertions(+), 19 deletions(-) create mode 100644 src/zen/tests/.prettierignore delete mode 100644 src/zen/tests/browser.toml create mode 100644 src/zen/tests/container_essentials/browser.toml rename src/zen/tests/{workspaces => container_essentials}/browser_container_specific_essentials.js (88%) create mode 100644 src/zen/tests/moz.build create mode 100644 src/zen/tests/urlbar/browser.toml create mode 100644 src/zen/tests/urlbar/browser_floating_urlbar.js create mode 100644 src/zen/tests/urlbar/head.js create mode 100644 src/zen/tests/workspaces/browser.toml diff --git a/.gitattributes b/.gitattributes index 9ef01c1e..018acd5f 100644 --- a/.gitattributes +++ b/.gitattributes @@ -1,2 +1,4 @@ *.patch linguist-language=C++ *.d.ts linguist-language=TypeScript + +src/zen/tests/*.js linguist-language=Test diff --git a/src/testing/mochitest/browser-test-js.patch b/src/testing/mochitest/browser-test-js.patch index 8efd16bd..b58503ab 100644 --- a/src/testing/mochitest/browser-test-js.patch +++ b/src/testing/mochitest/browser-test-js.patch @@ -1,7 +1,21 @@ diff --git a/testing/mochitest/browser-test.js b/testing/mochitest/browser-test.js -index ef29179988bb37e7ea441aa051b692e3ccc90f21..7eade843ad62e47f90dc06a4a1fb88b6d1c1a583 100644 +index ef29179988bb37e7ea441aa051b692e3ccc90f21..6c9641ed27722b5febd83f6e121df24d46b00067 100644 --- a/testing/mochitest/browser-test.js +++ b/testing/mochitest/browser-test.js +@@ -444,11 +444,11 @@ Tester.prototype = { + this.currentTest && + window.gBrowser && + AppConstants.MOZ_APP_NAME != "thunderbird" && +- gBrowser.tabs.length > 1 ++ gBrowser.tabs.length > 2 + ) { + let lastURI = ""; + let lastURIcount = 0; +- while (gBrowser.tabs.length > 1) { ++ while (gBrowser.tabs.length > 2) { + let lastTab = gBrowser.tabs[gBrowser.tabs.length - 1]; + if (!lastTab.closing) { + // Report the stale tab as an error only when they're not closing. @@ -483,12 +483,12 @@ Tester.prototype = { // Replace the last tab with a fresh one diff --git a/src/zen/moz.build b/src/zen/moz.build index aea9a225..005bafec 100644 --- a/src/zen/moz.build +++ b/src/zen/moz.build @@ -3,12 +3,8 @@ # 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/. - -BROWSER_CHROME_MANIFESTS += [ - "tests/browser.toml", -] - DIRS += [ "glance", - "mods" + "mods", + "tests", ] diff --git a/src/zen/tests/.prettierignore b/src/zen/tests/.prettierignore new file mode 100644 index 00000000..245773fb --- /dev/null +++ b/src/zen/tests/.prettierignore @@ -0,0 +1 @@ +run.sh diff --git a/src/zen/tests/browser.toml b/src/zen/tests/browser.toml deleted file mode 100644 index f3e7691d..00000000 --- a/src/zen/tests/browser.toml +++ /dev/null @@ -1,2 +0,0 @@ -["workspaces/browser_basic_workspaces.js"] -["workspaces/browser_container_specific_essentials.js"] diff --git a/src/zen/tests/container_essentials/browser.toml b/src/zen/tests/container_essentials/browser.toml new file mode 100644 index 00000000..f56bb5cd --- /dev/null +++ b/src/zen/tests/container_essentials/browser.toml @@ -0,0 +1,4 @@ +[DEFAULT] +prefs = ["zen.workspaces.container-specific-essentials-enabled=true"] + +["browser_container_specific_essentials.js"] diff --git a/src/zen/tests/workspaces/browser_container_specific_essentials.js b/src/zen/tests/container_essentials/browser_container_specific_essentials.js similarity index 88% rename from src/zen/tests/workspaces/browser_container_specific_essentials.js rename to src/zen/tests/container_essentials/browser_container_specific_essentials.js index 00dbc9d9..f4a39dc6 100644 --- a/src/zen/tests/workspaces/browser_container_specific_essentials.js +++ b/src/zen/tests/container_essentials/browser_container_specific_essentials.js @@ -3,10 +3,6 @@ 'use strict'; -add_setup(async function () { - ZenWorkspaces.containerSpecificEssentials = true; -}); - add_task(async function test_Check_Creation() { await ZenWorkspaces.createAndSaveWorkspace('Container Profile 1', undefined, false, 1); const workspaces = await ZenWorkspaces._workspaces(); @@ -18,6 +14,10 @@ add_task(async function test_Check_Creation() { }); ok(newTab, 'New tab should be opened.'); gZenPinnedTabManager.addToEssentials(newTab); + ok( + newTab.hasAttribute('zen-essential') && newTab.parentNode.getAttribute('container') == '1', + 'New tab should be marked as essential.' + ); ok( gBrowser.tabs.find((t) => t.hasAttribute('zen-essential') && t.getAttribute('usercontextid') == 1), 'New tab should be marked as essential.' diff --git a/src/zen/tests/moz.build b/src/zen/tests/moz.build new file mode 100644 index 00000000..4bafc23c --- /dev/null +++ b/src/zen/tests/moz.build @@ -0,0 +1,6 @@ + +BROWSER_CHROME_MANIFESTS += [ + "container_essentials/browser.toml", + "urlbar/browser.toml", + "workspaces/browser.toml", +] diff --git a/src/zen/tests/run.sh b/src/zen/tests/run.sh index 37bfafaf..70198493 100644 --- a/src/zen/tests/run.sh +++ b/src/zen/tests/run.sh @@ -1,13 +1,16 @@ #!/bin/bash +set -e + # make sure we are on root if [ ! -f "package.json" ]; then echo "Please run this script from the root of the project" exit 1 fi -#npm run build:ui - cd ./engine -./mach mochitest zen/tests/ $@ +./mach mochitest $@ \ + zen/tests/workspaces \ + zen/tests/container_essentials \ + zen/tests/urlbar cd .. diff --git a/src/zen/tests/urlbar/browser.toml b/src/zen/tests/urlbar/browser.toml new file mode 100644 index 00000000..5038b3e4 --- /dev/null +++ b/src/zen/tests/urlbar/browser.toml @@ -0,0 +1,7 @@ +[DEFAULT] +support-files = [ + "head.js", + "!/browser/components/urlbar/tests/browser/head.js", +] + +["browser_floating_urlbar.js"] diff --git a/src/zen/tests/urlbar/browser_floating_urlbar.js b/src/zen/tests/urlbar/browser_floating_urlbar.js new file mode 100644 index 00000000..433e4746 --- /dev/null +++ b/src/zen/tests/urlbar/browser_floating_urlbar.js @@ -0,0 +1,48 @@ +/* Any copyright is dedicated to the Public Domain. + https://creativecommons.org/publicdomain/zero/1.0/ */ + +'use strict'; + +ChromeUtils.defineESModuleGetters(this, { + UrlbarTestUtils: 'resource://testing-common/UrlbarTestUtils.sys.mjs', +}); + +add_task(async function test_Floating_Urlbar() { + gURLBar.blur(); + + await SimpleTest.promiseFocus(window); + document.getElementById('Browser:OpenLocation').doCommand(); + await UrlbarTestUtils.promiseAutocompleteResultPopup({ + window, + waitForFocus: SimpleTest.waitForFocus, + value: 'http://example.com/', + }); + + ok(gURLBar.textbox.hasAttribute('zen-floating-urlbar'), 'URL bar should be in floating mode'); +}); + +add_task(async function test_Click_Shoudnt_FLoat_Urlbar() { + gURLBar.blur(); + + await simulateClick(window); + + await UrlbarTestUtils.promiseAutocompleteResultPopup({ + window, + waitForFocus: SimpleTest.waitForFocus, + value: 'http://example.com/', + }); + + ok(!gURLBar.textbox.hasAttribute('zen-floating-urlbar'), 'URL bar should not be in floating mode'); +}); + +add_task(async function test_Floating_Highlight_Everything() { + gURLBar.blur(); + + await SimpleTest.promiseFocus(window); + await selectWithMouseDrag(2, 5); + document.getElementById('Browser:OpenLocation').doCommand(); + + // Selection range + ok(gURLBar.selectionStart == 0, 'Selection start should be 0'); + ok(gURLBar.selectionEnd == gURLBar.value.length, 'Selection end should be the length of the value'); +}); diff --git a/src/zen/tests/urlbar/head.js b/src/zen/tests/urlbar/head.js new file mode 100644 index 00000000..d0e0460c --- /dev/null +++ b/src/zen/tests/urlbar/head.js @@ -0,0 +1,11 @@ +/* Any copyright is dedicated to the Public Domain. + https://creativecommons.org/publicdomain/zero/1.0/ */ + +'use strict'; + +function simulateClick(win = window) { + let target = win.gURLBar.inputField; + let promise = BrowserTestUtils.waitForEvent(target, 'click'); + EventUtils.synthesizeMouseAtCenter(target, {}); + return promise; +} diff --git a/src/zen/tests/workspaces/browser.toml b/src/zen/tests/workspaces/browser.toml new file mode 100644 index 00000000..fd8b883c --- /dev/null +++ b/src/zen/tests/workspaces/browser.toml @@ -0,0 +1 @@ +["browser_basic_workspaces.js"] diff --git a/src/zen/tests/workspaces/browser_basic_workspaces.js b/src/zen/tests/workspaces/browser_basic_workspaces.js index 94ced75a..87f882fb 100644 --- a/src/zen/tests/workspaces/browser_basic_workspaces.js +++ b/src/zen/tests/workspaces/browser_basic_workspaces.js @@ -24,5 +24,4 @@ add_task(async function test_Check_Creation() { ok(workspacesAfterRemove.workspaces.length === 1, 'One workspace should exist.'); ok(workspacesAfterRemove.workspaces[0].uuid === currentWorkspaceUUID, 'The workspace should be the one we started with.'); ok(gBrowser.tabs.length === 2, 'There should be one tab.'); - BrowserTestUtils.removeTab(gBrowser.selectedTab); }); diff --git a/src/zen/workspaces/ZenWorkspaces.mjs b/src/zen/workspaces/ZenWorkspaces.mjs index 9474f6d7..d6665d05 100644 --- a/src/zen/workspaces/ZenWorkspaces.mjs +++ b/src/zen/workspaces/ZenWorkspaces.mjs @@ -825,9 +825,9 @@ var ZenWorkspaces = new (class extends ZenMultiWindowFeature { delete this._initialTab; } if (this._tabToRemoveForEmpty) { - if (typeof this._tabToSelect === 'number' && this._tabToSelect >= 0) { + const tabs = gBrowser.tabs.filter((tab) => !tab.collapsed && !tab.hasAttribute('zen-empty-tab')); + if (typeof this._tabToSelect === 'number' && this._tabToSelect >= 0 && tabs[this._tabToSelect]) { setTimeout(() => { - const tabs = gBrowser.tabs.filter((tab) => !tab.collapsed && !tab.hasAttribute('zen-empty-tab')); this.log(`Found tab to select: ${this._tabToSelect}, ${tabs.length}`); gBrowser.selectedTab = tabs[this._tabToSelect]; this._removedByStartupPage = true;