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.

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

mercurial