browser/devtools/shared/test/browser_telemetry_sidebar.js

Wed, 31 Dec 2014 06:09:35 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:09:35 +0100
changeset 0
6474c204b198
permissions
-rw-r--r--

Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.

michael@0 1 /* Any copyright is dedicated to the Public Domain.
michael@0 2 http://creativecommons.org/publicdomain/zero/1.0/ */
michael@0 3
michael@0 4 const TEST_URI = "data:text/html;charset=utf-8,<p>browser_telemetry_sidebar.js</p>";
michael@0 5
michael@0 6 // Because we need to gather stats for the period of time that a tool has been
michael@0 7 // opened we make use of setTimeout() to create tool active times.
michael@0 8 const TOOL_DELAY = 200;
michael@0 9
michael@0 10 let {Promise: promise} = Cu.import("resource://gre/modules/devtools/deprecated-sync-thenables.js", {});
michael@0 11 let {Services} = Cu.import("resource://gre/modules/Services.jsm", {});
michael@0 12
michael@0 13 let require = Cu.import("resource://gre/modules/devtools/Loader.jsm", {}).devtools.require;
michael@0 14 let Telemetry = require("devtools/shared/telemetry");
michael@0 15
michael@0 16 function init() {
michael@0 17 Telemetry.prototype.telemetryInfo = {};
michael@0 18 Telemetry.prototype._oldlog = Telemetry.prototype.log;
michael@0 19 Telemetry.prototype.log = function(histogramId, value) {
michael@0 20 if (histogramId) {
michael@0 21 if (!this.telemetryInfo[histogramId]) {
michael@0 22 this.telemetryInfo[histogramId] = [];
michael@0 23 }
michael@0 24
michael@0 25 this.telemetryInfo[histogramId].push(value);
michael@0 26 }
michael@0 27 };
michael@0 28
michael@0 29 testSidebar();
michael@0 30 }
michael@0 31
michael@0 32 function testSidebar() {
michael@0 33 info("Testing sidebar");
michael@0 34
michael@0 35 let target = TargetFactory.forTab(gBrowser.selectedTab);
michael@0 36
michael@0 37 gDevTools.showToolbox(target, "inspector").then(function(toolbox) {
michael@0 38 let inspector = toolbox.getCurrentPanel();
michael@0 39 let sidebarTools = ["ruleview", "computedview", "fontinspector", "layoutview"];
michael@0 40
michael@0 41 // Concatenate the array with itself so that we can open each tool twice.
michael@0 42 sidebarTools.push.apply(sidebarTools, sidebarTools);
michael@0 43
michael@0 44 // See TOOL_DELAY for why we need setTimeout here
michael@0 45 setTimeout(function selectSidebarTab() {
michael@0 46 let tool = sidebarTools.pop();
michael@0 47 if (tool) {
michael@0 48 inspector.sidebar.select(tool);
michael@0 49 setTimeout(function() {
michael@0 50 setTimeout(selectSidebarTab, TOOL_DELAY);
michael@0 51 }, TOOL_DELAY);
michael@0 52 } else {
michael@0 53 checkResults();
michael@0 54 }
michael@0 55 }, TOOL_DELAY);
michael@0 56 });
michael@0 57 }
michael@0 58
michael@0 59 function checkResults() {
michael@0 60 let result = Telemetry.prototype.telemetryInfo;
michael@0 61
michael@0 62 for (let [histId, value] of Iterator(result)) {
michael@0 63 if (histId.startsWith("DEVTOOLS_INSPECTOR_")) {
michael@0 64 // Inspector stats are tested in browser_telemetry_toolboxtabs.js so we
michael@0 65 // skip them here because we only open the inspector once for this test.
michael@0 66 continue;
michael@0 67 }
michael@0 68
michael@0 69 if (histId.endsWith("OPENED_PER_USER_FLAG")) {
michael@0 70 ok(value.length === 1 && value[0] === true,
michael@0 71 "Per user value " + histId + " has a single value of true");
michael@0 72 } else if (histId.endsWith("OPENED_BOOLEAN")) {
michael@0 73 ok(value.length > 1, histId + " has more than one entry");
michael@0 74
michael@0 75 let okay = value.every(function(element) {
michael@0 76 return element === true;
michael@0 77 });
michael@0 78
michael@0 79 ok(okay, "All " + histId + " entries are === true");
michael@0 80 } else if (histId.endsWith("TIME_ACTIVE_SECONDS")) {
michael@0 81 ok(value.length > 1, histId + " has more than one entry");
michael@0 82
michael@0 83 let okay = value.every(function(element) {
michael@0 84 return element > 0;
michael@0 85 });
michael@0 86
michael@0 87 ok(okay, "All " + histId + " entries have time > 0");
michael@0 88 }
michael@0 89 }
michael@0 90
michael@0 91 finishUp();
michael@0 92 }
michael@0 93
michael@0 94 function finishUp() {
michael@0 95 gBrowser.removeCurrentTab();
michael@0 96
michael@0 97 Telemetry.prototype.log = Telemetry.prototype._oldlog;
michael@0 98 delete Telemetry.prototype._oldlog;
michael@0 99 delete Telemetry.prototype.telemetryInfo;
michael@0 100
michael@0 101 TargetFactory = Services = promise = require = null;
michael@0 102
michael@0 103 finish();
michael@0 104 }
michael@0 105
michael@0 106 function test() {
michael@0 107 waitForExplicitFinish();
michael@0 108 gBrowser.selectedTab = gBrowser.addTab();
michael@0 109 gBrowser.selectedBrowser.addEventListener("load", function() {
michael@0 110 gBrowser.selectedBrowser.removeEventListener("load", arguments.callee, true);
michael@0 111 waitForFocus(init, content);
michael@0 112 }, true);
michael@0 113
michael@0 114 content.location = TEST_URI;
michael@0 115 }

mercurial