зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1496848 - Get rid of message manager global from browser_ContentSearch.js. r=adw
This is to simplify a later patch that makes it easier to deal with process flipping. Depends on D7936 Differential Revision: https://phabricator.services.mozilla.com/D7937 --HG-- extra : moz-landing-system : lando
This commit is contained in:
Родитель
c781ec84eb
Коммит
6e40bbfc36
|
@ -6,7 +6,6 @@ const TEST_MSG = "ContentSearchTest";
|
|||
const CONTENT_SEARCH_MSG = "ContentSearch";
|
||||
const TEST_CONTENT_SCRIPT_BASENAME = "contentSearch.js";
|
||||
|
||||
var gMsgMan;
|
||||
/* import-globals-from ../../../components/search/test/head.js */
|
||||
Services.scriptloader.loadSubScript(
|
||||
"chrome://mochitests/content/browser/browser/components/search/test/head.js",
|
||||
|
@ -30,11 +29,11 @@ add_task(async function setup() {
|
|||
});
|
||||
|
||||
add_task(async function GetState() {
|
||||
await addTab();
|
||||
gMsgMan.sendAsyncMessage(TEST_MSG, {
|
||||
let { mm } = await addTab();
|
||||
mm.sendAsyncMessage(TEST_MSG, {
|
||||
type: "GetState",
|
||||
});
|
||||
let msg = await waitForTestMsg("State");
|
||||
let msg = await waitForTestMsg(mm, "State");
|
||||
checkMsg(msg, {
|
||||
type: "State",
|
||||
data: await currentStateObj(),
|
||||
|
@ -42,7 +41,7 @@ add_task(async function GetState() {
|
|||
});
|
||||
|
||||
add_task(async function SetCurrentEngine() {
|
||||
await addTab();
|
||||
let { mm } = await addTab();
|
||||
let newCurrentEngine = null;
|
||||
let oldCurrentEngine = Services.search.currentEngine;
|
||||
let engines = Services.search.getVisibleEngines();
|
||||
|
@ -57,7 +56,7 @@ add_task(async function SetCurrentEngine() {
|
|||
"skipping this part of the test");
|
||||
return;
|
||||
}
|
||||
gMsgMan.sendAsyncMessage(TEST_MSG, {
|
||||
mm.sendAsyncMessage(TEST_MSG, {
|
||||
type: "SetCurrentEngine",
|
||||
data: newCurrentEngine.name,
|
||||
});
|
||||
|
@ -70,7 +69,7 @@ add_task(async function SetCurrentEngine() {
|
|||
deferred.resolve();
|
||||
}
|
||||
}, "browser-search-engine-modified");
|
||||
let searchPromise = waitForTestMsg("CurrentEngine");
|
||||
let searchPromise = waitForTestMsg(mm, "CurrentEngine");
|
||||
info("Waiting for test to observe engine-current...");
|
||||
await deferred.promise;
|
||||
let msg = await searchPromise;
|
||||
|
@ -80,7 +79,7 @@ add_task(async function SetCurrentEngine() {
|
|||
});
|
||||
|
||||
Services.search.currentEngine = oldCurrentEngine;
|
||||
msg = await waitForTestMsg("CurrentEngine");
|
||||
msg = await waitForTestMsg(mm, "CurrentEngine");
|
||||
checkMsg(msg, {
|
||||
type: "CurrentEngine",
|
||||
data: await currentEngineObj(oldCurrentEngine),
|
||||
|
@ -88,17 +87,17 @@ add_task(async function SetCurrentEngine() {
|
|||
});
|
||||
|
||||
add_task(async function modifyEngine() {
|
||||
await addTab();
|
||||
let { mm } = await addTab();
|
||||
let engine = Services.search.currentEngine;
|
||||
let oldAlias = engine.alias;
|
||||
engine.alias = "ContentSearchTest";
|
||||
let msg = await waitForTestMsg("CurrentState");
|
||||
let msg = await waitForTestMsg(mm, "CurrentState");
|
||||
checkMsg(msg, {
|
||||
type: "CurrentState",
|
||||
data: await currentStateObj(),
|
||||
});
|
||||
engine.alias = oldAlias;
|
||||
msg = await waitForTestMsg("CurrentState");
|
||||
msg = await waitForTestMsg(mm, "CurrentState");
|
||||
checkMsg(msg, {
|
||||
type: "CurrentState",
|
||||
data: await currentStateObj(),
|
||||
|
@ -106,7 +105,7 @@ add_task(async function modifyEngine() {
|
|||
});
|
||||
|
||||
add_task(async function search() {
|
||||
await addTab();
|
||||
let { mm } = await addTab();
|
||||
let engine = Services.search.currentEngine;
|
||||
let data = {
|
||||
engineName: engine.name,
|
||||
|
@ -116,12 +115,12 @@ add_task(async function search() {
|
|||
};
|
||||
let submissionURL =
|
||||
engine.getSubmission(data.searchString, "", data.whence).uri.spec;
|
||||
gMsgMan.sendAsyncMessage(TEST_MSG, {
|
||||
mm.sendAsyncMessage(TEST_MSG, {
|
||||
type: "Search",
|
||||
data,
|
||||
expectedURL: submissionURL,
|
||||
});
|
||||
let msg = await waitForTestMsg("loadStopped");
|
||||
let msg = await waitForTestMsg(mm, "loadStopped");
|
||||
Assert.equal(msg.data.url, submissionURL, "Correct search page loaded");
|
||||
});
|
||||
|
||||
|
@ -130,7 +129,7 @@ add_task(async function searchInBackgroundTab() {
|
|||
// in another. In other words, it performs a search in a background tab. The
|
||||
// search page should be loaded in the same tab that performed the search, in
|
||||
// the background tab.
|
||||
await addTab();
|
||||
let { mm } = await addTab();
|
||||
let engine = Services.search.currentEngine;
|
||||
let data = {
|
||||
engineName: engine.name,
|
||||
|
@ -140,7 +139,7 @@ add_task(async function searchInBackgroundTab() {
|
|||
};
|
||||
let submissionURL =
|
||||
engine.getSubmission(data.searchString, "", data.whence).uri.spec;
|
||||
gMsgMan.sendAsyncMessage(TEST_MSG, {
|
||||
mm.sendAsyncMessage(TEST_MSG, {
|
||||
type: "Search",
|
||||
data,
|
||||
expectedURL: submissionURL,
|
||||
|
@ -150,16 +149,16 @@ add_task(async function searchInBackgroundTab() {
|
|||
gBrowser.selectedTab = newTab;
|
||||
registerCleanupFunction(() => gBrowser.removeTab(newTab));
|
||||
|
||||
let msg = await waitForTestMsg("loadStopped");
|
||||
let msg = await waitForTestMsg(mm, "loadStopped");
|
||||
Assert.equal(msg.data.url, submissionURL, "Correct search page loaded");
|
||||
});
|
||||
|
||||
add_task(async function badImage() {
|
||||
await addTab();
|
||||
let { mm } = await addTab();
|
||||
// If the bad image URI caused an exception to be thrown within ContentSearch,
|
||||
// then we'll hang waiting for the CurrentState responses triggered by the new
|
||||
// engine. That's what we're testing, and obviously it shouldn't happen.
|
||||
let vals = await waitForNewEngine("contentSearchBadImage.xml", 1);
|
||||
let vals = await waitForNewEngine(mm, "contentSearchBadImage.xml", 1);
|
||||
let engine = vals[0];
|
||||
let finalCurrentStateMsg = vals[vals.length - 1];
|
||||
let expectedCurrentState = await currentStateObj();
|
||||
|
@ -176,20 +175,20 @@ add_task(async function badImage() {
|
|||
// Removing the engine triggers a final CurrentState message. Wait for it so
|
||||
// it doesn't trip up subsequent tests.
|
||||
Services.search.removeEngine(engine);
|
||||
await waitForTestMsg("CurrentState");
|
||||
await waitForTestMsg(mm, "CurrentState");
|
||||
});
|
||||
|
||||
add_task(async function GetSuggestions_AddFormHistoryEntry_RemoveFormHistoryEntry() {
|
||||
await addTab();
|
||||
let { mm } = await addTab();
|
||||
|
||||
// Add the test engine that provides suggestions.
|
||||
let vals = await waitForNewEngine("contentSearchSuggestions.xml", 0);
|
||||
let vals = await waitForNewEngine(mm, "contentSearchSuggestions.xml", 0);
|
||||
let engine = vals[0];
|
||||
|
||||
let searchStr = "browser_ContentSearch.js-suggestions-";
|
||||
|
||||
// Add a form history suggestion and wait for Satchel to notify about it.
|
||||
gMsgMan.sendAsyncMessage(TEST_MSG, {
|
||||
mm.sendAsyncMessage(TEST_MSG, {
|
||||
type: "AddFormHistoryEntry",
|
||||
data: searchStr + "form",
|
||||
});
|
||||
|
@ -204,7 +203,7 @@ add_task(async function GetSuggestions_AddFormHistoryEntry_RemoveFormHistoryEntr
|
|||
|
||||
// Send GetSuggestions using the test engine. Its suggestions should appear
|
||||
// in the remote suggestions in the Suggestions response below.
|
||||
gMsgMan.sendAsyncMessage(TEST_MSG, {
|
||||
mm.sendAsyncMessage(TEST_MSG, {
|
||||
type: "GetSuggestions",
|
||||
data: {
|
||||
engineName: engine.name,
|
||||
|
@ -213,7 +212,7 @@ add_task(async function GetSuggestions_AddFormHistoryEntry_RemoveFormHistoryEntr
|
|||
});
|
||||
|
||||
// Check the Suggestions response.
|
||||
let msg = await waitForTestMsg("Suggestions");
|
||||
let msg = await waitForTestMsg(mm, "Suggestions");
|
||||
checkMsg(msg, {
|
||||
type: "Suggestions",
|
||||
data: {
|
||||
|
@ -225,7 +224,7 @@ add_task(async function GetSuggestions_AddFormHistoryEntry_RemoveFormHistoryEntr
|
|||
});
|
||||
|
||||
// Delete the form history suggestion and wait for Satchel to notify about it.
|
||||
gMsgMan.sendAsyncMessage(TEST_MSG, {
|
||||
mm.sendAsyncMessage(TEST_MSG, {
|
||||
type: "RemoveFormHistoryEntry",
|
||||
data: searchStr + "form",
|
||||
});
|
||||
|
@ -239,7 +238,7 @@ add_task(async function GetSuggestions_AddFormHistoryEntry_RemoveFormHistoryEntr
|
|||
await deferred.promise;
|
||||
|
||||
// Send GetSuggestions again.
|
||||
gMsgMan.sendAsyncMessage(TEST_MSG, {
|
||||
mm.sendAsyncMessage(TEST_MSG, {
|
||||
type: "GetSuggestions",
|
||||
data: {
|
||||
engineName: engine.name,
|
||||
|
@ -248,7 +247,7 @@ add_task(async function GetSuggestions_AddFormHistoryEntry_RemoveFormHistoryEntr
|
|||
});
|
||||
|
||||
// The formHistory suggestions in the Suggestions response should be empty.
|
||||
msg = await waitForTestMsg("Suggestions");
|
||||
msg = await waitForTestMsg(mm, "Suggestions");
|
||||
checkMsg(msg, {
|
||||
type: "Suggestions",
|
||||
data: {
|
||||
|
@ -261,7 +260,7 @@ add_task(async function GetSuggestions_AddFormHistoryEntry_RemoveFormHistoryEntr
|
|||
|
||||
// Finally, clean up by removing the test engine.
|
||||
Services.search.removeEngine(engine);
|
||||
await waitForTestMsg("CurrentState");
|
||||
await waitForTestMsg(mm, "CurrentState");
|
||||
});
|
||||
|
||||
function buffersEqual(actualArrayBuffer, expectedArrayBuffer) {
|
||||
|
@ -303,24 +302,20 @@ function checkMsg(actualMsg, expectedMsgData) {
|
|||
checkArrayBuffers(actualMsgData, expectedMsgData);
|
||||
}
|
||||
|
||||
function waitForMsg(name, type) {
|
||||
function waitForTestMsg(mm, type) {
|
||||
return new Promise(resolve => {
|
||||
info("Waiting for " + name + " message " + type + "...");
|
||||
gMsgMan.addMessageListener(name, function onMsg(msg) {
|
||||
info("Received " + name + " message " + msg.data.type + "\n");
|
||||
info("Waiting for " + TEST_MSG + " message " + type + "...");
|
||||
mm.addMessageListener(TEST_MSG, function onMsg(msg) {
|
||||
info("Received " + TEST_MSG + " message " + msg.data.type + "\n");
|
||||
if (msg.data.type == type) {
|
||||
gMsgMan.removeMessageListener(name, onMsg);
|
||||
mm.removeMessageListener(TEST_MSG, onMsg);
|
||||
resolve(msg);
|
||||
}
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
function waitForTestMsg(type) {
|
||||
return waitForMsg(TEST_MSG, type);
|
||||
}
|
||||
|
||||
function waitForNewEngine(basename, numImages) {
|
||||
function waitForNewEngine(mm, basename, numImages) {
|
||||
info("Waiting for engine to be added: " + basename);
|
||||
|
||||
// Wait for the search events triggered by adding the new engine.
|
||||
|
@ -330,7 +325,7 @@ function waitForNewEngine(basename, numImages) {
|
|||
for (let i = 0; i < numImages; i++) {
|
||||
expectedSearchEvents.push("CurrentState");
|
||||
}
|
||||
let eventPromises = expectedSearchEvents.map(e => waitForTestMsg(e));
|
||||
let eventPromises = expectedSearchEvents.map(e => waitForTestMsg(mm, e));
|
||||
|
||||
// Wait for addEngine().
|
||||
let addDeferred = PromiseUtils.defer();
|
||||
|
@ -354,8 +349,9 @@ async function addTab() {
|
|||
registerCleanupFunction(() => gBrowser.removeTab(tab));
|
||||
|
||||
let url = getRootDirectory(gTestPath) + TEST_CONTENT_SCRIPT_BASENAME;
|
||||
gMsgMan = tab.linkedBrowser.messageManager;
|
||||
gMsgMan.loadFrameScript(url, false);
|
||||
let mm = tab.linkedBrowser.messageManager;
|
||||
mm.loadFrameScript(url, false);
|
||||
return { browser: tab.linkedBrowser, mm };
|
||||
}
|
||||
|
||||
var currentStateObj = async function() {
|
||||
|
|
Загрузка…
Ссылка в новой задаче