Wed, 31 Dec 2014 06:09:35 +0100
Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.
1 /* Any copyright is dedicated to the Public Domain.
2 http://creativecommons.org/publicdomain/zero/1.0/ */
4 const TEST_URI = "data:text/html;charset=utf-8,<p>browser_telemetry_sidebar.js</p>";
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;
10 let {Promise: promise} = Cu.import("resource://gre/modules/devtools/deprecated-sync-thenables.js", {});
11 let {Services} = Cu.import("resource://gre/modules/Services.jsm", {});
13 let require = Cu.import("resource://gre/modules/devtools/Loader.jsm", {}).devtools.require;
14 let Telemetry = require("devtools/shared/telemetry");
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 }
25 this.telemetryInfo[histogramId].push(value);
26 }
27 };
29 testSidebar();
30 }
32 function testSidebar() {
33 info("Testing sidebar");
35 let target = TargetFactory.forTab(gBrowser.selectedTab);
37 gDevTools.showToolbox(target, "inspector").then(function(toolbox) {
38 let inspector = toolbox.getCurrentPanel();
39 let sidebarTools = ["ruleview", "computedview", "fontinspector", "layoutview"];
41 // Concatenate the array with itself so that we can open each tool twice.
42 sidebarTools.push.apply(sidebarTools, sidebarTools);
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 }
59 function checkResults() {
60 let result = Telemetry.prototype.telemetryInfo;
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 }
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");
75 let okay = value.every(function(element) {
76 return element === true;
77 });
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");
83 let okay = value.every(function(element) {
84 return element > 0;
85 });
87 ok(okay, "All " + histId + " entries have time > 0");
88 }
89 }
91 finishUp();
92 }
94 function finishUp() {
95 gBrowser.removeCurrentTab();
97 Telemetry.prototype.log = Telemetry.prototype._oldlog;
98 delete Telemetry.prototype._oldlog;
99 delete Telemetry.prototype.telemetryInfo;
101 TargetFactory = Services = promise = require = null;
103 finish();
104 }
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);
114 content.location = TEST_URI;
115 }