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

Unified Diff: chrome/browser/sync/test/integration/bookmarks_helper.cc

Issue 2379433002: [Sync] Refactoring of sync integration test checkers to remove boilerplate await methods. (Closed)
Patch Set: Fixing another ChromeOS test. Created 4 years, 3 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
Index: chrome/browser/sync/test/integration/bookmarks_helper.cc
diff --git a/chrome/browser/sync/test/integration/bookmarks_helper.cc b/chrome/browser/sync/test/integration/bookmarks_helper.cc
index bc0ba98193ce1532a1eb53ff63862cf83389afd2..5774b31b184db53b6cc5d483d84f79c6b041047e 100644
--- a/chrome/browser/sync/test/integration/bookmarks_helper.cc
+++ b/chrome/browser/sync/test/integration/bookmarks_helper.cc
@@ -30,10 +30,7 @@
#include "chrome/browser/history/history_service_factory.h"
#include "chrome/browser/profiles/profile.h"
#include "chrome/browser/sync/profile_sync_service_factory.h"
-#include "chrome/browser/sync/test/integration/await_match_status_change_checker.h"
-#include "chrome/browser/sync/test/integration/multi_client_status_change_checker.h"
#include "chrome/browser/sync/test/integration/profile_sync_service_harness.h"
-#include "chrome/browser/sync/test/integration/single_client_status_change_checker.h"
#include "chrome/browser/sync/test/integration/sync_datatype_helper.h"
#include "chrome/browser/sync/test/integration/sync_test.h"
#include "chrome/common/chrome_paths.h"
@@ -76,8 +73,6 @@ class HistoryEmptyTask : public history::HistoryDBTask {
void DoneRunOnMainThread() override {}
private:
- ~HistoryEmptyTask() override {}
-
base::WaitableEvent* done_;
};
@@ -222,9 +217,6 @@ struct FaviconData {
icon_url(favicon_url) {
}
- ~FaviconData() {
- }
-
gfx::Image image;
GURL icon_url;
};
@@ -788,115 +780,6 @@ bool AllModelsMatch() {
return true;
}
-namespace {
-
-// Helper class used in the implementation of AwaitAllModelsMatch.
-class AllModelsMatchChecker : public MultiClientStatusChangeChecker {
- public:
- AllModelsMatchChecker();
- ~AllModelsMatchChecker() override;
-
- bool IsExitConditionSatisfied() override;
- std::string GetDebugMessage() const override;
-};
-
-AllModelsMatchChecker::AllModelsMatchChecker()
- : MultiClientStatusChangeChecker(
- sync_datatype_helper::test()->GetSyncServices()) {}
-
-AllModelsMatchChecker::~AllModelsMatchChecker() {}
-
-bool AllModelsMatchChecker::IsExitConditionSatisfied() {
- return AllModelsMatch();
-}
-
-std::string AllModelsMatchChecker::GetDebugMessage() const {
- return "Waiting for matching models";
-}
-
-} // namespace
-
-bool AwaitAllModelsMatch() {
- AllModelsMatchChecker checker;
- checker.Wait();
- return !checker.TimedOut();
-}
-
-namespace {
-
-// TODO(pvalenzuela): Remove this class and instead use
-// AwaitMatchStatusChangeChecker.
-class CountBookmarksWithTitlesMatchingChecker
- : public SingleClientStatusChangeChecker {
- public:
- CountBookmarksWithTitlesMatchingChecker(
- browser_sync::ProfileSyncService* service,
- int profile_index,
- const std::string& title,
- int expected_count)
- : SingleClientStatusChangeChecker(service),
- profile_index_(profile_index),
- title_(title),
- expected_count_(expected_count) {
- DCHECK_GE(expected_count, 0) << "expected_count must be non-negative.";
- }
-
- bool IsExitConditionSatisfied() override {
- int actual_count = CountBookmarksWithTitlesMatching(profile_index_, title_);
- return expected_count_ == actual_count;
- }
-
- std::string GetDebugMessage() const override {
- return "Waiting for bookmark count to match";
- }
-
- private:
- const int profile_index_;
- const std::string title_;
- const int expected_count_;
-};
-
-} // namespace
-
-bool AwaitCountBookmarksWithTitlesMatching(int profile,
- const std::string& title,
- int expected_count) {
- browser_sync::ProfileSyncService* service =
- sync_datatype_helper::test()->GetSyncService(profile);
- CountBookmarksWithTitlesMatchingChecker checker(service,
- profile,
- title,
- expected_count);
- checker.Wait();
- return !checker.TimedOut();
-}
-
-
-bool BookmarkCountsByUrlMatch(int profile,
- const GURL& url,
- int expected_count) {
- int actual_count = CountBookmarksWithUrlsMatching(profile, url);
- if (expected_count != actual_count) {
- DVLOG(1) << base::StringPrintf("Expected %d URL(s), but there were %d.",
- expected_count,
- actual_count);
- return false;
- }
- return true;
-}
-
-bool AwaitCountBookmarksWithUrlsMatching(int profile,
- const GURL& url,
- int expected_count) {
- AwaitMatchStatusChangeChecker checker(base::Bind(BookmarkCountsByUrlMatch,
- profile,
- base::ConstRef(url),
- expected_count),
- "Bookmark URL counts match.");
- checker.Wait();
- return !checker.TimedOut();
-}
-
bool ContainsDuplicateBookmarks(int profile) {
ui::TreeNodeIterator<const BookmarkNode> iterator(
GetBookmarkModel(profile)->root_node());
@@ -1011,3 +894,62 @@ std::string IndexedSubsubfolderName(int i) {
}
} // namespace bookmarks_helper
+
+BookmarksMatchChecker::BookmarksMatchChecker()
+ : MultiClientStatusChangeChecker(
+ sync_datatype_helper::test()->GetSyncServices()) {}
+
+bool BookmarksMatchChecker::IsExitConditionSatisfied() {
+ return bookmarks_helper::AllModelsMatch();
+}
+
+std::string BookmarksMatchChecker::GetDebugMessage() const {
+ return "Waiting for matching models";
+}
+
+BookmarksTitleChecker::BookmarksTitleChecker(int profile_index,
+ const std::string& title,
+ int expected_count)
+ : SingleClientStatusChangeChecker(
+ sync_datatype_helper::test()->GetSyncService(profile_index)),
+ profile_index_(profile_index),
+ title_(title),
+ expected_count_(expected_count) {
+ DCHECK_GE(expected_count, 0) << "expected_count must be non-negative.";
+}
+
+bool BookmarksTitleChecker::IsExitConditionSatisfied() {
+ int actual_count = bookmarks_helper::CountBookmarksWithTitlesMatching(
+ profile_index_, title_);
+ return expected_count_ == actual_count;
+}
+
+std::string BookmarksTitleChecker::GetDebugMessage() const {
+ return "Waiting for bookmark count to match";
+}
+
+namespace {
+
+bool BookmarkCountsByUrlMatch(int profile,
+ const GURL& url,
+ int expected_count) {
+ int actual_count =
+ bookmarks_helper::CountBookmarksWithUrlsMatching(profile, url);
+ if (expected_count != actual_count) {
+ DVLOG(1) << base::StringPrintf("Expected %d URL(s), but there were %d.",
+ expected_count, actual_count);
+ return false;
+ }
+ return true;
+}
+
+} // namespace
+
+BookmarksUrlChecker::BookmarksUrlChecker(int profile,
+ const GURL& url,
+ int expected_count)
+ : AwaitMatchStatusChangeChecker(base::Bind(BookmarkCountsByUrlMatch,
+ profile,
+ base::ConstRef(url),
+ expected_count),
+ "Bookmark URL counts match.") {}

Powered by Google App Engine
This is Rietveld 408576698