browser/devtools/shared/test/browser_telemetry_sidebar.js

changeset 0
6474c204b198
equal deleted inserted replaced
-1:000000000000 0:2d7612a65dc1
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_sidebar.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 testSidebar();
30 }
31
32 function testSidebar() {
33 info("Testing sidebar");
34
35 let target = TargetFactory.forTab(gBrowser.selectedTab);
36
37 gDevTools.showToolbox(target, "inspector").then(function(toolbox) {
38 let inspector = toolbox.getCurrentPanel();
39 let sidebarTools = ["ruleview", "computedview", "fontinspector", "layoutview"];
40
41 // Concatenate the array with itself so that we can open each tool twice.
42 sidebarTools.push.apply(sidebarTools, sidebarTools);
43
44 // See TOOL_DELAY for why we need setTimeout here
45 setTimeout(function selectSidebarTab() {
46 let tool = sidebarTools.pop();
47 if (tool) {
48 inspector.sidebar.select(tool);
49 setTimeout(function() {
50 setTimeout(selectSidebarTab, TOOL_DELAY);
51 }, TOOL_DELAY);
52 } else {
53 checkResults();
54 }
55 }, TOOL_DELAY);
56 });
57 }
58
59 function checkResults() {
60 let result = Telemetry.prototype.telemetryInfo;
61
62 for (let [histId, value] of Iterator(result)) {
63 if (histId.startsWith("DEVTOOLS_INSPECTOR_")) {
64 // Inspector stats are tested in browser_telemetry_toolboxtabs.js so we
65 // skip them here because we only open the inspector once for this test.
66 continue;
67 }
68
69 if (histId.endsWith("OPENED_PER_USER_FLAG")) {
70 ok(value.length === 1 && value[0] === true,
71 "Per user value " + histId + " has a single value of true");
72 } else if (histId.endsWith("OPENED_BOOLEAN")) {
73 ok(value.length > 1, histId + " has more than one entry");
74
75 let okay = value.every(function(element) {
76 return element === true;
77 });
78
79 ok(okay, "All " + histId + " entries are === true");
80 } else if (histId.endsWith("TIME_ACTIVE_SECONDS")) {
81 ok(value.length > 1, histId + " has more than one entry");
82
83 let okay = value.every(function(element) {
84 return element > 0;
85 });
86
87 ok(okay, "All " + histId + " entries have time > 0");
88 }
89 }
90
91 finishUp();
92 }
93
94 function finishUp() {
95 gBrowser.removeCurrentTab();
96
97 Telemetry.prototype.log = Telemetry.prototype._oldlog;
98 delete Telemetry.prototype._oldlog;
99 delete Telemetry.prototype.telemetryInfo;
100
101 TargetFactory = Services = promise = require = null;
102
103 finish();
104 }
105
106 function test() {
107 waitForExplicitFinish();
108 gBrowser.selectedTab = gBrowser.addTab();
109 gBrowser.selectedBrowser.addEventListener("load", function() {
110 gBrowser.selectedBrowser.removeEventListener("load", arguments.callee, true);
111 waitForFocus(init, content);
112 }, true);
113
114 content.location = TEST_URI;
115 }

mercurial