summaryrefslogtreecommitdiffstats
path: root/mobile/android/tests/browser/robocop/testReadingListCache.js
diff options
context:
space:
mode:
authorMatt A. Tobin <mattatobin@localhost.localdomain>2018-02-02 04:16:08 -0500
committerMatt A. Tobin <mattatobin@localhost.localdomain>2018-02-02 04:16:08 -0500
commit5f8de423f190bbb79a62f804151bc24824fa32d8 (patch)
tree10027f336435511475e392454359edea8e25895d /mobile/android/tests/browser/robocop/testReadingListCache.js
parent49ee0794b5d912db1f95dce6eb52d781dc210db5 (diff)
downloadUXP-5f8de423f190bbb79a62f804151bc24824fa32d8.tar
UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.tar.gz
UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.tar.lz
UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.tar.xz
UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.zip
Add m-esr52 at 52.6.0
Diffstat (limited to 'mobile/android/tests/browser/robocop/testReadingListCache.js')
-rw-r--r--mobile/android/tests/browser/robocop/testReadingListCache.js126
1 files changed, 126 insertions, 0 deletions
diff --git a/mobile/android/tests/browser/robocop/testReadingListCache.js b/mobile/android/tests/browser/robocop/testReadingListCache.js
new file mode 100644
index 000000000..d438dfb1e
--- /dev/null
+++ b/mobile/android/tests/browser/robocop/testReadingListCache.js
@@ -0,0 +1,126 @@
+// -*- indent-tabs-mode: nil; js-indent-level: 2 -*-
+/* This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
+
+/*globals ReaderMode */
+
+var { utils: Cu } = Components;
+
+Cu.import("resource://gre/modules/ReaderMode.jsm");
+Cu.import("resource://gre/modules/Services.jsm");
+Cu.import("resource://gre/modules/Task.jsm");
+
+var Reader = Services.wm.getMostRecentWindow("navigator:browser").Reader;
+
+const URL_PREFIX = "http://mochi.test:8888/tests/robocop/reader_mode_pages/";
+
+var TEST_PAGES = [
+ {
+ url: URL_PREFIX + "basic_article.html",
+ expected: {
+ title: "Article title",
+ byline: "by Jane Doe",
+ excerpt: "This is the article description.",
+ }
+ },
+ {
+ url: URL_PREFIX + "not_an_article.html",
+ expected: null
+ },
+ {
+ url: URL_PREFIX + "developer.mozilla.org/en/XULRunner/Build_Instructions.html",
+ expected: {
+ title: "Building XULRunner",
+ byline: null,
+ excerpt: "XULRunner is built using basically the same process as Firefox or other applications. Please read and follow the general Build Documentation for instructions on how to get sources and set up build prerequisites.",
+ }
+ },
+];
+
+add_task(function* test_article_not_found() {
+ let article = yield ReaderMode.getArticleFromCache(TEST_PAGES[0].url);
+ do_check_eq(article, null);
+});
+
+add_task(function* test_store_article() {
+ // Create an article object to store in the cache.
+ yield ReaderMode.storeArticleInCache({
+ 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,
+ });
+
+ let article = yield ReaderMode.getArticleFromCache(TEST_PAGES[0].url);
+ checkArticle(article, TEST_PAGES[0]);
+});
+
+add_task(function* test_remove_article() {
+ yield ReaderMode.removeArticleFromCache(TEST_PAGES[0].url);
+ let article = yield ReaderMode.getArticleFromCache(TEST_PAGES[0].url);
+ do_check_eq(article, null);
+});
+
+add_task(function* test_parse_articles() {
+ for (let testcase of TEST_PAGES) {
+ let article = yield ReaderMode.downloadAndParseDocument(testcase.url);
+ checkArticle(article, testcase);
+ }
+});
+
+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,
+ });
+ 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 article = yield ReaderMode.getArticleFromCache(TEST_PAGES[0].url);
+ checkArticle(article, TEST_PAGES[0]);
+});
+
+function checkArticle(article, testcase) {
+ if (testcase.expected == null) {
+ do_check_eq(article, null);
+ return;
+ }
+
+ do_check_neq(article, null);
+ do_check_eq(!!article.content, true); // A bit of a hack to avoid spamming the test log.
+ do_check_eq(article.url, testcase.url);
+ do_check_eq(article.title, testcase.expected.title);
+ do_check_eq(article.byline, testcase.expected.byline);
+ do_check_eq(article.excerpt, testcase.expected.excerpt);
+}
+
+run_next_test();