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

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

Issue 3305003: New authorization framework for sync. ... (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 10 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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2010 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 "testing/gtest/include/gtest/gtest.h" 5 #include "testing/gtest/include/gtest/gtest.h"
6 6
7 #include "base/message_loop.h" 7 #include "base/message_loop.h"
8 #include "base/scoped_ptr.h" 8 #include "base/scoped_ptr.h"
9 #include "chrome/browser/chrome_thread.h" 9 #include "chrome/browser/chrome_thread.h"
10 #include "chrome/browser/net/gaia/token_service.h" 10 #include "chrome/browser/net/gaia/token_service.h"
11 #include "chrome/browser/prefs/pref_service.h" 11 #include "chrome/browser/prefs/pref_service.h"
12 #include "chrome/browser/sync/glue/data_type_manager.h" 12 #include "chrome/browser/sync/glue/data_type_manager.h"
13 #include "chrome/browser/sync/glue/data_type_manager_mock.h" 13 #include "chrome/browser/sync/glue/data_type_manager_mock.h"
14 #include "chrome/browser/sync/profile_sync_factory_mock.h" 14 #include "chrome/browser/sync/profile_sync_factory_mock.h"
15 #include "chrome/browser/sync/profile_sync_test_util.h" 15 #include "chrome/browser/sync/profile_sync_test_util.h"
16 #include "chrome/browser/sync/test_profile_sync_service.h" 16 #include "chrome/browser/sync/test_profile_sync_service.h"
17 #include "chrome/common/net/gaia/gaia_auth_consumer.h" 17 #include "chrome/common/net/gaia/gaia_auth_consumer.h"
18 #include "chrome/common/net/gaia/gaia_constants.h"
18 #include "chrome/common/notification_type.h" 19 #include "chrome/common/notification_type.h"
19 #include "chrome/common/pref_names.h" 20 #include "chrome/common/pref_names.h"
20 #include "chrome/test/testing_profile.h" 21 #include "chrome/test/testing_profile.h"
21 #include "testing/gmock/include/gmock/gmock.h" 22 #include "testing/gmock/include/gmock/gmock.h"
22 23
23 using browser_sync::DataTypeManager; 24 using browser_sync::DataTypeManager;
24 using browser_sync::DataTypeManagerMock; 25 using browser_sync::DataTypeManagerMock;
25 using testing::_; 26 using testing::_;
26 using testing::DoAll; 27 using testing::DoAll;
27 using testing::InvokeArgument; 28 using testing::InvokeArgument;
28 using testing::Mock; 29 using testing::Mock;
29 using testing::Return; 30 using testing::Return;
30 31
31 ACTION_P(InvokeCallback, callback_result) { 32 ACTION_P(InvokeCallback, callback_result) {
32 arg0->Run(callback_result); 33 arg0->Run(callback_result);
33 delete arg0; 34 delete arg0;
34 } 35 }
35 36
36 // TODO(skrul) This test fails on the mac. See http://crbug.com/33443 37 // TODO(skrul) This test fails on the mac. See http://crbug.com/33443
37 #if defined(OS_MACOSX) 38 #if defined(OS_MACOSX)
38 #define SKIP_MACOSX(test) DISABLED_##test 39 #define SKIP_MACOSX(test) DISABLED_##test
39 #else 40 #else
40 #define SKIP_MACOSX(test) test 41 #define SKIP_MACOSX(test) test
41 #endif 42 #endif
42 43
44 // TODO(chron): Test not using cros_user flag and use signin_
43 class ProfileSyncServiceStartupTest : public testing::Test { 45 class ProfileSyncServiceStartupTest : public testing::Test {
44 public: 46 public:
45 ProfileSyncServiceStartupTest() 47 ProfileSyncServiceStartupTest()
46 : ui_thread_(ChromeThread::UI, &message_loop_) {} 48 : ui_thread_(ChromeThread::UI, &message_loop_) {}
47 49
48 virtual ~ProfileSyncServiceStartupTest() { 50 virtual ~ProfileSyncServiceStartupTest() {
49 // The PSS has some deletes that are scheduled on the main thread 51 // The PSS has some deletes that are scheduled on the main thread
50 // so we must delete the service and run the message loop. 52 // so we must delete the service and run the message loop.
51 service_.reset(); 53 service_.reset();
52 MessageLoop::current()->RunAllPending(); 54 MessageLoop::current()->RunAllPending();
53 } 55 }
54 56
55 virtual void SetUp() { 57 virtual void SetUp() {
56 service_.reset(new TestProfileSyncService(&factory_, &profile_, 58 service_.reset(new TestProfileSyncService(&factory_, &profile_,
57 false, true, NULL)); 59 "test", true, NULL));
58 service_->AddObserver(&observer_); 60 service_->AddObserver(&observer_);
59 service_->set_num_expected_resumes(0); 61 service_->set_num_expected_resumes(0);
60 service_->set_num_expected_pauses(0); 62 service_->set_num_expected_pauses(0);
61 service_->set_synchronous_sync_configuration(); 63 service_->set_synchronous_sync_configuration();
62 } 64 }
63 65
64 virtual void TearDown() { 66 virtual void TearDown() {
65 service_->RemoveObserver(&observer_); 67 service_->RemoveObserver(&observer_);
66 } 68 }
67 69
(...skipping 24 matching lines...) Expand all
92 // to be enabled. 94 // to be enabled.
93 EXPECT_CALL(observer_, OnStateChanged()).Times(1); 95 EXPECT_CALL(observer_, OnStateChanged()).Times(1);
94 service_->Initialize(); 96 service_->Initialize();
95 97
96 // Preferences should be back to defaults. 98 // Preferences should be back to defaults.
97 EXPECT_EQ(0, profile_.GetPrefs()->GetInt64(prefs::kSyncLastSyncedTime)); 99 EXPECT_EQ(0, profile_.GetPrefs()->GetInt64(prefs::kSyncLastSyncedTime));
98 EXPECT_FALSE(profile_.GetPrefs()->GetBoolean(prefs::kSyncHasSetupCompleted)); 100 EXPECT_FALSE(profile_.GetPrefs()->GetBoolean(prefs::kSyncHasSetupCompleted));
99 Mock::VerifyAndClearExpectations(data_type_manager); 101 Mock::VerifyAndClearExpectations(data_type_manager);
100 102
101 // Then start things up. 103 // Then start things up.
102 EXPECT_CALL(*data_type_manager, Configure(_)).Times(1); 104 EXPECT_CALL(*data_type_manager, Configure(_)).Times(2);
103 EXPECT_CALL(*data_type_manager, state()). 105 EXPECT_CALL(*data_type_manager, state()).
104 WillOnce(Return(DataTypeManager::CONFIGURED)); 106 WillOnce(Return(DataTypeManager::CONFIGURED));
105 EXPECT_CALL(*data_type_manager, Stop()).Times(1); 107 EXPECT_CALL(*data_type_manager, Stop()).Times(1);
106 EXPECT_CALL(observer_, OnStateChanged()).Times(4); 108 EXPECT_CALL(observer_, OnStateChanged()).Times(5);
107 service_->EnableForUser(NULL); 109
110 // Create some tokens in the token service; the service will startup when
111 // it is notified that tokens are available.
112 profile_.GetTokenService()->IssueAuthTokenForTest(
113 GaiaConstants::kSyncService, "sync_token");
114
108 syncable::ModelTypeSet set; 115 syncable::ModelTypeSet set;
109 set.insert(syncable::BOOKMARKS); 116 set.insert(syncable::BOOKMARKS);
110 service_->OnUserChoseDatatypes(false, set); 117 service_->OnUserChoseDatatypes(false, set);
111 } 118 }
112 119
113 TEST_F(ProfileSyncServiceStartupTest, SKIP_MACOSX(StartNormal)) { 120 TEST_F(ProfileSyncServiceStartupTest, SKIP_MACOSX(StartNormal)) {
114 DataTypeManagerMock* data_type_manager = SetUpDataTypeManager(); 121 DataTypeManagerMock* data_type_manager = SetUpDataTypeManager();
115 EXPECT_CALL(*data_type_manager, Configure(_)).Times(1); 122 EXPECT_CALL(*data_type_manager, Configure(_)).Times(1);
116 EXPECT_CALL(*data_type_manager, state()). 123 EXPECT_CALL(*data_type_manager, state()).
117 WillOnce(Return(DataTypeManager::CONFIGURED)); 124 WillOnce(Return(DataTypeManager::CONFIGURED));
118 EXPECT_CALL(*data_type_manager, Stop()).Times(1); 125 EXPECT_CALL(*data_type_manager, Stop()).Times(1);
119 126
120 EXPECT_CALL(observer_, OnStateChanged()).Times(3); 127 EXPECT_CALL(observer_, OnStateChanged()).Times(3);
121 128
129 // Pre load the tokens
130 profile_.GetTokenService()->IssueAuthTokenForTest(
131 GaiaConstants::kSyncService, "sync_token");
122 service_->Initialize(); 132 service_->Initialize();
123 } 133 }
124 134
125 TEST_F(ProfileSyncServiceStartupTest, SKIP_MACOSX(ManagedStartup)) { 135 TEST_F(ProfileSyncServiceStartupTest, SKIP_MACOSX(ManagedStartup)) {
126 // Disable sync through policy. 136 // Disable sync through policy.
127 profile_.GetPrefs()->SetBoolean(prefs::kSyncManaged, true); 137 profile_.GetPrefs()->SetBoolean(prefs::kSyncManaged, true);
128 138
129 EXPECT_CALL(factory_, CreateDataTypeManager(_, _)).Times(0); 139 EXPECT_CALL(factory_, CreateDataTypeManager(_, _)).Times(0);
130 EXPECT_CALL(observer_, OnStateChanged()).Times(1); 140 EXPECT_CALL(observer_, OnStateChanged()).Times(1);
131 141
132 // Service should not be started by Initialize() since it's managed. 142 // Service should not be started by Initialize() since it's managed.
143 profile_.GetTokenService()->IssueAuthTokenForTest(
144 GaiaConstants::kSyncService, "sync_token");
133 service_->Initialize(); 145 service_->Initialize();
134 } 146 }
135 147
136 TEST_F(ProfileSyncServiceStartupTest, SKIP_MACOSX(SwitchManaged)) { 148 TEST_F(ProfileSyncServiceStartupTest, SKIP_MACOSX(SwitchManaged)) {
137 DataTypeManagerMock* data_type_manager = SetUpDataTypeManager(); 149 DataTypeManagerMock* data_type_manager = SetUpDataTypeManager();
138 EXPECT_CALL(*data_type_manager, Configure(_)).Times(1); 150 EXPECT_CALL(*data_type_manager, Configure(_)).Times(1);
139 EXPECT_CALL(observer_, OnStateChanged()).Times(3); 151 EXPECT_CALL(observer_, OnStateChanged()).Times(3);
140 152
153 profile_.GetTokenService()->IssueAuthTokenForTest(
154 GaiaConstants::kSyncService, "sync_token");
141 service_->Initialize(); 155 service_->Initialize();
142 156
143 // The service should stop when switching to managed mode. 157 // The service should stop when switching to managed mode.
144 Mock::VerifyAndClearExpectations(data_type_manager); 158 Mock::VerifyAndClearExpectations(data_type_manager);
145 EXPECT_CALL(*data_type_manager, state()). 159 EXPECT_CALL(*data_type_manager, state()).
146 WillOnce(Return(DataTypeManager::CONFIGURED)); 160 WillOnce(Return(DataTypeManager::CONFIGURED));
147 EXPECT_CALL(*data_type_manager, Stop()).Times(1); 161 EXPECT_CALL(*data_type_manager, Stop()).Times(1);
148 EXPECT_CALL(observer_, OnStateChanged()).Times(2); 162 EXPECT_CALL(observer_, OnStateChanged()).Times(2);
149 profile_.GetPrefs()->SetBoolean(prefs::kSyncManaged, true); 163 profile_.GetPrefs()->SetBoolean(prefs::kSyncManaged, true);
150 164
151 // When switching back to unmanaged, the state should change, but the service 165 // When switching back to unmanaged, the state should change, but the service
152 // should not start up automatically (kSyncSetupCompleted will be false). 166 // should not start up automatically (kSyncSetupCompleted will be false).
153 Mock::VerifyAndClearExpectations(data_type_manager); 167 Mock::VerifyAndClearExpectations(data_type_manager);
154 EXPECT_CALL(factory_, CreateDataTypeManager(_, _)).Times(0); 168 EXPECT_CALL(factory_, CreateDataTypeManager(_, _)).Times(0);
155 EXPECT_CALL(observer_, OnStateChanged()).Times(1); 169 EXPECT_CALL(observer_, OnStateChanged()).Times(1);
156 profile_.GetPrefs()->ClearPref(prefs::kSyncManaged); 170 profile_.GetPrefs()->ClearPref(prefs::kSyncManaged);
157 } 171 }
158 172
159 TEST_F(ProfileSyncServiceStartupTest, SKIP_MACOSX(StartFailure)) { 173 TEST_F(ProfileSyncServiceStartupTest, SKIP_MACOSX(StartFailure)) {
160 DataTypeManagerMock* data_type_manager = SetUpDataTypeManager(); 174 DataTypeManagerMock* data_type_manager = SetUpDataTypeManager();
161 DataTypeManager::ConfigureResult result = 175 DataTypeManager::ConfigureResult result =
162 DataTypeManager::ASSOCIATION_FAILED; 176 DataTypeManager::ASSOCIATION_FAILED;
163 EXPECT_CALL(*data_type_manager, Configure(_)). 177 EXPECT_CALL(*data_type_manager, Configure(_)).
164 WillOnce(DoAll(Notify(NotificationType::SYNC_CONFIGURE_START), 178 WillOnce(DoAll(Notify(NotificationType::SYNC_CONFIGURE_START),
165 NotifyWithResult(NotificationType::SYNC_CONFIGURE_DONE, 179 NotifyWithResult(NotificationType::SYNC_CONFIGURE_DONE,
166 &result))); 180 &result)));
167 EXPECT_CALL(*data_type_manager, Stop()).Times(1);
168 EXPECT_CALL(*data_type_manager, state()). 181 EXPECT_CALL(*data_type_manager, state()).
169 WillOnce(Return(DataTypeManager::STOPPED)); 182 WillOnce(Return(DataTypeManager::STOPPED));
170 183
171 EXPECT_CALL(observer_, OnStateChanged()).Times(3); 184 EXPECT_CALL(observer_, OnStateChanged()).Times(3);
172 185
186 profile_.GetTokenService()->IssueAuthTokenForTest(
187 GaiaConstants::kSyncService, "sync_token");
173 service_->Initialize(); 188 service_->Initialize();
174 EXPECT_TRUE(service_->unrecoverable_error_detected()); 189 EXPECT_TRUE(service_->unrecoverable_error_detected());
175 } 190 }
176
177 class ProfileSyncServiceStartupBootstrapTest
178 : public ProfileSyncServiceStartupTest {
179 public:
180 ProfileSyncServiceStartupBootstrapTest() {}
181 virtual ~ProfileSyncServiceStartupBootstrapTest() {}
182
183 virtual void SetUp() {
184 service_.reset(new TestProfileSyncService(&factory_, &profile_,
185 true, true, NULL));
186 service_->AddObserver(&observer_);
187 service_->set_num_expected_resumes(0);
188 service_->set_num_expected_pauses(0);
189 service_->set_synchronous_sync_configuration();
190 }
191 };
192
193 TEST_F(ProfileSyncServiceStartupBootstrapTest, SKIP_MACOSX(StartFirstTime)) {
194 DataTypeManagerMock* data_type_manager = SetUpDataTypeManager();
195 EXPECT_CALL(*data_type_manager, Configure(_)).Times(1);
196 EXPECT_CALL(*data_type_manager, state()).
197 WillOnce(Return(DataTypeManager::CONFIGURED));
198 EXPECT_CALL(*data_type_manager, Stop()).Times(1);
199 EXPECT_CALL(observer_, OnStateChanged()).Times(4);
200
201 profile_.GetPrefs()->ClearPref(prefs::kSyncHasSetupCompleted);
202
203 // Pretend the login screen worked.
204 GaiaAuthConsumer::ClientLoginResult result;
205 result.sid = "sid";
206 result.lsid = "lsid";
207 profile_.GetTokenService()->Initialize("test",
208 &profile_);
209 profile_.GetTokenService()->UpdateCredentials(result);
210
211 // Will start sync even though setup hasn't been completed (since
212 // setup is bypassed when bootstrapping is enabled).
213 service_->Initialize();
214 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698