browser/components/search/test/browser_google.js

Wed, 31 Dec 2014 06:09:35 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:09:35 +0100
changeset 0
6474c204b198
permissions
-rw-r--r--

Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.

michael@0 1 /* Any copyright is dedicated to the Public Domain.
michael@0 2 * http://creativecommons.org/publicdomain/zero/1.0/ */
michael@0 3
michael@0 4 /*
michael@0 5 * Test Google search plugin URLs
michael@0 6 */
michael@0 7
michael@0 8 "use strict";
michael@0 9
michael@0 10 const BROWSER_SEARCH_PREF = "browser.search.";
michael@0 11
michael@0 12 const MOZ_PARAM_LOCALE = /\{moz:locale\}/g;
michael@0 13 const MOZ_PARAM_DIST_ID = /\{moz:distributionID\}/g;
michael@0 14 const MOZ_PARAM_OFFICIAL = /\{moz:official\}/g;
michael@0 15
michael@0 16 let runtime = Cc["@mozilla.org/xre/app-info;1"].getService(Ci.nsIXULRuntime);
michael@0 17 // Custom search parameters
michael@0 18 const MOZ_OFFICIAL = runtime.isOfficialBranding ? "official" : "unofficial";
michael@0 19
michael@0 20 var google_client;
michael@0 21 switch (runtime.defaultUpdateChannel) {
michael@0 22 case "beta":
michael@0 23 google_client = "firefox-beta";
michael@0 24 break;
michael@0 25 case "aurora":
michael@0 26 google_client = "firefox-aurora";
michael@0 27 break;
michael@0 28 case "nightly":
michael@0 29 google_client = "firefox-nightly";
michael@0 30 break;
michael@0 31 default:
michael@0 32 google_client = "firefox-a";
michael@0 33 break;
michael@0 34 }
michael@0 35
michael@0 36 const GOOGLE_CLIENT = google_client;
michael@0 37 const MOZ_DISTRIBUTION_ID = runtime.distributionID;
michael@0 38
michael@0 39 function test() {
michael@0 40 let engine = Services.search.getEngineByName("Google");
michael@0 41 ok(engine, "Google");
michael@0 42
michael@0 43 is(Services.search.defaultEngine, engine, "Check that Google is the default search engine");
michael@0 44
michael@0 45 let distributionID;
michael@0 46 try {
michael@0 47 distributionID = Services.prefs.getCharPref(BROWSER_SEARCH_PREF + "distributionID");
michael@0 48 } catch (ex) {
michael@0 49 distributionID = MOZ_DISTRIBUTION_ID;
michael@0 50 }
michael@0 51
michael@0 52 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 53 base = base.replace(MOZ_PARAM_LOCALE, getLocale());
michael@0 54 base = base.replace(MOZ_PARAM_DIST_ID, distributionID);
michael@0 55 base = base.replace(MOZ_PARAM_OFFICIAL, MOZ_OFFICIAL);
michael@0 56
michael@0 57 let url;
michael@0 58
michael@0 59 // Test search URLs (including purposes).
michael@0 60 url = engine.getSubmission("foo").uri.spec;
michael@0 61 is(url, base, "Check search URL for 'foo'");
michael@0 62 url = engine.getSubmission("foo", null, "contextmenu").uri.spec;
michael@0 63 is(url, base + "&channel=rcs", "Check context menu search URL for 'foo'");
michael@0 64 url = engine.getSubmission("foo", null, "keyword").uri.spec;
michael@0 65 is(url, base + "&channel=fflb", "Check keyword search URL for 'foo'");
michael@0 66 url = engine.getSubmission("foo", null, "searchbar").uri.spec;
michael@0 67 is(url, base + "&channel=sb", "Check search bar search URL for 'foo'");
michael@0 68 url = engine.getSubmission("foo", null, "homepage").uri.spec;
michael@0 69 is(url, base + "&channel=np&source=hp", "Check homepage search URL for 'foo'");
michael@0 70 url = engine.getSubmission("foo", null, "newtab").uri.spec;
michael@0 71 is(url, base + "&channel=nts", "Check newtab search URL for 'foo'");
michael@0 72
michael@0 73 // Check search suggestion URL.
michael@0 74 url = engine.getSubmission("foo", "application/x-suggestions+json").uri.spec;
michael@0 75 is(url, "https://www.google.com/complete/search?client=firefox&q=foo", "Check search suggestion URL for 'foo'");
michael@0 76
michael@0 77 // Check all other engine properties.
michael@0 78 const EXPECTED_ENGINE = {
michael@0 79 name: "Google",
michael@0 80 alias: null,
michael@0 81 description: "Google Search",
michael@0 82 searchForm: "https://www.google.com/",
michael@0 83 type: Ci.nsISearchEngine.TYPE_MOZSEARCH,
michael@0 84 hidden: false,
michael@0 85 wrappedJSObject: {
michael@0 86 queryCharset: "UTF-8",
michael@0 87 "_iconURL": "data:image/x-icon;base64,AAABAAIAEBAAAAAAAAB9AQAAJgAAACAgAAAAAAAA8gIAAKMBAACJUE5HDQoaCgAAAA1JSERSAAAAEAAAABAIBgAAAB/z/2EAAAFESURBVDjLpZNJSwNBEIXnt4lE4kHxovgT9BDwJHqPy0HEEOJBiAuCRg+KUdC4QS4KrpC4gCBGE3NQ48JsnZ6eZ3UOM6gjaePhQU93v6+qq2q0pqgeJj2S8EdJT1hr0OxBtKCD5iEd8QxDYpvhvOBAuMDKURX9C9aPu4GA1GEVkzvMg10UBfYveWAWgYAP00V01fa+R9M2bA51wJvhIn3qR+ybt3D3JNQBE5sMjCIOLFpoHzOwdsLRO22qA6R6kiZiWwxUvy/PUQZIhYZ1vFM9cvcOOsYNdcBgysISdSJBnZjJMlR0Fw8vAp0xoz5gao/h+NZBy4i/10XGwrPA+hmvDyhVRG2Avu/LwcrkFADZa16L1h330w1RNgc3DiJzCpPYRm1bpveXX11clQR28xwblHpk1vq1iP/5mcoS0CoXDZiL0vsJ+dzfl+3T/VYAAAAASUVORK5CYIKJUE5HDQoaCgAAAA1JSERSAAAAIAAAACAIBgAAAHN6evQAAAK5SURBVFjDxVfrSxRRFJ9/Jta/oyWjF5XQm6D6EkHRgygIIgjUTcueVgqVWSRRkppEUQYWWB8ye1iGWilWlo/Ude489s7M6Zw7D9dlt53dmd29cFiWvXvO77x+51xpaaUsoSxBaUWZQ4ECy5xji2xKZDyCMlMEw6lCNiOSgwZKJK1SkcKeSealfP64t0mBjl4Ow39MkDUL0p2RSROOtqhZdeUEYM1pBl39XCg/fEeFtWcY7G9W4csvUxjlBkCsQ4Nt9QyWVfvT6RsAKXw3aoDGATZeYIt+W1kjw7cJG0RctWDTRebbKd8A6h5pwsDb70ba3w/eUr3wt/cmwgfw6Yft4TNMQaY7o1P2ncm4FT4ANQH/jQBJ2xv7kqIXEADDql8eS3+n8bku7oxNm+EDIM/dU92upb3T/NJGeaNbDx/AsbsLRUY5Xn92caWXY5d8RV6gWllxSg4fAEnTC90DQW13BLlgXR2D3dcUeDVkwOthA1bXspxILWcm3HdThcfvufB26LcJpkOEAz9NKI/lzqpSEC7feol5EWnpSeSlIxCALUkApmULdjUqxQVAQnl3D/X/yQda4QBEq2TYc12By091MQ17Bg3R88nHKlQbVmHvj89awNBLYrwT9zXY2aBAxTkGFdiSxP/Jp6FLDw+AS7GfsdJTJ2EqSO5khD43nGfBARy/ZxOQgZHe7GPM1jzUvChUtmnBAXQPcKGMJp3fdFGq6NByEhiAO4b/YptFfQJwNyQ/bZkVQGcf90Ja25ndIyrKBOa/f8wIpwi3X1G8UcxNu7ozUS7tiH0jBswwS3RIaF1w6LYKU/ML2+8sGnjygQswtKrVIy/Qd9qQP6LnO64q4fPAKpxyZIymHo1jWk6p1ag2BsdNwQMHcC+M5kHFJX+YlPxpVlbCx2mZ5DzPI04k4kUwHHdskU3pH76iftG8yWlkAAAAAElFTkSuQmCC",
michael@0 88 _urls : [
michael@0 89 {
michael@0 90 type: "application/x-suggestions+json",
michael@0 91 method: "GET",
michael@0 92 template: "https://www.google.com/complete/search?client=firefox&q={searchTerms}",
michael@0 93 params: "",
michael@0 94 },
michael@0 95 {
michael@0 96 type: "text/html",
michael@0 97 method: "GET",
michael@0 98 template: "https://www.google.com/search",
michael@0 99 params: [
michael@0 100 {
michael@0 101 "name": "q",
michael@0 102 "value": "{searchTerms}",
michael@0 103 "purpose": undefined,
michael@0 104 },
michael@0 105 {
michael@0 106 "name": "ie",
michael@0 107 "value": "utf-8",
michael@0 108 "purpose": undefined,
michael@0 109 },
michael@0 110 {
michael@0 111 "name": "oe",
michael@0 112 "value": "utf-8",
michael@0 113 "purpose": undefined,
michael@0 114 },
michael@0 115 {
michael@0 116 "name": "aq",
michael@0 117 "value": "t",
michael@0 118 "purpose": undefined,
michael@0 119 },
michael@0 120 {
michael@0 121 "name": "rls",
michael@0 122 "value": "{moz:distributionID}:{moz:locale}:{moz:official}",
michael@0 123 "purpose": undefined,
michael@0 124 },
michael@0 125 {
michael@0 126 "name": "client",
michael@0 127 "value": GOOGLE_CLIENT,
michael@0 128 "purpose": undefined,
michael@0 129 },
michael@0 130 {
michael@0 131 "name": "channel",
michael@0 132 "value": "rcs",
michael@0 133 "purpose": "contextmenu",
michael@0 134 },
michael@0 135 {
michael@0 136 "name": "channel",
michael@0 137 "value": "fflb",
michael@0 138 "purpose": "keyword",
michael@0 139 },
michael@0 140 {
michael@0 141 "name": "channel",
michael@0 142 "value": "sb",
michael@0 143 "purpose": "searchbar",
michael@0 144 },
michael@0 145 {
michael@0 146 "name": "channel",
michael@0 147 "value": "np",
michael@0 148 "purpose": "homepage",
michael@0 149 },
michael@0 150 {
michael@0 151 "name": "channel",
michael@0 152 "value": "nts",
michael@0 153 "purpose": "newtab",
michael@0 154 },
michael@0 155 {
michael@0 156 "name": "source",
michael@0 157 "value": "hp",
michael@0 158 "purpose": "homepage",
michael@0 159 },
michael@0 160 ],
michael@0 161 mozparams: {
michael@0 162 "client": {
michael@0 163 "name": "client",
michael@0 164 "falseValue": "firefox",
michael@0 165 "trueValue": GOOGLE_CLIENT,
michael@0 166 "condition": "defaultEngine",
michael@0 167 "mozparam": true,
michael@0 168 },
michael@0 169 },
michael@0 170 },
michael@0 171 {
michael@0 172 type: "text/html",
michael@0 173 method: "GET",
michael@0 174 template: "https://www.google.com/",
michael@0 175 },
michael@0 176 ],
michael@0 177 },
michael@0 178 };
michael@0 179
michael@0 180 isSubObjectOf(EXPECTED_ENGINE, engine, "Google");
michael@0 181 }

mercurial