Bug 950904 - Add UITelemetry probe to capture window width & height. r=jimm
authorSam Foster <sfoster@mozilla.com>
Sun, 02 Feb 2014 14:59:56 -0800
changeset 182599 b6cc3c35d419e828e7771424de5d5e94e12170f5
parent 182584 92c81bf6052cbdab60c5d413e862b3f13a87d72f
child 182600 a91b8e6b8dcc808d72f6f1b37dc4a8ade98ef36d
push id3343
push userffxbld
push dateMon, 17 Mar 2014 21:55:32 +0000
treeherdermozilla-beta@2f7d3415f79f [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersjimm
bugs950904
milestone29.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 950904 - Add UITelemetry probe to capture window width & height. r=jimm
browser/metro/base/content/browser-ui.js
browser/metro/base/tests/mochitest/browser_ui_telemetry.js
browser/metro/base/tests/mochitest/metro.ini
--- a/browser/metro/base/content/browser-ui.js
+++ b/browser/metro/base/content/browser-ui.js
@@ -137,16 +137,25 @@ var BrowserUI = {
       }, 0);
     });
 
     // Only load IndexedDB.js when we actually need it. A general fix will happen in bug 647079.
     messageManager.addMessageListener("IndexedDB:Prompt", function(aMessage) {
       return IndexedDB.receiveMessage(aMessage);
     });
 
+    // hook up telemetry ping for UI data
+    try {
+      UITelemetry.addSimpleMeasureFunction("metro-ui",
+                                           BrowserUI._getMeasures.bind(BrowserUI));
+    } catch (ex) {
+      // swallow exception that occurs if metro-appbar measure is already set up
+      dump("Failed to addSimpleMeasureFunction in browser-ui: " + ex.message + "\n");
+    }
+
     // Delay the panel UI and Sync initialization
     window.addEventListener("UIReadyDelayed", function delayedInit(aEvent) {
       Util.dumpLn("* delay load started...");
       window.removeEventListener("UIReadyDelayed",  delayedInit, false);
 
       // Login Manager and Form History initialization
       Cc["@mozilla.org/login-manager;1"].getService(Ci.nsILoginManager);
       messageManager.addMessageListener("Browser:MozApplicationManifest", OfflineApps);
@@ -374,17 +383,17 @@ var BrowserUI = {
       let webNav = Ci.nsIWebNavigation;
       let flags = webNav.LOAD_FLAGS_ALLOW_THIRD_PARTY_FIXUP |
                   webNav.LOAD_FLAGS_FIXUP_SCHEME_TYPOS;
       aURI = yield Browser.getShortcutOrURI(aURI, postData);
       Browser.loadURI(aURI, { flags: flags, postData: postData });
 
       // Delay doing the fixup so the raw URI is passed to loadURIWithFlags
       // and the proper third-party fixup can be done
-      let fixupFlags = Ci.nsIURIFixup.FIXUP_FLAG_ALLOW_KEYWORD_LOOKUP | 
+      let fixupFlags = Ci.nsIURIFixup.FIXUP_FLAG_ALLOW_KEYWORD_LOOKUP |
                        Ci.nsIURIFixup.FIXUP_FLAG_FIX_SCHEME_TYPOS;
       let uri = gURIFixup.createFixupURI(aURI, fixupFlags);
       gHistSvc.markPageAsTyped(uri);
 
       BrowserUI._titleChanged(Browser.selectedBrowser);
     });
   },
 
@@ -741,16 +750,24 @@ var BrowserUI = {
     document.getElementById("bcast_preciseInput").setAttribute("input", "imprecise");
     let uri = Util.makeURI("chrome://browser/content/cursor.css");
     if (!StyleSheetSvc.sheetRegistered(uri, Ci.nsIStyleSheetService.AGENT_SHEET)) {
       StyleSheetSvc.loadAndRegisterSheet(uri,
                                          Ci.nsIStyleSheetService.AGENT_SHEET);
     }
   },
 
+  _getMeasures: function() {
+    let dimensions = {
+      "window-width": ContentAreaObserver.width,
+      "window-height": ContentAreaObserver.height
+    };
+    return dimensions;
+  },
+
   /*********************************
    * Event handling
    */
 
   handleEvent: function handleEvent(aEvent) {
     var target = aEvent.target;
     switch (aEvent.type) {
       // Window events
@@ -1126,17 +1143,17 @@ var BrowserUI = {
   confirmSanitizeDialog: function () {
     let bundle = Services.strings.createBundle("chrome://browser/locale/browser.properties");
     let title = bundle.GetStringFromName("clearPrivateData.title2");
     let options = bundle.GetStringFromName("optionsCharm");
     let message = bundle.GetStringFromName("clearPrivateData.message2").replace("#1", options);
     let clearbutton = bundle.GetStringFromName("clearPrivateData.clearButton");
 
     let prefsClearButton = document.getElementById("prefs-clear-data");
-    prefsClearButton.disabled = true; 
+    prefsClearButton.disabled = true;
 
     let buttonPressed = Services.prompt.confirmEx(
                           null,
                           title,
                           message,
                           Ci.nsIPrompt.BUTTON_POS_0 * Ci.nsIPrompt.BUTTON_TITLE_IS_STRING +
                           Ci.nsIPrompt.BUTTON_POS_1 * Ci.nsIPrompt.BUTTON_TITLE_CANCEL,
                           clearbutton,
new file mode 100644
--- /dev/null
+++ b/browser/metro/base/tests/mochitest/browser_ui_telemetry.js
@@ -0,0 +1,26 @@
+// -*- Mode: js2; tab-width: 2; indent-tabs-mode: nil; js2-basic-offset: 2; js2-skip-preprocessor-directives: t; -*-
+/* 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/. */
+
+"use strict";
+
+function test() {
+  runTests();
+}
+
+function getSimpleMeasurementsFromTelemetryPing() {
+  return Cu.import("resource://gre/modules/TelemetryPing.jsm", {}).
+    TelemetryPing.getPayload().simpleMeasurements;
+}
+
+gTests.push({
+  desc: "Test browser-ui telemetry",
+  run: function testBrowserUITelemetry() {
+    // startup should have registered simple measures function
+    let simpleMeasurements = getSimpleMeasurementsFromTelemetryPing();
+    ok(simpleMeasurements, "simpleMeasurements are truthy");
+    ok(simpleMeasurements.UITelemetry["metro-ui"]["window-width"], "window-width measurement was captured");
+    ok(simpleMeasurements.UITelemetry["metro-ui"]["window-height"], "window-height measurement was captured");
+  }
+});
--- a/browser/metro/base/tests/mochitest/metro.ini
+++ b/browser/metro/base/tests/mochitest/metro.ini
@@ -61,16 +61,17 @@ support-files =
 [browser_remotetabs.js]
 [browser_sessionstore.js]
 [browser_snappedState.js]
 [browser_tabs.js]
 [browser_tabs_container.js]
 [browser_test.js]
 [browser_tiles.js]
 [browser_topsites.js]
+[browser_ui_telemetry.js]
 [browser_urlbar.js]
 [browser_urlbar_highlightURLs.js]
 [browser_urlbar_trimURLs.js]
 
 # These tests have known failures in debug builds
 [browser_selection_basic.js]
 skip-if = debug
 [browser_selection_textarea.js]