Backed out changeset a3fbed43aa55 for a new set of intermittent failures.

MozReview-Commit-ID: 1lIDylABshC
This commit is contained in:
Kris Maglione 2016-04-25 18:13:41 -07:00
Родитель 68a55b4b39
Коммит 0c6f1f4c22
7 изменённых файлов: 64 добавлений и 76 удалений

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

@ -453,6 +453,39 @@ extensions.registerSchemaAPI("tabs", null, (extension, context) => {
create: function(createProperties) {
return new Promise((resolve, reject) => {
function createInWindow(window) {
let url;
if (createProperties.url !== null) {
url = context.uri.resolve(createProperties.url);
if (!context.checkLoadURL(url, {dontReportErrors: true})) {
reject({message: `URL not allowed: ${url}`});
return;
}
}
let tab = window.gBrowser.addTab(url || window.BROWSER_NEW_TAB_URL);
let active = true;
if (createProperties.active !== null) {
active = createProperties.active;
}
if (active) {
window.gBrowser.selectedTab = tab;
}
if (createProperties.index !== null) {
window.gBrowser.moveTabTo(tab, createProperties.index);
}
if (createProperties.pinned) {
window.gBrowser.pinTab(tab);
}
resolve(TabManager.convert(extension, tab));
}
let window = createProperties.windowId !== null ?
WindowManager.getWindow(createProperties.windowId, context) :
WindowManager.topWindow;
@ -462,66 +495,12 @@ extensions.registerSchemaAPI("tabs", null, (extension, context) => {
return;
}
Services.obs.removeObserver(obs, "browser-delayed-startup-finished");
resolve(window);
createInWindow(window);
};
Services.obs.addObserver(obs, "browser-delayed-startup-finished", false);
} else {
resolve(window);
createInWindow(window);
}
}).then(window => {
let url;
if (createProperties.url !== null) {
url = context.uri.resolve(createProperties.url);
if (!context.checkLoadURL(url, {dontReportErrors: true})) {
return Promise.reject({message: `Illegal URL: ${url}`});
}
}
let tab = window.gBrowser.addTab(url || window.BROWSER_NEW_TAB_URL);
// We can't wait for a location change event for about:newtab,
// since it may be pre-rendered, in which case its initial
// location change event has already fired.
let promise = Promise.resolve(tab);
if (createProperties.url) {
// Wait for the first location change event, so that operations
// like `executeScript` are dispatched to the inner window that
// contains the URL we're attempting to load.
promise = new Promise(resolve => {
let webProgress = tab.linkedBrowser.webProgress;
let listener = {
QueryInterface: XPCOMUtils.generateQI([Ci.nsIWebProgressListener, Ci.nsISupportsWeakReference]),
onLocationChange() {
webProgress.removeProgressListener(listener);
resolve(tab);
},
};
webProgress.addProgressListener(listener, Ci.nsIWebProgress.NOTIFY_LOCATION);
});
}
let active = true;
if (createProperties.active !== null) {
active = createProperties.active;
}
if (active) {
window.gBrowser.selectedTab = tab;
}
if (createProperties.index !== null) {
window.gBrowser.moveTabTo(tab, createProperties.index);
}
if (createProperties.pinned) {
window.gBrowser.pinTab(tab);
}
return promise;
}).then(tab => {
return TabManager.convert(extension, tab);
});
},
@ -551,7 +530,7 @@ extensions.registerSchemaAPI("tabs", null, (extension, context) => {
let url = context.uri.resolve(updateProperties.url);
if (!context.checkLoadURL(url, {dontReportErrors: true})) {
return Promise.reject({message: `Illegal URL: ${url}`});
return Promise.reject({message: `URL not allowed: ${url}`});
}
tab.linkedBrowser.loadURI(url);

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

@ -205,6 +205,8 @@ add_task(function* testTabSwitchContext() {
});
});
};
let tabLoadPromise;
return [
expect => {
browser.test.log("Initial state. No icon visible.");
@ -223,13 +225,16 @@ add_task(function* testTabSwitchContext() {
expect => {
browser.test.log("Create a new tab. No icon visible.");
browser.tabs.create({active: true, url: "about:blank?0"}, tab => {
tabLoadPromise = promiseTabLoad({url: "about:blank?0", id: tab.id});
tabs.push(tab.id);
expect(null);
});
},
expect => {
browser.test.log("Await tab load. No icon visible.");
expect(null);
tabLoadPromise.then(() => {
expect(null);
});
},
expect => {
browser.test.log("Change properties. Expect new properties.");

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

@ -101,11 +101,12 @@ add_task(function* () {
browser.test.log(`Testing tabs.create(${JSON.stringify(test.create)}), expecting ${JSON.stringify(test.result)}`);
let tabId;
let updatedPromise = new Promise(resolve => {
let onUpdated = (changedTabId, changed) => {
if (changed.url) {
if (changedTabId === tabId && changed.url) {
browser.tabs.onUpdated.removeListener(onUpdated);
resolve({tabId: changedTabId, url: changed.url});
resolve(changed.url);
}
};
browser.tabs.onUpdated.addListener(onUpdated);
@ -119,7 +120,6 @@ add_task(function* () {
browser.tabs.onCreated.addListener(onCreated);
});
let tabId;
Promise.all([
browser.tabs.create(test.create),
createdPromise,
@ -136,9 +136,8 @@ add_task(function* () {
}
return updatedPromise;
}).then(updated => {
browser.test.assertEq(tabId, updated.tabId, `Expected value for tab.id`);
browser.test.assertEq(expected.url, updated.url, `Expected value for tab.url`);
}).then(url => {
browser.test.assertEq(expected.url, url, `Expected value for tab.url`);
return browser.tabs.remove(tabId);
}).then(() => {

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

@ -13,7 +13,7 @@ function* testTabsCreateInvalidURL(tabsCreateURL) {
browser.test.onMessage.addListener((msg, tabsCreateURL) => {
browser.tabs.create({url: tabsCreateURL}, (tab) => {
browser.test.assertEq(undefined, tab, "on error tab should be undefined");
browser.test.assertTrue(/Illegal URL/.test(browser.runtime.lastError.message),
browser.test.assertTrue(/URL not allowed/.test(browser.runtime.lastError.message),
"runtime.lastError should report the expected error message");
// Remove the opened tab is any.

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

@ -12,7 +12,20 @@ add_task(function* testDetectLanguage() {
const BASE_PATH = "browser/browser/components/extensions/test/browser";
function loadTab(url) {
return browser.tabs.create({url});
let tabId;
let awaitUpdated = new Promise(resolve => {
browser.tabs.onUpdated.addListener(function onUpdated(changedTabId, changed, tab) {
if (changedTabId === tabId && changed.url) {
browser.tabs.onUpdated.removeListener(onUpdated);
resolve(tab);
}
});
});
return browser.tabs.create({url}).then(tab => {
tabId = tab.id;
return awaitUpdated;
});
}
loadTab(`http://example.co.jp/${BASE_PATH}/file_language_ja.html`).then(tab => {

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

@ -118,14 +118,6 @@ add_task(function* testExecuteScript() {
browser.test.assertEq("http://mochi.test:8888/", result, "Result for frameId[1] is correct");
}),
browser.tabs.create({url: "http://example.com/"}).then(tab => {
return browser.tabs.executeScript(tab.id, {code: "location.href"}).then(result => {
browser.test.assertEq("http://example.com/", result, "Script executed correctly in new tab");
return browser.tabs.remove(tab.id);
});
}),
new Promise(resolve => {
browser.runtime.onMessage.addListener(message => {
browser.test.assertEq("script ran", message, "Expected runtime message");
@ -143,7 +135,7 @@ add_task(function* testExecuteScript() {
let extension = ExtensionTestUtils.loadExtension({
manifest: {
"permissions": ["http://mochi.test/", "http://example.com/", "webNavigation"],
"permissions": ["http://mochi.test/", "webNavigation"],
},
background,

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

@ -37,7 +37,7 @@ function* testTabsUpdateURL(existentTabURL, tabsUpdateURL, isErrorExpected) {
if (!isErrorExpected) {
browser.test.fails(`tabs.update with URL ${tabsUpdateURL} should not be rejected`);
} else {
browser.test.assertTrue(/^Illegal URL/.test(error.message),
browser.test.assertTrue(/^URL not allowed/.test(error.message),
"tabs.update should be rejected with the expected error message");
}
};