Bug 1371294 - Add a basic test for the follow-on search add-on. r=mikedeboer
authorMark Banner <standard8@mozilla.com>
Fri, 13 Apr 2018 07:28:54 +0100
changeset 472119 c5afc8caa902b5c213e5c1520c482037f5546e38
parent 472118 91f269ab84959f18c7e9373bcb19ee66975824d7
child 472120 921741097e18e65b236aa834502f61d78cb0f805
push id1728
push userjlund@mozilla.com
push dateMon, 18 Jun 2018 21:12:27 +0000
treeherdermozilla-release@c296fde26f5f [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersmikedeboer
bugs1371294
milestone61.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1371294 - Add a basic test for the follow-on search add-on. r=mikedeboer MozReview-Commit-ID: Do1msiPVtWZ
browser/extensions/followonsearch/content/followonsearch-fs.js
browser/extensions/followonsearch/moz.build
browser/extensions/followonsearch/test/browser/.eslintrc.js
browser/extensions/followonsearch/test/browser/browser.ini
browser/extensions/followonsearch/test/browser/browser_followOnTelemetry.js
browser/extensions/followonsearch/test/browser/test.html
browser/extensions/followonsearch/test/browser/test2.html
browser/extensions/followonsearch/test/browser/testEngine.xml
--- a/browser/extensions/followonsearch/content/followonsearch-fs.js
+++ b/browser/extensions/followonsearch/content/followonsearch-fs.js
@@ -87,16 +87,25 @@ let searchDomains = [{
     "www.google.com.vn", "www.google.vu", "www.google.ws", "www.google.co.za",
     "www.google.co.zm", "www.google.co.zw",
   ],
   "search": "q",
   "prefix": ["client"],
   "followOnSearch": "oq",
   "codes": ["firefox-b-ab", "firefox-b", "firefox-b-1-ab", "firefox-b-1"],
   "sap": "google",
+}, {
+  // This is intended only for tests.
+  "domains": [ "mochi.test" ],
+  "search": "m",
+  "prefix": ["mt"],
+  "followOnSearch": "mtfo",
+  "reportPrefix": "form",
+  "codes": ["TEST"],
+  "sap": "mochitest"
 }];
 
 function getSearchDomainCodes(host) {
   for (let domainInfo of searchDomains) {
     if (domainInfo.domains.includes(host)) {
       return domainInfo;
     }
   }
--- a/browser/extensions/followonsearch/moz.build
+++ b/browser/extensions/followonsearch/moz.build
@@ -7,9 +7,11 @@
 with Files("**"):
     BUG_COMPONENT = ("Firefox", "Search")
 
 FINAL_TARGET_FILES.features['followonsearch@mozilla.com'] += [
   'bootstrap.js',
   'install.rdf',
 ]
 
+BROWSER_CHROME_MANIFESTS += ['test/browser/browser.ini']
+
 JAR_MANIFESTS += ['jar.mn']
new file mode 100644
--- /dev/null
+++ b/browser/extensions/followonsearch/test/browser/.eslintrc.js
@@ -0,0 +1,7 @@
+"use strict";
+
+module.exports = {
+  "extends": [
+    "plugin:mozilla/browser-test",
+  ],
+};
new file mode 100644
--- /dev/null
+++ b/browser/extensions/followonsearch/test/browser/browser.ini
@@ -0,0 +1,7 @@
+[DEFAULT]
+
+[browser_followOnTelemetry.js]
+support-files =
+  test.html
+  test2.html
+  testEngine.xml
new file mode 100644
--- /dev/null
+++ b/browser/extensions/followonsearch/test/browser/browser_followOnTelemetry.js
@@ -0,0 +1,66 @@
+/* Any copyright is dedicated to the Public Domain.
+   http://creativecommons.org/publicdomain/zero/1.0/ */
+
+"use strict";
+
+ChromeUtils.defineModuleGetter(this, "SearchTestUtils",
+  "resource://testing-common/SearchTestUtils.jsm");
+
+SearchTestUtils.init(Assert, registerCleanupFunction);
+
+const BASE_URL = "http://mochi.test:8888/browser/browser/extensions/followonsearch/test/browser/";
+const TEST_ENGINE_BASENAME = "testEngine.xml";
+
+add_task(async function test_followOnSearchTelemetry() {
+  let engine = await SearchTestUtils.promiseNewSearchEngine(
+    getRootDirectory(gTestPath) + TEST_ENGINE_BASENAME,
+    registerCleanupFunction);
+  let oldCurrentEngine = Services.search.currentEngine;
+  Services.search.currentEngine = engine;
+
+  let histogram = Services.telemetry.getKeyedHistogramById("SEARCH_COUNTS");
+  histogram.clear();
+
+  registerCleanupFunction(() => Services.search.currentEngine = oldCurrentEngine);
+
+  await BrowserTestUtils.withNewTab({gBrowser}, async browser => {
+    // Open the initial search page via entering a search on the URL bar.
+    let loadPromise = BrowserTestUtils.waitForLocationChange(gBrowser,
+      `${BASE_URL}test.html?searchm=test&mt=TEST`);
+
+    gURLBar.focus();
+    EventUtils.sendString("test");
+    EventUtils.sendKey("return");
+
+    await loadPromise;
+
+    // Perform a follow-on search, selecting the form in the page.
+    loadPromise = BrowserTestUtils.waitForLocationChange(gBrowser,
+      `${BASE_URL}test2.html?mtfo=followonsearchtest&mt=TEST&m=test`);
+
+    await ContentTask.spawn(browser, null, function() {
+      content.document.getElementById("submit").click();
+    });
+
+    await loadPromise;
+
+    let snapshot;
+
+    // We have to wait for the snapshot to come in, as there's async functionality
+    // in the extension.
+    await TestUtils.waitForCondition(() => {
+      snapshot = histogram.snapshot();
+      return "mochitest.follow-on:unknown:TEST" in snapshot;
+    });
+    Assert.ok("mochitest.follow-on:unknown:TEST" in snapshot,
+      "Histogram should have an entry for the follow-on search.");
+    Assert.deepEqual(snapshot["mochitest.follow-on:unknown:TEST"], {
+      counts: [ 1, 0, 0 ],
+      histogram_type: 4,
+      max: 2,
+      min: 1,
+      ranges: [ 0, 1, 2 ],
+      sum: 1,
+    }, "Histogram should have the correct snapshot data");
+  });
+});
new file mode 100644
--- /dev/null
+++ b/browser/extensions/followonsearch/test/browser/test.html
@@ -0,0 +1,15 @@
+<!DOCTYPE html>
+<html>
+<head>
+  <meta charset="utf-8" />
+  <title>Follow-on Search Test</title>
+</head>
+<body>
+  <form method="get" action="test2.html">
+    <input type="text" name="mtfo" value="followonsearchtest"/>
+    <input type="text" name="mt" value="TEST"/>
+    <input type="text" name="m" value="test"/>
+    <input type="submit" id="submit" value="submit"/>
+  </form>
+</body>
+</html>
new file mode 100644
--- /dev/null
+++ b/browser/extensions/followonsearch/test/browser/test2.html
@@ -0,0 +1,8 @@
+<!DOCTYPE html>
+<html>
+<head>
+  <meta charset="utf-8" />
+  <title>Follow-on Search Test Final Page</title>
+</head>
+<body></body>
+</html>
new file mode 100644
--- /dev/null
+++ b/browser/extensions/followonsearch/test/browser/testEngine.xml
@@ -0,0 +1,15 @@
+<!-- This Source Code Form is subject to the terms of the Mozilla Public
+   - License, v. 2.0. If a copy of the MPL was not distributed with this
+   - file, You can obtain one at http://mozilla.org/MPL/2.0/. -->
+
+<OpenSearchDescription xmlns="http://a9.com/-/spec/opensearch/1.1/"
+                       xmlns:moz="http://www.mozilla.org/2006/browser/search/">
+  <ShortName>Mochitest</ShortName>
+  <Description>Mochitest Engine</Description>
+  <InputEncoding>UTF-8</InputEncoding>
+  <Image width="16" height="16">data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAIAAACQkWg2AAABGklEQVQoz2NgGB6AnZ1dUlJSXl4eSDIyMhLW4Ovr%2B%2Fr168uXL69Zs4YoG%2BLi4i5dusTExMTGxsbNzd3f37937976%2BnpmZmagbHR09J49e5YvX66kpATVEBYW9ubNm2nTphkbG7e2tp44cQLIuHfvXm5urpaWFlDKysqqu7v73LlzECMYIiIiHj58mJCQoKKicvXq1bS0NKBgW1vbjh074uPjgeqAXE1NzSdPnvDz84M0AEUvXLgAsW379u1z5swBen3jxo2zZ892cHB4%2BvQp0KlAfwI1cHJyghQFBwfv2rULokFXV%2FfixYu7d%2B8GGqGgoMDKyrpu3br9%2B%2FcDuXl5eVA%2FAEWBfoWHAdAYoNuAYQ0XAeoUERFhGDYAAPoUaT2dfWJuAAAAAElFTkSuQmCC</Image>
+  <Url type="text/html" method="GET" template="http://mochi.test:8888/browser/browser/extensions/followonsearch/test/browser/test.html?search" rel="searchform">
+    <Param name="m" value="{searchTerms}"/>
+    <Param name="mt" value="TEST"/>
+  </Url>
+</OpenSearchDescription>