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

Side by Side Diff: chrome/browser/sync/test/integration/sync_integration_test_util.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 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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/sync_integration_test_util.h" 5 #include "chrome/browser/sync/test/integration/sync_integration_test_util.h"
6 6
7 #include <string> 7 #include <string>
8 8
9 #include "base/strings/stringprintf.h" 9 #include "base/strings/stringprintf.h"
10 #include "chrome/browser/sync/test/integration/fake_server_match_status_checker. h" 10 #include "chrome/browser/sync/test/integration/fake_server_match_status_checker. h"
11 #include "chrome/browser/sync/test/integration/single_client_status_change_check er.h"
12 #include "chrome/browser/sync/test/integration/updated_progress_marker_checker.h "
13 #include "components/browser_sync/profile_sync_service.h" 11 #include "components/browser_sync/profile_sync_service.h"
14 12
15 namespace { 13 ServerCountMatchStatusChecker::ServerCountMatchStatusChecker(
14 syncer::ModelType type,
15 size_t count)
16 : type_(type), count_(count) {}
16 17
17 // Helper class to block until the server has a given number of entities. 18 bool ServerCountMatchStatusChecker::IsExitConditionSatisfied() {
18 class ServerCountMatchStatusChecker 19 return count_ == fake_server()->GetSyncEntitiesByModelType(type_).size();
19 : public fake_server::FakeServerMatchStatusChecker {
20 public:
21 ServerCountMatchStatusChecker(syncer::ModelType type, size_t count)
22 : type_(type), count_(count) {}
23 ~ServerCountMatchStatusChecker() override {}
24
25 bool IsExitConditionSatisfied() override {
26 return count_ == fake_server()->GetSyncEntitiesByModelType(type_).size();
27 }
28
29 std::string GetDebugMessage() const override {
30 return base::StringPrintf(
31 "Waiting for fake server entity count %zu to match expected count %zu "
32 "for type %d",
33 (size_t)fake_server()->GetSyncEntitiesByModelType(type_).size(), count_,
34 type_);
35 }
36
37 private:
38 const syncer::ModelType type_;
39 const size_t count_;
40 };
41
42 class PassphraseRequiredChecker : public SingleClientStatusChangeChecker {
43 public:
44 explicit PassphraseRequiredChecker(browser_sync::ProfileSyncService* service)
45 : SingleClientStatusChangeChecker(service) {}
46
47 bool IsExitConditionSatisfied() override {
48 return service()->IsPassphraseRequired();
49 }
50
51 std::string GetDebugMessage() const override { return "Passhrase Required"; }
52 };
53
54 class PassphraseAcceptedChecker : public SingleClientStatusChangeChecker {
55 public:
56 explicit PassphraseAcceptedChecker(browser_sync::ProfileSyncService* service)
57 : SingleClientStatusChangeChecker(service) {}
58
59 bool IsExitConditionSatisfied() override {
60 return !service()->IsPassphraseRequired() &&
61 service()->IsUsingSecondaryPassphrase();
62 }
63
64 std::string GetDebugMessage() const override { return "Passhrase Accepted"; }
65 };
66
67 } // namespace
68
69 namespace sync_integration_test_util {
70
71 bool AwaitPassphraseRequired(browser_sync::ProfileSyncService* service) {
72 PassphraseRequiredChecker checker(service);
73 checker.Wait();
74 return !checker.TimedOut();
75 } 20 }
76 21
77 bool AwaitPassphraseAccepted(browser_sync::ProfileSyncService* service) { 22 std::string ServerCountMatchStatusChecker::GetDebugMessage() const {
78 PassphraseAcceptedChecker checker(service); 23 return base::StringPrintf(
79 checker.Wait(); 24 "Waiting for fake server entity count %zu to match expected count %zu "
80 return !checker.TimedOut(); 25 "for type %d",
26 (size_t)fake_server()->GetSyncEntitiesByModelType(type_).size(), count_,
27 type_);
81 } 28 }
82 29
83 bool AwaitCommitActivityCompletion(browser_sync::ProfileSyncService* service) { 30 PassphraseRequiredChecker::PassphraseRequiredChecker(
84 UpdatedProgressMarkerChecker checker(service); 31 browser_sync::ProfileSyncService* service)
85 checker.Wait(); 32 : SingleClientStatusChangeChecker(service) {}
86 return !checker.TimedOut(); 33
34 bool PassphraseRequiredChecker::IsExitConditionSatisfied() {
35 return service()->IsPassphraseRequired();
87 } 36 }
88 37
89 bool AwaitServerCount(syncer::ModelType type, size_t count) { 38 std::string PassphraseRequiredChecker::GetDebugMessage() const {
90 ServerCountMatchStatusChecker checker(type, count); 39 return "Passhrase Required";
91 checker.Wait();
92 return !checker.TimedOut();
93 } 40 }
94 41
95 } // namespace sync_integration_test_util 42 PassphraseAcceptedChecker::PassphraseAcceptedChecker(
43 browser_sync::ProfileSyncService* service)
44 : SingleClientStatusChangeChecker(service) {}
45
46 bool PassphraseAcceptedChecker::IsExitConditionSatisfied() {
47 return !service()->IsPassphraseRequired() &&
48 service()->IsUsingSecondaryPassphrase();
49 }
50
51 std::string PassphraseAcceptedChecker::GetDebugMessage() const {
52 return "Passhrase Accepted";
53 }
OLDNEW
« no previous file with comments | « chrome/browser/sync/test/integration/sync_integration_test_util.h ('k') | chrome/browser/sync/test/integration/sync_test.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698