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.
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_toolboxtabs_inspector.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 | openToolboxTabTwice("inspector", false); |
michael@0 | 30 | } |
michael@0 | 31 | |
michael@0 | 32 | function openToolboxTabTwice(id, secondPass) { |
michael@0 | 33 | let target = TargetFactory.forTab(gBrowser.selectedTab); |
michael@0 | 34 | |
michael@0 | 35 | gDevTools.showToolbox(target, id).then(function(toolbox) { |
michael@0 | 36 | info("Toolbox tab " + id + " opened"); |
michael@0 | 37 | |
michael@0 | 38 | toolbox.once("destroyed", function() { |
michael@0 | 39 | if (secondPass) { |
michael@0 | 40 | checkResults(); |
michael@0 | 41 | } else { |
michael@0 | 42 | openToolboxTabTwice(id, true); |
michael@0 | 43 | } |
michael@0 | 44 | }); |
michael@0 | 45 | // We use a timeout to check the tools active time |
michael@0 | 46 | setTimeout(function() { |
michael@0 | 47 | gDevTools.closeToolbox(target); |
michael@0 | 48 | }, TOOL_DELAY); |
michael@0 | 49 | }).then(null, reportError); |
michael@0 | 50 | } |
michael@0 | 51 | |
michael@0 | 52 | function checkResults() { |
michael@0 | 53 | let result = Telemetry.prototype.telemetryInfo; |
michael@0 | 54 | |
michael@0 | 55 | for (let [histId, value] of Iterator(result)) { |
michael@0 | 56 | if (histId.endsWith("OPENED_PER_USER_FLAG")) { |
michael@0 | 57 | ok(value.length === 1 && value[0] === true, |
michael@0 | 58 | "Per user value " + histId + " has a single value of true"); |
michael@0 | 59 | } else if (histId.endsWith("OPENED_BOOLEAN")) { |
michael@0 | 60 | ok(value.length > 1, histId + " has more than one entry"); |
michael@0 | 61 | |
michael@0 | 62 | let okay = value.every(function(element) { |
michael@0 | 63 | return element === true; |
michael@0 | 64 | }); |
michael@0 | 65 | |
michael@0 | 66 | ok(okay, "All " + histId + " entries are === true"); |
michael@0 | 67 | } else if (histId.endsWith("TIME_ACTIVE_SECONDS")) { |
michael@0 | 68 | ok(value.length > 1, histId + " has more than one entry"); |
michael@0 | 69 | |
michael@0 | 70 | let okay = value.every(function(element) { |
michael@0 | 71 | return element > 0; |
michael@0 | 72 | }); |
michael@0 | 73 | |
michael@0 | 74 | ok(okay, "All " + histId + " entries have time > 0"); |
michael@0 | 75 | } |
michael@0 | 76 | } |
michael@0 | 77 | |
michael@0 | 78 | finishUp(); |
michael@0 | 79 | } |
michael@0 | 80 | |
michael@0 | 81 | function reportError(error) { |
michael@0 | 82 | let stack = " " + error.stack.replace(/\n?.*?@/g, "\n JS frame :: "); |
michael@0 | 83 | |
michael@0 | 84 | ok(false, "ERROR: " + error + " at " + error.fileName + ":" + |
michael@0 | 85 | error.lineNumber + "\n\nStack trace:" + stack); |
michael@0 | 86 | finishUp(); |
michael@0 | 87 | } |
michael@0 | 88 | |
michael@0 | 89 | function finishUp() { |
michael@0 | 90 | gBrowser.removeCurrentTab(); |
michael@0 | 91 | |
michael@0 | 92 | Telemetry.prototype.log = Telemetry.prototype._oldlog; |
michael@0 | 93 | delete Telemetry.prototype._oldlog; |
michael@0 | 94 | delete Telemetry.prototype.telemetryInfo; |
michael@0 | 95 | |
michael@0 | 96 | TargetFactory = Services = promise = require = null; |
michael@0 | 97 | |
michael@0 | 98 | finish(); |
michael@0 | 99 | } |
michael@0 | 100 | |
michael@0 | 101 | function test() { |
michael@0 | 102 | waitForExplicitFinish(); |
michael@0 | 103 | gBrowser.selectedTab = gBrowser.addTab(); |
michael@0 | 104 | gBrowser.selectedBrowser.addEventListener("load", function() { |
michael@0 | 105 | gBrowser.selectedBrowser.removeEventListener("load", arguments.callee, true); |
michael@0 | 106 | waitForFocus(init, content); |
michael@0 | 107 | }, true); |
michael@0 | 108 | |
michael@0 | 109 | content.location = TEST_URI; |
michael@0 | 110 | } |