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

changeset 0
6474c204b198
equal deleted inserted replaced
-1:000000000000 0:a447157a4040
1 /* Any copyright is dedicated to the Public Domain.
2 http://creativecommons.org/publicdomain/zero/1.0/ */
3
4 /**
5 * Tests if the statistics view is populated correctly.
6 */
7
8 function test() {
9 initNetMonitor(STATISTICS_URL).then(([aTab, aDebuggee, aMonitor]) => {
10 info("Starting test... ");
11
12 let panel = aMonitor.panelWin;
13 let { document, $, $all, EVENTS, NetMonitorView } = panel;
14
15 is(NetMonitorView.currentFrontendMode, "network-inspector-view",
16 "The initial frontend mode is correct.");
17
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.");
22
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.");
28
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.");
33
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.");
42
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.");
46
47 yield until(() => $all(".table-chart-container:not([placeholder=true])").length == 2);
48 ok(true, "Two real table charts appear to be rendered correctly.")
49
50 teardown(aMonitor).then(finish);
51 });
52 });
53 });
54
55 NetMonitorView.toggleFrontendMode();
56
57 is(NetMonitorView.currentFrontendMode, "network-statistics-view",
58 "The current frontend mode is correct.");
59 });
60 }
61
62 function waitForTick() {
63 let deferred = promise.defer();
64 executeSoon(deferred.resolve);
65 return deferred.promise;
66 }
67
68 function until(predicate) {
69 return Task.spawn(function*() {
70 while (!predicate()) yield waitForTick();
71 });
72 }

mercurial