browser/devtools/netmonitor/test/browser_net_statistics-01.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 /**
     5  * Tests if the statistics view is populated correctly.
     6  */
     8 function test() {
     9   initNetMonitor(STATISTICS_URL).then(([aTab, aDebuggee, aMonitor]) => {
    10     info("Starting test... ");
    12     let panel = aMonitor.panelWin;
    13     let { document, $, $all, EVENTS, NetMonitorView } = panel;
    15     is(NetMonitorView.currentFrontendMode, "network-inspector-view",
    16       "The initial frontend mode is correct.");
    18     is($("#primed-cache-chart").childNodes.length, 0,
    19       "There should be no primed cache chart created yet.");
    20     is($("#empty-cache-chart").childNodes.length, 0,
    21       "There should be no empty cache chart created yet.");
    23     waitFor(panel, EVENTS.PLACEHOLDER_CHARTS_DISPLAYED).then(() => {
    24       is($("#primed-cache-chart").childNodes.length, 1,
    25         "There should be a placeholder primed cache chart created now.");
    26       is($("#empty-cache-chart").childNodes.length, 1,
    27         "There should be a placeholder empty cache chart created now.");
    29       is($all(".pie-chart-container[placeholder=true]").length, 2,
    30         "Two placeholder pie chart appear to be rendered correctly.");
    31       is($all(".table-chart-container[placeholder=true]").length, 2,
    32         "Two placeholder table chart appear to be rendered correctly.");
    34       promise.all([
    35         waitFor(panel, EVENTS.PRIMED_CACHE_CHART_DISPLAYED),
    36         waitFor(panel, EVENTS.EMPTY_CACHE_CHART_DISPLAYED)
    37       ]).then(() => {
    38         is($("#primed-cache-chart").childNodes.length, 1,
    39           "There should be a real primed cache chart created now.");
    40         is($("#empty-cache-chart").childNodes.length, 1,
    41           "There should be a real empty cache chart created now.");
    43         Task.spawn(function*() {
    44           yield until(() => $all(".pie-chart-container:not([placeholder=true])").length == 2);
    45           ok(true, "Two real pie charts appear to be rendered correctly.");
    47           yield until(() => $all(".table-chart-container:not([placeholder=true])").length == 2);
    48           ok(true, "Two real table charts appear to be rendered correctly.")
    50           teardown(aMonitor).then(finish);
    51         });
    52       });
    53     });
    55     NetMonitorView.toggleFrontendMode();
    57     is(NetMonitorView.currentFrontendMode, "network-statistics-view",
    58       "The current frontend mode is correct.");
    59   });
    60 }
    62 function waitForTick() {
    63   let deferred = promise.defer();
    64   executeSoon(deferred.resolve);
    65   return deferred.promise;
    66 }
    68 function until(predicate) {
    69   return Task.spawn(function*() {
    70     while (!predicate()) yield waitForTick();
    71   });
    72 }

mercurial