Bug 1288885: Migrate history mochitests to xpcshell. r?aswan draft
authorKris Maglione <maglione.k@gmail.com>
Fri, 22 Jul 2016 18:57:38 -0700
changeset 392211 aabec59ec6ccbbd37b7ba8b657ba684500676718
parent 392210 012fe7bea9f2a9fc3e78aa7542a99a4e9cf3f7d1
child 392212 9bf88cf0528549870e486f4a8455ce57168b62d1
push id23963
push usermaglione.k@gmail.com
push dateSun, 24 Jul 2016 23:16:27 +0000
reviewersaswan
bugs1288885
milestone50.0a1
Bug 1288885: Migrate history mochitests to xpcshell. r?aswan MozReview-Commit-ID: tzQdEJx6TN
browser/components/extensions/test/browser/browser.ini
browser/components/extensions/test/browser/browser_ext_history.js
browser/components/extensions/test/xpcshell/test_ext_history.js
browser/components/extensions/test/xpcshell/xpcshell.ini
--- a/browser/components/extensions/test/browser/browser.ini
+++ b/browser/components/extensions/test/browser/browser.ini
@@ -29,17 +29,16 @@ support-files =
 [browser_ext_contentscript_connect.js]
 [browser_ext_contextMenus.js]
 [browser_ext_contextMenus_checkboxes.js]
 [browser_ext_contextMenus_icons.js]
 [browser_ext_contextMenus_radioGroups.js]
 [browser_ext_contextMenus_uninstall.js]
 [browser_ext_currentWindow.js]
 [browser_ext_getViews.js]
-[browser_ext_history.js]
 [browser_ext_incognito_popup.js]
 [browser_ext_lastError.js]
 [browser_ext_optionsPage_privileges.js]
 [browser_ext_pageAction_context.js]
 [browser_ext_pageAction_popup.js]
 [browser_ext_pageAction_popup_resize.js]
 [browser_ext_pageAction_simple.js]
 [browser_ext_popup_api_injection.js]
rename from browser/components/extensions/test/browser/browser_ext_history.js
rename to browser/components/extensions/test/xpcshell/test_ext_history.js
--- a/browser/components/extensions/test/browser/browser_ext_history.js
+++ b/browser/components/extensions/test/xpcshell/test_ext_history.js
@@ -4,16 +4,19 @@
 
 XPCOMUtils.defineLazyModuleGetter(this, "PlacesTestUtils",
                                   "resource://testing-common/PlacesTestUtils.jsm");
 XPCOMUtils.defineLazyModuleGetter(this, "PlacesUtils",
                                   "resource://gre/modules/PlacesUtils.jsm");
 XPCOMUtils.defineLazyModuleGetter(this, "ExtensionUtils",
                                   "resource://gre/modules/ExtensionUtils.jsm");
 
+ExtensionManagement.registerScript("chrome://browser/content/ext-history.js");
+ExtensionManagement.registerSchema("chrome://browser/content/schemas/history.json");
+
 add_task(function* test_delete() {
   function background() {
     let historyClearedCount = 0;
     let removedUrls = [];
 
     browser.history.onVisitRemoved.addListener(data => {
       if (data.allHistory) {
         historyClearedCount++;
@@ -80,58 +83,58 @@ add_task(function* test_delete() {
       }
     } else {
       pushVisit(visit.visits);
     }
     visits.push(visit);
   }
 
   yield PlacesUtils.history.insertMany(visits);
-  is(yield PlacesTestUtils.visitsInDB(visits[0].url), 5, "5 visits for uri found in history database");
+  equal(yield PlacesTestUtils.visitsInDB(visits[0].url), 5, "5 visits for uri found in history database");
 
   let testUrl = visits[2].url;
   ok(yield PlacesTestUtils.isPageInDB(testUrl), "expected url found in history database");
 
   extension.sendMessage("delete-url", testUrl);
   yield extension.awaitMessage("url-deleted");
-  is(yield PlacesTestUtils.isPageInDB(testUrl), false, "expected url not found in history database");
+  equal(yield PlacesTestUtils.isPageInDB(testUrl), false, "expected url not found in history database");
 
   // delete 3 of the 5 visits for url 1
   let filter = {
     startTime: visits[0].visits[0].date,
     endTime: visits[0].visits[2].date,
   };
 
   extension.sendMessage("delete-range", filter);
   let removedUrls = yield extension.awaitMessage("range-deleted");
   ok(!removedUrls.includes(visits[0].url), `${visits[0].url} not received by onVisitRemoved`);
   ok(yield PlacesTestUtils.isPageInDB(visits[0].url), "expected uri found in history database");
-  is(yield PlacesTestUtils.visitsInDB(visits[0].url), 2, "2 visits for uri found in history database");
+  equal(yield PlacesTestUtils.visitsInDB(visits[0].url), 2, "2 visits for uri found in history database");
   ok(yield PlacesTestUtils.isPageInDB(visits[1].url), "expected uri found in history database");
-  is(yield PlacesTestUtils.visitsInDB(visits[1].url), 1, "1 visit for uri found in history database");
+  equal(yield PlacesTestUtils.visitsInDB(visits[1].url), 1, "1 visit for uri found in history database");
 
   // delete the rest of the visits for url 1, and the visit for url 2
   filter.startTime = visits[0].visits[0].date;
   filter.endTime = visits[1].visits[0].date;
 
   extension.sendMessage("delete-range", filter);
   yield extension.awaitMessage("range-deleted");
 
-  is(yield PlacesTestUtils.isPageInDB(visits[0].url), false, "expected uri not found in history database");
-  is(yield PlacesTestUtils.visitsInDB(visits[0].url), 0, "0 visits for uri found in history database");
-  is(yield PlacesTestUtils.isPageInDB(visits[1].url), false, "expected uri not found in history database");
-  is(yield PlacesTestUtils.visitsInDB(visits[1].url), 0, "0 visits for uri found in history database");
+  equal(yield PlacesTestUtils.isPageInDB(visits[0].url), false, "expected uri not found in history database");
+  equal(yield PlacesTestUtils.visitsInDB(visits[0].url), 0, "0 visits for uri found in history database");
+  equal(yield PlacesTestUtils.isPageInDB(visits[1].url), false, "expected uri not found in history database");
+  equal(yield PlacesTestUtils.visitsInDB(visits[1].url), 0, "0 visits for uri found in history database");
 
   ok(yield PlacesTestUtils.isPageInDB(visits[3].url), "expected uri found in history database");
 
   extension.sendMessage("delete-all");
   [historyClearedCount, removedUrls] = yield extension.awaitMessage("history-cleared");
-  is(PlacesUtils.history.hasHistoryEntries, false, "history is empty");
-  is(historyClearedCount, 2, "onVisitRemoved called for each clearing of history");
-  is(removedUrls.length, 3, "onVisitRemoved called the expected number of times");
+  equal(PlacesUtils.history.hasHistoryEntries, false, "history is empty");
+  equal(historyClearedCount, 2, "onVisitRemoved called for each clearing of history");
+  equal(removedUrls.length, 3, "onVisitRemoved called the expected number of times");
   for (let i = 1; i < 3; ++i) {
     let url = visits[i].url;
     ok(removedUrls.includes(url), `${url} received by onVisitRemoved`);
   }
   yield extension.unload();
 });
 
 add_task(function* test_search() {
@@ -210,45 +213,45 @@ add_task(function* test_search() {
   });
 
   function findResult(url, results) {
     return results.find(r => r.url === url);
   }
 
   function checkResult(results, url, expectedCount) {
     let result = findResult(url, results);
-    isnot(result, null, `history.search result was found for ${url}`);
-    is(result.visitCount, expectedCount, `history.search reports ${expectedCount} visit(s)`);
-    is(result.title, `test visit for ${url}`, "title for search result is correct");
+    notEqual(result, null, `history.search result was found for ${url}`);
+    equal(result.visitCount, expectedCount, `history.search reports ${expectedCount} visit(s)`);
+    equal(result.title, `test visit for ${url}`, "title for search result is correct");
   }
 
   yield extension.startup();
   yield extension.awaitMessage("ready");
   yield PlacesTestUtils.clearHistory();
 
   yield PlacesUtils.history.insertMany(PAGE_INFOS);
 
   extension.sendMessage("check-history");
 
   let results = yield extension.awaitMessage("empty-search");
-  is(results.length, 3, "history.search with empty text returned 3 results");
+  equal(results.length, 3, "history.search with empty text returned 3 results");
   checkResult(results, SINGLE_VISIT_URL, 1);
   checkResult(results, DOUBLE_VISIT_URL, 2);
   checkResult(results, MOZILLA_VISIT_URL, 1);
 
   results = yield extension.awaitMessage("text-search");
-  is(results.length, 1, "history.search with specific text returned 1 result");
+  equal(results.length, 1, "history.search with specific text returned 1 result");
   checkResult(results, MOZILLA_VISIT_URL, 1);
 
   results = yield extension.awaitMessage("max-results-search");
-  is(results.length, 1, "history.search with maxResults returned 1 result");
+  equal(results.length, 1, "history.search with maxResults returned 1 result");
   checkResult(results, DOUBLE_VISIT_URL, 2);
 
   results = yield extension.awaitMessage("date-range-search");
-  is(results.length, 2, "history.search with a date range returned 2 result");
+  equal(results.length, 2, "history.search with a date range returned 2 result");
   checkResult(results, DOUBLE_VISIT_URL, 2);
   checkResult(results, SINGLE_VISIT_URL, 1);
 
   yield extension.awaitFinish("search");
   yield extension.unload();
   yield PlacesTestUtils.clearHistory();
 });
 
@@ -297,19 +300,19 @@ add_task(function* test_add_url() {
     [{transition: "generated"}, "an invalid transition", "|generated| is not a supported transition for history"],
     [{visitTime: Date.now() + 1000000}, "a future date", "cannot be a future date"],
     [{url: "about.config"}, "an invalid url", "about.config is not a valid URL"],
   ];
 
   function* checkUrl(results) {
     ok(yield PlacesTestUtils.isPageInDB(results.details.url), `${results.details.url} found in history database`);
     ok(PlacesUtils.isValidGuid(results.result.id), "URL was added with a valid id");
-    is(results.result.title, results.details.title, "URL was added with the correct title");
+    equal(results.result.title, results.details.title, "URL was added with the correct title");
     if (results.details.visitTime) {
-      is(results.result.lastVisitTime,
+      equal(results.result.lastVisitTime,
          Number(ExtensionUtils.normalizeTime(results.details.visitTime)),
          "URL was added with the correct date");
     }
   }
 
   let extension = ExtensionTestUtils.loadExtension({
     manifest: {
       permissions: ["history"],
@@ -453,22 +456,22 @@ add_task(function* test_on_visited() {
 
   yield PlacesUtils.history.insertMany(PAGE_INFOS);
 
   let onVisitedData = yield extension.awaitMessage("on-visited-data");
 
   function checkOnVisitedData(index, expected) {
     let onVisited = onVisitedData[index];
     ok(PlacesUtils.isValidGuid(onVisited.id), "onVisited received a valid id");
-    is(onVisited.url, expected.url, "onVisited received the expected url");
+    equal(onVisited.url, expected.url, "onVisited received the expected url");
     // Title will be blank until bug 1287928 lands
     // https://bugzilla.mozilla.org/show_bug.cgi?id=1287928
-    is(onVisited.title, "", "onVisited received a blank title");
-    is(onVisited.lastVisitTime, expected.time, "onVisited received the expected time");
-    is(onVisited.visitCount, expected.visitCount, "onVisited received the expected visitCount");
+    equal(onVisited.title, "", "onVisited received a blank title");
+    equal(onVisited.lastVisitTime, expected.time, "onVisited received the expected time");
+    equal(onVisited.visitCount, expected.visitCount, "onVisited received the expected visitCount");
   }
 
   let expected = {
     url: PAGE_INFOS[0].url,
     title: PAGE_INFOS[0].title,
     time: PAGE_INFOS[0].visits[0].date.getTime(),
     visitCount: 1,
   };
--- a/browser/components/extensions/test/xpcshell/xpcshell.ini
+++ b/browser/components/extensions/test/xpcshell/xpcshell.ini
@@ -1,6 +1,7 @@
 [DEFAULT]
 head = head.js
 tail =
 firefox-appdir = browser
 
+[test_ext_history.js]
 [test_ext_manifest_commands.js]