Bug 1362034 - Tests for addTab() to provide the correct triggering principal. r=ckerschb,Gijs

Summary: Depends on D2046

Reviewers: ckerschb, Gijs

Reviewed By: ckerschb, Gijs

Bug #: 1362034

Differential Revision: https://phabricator.services.mozilla.com/D2047

--HG--
extra : rebase_source : 4bb9e7feb0704239756e6e38623c0fea81669f7b
extra : amend_source : 9417f96547735fbdc55ea23666327a5cb86ac92f
This commit is contained in:
Jonathan Kingston 2018-08-06 19:56:37 +03:00
Родитель 9be2ebdb53
Коммит 4ca581ffed
75 изменённых файлов: 184 добавлений и 151 удалений

Просмотреть файл

@ -32,7 +32,7 @@
this.invoke = function addTab_invoke()
{
tabBrowser().addTab(aURL);
tabBrowser().addTrustedTab(aURL);
}
this.getID = function addTab_getID()

Просмотреть файл

@ -45,7 +45,7 @@ add_task(async function closeWindowWithMultipleTabsIncludingOneBeforeUnload() {
let newWin = await promiseOpenAndLoadWindow({}, true);
let firstTab = newWin.gBrowser.selectedTab;
await promiseTabLoadEvent(firstTab, TEST_PAGE);
await promiseTabLoadEvent(newWin.gBrowser.addTab(), "http://example.com/");
await promiseTabLoadEvent(BrowserTestUtils.addTab(newWin.gBrowser), "http://example.com/");
let windowClosedPromise = BrowserTestUtils.domWindowClosed(newWin);
expectingDialog = true;
newWin.BrowserTryToCloseWindow();

Просмотреть файл

@ -20,7 +20,7 @@ add_task(async function() {
let tab = win.gBrowser.tabContainer.firstChild;
await promiseTabLoadEvent(tab, getRootDirectory(gTestPath) + "test_bug462673.html");
var newTab = win.gBrowser.addTab();
var newTab = BrowserTestUtils.addTab(win.gBrowser);
var newBrowser = newTab.linkedBrowser;
win.gBrowser.removeTab(tab);
ok(!win.closed, "Window stays open");

Просмотреть файл

@ -10,7 +10,7 @@
add_task(async function test() {
let win = await BrowserTestUtils.openNewBrowserWindow({private: true});
let tab = win.gBrowser.selectedTab = win.gBrowser.addTab("about:addons");
let tab = win.gBrowser.selectedTab = BrowserTestUtils.addTab(win.gBrowser, "about:addons");
await BrowserTestUtils.browserLoaded(tab.linkedBrowser);
await promiseWaitForFocus(win);

Просмотреть файл

@ -17,7 +17,7 @@ add_task(async function() {
ok(true, "tests succeeded");
// Create a second tab so that we can move the original one out.
win.gBrowser.addTab("about:blank", {skipAnimation: true});
BrowserTestUtils.addTab(win.gBrowser, "about:blank", {skipAnimation: true});
// Tear off the original tab.
let browser = win.gBrowser.selectedBrowser;

Просмотреть файл

@ -97,7 +97,7 @@ add_task(async function testExceptionAddition() {
testTrackingPageUnblocked();
info("Test that the exception is remembered across tabs in the same private window");
tab = browser.selectedTab = browser.addTab();
tab = browser.selectedTab = BrowserTestUtils.addTab(browser);
info("Load a test page containing tracking elements");
await promiseTabLoadEvent(tab, TRACKING_PAGE);

Просмотреть файл

@ -90,7 +90,7 @@ function test_getBoolPref() {
}
function test_openNewTabWith() {
openNewTabWith("http://example.com/");
openNewTabWith("http://example.com/", null, {triggeringPrincipal: Services.scriptSecurityManager.createNullPrincipal({})});
let tab = gBrowser.selectedTab = gBrowser.tabs[1];
BrowserTestUtils.browserLoaded(tab.linkedBrowser).then(() => {
is(tab.linkedBrowser.currentURI.spec, "http://example.com/", "example.com loaded");

Просмотреть файл

@ -32,7 +32,7 @@ add_task(async function multiple_tabs() {
// Add a background tab to cause another page to load *without* putting the
// desired URL in a background tab, which results in its timers being throttled.
gBrowser.addTab();
BrowserTestUtils.addTab(gBrowser);
// Wait until places has stored the page info
const pageInfo = await waitForPageInfo(TEST_PATH);

Просмотреть файл

@ -303,7 +303,10 @@ async function createTabs(howMany) {
uris.push("about:blank");
}
gBrowser.loadTabs(uris, { inBackground: true });
gBrowser.loadTabs(uris, {
inBackground: true,
triggeringPrincipal: Services.scriptSecurityManager.getSystemPrincipal(),
});
await BrowserTestUtils.waitForCondition(() => {
return Array.from(gBrowser.tabs).every(tab => tab._fullyOpen);

Просмотреть файл

@ -210,7 +210,7 @@ function referrerTestCaseLoaded(aTestNumber, aParams) {
"&cross=" + escape(test.cross || "");
let browser = gTestWindow.gBrowser;
return BrowserTestUtils.openNewForegroundTab(browser, () => {
browser.selectedTab = browser.addTab(url, aParams);
browser.selectedTab = BrowserTestUtils.addTab(browser, url, aParams);
}, false, true);
}

Просмотреть файл

@ -154,7 +154,10 @@ async function doTest(aInsertRelatedAfterCurrent, aInsertAfterCurrent) {
// loadTabs will insertAfterCurrent
let nextTab = aInsertAfterCurrent ? gBrowser.selectedTab._tPos + 1 : gBrowser.tabs.length;
gBrowser.loadTabs(bulkLoad, { inBackground: true });
gBrowser.loadTabs(bulkLoad, {
inBackground: true,
triggeringPrincipal: Services.scriptSecurityManager.getSystemPrincipal(),
});
await loadPromises;
for (let i = nextTab, j = 0; j < bulkLoad.length; i++, j++) {
is(gBrowser.tabs[i].linkedBrowser.currentURI.spec, bulkLoad[j], `bulkLoad tab pos ${i} matched`);

Просмотреть файл

@ -21,7 +21,7 @@ function test() {
testState(false);
let pinnedTab = gBrowser.addTab();
let pinnedTab = BrowserTestUtils.addTab(gBrowser);
gBrowser.pinTab(pinnedTab);
// Just pinning the tab shouldn't change the key state.
@ -45,7 +45,7 @@ function test() {
testState(true);
// Test that accel+w in a pinned tab selects the next tab.
let pinnedTab2 = gBrowser.addTab();
let pinnedTab2 = BrowserTestUtils.addTab(gBrowser);
gBrowser.pinTab(pinnedTab2);
gBrowser.selectedTab = pinnedTab;

Просмотреть файл

@ -4,8 +4,10 @@
var tabs = [];
function addTab(aURL) {
tabs.push(gBrowser.addTab(aURL, {skipAnimation: true}));
function addTab(aURL, done) {
tabs.push(BrowserTestUtils.addTab(gBrowser, aURL, {
skipAnimation: true,
}, done));
}
function switchTab(index) {
@ -20,10 +22,13 @@ function testAttrib(tabIndex, attrib, expected) {
add_task(async function setup() {
is(gBrowser.tabs.length, 1, "one tab is open initially");
addTab("http://mochi.test:8888/#0");
addTab("http://mochi.test:8888/#1");
addTab("http://mochi.test:8888/#2");
addTab("http://mochi.test:8888/#3");
await new Promise(r => addTab("http://mochi.test:8888/#0", r));
await new Promise(r => addTab("http://mochi.test:8888/#1", r));
await new Promise(r => addTab("http://mochi.test:8888/#2", r));
await new Promise(r => addTab("http://mochi.test:8888/#3", r));
is(gBrowser.tabs.length, 5, "five tabs are open after setup");
EventUtils.synthesizeMouse(tabs[1], 1, 1, {type: "mouseover"});
});
// Add several new tabs in sequence, hiding some, to ensure that the

Просмотреть файл

@ -14,7 +14,7 @@ add_task(async function testShieldAnimation() {
await UrlClassifierTestUtils.addTestTrackers();
Services.prefs.setBoolPref(TP_PREF, true);
let tab = gBrowser.selectedTab = gBrowser.addTab();
let tab = gBrowser.selectedTab = BrowserTestUtils.addTab(gBrowser);
let animationIcon = document.getElementById("tracking-protection-icon-animatable-image");
let noAnimationIcon = document.getElementById("tracking-protection-icon");

Просмотреть файл

@ -231,7 +231,7 @@ add_task(async function testNormalBrowsing() {
await UrlClassifierTestUtils.addTestTrackers();
tabbrowser = gBrowser;
let tab = tabbrowser.selectedTab = tabbrowser.addTab();
let tab = tabbrowser.selectedTab = BrowserTestUtils.addTab(tabbrowser);
TrackingProtection = gBrowser.ownerGlobal.TrackingProtection;
ok(TrackingProtection, "TP is attached to the browser window");
@ -252,7 +252,7 @@ add_task(async function testNormalBrowsing() {
add_task(async function testPrivateBrowsing() {
let privateWin = await BrowserTestUtils.openNewBrowserWindow({private: true});
tabbrowser = privateWin.gBrowser;
let tab = tabbrowser.selectedTab = tabbrowser.addTab();
let tab = tabbrowser.selectedTab = BrowserTestUtils.addTab(tabbrowser);
TrackingProtection = tabbrowser.ownerGlobal.TrackingProtection;
ok(TrackingProtection, "TP is attached to the private window");

Просмотреть файл

@ -67,7 +67,7 @@ var tests = [
function loadTabInWindow(win, callback) {
info("Loading tab");
let url = "http://user:pass@example.com/";
let tab = win.gBrowser.selectedTab = win.gBrowser.addTab(url);
let tab = win.gBrowser.selectedTab = BrowserTestUtils.addTab(win.gBrowser, url);
BrowserTestUtils.browserLoaded(tab.linkedBrowser, false, url).then(() => {
info("Tab loaded");
is(win.gURLBar.textValue, "example.com", "URL bar had user/pass stripped initially");

Просмотреть файл

@ -162,7 +162,7 @@ function get_test_function_for_localhost_with_hostname(hostName, isPrivate) {
browser.removeTab(tab);
// Now try again with the pref set.
tab = browser.selectedTab = browser.addTab("about:blank");
tab = browser.selectedTab = BrowserTestUtils.addTab(browser, "about:blank");
await BrowserTestUtils.browserLoaded(tab.linkedBrowser);
// In a private window, the notification should appear again.
await runURLBarSearchTest({

Просмотреть файл

@ -166,6 +166,7 @@ skip-if = !e10s || debug || asan
[browser_ext_tabs_captureVisibleTab.js]
[browser_ext_tabs_create.js]
skip-if = os == "linux" && debug && bits == 32 # Bug 1350189
[browser_ext_tabs_create_url.js]
[browser_ext_tabs_create_invalid_url.js]
[browser_ext_tabs_detectLanguage.js]
[browser_ext_tabs_discard.js]

Просмотреть файл

@ -175,57 +175,6 @@ add_task(async function test_create_options() {
BrowserTestUtils.removeTab(tab);
});
add_task(async function test_urlbar_focus() {
const extension = ExtensionTestUtils.loadExtension({
background() {
browser.tabs.onUpdated.addListener(function onUpdated(_, info) {
if (info.status === "complete") {
browser.test.sendMessage("complete");
browser.tabs.onUpdated.removeListener(onUpdated);
}
});
browser.test.onMessage.addListener(async (cmd, ...args) => {
const result = await browser.tabs[cmd](...args);
browser.test.sendMessage("result", result);
});
},
});
await extension.startup();
// Test content is focused after opening a regular url
extension.sendMessage("create", {url: "https://example.com"});
const [tab1] = await Promise.all([
extension.awaitMessage("result"),
extension.awaitMessage("complete"),
]);
is(document.activeElement.tagName, "browser", "Content focused after opening a web page");
extension.sendMessage("remove", tab1.id);
await extension.awaitMessage("result");
// Test urlbar is focused after opening an empty tab
extension.sendMessage("create", {});
const tab2 = await extension.awaitMessage("result");
const active = document.activeElement;
info(`Active element: ${active.tagName}, id: ${active.id}, class: ${active.className}`);
const parent = active.parentNode;
info(`Parent element: ${parent.tagName}, id: ${parent.id}, class: ${parent.className}`);
info(`After opening an empty tab, gURLBar.focused: ${gURLBar.focused}`);
is(active.tagName, "html:input", "Input element focused");
ok(active.classList.contains("urlbar-input"), "Urlbar focused");
extension.sendMessage("remove", tab2.id);
await extension.awaitMessage("result");
await extension.unload();
});
add_task(async function test_create_with_popup() {
const extension = ExtensionTestUtils.loadExtension({
async background() {

Просмотреть файл

@ -0,0 +1,55 @@
/* -*- Mode: indent-tabs-mode: nil; js-indent-level: 2 -*- */
/* vim: set sts=2 sw=2 et tw=80: */
"use strict";
add_task(async function test_urlbar_focus() {
const extension = ExtensionTestUtils.loadExtension({
background() {
browser.tabs.onUpdated.addListener(function onUpdated(_, info) {
if (info.status === "complete") {
browser.test.sendMessage("complete");
browser.tabs.onUpdated.removeListener(onUpdated);
}
});
browser.test.onMessage.addListener(async (cmd, ...args) => {
const result = await browser.tabs[cmd](...args);
browser.test.sendMessage("result", result);
});
},
});
await extension.startup();
// Test content is focused after opening a regular url
extension.sendMessage("create", {url: "https://example.com"});
const [tab1] = await Promise.all([
extension.awaitMessage("result"),
extension.awaitMessage("complete"),
]);
is(document.activeElement.tagName, "browser", "Content focused after opening a web page");
extension.sendMessage("remove", tab1.id);
await extension.awaitMessage("result");
// Test urlbar is focused after opening an empty tab
extension.sendMessage("create", {});
const tab2 = await extension.awaitMessage("result");
const active = document.activeElement;
info(`Active element: ${active.tagName}, id: ${active.id}, class: ${active.className}`);
const parent = active.parentNode;
info(`Parent element: ${parent.tagName}, id: ${parent.id}, class: ${parent.className}`);
info(`After opening an empty tab, gURLBar.focused: ${gURLBar.focused}`);
is(active.tagName, "html:input", "Input element focused");
ok(active.classList.contains("urlbar-input"), "Urlbar focused");
extension.sendMessage("remove", tab2.id);
await extension.awaitMessage("result");
await extension.unload();
});

Просмотреть файл

@ -171,7 +171,9 @@ class TestFirefoxRefresh(MarionetteTestCase):
});
let expectedTabs = new Set();
for (let url of expectedURLs) {
expectedTabs.add(gBrowser.addTab(url));
expectedTabs.add(gBrowser.addTab(url, {
triggeringPrincipal: Services.scriptSecurityManager.getSystemPrincipal(),
}));
}
// Close any other tabs that might be open:
let allTabs = Array.from(gBrowser.tabs);

Просмотреть файл

@ -9,7 +9,7 @@ add_task(async function testNoSessionRestoreButton() {
(await BrowserTestUtils.openNewBrowserWindow({private: true})).close();
let win = await BrowserTestUtils.openNewBrowserWindow({private: true});
let tab = win.gBrowser.addTab("about:sessionrestore");
let tab = BrowserTestUtils.addTab(win.gBrowser, "about:sessionrestore");
let browser = tab.linkedBrowser;
await BrowserTestUtils.browserLoaded(browser);

Просмотреть файл

@ -61,7 +61,7 @@ function get_cache_for_private_window() {
ok(true, "The private window got loaded");
let tab = win.gBrowser.addTab("http://example.org");
let tab = BrowserTestUtils.addTab(win.gBrowser, "http://example.org");
win.gBrowser.selectedTab = tab;
let newTabBrowser = win.gBrowser.getBrowserForTab(tab);

Просмотреть файл

@ -159,7 +159,7 @@ async function assignCookies(aBrowser, aURL, aCookieValue) {
}
async function openTab(aBrowser, aURL) {
let tab = aBrowser.addTab(aURL);
let tab = BrowserTestUtils.addTab(aBrowser, aURL);
// Select tab and make sure its browser is focused.
aBrowser.selectedTab = tab;

Просмотреть файл

@ -11,7 +11,7 @@ add_task(async function test() {
function checkGeolocation(aPrivateMode, aWindow) {
return (async function() {
aWindow.gBrowser.selectedTab = aWindow.gBrowser.addTab(testPageURL);
aWindow.gBrowser.selectedTab = BrowserTestUtils.addTab(aWindow.gBrowser, testPageURL);
await BrowserTestUtils.browserLoaded(aWindow.gBrowser.selectedBrowser);
let notification = aWindow.PopupNotifications.getNotification("geolocation");

Просмотреть файл

@ -9,7 +9,7 @@
let win = await BrowserTestUtils.openNewBrowserWindow({private: true});
win.gBrowser.selectedTab = win.gBrowser.addTab(page1);
win.gBrowser.selectedTab = BrowserTestUtils.addTab(win.gBrowser, page1);
let browser = win.gBrowser.selectedBrowser;
await BrowserTestUtils.browserLoaded(browser);

Просмотреть файл

@ -15,7 +15,7 @@ add_task(async function test() {
// Step 1.
let privateWin = await BrowserTestUtils.openNewBrowserWindow({private: true});
let privateBrowser = privateWin.gBrowser.addTab(
let privateBrowser = BrowserTestUtils.addTab(privateWin.gBrowser,
prefix + "browser_privatebrowsing_localStorage_before_after_page.html").linkedBrowser;
await BrowserTestUtils.browserLoaded(privateBrowser);
@ -23,7 +23,7 @@ add_task(async function test() {
// Step 2.
let win = await BrowserTestUtils.openNewBrowserWindow();
let browser = win.gBrowser.addTab(
let browser = BrowserTestUtils.addTab(win.gBrowser,
prefix + "browser_privatebrowsing_localStorage_before_after_page2.html").linkedBrowser;
await BrowserTestUtils.browserLoaded(browser);

Просмотреть файл

@ -8,7 +8,7 @@
add_task(async function test_no_session_restore_menu_option() {
let win = await BrowserTestUtils.openNewBrowserWindow({ private: true });
ok(true, "The first private window got loaded");
win.gBrowser.addTab("about:mozilla");
BrowserTestUtils.addTab(win.gBrowser, "about:mozilla");
await BrowserTestUtils.closeWindow(win);
win = await BrowserTestUtils.openNewBrowserWindow({ private: true });

Просмотреть файл

@ -12,7 +12,7 @@ add_task(async function test() {
"browser/components/privatebrowsing/test/browser/browser_privatebrowsing_protocolhandler_page.html";
let doTest = async function(aIsPrivateMode, aWindow) {
let tab = aWindow.gBrowser.selectedTab = aWindow.gBrowser.addTab(testURI);
let tab = aWindow.gBrowser.selectedTab = BrowserTestUtils.addTab(aWindow.gBrowser, testURI);
await BrowserTestUtils.browserLoaded(tab.linkedBrowser);
let promiseFinished = PromiseUtils.defer();

Просмотреть файл

@ -27,7 +27,7 @@ function testWhitelistedPage(window) {
add_task(async function testNormalBrowsing() {
tabbrowser = gBrowser;
let tab = tabbrowser.selectedTab = tabbrowser.addTab();
let tab = tabbrowser.selectedTab = BrowserTestUtils.addTab(tabbrowser);
info("Load a test page that's whitelisted");
Services.prefs.setCharPref(PREF_WHITELISTED_HOSTNAMES, "example.com,www.ItIsaTrap.org,example.net");

Просмотреть файл

@ -33,8 +33,8 @@ add_task(async function test() {
container.addEventListener("TabOpen", tabAdded);
BrowserTestUtils.addTab(gBrowser, "about:blank");
BrowserSearch.loadSearchFromContext("mozilla");
BrowserSearch.loadSearchFromContext("firefox");
BrowserSearch.loadSearchFromContext("mozilla", Services.scriptSecurityManager.getSystemPrincipal());
BrowserSearch.loadSearchFromContext("firefox", Services.scriptSecurityManager.getSystemPrincipal());
// Wait for all the tabs to open.
await tabsLoadedDeferred.promise;

Просмотреть файл

@ -93,7 +93,7 @@ async function testSearchEngine(engineDetails) {
run() {
// Simulate a contextmenu search
// FIXME: This is a bit "low-level"...
BrowserSearch.loadSearch("foo", false, "contextmenu");
BrowserSearch._loadSearch("foo", false, "contextmenu", Services.scriptSecurityManager.getSystemPrincipal());
}
},
{

Просмотреть файл

@ -111,7 +111,7 @@ async function testSearchEngine(engineDetails) {
run() {
// Simulate a contextmenu search
// FIXME: This is a bit "low-level"...
BrowserSearch.loadSearch("foo", false, "contextmenu");
BrowserSearch._loadSearch("foo", false, "contextmenu", Services.scriptSecurityManager.getSystemPrincipal());
}
},
{

Просмотреть файл

@ -163,7 +163,7 @@ let setupTest = async function(options, testFunction) {
* The browser window to load the tabs in
*/
function injectTestTabs(win) {
let promises = TEST_URLS.map(url => win.gBrowser.addTab(url))
let promises = TEST_URLS.map(url => BrowserTestUtils.addTab(win.gBrowser, url))
.map(tab => BrowserTestUtils.browserLoaded(tab.linkedBrowser));
return Promise.all(promises);
}
@ -313,7 +313,7 @@ add_task(async function test_open_close_window_and_popup() {
openDialog(location, "popup2", POPUP_FEATURES, TEST_URLS[1]);
let popup2 = await popup2Promise;
popup2.gBrowser.addTab(TEST_URLS[0]);
BrowserTestUtils.addTab(popup2.gBrowser, TEST_URLS[0]);
let closed = await closeWindowForRestoration(newWin);
ok(closed, "Should be able to close the window");
@ -378,7 +378,7 @@ add_task(async function test_open_close_only_popup() {
openDialog(location, "popup", POPUP_FEATURES, TEST_URLS[1]);
popup = await popupPromise;
popup.gBrowser.addTab(TEST_URLS[0]);
BrowserTestUtils.addTab(popup.gBrowser, TEST_URLS[0]);
is(popup.gBrowser.browsers.length, 2,
"Did not restore to the popup window (2)");

Просмотреть файл

@ -25,7 +25,7 @@ add_task(async function new_window() {
let newWin;
try {
newWin = await promiseNewWindowLoaded();
let tab = newWin.gBrowser.addTab("http://example.com/browser_625016.js?" + Math.random());
let tab = BrowserTestUtils.addTab(newWin.gBrowser, "http://example.com/browser_625016.js?" + Math.random());
await promiseBrowserLoaded(tab.linkedBrowser);
// Double check that we have no closed windows

Просмотреть файл

@ -113,7 +113,7 @@ add_task(async function test_3() {
});
async function promiseTabLoad(win, url) {
let tab = win.gBrowser.addTab(url);
let tab = BrowserTestUtils.addTab(win.gBrowser, url);
await promiseBrowserLoaded(tab.linkedBrowser);
await TabStateFlusher.flush(tab.linkedBrowser);
}

Просмотреть файл

@ -116,7 +116,7 @@ function promiseNewWindow() {
}
async function createTabWithStorageData(urls, win = window) {
let tab = win.gBrowser.addTab();
let tab = BrowserTestUtils.addTab(win.gBrowser);
let browser = tab.linkedBrowser;
for (let url of urls) {

Просмотреть файл

@ -50,7 +50,7 @@ add_task(async function test_open_and_close() {
await promiseBrowserLoaded(newTab2.linkedBrowser);
let newWin = await promiseNewWindowLoaded();
let tab = newWin.gBrowser.addTab(URL_NEWWIN);
let tab = BrowserTestUtils.addTab(newWin.gBrowser, URL_NEWWIN);
await promiseBrowserLoaded(tab.linkedBrowser);

Просмотреть файл

@ -300,7 +300,7 @@ add_task(async function test_revive_all_tabs_from_session_store() {
// a second window, since only selected tabs will show
// about:tabcrashed.
let win2 = await BrowserTestUtils.openNewBrowserWindow();
let newTab2 = win2.gBrowser.addTab(PAGE_1, { sameProcessAsFrameLoader: browser.frameLoader });
let newTab2 = BrowserTestUtils.addTab(win2.gBrowser, PAGE_1, { sameProcessAsFrameLoader: browser.frameLoader });
win2.gBrowser.selectedTab = newTab2;
let browser2 = newTab2.linkedBrowser;
ok(browser2.isRemoteBrowser, "Should be a remote browser");
@ -407,7 +407,7 @@ add_task(async function test_hide_restore_all_button() {
// Load up a second window so we can get another tab to show
// about:tabcrashed
let win2 = await BrowserTestUtils.openNewBrowserWindow();
let newTab3 = win2.gBrowser.addTab(PAGE_2, { sameProcessAsFrameLoader: browser.frameLoader });
let newTab3 = BrowserTestUtils.addTab(win2.gBrowser, PAGE_2, { sameProcessAsFrameLoader: browser.frameLoader });
win2.gBrowser.selectedTab = newTab3;
let otherWinBrowser = newTab3.linkedBrowser;
await promiseBrowserLoaded(otherWinBrowser);

Просмотреть файл

@ -16,7 +16,7 @@ add_task(async function test() {
await promiseBrowserLoaded(win.gBrowser.selectedBrowser);
// Open a second tab and close the first one.
let tab = win.gBrowser.addTab("about:mozilla");
let tab = BrowserTestUtils.addTab(win.gBrowser, "about:mozilla");
await promiseBrowserLoaded(tab.linkedBrowser);
await TabStateFlusher.flush(tab.linkedBrowser);
await promiseRemoveTabAndSessionState(win.gBrowser.tabs[0]);

Просмотреть файл

@ -72,7 +72,7 @@ add_task(async function() {
mm.loadFrameScript(FRAME_SCRIPT, true);
// Create a new tab in the new window that will load the frame script.
let tab = win.gBrowser.addTab("about:mozilla");
let tab = BrowserTestUtils.addTab(win.gBrowser, "about:mozilla");
let browser = tab.linkedBrowser;
await promiseBrowserLoaded(browser);
await TabStateFlusher.flush(browser);
@ -86,7 +86,7 @@ add_task(async function() {
is(ss.getClosedTabCount(win), 0, "no tabs to restore");
// Create a new tab in the new window that will load the frame script.
tab = win.gBrowser.addTab("about:mozilla");
tab = BrowserTestUtils.addTab(win.gBrowser, "about:mozilla");
browser = tab.linkedBrowser;
await promiseBrowserLoaded(browser);
await TabStateFlusher.flush(browser);
@ -109,7 +109,7 @@ add_task(async function() {
let win = await promiseNewWindowLoaded({private: true});
// Create a new tab in the new window that will load the frame script.
let tab = win.gBrowser.addTab("about:mozilla");
let tab = BrowserTestUtils.addTab(win.gBrowser, "about:mozilla");
let browser = tab.linkedBrowser;
await promiseBrowserLoaded(browser);
await TabStateFlusher.flush(browser);

Просмотреть файл

@ -116,7 +116,7 @@ add_task(async function test_scroll_background_tabs() {
pushPrefs(["browser.sessionstore.restore_on_demand", true]);
let newWin = await BrowserTestUtils.openNewBrowserWindow();
let tab = newWin.gBrowser.addTab(URL);
let tab = BrowserTestUtils.addTab(newWin.gBrowser, URL);
let browser = tab.linkedBrowser;
await BrowserTestUtils.browserLoaded(browser);

Просмотреть файл

@ -21,7 +21,7 @@ add_task(async function test_scroll_background_about_reader_tabs() {
pushPrefs(["browser.sessionstore.restore_on_demand", true]);
let newWin = await BrowserTestUtils.openNewBrowserWindow();
let tab = newWin.gBrowser.addTab(READER_MODE_URL);
let tab = BrowserTestUtils.addTab(newWin.gBrowser, READER_MODE_URL);
let browser = tab.linkedBrowser;
await Promise.all([
BrowserTestUtils.browserLoaded(browser),

Просмотреть файл

@ -16,7 +16,7 @@ add_task(async function() {
let win = await promiseNewWindowLoaded();
// Add a new tab.
let tab = win.gBrowser.addTab("about:blank");
let tab = BrowserTestUtils.addTab(win.gBrowser, "about:blank");
let browser = tab.linkedBrowser;
await promiseBrowserLoaded(browser);
ok(browser.isRemoteBrowser, "browser is remote");

Просмотреть файл

@ -8,7 +8,7 @@
ChromeUtils.import("resource:///modules/sessionstore/SessionStore.jsm");
async function openAndCloseTab(window, url) {
let tab = window.gBrowser.addTab(url);
let tab = BrowserTestUtils.addTab(window.gBrowser, url);
await promiseBrowserLoaded(tab.linkedBrowser, true, url);
await TabStateFlusher.flush(tab.linkedBrowser);
await promiseRemoveTabAndSessionState(tab);

Просмотреть файл

@ -13,7 +13,9 @@ add_task(async function() {
// Create 4 tabs with different userContextId.
for (let userContextId = 1; userContextId < 5; userContextId++) {
let tab = win.gBrowser.addTab("http://example.com/", {userContextId});
let tab = BrowserTestUtils.addTab(win.gBrowser, "http://example.com/", {
userContextId,
});
await promiseBrowserLoaded(tab.linkedBrowser);
await TabStateFlusher.flush(tab.linkedBrowser);
}
@ -36,7 +38,9 @@ add_task(async function() {
// Create tabs with different userContextId, but this time we create them with
// fewer tabs and with different order with win.
for (let userContextId = 3; userContextId > 0; userContextId--) {
let tab = win2.gBrowser.addTab("http://example.com/", {userContextId});
let tab = BrowserTestUtils.addTab(win2.gBrowser, "http://example.com/", {
userContextId,
});
await promiseBrowserLoaded(tab.linkedBrowser);
await TabStateFlusher.flush(tab.linkedBrowser);
}
@ -76,7 +80,9 @@ add_task(async function() {
let win = await BrowserTestUtils.openNewBrowserWindow();
await TabStateFlusher.flush(win.gBrowser.selectedBrowser);
let tab = win.gBrowser.addTab("http://example.com/", { userContextId: 1 });
let tab = BrowserTestUtils.addTab(win.gBrowser, "http://example.com/", {
userContextId: 1,
});
await promiseBrowserLoaded(tab.linkedBrowser);
await TabStateFlusher.flush(tab.linkedBrowser);
@ -92,7 +98,9 @@ add_task(async function() {
let win2 = await BrowserTestUtils.openNewBrowserWindow();
let tab2 = win2.gBrowser.addTab("http://example.com/", { userContextId: 1 });
let tab2 = BrowserTestUtils.addTab(win2.gBrowser, "http://example.com/", {
userContextId: 1,
});
await promiseBrowserLoaded(tab2.linkedBrowser);
await TabStateFlusher.flush(tab2.linkedBrowser);

Просмотреть файл

@ -71,7 +71,7 @@ var { helpers, assert } = (function () {
options.isFirefox = true;
var tabbrowser = options.chromeWindow.gBrowser;
options.tab = tabbrowser.addTab();
options.tab = BrowserTestUtils.addTab(tabbrowser);
tabbrowser.selectedTab = options.tab;
options.browser = tabbrowser.getBrowserForTab(options.tab);
options.target = TargetFactory.forTab(options.tab);
@ -117,7 +117,7 @@ var { helpers, assert } = (function () {
options.isFirefox = true;
var tabbrowser = options.chromeWindow.gBrowser;
options.tab = tabbrowser.addTab();
options.tab = BrowserTestUtils.addTab(tabbrowser);
tabbrowser.selectedTab = options.tab;
options.browser = tabbrowser.getBrowserForTab(options.tab);
options.target = TargetFactory.forTab(options.tab);

Просмотреть файл

@ -88,7 +88,7 @@ this.addTab = function addTab(aUrl, aWindow) {
let targetBrowser = targetWindow.gBrowser;
targetWindow.focus();
let tab = targetBrowser.selectedTab = targetBrowser.addTab(aUrl);
let tab = targetBrowser.selectedTab = BrowserTestUtils.addTab(targetBrowser, aUrl);
let linkedBrowser = tab.linkedBrowser;
info("Loading frame script with url " + FRAME_SCRIPT_URL + ".");

Просмотреть файл

@ -28,7 +28,7 @@ var addTab = function(url, win) {
const targetWindow = win || window;
const targetBrowser = targetWindow.gBrowser;
const tab = targetBrowser.selectedTab = targetBrowser.addTab(url);
const tab = targetBrowser.selectedTab = BrowserTestUtils.addTab(targetBrowser, url);
BrowserTestUtils.browserLoaded(targetBrowser.selectedBrowser)
.then(function() {
info("URL '" + url + "' loading complete");

Просмотреть файл

@ -31,7 +31,7 @@ add_task(async function() {
const privateWindow = await openNewBrowserWindow({ private: true });
ok(PrivateBrowsingUtils.isWindowPrivate(privateWindow), "window is private");
const privateBrowser = privateWindow.gBrowser;
privateBrowser.selectedTab = privateBrowser.addTab(PRIVATE_TEST_URI);
privateBrowser.selectedTab = BrowserTestUtils.addTab(privateBrowser, PRIVATE_TEST_URI);
const privateTab = privateBrowser.selectedTab;
info("private tab opened");

Просмотреть файл

@ -34,7 +34,8 @@ add_task(async function() {
await waitForDelayedStartupFinished(win);
info("Open a new tab on the new window to ensure the focus is on the new window");
const tab = win.gBrowser.addTab("data:text/html;charset=utf-8,<title>foo</title>");
const tab = BrowserTestUtils.addTab(win.gBrowser,
"data:text/html;charset=utf-8,<title>foo</title>");
await BrowserTestUtils.browserLoaded(win.gBrowser.getBrowserForTab(tab));
info("Synthesize a DevTools shortcut, the toolbox should not open on this new window.");

Просмотреть файл

@ -48,7 +48,8 @@ function timelineTestOpenUrl(url) {
});
let loadPromise = new Promise(function(resolve, reject) {
let tab = window.gBrowser.selectedTab = window.gBrowser.addTab(url);
let browser = window.gBrowser;
let tab = browser.selectedTab = BrowserTestUtils.addTab(browser, url);
let linkedBrowser = tab.linkedBrowser;
BrowserTestUtils.browserLoaded(linkedBrowser).then(() => resolve(tab));

Просмотреть файл

@ -4,7 +4,7 @@ const TEST_URI = getRootDirectory(gTestPath).replace("chrome://mochitests/conten
* Loading an image from https:// should work.
*/
add_task(async function load_image_from_https_test() {
let tab = gBrowser.addTab(TEST_URI);
let tab = BrowserTestUtils.addTab(gBrowser, TEST_URI);
await BrowserTestUtils.browserLoaded(tab.linkedBrowser);
gBrowser.selectedTab = tab;
@ -38,7 +38,7 @@ add_task(async function load_image_from_https_test() {
* Loading an image from http:// should be rejected.
*/
add_task(async function load_image_from_http_test() {
let tab = gBrowser.addTab(TEST_URI);
let tab = BrowserTestUtils.addTab(gBrowser, TEST_URI);
await BrowserTestUtils.browserLoaded(tab.linkedBrowser);
gBrowser.selectedTab = tab;
@ -74,7 +74,7 @@ add_task(async function load_image_from_http_test() {
* The load from https:// should be replaced.
*/
add_task(async function load_https_and_http_test() {
let tab = gBrowser.addTab(TEST_URI);
let tab = BrowserTestUtils.addTab(gBrowser, TEST_URI);
await BrowserTestUtils.browserLoaded(tab.linkedBrowser);
// Clear image cache, otherwise in non-e10s mode the image might be cached by
@ -121,7 +121,7 @@ add_task(async function load_https_and_http_test() {
* the imageBlockingStatus value.
*/
add_task(async function block_pending_request_test() {
let tab = gBrowser.addTab(TEST_URI);
let tab = BrowserTestUtils.addTab(gBrowser, TEST_URI);
await BrowserTestUtils.browserLoaded(tab.linkedBrowser);
gBrowser.selectedTab = tab;

Просмотреть файл

@ -20,11 +20,11 @@ add_task(async function() {
});
await win2Promise;
var tab1 = win1.gBrowser.addTab(URL);
var tab1 = BrowserTestUtils.addTab(win1.gBrowser, URL);
await BrowserTestUtils.browserLoaded(win1.gBrowser.getBrowserForTab(tab1));
var browser1 = gBrowser.getBrowserForTab(tab1);
var tab2 = win2.gBrowser.addTab(URL);
var tab2 = BrowserTestUtils.addTab(win2.gBrowser, URL);
await BrowserTestUtils.browserLoaded(win2.gBrowser.getBrowserForTab(tab2));
var browser2 = gBrowser.getBrowserForTab(tab2);

Просмотреть файл

@ -103,7 +103,7 @@ function test() {
return BrowserTestUtils.openNewBrowserWindow({private: true});
}).then(pw => {
privateWin = pw;
privateTab = pw.gBrowser.addTab("http://example.com/");
privateTab = BrowserTestUtils.addTab(pw.gBrowser, "http://example.com/");
return BrowserTestUtils.browserLoaded(privateTab.linkedBrowser);
}).then(tab => {
return Promise.all([

Просмотреть файл

@ -43,7 +43,7 @@ function runPass(getterFile, finishedCallback) {
function afterPrivateWindowOpened() {
// In the private window, open the getter file, and wait for a new tab to be opened.
privateWin.gBrowser.selectedTab = privateWin.gBrowser.addTab(rootDir + getterFile);
privateWin.gBrowser.selectedTab = BrowserTestUtils.addTab(privateWin.gBrowser, rootDir + getterFile);
testBrowser = privateWin.gBrowser.selectedBrowser;
privateWin.gBrowser.tabContainer.addEventListener("TabOpen", onNewTabOpened, true);
}
@ -77,7 +77,7 @@ function runPass(getterFile, finishedCallback) {
function afterPrivateWindowOpened2() {
// In the private window, open the setter file, and wait for it to load.
privateWin.gBrowser.selectedTab = privateWin.gBrowser.addTab(rootDir + "file_bug1108547-1.html");
privateWin.gBrowser.selectedTab = BrowserTestUtils.addTab(privateWin.gBrowser, rootDir + "file_bug1108547-1.html");
BrowserTestUtils.browserLoaded(privateWin.gBrowser.selectedBrowser).then(afterOpenCookieSetter2);
}

Просмотреть файл

@ -49,7 +49,7 @@ add_task(async function test2() {
}, win);
info("creating private tab");
win.gBrowser.selectedTab = win.gBrowser.addTab();
win.gBrowser.selectedTab = BrowserTestUtils.addTab(win.gBrowser);
info("loading test page: " + testPageURL);
win.gBrowser.selectedBrowser.loadURI(testPageURL);

Просмотреть файл

@ -26,7 +26,7 @@ add_task(async function test2() {
let win = await BrowserTestUtils.openNewBrowserWindow({ private: true });
info("creating tab");
win.gBrowser.selectedTab = win.gBrowser.addTab();
win.gBrowser.selectedTab = BrowserTestUtils.addTab(win.gBrowser);
win.gBrowser.selectedBrowser.loadURI(testPageURL);
await waitForMessage("InvalidStateError", win.gBrowser);
win.gBrowser.removeCurrentTab();

Просмотреть файл

@ -22,7 +22,7 @@ add_task(async function testPermissionUnknownInPrivateWindow() {
}, win);
info("Creating private tab");
win.gBrowser.selectedTab = win.gBrowser.addTab();
win.gBrowser.selectedTab = BrowserTestUtils.addTab(win.gBrowser);
info("Loading test page: " + testPageURL);
win.gBrowser.selectedBrowser.loadURI(testPageURL);

Просмотреть файл

@ -15,11 +15,11 @@ add_task(async function() {
var URL = "http://mochi.test:8888/browser/dom/tests/browser/page_privatestorageevent.html";
var privTab = privWin.gBrowser.addTab(URL);
var privTab = BrowserTestUtils.addTab(privWin.gBrowser, URL);
await BrowserTestUtils.browserLoaded(privWin.gBrowser.getBrowserForTab(privTab));
var privBrowser = gBrowser.getBrowserForTab(privTab);
var pubTab = pubWin.gBrowser.addTab(URL);
var pubTab = BrowserTestUtils.addTab(pubWin.gBrowser, URL);
await BrowserTestUtils.browserLoaded(pubWin.gBrowser.getBrowserForTab(pubTab));
var pubBrowser = gBrowser.getBrowserForTab(pubTab);

Просмотреть файл

@ -420,7 +420,8 @@ async function largeAllocSuccessTests() {
let newWindow = await BrowserTestUtils.openNewBrowserWindow();
newWindow.gBrowser.adoptTab(gBrowser.getTabForBrowser(aBrowser), 0);
newWindow.gBrowser.adoptTab(gBrowser.getTabForBrowser(aBrowser), 0, null,
Services.scriptSecurityManager.getSystemPrincipal());
let newTab = newWindow.gBrowser.tabs[0];
is(newTab.linkedBrowser.currentURI.spec, TEST_URI);

Просмотреть файл

@ -196,7 +196,7 @@ var BrowserTestUtils = {
opening();
tab = tabbrowser.selectedTab;
} else {
tabbrowser.selectedTab = tab = tabbrowser.addTab(opening);
tabbrowser.selectedTab = tab = BrowserTestUtils.addTab(tabbrowser, opening);
}
})
];

Просмотреть файл

@ -95,7 +95,8 @@ function loadMochitest(e) {
win.removeEventListener("mochitest-load", loadMochitest);
// for mochitest-plain, navigating to the url is all we need
win.loadURI(url);
win.loadURI(url, null, null, null, null, null, null, null,
Services.scriptSecurityManager.getSystemPrincipal());
if (flavor == "mochitest") {
return;
}

Просмотреть файл

@ -576,7 +576,10 @@ Tester.prototype = {
// Replace the last tab with a fresh one
if (window.gBrowser) {
gBrowser.addTab("about:blank", { skipAnimation: true });
gBrowser.addTab("about:blank", {
skipAnimation: true,
triggeringPrincipal: Services.scriptSecurityManager.getSystemPrincipal(),
});
gBrowser.removeTab(gBrowser.selectedTab, { skipPermitUnload: true });
gBrowser.stop();
}

Просмотреть файл

@ -18,7 +18,7 @@ add_task(async function test_support_tab_separators() {
info("Checking background tab separator color");
let tab = gBrowser.addTab("about:blank");
let tab = BrowserTestUtils.addTab(gBrowser, "about:blank");
Assert.equal(window.getComputedStyle(tab, "::before").borderLeftColor,
`rgb(${hexToRGB(TAB_SEPARATOR_COLOR).join(", ")})`,

Просмотреть файл

@ -38,7 +38,7 @@ add_task(async function setup_test_preference() {
add_task(async function block_autoplay_media() {
info("- open new background tab1 -");
let tab1 = window.gBrowser.addTab("about:blank");
let tab1 = BrowserTestUtils.addTab(window.gBrowser, "about:blank");
tab1.linkedBrowser.loadURI(PAGE);
await BrowserTestUtils.browserLoaded(tab1.linkedBrowser);
@ -46,7 +46,7 @@ add_task(async function block_autoplay_media() {
await check_audio_suspended(tab1.linkedBrowser, SuspendedType.SUSPENDED_BLOCK);
info("- open new background tab2 -");
let tab2 = window.gBrowser.addTab("about:blank");
let tab2 = BrowserTestUtils.addTab(window.gBrowser, "about:blank");
tab2.linkedBrowser.loadURI(PAGE);
await BrowserTestUtils.browserLoaded(tab2.linkedBrowser);
@ -90,7 +90,7 @@ add_task(async function block_autoplay_media() {
]});
info("- open new background tab4 -");
let tab4 = window.gBrowser.addTab("about:blank");
let tab4 = BrowserTestUtils.addTab(window.gBrowser, "about:blank");
tab4.linkedBrowser.loadURI(PAGE);
await BrowserTestUtils.browserLoaded(tab4.linkedBrowser);
info("- should block autoplay for non-visited tab4 -");

Просмотреть файл

@ -37,7 +37,7 @@ add_task(async function setup_test_preference() {
add_task(async function block_autoplay_media() {
info("- open new background tab1, and check tab1's media suspend type -");
let tab1 = window.gBrowser.addTab("about:blank");
let tab1 = BrowserTestUtils.addTab(window.gBrowser, "about:blank");
tab1.linkedBrowser.loadURI(PAGE_SHOULD_NOT_PLAY);
await BrowserTestUtils.browserLoaded(tab1.linkedBrowser);
await ContentTask.spawn(tab1.linkedBrowser, SuspendedType.NONE_SUSPENDED,
@ -47,7 +47,7 @@ add_task(async function block_autoplay_media() {
await waitForTabBlockEvent(tab1, false);
info("- open new background tab2, and check tab2's media suspend type -");
let tab2 = window.gBrowser.addTab("about:blank");
let tab2 = BrowserTestUtils.addTab(window.gBrowser, "about:blank");
tab2.linkedBrowser.loadURI(PAGE_SHOULD_PLAY);
await BrowserTestUtils.browserLoaded(tab2.linkedBrowser);
await ContentTask.spawn(tab2.linkedBrowser, SuspendedType.SUSPENDED_BLOCK,

Просмотреть файл

@ -58,7 +58,7 @@ add_task(async function setup_test_preference() {
*/
add_task(async function media_should_be_able_to_play_in_visible_tab() {
info("- open new background tab, and check tab's media pause state -");
let tab = window.gBrowser.addTab("about:blank");
let tab = BrowserTestUtils.addTab(window.gBrowser, "about:blank");
tab.linkedBrowser.loadURI(PAGE);
await BrowserTestUtils.browserLoaded(tab.linkedBrowser);
await ContentTask.spawn(tab.linkedBrowser, true,

Просмотреть файл

@ -84,7 +84,7 @@ add_task(async function setup_test_preference() {
add_task(async function block_multiple_media() {
info("- open new background tab -");
let tab = window.gBrowser.addTab("about:blank");
let tab = BrowserTestUtils.addTab(window.gBrowser, "about:blank");
let browser = tab.linkedBrowser;
browser.loadURI(PAGE);
await BrowserTestUtils.browserLoaded(browser);

Просмотреть файл

@ -52,7 +52,7 @@ add_task(async function setup_test_preference() {
add_task(async function block_not_in_tree_media() {
info("- open new background tab -");
let tab = window.gBrowser.addTab("about:blank");
let tab = BrowserTestUtils.addTab(window.gBrowser, "about:blank");
tab.linkedBrowser.loadURI(PAGE);
await BrowserTestUtils.browserLoaded(tab.linkedBrowser);

Просмотреть файл

@ -63,7 +63,7 @@ add_task(async function setup_test_preference() {
add_task(async function unblock_icon_should_disapear_after_resume_tab() {
info("- open new background tab -");
let tab = window.gBrowser.addTab("about:blank");
let tab = BrowserTestUtils.addTab(window.gBrowser, "about:blank");
tab.linkedBrowser.loadURI(PAGE);
await BrowserTestUtils.browserLoaded(tab.linkedBrowser);

Просмотреть файл

@ -10,7 +10,7 @@ add_task(async function setup_test_preference() {
add_task(async function block_plug_in() {
info("- open new background tab -");
let tab = window.gBrowser.addTab("about:blank");
let tab = BrowserTestUtils.addTab(window.gBrowser, "about:blank");
tab.linkedBrowser.loadURI(PAGE);
await BrowserTestUtils.browserLoaded(tab.linkedBrowser);

Просмотреть файл

@ -34,7 +34,7 @@ add_task(async function setup_test_preference() {
add_task(async function unblock_icon_should_disapear_after_resume_tab() {
info("- open new background tab -");
let tab = window.gBrowser.addTab("about:blank");
let tab = BrowserTestUtils.addTab(window.gBrowser, "about:blank");
tab.linkedBrowser.loadURI(PAGE);
await BrowserTestUtils.browserLoaded(tab.linkedBrowser);
@ -64,7 +64,7 @@ add_task(async function unblock_icon_should_disapear_after_resume_tab() {
add_task(async function should_not_show_sound_indicator_after_resume_tab() {
info("- open new background tab -");
let tab = window.gBrowser.addTab("about:blank");
let tab = BrowserTestUtils.addTab(window.gBrowser, "about:blank");
tab.linkedBrowser.loadURI(PAGE);
await BrowserTestUtils.browserLoaded(tab.linkedBrowser);

Просмотреть файл

@ -16,7 +16,7 @@ add_task(async function setup_test_preference() {
add_task(async function block_web_audio() {
info("- open new background tab -");
let tab = window.gBrowser.addTab("about:blank");
let tab = BrowserTestUtils.addTab(window.gBrowser, "about:blank");
tab.linkedBrowser.loadURI(PAGE);
await BrowserTestUtils.browserLoaded(tab.linkedBrowser);

Просмотреть файл

@ -102,7 +102,7 @@ add_task(async function setup_test_preference() {
*/
add_task(async function resume_and_suspend_background_video_decoding() {
info("- open new background tab -");
let tab = window.gBrowser.addTab("about:blank");
let tab = BrowserTestUtils.addTab(window.gBrowser, "about:blank");
let browser = tab.linkedBrowser;
info("- before loading media, we shoudn't send the tab hover msg for tab -");