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:
Gregory Szorc 2014-06-25 12:38:37 -07:00
Родитель 9241a8d8d6
Коммит 39d917bcf8
1 изменённых файлов: 35 добавлений и 62 удалений

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

@ -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,72 +18,47 @@ function test() {
.wrappedJSObject
.healthReporter;
ok(reporter, "Health Reporter available.");
reporter.onInit().then(function onInit() {
let provider = reporter.getProvider("org.mozilla.searches");
ok(provider, "Searches provider is available.");
let m = provider.getMeasurement("counts", 3);
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 now = new Date();
let oldCount = 0;
let data = yield m.getValues();
let now = new Date();
let oldCount = 0;
// This will to be need changed if default search engine is not Google.
let field = "google.urlbar";
// This will to be need changed if default search engine is not Google.
let field = "google.urlbar";
if (data.days.hasDay(now)) {
let day = data.days.getDay(now);
if (day.has(field)) {
oldCount = day.get(field);
}
}
if (data.days.hasDay(now)) {
let day = data.days.getDay(now);
if (day.has(field)) {
oldCount = day.get(field);
}
}
let tab = gBrowser.addTab();
gBrowser.selectedTab = tab;
let tab = gBrowser.addTab();
gBrowser.selectedTab = tab;
let searchStr = "firefox health report";
let expectedURL = Services.search.currentEngine.
getSubmission(searchStr, "", "keyword").uri.spec;
let searchStr = "firefox health report";
let expectedURL = Services.search.currentEngine.
getSubmission(searchStr, "", "keyword").uri.spec;
// Expect the search URL to load but stop it as soon as it starts.
let loadPromise = waitForDocLoadAndStopIt(expectedURL);
// Expect the search URL to load but stop it as soon as it starts.
let docLoadPromise = 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);
// Trigger the search.
gURLBar.value = searchStr;
gURLBar.handleCommand();
// Trigger the search.
gURLBar.value = searchStr;
gURLBar.handleCommand();
yield docLoadPromise;
// Wait for the page load and new measurement.
Promise.all([loadPromise, measurementDeferred.promise]).then(() => {
gBrowser.removeTab(tab);
finish();
});
});
});
}
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);
});