browser/devtools/shared/test/browser_telemetry_toolboxtabs_options.js

changeset 0
6474c204b198
equal deleted inserted replaced
-1:000000000000 0:65b63095a304
1 /* Any copyright is dedicated to the Public Domain.
2 http://creativecommons.org/publicdomain/zero/1.0/ */
3
4 const TEST_URI = "data:text/html;charset=utf-8,<p>browser_telemetry_toolboxtabs_options.js</p>";
5
6 // Because we need to gather stats for the period of time that a tool has been
7 // opened we make use of setTimeout() to create tool active times.
8 const TOOL_DELAY = 200;
9
10 let {Promise: promise} = Cu.import("resource://gre/modules/devtools/deprecated-sync-thenables.js", {});
11 let {Services} = Cu.import("resource://gre/modules/Services.jsm", {});
12
13 let require = Cu.import("resource://gre/modules/devtools/Loader.jsm", {}).devtools.require;
14 let Telemetry = require("devtools/shared/telemetry");
15
16 function init() {
17 Telemetry.prototype.telemetryInfo = {};
18 Telemetry.prototype._oldlog = Telemetry.prototype.log;
19 Telemetry.prototype.log = function(histogramId, value) {
20 if (histogramId) {
21 if (!this.telemetryInfo[histogramId]) {
22 this.telemetryInfo[histogramId] = [];
23 }
24
25 this.telemetryInfo[histogramId].push(value);
26 }
27 }
28
29 openToolboxTabTwice("options", false);
30 }
31
32 function openToolboxTabTwice(id, secondPass) {
33 let target = TargetFactory.forTab(gBrowser.selectedTab);
34
35 gDevTools.showToolbox(target, id).then(function(toolbox) {
36 info("Toolbox tab " + id + " opened");
37
38 toolbox.once("destroyed", function() {
39 if (secondPass) {
40 checkResults();
41 } else {
42 openToolboxTabTwice(id, true);
43 }
44 });
45 // We use a timeout to check the tools active time
46 setTimeout(function() {
47 gDevTools.closeToolbox(target);
48 }, TOOL_DELAY);
49 }).then(null, reportError);
50 }
51
52 function checkResults() {
53 let result = Telemetry.prototype.telemetryInfo;
54
55 for (let [histId, value] of Iterator(result)) {
56 if (histId.endsWith("OPENED_PER_USER_FLAG")) {
57 ok(value.length === 1 && value[0] === true,
58 "Per user value " + histId + " has a single value of true");
59 } else if (histId.endsWith("OPENED_BOOLEAN")) {
60 ok(value.length > 1, histId + " has more than one entry");
61
62 let okay = value.every(function(element) {
63 return element === true;
64 });
65
66 ok(okay, "All " + histId + " entries are === true");
67 } else if (histId.endsWith("TIME_ACTIVE_SECONDS")) {
68 ok(value.length > 1, histId + " has more than one entry");
69
70 let okay = value.every(function(element) {
71 return element > 0;
72 });
73
74 ok(okay, "All " + histId + " entries have time > 0");
75 }
76 }
77
78 finishUp();
79 }
80
81 function reportError(error) {
82 let stack = " " + error.stack.replace(/\n?.*?@/g, "\n JS frame :: ");
83
84 ok(false, "ERROR: " + error + " at " + error.fileName + ":" +
85 error.lineNumber + "\n\nStack trace:" + stack);
86 finishUp();
87 }
88
89 function finishUp() {
90 gBrowser.removeCurrentTab();
91
92 Telemetry.prototype.log = Telemetry.prototype._oldlog;
93 delete Telemetry.prototype._oldlog;
94 delete Telemetry.prototype.telemetryInfo;
95
96 TargetFactory = Services = promise = require = null;
97
98 finish();
99 }
100
101 function test() {
102 waitForExplicitFinish();
103 gBrowser.selectedTab = gBrowser.addTab();
104 gBrowser.selectedBrowser.addEventListener("load", function() {
105 gBrowser.selectedBrowser.removeEventListener("load", arguments.callee, true);
106 waitForFocus(init, content);
107 }, true);
108
109 content.location = TEST_URI;
110 }

mercurial