Bug 1290157 - Always pass an array to tabs.executeScript on success r=kmag

MozReview-Commit-ID: Ctw8RUtfEZC

--HG--
extra : rebase_source : 7f76c1c99b5948463e5bfa0f7270fe50f6e95a88
This commit is contained in:
Rob Wu 2016-08-09 00:28:47 -07:00
Родитель 0765167097
Коммит 65acb9a681
6 изменённых файлов: 23 добавлений и 20 удалений

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

@ -809,11 +809,11 @@ extensions.registerSchemaAPI("tabs", (extension, context) => {
},
insertCSS: function(tabId, details) {
return self.tabs._execute(tabId, details, "css", "insertCSS");
return self.tabs._execute(tabId, details, "css", "insertCSS").then(() => {});
},
removeCSS: function(tabId, details) {
return self.tabs._execute(tabId, details, "css", "removeCSS");
return self.tabs._execute(tabId, details, "css", "removeCSS").then(() => {});
},
connect: function(tabId, connectInfo) {

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

@ -21,7 +21,8 @@ add_task(function* testExecuteScript() {
browser.tabs.executeScript({
code: "42",
}).then(result => {
browser.test.assertEq(42, result, "Expected callback result");
browser.test.assertEq(1, result.length, "Expected one callback result");
browser.test.assertEq(42, result[0], "Expected callback result");
}),
browser.tabs.executeScript({
@ -37,13 +38,15 @@ add_task(function* testExecuteScript() {
browser.tabs.executeScript({
file: "script.js",
}).then(result => {
browser.test.assertEq(undefined, result, "Expected callback result");
browser.test.assertEq(1, result.length, "Expected one callback result");
browser.test.assertEq(undefined, result[0], "Expected callback result");
}),
browser.tabs.executeScript({
file: "script2.js",
}).then(result => {
browser.test.assertEq(27, result, "Expected callback result");
browser.test.assertEq(1, result.length, "Expected one callback result");
browser.test.assertEq(27, result[0], "Expected callback result");
}),
browser.tabs.executeScript({
@ -62,9 +65,10 @@ add_task(function* testExecuteScript() {
code: "location.href;",
runAt: "document_end",
}).then(result => {
browser.test.assertTrue(typeof(result) == "string", "Result is a string");
browser.test.assertEq(1, result.length, "Expected callback result");
browser.test.assertEq("string", typeof result[0], "Result is a string");
browser.test.assertTrue(/\/file_iframe_document\.html$/.test(result), "Result is correct");
browser.test.assertTrue(/\/file_iframe_document\.html$/.test(result[0]), "Result is correct");
}),
browser.tabs.executeScript({
@ -118,7 +122,7 @@ add_task(function* testExecuteScript() {
browser.tabs.executeScript({
code: "Promise.resolve(42)",
}).then(result => {
browser.test.assertEq(42, result, "Got expected promise resolution value as result");
browser.test.assertEq(42, result[0], "Got expected promise resolution value as result");
}),
browser.tabs.executeScript({
@ -138,19 +142,21 @@ add_task(function* testExecuteScript() {
code: "location.href;",
frameId: frames[0].frameId,
}).then(result => {
browser.test.assertTrue(/\/file_iframe_document\.html$/.test(result), `Result for frameId[0] is correct: ${result}`);
browser.test.assertEq(1, result.length, "Expected one result");
browser.test.assertTrue(/\/file_iframe_document\.html$/.test(result[0]), `Result for frameId[0] is correct: ${result[0]}`);
}),
browser.tabs.executeScript({
code: "location.href;",
frameId: frames[1].frameId,
}).then(result => {
browser.test.assertEq("http://mochi.test:8888/", result, "Result for frameId[1] is correct");
browser.test.assertEq(1, result.length, "Expected one result");
browser.test.assertEq("http://mochi.test:8888/", result[0], "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");
browser.test.assertEq("http://example.com/", result[0], "Script executed correctly in new tab");
return browser.tabs.remove(tab.id);
});

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

@ -49,7 +49,7 @@ add_task(function* testExecuteScript() {
return browser.tabs.executeScript({
code: `(${checkCSS})()`,
});
}).then(result => {
}).then(([result]) => {
browser.test.assertEq(background, result[0], "Expected background color");
browser.test.assertEq(foreground, result[1], "Expected foreground color");
return next();

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

@ -33,14 +33,14 @@ add_task(function* () {
return awaitLoad(tabId);
}).then(() => {
return browser.tabs.executeScript(tabId, {code: "document.body.textContent"});
}).then(textContent => {
}).then(([textContent]) => {
browser.test.assertEq("", textContent, "`textContent` should be empty when bypassCache=false");
return browser.tabs.reload(tabId, {bypassCache: true});
}).then(() => {
return awaitLoad(tabId);
}).then(() => {
return browser.tabs.executeScript(tabId, {code: "document.body.textContent"});
}).then(textContent => {
}).then(([textContent]) => {
let [pragma, cacheControl] = textContent.split(":");
browser.test.assertEq("no-cache", pragma, "`pragma` should be set to `no-cache` when bypassCache is true");
browser.test.assertEq("no-cache", cacheControl, "`cacheControl` should be set to `no-cache` when bypassCache is true");

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

@ -66,7 +66,7 @@ add_task(function* testExecuteScript() {
return browser.tabs.executeScript({
code: `(${checkCSS})()`,
});
}).then(result => {
}).then(([result]) => {
browser.test.assertEq(background, result[0], "Expected background color");
browser.test.assertEq(foreground, result[1], "Expected foreground color");
return next();

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

@ -614,13 +614,10 @@ DocumentManager = {
return Promise.reject({message: `No window matching ${JSON.stringify(details)}`});
}
if (options.all_frames) {
return Promise.all(promises);
}
if (promises.length > 1) {
if (!options.all_frames && promises.length > 1) {
return Promise.reject({message: `Internal error: Script matched multiple windows`});
}
return promises[0];
return Promise.all(promises);
},
enumerateWindows: function* (docShell) {