diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-07 17:32:43 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-07 17:32:43 +0000 |
commit | 6bf0a5cb5034a7e684dcc3500e841785237ce2dd (patch) | |
tree | a68f146d7fa01f0134297619fbe7e33db084e0aa /browser/base/content/test/tabs/browser_relatedTabs_reset.js | |
parent | Initial commit. (diff) | |
download | thunderbird-6bf0a5cb5034a7e684dcc3500e841785237ce2dd.tar.xz thunderbird-6bf0a5cb5034a7e684dcc3500e841785237ce2dd.zip |
Adding upstream version 1:115.7.0.upstream/1%115.7.0upstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'browser/base/content/test/tabs/browser_relatedTabs_reset.js')
-rw-r--r-- | browser/base/content/test/tabs/browser_relatedTabs_reset.js | 81 |
1 files changed, 81 insertions, 0 deletions
diff --git a/browser/base/content/test/tabs/browser_relatedTabs_reset.js b/browser/base/content/test/tabs/browser_relatedTabs_reset.js new file mode 100644 index 0000000000..531a9e723d --- /dev/null +++ b/browser/base/content/test/tabs/browser_relatedTabs_reset.js @@ -0,0 +1,81 @@ +/* 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/. */ + +add_task(async function () { + is(gBrowser.tabs.length, 1, "one tab is open initially"); + + const TestPage = + "http://mochi.test:8888/browser/browser/base/content/test/general/dummy_page.html"; + + // Add several new tabs in sequence + let tabs = []; + let ReferrerInfo = Components.Constructor( + "@mozilla.org/referrer-info;1", + "nsIReferrerInfo", + "init" + ); + + function getPrincipal(url, attrs) { + let uri = Services.io.newURI(url); + if (!attrs) { + attrs = {}; + } + return Services.scriptSecurityManager.createContentPrincipal(uri, attrs); + } + + function addTab(aURL, aReferrer) { + let referrerInfo = new ReferrerInfo( + Ci.nsIReferrerInfo.EMPTY, + true, + aReferrer + ); + let triggeringPrincipal = getPrincipal(aURL); + let tab = BrowserTestUtils.addTab(gBrowser, aURL, { + referrerInfo, + triggeringPrincipal, + }); + tabs.push(tab); + return BrowserTestUtils.browserLoaded(tab.linkedBrowser); + } + + function loadTab(tab, url) { + let loaded = BrowserTestUtils.browserLoaded(tab.linkedBrowser); + info("Loading page: " + url); + BrowserTestUtils.loadURIString(tab.linkedBrowser, url); + return loaded; + } + + function testPosition(tabNum, expectedPosition, msg) { + is( + Array.prototype.indexOf.call(gBrowser.tabs, tabs[tabNum]), + expectedPosition, + msg + ); + } + + // Initial selected tab + await addTab("http://mochi.test:8888/#0"); + testPosition(0, 1, "Initial tab opened in position 1"); + gBrowser.selectedTab = tabs[0]; + + // Related tabs + await addTab("http://mochi.test:8888/#1", gBrowser.currentURI); + testPosition(1, 2, "Related tab was opened to the far right"); + + await addTab("http://mochi.test:8888/#2", gBrowser.currentURI); + testPosition(2, 3, "Related tab was opened to the far right"); + + // Load a new page + await loadTab(tabs[0], TestPage); + + // Add a new related tab after the page load + await addTab("http://mochi.test:8888/#3", gBrowser.currentURI); + testPosition( + 3, + 2, + "Tab opened to the right of initial tab after system navigation" + ); + + tabs.forEach(gBrowser.removeTab, gBrowser); +}); |