Bug 1249263 - fix test_removeByFilter.js to wait for the assertInDB and assertNotInDB promises, r=mak. a=tomcat
authorFlorian Quèze <florian@queze.net>
Fri, 12 May 2017 14:56:51 +0200
changeset 358077 1178b701781d
parent 358076 78bda617988b
child 358078 f0c6a71517c2
push id31809
push userflorian@queze.net
push dateFri, 12 May 2017 12:59:58 +0000
treeherdermozilla-central@1178b701781d [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersmak, tomcat
bugs1249263
milestone55.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1249263 - fix test_removeByFilter.js to wait for the assertInDB and assertNotInDB promises, r=mak. a=tomcat
toolkit/components/places/tests/history/test_removeByFilter.js
--- a/toolkit/components/places/tests/history/test_removeByFilter.js
+++ b/toolkit/components/places/tests/history/test_removeByFilter.js
@@ -33,17 +33,17 @@ add_task(async function test_removeByFil
     await PlacesTestUtils.addVisits(visits);
     if (bookmarkedUri !== null && visits.map(v => v.uri).includes(bookmarkedUri)) {
       await PlacesUtils.bookmarks.insert({
         parentGuid: PlacesUtils.bookmarks.unfiledGuid,
         url: bookmarkedUri,
         title: "test bookmark"
       });
     }
-    checkBeforeRemove();
+    await checkBeforeRemove();
 
     // Take care of any observers (due to bookmarks)
     let { observer, promiseObserved } = getObserverPromise(bookmarkedUri);
     if (observer) {
       PlacesUtils.history.addObserver(observer, false);
     }
     // Perfom delete operation on database
     let removed = false;
@@ -53,22 +53,22 @@ add_task(async function test_removeByFil
       removed = await PlacesUtils.history.removeByFilter(filter, pageInfo => {
         Assert.ok(PlacesUtils.validatePageInfo(pageInfo, false), "pageInfo should follow a basic format");
         Assert.ok(netCallbacksRequired > 0, "Callback called as many times as required");
         netCallbacksRequired--;
       });
     } else {
       removed = await PlacesUtils.history.removeByFilter(filter);
     }
-    checkAfterRemove();
+    await checkAfterRemove();
     await promiseObserved;
     if (observer) {
       PlacesUtils.history.removeObserver(observer);
       // Remove the added bookmarks as they interfere with following tests
-      PlacesUtils.bookmarks.eraseEverything();
+      await PlacesUtils.bookmarks.eraseEverything();
     }
       Assert.ok((await PlacesTestUtils.isPageInDB(witnessURI)), "Witness URI is still in database");
     return removed;
   };
 
   const remoteUriList = [ "http://mozilla.org/test_browserhistory/test_removeByFilter/" + Math.random(),
                           "http://subdomain1.mozilla.org/test_browserhistory/test_removeByFilter/" + Math.random(),
                           "http://subdomain2.mozilla.org/test_browserhistory/test_removeByFilter/" + Math.random()
@@ -141,76 +141,76 @@ add_task(async function test_removeByFil
       if (bookmarkUse) {
         bookmarkedUri = (arr) => arr[0];
         checkableArray = (arr) => arr.slice(1);
         checkClosure = function(aUri) { };
       }
       // Case A 1: Dates
       await removeByFilterTester(sameHostVisits,
                                  { beginDate: new Date(2004, 1, 1), endDate: new Date(2006, 1, 1) },
-                                 () => assertInDB(remoteUriList[0]),
-                                 () => checkClosure(remoteUriList[0]),
+                                 async () => await assertInDB(remoteUriList[0]),
+                                 async () => await checkClosure(remoteUriList[0]),
                                  callbackUse, bookmarkedUri(remoteUriList));
       // Case A 2: Single Sub-host
       await removeByFilterTester(sameHostVisits, { host: "mozilla.org" },
-                                 () => assertInDB(remoteUriList[0]),
-                                 () => checkClosure(remoteUriList[0]),
+                                 async () => await assertInDB(remoteUriList[0]),
+                                 async () => await checkClosure(remoteUriList[0]),
                                  callbackUse, bookmarkedUri(remoteUriList));
       // Case A 3: Multiple subhost
       await removeByFilterTester(randomHostVisits, { host: "*.mozilla.org" },
-                                 () => remoteUriList.forEach(assertInDB),
-                                 () => checkableArray(remoteUriList).forEach(checkClosure),
+                                 async () => { for (let uri of remoteUriList) await assertInDB(uri); },
+                                 async () => { for (let uri of checkableArray(remoteUriList)) await checkClosure(uri) },
                                  callbackUse, bookmarkedUri(remoteUriList));
     }
 
     // Case A 4: Localhost
     await removeByFilterTester(localhostVisits, { host: "localhost" },
-                               () => localhostUriList.forEach(assertInDB),
-                               () => localhostUriList.forEach(assertNotInDB),
+                               async () => { for (let uri of localhostUriList) await assertInDB(uri) },
+                               async () => { for (let uri of localhostUriList) await assertNotInDB(uri) },
                                callbackUse);
     // Case A 5: Local Files
     await removeByFilterTester(fileVisits, { host: "" },
-                               () => fileUriList.forEach(assertInDB),
-                               () => fileUriList.forEach(assertNotInDB),
+                               async () => { for (let uri of fileUriList) await assertInDB(uri) },
+                               async () => { for (let uri of fileUriList) await assertNotInDB(uri) },
                                callbackUse);
 
     // Case B: Tests which do not remove anything (inverses)
     // Case B 1: Date
     await removeByFilterTester(sameHostVisits,
                                { beginDate: new Date(2001, 1, 1), endDate: new Date(2002, 1, 1) },
-                               () => assertInDB(remoteUriList[0]),
-                               () => assertInDB(remoteUriList[0]),
+                               async () => await assertInDB(remoteUriList[0]),
+                               async () => await assertInDB(remoteUriList[0]),
                                callbackUse);
     // Case B 2 : Single subhost
     await removeByFilterTester(sameHostVisits, { host: "notthere.org" },
-                               () => assertInDB(remoteUriList[0]),
-                               () => assertInDB(remoteUriList[0]),
+                               async () => await assertInDB(remoteUriList[0]),
+                               async () => await assertInDB(remoteUriList[0]),
                                callbackUse);
     // Case B 3 : Multiple subhosts
     await removeByFilterTester(randomHostVisits, { host: "*.notthere.org" },
-                               () => remoteUriList.forEach(assertInDB),
-                               () => remoteUriList.forEach(assertInDB),
+                               async () => { for (let uri of remoteUriList) await assertInDB(uri) },
+                               async () => { for (let uri of remoteUriList) await assertInDB(uri) },
                                callbackUse);
 
     // Case C: Combination Cases
     // Case C 1: single subhost
     await removeByFilterTester(sameHostVisits,
                                { host: "mozilla.org",
                                  beginDate: new Date(2004, 1, 1),
                                  endDate: new Date(2006, 1, 1) },
-                               () => assertInDB(remoteUriList[0]),
-                               () => assertNotInDB(remoteUriList[0]),
+                               async () => await assertInDB(remoteUriList[0]),
+                               async () => await assertNotInDB(remoteUriList[0]),
                                callbackUse);
     // Case C 2: multiple subhost
     await removeByFilterTester(randomHostVisits,
                                { host: "*.mozilla.org",
                                  beginDate: new Date(2005, 1, 1),
                                  endDate: new Date(2017, 1, 1) },
-                               () => remoteUriList.forEach(assertInDB),
-                               () => remoteUriList.forEach(assertNotInDB),
+                               async () => { for (let uri of remoteUriList) await assertInDB(uri) },
+                               async () => { for (let uri of remoteUriList) await assertNotInDB(uri) },
                                callbackUse);
   }
 });
 
 
 // Test various error cases
 add_task(async function test_error_cases() {
   Assert.throws(