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

Side by Side Diff: chrome/browser/sync/sync_startup_tracker_unittest.cc

Issue 1175243009: [Sync] Rename SyncEnabledAndLoggedIn() to CanStartSync(). (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Missed a const transition. Created 5 years, 6 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) 2013 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2013 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 "base/memory/scoped_ptr.h" 5 #include "base/memory/scoped_ptr.h"
6 #include "chrome/browser/sync/profile_sync_service_factory.h" 6 #include "chrome/browser/sync/profile_sync_service_factory.h"
7 #include "chrome/browser/sync/profile_sync_service_mock.h" 7 #include "chrome/browser/sync/profile_sync_service_mock.h"
8 #include "chrome/browser/sync/sync_startup_tracker.h" 8 #include "chrome/browser/sync/sync_startup_tracker.h"
9 #include "content/public/test/test_browser_thread_bundle.h" 9 #include "content/public/test/test_browser_thread_bundle.h"
10 #include "testing/gmock/include/gmock/gmock.h" 10 #include "testing/gmock/include/gmock/gmock.h"
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
49 49
50 void TearDown() override { profile_.reset(); } 50 void TearDown() override { profile_.reset(); }
51 51
52 void SetupNonInitializedPSS() { 52 void SetupNonInitializedPSS() {
53 EXPECT_CALL(*mock_pss_, GetAuthError()) 53 EXPECT_CALL(*mock_pss_, GetAuthError())
54 .WillRepeatedly(ReturnRef(no_error_)); 54 .WillRepeatedly(ReturnRef(no_error_));
55 EXPECT_CALL(*mock_pss_, backend_initialized()) 55 EXPECT_CALL(*mock_pss_, backend_initialized())
56 .WillRepeatedly(Return(false)); 56 .WillRepeatedly(Return(false));
57 EXPECT_CALL(*mock_pss_, HasUnrecoverableError()) 57 EXPECT_CALL(*mock_pss_, HasUnrecoverableError())
58 .WillRepeatedly(Return(false)); 58 .WillRepeatedly(Return(false));
59 EXPECT_CALL(*mock_pss_, IsSyncEnabledAndLoggedIn()) 59 EXPECT_CALL(*mock_pss_, CanSyncStart()).WillRepeatedly(Return(true));
60 .WillRepeatedly(Return(true));
61 } 60 }
62 61
63 content::TestBrowserThreadBundle thread_bundle_; 62 content::TestBrowserThreadBundle thread_bundle_;
64 GoogleServiceAuthError no_error_; 63 GoogleServiceAuthError no_error_;
65 scoped_ptr<TestingProfile> profile_; 64 scoped_ptr<TestingProfile> profile_;
66 ProfileSyncServiceMock* mock_pss_; 65 ProfileSyncServiceMock* mock_pss_;
67 MockObserver observer_; 66 MockObserver observer_;
68 }; 67 };
69 68
70 TEST_F(SyncStartupTrackerTest, SyncAlreadyInitialized) { 69 TEST_F(SyncStartupTrackerTest, SyncAlreadyInitialized) {
71 EXPECT_CALL(*mock_pss_, backend_initialized()).WillRepeatedly(Return(true)); 70 EXPECT_CALL(*mock_pss_, backend_initialized()).WillRepeatedly(Return(true));
72 EXPECT_CALL(*mock_pss_, IsSyncEnabledAndLoggedIn()) 71 EXPECT_CALL(*mock_pss_, CanSyncStart()).WillRepeatedly(Return(true));
73 .WillRepeatedly(Return(true));
74 EXPECT_CALL(observer_, SyncStartupCompleted()); 72 EXPECT_CALL(observer_, SyncStartupCompleted());
75 SyncStartupTracker tracker(profile_.get(), &observer_); 73 SyncStartupTracker tracker(profile_.get(), &observer_);
76 } 74 }
77 75
78 TEST_F(SyncStartupTrackerTest, SyncNotSignedIn) { 76 TEST_F(SyncStartupTrackerTest, SyncNotSignedIn) {
79 // Make sure that we get a SyncStartupFailed() callback if sync is not logged 77 // Make sure that we get a SyncStartupFailed() callback if sync is not logged
80 // in. 78 // in.
81 EXPECT_CALL(*mock_pss_, backend_initialized()).WillRepeatedly(Return(false)); 79 EXPECT_CALL(*mock_pss_, backend_initialized()).WillRepeatedly(Return(false));
82 EXPECT_CALL(*mock_pss_, IsSyncEnabledAndLoggedIn()).WillRepeatedly( 80 EXPECT_CALL(*mock_pss_, CanSyncStart()).WillRepeatedly(Return(false));
83 Return(false));
84 EXPECT_CALL(observer_, SyncStartupFailed()); 81 EXPECT_CALL(observer_, SyncStartupFailed());
85 SyncStartupTracker tracker(profile_.get(), &observer_); 82 SyncStartupTracker tracker(profile_.get(), &observer_);
86 } 83 }
87 84
88 TEST_F(SyncStartupTrackerTest, SyncAuthError) { 85 TEST_F(SyncStartupTrackerTest, SyncAuthError) {
89 // Make sure that we get a SyncStartupFailed() callback if sync gets an auth 86 // Make sure that we get a SyncStartupFailed() callback if sync gets an auth
90 // error. 87 // error.
91 EXPECT_CALL(*mock_pss_, backend_initialized()).WillRepeatedly(Return(false)); 88 EXPECT_CALL(*mock_pss_, backend_initialized()).WillRepeatedly(Return(false));
92 EXPECT_CALL(*mock_pss_, IsSyncEnabledAndLoggedIn()).WillRepeatedly( 89 EXPECT_CALL(*mock_pss_, CanSyncStart()).WillRepeatedly(Return(true));
93 Return(true));
94 GoogleServiceAuthError error( 90 GoogleServiceAuthError error(
95 GoogleServiceAuthError::INVALID_GAIA_CREDENTIALS); 91 GoogleServiceAuthError::INVALID_GAIA_CREDENTIALS);
96 EXPECT_CALL(*mock_pss_, GetAuthError()).WillRepeatedly(ReturnRef(error)); 92 EXPECT_CALL(*mock_pss_, GetAuthError()).WillRepeatedly(ReturnRef(error));
97 EXPECT_CALL(observer_, SyncStartupFailed()); 93 EXPECT_CALL(observer_, SyncStartupFailed());
98 SyncStartupTracker tracker(profile_.get(), &observer_); 94 SyncStartupTracker tracker(profile_.get(), &observer_);
99 } 95 }
100 96
101 TEST_F(SyncStartupTrackerTest, SyncDelayedInitialization) { 97 TEST_F(SyncStartupTrackerTest, SyncDelayedInitialization) {
102 // Non-initialized PSS should result in no callbacks to the observer. 98 // Non-initialized PSS should result in no callbacks to the observer.
103 SetupNonInitializedPSS(); 99 SetupNonInitializedPSS();
(...skipping 11 matching lines...) Expand all
115 // Non-initialized PSS should result in no callbacks to the observer. 111 // Non-initialized PSS should result in no callbacks to the observer.
116 SetupNonInitializedPSS(); 112 SetupNonInitializedPSS();
117 EXPECT_CALL(observer_, SyncStartupCompleted()).Times(0); 113 EXPECT_CALL(observer_, SyncStartupCompleted()).Times(0);
118 EXPECT_CALL(observer_, SyncStartupFailed()).Times(0); 114 EXPECT_CALL(observer_, SyncStartupFailed()).Times(0);
119 SyncStartupTracker tracker(profile_.get(), &observer_); 115 SyncStartupTracker tracker(profile_.get(), &observer_);
120 Mock::VerifyAndClearExpectations(&observer_); 116 Mock::VerifyAndClearExpectations(&observer_);
121 Mock::VerifyAndClearExpectations(mock_pss_); 117 Mock::VerifyAndClearExpectations(mock_pss_);
122 118
123 // Now, mark the PSS as having an auth error. 119 // Now, mark the PSS as having an auth error.
124 EXPECT_CALL(*mock_pss_, backend_initialized()).WillRepeatedly(Return(false)); 120 EXPECT_CALL(*mock_pss_, backend_initialized()).WillRepeatedly(Return(false));
125 EXPECT_CALL(*mock_pss_, IsSyncEnabledAndLoggedIn()).WillRepeatedly( 121 EXPECT_CALL(*mock_pss_, CanSyncStart()).WillRepeatedly(Return(true));
126 Return(true));
127 GoogleServiceAuthError error( 122 GoogleServiceAuthError error(
128 GoogleServiceAuthError::INVALID_GAIA_CREDENTIALS); 123 GoogleServiceAuthError::INVALID_GAIA_CREDENTIALS);
129 EXPECT_CALL(*mock_pss_, GetAuthError()).WillRepeatedly(ReturnRef(error)); 124 EXPECT_CALL(*mock_pss_, GetAuthError()).WillRepeatedly(ReturnRef(error));
130 EXPECT_CALL(observer_, SyncStartupFailed()); 125 EXPECT_CALL(observer_, SyncStartupFailed());
131 tracker.OnStateChanged(); 126 tracker.OnStateChanged();
132 } 127 }
133 128
134 TEST_F(SyncStartupTrackerTest, SyncDelayedUnrecoverableError) { 129 TEST_F(SyncStartupTrackerTest, SyncDelayedUnrecoverableError) {
135 // Non-initialized PSS should result in no callbacks to the observer. 130 // Non-initialized PSS should result in no callbacks to the observer.
136 SetupNonInitializedPSS(); 131 SetupNonInitializedPSS();
137 EXPECT_CALL(observer_, SyncStartupCompleted()).Times(0); 132 EXPECT_CALL(observer_, SyncStartupCompleted()).Times(0);
138 EXPECT_CALL(observer_, SyncStartupFailed()).Times(0); 133 EXPECT_CALL(observer_, SyncStartupFailed()).Times(0);
139 SyncStartupTracker tracker(profile_.get(), &observer_); 134 SyncStartupTracker tracker(profile_.get(), &observer_);
140 Mock::VerifyAndClearExpectations(&observer_); 135 Mock::VerifyAndClearExpectations(&observer_);
141 Mock::VerifyAndClearExpectations(mock_pss_); 136 Mock::VerifyAndClearExpectations(mock_pss_);
142 137
143 // Now, mark the PSS as having an unrecoverable error. 138 // Now, mark the PSS as having an unrecoverable error.
144 EXPECT_CALL(*mock_pss_, backend_initialized()).WillRepeatedly(Return(false)); 139 EXPECT_CALL(*mock_pss_, backend_initialized()).WillRepeatedly(Return(false));
145 EXPECT_CALL(*mock_pss_, IsSyncEnabledAndLoggedIn()).WillRepeatedly( 140 EXPECT_CALL(*mock_pss_, CanSyncStart()).WillRepeatedly(Return(true));
146 Return(true));
147 GoogleServiceAuthError error( 141 GoogleServiceAuthError error(
148 GoogleServiceAuthError::INVALID_GAIA_CREDENTIALS); 142 GoogleServiceAuthError::INVALID_GAIA_CREDENTIALS);
149 EXPECT_CALL(*mock_pss_, GetAuthError()).WillRepeatedly(ReturnRef(error)); 143 EXPECT_CALL(*mock_pss_, GetAuthError()).WillRepeatedly(ReturnRef(error));
150 EXPECT_CALL(observer_, SyncStartupFailed()); 144 EXPECT_CALL(observer_, SyncStartupFailed());
151 tracker.OnStateChanged(); 145 tracker.OnStateChanged();
152 } 146 }
153 147
154 } // namespace 148 } // namespace
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698