diff --git a/browser/base/content/browser-context.inc b/browser/base/content/browser-context.inc index d4fd052879de..875cfaf5c96f 100644 --- a/browser/base/content/browser-context.inc +++ b/browser/base/content/browser-context.inc @@ -261,7 +261,8 @@ accesskey="&keywordfield.accesskey;" oncommand="AddKeywordForSearchField();"/> + oncommand="BrowserSearch.loadSearch(getBrowserSelection(), true, + 'application/x-moz-contextsearch');"/> diff --git a/browser/base/content/browser.js b/browser/base/content/browser.js index 57c80d8c03c3..e59319f098ff 100644 --- a/browser/base/content/browser.js +++ b/browser/base/content/browser.js @@ -3525,8 +3525,13 @@ const BrowserSearch = { * @param useNewTab * Boolean indicating whether or not the search should load in a new * tab. + * + * @param responseType [optional] + * The MIME type that we'd like to receive in response + * to this submission. If null or the the response type is not supported + * for the search engine, will fallback to "text/html". */ - loadSearch: function BrowserSearch_search(searchText, useNewTab) { + loadSearch: function BrowserSearch_search(searchText, useNewTab, responseType) { var engine; // If the search bar is visible, use the current engine, otherwise, fall @@ -3536,7 +3541,12 @@ const BrowserSearch = { else engine = Services.search.defaultEngine; - var submission = engine.getSubmission(searchText); // HTML response + var submission = engine.getSubmission(searchText, responseType); + + // If a response type was specified and getSubmission returned null, + // fallback to the default response type. + if (!submission && responseType) + submission = engine.getSubmission(searchText); // getSubmission can return null if the engine doesn't have a URL // with a text/html response type. This is unlikely (since diff --git a/browser/base/content/test/browser_canonizeURL.js b/browser/base/content/test/browser_canonizeURL.js index b544416f96fa..10cf50aada6c 100644 --- a/browser/base/content/test/browser_canonizeURL.js +++ b/browser/base/content/test/browser_canonizeURL.js @@ -17,7 +17,7 @@ var pairs = [ ["1.1.1.1", "http://1.1.1.1/"], ["ftp://example", "ftp://example/"], ["ftp.example.bar", "ftp://ftp.example.bar/"], - ["ex ample", Services.search.originalDefaultEngine.getSubmission("ex ample").uri.spec], + ["ex ample", Services.search.originalDefaultEngine.getSubmission("ex ample", "application/x-moz-keywordsearch").uri.spec], ]; function testNext() { diff --git a/browser/base/content/test/browser_keywordSearch.js b/browser/base/content/test/browser_keywordSearch.js index 38ed7ae48e4b..8a7dbd4ea0ee 100644 --- a/browser/base/content/test/browser_keywordSearch.js +++ b/browser/base/content/test/browser_keywordSearch.js @@ -7,12 +7,12 @@ var gTests = [ { name: "normal search (search service)", testText: "test search", - searchURL: Services.search.originalDefaultEngine.getSubmission("test search").uri.spec + searchURL: Services.search.originalDefaultEngine.getSubmission("test search", "application/x-moz-keywordsearch").uri.spec }, { name: "?-prefixed search (search service)", testText: "? foo ", - searchURL: Services.search.originalDefaultEngine.getSubmission("foo").uri.spec + searchURL: Services.search.originalDefaultEngine.getSubmission("foo", "application/x-moz-keywordsearch").uri.spec }, { name: "normal search (keyword.url)", diff --git a/browser/components/search/test/Makefile.in b/browser/components/search/test/Makefile.in index 1fe01b3f2d90..d7f84a2233f0 100644 --- a/browser/components/search/test/Makefile.in +++ b/browser/components/search/test/Makefile.in @@ -46,7 +46,9 @@ include $(topsrcdir)/config/rules.mk _BROWSER_TEST_FILES = browser_405664.js \ browser_addEngine.js \ + browser_contextmenu.js \ testEngine.xml \ + testEngine_mozsearch.xml \ testEngine.src \ browser_426329.js \ 426329.xml \ diff --git a/browser/components/search/test/browser_426329.js b/browser/components/search/test/browser_426329.js index 8e1b6c5545af..5a54d5def03f 100644 --- a/browser/components/search/test/browser_426329.js +++ b/browser/components/search/test/browser_426329.js @@ -8,6 +8,8 @@ this._scriptLoader.loadSubScript("chrome://mochikit/content/tests/SimpleTest/Chr function test() { waitForExplicitFinish(); + const ENGINE_HTML_BASE = "http://mochi.test:8888/browser/browser/components/search/test/test.html"; + var searchEntries = ["test", "More Text", "Some Text"]; var searchBar = BrowserSearch.searchBar; var searchButton = document.getAnonymousElementByAttribute(searchBar, @@ -57,6 +59,7 @@ function test() { is(gBrowser.tabs.length, preTabNo, "Return key did not open new tab"); is(event.originalTarget, preSelectedBrowser.contentDocument, "Return key loaded results in current tab"); + is(event.originalTarget.URL, expectedURL(searchBar.value), "Check URL of search page opened"); testAltReturn(); }); @@ -72,6 +75,7 @@ function test() { "Alt+Return key loaded results in new tab"); is(event.originalTarget, gBrowser.contentDocument, "Alt+Return key loaded results in foreground tab"); + is(event.originalTarget.URL, expectedURL(searchBar.value), "Check URL of search page opened"); //Shift key has no effect for now, so skip it //testShiftAltReturn(); @@ -89,6 +93,7 @@ function test() { "Shift+Alt+Return key loaded results in new tab"); isnot(event.originalTarget, gBrowser.contentDocument, "Shift+Alt+Return key loaded results in background tab"); + is(event.originalTarget.URL, expectedURL(searchBar.value), "Check URL of search page opened"); testLeftClick(); }); @@ -102,6 +107,7 @@ function test() { is(gBrowser.tabs.length, preTabNo, "LeftClick did not open new tab"); is(event.originalTarget, preSelectedBrowser.contentDocument, "LeftClick loaded results in current tab"); + is(event.originalTarget.URL, expectedURL(searchBar.value), "Check URL of search page opened"); testMiddleClick(); }); @@ -117,6 +123,7 @@ function test() { "MiddleClick loaded results in new tab"); is(event.originalTarget, gBrowser.contentDocument, "MiddleClick loaded results in foreground tab"); + is(event.originalTarget.URL, expectedURL(searchBar.value), "Check URL of search page opened"); testShiftMiddleClick(); }); @@ -132,6 +139,7 @@ function test() { "Shift+MiddleClick loaded results in new tab"); isnot(event.originalTarget, gBrowser.contentDocument, "Shift+MiddleClick loaded results in background tab"); + is(event.originalTarget.URL, expectedURL(searchBar.value), "Check URL of search page opened"); testDropText(); }); @@ -232,6 +240,13 @@ function test() { aTarget.dispatchEvent(event); } + function expectedURL(aSearchTerms) { + var textToSubURI = Cc["@mozilla.org/intl/texttosuburi;1"]. + getService(Ci.nsITextToSubURI); + var searchArg = textToSubURI.ConvertAndEscape("utf-8", aSearchTerms); + return ENGINE_HTML_BASE + "?test=" + searchArg; + } + // modified from toolkit/components/satchel/test/test_form_autocomplete.html function checkMenuEntries(expectedValues) { var actualValues = getMenuEntries(); diff --git a/browser/components/search/test/browser_contextmenu.js b/browser/components/search/test/browser_contextmenu.js new file mode 100644 index 000000000000..1151d68f0966 --- /dev/null +++ b/browser/components/search/test/browser_contextmenu.js @@ -0,0 +1,97 @@ +/* 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 + */ + +function test() { + waitForExplicitFinish(); + + const ss = Services.search; + const ENGINE_NAME = "Foo"; + var contextMenu; + + function observer(aSub, aTopic, aData) { + switch (aData) { + case "engine-added": + var engine = ss.getEngineByName(ENGINE_NAME); + ok(engine, "Engine was added."); + //XXX Bug 493051 + //ss.currentEngine = engine; + break; + case "engine-current": + ok(ss.currentEngine.name == ENGINE_NAME, "currentEngine set"); + startTest(); + break; + case "engine-removed": + Services.obs.removeObserver(observer, "browser-search-engine-modified"); + finish(); + break; + } + } + + Services.obs.addObserver(observer, "browser-search-engine-modified", false); + ss.addEngine("http://mochi.test:8888/browser/browser/components/search/test/testEngine_mozsearch.xml", + Ci.nsISearchEngine.DATA_XML, "data:image/x-icon,%00", + false); + + function startTest() { + contextMenu = document.getElementById("contentAreaContextMenu"); + ok(contextMenu, "Got context menu XUL"); + + doOnloadOnce(testContextMenu); + var tab = gBrowser.addTab("data:text/plain,test%20search"); + gBrowser.selectedTab = tab; + } + + function testContextMenu() { + function rightClickOnDocument(){ + var clickTarget = content.document.body; + var eventDetails = { type: "contextmenu", button: 2 }; + EventUtils.synthesizeMouseAtCenter(clickTarget, eventDetails, content); + SimpleTest.executeSoon(checkContextMenu); + } + + // check the search menu item and then perform a search + function checkContextMenu() { + var searchItem = contextMenu.getElementsByAttribute("id", "context-searchselect")[0]; + ok(searchItem, "Got search context menu item"); + is(searchItem.label, 'Search ' + ENGINE_NAME + ' for "test search"', "Check context menu label"); + is(searchItem.disabled, false, "Check that search context menu item is enabled"); + searchItem.click(); + } + + function checkSearchURL(event){ + is(event.originalTarget.URL, + "http://mochi.test:8888/browser/browser/components/search/test/?test=test+search&ie=utf-8&client=app&channel=contextsearch", + "Checking context menu search URL"); + finalize(); + } + + doOnloadOnce(checkSearchURL); + + // select the text on the page + var selectAllItem = contextMenu.getElementsByAttribute("id", "context-selectall")[0]; + ok(selectAllItem, "Got select all context menu item"); + selectAllItem.click(); + + // wait for the selection to take effect + SimpleTest.executeSoon(rightClickOnDocument); + } + + function finalize() { + while (gBrowser.tabs.length != 1) { + gBrowser.removeTab(gBrowser.tabs[0]); + } + content.location.href = "about:blank"; + var engine = ss.getEngineByName(ENGINE_NAME); + ss.removeEngine(engine); + } + + function doOnloadOnce(callback) { + gBrowser.addEventListener("DOMContentLoaded", function handleLoad(event) { + gBrowser.removeEventListener("DOMContentLoaded", handleLoad, true); + callback(event); + }, true); + } +} diff --git a/browser/components/search/test/testEngine_mozsearch.xml b/browser/components/search/test/testEngine_mozsearch.xml new file mode 100644 index 000000000000..bb64aa131b15 --- /dev/null +++ b/browser/components/search/test/testEngine_mozsearch.xml @@ -0,0 +1,25 @@ + + Foo + Foo Search + utf-8 + data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAIAAACQkWg2AAABGklEQVQoz2NgGB6AnZ1dUlJSXl4eSDIyMhLW4Ovr%2B%2Fr168uXL69Zs4YoG%2BLi4i5dusTExMTGxsbNzd3f37937976%2BnpmZmagbHR09J49e5YvX66kpATVEBYW9ubNm2nTphkbG7e2tp44cQLIuHfvXm5urpaWFlDKysqqu7v73LlzECMYIiIiHj58mJCQoKKicvXq1bS0NKBgW1vbjh074uPjgeqAXE1NzSdPnvDz84M0AEUvXLgAsW379u1z5swBen3jxo2zZ892cHB4%2BvQp0KlAfwI1cHJyghQFBwfv2rULokFXV%2FfixYu7d%2B8GGqGgoMDKyrpu3br9%2B%2FcDuXl5eVA%2FAEWBfoWHAdAYoNuAYQ0XAeoUERFhGDYAAPoUaT2dfWJuAAAAAElFTkSuQmCC + + + + + + + + + + + + + + + + + + + http://mochi.test:8888/browser/browser/components/search/test/ + diff --git a/browser/locales/en-US/searchplugins/google-params.inc b/browser/locales/en-US/searchplugins/google-params.inc new file mode 100644 index 000000000000..1764477c8f88 --- /dev/null +++ b/browser/locales/en-US/searchplugins/google-params.inc @@ -0,0 +1,15 @@ + + + + + + +#if MOZ_UPDATE_CHANNEL == beta + +#elif MOZ_UPDATE_CHANNEL == aurora + +#elif MOZ_UPDATE_CHANNEL == nightly + +#else + +#endif diff --git a/browser/locales/en-US/searchplugins/google.xml b/browser/locales/en-US/searchplugins/google.xml index 68baf25e1d5b..3e6794c39e48 100644 --- a/browser/locales/en-US/searchplugins/google.xml +++ b/browser/locales/en-US/searchplugins/google.xml @@ -5,21 +5,17 @@ data:image/png;base64,AAABAAEAEBAAAAEAGABoAwAAFgAAACgAAAAQAAAAIAAAAAEAGAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAADs9Pt8xetPtu9FsfFNtu%2BTzvb2%2B%2Fne4dFJeBw0egA%2FfAJAfAA8ewBBegAAAAD%2B%2FPtft98Mp%2BwWsfAVsvEbs%2FQeqvF8xO7%2F%2F%2F63yqkxdgM7gwE%2FggM%2BfQA%2BegBDeQDe7PIbotgQufcMufEPtfIPsvAbs%2FQvq%2Bfz%2Bf%2F%2B%2B%2FZKhR05hgBBhQI8hgBAgAI9ewD0%2B%2Fg3pswAtO8Cxf4Kw%2FsJvvYAqupKsNv%2B%2Fv7%2F%2FP5VkSU0iQA7jQA9hgBDgQU%2BfQH%2F%2Ff%2FQ6fM4sM4KsN8AteMCruIqqdbZ7PH8%2Fv%2Fg6Nc%2Fhg05kAA8jAM9iQI%2BhQA%2BgQDQu6b97uv%2F%2F%2F7V8Pqw3eiWz97q8%2Ff%2F%2F%2F%2F7%2FPptpkkqjQE4kwA7kAA5iwI8iAA8hQCOSSKdXjiyflbAkG7u2s%2F%2B%2F%2F39%2F%2F7r8utrqEYtjQE8lgA7kwA7kwA9jwA9igA9hACiWSekVRyeSgiYSBHx6N%2F%2B%2Fv7k7OFRmiYtlAA5lwI7lwI4lAA7kgI9jwE9iwI4iQCoVhWcTxCmb0K%2BooT8%2Fv%2F7%2F%2F%2FJ2r8fdwI1mwA3mQA3mgA8lAE8lAE4jwA9iwE%2BhwGfXifWvqz%2B%2Ff%2F58u%2Fev6Dt4tr%2B%2F%2F2ZuIUsggA7mgM6mAM3lgA5lgA6kQE%2FkwBChwHt4dv%2F%2F%2F728ei1bCi7VAC5XQ7kz7n%2F%2F%2F6bsZkgcB03lQA9lgM7kwA2iQktZToPK4r9%2F%2F%2F9%2F%2F%2FSqYK5UwDKZAS9WALIkFn%2B%2F%2F3%2F%2BP8oKccGGcIRJrERILYFEMwAAuEAAdX%2F%2Ff7%2F%2FP%2B%2BfDvGXQLIZgLEWgLOjlf7%2F%2F%2F%2F%2F%2F9QU90EAPQAAf8DAP0AAfMAAOUDAtr%2F%2F%2F%2F7%2B%2Fu2bCTIYwDPZgDBWQDSr4P%2F%2Fv%2F%2F%2FP5GRuABAPkAA%2FwBAfkDAPAAAesAAN%2F%2F%2B%2Fz%2F%2F%2F64g1C5VwDMYwK8Yg7y5tz8%2Fv%2FV1PYKDOcAAP0DAf4AAf0AAfYEAOwAAuAAAAD%2F%2FPvi28ymXyChTATRrIb8%2F%2F3v8fk6P8MAAdUCAvoAAP0CAP0AAfYAAO4AAACAAQAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAACAAQAA - - - - - - -#if MOZ_UPDATE_CHANNEL == beta - -#elif MOZ_UPDATE_CHANNEL == aurora - -#elif MOZ_UPDATE_CHANNEL == nightly - -#else - -#endif +#include google-params.inc + + + +#include google-params.inc + + + + +#include google-params.inc + http://www.google.com/