Bug 748562 - Kill AddPageWithDetails, in Sync. r=rnewman
authorPaolo Amadini <paolo.mozmail@amadzone.org>
Mon, 14 May 2012 20:42:29 +0200
changeset 93876 d030e76e9ed3f51c8c1e13da0067cf989cf192d0
parent 93875 b001da365ab72215b99d66938f4cc217f9c938e9
child 93877 4b199744d601e662eba52008340e44bc0cccd3d7
push id9363
push userpaolo.mozmail@amadzone.org
push dateMon, 14 May 2012 18:43:14 +0000
treeherdermozilla-inbound@4b199744d601 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersrnewman
bugs748562
milestone15.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 748562 - Kill AddPageWithDetails, in Sync. r=rnewman
services/sync/tests/unit/test_history_store.js
services/sync/tests/unit/test_places_guid_downgrade.js
--- a/services/sync/tests/unit/test_history_store.js
+++ b/services/sync/tests/unit/test_history_store.js
@@ -77,54 +77,71 @@ function run_test() {
 }
 
 add_test(function test_store() {
   _("Verify that we've got an empty store to work with.");
   do_check_empty(store.getAllIDs());
 
   _("Let's create an entry in the database.");
   fxuri = Utils.makeURI("http://getfirefox.com/");
-   PlacesUtils.history.addPageWithDetails(fxuri, "Get Firefox!", TIMESTAMP1);
 
-  _("Verify that the entry exists.");
-  let ids = Object.keys(store.getAllIDs());
-  do_check_eq(ids.length, 1);
-  fxguid = ids[0];
-  do_check_true(store.itemExists(fxguid));
+  let place = {
+    uri: fxuri,
+    title: "Get Firefox!",
+    visits: [{
+      visitDate: TIMESTAMP1,
+      transitionType: Ci.nsINavHistoryService.TRANSITION_LINK
+    }]
+  };
+  PlacesUtils.asyncHistory.updatePlaces(place, {
+    handleError: function handleError() {
+      do_throw("Unexpected error in adding visit.");
+    },
+    handleResult: function handleResult() {},
+    handleCompletion: onVisitAdded
+  });
 
-  _("If we query a non-existent record, it's marked as deleted.");
-  let record = store.createRecord("non-existent");
-  do_check_true(record.deleted);
+  function onVisitAdded() {
+    _("Verify that the entry exists.");
+    let ids = Object.keys(store.getAllIDs());
+    do_check_eq(ids.length, 1);
+    fxguid = ids[0];
+    do_check_true(store.itemExists(fxguid));
+
+    _("If we query a non-existent record, it's marked as deleted.");
+    let record = store.createRecord("non-existent");
+    do_check_true(record.deleted);
 
-  _("Verify createRecord() returns a complete record.");
-  record = store.createRecord(fxguid);
-  do_check_eq(record.histUri, fxuri.spec);
-  do_check_eq(record.title, "Get Firefox!");
-  do_check_eq(record.visits.length, 1);
-  do_check_eq(record.visits[0].date, TIMESTAMP1);
-  do_check_eq(record.visits[0].type, Ci.nsINavHistoryService.TRANSITION_LINK);
+    _("Verify createRecord() returns a complete record.");
+    record = store.createRecord(fxguid);
+    do_check_eq(record.histUri, fxuri.spec);
+    do_check_eq(record.title, "Get Firefox!");
+    do_check_eq(record.visits.length, 1);
+    do_check_eq(record.visits[0].date, TIMESTAMP1);
+    do_check_eq(record.visits[0].type, Ci.nsINavHistoryService.TRANSITION_LINK);
 
-  _("Let's modify the record and have the store update the database.");
-  let secondvisit = {date: TIMESTAMP2,
-                     type: Ci.nsINavHistoryService.TRANSITION_TYPED};
-  onNextTitleChanged(ensureThrows(function() {
-    let queryres = queryHistoryVisits(fxuri);
-    do_check_eq(queryres.length, 2);
-    do_check_eq(queryres[0].time, TIMESTAMP1);
-    do_check_eq(queryres[0].title, "Hol Dir Firefox!");
-    do_check_eq(queryres[1].time, TIMESTAMP2);
-    do_check_eq(queryres[1].title, "Hol Dir Firefox!");
-    run_next_test();
-  }));
-  applyEnsureNoFailures([
-    {id: fxguid,
-     histUri: record.histUri,
-     title: "Hol Dir Firefox!",
-     visits: [record.visits[0], secondvisit]}
-  ]);
+    _("Let's modify the record and have the store update the database.");
+    let secondvisit = {date: TIMESTAMP2,
+                       type: Ci.nsINavHistoryService.TRANSITION_TYPED};
+    onNextTitleChanged(ensureThrows(function() {
+      let queryres = queryHistoryVisits(fxuri);
+      do_check_eq(queryres.length, 2);
+      do_check_eq(queryres[0].time, TIMESTAMP1);
+      do_check_eq(queryres[0].title, "Hol Dir Firefox!");
+      do_check_eq(queryres[1].time, TIMESTAMP2);
+      do_check_eq(queryres[1].title, "Hol Dir Firefox!");
+      run_next_test();
+    }));
+    applyEnsureNoFailures([
+      {id: fxguid,
+       histUri: record.histUri,
+       title: "Hol Dir Firefox!",
+       visits: [record.visits[0], secondvisit]}
+    ]);
+  }
 });
 
 add_test(function test_store_create() {
   _("Create a brand new record through the store.");
   tbguid = Utils.makeGUID();
   tburi = Utils.makeURI("http://getthunderbird.com");
   onNextTitleChanged(ensureThrows(function() {
     do_check_attribute_count(store.getAllIDs(), 2);
--- a/services/sync/tests/unit/test_places_guid_downgrade.js
+++ b/services/sync/tests/unit/test_places_guid_downgrade.js
@@ -30,17 +30,19 @@ function removePlacesDatabase() {
 }
 
 Svc.Obs.add("places-shutdown", function () {
   do_timeout(0, removePlacesDatabase);
 });
 
 
 // Verify initial database state. Function borrowed from places tests.
-function test_initial_state() {
+add_test(function test_initial_state() {
+  _("Verify initial setup: v11 database is available");
+
   // Mostly sanity checks our starting DB to make sure it's setup as we expect
   // it to be.
   let dbFile = gSyncProfile.clone();
   dbFile.append(kDBName);
   let db = storageSvc.openUnsharedDatabase(dbFile);
 
   let stmt = db.createStatement("PRAGMA journal_mode");
   do_check_true(stmt.executeStep());
@@ -71,71 +73,90 @@ function test_initial_state() {
   do_check_true(stmt.executeStep());
   do_check_neq(stmt.getInt32(0), 0);
   stmt.finalize();
 
   // Check our schema version to make sure it is actually at 10.
   do_check_eq(db.schemaVersion, 10);
 
   db.close();
-}
 
-function test_history_guids() {
+  run_next_test();
+});
+
+add_test(function test_history_guids() {
   let engine = new HistoryEngine();
   let store = engine._store;
 
-  PlacesUtils.history.addPageWithDetails(fxuri, "Get Firefox!",
-                                         Date.now() * 1000);
-  PlacesUtils.history.addPageWithDetails(tburi, "Get Thunderbird!",
-                                         Date.now() * 1000);
+  let places = [
+    {
+      uri: fxuri,
+      title: "Get Firefox!",
+      visits: [{
+        visitDate: Date.now() * 1000,
+        transitionType: Ci.nsINavHistoryService.TRANSITION_LINK
+      }]
+    },
+    {
+      uri: tburi,
+      title: "Get Thunderbird!",
+      visits: [{
+        visitDate: Date.now() * 1000,
+        transitionType: Ci.nsINavHistoryService.TRANSITION_LINK
+      }]
+    }
+  ];
+  PlacesUtils.asyncHistory.updatePlaces(places, {
+    handleError: function handleError() {
+      do_throw("Unexpected error in adding visit.");
+    },
+    handleResult: function handleResult() {},
+    handleCompletion: onVisitAdded
+  });
 
-  // Hack: flush the places db by adding a random bookmark.
-  let uri = Utils.makeURI("http://mozilla.com/");
-  let fxid = PlacesUtils.bookmarks.insertBookmark(
-    PlacesUtils.bookmarks.toolbarFolder,
-    uri,
-    PlacesUtils.bookmarks.DEFAULT_INDEX,
-    "Mozilla");
-
-  let fxguid = store.GUIDForUri(fxuri, true);
-  let tbguid = store.GUIDForUri(tburi, true);
-  dump("fxguid: " + fxguid + "\n");
-  dump("tbguid: " + tbguid + "\n");
-
-  _("History: Verify GUIDs are added to the guid column.");
-  let connection = PlacesUtils.history
-                              .QueryInterface(Ci.nsPIPlacesDatabase)
-                              .DBConnection;
-  let stmt = connection.createAsyncStatement(
-    "SELECT id FROM moz_places WHERE guid = :guid");
+  function onVisitAdded() {
+    let fxguid = store.GUIDForUri(fxuri, true);
+    let tbguid = store.GUIDForUri(tburi, true);
+    dump("fxguid: " + fxguid + "\n");
+    dump("tbguid: " + tbguid + "\n");
 
-  stmt.params.guid = fxguid;
-  let result = Async.querySpinningly(stmt, ["id"]);
-  do_check_eq(result.length, 1);
+    _("History: Verify GUIDs are added to the guid column.");
+    let connection = PlacesUtils.history
+                                .QueryInterface(Ci.nsPIPlacesDatabase)
+                                .DBConnection;
+    let stmt = connection.createAsyncStatement(
+      "SELECT id FROM moz_places WHERE guid = :guid");
 
-  stmt.params.guid = tbguid;
-  result = Async.querySpinningly(stmt, ["id"]);
-  do_check_eq(result.length, 1);
-  stmt.finalize();
+    stmt.params.guid = fxguid;
+    let result = Async.querySpinningly(stmt, ["id"]);
+    do_check_eq(result.length, 1);
+
+    stmt.params.guid = tbguid;
+    result = Async.querySpinningly(stmt, ["id"]);
+    do_check_eq(result.length, 1);
+    stmt.finalize();
 
-  _("History: Verify GUIDs weren't added to annotations.");
-  stmt = connection.createAsyncStatement(
-    "SELECT a.content AS guid FROM moz_annos a WHERE guid = :guid");
+    _("History: Verify GUIDs weren't added to annotations.");
+    stmt = connection.createAsyncStatement(
+      "SELECT a.content AS guid FROM moz_annos a WHERE guid = :guid");
 
-  stmt.params.guid = fxguid;
-  result = Async.querySpinningly(stmt, ["guid"]);
-  do_check_eq(result.length, 0);
+    stmt.params.guid = fxguid;
+    result = Async.querySpinningly(stmt, ["guid"]);
+    do_check_eq(result.length, 0);
 
-  stmt.params.guid = tbguid;
-  result = Async.querySpinningly(stmt, ["guid"]);
-  do_check_eq(result.length, 0);
-  stmt.finalize();
-}
+    stmt.params.guid = tbguid;
+    result = Async.querySpinningly(stmt, ["guid"]);
+    do_check_eq(result.length, 0);
+    stmt.finalize();
 
-function test_bookmark_guids() {
+    run_next_test();
+  }
+});
+
+add_test(function test_bookmark_guids() {
   let engine = new BookmarksEngine();
   let store = engine._store;
 
   let fxid = PlacesUtils.bookmarks.insertBookmark(
     PlacesUtils.bookmarks.toolbarFolder,
     fxuri,
     PlacesUtils.bookmarks.DEFAULT_INDEX,
     "Get Firefox!");
@@ -173,18 +194,17 @@ function test_bookmark_guids() {
   stmt.params.guid = fxguid;
   result = Async.querySpinningly(stmt, ["guid"]);
   do_check_eq(result.length, 0);
 
   stmt.params.guid = tbguid;
   result = Async.querySpinningly(stmt, ["guid"]);
   do_check_eq(result.length, 0);
   stmt.finalize();
-}
+
+  run_next_test();
+});
 
 function run_test() {
   setPlacesDatabase("places_v10_from_v11.sqlite");
 
-  _("Verify initial setup: v11 database is available");
-  test_initial_state();
-  test_history_guids();
-  test_bookmark_guids();
+  run_next_test();
 }