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

Side by Side Diff: chrome/browser/sync/test/integration/typed_urls_helper.cc

Issue 2379433002: [Sync] Refactoring of sync integration test checkers to remove boilerplate await methods. (Closed)
Patch Set: Rebase Created 4 years, 2 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 unified diff | Download patch
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "chrome/browser/sync/test/integration/typed_urls_helper.h" 5 #include "chrome/browser/sync/test/integration/typed_urls_helper.h"
6 6
7 #include <stddef.h> 7 #include <stddef.h>
8 8
9 #include <memory>
10
9 #include "base/compiler_specific.h" 11 #include "base/compiler_specific.h"
10 #include "base/strings/utf_string_conversions.h" 12 #include "base/strings/utf_string_conversions.h"
11 #include "base/synchronization/waitable_event.h" 13 #include "base/synchronization/waitable_event.h"
12 #include "base/task/cancelable_task_tracker.h" 14 #include "base/task/cancelable_task_tracker.h"
13 #include "base/time/time.h" 15 #include "base/time/time.h"
14 #include "chrome/browser/history/history_service_factory.h" 16 #include "chrome/browser/history/history_service_factory.h"
15 #include "chrome/browser/profiles/profile.h" 17 #include "chrome/browser/profiles/profile.h"
16 #include "chrome/browser/sync/test/integration/multi_client_status_change_checke r.h"
17 #include "chrome/browser/sync/test/integration/sync_datatype_helper.h" 18 #include "chrome/browser/sync/test/integration/sync_datatype_helper.h"
18 #include "chrome/browser/sync/test/integration/sync_test.h" 19 #include "chrome/browser/sync/test/integration/sync_test.h"
19 #include "components/history/core/browser/history_backend.h" 20 #include "components/history/core/browser/history_backend.h"
20 #include "components/history/core/browser/history_db_task.h" 21 #include "components/history/core/browser/history_db_task.h"
21 #include "components/history/core/browser/history_service.h" 22 #include "components/history/core/browser/history_service.h"
22 23
23 using sync_datatype_helper::test; 24 using sync_datatype_helper::test;
24 25
25 namespace { 26 namespace {
26 27
(...skipping 128 matching lines...) Expand 10 before | Expand all | Expand 10 after
155 wait_event.Wait(); 156 wait_event.Wait();
156 } 157 }
157 158
158 // Creates a URLRow in the specified HistoryService with the passed transition 159 // Creates a URLRow in the specified HistoryService with the passed transition
159 // type. 160 // type.
160 void AddToHistory(history::HistoryService* service, 161 void AddToHistory(history::HistoryService* service,
161 const GURL& url, 162 const GURL& url,
162 ui::PageTransition transition, 163 ui::PageTransition transition,
163 history::VisitSource source, 164 history::VisitSource source,
164 const base::Time& timestamp) { 165 const base::Time& timestamp) {
165 service->AddPage(url, 166 service->AddPage(url, timestamp,
166 timestamp, 167 NULL, // scope
167 NULL, // scope 168 1234, // nav_entry_id
168 1234, // nav_entry_id
169 GURL(), // referrer 169 GURL(), // referrer
170 history::RedirectList(), 170 history::RedirectList(), transition, source, false);
171 transition,
172 source,
173 false);
174 } 171 }
175 172
176 history::URLRows GetTypedUrlsFromHistoryService( 173 history::URLRows GetTypedUrlsFromHistoryService(
177 history::HistoryService* service) { 174 history::HistoryService* service) {
178 base::CancelableTaskTracker tracker; 175 base::CancelableTaskTracker tracker;
179 history::URLRows rows; 176 history::URLRows rows;
180 base::WaitableEvent wait_event( 177 base::WaitableEvent wait_event(
181 base::WaitableEvent::ResetPolicy::MANUAL, 178 base::WaitableEvent::ResetPolicy::MANUAL,
182 base::WaitableEvent::InitialState::NOT_SIGNALED); 179 base::WaitableEvent::InitialState::NOT_SIGNALED);
183 service->ScheduleDBTask(std::unique_ptr<history::HistoryDBTask>( 180 service->ScheduleDBTask(std::unique_ptr<history::HistoryDBTask>(
(...skipping 230 matching lines...) Expand 10 before | Expand all | Expand 10 after
414 golden_urls = GetTypedUrlsFromClient(0); 411 golden_urls = GetTypedUrlsFromClient(0);
415 } 412 }
416 for (int i = 0; i < test()->num_clients(); ++i) { 413 for (int i = 0; i < test()->num_clients(); ++i) {
417 history::URLRows urls = GetTypedUrlsFromClient(i); 414 history::URLRows urls = GetTypedUrlsFromClient(i);
418 if (!CheckURLRowVectorsAreEqual(golden_urls, urls)) 415 if (!CheckURLRowVectorsAreEqual(golden_urls, urls))
419 return false; 416 return false;
420 } 417 }
421 return true; 418 return true;
422 } 419 }
423 420
424 namespace { 421 } // namespace typed_urls_helper
425
426 // Helper class used in the implementation of
427 // AwaitCheckAllProfilesHaveSameURLs.
428 class ProfilesHaveSameURLsChecker : public MultiClientStatusChangeChecker {
429 public:
430 ProfilesHaveSameURLsChecker();
431 ~ProfilesHaveSameURLsChecker() override;
432
433 bool IsExitConditionSatisfied() override;
434 std::string GetDebugMessage() const override;
435 };
436 422
437 ProfilesHaveSameURLsChecker::ProfilesHaveSameURLsChecker() 423 ProfilesHaveSameURLsChecker::ProfilesHaveSameURLsChecker()
438 : MultiClientStatusChangeChecker( 424 : MultiClientStatusChangeChecker(
439 sync_datatype_helper::test()->GetSyncServices()) {} 425 sync_datatype_helper::test()->GetSyncServices()) {}
440 426
441 ProfilesHaveSameURLsChecker::~ProfilesHaveSameURLsChecker() {}
442
443 bool ProfilesHaveSameURLsChecker::IsExitConditionSatisfied() { 427 bool ProfilesHaveSameURLsChecker::IsExitConditionSatisfied() {
444 return CheckAllProfilesHaveSameURLs(); 428 return typed_urls_helper::CheckAllProfilesHaveSameURLs();
445 } 429 }
446 430
447 std::string ProfilesHaveSameURLsChecker::GetDebugMessage() const { 431 std::string ProfilesHaveSameURLsChecker::GetDebugMessage() const {
448 return "Waiting for matching typed urls profiles"; 432 return "Waiting for matching typed urls profiles";
449 } 433 }
450
451 } // namespace
452
453 bool AwaitCheckAllProfilesHaveSameURLs() {
454 ProfilesHaveSameURLsChecker checker;
455 checker.Wait();
456 return !checker.TimedOut();
457 }
458
459 } // namespace typed_urls_helper
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698