michael@0: /* Any copyright is dedicated to the Public Domain. michael@0: http://creativecommons.org/publicdomain/zero/1.0/ */ michael@0: michael@0: /** michael@0: * Tests if the statistics view is populated correctly. michael@0: */ michael@0: michael@0: function test() { michael@0: initNetMonitor(STATISTICS_URL).then(([aTab, aDebuggee, aMonitor]) => { michael@0: info("Starting test... "); michael@0: michael@0: let panel = aMonitor.panelWin; michael@0: let { document, $, $all, EVENTS, NetMonitorView } = panel; michael@0: michael@0: is(NetMonitorView.currentFrontendMode, "network-inspector-view", michael@0: "The initial frontend mode is correct."); michael@0: michael@0: is($("#primed-cache-chart").childNodes.length, 0, michael@0: "There should be no primed cache chart created yet."); michael@0: is($("#empty-cache-chart").childNodes.length, 0, michael@0: "There should be no empty cache chart created yet."); michael@0: michael@0: waitFor(panel, EVENTS.PLACEHOLDER_CHARTS_DISPLAYED).then(() => { michael@0: is($("#primed-cache-chart").childNodes.length, 1, michael@0: "There should be a placeholder primed cache chart created now."); michael@0: is($("#empty-cache-chart").childNodes.length, 1, michael@0: "There should be a placeholder empty cache chart created now."); michael@0: michael@0: is($all(".pie-chart-container[placeholder=true]").length, 2, michael@0: "Two placeholder pie chart appear to be rendered correctly."); michael@0: is($all(".table-chart-container[placeholder=true]").length, 2, michael@0: "Two placeholder table chart appear to be rendered correctly."); michael@0: michael@0: promise.all([ michael@0: waitFor(panel, EVENTS.PRIMED_CACHE_CHART_DISPLAYED), michael@0: waitFor(panel, EVENTS.EMPTY_CACHE_CHART_DISPLAYED) michael@0: ]).then(() => { michael@0: is($("#primed-cache-chart").childNodes.length, 1, michael@0: "There should be a real primed cache chart created now."); michael@0: is($("#empty-cache-chart").childNodes.length, 1, michael@0: "There should be a real empty cache chart created now."); michael@0: michael@0: Task.spawn(function*() { michael@0: yield until(() => $all(".pie-chart-container:not([placeholder=true])").length == 2); michael@0: ok(true, "Two real pie charts appear to be rendered correctly."); michael@0: michael@0: yield until(() => $all(".table-chart-container:not([placeholder=true])").length == 2); michael@0: ok(true, "Two real table charts appear to be rendered correctly.") michael@0: michael@0: teardown(aMonitor).then(finish); michael@0: }); michael@0: }); michael@0: }); michael@0: michael@0: NetMonitorView.toggleFrontendMode(); michael@0: michael@0: is(NetMonitorView.currentFrontendMode, "network-statistics-view", michael@0: "The current frontend mode is correct."); michael@0: }); michael@0: } michael@0: michael@0: function waitForTick() { michael@0: let deferred = promise.defer(); michael@0: executeSoon(deferred.resolve); michael@0: return deferred.promise; michael@0: } michael@0: michael@0: function until(predicate) { michael@0: return Task.spawn(function*() { michael@0: while (!predicate()) yield waitForTick(); michael@0: }); michael@0: }