Bug 1092607 - Intermittent failure in test_PlacesUtils_asyncGetBookmarkIds.js, r=ttaubert
authorMarco Bonardo <mbonardo@mozilla.com>
Mon, 03 Aug 2015 15:00:03 +0200
changeset 287576 15da891157bfcbe82c30919c70e5fb0027d14c87
parent 287575 47a42d3aa754a786fd472f089c17b71d1379f57e
child 287577 c2b099fa12eeffe0e5322e19f7f73e7d9e46be39
push id5067
push userraliiev@mozilla.com
push dateMon, 21 Sep 2015 14:04:52 +0000
treeherdermozilla-beta@14221ffe5b2f [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersttaubert
bugs1092607
milestone42.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 1092607 - Intermittent failure in test_PlacesUtils_asyncGetBookmarkIds.js, r=ttaubert
toolkit/components/places/tests/unit/test_PlacesUtils_asyncGetBookmarkIds.js
--- a/toolkit/components/places/tests/unit/test_PlacesUtils_asyncGetBookmarkIds.js
+++ b/toolkit/components/places/tests/unit/test_PlacesUtils_asyncGetBookmarkIds.js
@@ -1,86 +1,77 @@
-/* Any copyright is dedicated to the Public Domain.
-   http://creativecommons.org/publicdomain/zero/1.0/ */
-
 /**
  * This file tests PlacesUtils.asyncGetBookmarkIds method.
  */
 
 const TEST_URL = "http://www.example.com/";
 
-[
-
-  function test_no_bookmark() {
-    PlacesUtils.asyncGetBookmarkIds(TEST_URL, (aItemIds, aURI) => {
-      do_check_eq(aItemIds.length, 0);
-      do_check_eq(aURI, TEST_URL);
-      run_next_test();
-    });
-  },
-
-  function test_one_bookmark_nsIURI() {
-    let uri = NetUtil.newURI(TEST_URL);
-    let itemId = PlacesUtils.bookmarks.insertBookmark(
-      PlacesUtils.unfiledBookmarksFolderId, uri, "test",
-      PlacesUtils.bookmarks.DEFAULT_INDEX
-    );
-    PlacesUtils.asyncGetBookmarkIds(uri, (aItemIds, aURI) => {
-      do_check_eq(aItemIds.length, 1);
-      do_check_eq(aItemIds[0], itemId);
-      do_check_true(aURI.equals(uri));
-      PlacesUtils.bookmarks.removeItem(itemId);
-      run_next_test();
-    });
-  },
-
-  function test_one_bookmark_spec() {
-    let uri = NetUtil.newURI(TEST_URL);
-    let itemId = PlacesUtils.bookmarks.insertBookmark(
-      PlacesUtils.unfiledBookmarksFolderId, uri, "test",
-      PlacesUtils.bookmarks.DEFAULT_INDEX
-    );
-    PlacesUtils.asyncGetBookmarkIds(TEST_URL, (aItemIds, aURI) => {
-      do_check_eq(aItemIds.length, 1);
-      do_check_eq(aItemIds[0], itemId);
-      do_check_eq(aURI, TEST_URL);
-      PlacesUtils.bookmarks.removeItem(itemId);
-      run_next_test();
+let promiseAsyncGetBookmarkIds = Task.async(function* (url) {
+  yield PlacesTestUtils.promiseAsyncUpdates();
+  return new Promise(resolve => {
+    PlacesUtils.asyncGetBookmarkIds(url, (itemIds, uri) => {
+      Assert.equal(uri, url);
+      resolve({ itemIds, url });
     });
-  },
+  });
+});
+
+add_task(function* test_no_bookmark() {
+  let { itemIds, url } = yield promiseAsyncGetBookmarkIds(TEST_URL);
+  Assert.equal(itemIds.length, 0);
+  Assert.equal(url, TEST_URL);
+});
+
+add_task(function* test_one_bookmark() {
+  let bookmark = yield PlacesUtils.bookmarks.insert({
+    parentGuid: PlacesUtils.bookmarks.unfiledGuid,
+    url: TEST_URL,
+    title: "test"
+  });
+  let itemId = yield PlacesUtils.promiseItemId(bookmark.guid);
+  {
+    let { itemIds, url } = yield promiseAsyncGetBookmarkIds(NetUtil.newURI(TEST_URL));
+    Assert.equal(itemIds.length, 1);
+    Assert.equal(itemIds[0], itemId);
+    Assert.equal(url.spec, TEST_URL);
+  }
+  {
+    let { itemIds, url } = yield promiseAsyncGetBookmarkIds(TEST_URL);
+    Assert.equal(itemIds.length, 1);
+    Assert.equal(itemIds[0], itemId);
+    Assert.equal(url, TEST_URL);
+  }
+  yield PlacesUtils.bookmarks.remove(bookmark);
+});
 
-  function test_multiple_bookmarks() {
-    let uri = NetUtil.newURI(TEST_URL);
-    let itemIds = [];
-    itemIds.push(PlacesUtils.bookmarks.insertBookmark(
-      PlacesUtils.unfiledBookmarksFolderId, uri, "test",
-      PlacesUtils.bookmarks.DEFAULT_INDEX
-    ));
-    itemIds.push(PlacesUtils.bookmarks.insertBookmark(
-      PlacesUtils.unfiledBookmarksFolderId, uri, "test",
-      PlacesUtils.bookmarks.DEFAULT_INDEX
-    ));
-    PlacesUtils.asyncGetBookmarkIds(uri, (aItemIds, aURI) => {
-      do_check_eq(aItemIds.length, 2);
-      do_check_true(do_compare_arrays(itemIds, aItemIds));
-      do_check_true(aURI.equals(uri));
-      itemIds.forEach(PlacesUtils.bookmarks.removeItem);
-      run_next_test();
-    });
-  },
+add_task(function* test_multiple_bookmarks() {
+  let ids = [];
+  let bookmark1 = yield PlacesUtils.bookmarks.insert({
+    parentGuid: PlacesUtils.bookmarks.unfiledGuid,
+    url: TEST_URL,
+    title: "test"
+  });
+  ids.push((yield PlacesUtils.promiseItemId(bookmark1.guid)));
+  let bookmark2 = yield PlacesUtils.bookmarks.insert({
+    parentGuid: PlacesUtils.bookmarks.unfiledGuid,
+    url: TEST_URL,
+    title: "test"
+  });
+  ids.push((yield PlacesUtils.promiseItemId(bookmark2.guid)));
 
-  function test_cancel() {
-    let pending = PlacesUtils.asyncGetBookmarkIds(TEST_URL, (aItemIds, aURI) => {
-      do_throw("A canceled pending statement should not be invoked");
-    });
-    pending.cancel();
-    PlacesUtils.asyncGetBookmarkIds(TEST_URL, (aItemIds, aURI) => {
-      do_check_eq(aItemIds.length, 0);
-      do_check_eq(aURI, TEST_URL);
-      run_next_test();
-    });
-  },
+  let { itemIds, url } = yield promiseAsyncGetBookmarkIds(TEST_URL);
+  Assert.deepEqual(ids, itemIds);
+  Assert.equal(url, TEST_URL);
+
+  yield PlacesUtils.bookmarks.remove(bookmark1);
+  yield PlacesUtils.bookmarks.remove(bookmark2);
+});
 
-].forEach(add_test);
+add_task(function* test_cancel() {
+  let pending = PlacesUtils.asyncGetBookmarkIds(TEST_URL, () => {
+    Assert.ok(false, "A canceled pending statement should not be invoked");
+  });
+  pending.cancel();
 
-function run_test() {
-  run_next_test();
-}
+  let { itemIds, url } = yield promiseAsyncGetBookmarkIds(TEST_URL);
+  Assert.equal(itemIds.length, 0);
+  Assert.equal(url, TEST_URL);
+});