browser/devtools/shared/test/browser_telemetry_toolboxtabs_styleeditor.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.

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

mercurial