Bug 1089695 - Async sanitize.js (newtab tests);r=ttaubert

--HG--
extra : transplant_source : %23%03%86%AB%C8lk-3%7C%20%40%90E%EFl%09%FE%E85
This commit is contained in:
David Rajchenbach-Teller 2015-07-27 19:19:26 +02:00
Родитель 34c2816fc1
Коммит 798295da7d
2 изменённых файлов: 80 добавлений и 31 удалений

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

@ -11,20 +11,27 @@ Cc["@mozilla.org/moz/jssubscript-loader;1"]
var {Sanitizer} = tmp;
function runTests() {
sanitizeHistory();
yield addFakeVisits();
yield addNewTabPageTab();
add_task(function*() {
yield promiseSanitizeHistory();
yield promiseAddFakeVisits();
yield addNewTabPageTabPromise();
is(getCell(0).site.url, URL, "first site is our fake site");
whenPagesUpdated();
yield sanitizeHistory();
whenPagesUpdated(() => {});
yield promiseSanitizeHistory();
ok(!getCell(0).site, "the fake site is gone");
}
// Now wait until the grid is updated
while (true) {
if (!getCell(0).site) {
break;
}
info("the fake site is still present");
yield new Promise(resolve => setTimeout(resolve, 1000));
}
ok(!getCell(0).site, "fake site is gone");
});
function addFakeVisits() {
function promiseAddFakeVisits() {
let visits = [];
for (let i = 59; i > 0; i--) {
visits.push({
@ -37,19 +44,21 @@ function addFakeVisits() {
title: "fake site",
visits: visits
};
PlacesUtils.asyncHistory.updatePlaces(place, {
handleError: function () ok(false, "couldn't add visit"),
handleResult: function () {},
handleCompletion: function () {
NewTabUtils.links.populateCache(function () {
NewTabUtils.allPages.update();
TestRunner.next();
}, true);
}
return new Promise((resolve, reject) => {
PlacesUtils.asyncHistory.updatePlaces(place, {
handleError: function () reject(new Error("Couldn't add visit")),
handleResult: function () {},
handleCompletion: function () {
NewTabUtils.links.populateCache(function () {
NewTabUtils.allPages.update();
resolve();
}, true);
}
});
});
}
function sanitizeHistory() {
function promiseSanitizeHistory() {
let s = new Sanitizer();
s.prefDomain = "privacy.cpd.";
@ -64,5 +73,5 @@ function sanitizeHistory() {
prefs.setBoolPref("sessions", false);
prefs.setBoolPref("siteSettings", false);
s.sanitize();
return s.sanitize();
}

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

@ -116,18 +116,58 @@ function watchLinksChangeOnce() {
/**
* Provide the default test function to start our test runner.
*
* We need different code paths for tests that are still wired for
* `TestRunner` and tests that have been ported to `add_task` as
* we cannot have both in the same file.
*/
function test() {
waitForExplicitFinish();
// start TestRunner.run() after directory links is downloaded and written to disk
watchLinksChangeOnce().then(() => {
// Wait for hidden page to update with the desired links
whenPagesUpdated(() => TestRunner.run(), true);
});
function isTestPortedToAddTask() {
return gTestPath.endsWith("browser_newtab_bug722273.js");
}
if (!isTestPortedToAddTask()) {
this.test = function() {
waitForExplicitFinish();
// start TestRunner.run() after directory links is downloaded and written to disk
watchLinksChangeOnce().then(() => {
// Wait for hidden page to update with the desired links
whenPagesUpdated(() => TestRunner.run(), true);
});
// Save the original directory source (which is set globally for tests)
gOrigDirectorySource = Services.prefs.getCharPref(PREF_NEWTAB_DIRECTORYSOURCE);
Services.prefs.setCharPref(PREF_NEWTAB_DIRECTORYSOURCE, gDirectorySource);
// Save the original directory source (which is set globally for tests)
gOrigDirectorySource = Services.prefs.getCharPref(PREF_NEWTAB_DIRECTORYSOURCE);
Services.prefs.setCharPref(PREF_NEWTAB_DIRECTORYSOURCE, gDirectorySource);
}
} else {
add_task(function* setup() {
registerCleanupFunction(function() {
return new Promise(resolve => {
function cleanupAndFinish() {
PlacesTestUtils.clearHistory().then(() => {
whenPagesUpdated(resolve);
NewTabUtils.restore();
});
}
let callbacks = NewTabUtils.links._populateCallbacks;
let numCallbacks = callbacks.length;
if (numCallbacks)
callbacks.splice(0, numCallbacks, cleanupAndFinish);
else
cleanupAndFinish();
});
});
let promiseReady = Task.spawn(function*() {
yield watchLinksChangeOnce();
yield new Promise(resolve => whenPagesUpdated(resolve, true));
});
// Save the original directory source (which is set globally for tests)
gOrigDirectorySource = Services.prefs.getCharPref(PREF_NEWTAB_DIRECTORYSOURCE);
Services.prefs.setCharPref(PREF_NEWTAB_DIRECTORYSOURCE, gDirectorySource);
yield promiseReady;
});
}
/**