mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-10-18 15:55:36 +00:00
Bug 1089695 - Async sanitize.js (newtab tests). r=ttaubert
--HG-- extra : transplant_source : %23%A2%EFh%FD%D8%94%A8%C91G%27%B3Z%0E%14%AF%F5%B6%EE
This commit is contained in:
parent
7c5b398ffd
commit
a1da39a67c
@ -11,20 +11,27 @@ Cc["@mozilla.org/moz/jssubscript-loader;1"]
|
||||
|
||||
let {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;
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
|
Loading…
Reference in New Issue
Block a user