forked from mirrors/gecko-dev
This is a rollup of all the patches that have landed on the cedar project branch:891252fdd0Bug 1492475 - Part 1: Migrate most, if not all nsSearchService consumers to use async APIs. r=florian79b2eb2367Bug 1492475 - Part 2: Move nsIBrowserSearchService.idl to toolkit/components/search/nsISearchService.idl and update references. r=floriana947d3cdf0Bug 1492475 - Part 3: The search service init() method should simply return a Promise. r=florianc1e172dfacBug 1492475 - Part 4: Remove the synchronous initialization flow. r=floriancd41189eacBug 1492475 - Part 5: Since async initialization of the search service now is implicit behavior, remove the distinctive verbiage used internally. r=florian2ae7189dfaBug 1492475 - Part 6: Update the cache build task to work with an actual Promise and re-initialize only once at the same time - all to fix race conditions here. r=florianc8ee92973fBug 1492475 - Part 7: Make the region fetch not block the init flow, to ensure it's as fast as possible. r=florianc44e674e16Bug 1492475 - Part 8: Introduce an init flag, which can only be used privately, that allows to explicitly skip waiting for the region check process to complete. r=florian6c79eaf1d3Bug 1492475 - Part 9: Update unit tests to stop using 'currentEngine', in favor of 'defaultEngine'. r=Standard821b3aa17eeBug 1492475 - Part 10: Update unit tests to be fully aware of the new, async signatures of the search service API and remove sync init flow tests. r=mkaply,floriance5ba69019Bug 1492475 - Part 11: Repair incorrect usage of the `identifier` property of nsISearchEngine instances. r=florianfd177a7994Bug 1518543 - Fix up the Android (Fennec) nsISearchService shim to work with the new asynchronous API. r=florian3653d8ee22Bug 1523708 - Change the search service interaction in the show-heartbeat action to use the new async API. r=florian Differential Revision: https://phabricator.services.mozilla.com/D18355 --HG-- rename : netwerk/base/nsIBrowserSearchService.idl => toolkit/components/search/nsISearchService.idl extra : moz-landing-system : lando
185 lines
6 KiB
JavaScript
185 lines
6 KiB
JavaScript
const ANY_URL = undefined;
|
|
|
|
registerCleanupFunction(async function cleanup() {
|
|
while (gBrowser.tabs.length > 1) {
|
|
BrowserTestUtils.removeTab(gBrowser.tabs[gBrowser.tabs.length - 1]);
|
|
}
|
|
await Services.search.setDefault(originalEngine);
|
|
let engine = Services.search.getEngineByName("MozSearch");
|
|
await Services.search.removeEngine(engine);
|
|
});
|
|
|
|
let originalEngine;
|
|
add_task(async function test_setup() {
|
|
// Stop search-engine loads from hitting the network
|
|
await Services.search.addEngineWithDetails("MozSearch", "", "", "", "GET",
|
|
"http://example.com/?q={searchTerms}");
|
|
let engine = Services.search.getEngineByName("MozSearch");
|
|
originalEngine = await Services.search.getDefault();
|
|
await Services.search.setDefault(engine);
|
|
});
|
|
|
|
add_task(async function single_url() {
|
|
await dropText("mochi.test/first",
|
|
["http://www.mochi.test/first"]);
|
|
});
|
|
add_task(async function single_javascript() {
|
|
await dropText("javascript:'bad'", []);
|
|
});
|
|
add_task(async function single_javascript_capital() {
|
|
await dropText("jAvascript:'bad'", []);
|
|
});
|
|
add_task(async function single_search() {
|
|
await dropText("search this",
|
|
[ANY_URL]);
|
|
});
|
|
add_task(async function single_url2() {
|
|
await dropText("mochi.test/second",
|
|
["http://www.mochi.test/second"]);
|
|
});
|
|
add_task(async function single_data_url() {
|
|
await dropText("data:text/html,bad", []);
|
|
});
|
|
add_task(async function single_url3() {
|
|
await dropText("mochi.test/third",
|
|
["http://www.mochi.test/third"]);
|
|
});
|
|
|
|
// Single text/plain item, with multiple links.
|
|
add_task(async function multiple_urls() {
|
|
await dropText("mochi.test/1\nmochi.test/2",
|
|
[
|
|
"http://www.mochi.test/1",
|
|
"http://www.mochi.test/2",
|
|
]);
|
|
});
|
|
add_task(async function multiple_urls_javascript() {
|
|
await dropText("javascript:'bad1'\nmochi.test/3", []);
|
|
});
|
|
add_task(async function multiple_urls_data() {
|
|
await dropText("mochi.test/4\ndata:text/html,bad1", []);
|
|
});
|
|
|
|
// Multiple text/plain items, with single and multiple links.
|
|
add_task(async function multiple_items_single_and_multiple_links() {
|
|
await drop([[{type: "text/plain",
|
|
data: "mochi.test/5"}],
|
|
[{type: "text/plain",
|
|
data: "mochi.test/6\nmochi.test/7"}]],
|
|
[
|
|
"http://www.mochi.test/5",
|
|
"http://www.mochi.test/6",
|
|
"http://www.mochi.test/7",
|
|
]);
|
|
});
|
|
|
|
// Single text/x-moz-url item, with multiple links.
|
|
// "text/x-moz-url" has titles in even-numbered lines.
|
|
add_task(async function single_moz_url_multiple_links() {
|
|
await drop([[{type: "text/x-moz-url",
|
|
data: "mochi.test/8\nTITLE8\nmochi.test/9\nTITLE9"}]],
|
|
[
|
|
"http://www.mochi.test/8",
|
|
"http://www.mochi.test/9",
|
|
]);
|
|
});
|
|
|
|
// Single item with multiple types.
|
|
add_task(async function single_item_multiple_types() {
|
|
await drop([[{type: "text/plain",
|
|
data: "mochi.test/10"},
|
|
{type: "text/x-moz-url",
|
|
data: "mochi.test/11\nTITLE11"}]],
|
|
["http://www.mochi.test/11"]);
|
|
});
|
|
|
|
// Warn when too many URLs are dropped.
|
|
add_task(async function multiple_tabs_under_max() {
|
|
let urls = [];
|
|
for (let i = 0; i < 5; i++) {
|
|
urls.push("mochi.test/multi" + i);
|
|
}
|
|
await dropText(urls.join("\n"),
|
|
[
|
|
"http://www.mochi.test/multi0",
|
|
"http://www.mochi.test/multi1",
|
|
"http://www.mochi.test/multi2",
|
|
"http://www.mochi.test/multi3",
|
|
"http://www.mochi.test/multi4",
|
|
]);
|
|
});
|
|
add_task(async function multiple_tabs_over_max_accept() {
|
|
await pushPrefs(["browser.tabs.maxOpenBeforeWarn", 4]);
|
|
|
|
let confirmPromise = BrowserTestUtils.promiseAlertDialog("accept");
|
|
|
|
let urls = [];
|
|
for (let i = 0; i < 5; i++) {
|
|
urls.push("mochi.test/accept" + i);
|
|
}
|
|
await dropText(urls.join("\n"),
|
|
[
|
|
"http://www.mochi.test/accept0",
|
|
"http://www.mochi.test/accept1",
|
|
"http://www.mochi.test/accept2",
|
|
"http://www.mochi.test/accept3",
|
|
"http://www.mochi.test/accept4",
|
|
]);
|
|
|
|
await confirmPromise;
|
|
|
|
await popPrefs();
|
|
});
|
|
add_task(async function multiple_tabs_over_max_cancel() {
|
|
await pushPrefs(["browser.tabs.maxOpenBeforeWarn", 4]);
|
|
|
|
let confirmPromise = BrowserTestUtils.promiseAlertDialog("cancel");
|
|
|
|
let urls = [];
|
|
for (let i = 0; i < 5; i++) {
|
|
urls.push("mochi.test/cancel" + i);
|
|
}
|
|
await dropText(urls.join("\n"), []);
|
|
|
|
await confirmPromise;
|
|
|
|
await popPrefs();
|
|
});
|
|
|
|
function dropText(text, expectedURLs) {
|
|
return drop([[{type: "text/plain", data: text}]], expectedURLs);
|
|
}
|
|
|
|
async function drop(dragData, expectedURLs) {
|
|
let dragDataString = JSON.stringify(dragData);
|
|
info(`Starting test for dragData:${dragDataString}; expectedURLs.length:${expectedURLs.length}`);
|
|
let EventUtils = {};
|
|
Services.scriptloader.loadSubScript("chrome://mochikit/content/tests/SimpleTest/EventUtils.js", EventUtils);
|
|
|
|
let awaitDrop = BrowserTestUtils.waitForEvent(gBrowser.tabContainer, "drop");
|
|
|
|
let loadedPromises = expectedURLs.map(
|
|
url => BrowserTestUtils.waitForNewTab(gBrowser, url, false, true));
|
|
|
|
// A drop type of "link" onto an existing tab would normally trigger a
|
|
// load in that same tab, but tabbrowser code in _getDragTargetTab treats
|
|
// drops on the outer edges of a tab differently (loading a new tab
|
|
// instead). Make events created by synthesizeDrop have all of their
|
|
// coordinates set to 0 (screenX/screenY), so they're treated as drops
|
|
// on the outer edge of the tab, thus they open new tabs.
|
|
var event = {
|
|
clientX: 0,
|
|
clientY: 0,
|
|
screenX: 0,
|
|
screenY: 0,
|
|
};
|
|
EventUtils.synthesizeDrop(gBrowser.selectedTab, gBrowser.selectedTab, dragData, "link", window, undefined, event);
|
|
|
|
let tabs = await Promise.all(loadedPromises);
|
|
for (let tab of tabs) {
|
|
BrowserTestUtils.removeTab(tab);
|
|
}
|
|
|
|
await awaitDrop;
|
|
ok(true, "Got drop event");
|
|
}
|