browser/devtools/netmonitor/test/browser_net_statistics-01.js

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/browser/devtools/netmonitor/test/browser_net_statistics-01.js	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,72 @@
     1.4 +/* Any copyright is dedicated to the Public Domain.
     1.5 +   http://creativecommons.org/publicdomain/zero/1.0/ */
     1.6 +
     1.7 +/**
     1.8 + * Tests if the statistics view is populated correctly.
     1.9 + */
    1.10 +
    1.11 +function test() {
    1.12 +  initNetMonitor(STATISTICS_URL).then(([aTab, aDebuggee, aMonitor]) => {
    1.13 +    info("Starting test... ");
    1.14 +
    1.15 +    let panel = aMonitor.panelWin;
    1.16 +    let { document, $, $all, EVENTS, NetMonitorView } = panel;
    1.17 +
    1.18 +    is(NetMonitorView.currentFrontendMode, "network-inspector-view",
    1.19 +      "The initial frontend mode is correct.");
    1.20 +
    1.21 +    is($("#primed-cache-chart").childNodes.length, 0,
    1.22 +      "There should be no primed cache chart created yet.");
    1.23 +    is($("#empty-cache-chart").childNodes.length, 0,
    1.24 +      "There should be no empty cache chart created yet.");
    1.25 +
    1.26 +    waitFor(panel, EVENTS.PLACEHOLDER_CHARTS_DISPLAYED).then(() => {
    1.27 +      is($("#primed-cache-chart").childNodes.length, 1,
    1.28 +        "There should be a placeholder primed cache chart created now.");
    1.29 +      is($("#empty-cache-chart").childNodes.length, 1,
    1.30 +        "There should be a placeholder empty cache chart created now.");
    1.31 +
    1.32 +      is($all(".pie-chart-container[placeholder=true]").length, 2,
    1.33 +        "Two placeholder pie chart appear to be rendered correctly.");
    1.34 +      is($all(".table-chart-container[placeholder=true]").length, 2,
    1.35 +        "Two placeholder table chart appear to be rendered correctly.");
    1.36 +
    1.37 +      promise.all([
    1.38 +        waitFor(panel, EVENTS.PRIMED_CACHE_CHART_DISPLAYED),
    1.39 +        waitFor(panel, EVENTS.EMPTY_CACHE_CHART_DISPLAYED)
    1.40 +      ]).then(() => {
    1.41 +        is($("#primed-cache-chart").childNodes.length, 1,
    1.42 +          "There should be a real primed cache chart created now.");
    1.43 +        is($("#empty-cache-chart").childNodes.length, 1,
    1.44 +          "There should be a real empty cache chart created now.");
    1.45 +
    1.46 +        Task.spawn(function*() {
    1.47 +          yield until(() => $all(".pie-chart-container:not([placeholder=true])").length == 2);
    1.48 +          ok(true, "Two real pie charts appear to be rendered correctly.");
    1.49 +
    1.50 +          yield until(() => $all(".table-chart-container:not([placeholder=true])").length == 2);
    1.51 +          ok(true, "Two real table charts appear to be rendered correctly.")
    1.52 +
    1.53 +          teardown(aMonitor).then(finish);
    1.54 +        });
    1.55 +      });
    1.56 +    });
    1.57 +
    1.58 +    NetMonitorView.toggleFrontendMode();
    1.59 +
    1.60 +    is(NetMonitorView.currentFrontendMode, "network-statistics-view",
    1.61 +      "The current frontend mode is correct.");
    1.62 +  });
    1.63 +}
    1.64 +
    1.65 +function waitForTick() {
    1.66 +  let deferred = promise.defer();
    1.67 +  executeSoon(deferred.resolve);
    1.68 +  return deferred.promise;
    1.69 +}
    1.70 +
    1.71 +function until(predicate) {
    1.72 +  return Task.spawn(function*() {
    1.73 +    while (!predicate()) yield waitForTick();
    1.74 +  });
    1.75 +}

mercurial