michael@0: /* Any copyright is dedicated to the Public Domain. michael@0: * http://creativecommons.org/publicdomain/zero/1.0/ */ michael@0: michael@0: /* michael@0: * Test Google search plugin URLs michael@0: */ michael@0: michael@0: "use strict"; michael@0: michael@0: const BROWSER_SEARCH_PREF = "browser.search."; michael@0: michael@0: const MOZ_PARAM_LOCALE = /\{moz:locale\}/g; michael@0: const MOZ_PARAM_DIST_ID = /\{moz:distributionID\}/g; michael@0: const MOZ_PARAM_OFFICIAL = /\{moz:official\}/g; michael@0: michael@0: let runtime = Cc["@mozilla.org/xre/app-info;1"].getService(Ci.nsIXULRuntime); michael@0: // Custom search parameters michael@0: const MOZ_OFFICIAL = runtime.isOfficialBranding ? "official" : "unofficial"; michael@0: michael@0: var google_client; michael@0: switch (runtime.defaultUpdateChannel) { michael@0: case "beta": michael@0: google_client = "firefox-beta"; michael@0: break; michael@0: case "aurora": michael@0: google_client = "firefox-aurora"; michael@0: break; michael@0: case "nightly": michael@0: google_client = "firefox-nightly"; michael@0: break; michael@0: default: michael@0: google_client = "firefox-a"; michael@0: break; michael@0: } michael@0: michael@0: const GOOGLE_CLIENT = google_client; michael@0: const MOZ_DISTRIBUTION_ID = runtime.distributionID; michael@0: michael@0: function test() { michael@0: let engine = Services.search.getEngineByName("Google"); michael@0: ok(engine, "Google"); michael@0: michael@0: is(Services.search.defaultEngine, engine, "Check that Google is the default search engine"); michael@0: michael@0: let distributionID; michael@0: try { michael@0: distributionID = Services.prefs.getCharPref(BROWSER_SEARCH_PREF + "distributionID"); michael@0: } catch (ex) { michael@0: distributionID = MOZ_DISTRIBUTION_ID; michael@0: } michael@0: michael@0: let base = "https://www.google.com/search?q=foo&ie=utf-8&oe=utf-8&aq=t&rls={moz:distributionID}:{moz:locale}:{moz:official}&client=" + GOOGLE_CLIENT; michael@0: base = base.replace(MOZ_PARAM_LOCALE, getLocale()); michael@0: base = base.replace(MOZ_PARAM_DIST_ID, distributionID); michael@0: base = base.replace(MOZ_PARAM_OFFICIAL, MOZ_OFFICIAL); michael@0: michael@0: let url; michael@0: michael@0: // Test search URLs (including purposes). michael@0: url = engine.getSubmission("foo").uri.spec; michael@0: is(url, base, "Check search URL for 'foo'"); michael@0: url = engine.getSubmission("foo", null, "contextmenu").uri.spec; michael@0: is(url, base + "&channel=rcs", "Check context menu search URL for 'foo'"); michael@0: url = engine.getSubmission("foo", null, "keyword").uri.spec; michael@0: is(url, base + "&channel=fflb", "Check keyword search URL for 'foo'"); michael@0: url = engine.getSubmission("foo", null, "searchbar").uri.spec; michael@0: is(url, base + "&channel=sb", "Check search bar search URL for 'foo'"); michael@0: url = engine.getSubmission("foo", null, "homepage").uri.spec; michael@0: is(url, base + "&channel=np&source=hp", "Check homepage search URL for 'foo'"); michael@0: url = engine.getSubmission("foo", null, "newtab").uri.spec; michael@0: is(url, base + "&channel=nts", "Check newtab search URL for 'foo'"); michael@0: michael@0: // Check search suggestion URL. michael@0: url = engine.getSubmission("foo", "application/x-suggestions+json").uri.spec; michael@0: is(url, "https://www.google.com/complete/search?client=firefox&q=foo", "Check search suggestion URL for 'foo'"); michael@0: michael@0: // Check all other engine properties. michael@0: const EXPECTED_ENGINE = { michael@0: name: "Google", michael@0: alias: null, michael@0: description: "Google Search", michael@0: searchForm: "https://www.google.com/", michael@0: type: Ci.nsISearchEngine.TYPE_MOZSEARCH, michael@0: hidden: false, michael@0: wrappedJSObject: { michael@0: queryCharset: "UTF-8", michael@0: "_iconURL": "data:image/x-icon;base64,AAABAAIAEBAAAAAAAAB9AQAAJgAAACAgAAAAAAAA8gIAAKMBAACJUE5HDQoaCgAAAA1JSERSAAAAEAAAABAIBgAAAB/z/2EAAAFESURBVDjLpZNJSwNBEIXnt4lE4kHxovgT9BDwJHqPy0HEEOJBiAuCRg+KUdC4QS4KrpC4gCBGE3NQ48JsnZ6eZ3UOM6gjaePhQU93v6+qq2q0pqgeJj2S8EdJT1hr0OxBtKCD5iEd8QxDYpvhvOBAuMDKURX9C9aPu4GA1GEVkzvMg10UBfYveWAWgY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KBOa/f8wIpwi3X1G8UcxNu7ozUS7tiH0jBswwS3RIaF1w6LYKU/ML2+8sGnjygQswtKrVIy/Qd9qQP6LnO64q4fPAKpxyZIymHo1jWk6p1ag2BsdNwQMHcC+M5kHFJX+YlPxpVlbCx2mZ5DzPI04k4kUwHHdskU3pH76iftG8yWlkAAAAAElFTkSuQmCC", michael@0: _urls : [ michael@0: { michael@0: type: "application/x-suggestions+json", michael@0: method: "GET", michael@0: template: "https://www.google.com/complete/search?client=firefox&q={searchTerms}", michael@0: params: "", michael@0: }, michael@0: { michael@0: type: "text/html", michael@0: method: "GET", michael@0: template: "https://www.google.com/search", michael@0: params: [ michael@0: { michael@0: "name": "q", michael@0: "value": "{searchTerms}", michael@0: "purpose": undefined, michael@0: }, michael@0: { michael@0: "name": "ie", michael@0: "value": "utf-8", michael@0: "purpose": undefined, michael@0: }, michael@0: { michael@0: "name": "oe", michael@0: "value": "utf-8", michael@0: "purpose": undefined, michael@0: }, michael@0: { michael@0: "name": "aq", michael@0: "value": "t", michael@0: "purpose": undefined, michael@0: }, michael@0: { michael@0: "name": "rls", michael@0: "value": "{moz:distributionID}:{moz:locale}:{moz:official}", michael@0: "purpose": undefined, michael@0: }, michael@0: { michael@0: "name": "client", michael@0: "value": GOOGLE_CLIENT, michael@0: "purpose": undefined, michael@0: }, michael@0: { michael@0: "name": "channel", michael@0: "value": "rcs", michael@0: "purpose": "contextmenu", michael@0: }, michael@0: { michael@0: "name": "channel", michael@0: "value": "fflb", michael@0: "purpose": "keyword", michael@0: }, michael@0: { michael@0: "name": "channel", michael@0: "value": "sb", michael@0: "purpose": "searchbar", michael@0: }, michael@0: { michael@0: "name": "channel", michael@0: "value": "np", michael@0: "purpose": "homepage", michael@0: }, michael@0: { michael@0: "name": "channel", michael@0: "value": "nts", michael@0: "purpose": "newtab", michael@0: }, michael@0: { michael@0: "name": "source", michael@0: "value": "hp", michael@0: "purpose": "homepage", michael@0: }, michael@0: ], michael@0: mozparams: { michael@0: "client": { michael@0: "name": "client", michael@0: "falseValue": "firefox", michael@0: "trueValue": GOOGLE_CLIENT, michael@0: "condition": "defaultEngine", michael@0: "mozparam": true, michael@0: }, michael@0: }, michael@0: }, michael@0: { michael@0: type: "text/html", michael@0: method: "GET", michael@0: template: "https://www.google.com/", michael@0: }, michael@0: ], michael@0: }, michael@0: }; michael@0: michael@0: isSubObjectOf(EXPECTED_ENGINE, engine, "Google"); michael@0: }