Bug 832133 - Stop using addvisit() in toolkit cpp tests.
authorMarco Bonardo <mbonardo@mozilla.com>
Fri, 25 Jan 2013 11:16:24 +0100
changeset 119858 95bb08ab18d87226e538f02cb4c9dc0f013e56c5
parent 119857 bd89dd17b9ddbb2ea812bd0ba6ce3059cae4bcd5
child 119859 eb42fd7cdd465abbef35f0895af4ca79e5027f62
push id1317
push userryanvm@gmail.com
push dateSun, 27 Jan 2013 02:21:57 +0000
treeherderfx-team@47684913d63d [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
bugs832133
milestone21.0a1
Bug 832133 - Stop using addvisit() in toolkit cpp tests. r=Mano
toolkit/components/places/tests/cpp/places_test_harness.h
--- a/toolkit/components/places/tests/cpp/places_test_harness.h
+++ b/toolkit/components/places/tests/cpp/places_test_harness.h
@@ -19,17 +19,16 @@
 #include "mozIStorageAsyncStatement.h"
 #include "mozIStorageStatementCallback.h"
 #include "mozIStoragePendingStatement.h"
 #include "nsPIPlacesDatabase.h"
 #include "nsIObserver.h"
 #include "prinrval.h"
 #include "mozilla/Attributes.h"
 
-#define TOPIC_FRECENCY_UPDATED "places-frecency-updated"
 #define WAITFORTOPIC_TIMEOUT_SECONDS 5
 
 
 static size_t gTotalTests = 0;
 static size_t gPassedTests = 0;
 
 #define do_check_true(aCondition) \
   PR_BEGIN_MACRO \
@@ -196,40 +195,16 @@ void AsyncStatementSpinner::SpinUntilCom
   nsCOMPtr<nsIThread> thread(::do_GetCurrentThread());
   nsresult rv = NS_OK;
   bool processed = true;
   while (!mCompleted && NS_SUCCEEDED(rv)) {
     rv = thread->ProcessNextEvent(true, &processed);
   }
 }
 
-/**
- * Adds a URI to the database.
- *
- * @param aURI
- *        The URI to add to the database.
- */
-void
-addURI(nsIURI* aURI)
-{
-  nsRefPtr<WaitForTopicSpinner> spinner =
-    new WaitForTopicSpinner(TOPIC_FRECENCY_UPDATED);
-
-  nsCOMPtr<nsINavHistoryService> hist =
-    do_GetService(NS_NAVHISTORYSERVICE_CONTRACTID);
-  int64_t id;
-  nsresult rv = hist->AddVisit(aURI, PR_Now(), nullptr,
-                               nsINavHistoryService::TRANSITION_LINK, false,
-                               0, &id);
-  do_check_success(rv);
-
-  // Wait for frecency update.
-  spinner->Spin();
-}
-
 struct PlaceRecord
 {
   int64_t id;
   int32_t hidden;
   int32_t typed;
   int32_t visitCount;
   nsCString guid;
 };
@@ -350,16 +325,51 @@ do_get_lastVisit(int64_t placeId, VisitR
   rv = stmt->GetInt64(0, &result.id);
   do_check_success(rv);
   rv = stmt->GetInt64(1, &result.lastVisitId);
   do_check_success(rv);
   rv = stmt->GetInt32(2, &result.transitionType);
   do_check_success(rv);
 }
 
+void
+do_wait_async_updates() {
+  nsCOMPtr<mozIStorageConnection> db = do_get_db();
+  nsCOMPtr<mozIStorageAsyncStatement> stmt;
+
+  db->CreateAsyncStatement(NS_LITERAL_CSTRING("BEGIN EXCLUSIVE"),
+                           getter_AddRefs(stmt));
+  nsCOMPtr<mozIStoragePendingStatement> pending;
+  (void)stmt->ExecuteAsync(nullptr, getter_AddRefs(pending));
+
+  db->CreateAsyncStatement(NS_LITERAL_CSTRING("COMMIT"),
+                           getter_AddRefs(stmt));
+  nsRefPtr<AsyncStatementSpinner> spinner = new AsyncStatementSpinner();
+  (void)stmt->ExecuteAsync(spinner, getter_AddRefs(pending));
+
+  spinner->SpinUntilCompleted();
+}
+
+/**
+ * Adds a URI to the database.
+ *
+ * @param aURI
+ *        The URI to add to the database.
+ */
+void
+addURI(nsIURI* aURI)
+{
+  nsCOMPtr<mozilla::IHistory> history = do_GetService(NS_IHISTORY_CONTRACTID);
+  do_check_true(history);
+  nsresult rv = history->VisitURI(aURI, nullptr, mozilla::IHistory::TOP_LEVEL);
+  do_check_success(rv);
+
+  do_wait_async_updates();
+}
+
 static const char TOPIC_PROFILE_CHANGE[] = "profile-before-change";
 static const char TOPIC_PLACES_CONNECTION_CLOSED[] = "places-connection-closed";
 
 class WaitForConnectionClosed MOZ_FINAL : public nsIObserver
 {
   nsRefPtr<WaitForTopicSpinner> mSpinner;
 public:
   NS_DECL_ISUPPORTS