mirror of
https://gitlab.winehq.org/wine/wine-gecko.git
synced 2024-09-13 09:24:08 -07:00
Bug 1093869 - Migrate indexedDB reader mode cache. r=bnicholson
This commit is contained in:
parent
ac8e9b2db3
commit
a08fd6e2d8
@ -73,6 +73,47 @@ add_task(function* test_parse_articles() {
|
||||
}
|
||||
});
|
||||
|
||||
add_task(function* test_migrate_cache() {
|
||||
// Store an article in the old indexedDB reader mode cache.
|
||||
let cacheDB = yield new Promise((resolve, reject) => {
|
||||
let win = Services.wm.getMostRecentWindow("navigator:browser");
|
||||
let request = win.indexedDB.open("about:reader", 1);
|
||||
request.onerror = event => reject(request.error);
|
||||
|
||||
// This will always happen because there is no pre-existing data store.
|
||||
request.onupgradeneeded = event => {
|
||||
let cacheDB = event.target.result;
|
||||
cacheDB.createObjectStore("articles", { keyPath: "url" });
|
||||
};
|
||||
|
||||
request.onsuccess = event => resolve(event.target.result);
|
||||
});
|
||||
|
||||
yield new Promise((resolve, reject) => {
|
||||
let transaction = cacheDB.transaction(["articles"], "readwrite");
|
||||
let store = transaction.objectStore("articles");
|
||||
|
||||
let request = store.add({
|
||||
url: TEST_PAGES[0].url,
|
||||
content: "Lorem ipsum",
|
||||
title: TEST_PAGES[0].expected.title,
|
||||
byline: TEST_PAGES[0].expected.byline,
|
||||
excerpt: TEST_PAGES[0].expected.excerpt,
|
||||
length: TEST_PAGES[0].expected.length
|
||||
});
|
||||
request.onerror = event => reject(request.error);
|
||||
request.onsuccess = event => resolve();
|
||||
});
|
||||
|
||||
// Migrate the cache.
|
||||
yield Reader.migrateCache();
|
||||
|
||||
// Check to make sure the article made it into the new cache.
|
||||
let uri = Services.io.newURI(TEST_PAGES[0].url, null, null);
|
||||
let article = yield Reader.getArticleFromCache(uri);
|
||||
checkArticle(article, TEST_PAGES[0]);
|
||||
});
|
||||
|
||||
function checkArticle(article, testcase) {
|
||||
if (testcase.expected == null) {
|
||||
do_check_eq(article, null);
|
||||
|
@ -419,5 +419,49 @@ let Reader = {
|
||||
return OS.File.makeDir(dir);
|
||||
}
|
||||
});
|
||||
}
|
||||
},
|
||||
|
||||
/**
|
||||
* Migrates old indexedDB reader mode cache to new JSON cache.
|
||||
*/
|
||||
migrateCache: Task.async(function* () {
|
||||
let cacheDB = yield new Promise((resolve, reject) => {
|
||||
let request = window.indexedDB.open("about:reader", 1);
|
||||
request.onsuccess = event => resolve(event.target.result);
|
||||
request.onerror = event => reject(request.error);
|
||||
|
||||
// If there is no DB to migrate, don't do anything.
|
||||
request.onupgradeneeded = event => resolve(null);
|
||||
});
|
||||
|
||||
if (!cacheDB) {
|
||||
return;
|
||||
}
|
||||
|
||||
let articles = yield new Promise((resolve, reject) => {
|
||||
let articles = [];
|
||||
|
||||
let transaction = cacheDB.transaction(cacheDB.objectStoreNames);
|
||||
let store = transaction.objectStore(cacheDB.objectStoreNames[0]);
|
||||
|
||||
let request = store.openCursor();
|
||||
request.onsuccess = event => {
|
||||
let cursor = event.target.result;
|
||||
if (!cursor) {
|
||||
resolve(articles);
|
||||
} else {
|
||||
articles.push(cursor.value);
|
||||
cursor.continue();
|
||||
}
|
||||
};
|
||||
request.onerror = event => reject(request.error);
|
||||
});
|
||||
|
||||
for (let article of articles) {
|
||||
yield this.storeArticleInCache(article);
|
||||
}
|
||||
|
||||
// Delete the database.
|
||||
window.indexedDB.deleteDatabase("about:reader");
|
||||
}),
|
||||
};
|
||||
|
@ -870,6 +870,10 @@ var BrowserApp = {
|
||||
Services.prefs.setBoolPref("searchActivity.default.migrated", true);
|
||||
SearchEngines.migrateSearchActivityDefaultPref();
|
||||
}
|
||||
|
||||
if (this._startupStatus === "upgrade") {
|
||||
Reader.migrateCache().catch(e => Cu.reportError("Error migrating Reader cache: " + e));
|
||||
}
|
||||
},
|
||||
|
||||
// This function returns false during periods where the browser displayed document is
|
||||
|
Loading…
Reference in New Issue
Block a user