diff options
author | Matt A. Tobin <mattatobin@localhost.localdomain> | 2018-02-02 04:16:08 -0500 |
---|---|---|
committer | Matt A. Tobin <mattatobin@localhost.localdomain> | 2018-02-02 04:16:08 -0500 |
commit | 5f8de423f190bbb79a62f804151bc24824fa32d8 (patch) | |
tree | 10027f336435511475e392454359edea8e25895d /browser/components/search/test/browser_contextmenu.js | |
parent | 49ee0794b5d912db1f95dce6eb52d781dc210db5 (diff) | |
download | UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.tar UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.tar.gz UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.tar.lz UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.tar.xz UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.zip |
Add m-esr52 at 52.6.0
Diffstat (limited to 'browser/components/search/test/browser_contextmenu.js')
-rw-r--r-- | browser/components/search/test/browser_contextmenu.js | 101 |
1 files changed, 101 insertions, 0 deletions
diff --git a/browser/components/search/test/browser_contextmenu.js b/browser/components/search/test/browser_contextmenu.js new file mode 100644 index 000000000..c485242b4 --- /dev/null +++ b/browser/components/search/test/browser_contextmenu.js @@ -0,0 +1,101 @@ +/* Any copyright is dedicated to the Public Domain. + * * http://creativecommons.org/publicdomain/zero/1.0/ */ +/* + * Test searching for the selected text using the context menu + */ + +add_task(function* () { + const ss = Services.search; + const ENGINE_NAME = "Foo"; + var contextMenu; + + // We want select events to be fired. + yield new Promise(resolve => SpecialPowers.pushPrefEnv({"set": [["dom.select_events.enabled", true]]}, resolve)); + + let envService = Cc["@mozilla.org/process/environment;1"].getService(Ci.nsIEnvironment); + let originalValue = envService.get("XPCSHELL_TEST_PROFILE_DIR"); + envService.set("XPCSHELL_TEST_PROFILE_DIR", "1"); + + let url = "chrome://mochitests/content/browser/browser/components/search/test/"; + let resProt = Services.io.getProtocolHandler("resource") + .QueryInterface(Ci.nsIResProtocolHandler); + let originalSubstitution = resProt.getSubstitution("search-plugins"); + resProt.setSubstitution("search-plugins", + Services.io.newURI(url, null, null)); + + let searchDonePromise; + yield new Promise(resolve => { + function observer(aSub, aTopic, aData) { + switch (aData) { + case "engine-added": + var engine = ss.getEngineByName(ENGINE_NAME); + ok(engine, "Engine was added."); + ss.currentEngine = engine; + envService.set("XPCSHELL_TEST_PROFILE_DIR", originalValue); + resProt.setSubstitution("search-plugins", originalSubstitution); + break; + case "engine-current": + is(ss.currentEngine.name, ENGINE_NAME, "currentEngine set"); + resolve(); + break; + case "engine-removed": + Services.obs.removeObserver(observer, "browser-search-engine-modified"); + if (searchDonePromise) { + searchDonePromise(); + } + break; + } + } + + Services.obs.addObserver(observer, "browser-search-engine-modified", false); + ss.addEngine("resource://search-plugins/testEngine_mozsearch.xml", + null, "data:image/x-icon,%00", false); + }); + + contextMenu = document.getElementById("contentAreaContextMenu"); + ok(contextMenu, "Got context menu XUL"); + + let tab = yield BrowserTestUtils.openNewForegroundTab(gBrowser, "data:text/plain;charset=utf8,test%20search"); + + yield ContentTask.spawn(tab.linkedBrowser, "", function*() { + return new Promise(resolve => { + content.document.addEventListener("selectionchange", function selectionChanged() { + content.document.removeEventListener("selectionchange", selectionChanged); + resolve(); + }); + content.document.getSelection().selectAllChildren(content.document.body); + }); + }); + + var eventDetails = { type: "contextmenu", button: 2 }; + + let popupPromise = BrowserTestUtils.waitForEvent(contextMenu, "popupshown"); + BrowserTestUtils.synthesizeMouseAtCenter("body", eventDetails, gBrowser.selectedBrowser); + yield popupPromise; + + info("checkContextMenu"); + var searchItem = contextMenu.getElementsByAttribute("id", "context-searchselect")[0]; + ok(searchItem, "Got search context menu item"); + is(searchItem.label, 'Search ' + ENGINE_NAME + ' for \u201ctest search\u201d', "Check context menu label"); + is(searchItem.disabled, false, "Check that search context menu item is enabled"); + + yield BrowserTestUtils.openNewForegroundTab(gBrowser, () => { + searchItem.click(); + }); + + is(gBrowser.currentURI.spec, + "http://mochi.test:8888/browser/browser/components/search/test/?test=test+search&ie=utf-8&channel=contextsearch", + "Checking context menu search URL"); + + contextMenu.hidePopup(); + + // Remove the tab opened by the search + gBrowser.removeCurrentTab(); + + yield new Promise(resolve => { + searchDonePromise = resolve; + ss.removeEngine(ss.currentEngine); + }); + + gBrowser.removeCurrentTab(); +}); |