Bug 1299458 - Telemetry data from Search bar is not properly collected when searching in new tab from context menu. r=florian
authorDrew Willcoxon <adw@mozilla.com>
Fri, 16 Sep 2016 18:12:13 -0700
changeset 314478 2a6c70abee77fd8b967c8e1c4f77ae36619880ff
parent 314422 d1df1692dbb4b1f635ef52696233373309ba0b8c
child 314479 70c93b940d716bf091c3ba95658aafdeb783386a
push id81903
push usercbook@mozilla.com
push dateTue, 20 Sep 2016 10:04:26 +0000
treeherdermozilla-inbound@150109898e5f [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersflorian
bugs1299458
milestone51.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 1299458 - Telemetry data from Search bar is not properly collected when searching in new tab from context menu. r=florian MozReview-Commit-ID: 43y0V0ShcLm
browser/components/search/content/search.xml
browser/components/search/test/browser.ini
browser/components/search/test/browser_oneOffContextMenu.js
--- a/browser/components/search/content/search.xml
+++ b/browser/components/search/content/search.xml
@@ -1285,18 +1285,18 @@
               this.query = event.target.oneOffSearchQuery || event.target.value;
               break;
             case "popupshowing":
               this._rebuild();
               break;
             case "popuphidden":
               Services.tm.mainThread.dispatch(() => {
                 this.selectedButton = null;
+                this._contextEngine = null;
               }, Ci.nsIThread.DISPATCH_NORMAL);
-              this._contextEngine = null;
               break;
           }
         ]]></body>
       </method>
 
       <method name="showSettings">
         <body><![CDATA[
           BrowserUITelemetry.countSearchSettingsEvent(this.telemetryOrigin);
--- a/browser/components/search/test/browser.ini
+++ b/browser/components/search/test/browser.ini
@@ -24,16 +24,17 @@ support-files =
 [browser_contextSearchTabPosition.js]
 skip-if = os == "mac" # bug 967013
 [browser_google.js]
 [browser_google_codes.js]
 [browser_google_behavior.js]
 [browser_healthreport.js]
 [browser_hiddenOneOffs_cleanup.js]
 [browser_hiddenOneOffs_diacritics.js]
+[browser_oneOffContextMenu.js]
 [browser_oneOffHeader.js]
 [browser_private_search_perwindowpb.js]
 [browser_yahoo.js]
 [browser_yahoo_behavior.js]
 [browser_abouthome_behavior.js]
 skip-if = true # Bug ??????, Bug 1100301 - leaks windows until shutdown when --run-by-dir
 [browser_aboutSearchReset.js]
 [browser_searchbar_openpopup.js]
new file mode 100644
--- /dev/null
+++ b/browser/components/search/test/browser_oneOffContextMenu.js
@@ -0,0 +1,99 @@
+"use strict";
+
+const TEST_ENGINE_NAME = "Foo";
+const TEST_ENGINE_BASENAME = "testEngine.xml";
+
+const searchbar = document.getElementById("searchbar");
+const searchPopup = document.getElementById("PopupSearchAutoComplete");
+const searchIcon = document.getAnonymousElementByAttribute(
+  searchbar, "anonid", "searchbar-search-button"
+);
+const oneOffBinding = document.getAnonymousElementByAttribute(
+  searchPopup, "anonid", "search-one-off-buttons"
+);
+const contextMenu = document.getAnonymousElementByAttribute(
+  oneOffBinding, "anonid", "search-one-offs-context-menu"
+);
+const oneOffButtons = document.getAnonymousElementByAttribute(
+  oneOffBinding, "anonid", "search-panel-one-offs"
+);
+const searchInNewTabMenuItem = document.getAnonymousElementByAttribute(
+  oneOffBinding, "anonid", "search-one-offs-context-open-in-new-tab"
+);
+
+add_task(function* init() {
+  yield promiseNewEngine(TEST_ENGINE_BASENAME, {
+    setAsCurrent: false,
+  });
+});
+
+add_task(function* extendedTelemetryDisabled() {
+  yield SpecialPowers.pushPrefEnv({set: [["toolkit.telemetry.enabled", false]]});
+  yield doTest();
+  checkTelemetry("other");
+});
+
+add_task(function* extendedTelemetryEnabled() {
+  yield SpecialPowers.pushPrefEnv({set: [["toolkit.telemetry.enabled", true]]});
+  yield doTest();
+  checkTelemetry("other-" + TEST_ENGINE_NAME);
+});
+
+function* doTest() {
+  // Open the popup.
+  let promise = promiseEvent(searchPopup, "popupshown");
+  info("Opening search panel");
+  EventUtils.synthesizeMouseAtCenter(searchIcon, {});
+  yield promise;
+
+  // Get the one-off button for the test engine.
+  let oneOffButton;
+  for (let node of oneOffButtons.childNodes) {
+    if (node.engine && node.engine.name == TEST_ENGINE_NAME) {
+      oneOffButton = node;
+      break;
+    }
+  }
+  Assert.notEqual(oneOffButton, undefined,
+                  "One-off for test engine should exist");
+
+  // Open the context menu on the one-off.
+  promise = BrowserTestUtils.waitForEvent(contextMenu, "popupshown");
+  EventUtils.synthesizeMouseAtCenter(oneOffButton, {
+    type: "contextmenu",
+    button: 2,
+  });
+  yield promise;
+
+  // Click the Search in New Tab menu item.
+  promise = BrowserTestUtils.waitForNewTab(gBrowser);
+  EventUtils.synthesizeMouseAtCenter(searchInNewTabMenuItem, {});
+  let tab = yield promise;
+
+  // Check the loaded tab.
+  Assert.equal(tab.linkedBrowser.currentURI.spec,
+               "http://mochi.test:8888/browser/browser/components/search/test/",
+               "Expected search tab should have loaded");
+
+  yield BrowserTestUtils.removeTab(tab);
+
+  // Move the cursor out of the panel area to avoid messing with other tests.
+  yield EventUtils.synthesizeNativeMouseMove(searchbar);
+}
+
+function checkTelemetry(expectedEngineName) {
+  let propertyPath = [
+    "countableEvents",
+    "__DEFAULT__",
+    "search-oneoff",
+    expectedEngineName + ".oneoff-context-searchbar",
+    "unknown",
+    "tab-background",
+  ];
+  let telem = BrowserUITelemetry.getToolbarMeasures();
+  for (let prop of propertyPath) {
+    Assert.ok(prop in telem, "Property " + prop + " should be in the telemetry");
+    telem = telem[prop];
+  }
+  Assert.equal(telem, 1, "Click count");
+}