Bug 1103216: update tests to deal with Google parameter changes, r=felipe, a=gavin
authorGavin Sharp <gavin@gavinsharp.com>
Mon, 24 Nov 2014 11:17:40 -0800
changeset 226139 7e8c680fcb2dee728473e04c1e35b0501cd58933
parent 226138 fe02b53b949ef324c55e042b65edb189752db60a
child 226140 d9d3454e8c4d504a33344e72efdf42500031be7e
push id4177
push usergsharp@mozilla.com
push dateMon, 24 Nov 2014 20:30:33 +0000
treeherdermozilla-beta@d9d3454e8c4d [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersfelipe, gavin
bugs1103216
milestone34.0
Bug 1103216: update tests to deal with Google parameter changes, r=felipe, a=gavin
browser/components/search/test/browser_google.js
browser/components/search/test/browser_google_behavior.js
--- a/browser/components/search/test/browser_google.js
+++ b/browser/components/search/test/browser_google.js
@@ -2,78 +2,37 @@
  * http://creativecommons.org/publicdomain/zero/1.0/ */
 
 /*
  * Test Google search plugin URLs
  */
 
 "use strict";
 
-const BROWSER_SEARCH_PREF      = "browser.search.";
-
-const MOZ_PARAM_LOCALE         = /\{moz:locale\}/g;
-const MOZ_PARAM_DIST_ID        = /\{moz:distributionID\}/g;
-const MOZ_PARAM_OFFICIAL       = /\{moz:official\}/g;
-
-let runtime = Cc["@mozilla.org/xre/app-info;1"].getService(Ci.nsIXULRuntime);
-// Custom search parameters
-const MOZ_OFFICIAL = runtime.isOfficialBranding ? "official" : "unofficial";
-
-var google_client;
-switch (runtime.defaultUpdateChannel) {
-case "beta":
-  google_client = "firefox-beta";
-  break;
-case "aurora":
-  google_client = "firefox-aurora";
-  break;
-case "nightly":
-  google_client = "firefox-nightly";
-  break;
-default:
-  google_client = "firefox-a";
-  break;
-}
-
-const GOOGLE_CLIENT = google_client;
-const MOZ_DISTRIBUTION_ID = runtime.distributionID;
-
 function test() {
   let engine = Services.search.getEngineByName("Google");
   ok(engine, "Google");
 
-  is(Services.search.defaultEngine, engine, "Check that Google is the default search engine");
-
-  let distributionID;
-  try {
-    distributionID = Services.prefs.getCharPref(BROWSER_SEARCH_PREF + "distributionID");
-  } catch (ex) {
-    distributionID = MOZ_DISTRIBUTION_ID;
-  }
-
-  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;
-  base = base.replace(MOZ_PARAM_LOCALE, getLocale());
-  base = base.replace(MOZ_PARAM_DIST_ID, distributionID);
-  base = base.replace(MOZ_PARAM_OFFICIAL, MOZ_OFFICIAL);
+  let base = "https://www.google.com/search?q=foo&ie=utf-8&oe=utf-8";
 
   let url;
 
   // Test search URLs (including purposes).
   url = engine.getSubmission("foo").uri.spec;
   is(url, base, "Check search URL for 'foo'");
   url = engine.getSubmission("foo", null, "contextmenu").uri.spec;
-  is(url, base + "&channel=rcs", "Check context menu search URL for 'foo'");
+  is(url, base, "Check context menu search URL for 'foo'");
   url = engine.getSubmission("foo", null, "keyword").uri.spec;
-  is(url, base + "&channel=fflb", "Check keyword search URL for 'foo'");
+  is(url, base, "Check keyword search URL for 'foo'");
   url = engine.getSubmission("foo", null, "searchbar").uri.spec;
-  is(url, base + "&channel=sb", "Check search bar search URL for 'foo'");
+  is(url, base, "Check search bar search URL for 'foo'");
   url = engine.getSubmission("foo", null, "homepage").uri.spec;
-  is(url, base + "&channel=np&source=hp", "Check homepage search URL for 'foo'");
+  is(url, base, "Check homepage search URL for 'foo'");
   url = engine.getSubmission("foo", null, "newtab").uri.spec;
-  is(url, base + "&channel=nts", "Check newtab search URL for 'foo'");
+  is(url, base, "Check newtab search URL for 'foo'");
 
   // Check search suggestion URL.
   url = engine.getSubmission("foo", "application/x-suggestions+json").uri.spec;
   is(url, "https://www.google.com/complete/search?client=firefox&q=foo", "Check search suggestion URL for 'foo'");
 
   // Check result parsing and alternate domains.
   let alternateBase = base.replace("www.google.com", "www.google.fr");
   is(Services.search.parseSubmissionURL(base).terms, "foo",
@@ -114,70 +73,18 @@ function test() {
               "value": "utf-8",
               "purpose": undefined,
             },
             {
               "name": "oe",
               "value": "utf-8",
               "purpose": undefined,
             },
-            {
-              "name": "aq",
-              "value": "t",
-              "purpose": undefined,
-            },
-            {
-              "name": "rls",
-              "value": "{moz:distributionID}:{moz:locale}:{moz:official}",
-              "purpose": undefined,
-            },
-            {
-              "name": "client",
-              "value": GOOGLE_CLIENT,
-              "purpose": undefined,
-            },
-            {
-              "name": "channel",
-              "value": "rcs",
-              "purpose": "contextmenu",
-            },
-            {
-              "name": "channel",
-              "value": "fflb",
-              "purpose": "keyword",
-            },
-            {
-              "name": "channel",
-              "value": "sb",
-              "purpose": "searchbar",
-            },
-            {
-              "name": "channel",
-              "value": "np",
-              "purpose": "homepage",
-            },
-            {
-              "name": "channel",
-              "value": "nts",
-              "purpose": "newtab",
-            },
-            {
-              "name": "source",
-              "value": "hp",
-              "purpose": "homepage",
-            },
           ],
           mozparams: {
-            "client": {
-              "name": "client",
-              "falseValue": "firefox",
-              "trueValue": GOOGLE_CLIENT,
-              "condition": "defaultEngine",
-              "mozparam": true,
-            },
           },
         },
         {
           type: "text/html",
           method: "GET",
           template: "https://www.google.com/",
         },
       ],
--- a/browser/components/search/test/browser_google_behavior.js
+++ b/browser/components/search/test/browser_google_behavior.js
@@ -2,107 +2,69 @@
  * http://creativecommons.org/publicdomain/zero/1.0/ */
 
 /*
  * Test Google search plugin URLs
  */
 
 "use strict";
 
-const BROWSER_SEARCH_PREF      = "browser.search.";
-
-const MOZ_PARAM_LOCALE         = /\{moz:locale\}/g;
-const MOZ_PARAM_DIST_ID        = /\{moz:distributionID\}/g;
-const MOZ_PARAM_OFFICIAL       = /\{moz:official\}/g;
-
-let runtime = Cc["@mozilla.org/xre/app-info;1"].getService(Ci.nsIXULRuntime);
-// Custom search parameters
-const MOZ_OFFICIAL = runtime.isOfficialBranding ? "official" : "unofficial";
-
-var google_client;
-switch (runtime.defaultUpdateChannel) {
-case "beta":
-  google_client = "firefox-beta";
-  break;
-case "aurora":
-  google_client = "firefox-aurora";
-  break;
-case "nightly":
-  google_client = "firefox-nightly";
-  break;
-default:
-  google_client = "firefox-a";
-  break;
-}
-
-const GOOGLE_CLIENT = google_client;
-const MOZ_DISTRIBUTION_ID = runtime.distributionID;
-
 function test() {
   let engine = Services.search.getEngineByName("Google");
   ok(engine, "Google is installed");
 
-  is(Services.search.defaultEngine, engine, "Check that Google is the default search engine");
+  let previouslySelectedEngine = Services.search.currentEngine;
+  Services.search.currentEngine = engine;
 
-  let distributionID;
-  try {
-    distributionID = Services.prefs.getCharPref(BROWSER_SEARCH_PREF + "distributionID");
-  } catch (ex) {
-    distributionID = MOZ_DISTRIBUTION_ID;
-  }
-
-  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;
-  base = base.replace(MOZ_PARAM_LOCALE, getLocale());
-  base = base.replace(MOZ_PARAM_DIST_ID, distributionID);
-  base = base.replace(MOZ_PARAM_OFFICIAL, MOZ_OFFICIAL);
+  let base = "https://www.google.com/search?q=foo&ie=utf-8&oe=utf-8";
 
   let url;
 
   // Test search URLs (including purposes).
   url = engine.getSubmission("foo").uri.spec;
   is(url, base, "Check search URL for 'foo'");
 
   waitForExplicitFinish();
 
   var gCurrTest;
   var gTests = [
     {
       name: "context menu search",
-      searchURL: base + "&channel=rcs",
+      searchURL: base,
       run: function () {
         // Simulate a contextmenu search
         // FIXME: This is a bit "low-level"...
         BrowserSearch.loadSearch("foo", false, "contextmenu");
       }
     },
     {
       name: "keyword search",
-      searchURL: base + "&channel=fflb",
+      searchURL: base,
       run: function () {
         gURLBar.value = "? foo";
         gURLBar.focus();
         EventUtils.synthesizeKey("VK_RETURN", {});
       }
     },
     {
       name: "search bar search",
-      searchURL: base + "&channel=sb",
+      searchURL: base,
       run: function () {
         let sb = BrowserSearch.searchBar;
         sb.focus();
         sb.value = "foo";
         registerCleanupFunction(function () {
           sb.value = "";
         });
         EventUtils.synthesizeKey("VK_RETURN", {});
       }
     },
     {
       name: "new tab search",
-      searchURL: base + "&channel=nts",
+      searchURL: base,
       run: function () {
         function doSearch(doc) {
           // Re-add the listener, and perform a search
           gBrowser.addProgressListener(listener);
           doc.getElementById("newtab-search-text").value = "foo";
           doc.getElementById("newtab-search-submit").click();
         }
 
@@ -136,17 +98,17 @@ function test() {
               }
             });
           }
         }, true);
       }
     },
     {
       name: "home page search",
-      searchURL: base + "&channel=np&source=hp",
+      searchURL: base,
       run: function () {
         // Bug 992270: Ignore uncaught about:home exceptions (related to snippets from IndexedDB)
         ignoreAllUncaughtExceptions(true);
 
         // load about:home, but remove the listener first so it doesn't
         // get in the way
         gBrowser.removeProgressListener(listener);
         gBrowser.loadURI("about:home");
@@ -211,16 +173,17 @@ function test() {
 
       executeSoon(nextTest);
     }
   }
 
   registerCleanupFunction(function () {
     gBrowser.removeProgressListener(listener);
     gBrowser.removeTab(tab);
+    Services.search.currentEngine = previouslySelectedEngine;
   });
 
   tab.linkedBrowser.addEventListener("load", function load() {
     tab.linkedBrowser.removeEventListener("load", load, true);
     gBrowser.addProgressListener(listener);
     nextTest();
   }, true);
 }