Bug 1394101 - Part 1 Port Bug 1374282 [Switch to async/await from Task.jsm/yield] to SeaMonkey. r=IanN
See also Bug 1353542 [Switch to async/await from Task.jsm/yield (edit)].
This commit is contained in:
Родитель
57caf966f8
Коммит
746d29d3f8
|
@ -12,8 +12,6 @@ XPCOMUtils.defineLazyModuleGetter(this, "TelemetryStopwatch",
|
|||
"resource://gre/modules/TelemetryStopwatch.jsm");
|
||||
XPCOMUtils.defineLazyModuleGetter(this, "NetUtil",
|
||||
"resource://gre/modules/NetUtil.jsm");
|
||||
XPCOMUtils.defineLazyModuleGetter(this, "Task",
|
||||
"resource://gre/modules/Task.jsm");
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
//// Constants
|
||||
|
|
|
@ -198,7 +198,7 @@ function addPageBook(aURI, aTitle, aBook, aTags, aKey, aTransitionType, aNoVisit
|
|||
gNextTestSetupTasks.push([task_addPageBook, arguments]);
|
||||
}
|
||||
|
||||
function* task_addPageBook(aURI, aTitle, aBook, aTags, aKey, aTransitionType, aNoVisit)
|
||||
async function task_addPageBook(aURI, aTitle, aBook, aTags, aKey, aTransitionType, aNoVisit)
|
||||
{
|
||||
// Add a page entry for the current uri
|
||||
gPages[aURI] = [aURI, aBook != undefined ? aBook : aTitle, aTags];
|
||||
|
@ -212,7 +212,7 @@ function* task_addPageBook(aURI, aTitle, aBook, aTags, aKey, aTransitionType, aN
|
|||
|
||||
// Add the page and a visit if we need to
|
||||
if (!aNoVisit) {
|
||||
yield PlacesTestUtils.addVisits({
|
||||
await PlacesTestUtils.addVisits({
|
||||
uri: uri,
|
||||
transition: aTransitionType || TRANSITION_LINK,
|
||||
visitDate: gDate,
|
||||
|
@ -230,7 +230,7 @@ function* task_addPageBook(aURI, aTitle, aBook, aTags, aKey, aTransitionType, aN
|
|||
|
||||
// Add a keyword to the bookmark if we need to
|
||||
if (aKey != undefined)
|
||||
yield PlacesUtils.keywords.insert({url: uri.spec, keyword: aKey});
|
||||
await PlacesUtils.keywords.insert({url: uri.spec, keyword: aKey});
|
||||
|
||||
// Add tags if we need to
|
||||
if (aTags != undefined && aTags.length > 0) {
|
||||
|
@ -266,10 +266,10 @@ function run_test() {
|
|||
if (func)
|
||||
func();
|
||||
|
||||
Task.spawn(function* () {
|
||||
(async function() {
|
||||
// Iterate over all tasks and execute them
|
||||
for (let [fn, args] of gNextTestSetupTasks) {
|
||||
yield fn.apply(this, args);
|
||||
await fn.apply(this, args);
|
||||
}
|
||||
|
||||
// Clean up to allow tests to register more functions.
|
||||
|
@ -278,9 +278,9 @@ function run_test() {
|
|||
// At this point frecency could still be updating due to latest pages
|
||||
// updates. This is not a problem in real life, but autocomplete tests
|
||||
// should return reliable resultsets, thus we have to wait.
|
||||
yield PlacesTestUtils.promiseAsyncUpdates();
|
||||
await PlacesTestUtils.promiseAsyncUpdates();
|
||||
|
||||
}).then(() => ensure_results(search, expected),
|
||||
})().then(() => ensure_results(search, expected),
|
||||
do_report_unexpected_exception);
|
||||
}
|
||||
|
||||
|
@ -302,10 +302,10 @@ function markTyped(aURIs, aTitle)
|
|||
gNextTestSetupTasks.push([task_markTyped, arguments]);
|
||||
}
|
||||
|
||||
function* task_markTyped(aURIs, aTitle)
|
||||
async function task_markTyped(aURIs, aTitle)
|
||||
{
|
||||
for (let uri of aURIs) {
|
||||
yield PlacesTestUtils.addVisits({
|
||||
await PlacesTestUtils.addVisits({
|
||||
uri: toURI(kURIs[uri]),
|
||||
transition: TRANSITION_TYPED,
|
||||
title: kTitles[aTitle]
|
||||
|
|
|
@ -20,7 +20,7 @@ function run_test()
|
|||
run_next_test();
|
||||
}
|
||||
|
||||
add_task(function* test_autocomplete_on_value_removed()
|
||||
add_task(async function test_autocomplete_on_value_removed()
|
||||
{
|
||||
// QI to nsIAutoCompleteSimpleResultListener
|
||||
var listener = Cc["@mozilla.org/autocomplete/search;1?name=history"].
|
||||
|
@ -28,7 +28,7 @@ add_task(function* test_autocomplete_on_value_removed()
|
|||
|
||||
// add history visit
|
||||
var testUri = uri("http://foo.mozilla.com/");
|
||||
yield PlacesTestUtils.addVisits({
|
||||
await PlacesTestUtils.addVisits({
|
||||
uri: testUri,
|
||||
referrer: uri("http://mozilla.com/")
|
||||
});
|
||||
|
|
|
@ -32,7 +32,7 @@ function setSearch(aSearch) {
|
|||
prefs.setBoolPref("browser.urlbar.autocomplete.enabled", !!aSearch);
|
||||
}
|
||||
|
||||
add_task(function* test_sync_enabled() {
|
||||
add_task(async function test_sync_enabled() {
|
||||
// Initialize autocomplete component.
|
||||
Cc["@mozilla.org/autocomplete/search;1?name=history"]
|
||||
.getService(Ci.mozIPlacesAutoComplete);
|
||||
|
|
|
@ -33,8 +33,6 @@ XPCOMUtils.defineLazyModuleGetter(this, "Promise",
|
|||
"resource://gre/modules/Promise.jsm");
|
||||
XPCOMUtils.defineLazyModuleGetter(this, "Services",
|
||||
"resource://gre/modules/Services.jsm");
|
||||
XPCOMUtils.defineLazyModuleGetter(this, "Task",
|
||||
"resource://gre/modules/Task.jsm");
|
||||
XPCOMUtils.defineLazyModuleGetter(this, "BookmarkJSONUtils",
|
||||
"resource://gre/modules/BookmarkJSONUtils.jsm");
|
||||
XPCOMUtils.defineLazyModuleGetter(this, "BookmarkHTMLUtils",
|
||||
|
@ -858,11 +856,11 @@ function checkBookmarkObject(info) {
|
|||
/**
|
||||
* Reads foreign_count value for a given url.
|
||||
*/
|
||||
function* foreign_count(url) {
|
||||
async function foreign_count(url) {
|
||||
if (url instanceof Ci.nsIURI)
|
||||
url = url.spec;
|
||||
let db = yield PlacesUtils.promiseDBConnection();
|
||||
let rows = yield db.executeCached(
|
||||
let db = await PlacesUtils.promiseDBConnection();
|
||||
let rows = await db.executeCached(
|
||||
`SELECT foreign_count FROM moz_places
|
||||
WHERE url_hash = hash(:url) AND url = :url
|
||||
`, { url });
|
||||
|
|
|
@ -76,7 +76,7 @@ function run_test() {
|
|||
run_next_test();
|
||||
}
|
||||
|
||||
add_task(function test_execute() {
|
||||
add_task(async function test_execute() {
|
||||
do_test_pending();
|
||||
|
||||
print("Initialize suiteglue before Places");
|
||||
|
@ -101,7 +101,7 @@ add_task(function test_execute() {
|
|||
|
||||
print("Add visits.");
|
||||
for (let aUrl of URIS) {
|
||||
yield promiseAddVisits({uri: uri(aUrl), visitDate: timeInMicroseconds++,
|
||||
await promiseAddVisits({uri: uri(aUrl), visitDate: timeInMicroseconds++,
|
||||
transition: PlacesUtils.history.TRANSITION_TYPED})
|
||||
}
|
||||
print("Add cache.");
|
||||
|
|
|
@ -7,8 +7,6 @@ Components.utils.import("resource://gre/modules/Services.jsm");
|
|||
|
||||
XPCOMUtils.defineLazyModuleGetter(this, "PlacesUtils",
|
||||
"resource://gre/modules/PlacesUtils.jsm");
|
||||
XPCOMUtils.defineLazyModuleGetter(this, "Task",
|
||||
"resource://gre/modules/Task.jsm");
|
||||
const Ci = Components.interfaces;
|
||||
const Cc = Components.classes;
|
||||
|
||||
|
@ -121,14 +119,14 @@ var gEngineManagerDialog = {
|
|||
tree.startEditing(index, column);
|
||||
},
|
||||
|
||||
editKeyword: Task.async(function* (aEngine, aNewKeyword) {
|
||||
async editKeyword(aEngine, aNewKeyword) {
|
||||
let keyword = aNewKeyword.trim();
|
||||
if (keyword) {
|
||||
let eduplicate = false;
|
||||
let dupName = "";
|
||||
|
||||
// Check for duplicates in Places keywords.
|
||||
let bduplicate = !!(yield PlacesUtils.keywords.fetch(keyword));
|
||||
let bduplicate = !!(await PlacesUtils.keywords.fetch(keyword));
|
||||
|
||||
// Check for duplicates in changes we haven't committed yet
|
||||
let engines = gEngineView._engineStore.engines;
|
||||
|
@ -156,7 +154,7 @@ var gEngineManagerDialog = {
|
|||
gEngineView._engineStore.changeEngine(aEngine, "alias", keyword);
|
||||
gEngineView.invalidate();
|
||||
return true;
|
||||
}),
|
||||
},
|
||||
|
||||
onSelect: function engineManager_onSelect() {
|
||||
// Buttons only work if an engine is selected and it's not the last engine,
|
||||
|
|
|
@ -33,8 +33,6 @@ XPCOMUtils.defineLazyModuleGetter(this, "BookmarkHTMLUtils",
|
|||
XPCOMUtils.defineLazyModuleGetter(this, "BookmarkJSONUtils",
|
||||
"resource://gre/modules/BookmarkJSONUtils.jsm");
|
||||
|
||||
XPCOMUtils.defineLazyModuleGetter(this, "Task",
|
||||
"resource://gre/modules/Task.jsm");
|
||||
|
||||
XPCOMUtils.defineLazyGetter(this, "DebuggerServer", () => {
|
||||
var tmp = {};
|
||||
|
@ -918,11 +916,11 @@ SuiteGlue.prototype = {
|
|||
* Set to true by safe-mode dialog to indicate we must restore default
|
||||
* bookmarks.
|
||||
*/
|
||||
_initPlaces: Task.async(function(aInitialMigrationPerformed) {
|
||||
async _initPlaces(aInitialMigrationPerformed) {
|
||||
// We must instantiate the history service since it will tell us if we
|
||||
// need to import or restore bookmarks due to first-run, corruption or
|
||||
// forced migration (due to a major schema change).
|
||||
var bookmarksBackupFile = yield PlacesBackups.getMostRecentBackup();
|
||||
var bookmarksBackupFile = await PlacesBackups.getMostRecentBackup();
|
||||
|
||||
// If the database is corrupt or has been newly created we should
|
||||
// import bookmarks. Same if we don't have any JSON backups, which
|
||||
|
@ -961,7 +959,7 @@ SuiteGlue.prototype = {
|
|||
// Get latest JSON backup.
|
||||
if (bookmarksBackupFile) {
|
||||
// Restore from JSON backup.
|
||||
yield BookmarkJSONUtils.importFromFile(bookmarksBackupFile, true);
|
||||
await BookmarkJSONUtils.importFromFile(bookmarksBackupFile, true);
|
||||
importBookmarks = false;
|
||||
}
|
||||
else if (dbStatus == PlacesUtils.history.DATABASE_STATUS_OK) {
|
||||
|
@ -1052,7 +1050,7 @@ SuiteGlue.prototype = {
|
|||
this._idleService.addIdleObserver(this, BOOKMARKS_BACKUP_IDLE_TIME);
|
||||
this._isIdleObserver = true;
|
||||
}
|
||||
}),
|
||||
},
|
||||
|
||||
/**
|
||||
* Places shut-down tasks
|
||||
|
|
|
@ -32,7 +32,7 @@ function test() {
|
|||
* their state at least once.
|
||||
*/
|
||||
|
||||
function runTests() {
|
||||
async function runTests() {
|
||||
let win;
|
||||
|
||||
// Wait until the new window has been opened.
|
||||
|
@ -44,7 +44,7 @@ function runTests() {
|
|||
|
||||
// Set the new browser state that will
|
||||
// restore a window with two slowly loading tabs.
|
||||
yield SessionStore.setBrowserState(JSON.stringify(TEST_STATE));
|
||||
await SessionStore.setBrowserState(JSON.stringify(TEST_STATE));
|
||||
|
||||
// The window has now been opened. Check the state that is returned,
|
||||
// this should come from the cache while the window isn't restored, yet.
|
||||
|
@ -53,7 +53,7 @@ function runTests() {
|
|||
|
||||
// The history has now been restored and the tabs are loading. The data must
|
||||
// now come from the window, if it's correctly been marked as dirty before.
|
||||
yield whenDelayedStartupFinished(win, next);
|
||||
await whenDelayedStartupFinished(win, next);
|
||||
info("the delayed startup has finished");
|
||||
checkWindows();
|
||||
}
|
||||
|
|
|
@ -6,18 +6,18 @@ XPCOMUtils.defineLazyModuleGetter(this, "FormHistory",
|
|||
var sanTests = {
|
||||
cache: {
|
||||
desc: "Cache",
|
||||
setup: function() {
|
||||
async setup() {
|
||||
var entry = null;
|
||||
this.cs = Services.cache.createSession("SanitizerTest", Components.interfaces.nsICache.STORE_ANYWHERE, true);
|
||||
entry = yield promiseOpenCacheEntry("http://santizer.test", Components.interfaces.nsICache.ACCESS_READ_WRITE, this.cs);
|
||||
entry = await promiseOpenCacheEntry("http://santizer.test", Components.interfaces.nsICache.ACCESS_READ_WRITE, this.cs);
|
||||
entry.setMetaDataElement("Foo", "Bar");
|
||||
entry.markValid();
|
||||
entry.close();
|
||||
},
|
||||
|
||||
check: function(aShouldBeCleared) {
|
||||
async check(aShouldBeCleared) {
|
||||
let entry = null;
|
||||
entry = yield promiseOpenCacheEntry("http://santizer.test", Components.interfaces.nsICache.ACCESS_READ, this.cs);
|
||||
entry = await promiseOpenCacheEntry("http://santizer.test", Components.interfaces.nsICache.ACCESS_READ, this.cs);
|
||||
|
||||
if (entry) {
|
||||
entry.close();
|
||||
|
@ -29,19 +29,19 @@ var sanTests = {
|
|||
|
||||
offlineApps: {
|
||||
desc: "Offline app cache",
|
||||
setup: function() {
|
||||
async setup() {
|
||||
//XXX test offline DOMStorage
|
||||
var entry = null;
|
||||
this.cs = Services.cache.createSession("SanitizerTest", Components.interfaces.nsICache.STORE_OFFLINE, true);
|
||||
entry = yield promiseOpenCacheEntry("http://santizer.test", Components.interfaces.nsICache.ACCESS_READ_WRITE, this.cs);
|
||||
entry = await promiseOpenCacheEntry("http://santizer.test", Components.interfaces.nsICache.ACCESS_READ_WRITE, this.cs);
|
||||
entry.setMetaDataElement("Foo", "Bar");
|
||||
entry.markValid();
|
||||
entry.close();
|
||||
},
|
||||
|
||||
check: function(aShouldBeCleared) {
|
||||
async check(aShouldBeCleared) {
|
||||
var entry = null;
|
||||
entry = yield promiseOpenCacheEntry("http://santizer.test", Components.interfaces.nsICache.ACCESS_READ, this.cs);
|
||||
entry = await promiseOpenCacheEntry("http://santizer.test", Components.interfaces.nsICache.ACCESS_READ, this.cs);
|
||||
if (entry) {
|
||||
entry.close();
|
||||
}
|
||||
|
@ -72,11 +72,11 @@ var sanTests = {
|
|||
|
||||
history: {
|
||||
desc: "History",
|
||||
setup: function() {
|
||||
async setup() {
|
||||
var ios = Components.classes["@mozilla.org/network/io-service;1"]
|
||||
.getService(Components.interfaces.nsIIOService);
|
||||
var uri = ios.newURI("http://sanitizer.test/");
|
||||
yield promiseAddVisits({
|
||||
await promiseAddVisits({
|
||||
uri: uri,
|
||||
title: "Sanitizer!"
|
||||
});
|
||||
|
@ -164,7 +164,7 @@ var sanTests = {
|
|||
|
||||
formdata: {
|
||||
desc: "Form history",
|
||||
setup: function() {
|
||||
async setup() {
|
||||
// Adds a form entry to history.
|
||||
function promiseAddFormEntry(aName, aValue) {
|
||||
return new Promise((resolve, reject) =>
|
||||
|
@ -179,9 +179,9 @@ var sanTests = {
|
|||
})
|
||||
)
|
||||
}
|
||||
yield promiseAddFormEntry("Sanitizer", "Foo");
|
||||
await promiseAddFormEntry("Sanitizer", "Foo");
|
||||
},
|
||||
check: function(aShouldBeCleared) {
|
||||
async check(aShouldBeCleared) {
|
||||
// Check if a form name exists.
|
||||
function formNameExists(aName) {
|
||||
return new Promise((resolve, reject) => {
|
||||
|
@ -202,7 +202,7 @@ var sanTests = {
|
|||
}
|
||||
|
||||
// Checking for Sanitizer form history entry creation.
|
||||
let exists = yield formNameExists("Sanitizer");
|
||||
let exists = await formNameExists("Sanitizer");
|
||||
do_check_eq(exists, !aShouldBeCleared);
|
||||
}
|
||||
},
|
||||
|
@ -303,7 +303,7 @@ var sanTests = {
|
|||
}
|
||||
}
|
||||
|
||||
function fullSanitize() {
|
||||
async function fullSanitize() {
|
||||
do_print("Now doing a full sanitize run");
|
||||
var prefs = Services.prefs.getBranch("privacy.item.");
|
||||
|
||||
|
@ -311,7 +311,7 @@ function fullSanitize() {
|
|||
|
||||
for (var testName in sanTests) {
|
||||
var test = sanTests[testName];
|
||||
yield test.setup();
|
||||
await test.setup();
|
||||
prefs.setBoolPref(testName, true);
|
||||
}
|
||||
|
||||
|
@ -319,7 +319,7 @@ function fullSanitize() {
|
|||
|
||||
for (var testName in sanTests) {
|
||||
var test = sanTests[testName];
|
||||
yield test.check(true);
|
||||
await test.check(true);
|
||||
do_print(test.desc + " data cleared by full sanitize");
|
||||
try {
|
||||
prefs.clearUserPref(testName);
|
||||
|
@ -336,19 +336,19 @@ function run_test()
|
|||
run_next_test();
|
||||
}
|
||||
|
||||
add_task(function test_browser_sanitizer()
|
||||
add_task(async function test_browser_sanitizer()
|
||||
{
|
||||
for (var testName in sanTests) {
|
||||
let test = sanTests[testName];
|
||||
dump("\nExecuting test: " + testName + "\n" + "*** " + test.desc + "\n");
|
||||
yield test.setup();
|
||||
yield test.check(false);
|
||||
await test.setup();
|
||||
await test.check(false);
|
||||
|
||||
do_check_true(Sanitizer.items[testName].canClear);
|
||||
Sanitizer.items[testName].clear();
|
||||
do_print(test.desc + " data cleared");
|
||||
|
||||
yield test.check(true);
|
||||
await test.check(true);
|
||||
}
|
||||
});
|
||||
|
||||
|
|
Загрузка…
Ссылка в новой задаче