michael@0: /* Any copyright is dedicated to the Public Domain. michael@0: http://creativecommons.org/publicdomain/zero/1.0/ */ michael@0: michael@0: const TEST_URI = "data:text/html;charset=utf-8,
browser_telemetry_toolboxtabs_styleeditor.js
"; michael@0: michael@0: // Because we need to gather stats for the period of time that a tool has been michael@0: // opened we make use of setTimeout() to create tool active times. michael@0: const TOOL_DELAY = 200; michael@0: michael@0: let {Promise: promise} = Cu.import("resource://gre/modules/devtools/deprecated-sync-thenables.js", {}); michael@0: let {Services} = Cu.import("resource://gre/modules/Services.jsm", {}); michael@0: michael@0: let require = Cu.import("resource://gre/modules/devtools/Loader.jsm", {}).devtools.require; michael@0: let Telemetry = require("devtools/shared/telemetry"); michael@0: michael@0: function init() { michael@0: Telemetry.prototype.telemetryInfo = {}; michael@0: Telemetry.prototype._oldlog = Telemetry.prototype.log; michael@0: Telemetry.prototype.log = function(histogramId, value) { michael@0: if (histogramId) { michael@0: if (!this.telemetryInfo[histogramId]) { michael@0: this.telemetryInfo[histogramId] = []; michael@0: } michael@0: michael@0: this.telemetryInfo[histogramId].push(value); michael@0: } michael@0: } michael@0: michael@0: openToolboxTabTwice("styleeditor", false); michael@0: } michael@0: michael@0: function openToolboxTabTwice(id, secondPass) { michael@0: let target = TargetFactory.forTab(gBrowser.selectedTab); michael@0: michael@0: gDevTools.showToolbox(target, id).then(function(toolbox) { michael@0: info("Toolbox tab " + id + " opened"); michael@0: michael@0: toolbox.once("destroyed", function() { michael@0: if (secondPass) { michael@0: checkResults(); michael@0: } else { michael@0: openToolboxTabTwice(id, true); michael@0: } michael@0: }); michael@0: // We use a timeout to check the tools active time michael@0: setTimeout(function() { michael@0: gDevTools.closeToolbox(target); michael@0: }, TOOL_DELAY); michael@0: }).then(null, reportError); michael@0: } michael@0: michael@0: function checkResults() { michael@0: let result = Telemetry.prototype.telemetryInfo; michael@0: michael@0: for (let [histId, value] of Iterator(result)) { michael@0: if (histId.endsWith("OPENED_PER_USER_FLAG")) { michael@0: ok(value.length === 1 && value[0] === true, michael@0: "Per user value " + histId + " has a single value of true"); michael@0: } else if (histId.endsWith("OPENED_BOOLEAN")) { michael@0: ok(value.length > 1, histId + " has more than one entry"); michael@0: michael@0: let okay = value.every(function(element) { michael@0: return element === true; michael@0: }); michael@0: michael@0: ok(okay, "All " + histId + " entries are === true"); michael@0: } else if (histId.endsWith("TIME_ACTIVE_SECONDS")) { michael@0: ok(value.length > 1, histId + " has more than one entry"); michael@0: michael@0: let okay = value.every(function(element) { michael@0: return element > 0; michael@0: }); michael@0: michael@0: ok(okay, "All " + histId + " entries have time > 0"); michael@0: } michael@0: } michael@0: michael@0: finishUp(); michael@0: } michael@0: michael@0: function reportError(error) { michael@0: let stack = " " + error.stack.replace(/\n?.*?@/g, "\n JS frame :: "); michael@0: michael@0: ok(false, "ERROR: " + error + " at " + error.fileName + ":" + michael@0: error.lineNumber + "\n\nStack trace:" + stack); michael@0: finishUp(); michael@0: } michael@0: michael@0: function finishUp() { michael@0: gBrowser.removeCurrentTab(); michael@0: michael@0: Telemetry.prototype.log = Telemetry.prototype._oldlog; michael@0: delete Telemetry.prototype._oldlog; michael@0: delete Telemetry.prototype.telemetryInfo; michael@0: michael@0: TargetFactory = Services = promise = require = null; michael@0: michael@0: finish(); michael@0: } michael@0: michael@0: function test() { michael@0: waitForExplicitFinish(); michael@0: gBrowser.selectedTab = gBrowser.addTab(); michael@0: gBrowser.selectedBrowser.addEventListener("load", function() { michael@0: gBrowser.selectedBrowser.removeEventListener("load", arguments.callee, true); michael@0: waitForFocus(init, content); michael@0: }, true); michael@0: michael@0: content.location = TEST_URI; michael@0: }