Bug 806460 - Part 0: modernize test_bookmark_store.js. r=gps
authorRichard Newman <rnewman@mozilla.com>
Mon, 29 Oct 2012 15:22:31 -0700
changeset 111868 ea46051fdc771d13922a9c1c0673c4eea1eb169d
parent 111867 dd59fc450c806991f402f37b822c921fe0b90dec
child 111869 561c637077fa4d222d2d8471a75d380fa390b24d
push id93
push usernmatsakis@mozilla.com
push dateWed, 31 Oct 2012 21:26:57 +0000
reviewersgps
bugs806460
milestone19.0a1
Bug 806460 - Part 0: modernize test_bookmark_store.js. r=gps
services/sync/tests/unit/test_bookmark_store.js
--- a/services/sync/tests/unit/test_bookmark_store.js
+++ b/services/sync/tests/unit/test_bookmark_store.js
@@ -10,17 +10,17 @@ const PARENT_ANNO = "sync/parent";
 
 Service.engineManager.register(BookmarksEngine);
 let engine = Service.engineManager.get("bookmarks");
 let store = engine._store;
 let fxuri = Utils.makeURI("http://getfirefox.com/");
 let tburi = Utils.makeURI("http://getthunderbird.com/");
 
 
-function test_bookmark_create() {
+add_test(function test_bookmark_create() {
   try {
     _("Ensure the record isn't present yet.");
     let ids = PlacesUtils.bookmarks.getBookmarkIdsForURI(fxuri, {});
     do_check_eq(ids.length, 0);
 
     _("Let's create a new record.");
     let fxrecord = new Bookmark("bookmarks", "get-firefox1");
     fxrecord.bmkUri        = fxuri.spec;
@@ -81,20 +81,21 @@ function test_bookmark_create() {
     }
     do_check_eq(error.result, Cr.NS_ERROR_NOT_AVAILABLE);
     do_check_eq(PlacesUtils.bookmarks.getFolderIdForItem(id),
                 PlacesUtils.bookmarks.toolbarFolder);
     do_check_eq(PlacesUtils.bookmarks.getKeywordForBookmark(id), null);
   } finally {
     _("Clean up.");
     store.wipe();
+    run_next_test();
   }
-}
+});
 
-function test_bookmark_update() {
+add_test(function test_bookmark_update() {
   try {
     _("Create a bookmark whose values we'll change.");
     let bmk1_id = PlacesUtils.bookmarks.insertBookmark(
       PlacesUtils.bookmarks.toolbarFolder, fxuri,
       PlacesUtils.bookmarks.DEFAULT_INDEX,
       "Get Firefox!");
     PlacesUtils.annotations.setItemAnnotation(
       bmk1_id, "bookmarkProperties/description", "Firefox is awesome.", 0,
@@ -115,40 +116,42 @@ function test_bookmark_update() {
       PlacesUtils.annotations.getItemAnnotation(
         bmk1_id, "bookmarkProperties/description");
     }, Cr.NS_ERROR_NOT_AVAILABLE);
     do_check_eq(PlacesUtils.bookmarks.getItemTitle(bmk1_id), null);
     do_check_eq(PlacesUtils.bookmarks.getKeywordForBookmark(bmk1_id), null);
   } finally {
     _("Clean up.");
     store.wipe();
+    run_next_test();
   }
-}
+});
 
-function test_bookmark_createRecord() {
+add_test(function test_bookmark_createRecord() {
   try {
     _("Create a bookmark without a description or title.");
     let bmk1_id = PlacesUtils.bookmarks.insertBookmark(
       PlacesUtils.bookmarks.toolbarFolder, fxuri,
       PlacesUtils.bookmarks.DEFAULT_INDEX, null);
     let bmk1_guid = store.GUIDForId(bmk1_id);
 
     _("Verify that the record is created accordingly.");
     let record = store.createRecord(bmk1_guid);
     do_check_eq(record.title, null);
     do_check_eq(record.description, null);
     do_check_eq(record.keyword, null);
 
   } finally {
     _("Clean up.");
     store.wipe();
+    run_next_test();
   }
-}
+});
 
-function test_folder_create() {
+add_test(function test_folder_create() {
   try {
     _("Create a folder.");
     let folder = new BookmarkFolder("bookmarks", "testfolder-1");
     folder.parentName = "Bookmarks Toolbar";
     folder.parentid   = "toolbar";
     folder.title      = "Test Folder";
     store.applyIncoming(folder);
 
@@ -166,20 +169,21 @@ function test_folder_create() {
     for each (let property in ["title", "parentName", "parentid"])
       do_check_eq(newrecord[property], folder[property]);
 
     _("Folders have high sort index to ensure they're synced first.");
     do_check_eq(newrecord.sortindex, 1000000);
   } finally {
     _("Clean up.");
     store.wipe();
+    run_next_test();
   }
-}
+});
 
-function test_folder_createRecord() {
+add_test(function test_folder_createRecord() {
   try {
     _("Create a folder.");
     let folder1_id = PlacesUtils.bookmarks.createFolder(
       PlacesUtils.bookmarks.toolbarFolder, "Folder1", 0);
     let folder1_guid = store.GUIDForId(folder1_id);
 
     _("Create two bookmarks in that folder without assigning them GUIDs.");
     let bmk1_id = PlacesUtils.bookmarks.insertBookmark(
@@ -199,20 +203,21 @@ function test_folder_createRecord() {
     let bmk2_guid = store.GUIDForId(bmk2_id);
     do_check_eq(record.children.length, 2);
     do_check_eq(record.children[0], bmk1_guid);
     do_check_eq(record.children[1], bmk2_guid);
 
   } finally {
     _("Clean up.");
     store.wipe();
+    run_next_test();
   }
-}
+});
 
-function test_deleted() {
+add_test(function test_deleted() {
   try {
     _("Create a bookmark that will be deleted.");
     let bmk1_id = PlacesUtils.bookmarks.insertBookmark(
       PlacesUtils.bookmarks.toolbarFolder, fxuri,
       PlacesUtils.bookmarks.DEFAULT_INDEX, "Get Firefox!");
     let bmk1_guid = store.GUIDForId(bmk1_id);
 
     _("Delete the bookmark through the store.");
@@ -230,20 +235,21 @@ function test_deleted() {
     do_check_eq(error.result, Cr.NS_ERROR_ILLEGAL_VALUE);
 
     let newrec = store.createRecord(bmk1_guid);
     do_check_eq(newrec.deleted, true);
 
   } finally {
     _("Clean up.");
     store.wipe();
+    run_next_test();
   }
-}
+});
 
-function test_move_folder() {
+add_test(function test_move_folder() {
   try {
     _("Create two folders and a bookmark in one of them.");
     let folder1_id = PlacesUtils.bookmarks.createFolder(
       PlacesUtils.bookmarks.toolbarFolder, "Folder1", 0);
     let folder1_guid = store.GUIDForId(folder1_id);
     let folder2_id = PlacesUtils.bookmarks.createFolder(
       PlacesUtils.bookmarks.toolbarFolder, "Folder2", 0);
     let folder2_guid = store.GUIDForId(folder2_id);
@@ -258,20 +264,21 @@ function test_move_folder() {
     store.applyIncoming(record);
 
     _("Verify the new parent.");
     let new_folder_id = PlacesUtils.bookmarks.getFolderIdForItem(bmk_id);
     do_check_eq(store.GUIDForId(new_folder_id), folder2_guid);
   } finally {
     _("Clean up.");
     store.wipe();
+    run_next_test();
   }
-}
+});
 
-function test_move_order() {
+add_test(function test_move_order() {
   // Make sure the tracker is turned on.
   Svc.Obs.notify("weave:engine:start-tracking");
   try {
     _("Create two bookmarks");
     let bmk1_id = PlacesUtils.bookmarks.insertBookmark(
       PlacesUtils.bookmarks.toolbarFolder, fxuri,
       PlacesUtils.bookmarks.DEFAULT_INDEX, "Get Firefox!");
     let bmk1_guid = store.GUIDForId(bmk1_id);
@@ -301,20 +308,21 @@ function test_move_order() {
     _("Verify new order.");
     do_check_eq(PlacesUtils.bookmarks.getItemIndex(bmk2_id), 0);
     do_check_eq(PlacesUtils.bookmarks.getItemIndex(bmk1_id), 1);
 
   } finally {
     Svc.Obs.notify("weave:engine:stop-tracking");
     _("Clean up.");
     store.wipe();
+    run_next_test();
   }
-}
+});
 
-function test_orphan() {
+add_test(function test_orphan() {
   try {
 
     _("Add a new bookmark locally.");
     let bmk1_id = PlacesUtils.bookmarks.insertBookmark(
       PlacesUtils.bookmarks.toolbarFolder, fxuri,
       PlacesUtils.bookmarks.DEFAULT_INDEX, "Get Firefox!");
     let bmk1_guid = store.GUIDForId(bmk1_id);
     do_check_eq(PlacesUtils.bookmarks.getFolderIdForItem(bmk1_id),
@@ -336,20 +344,21 @@ function test_orphan() {
     do_check_eq(PlacesUtils.bookmarks.getFolderIdForItem(bmk1_id),
                 PlacesUtils.bookmarks.toolbarFolder);
     do_check_eq(PlacesUtils.annotations.getItemAnnotation(bmk1_id, PARENT_ANNO),
                 "non-existent");
 
   } finally {
     _("Clean up.");
     store.wipe();
+    run_next_test();
   }
-}
+});
 
-function test_reparentOrphans() {
+add_test(function test_reparentOrphans() {
   try {
     let folder1_id = PlacesUtils.bookmarks.createFolder(
       PlacesUtils.bookmarks.toolbarFolder, "Folder1", 0);
     let folder1_guid = store.GUIDForId(folder1_id);
 
     _("Create a bogus orphan record and write the record back to the store to trigger _reparentOrphans.");
     PlacesUtils.annotations.setItemAnnotation(
       folder1_id, PARENT_ANNO, folder1_guid, 0,
@@ -361,27 +370,21 @@ function test_reparentOrphans() {
 
     _("Verify that is has been marked as an orphan even though it couldn't be moved into itself.");
     do_check_eq(PlacesUtils.annotations.getItemAnnotation(folder1_id, PARENT_ANNO),
                 folder1_guid);
 
   } finally {
     _("Clean up.");
     store.wipe();
+
+    if (engine._tracker._lazySave) {
+      engine._tracker._lazySave.clear();
+    }
+
+    run_next_test();
   }
-}
+});
 
 function run_test() {
   initTestLogging('Trace');
-  test_bookmark_create();
-  test_bookmark_createRecord();
-  test_bookmark_update();
-  test_folder_create();
-  test_folder_createRecord();
-  test_deleted();
-  test_move_folder();
-  test_move_order();
-  test_orphan();
-  test_reparentOrphans();
-  if (engine._tracker._lazySave) {
-    engine._tracker._lazySave.clear();
-  }
+  run_next_test();
 }