browser/devtools/shared/test/browser_telemetry_button_tilt.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_button_tilt.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 = Cu.import("resource://gre/modules/devtools/deprecated-sync-thenables.js", {}).Promise;
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 testButton("command-button-tilt");
michael@0 30 }
michael@0 31
michael@0 32 function testButton(id) {
michael@0 33 info("Testing " + id);
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 info("inspector opened");
michael@0 39
michael@0 40 let button = toolbox.doc.querySelector("#" + id);
michael@0 41 ok(button, "Captain, we have the button");
michael@0 42
michael@0 43 delayedClicks(button, 4).then(function() {
michael@0 44 checkResults("_TILT_");
michael@0 45 });
michael@0 46 }).then(null, console.error);
michael@0 47 }
michael@0 48
michael@0 49 function delayedClicks(node, clicks) {
michael@0 50 let deferred = promise.defer();
michael@0 51 let clicked = 0;
michael@0 52
michael@0 53 // See TOOL_DELAY for why we need setTimeout here
michael@0 54 setTimeout(function delayedClick() {
michael@0 55 info("Clicking button " + node.id);
michael@0 56 node.click();
michael@0 57 clicked++;
michael@0 58
michael@0 59 if (clicked >= clicks) {
michael@0 60 deferred.resolve(node);
michael@0 61 } else {
michael@0 62 setTimeout(delayedClick, TOOL_DELAY);
michael@0 63 }
michael@0 64 }, TOOL_DELAY);
michael@0 65
michael@0 66 return deferred.promise;
michael@0 67 }
michael@0 68
michael@0 69 function checkResults(histIdFocus) {
michael@0 70 let result = Telemetry.prototype.telemetryInfo;
michael@0 71
michael@0 72 for (let [histId, value] of Iterator(result)) {
michael@0 73 if (histId.startsWith("DEVTOOLS_INSPECTOR_") ||
michael@0 74 !histId.contains(histIdFocus)) {
michael@0 75 // Inspector stats are tested in
michael@0 76 // browser_telemetry_toolboxtabs_{toolname}.js so we skip them here
michael@0 77 // because we only open the inspector once for this test.
michael@0 78 continue;
michael@0 79 }
michael@0 80
michael@0 81 if (histId.endsWith("OPENED_PER_USER_FLAG")) {
michael@0 82 ok(value.length === 1 && value[0] === true,
michael@0 83 "Per user value " + histId + " has a single value of true");
michael@0 84 } else if (histId.endsWith("OPENED_BOOLEAN")) {
michael@0 85 ok(value.length > 1, histId + " has more than one entry");
michael@0 86
michael@0 87 let okay = value.every(function(element) {
michael@0 88 return element === true;
michael@0 89 });
michael@0 90
michael@0 91 ok(okay, "All " + histId + " entries are === true");
michael@0 92 } else if (histId.endsWith("TIME_ACTIVE_SECONDS")) {
michael@0 93 ok(value.length > 1, histId + " has more than one entry");
michael@0 94
michael@0 95 let okay = value.every(function(element) {
michael@0 96 return element > 0;
michael@0 97 });
michael@0 98
michael@0 99 ok(okay, "All " + histId + " entries have time > 0");
michael@0 100 }
michael@0 101 }
michael@0 102
michael@0 103 finishUp();
michael@0 104 }
michael@0 105
michael@0 106 function finishUp() {
michael@0 107 gBrowser.removeCurrentTab();
michael@0 108
michael@0 109 Telemetry.prototype.log = Telemetry.prototype._oldlog;
michael@0 110 delete Telemetry.prototype._oldlog;
michael@0 111 delete Telemetry.prototype.telemetryInfo;
michael@0 112
michael@0 113 TargetFactory = Services = promise = require = null;
michael@0 114
michael@0 115 finish();
michael@0 116 }
michael@0 117
michael@0 118 function test() {
michael@0 119 waitForExplicitFinish();
michael@0 120 gBrowser.selectedTab = gBrowser.addTab();
michael@0 121 gBrowser.selectedBrowser.addEventListener("load", function() {
michael@0 122 gBrowser.selectedBrowser.removeEventListener("load", arguments.callee, true);
michael@0 123 waitForFocus(init, content);
michael@0 124 }, true);
michael@0 125
michael@0 126 content.location = TEST_URI;
michael@0 127 }

mercurial