Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(6793)

Unified Diff: chrome/test/live_sync/typed_urls_helper.cc

Issue 7461109: Allow sync integration tests to operate on multiple datatypes: Typed Urls (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: CR feedback; rebase Created 9 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « chrome/test/live_sync/typed_urls_helper.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/test/live_sync/typed_urls_helper.cc
diff --git a/chrome/test/live_sync/live_typed_urls_sync_test.cc b/chrome/test/live_sync/typed_urls_helper.cc
similarity index 69%
rename from chrome/test/live_sync/live_typed_urls_sync_test.cc
rename to chrome/test/live_sync/typed_urls_helper.cc
index 80cdd4a70ed463c7e376bd7e754a4a4e5708f88a..a549ad487bfa1ee04de9f5de9a1a18dc611ea902 100644
--- a/chrome/test/live_sync/live_typed_urls_sync_test.cc
+++ b/chrome/test/live_sync/typed_urls_helper.cc
@@ -2,7 +2,7 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
-#include "chrome/test/live_sync/live_typed_urls_sync_test.h"
+#include "chrome/test/live_sync/typed_urls_helper.h"
#include "base/synchronization/waitable_event.h"
#include "base/time.h"
@@ -11,8 +11,12 @@
#include "chrome/browser/history/history_backend.h"
#include "chrome/browser/history/history_types.h"
#include "chrome/browser/profiles/profile.h"
+#include "chrome/test/live_sync/live_sync_test.h"
+#include "chrome/test/live_sync/sync_datatype_helper.h"
#include "content/browser/cancelable_request.h"
+using sync_datatype_helper::test;
+
namespace {
class FlushHistoryDBQueueTask : public HistoryDBTask {
@@ -50,23 +54,35 @@ class GetTypedUrlsTask : public HistoryDBTask {
base::WaitableEvent* wait_event_;
};
-} // namespace
-
-LiveTypedUrlsSyncTest::LiveTypedUrlsSyncTest(TestType test_type)
- : LiveSyncTest(test_type),
- timestamp_(base::Time::Now()) {}
-
-LiveTypedUrlsSyncTest::~LiveTypedUrlsSyncTest() {}
-
-std::vector<history::URLRow>
-LiveTypedUrlsSyncTest::GetTypedUrlsFromClient(int index) {
+// Waits for the history DB thread to finish executing its current set of
+// tasks.
+void WaitForHistoryDBThread(int index) {
+ CancelableRequestConsumer cancelable_consumer;
HistoryService* service =
- GetProfile(index)->GetHistoryServiceWithoutCreating();
- return GetTypedUrlsFromHistoryService(service);
+ test()->GetProfile(index)->GetHistoryServiceWithoutCreating();
+ base::WaitableEvent wait_event(true, false);
+ service->ScheduleDBTask(new FlushHistoryDBQueueTask(&wait_event),
+ &cancelable_consumer);
+ wait_event.Wait();
+}
+
+// Creates a URLRow in the specified HistoryService.
+void AddToHistory(HistoryService* service,
+ const GURL& url,
+ const base::Time& timestamp) {
+ service->AddPage(url,
+ timestamp,
+ NULL, // scope
+ 1234, // page_id
+ GURL(), // referrer
+ PageTransition::TYPED,
+ history::RedirectList(),
+ history::SOURCE_BROWSED,
+ false);
}
-std::vector<history::URLRow>
-LiveTypedUrlsSyncTest::GetTypedUrlsFromHistoryService(HistoryService *service) {
+std::vector<history::URLRow> GetTypedUrlsFromHistoryService(
+ HistoryService* service) {
CancelableRequestConsumer cancelable_consumer;
std::vector<history::URLRow> rows;
base::WaitableEvent wait_event(true, false);
@@ -76,24 +92,40 @@ LiveTypedUrlsSyncTest::GetTypedUrlsFromHistoryService(HistoryService *service) {
return rows;
}
-base::Time LiveTypedUrlsSyncTest::GetTimestamp() {
+static base::Time* timestamp = NULL;
+
+} // namespace
+
+namespace typed_urls_helper {
+
+std::vector<history::URLRow> GetTypedUrlsFromClient(int index) {
+ HistoryService* service =
+ test()->GetProfile(index)->GetHistoryServiceWithoutCreating();
+ return GetTypedUrlsFromHistoryService(service);
+}
+
+base::Time GetTimestamp() {
// The history subsystem doesn't like identical timestamps for page visits,
// and it will massage the visit timestamps if we try to use identical
// values, which can lead to spurious errors. So make sure all timestamps
// are unique.
- base::Time original = timestamp_;
- timestamp_ += base::TimeDelta::FromMilliseconds(1);
+ if (!::timestamp)
+ ::timestamp = new base::Time(base::Time::Now());
+ base::Time original = *::timestamp;
+ *::timestamp += base::TimeDelta::FromMilliseconds(1);
return original;
}
-void LiveTypedUrlsSyncTest::AddUrlToHistory(int index, const GURL& url) {
+void AddUrlToHistory(int index, const GURL& url) {
base::Time timestamp = GetTimestamp();
- AddToHistory(GetProfile(index)->GetHistoryServiceWithoutCreating(),
- url,
- timestamp);
- AddToHistory(verifier()->GetHistoryService(Profile::IMPLICIT_ACCESS),
+ AddToHistory(test()->GetProfile(index)->GetHistoryServiceWithoutCreating(),
url,
timestamp);
+ if (test()->use_verifier())
+ AddToHistory(
+ test()->verifier()->GetHistoryService(Profile::IMPLICIT_ACCESS),
+ url,
+ timestamp);
// Wait until the AddPage() request has completed so we know the change has
// filtered down to the sync observers (don't need to wait for the
@@ -101,37 +133,15 @@ void LiveTypedUrlsSyncTest::AddUrlToHistory(int index, const GURL& url) {
WaitForHistoryDBThread(index);
}
-void LiveTypedUrlsSyncTest::AddToHistory(HistoryService* service,
- const GURL& url,
- const base::Time& timestamp) {
- service->AddPage(url,
- timestamp,
- NULL, // scope
- 1234, // page_id
- GURL(), // referrer
- PageTransition::TYPED,
- history::RedirectList(),
- history::SOURCE_BROWSED,
- false);
-}
-
-void LiveTypedUrlsSyncTest::DeleteUrlFromHistory(int index, const GURL& url) {
- GetProfile(index)->GetHistoryServiceWithoutCreating()->DeleteURL(url);
- verifier()->GetHistoryService(Profile::IMPLICIT_ACCESS)->DeleteURL(url);
+void DeleteUrlFromHistory(int index, const GURL& url) {
+ test()->GetProfile(index)->GetHistoryServiceWithoutCreating()->DeleteURL(url);
+ if (test()->use_verifier())
+ test()->verifier()->GetHistoryService(Profile::IMPLICIT_ACCESS)->
+ DeleteURL(url);
WaitForHistoryDBThread(index);
}
-void LiveTypedUrlsSyncTest::WaitForHistoryDBThread(int index) {
- CancelableRequestConsumer cancelable_consumer;
- HistoryService* service =
- GetProfile(index)->GetHistoryServiceWithoutCreating();
- base::WaitableEvent wait_event(true, false);
- service->ScheduleDBTask(new FlushHistoryDBQueueTask(&wait_event),
- &cancelable_consumer);
- wait_event.Wait();
-}
-
-void LiveTypedUrlsSyncTest::AssertURLRowVectorsAreEqual(
+void AssertURLRowVectorsAreEqual(
const std::vector<history::URLRow>& left,
const std::vector<history::URLRow>& right) {
ASSERT_EQ(left.size(), right.size());
@@ -150,7 +160,7 @@ void LiveTypedUrlsSyncTest::AssertURLRowVectorsAreEqual(
}
}
-void LiveTypedUrlsSyncTest::AssertURLRowsAreEqual(
+void AssertURLRowsAreEqual(
const history::URLRow& left, const history::URLRow& right) {
ASSERT_EQ(left.url(), right.url());
ASSERT_EQ(left.title(), right.title());
@@ -160,13 +170,15 @@ void LiveTypedUrlsSyncTest::AssertURLRowsAreEqual(
ASSERT_EQ(left.hidden(), right.hidden());
}
-void LiveTypedUrlsSyncTest::AssertAllProfilesHaveSameURLsAsVerifier() {
+void AssertAllProfilesHaveSameURLsAsVerifier() {
HistoryService* verifier_service =
- verifier()->GetHistoryService(Profile::IMPLICIT_ACCESS);
+ test()->verifier()->GetHistoryService(Profile::IMPLICIT_ACCESS);
std::vector<history::URLRow> verifier_urls =
GetTypedUrlsFromHistoryService(verifier_service);
- for (int i = 0; i < num_clients(); ++i) {
+ for (int i = 0; i < test()->num_clients(); ++i) {
std::vector<history::URLRow> urls = GetTypedUrlsFromClient(i);
AssertURLRowVectorsAreEqual(verifier_urls, urls);
}
}
+
+} // namespace typed_urls_helper
« no previous file with comments | « chrome/test/live_sync/typed_urls_helper.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698