bug 1218576 - Update test browser_use_counters.js to use aggregated child telemetry r=gfritzsche

waitOnCondition is used to wait for the telemetry batch to be processed
(roughly every 2s). It resolves and rejects to the same value as there are a
couple of xfail tests that need the wrong answer.

MozReview-Commit-ID: I1JqEXQSL7d
This commit is contained in:
Chris H-C 2016-07-05 09:34:33 -04:00
Родитель 01ec9d91b8
Коммит 2079cedba0
1 изменённых файлов: 20 добавлений и 23 удалений

Просмотреть файл

@ -3,6 +3,7 @@
requestLongerTimeout(2); requestLongerTimeout(2);
var {Promise: promise} = Cu.import("resource://gre/modules/Promise.jsm", {}); var {Promise: promise} = Cu.import("resource://gre/modules/Promise.jsm", {});
Cu.import("resource://gre/modules/Services.jsm");
const gHttpTestRoot = "http://example.com/browser/dom/base/test/"; const gHttpTestRoot = "http://example.com/browser/dom/base/test/";
@ -104,22 +105,18 @@ function waitForPageLoad(browser) {
}); });
} }
function grabHistogramsFromContent(browser, use_counter_middlefix) { function grabHistogramsFromContent(use_counter_middlefix, page_before = null) {
return ContentTask.spawn(browser, { middlefix: use_counter_middlefix }, function* (arg) {
let telemetry = Cc["@mozilla.org/base/telemetry;1"].getService(Ci.nsITelemetry); let telemetry = Cc["@mozilla.org/base/telemetry;1"].getService(Ci.nsITelemetry);
function snapshot_histogram(name) { let suffix = Services.appinfo.browserTabsRemoteAutostart ? "#content" : "";
return telemetry.getHistogramById(name).snapshot(); let gather = () => [
} telemetry.getHistogramById("USE_COUNTER2_" + use_counter_middlefix + "_PAGE" + suffix).snapshot().sum,
telemetry.getHistogramById("USE_COUNTER2_" + use_counter_middlefix + "_DOCUMENT" + suffix).snapshot().sum,
let histogram_page_name = "USE_COUNTER2_" + arg.middlefix + "_PAGE"; telemetry.getHistogramById("CONTENT_DOCUMENTS_DESTROYED" + suffix).snapshot().sum,
let histogram_document_name = "USE_COUNTER2_" + arg.middlefix + "_DOCUMENT"; telemetry.getHistogramById("TOP_LEVEL_CONTENT_DOCUMENTS_DESTROYED" + suffix).snapshot().sum,
let histogram_page = snapshot_histogram(histogram_page_name); ];
let histogram_document = snapshot_histogram(histogram_document_name); return BrowserTestUtils.waitForCondition(() => {
let histogram_docs = snapshot_histogram("CONTENT_DOCUMENTS_DESTROYED"); return page_before != telemetry.getHistogramById("USE_COUNTER2_" + use_counter_middlefix + "_PAGE" + suffix).snapshot().sum;
let histogram_toplevel_docs = snapshot_histogram("TOP_LEVEL_CONTENT_DOCUMENTS_DESTROYED"); }).then(gather, gather);
return [histogram_page.sum, histogram_document.sum,
histogram_docs.sum, histogram_toplevel_docs.sum];
});
} }
var check_use_counter_iframe = Task.async(function* (file, use_counter_middlefix, check_documents=true) { var check_use_counter_iframe = Task.async(function* (file, use_counter_middlefix, check_documents=true) {
@ -133,7 +130,7 @@ var check_use_counter_iframe = Task.async(function* (file, use_counter_middlefix
// interested in. // interested in.
let [histogram_page_before, histogram_document_before, let [histogram_page_before, histogram_document_before,
histogram_docs_before, histogram_toplevel_docs_before] = histogram_docs_before, histogram_toplevel_docs_before] =
yield grabHistogramsFromContent(gBrowser.selectedBrowser, use_counter_middlefix); yield grabHistogramsFromContent(use_counter_middlefix);
gBrowser.selectedBrowser.loadURI(gHttpTestRoot + "file_use_counter_outer.html"); gBrowser.selectedBrowser.loadURI(gHttpTestRoot + "file_use_counter_outer.html");
yield waitForPageLoad(gBrowser.selectedBrowser); yield waitForPageLoad(gBrowser.selectedBrowser);
@ -151,7 +148,7 @@ var check_use_counter_iframe = Task.async(function* (file, use_counter_middlefix
event.target.removeEventListener("load", listener, true); event.target.removeEventListener("load", listener, true);
// We flush the main document first, then the iframe's document to // We flush the main document first, then the iframe's document to
// ensure any propagation that might happen from child->parent should // ensure any propagation that might happen from content->parent should
// have already happened when counters are reported to telemetry. // have already happened when counters are reported to telemetry.
wu.forceUseCounterFlush(content.document); wu.forceUseCounterFlush(content.document);
wu.forceUseCounterFlush(iframe.contentDocument); wu.forceUseCounterFlush(iframe.contentDocument);
@ -174,7 +171,7 @@ var check_use_counter_iframe = Task.async(function* (file, use_counter_middlefix
// Grab histograms again and compare. // Grab histograms again and compare.
let [histogram_page_after, histogram_document_after, let [histogram_page_after, histogram_document_after,
histogram_docs_after, histogram_toplevel_docs_after] = histogram_docs_after, histogram_toplevel_docs_after] =
yield grabHistogramsFromContent(gBrowser.selectedBrowser, use_counter_middlefix); yield grabHistogramsFromContent(use_counter_middlefix, histogram_page_before);
is(histogram_page_after, histogram_page_before + 1, is(histogram_page_after, histogram_page_before + 1,
"page counts for " + use_counter_middlefix + " after are correct"); "page counts for " + use_counter_middlefix + " after are correct");
@ -197,7 +194,7 @@ var check_use_counter_img = Task.async(function* (file, use_counter_middlefix) {
// interested in. // interested in.
let [histogram_page_before, histogram_document_before, let [histogram_page_before, histogram_document_before,
histogram_docs_before, histogram_toplevel_docs_before] = histogram_docs_before, histogram_toplevel_docs_before] =
yield grabHistogramsFromContent(gBrowser.selectedBrowser, use_counter_middlefix); yield grabHistogramsFromContent(use_counter_middlefix);
gBrowser.selectedBrowser.loadURI(gHttpTestRoot + "file_use_counter_outer.html"); gBrowser.selectedBrowser.loadURI(gHttpTestRoot + "file_use_counter_outer.html");
yield waitForPageLoad(gBrowser.selectedBrowser); yield waitForPageLoad(gBrowser.selectedBrowser);
@ -239,7 +236,7 @@ var check_use_counter_img = Task.async(function* (file, use_counter_middlefix) {
// Grab histograms again and compare. // Grab histograms again and compare.
let [histogram_page_after, histogram_document_after, let [histogram_page_after, histogram_document_after,
histogram_docs_after, histogram_toplevel_docs_after] = histogram_docs_after, histogram_toplevel_docs_after] =
yield grabHistogramsFromContent(gBrowser.selectedBrowser, use_counter_middlefix); yield grabHistogramsFromContent(use_counter_middlefix, histogram_page_before);
is(histogram_page_after, histogram_page_before + 1, is(histogram_page_after, histogram_page_before + 1,
"page counts for " + use_counter_middlefix + " after are correct"); "page counts for " + use_counter_middlefix + " after are correct");
is(histogram_document_after, histogram_document_before + 1, is(histogram_document_after, histogram_document_before + 1,
@ -263,7 +260,7 @@ var check_use_counter_direct = Task.async(function* (file, use_counter_middlefix
// interested in. // interested in.
let [histogram_page_before, histogram_document_before, let [histogram_page_before, histogram_document_before,
histogram_docs_before, histogram_toplevel_docs_before] = histogram_docs_before, histogram_toplevel_docs_before] =
yield grabHistogramsFromContent(gBrowser.selectedBrowser, use_counter_middlefix); yield grabHistogramsFromContent(use_counter_middlefix);
gBrowser.selectedBrowser.loadURI(gHttpTestRoot + file); gBrowser.selectedBrowser.loadURI(gHttpTestRoot + file);
yield ContentTask.spawn(gBrowser.selectedBrowser, null, function*() { yield ContentTask.spawn(gBrowser.selectedBrowser, null, function*() {
@ -292,7 +289,7 @@ var check_use_counter_direct = Task.async(function* (file, use_counter_middlefix
// Grab histograms again and compare. // Grab histograms again and compare.
let [histogram_page_after, histogram_document_after, let [histogram_page_after, histogram_document_after,
histogram_docs_after, histogram_toplevel_docs_after] = histogram_docs_after, histogram_toplevel_docs_after] =
yield grabHistogramsFromContent(gBrowser.selectedBrowser, use_counter_middlefix); yield grabHistogramsFromContent(use_counter_middlefix, histogram_page_before);
(xfail ? todo_is : is)(histogram_page_after, histogram_page_before + 1, (xfail ? todo_is : is)(histogram_page_after, histogram_page_before + 1,
"page counts for " + use_counter_middlefix + " after are correct"); "page counts for " + use_counter_middlefix + " after are correct");
(xfail ? todo_is : is)(histogram_document_after, histogram_document_before + 1, (xfail ? todo_is : is)(histogram_document_after, histogram_document_before + 1,