mirror of
https://gitlab.winehq.org/wine/wine-gecko.git
synced 2024-09-13 09:24:08 -07:00
6e2a38d03c
Moves nsSidebar.js to toolkit and makes it just pass messages to chrome for each API call. MainProcessSingleton listens for those messages and passes the call along to the search service. Combines the validation code into the same function and takes the opportunity to support relative URLs too. Adds a bunch of tests for these web APIs. Also fixes: Bug 518929: Implement window.external APIs in core code Bug 530847: Remove Fennec's nsISidebar implementation once that code is moved into the core Bug 517720: Adding a search engine using relative URIs is not supported --HG-- rename : browser/components/sidebar/nsSidebar.js => toolkit/components/search/nsSidebar.js extra : rebase_source : 3e9caa49383e78e73e5f111ff09fb063f2cfa7c0
175 lines
6.7 KiB
JavaScript
175 lines
6.7 KiB
JavaScript
let ROOT = getRootDirectory(gTestPath).replace("chrome://mochitests/content", "http://example.com");
|
|
|
|
function AddSearchProvider(...args) {
|
|
return gBrowser.addTab(ROOT + "webapi.html?AddSearchProvider:" + encodeURIComponent(JSON.stringify(args)));
|
|
}
|
|
|
|
function addSearchEngine(...args) {
|
|
return gBrowser.addTab(ROOT + "webapi.html?addSearchEngine:" + encodeURIComponent(JSON.stringify(args)));
|
|
}
|
|
|
|
function promiseDialogOpened() {
|
|
return new Promise((resolve, reject) => {
|
|
Services.wm.addListener({
|
|
onOpenWindow: function(xulWin) {
|
|
Services.wm.removeListener(this);
|
|
|
|
let win = xulWin.QueryInterface(Ci.nsIInterfaceRequestor)
|
|
.getInterface(Ci.nsIDOMWindow);
|
|
waitForFocus(() => {
|
|
if (win.location == "chrome://global/content/commonDialog.xul")
|
|
resolve(win)
|
|
else
|
|
reject();
|
|
}, win);
|
|
}
|
|
});
|
|
});
|
|
}
|
|
|
|
add_task(function* test_working_AddSearchProvider() {
|
|
gBrowser.selectedTab = AddSearchProvider(ROOT + "testEngine.xml");
|
|
|
|
let dialog = yield promiseDialogOpened();
|
|
is(dialog.args.promptType, "confirmEx", "Should see the confirmation dialog.");
|
|
is(dialog.args.text, "Add \"Foo\" to the list of engines available in the search bar?\n\nFrom: example.com",
|
|
"Should have seen the right install message");
|
|
dialog.document.documentElement.cancelDialog();
|
|
|
|
gBrowser.removeCurrentTab();
|
|
});
|
|
|
|
add_task(function* test_HTTP_AddSearchProvider() {
|
|
gBrowser.selectedTab = AddSearchProvider(ROOT.replace("http:", "HTTP:") + "testEngine.xml");
|
|
|
|
let dialog = yield promiseDialogOpened();
|
|
is(dialog.args.promptType, "confirmEx", "Should see the confirmation dialog.");
|
|
is(dialog.args.text, "Add \"Foo\" to the list of engines available in the search bar?\n\nFrom: example.com",
|
|
"Should have seen the right install message");
|
|
dialog.document.documentElement.cancelDialog();
|
|
|
|
gBrowser.removeCurrentTab();
|
|
});
|
|
|
|
add_task(function* test_relative_AddSearchProvider() {
|
|
gBrowser.selectedTab = AddSearchProvider("testEngine.xml");
|
|
|
|
let dialog = yield promiseDialogOpened();
|
|
is(dialog.args.promptType, "confirmEx", "Should see the confirmation dialog.");
|
|
is(dialog.args.text, "Add \"Foo\" to the list of engines available in the search bar?\n\nFrom: example.com",
|
|
"Should have seen the right install message");
|
|
dialog.document.documentElement.cancelDialog();
|
|
|
|
gBrowser.removeCurrentTab();
|
|
});
|
|
|
|
add_task(function* test_invalid_AddSearchProvider() {
|
|
gBrowser.selectedTab = AddSearchProvider("z://foobar");
|
|
|
|
let dialog = yield promiseDialogOpened();
|
|
is(dialog.args.promptType, "alert", "Should see the alert dialog.");
|
|
is(dialog.args.text, "This search engine isn't supported by Nightly and can't be installed.",
|
|
"Should have seen the right error message")
|
|
dialog.document.documentElement.acceptDialog();
|
|
|
|
gBrowser.removeCurrentTab();
|
|
});
|
|
|
|
add_task(function* test_missing_AddSearchProvider() {
|
|
let url = ROOT + "foobar.xml";
|
|
gBrowser.selectedTab = AddSearchProvider(url);
|
|
|
|
let dialog = yield promiseDialogOpened();
|
|
is(dialog.args.promptType, "alert", "Should see the alert dialog.");
|
|
is(dialog.args.text, "Nightly could not download the search plugin from:\n" + url,
|
|
"Should have seen the right error message")
|
|
dialog.document.documentElement.acceptDialog();
|
|
|
|
gBrowser.removeCurrentTab();
|
|
});
|
|
|
|
add_task(function* test_working_addSearchEngine_xml() {
|
|
gBrowser.selectedTab = addSearchEngine(ROOT + "testEngine.xml", "", "", "");
|
|
|
|
let dialog = yield promiseDialogOpened();
|
|
is(dialog.args.promptType, "confirmEx", "Should see the confirmation dialog.");
|
|
is(dialog.args.text, "Add \"Foo\" to the list of engines available in the search bar?\n\nFrom: example.com",
|
|
"Should have seen the right install message");
|
|
dialog.document.documentElement.cancelDialog();
|
|
|
|
gBrowser.removeCurrentTab();
|
|
});
|
|
|
|
add_task(function* test_working_addSearchEngine_src() {
|
|
gBrowser.selectedTab = addSearchEngine(ROOT + "testEngine.src", "", "", "");
|
|
|
|
let dialog = yield promiseDialogOpened();
|
|
is(dialog.args.promptType, "confirmEx", "Should see the confirmation dialog.");
|
|
is(dialog.args.text, "Add \"Test Sherlock\" to the list of engines available in the search bar?\n\nFrom: example.com",
|
|
"Should have seen the right install message");
|
|
dialog.document.documentElement.cancelDialog();
|
|
|
|
gBrowser.removeCurrentTab();
|
|
});
|
|
|
|
add_task(function* test_relative_addSearchEngine_xml() {
|
|
gBrowser.selectedTab = addSearchEngine("testEngine.xml", "", "", "");
|
|
|
|
let dialog = yield promiseDialogOpened();
|
|
is(dialog.args.promptType, "confirmEx", "Should see the confirmation dialog.");
|
|
is(dialog.args.text, "Add \"Foo\" to the list of engines available in the search bar?\n\nFrom: example.com",
|
|
"Should have seen the right install message");
|
|
dialog.document.documentElement.cancelDialog();
|
|
|
|
gBrowser.removeCurrentTab();
|
|
});
|
|
|
|
add_task(function* test_relative_addSearchEngine_src() {
|
|
gBrowser.selectedTab = addSearchEngine("testEngine.src", "", "", "");
|
|
|
|
let dialog = yield promiseDialogOpened();
|
|
is(dialog.args.promptType, "confirmEx", "Should see the confirmation dialog.");
|
|
is(dialog.args.text, "Add \"Test Sherlock\" to the list of engines available in the search bar?\n\nFrom: example.com",
|
|
"Should have seen the right install message");
|
|
dialog.document.documentElement.cancelDialog();
|
|
|
|
gBrowser.removeCurrentTab();
|
|
});
|
|
|
|
add_task(function* test_invalid_addSearchEngine() {
|
|
gBrowser.selectedTab = addSearchEngine("z://foobar", "", "", "");
|
|
|
|
let dialog = yield promiseDialogOpened();
|
|
is(dialog.args.promptType, "alert", "Should see the alert dialog.");
|
|
is(dialog.args.text, "This search engine isn't supported by Nightly and can't be installed.",
|
|
"Should have seen the right error message")
|
|
dialog.document.documentElement.acceptDialog();
|
|
|
|
gBrowser.removeCurrentTab();
|
|
});
|
|
|
|
add_task(function* test_invalid_icon_addSearchEngine() {
|
|
gBrowser.selectedTab = addSearchEngine(ROOT + "testEngine.src", "z://foobar", "", "");
|
|
|
|
let dialog = yield promiseDialogOpened();
|
|
is(dialog.args.promptType, "alert", "Should see the alert dialog.");
|
|
is(dialog.args.text, "This search engine isn't supported by Nightly and can't be installed.",
|
|
"Should have seen the right error message")
|
|
dialog.document.documentElement.acceptDialog();
|
|
|
|
gBrowser.removeCurrentTab();
|
|
});
|
|
|
|
add_task(function* test_missing_addSearchEngine() {
|
|
let url = ROOT + "foobar.xml";
|
|
gBrowser.selectedTab = addSearchEngine(url, "", "", "");
|
|
|
|
let dialog = yield promiseDialogOpened();
|
|
is(dialog.args.promptType, "alert", "Should see the alert dialog.");
|
|
is(dialog.args.text, "Nightly could not download the search plugin from:\n" + url,
|
|
"Should have seen the right error message")
|
|
dialog.document.documentElement.acceptDialog();
|
|
|
|
gBrowser.removeCurrentTab();
|
|
});
|