зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1029031 - Rewrite test to use tasks; r=MattN
An upcoming patch will add more code to browser_urlbar_search_healthreport.js. We now have support for running tasks in bc tests, so let's use it to make my life easier. --HG-- extra : rebase_source : 2fbec7c264f7ebaa8b9abd49694ae56c4d74b7c7 extra : amend_source : 551ee4c0e87f42cd44c9b5395278b56dfbc89b90
This commit is contained in:
Родитель
9241a8d8d6
Коммит
39d917bcf8
|
@ -3,15 +3,13 @@
|
|||
|
||||
"use strict";
|
||||
|
||||
function test() {
|
||||
waitForExplicitFinish();
|
||||
add_task(function* test_healthreport_search_recording() {
|
||||
try {
|
||||
let cm = Cc["@mozilla.org/categorymanager;1"].getService(Ci.nsICategoryManager);
|
||||
cm.getCategoryEntry("healthreport-js-provider-default", "SearchesProvider");
|
||||
} catch (ex) {
|
||||
// Health Report disabled, or no SearchesProvider.
|
||||
ok(true, "Firefox Health Report is not enabled.");
|
||||
finish();
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -20,12 +18,12 @@ function test() {
|
|||
.wrappedJSObject
|
||||
.healthReporter;
|
||||
ok(reporter, "Health Reporter available.");
|
||||
reporter.onInit().then(function onInit() {
|
||||
yield reporter.onInit();
|
||||
let provider = reporter.getProvider("org.mozilla.searches");
|
||||
ok(provider, "Searches provider is available.");
|
||||
let m = provider.getMeasurement("counts", 3);
|
||||
|
||||
m.getValues().then(function onData(data) {
|
||||
let data = yield m.getValues();
|
||||
let now = new Date();
|
||||
let oldCount = 0;
|
||||
|
||||
|
@ -47,45 +45,20 @@ function test() {
|
|||
getSubmission(searchStr, "", "keyword").uri.spec;
|
||||
|
||||
// Expect the search URL to load but stop it as soon as it starts.
|
||||
let loadPromise = waitForDocLoadAndStopIt(expectedURL);
|
||||
|
||||
// Meanwhile, poll for the new measurement.
|
||||
let count = 0;
|
||||
let measurementDeferred = Promise.defer();
|
||||
function getNewMeasurement() {
|
||||
if (count++ >= 10) {
|
||||
ok(false, "Timed out waiting for new measurement");
|
||||
measurementDeferred.resolve();
|
||||
return;
|
||||
}
|
||||
m.getValues().then(function onData(data) {
|
||||
if (data.days.hasDay(now)) {
|
||||
let day = data.days.getDay(now);
|
||||
if (day.has(field)) {
|
||||
let newCount = day.get(field);
|
||||
if (newCount > oldCount) {
|
||||
is(newCount, oldCount + 1,
|
||||
"Exactly one search has been recorded.");
|
||||
measurementDeferred.resolve();
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
executeSoon(getNewMeasurement);
|
||||
});
|
||||
}
|
||||
executeSoon(getNewMeasurement);
|
||||
let docLoadPromise = waitForDocLoadAndStopIt(expectedURL);
|
||||
|
||||
// Trigger the search.
|
||||
gURLBar.value = searchStr;
|
||||
gURLBar.handleCommand();
|
||||
|
||||
// Wait for the page load and new measurement.
|
||||
Promise.all([loadPromise, measurementDeferred.promise]).then(() => {
|
||||
gBrowser.removeTab(tab);
|
||||
finish();
|
||||
});
|
||||
});
|
||||
});
|
||||
}
|
||||
yield docLoadPromise;
|
||||
|
||||
data = yield m.getValues();
|
||||
ok(data.days.hasDay(now), "We have a search measurement for today.");
|
||||
let day = data.days.getDay(now);
|
||||
ok(day.has(field), "Have a search count for the urlbar.");
|
||||
let newCount = day.get(field);
|
||||
is(newCount, oldCount + 1, "We recorded one new search.");
|
||||
|
||||
gBrowser.removeTab(tab);
|
||||
});
|
||||
|
|
Загрузка…
Ссылка в новой задаче