OLD | NEW |
---|---|
1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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/ui/webui/settings/sync_handler.h" | 5 #include "chrome/browser/ui/webui/settings/people_handler.h" |
6 | 6 |
7 #include <vector> | 7 #include <vector> |
8 | 8 |
9 #include "base/command_line.h" | 9 #include "base/command_line.h" |
10 #include "base/json/json_writer.h" | 10 #include "base/json/json_writer.h" |
11 #include "base/memory/scoped_ptr.h" | 11 #include "base/memory/scoped_ptr.h" |
12 #include "base/prefs/pref_service.h" | 12 #include "base/prefs/pref_service.h" |
13 #include "base/stl_util.h" | 13 #include "base/stl_util.h" |
14 #include "base/values.h" | 14 #include "base/values.h" |
15 #include "chrome/browser/signin/fake_signin_manager_builder.h" | 15 #include "chrome/browser/signin/fake_signin_manager_builder.h" |
(...skipping 21 matching lines...) Expand all Loading... | |
37 using ::testing::_; | 37 using ::testing::_; |
38 using ::testing::Mock; | 38 using ::testing::Mock; |
39 using ::testing::Return; | 39 using ::testing::Return; |
40 using ::testing::ReturnRef; | 40 using ::testing::ReturnRef; |
41 using ::testing::Values; | 41 using ::testing::Values; |
42 | 42 |
43 typedef GoogleServiceAuthError AuthError; | 43 typedef GoogleServiceAuthError AuthError; |
44 | 44 |
45 namespace { | 45 namespace { |
46 | 46 |
47 MATCHER_P(ModelTypeSetMatches, value, "") { return arg.Equals(value); } | 47 MATCHER_P(ModelTypeSetMatches, value, "") { |
48 return arg.Equals(value); | |
49 } | |
48 | 50 |
49 const char kTestUser[] = "chrome.p13n.test@gmail.com"; | 51 const char kTestUser[] = "chrome.p13n.test@gmail.com"; |
50 | 52 |
51 // Returns a ModelTypeSet with all user selectable types set. | 53 // Returns a ModelTypeSet with all user selectable types set. |
52 syncer::ModelTypeSet GetAllTypes() { | 54 syncer::ModelTypeSet GetAllTypes() { |
53 return syncer::UserSelectableTypes(); | 55 return syncer::UserSelectableTypes(); |
54 } | 56 } |
55 | 57 |
56 enum SyncAllDataConfig { | 58 enum SyncAllDataConfig { SYNC_ALL_DATA, CHOOSE_WHAT_TO_SYNC, SYNC_NOTHING }; |
57 SYNC_ALL_DATA, | |
58 CHOOSE_WHAT_TO_SYNC, | |
59 SYNC_NOTHING | |
60 }; | |
61 | 59 |
62 enum EncryptAllConfig { | 60 enum EncryptAllConfig { ENCRYPT_ALL_DATA, ENCRYPT_PASSWORDS }; |
63 ENCRYPT_ALL_DATA, | |
64 ENCRYPT_PASSWORDS | |
65 }; | |
66 | 61 |
67 // Create a json-format string with the key/value pairs appropriate for a call | 62 // Create a json-format string with the key/value pairs appropriate for a call |
68 // to HandleConfigure(). If |extra_values| is non-null, then the values from | 63 // to HandleConfigure(). If |extra_values| is non-null, then the values from |
69 // the passed dictionary are added to the json. | 64 // the passed dictionary are added to the json. |
70 std::string GetConfiguration(const base::DictionaryValue* extra_values, | 65 std::string GetConfiguration(const base::DictionaryValue* extra_values, |
71 SyncAllDataConfig sync_all, | 66 SyncAllDataConfig sync_all, |
72 syncer::ModelTypeSet types, | 67 syncer::ModelTypeSet types, |
73 const std::string& passphrase, | 68 const std::string& passphrase, |
74 EncryptAllConfig encrypt_all) { | 69 EncryptAllConfig encrypt_all) { |
75 base::DictionaryValue result; | 70 base::DictionaryValue result; |
(...skipping 23 matching lines...) Expand all Loading... | |
99 } | 94 } |
100 | 95 |
101 // Checks whether the passed |dictionary| contains a |key| with the given | 96 // Checks whether the passed |dictionary| contains a |key| with the given |
102 // |expected_value|. If |omit_if_false| is true, then the value should only | 97 // |expected_value|. If |omit_if_false| is true, then the value should only |
103 // be present if |expected_value| is true. | 98 // be present if |expected_value| is true. |
104 void CheckBool(const base::DictionaryValue* dictionary, | 99 void CheckBool(const base::DictionaryValue* dictionary, |
105 const std::string& key, | 100 const std::string& key, |
106 bool expected_value, | 101 bool expected_value, |
107 bool omit_if_false) { | 102 bool omit_if_false) { |
108 if (omit_if_false && !expected_value) { | 103 if (omit_if_false && !expected_value) { |
109 EXPECT_FALSE(dictionary->HasKey(key)) << | 104 EXPECT_FALSE(dictionary->HasKey(key)) << "Did not expect to find value for " |
110 "Did not expect to find value for " << key; | 105 << key; |
111 } else { | 106 } else { |
112 bool actual_value; | 107 bool actual_value; |
113 EXPECT_TRUE(dictionary->GetBoolean(key, &actual_value)) << | 108 EXPECT_TRUE(dictionary->GetBoolean(key, &actual_value)) |
114 "No value found for " << key; | 109 << "No value found for " << key; |
115 EXPECT_EQ(expected_value, actual_value) << | 110 EXPECT_EQ(expected_value, actual_value) << "Mismatch found for " << key; |
116 "Mismatch found for " << key; | |
117 } | 111 } |
118 } | 112 } |
119 | 113 |
120 void CheckBool(const base::DictionaryValue* dictionary, | 114 void CheckBool(const base::DictionaryValue* dictionary, |
121 const std::string& key, | 115 const std::string& key, |
122 bool expected_value) { | 116 bool expected_value) { |
123 return CheckBool(dictionary, key, expected_value, false); | 117 return CheckBool(dictionary, key, expected_value, false); |
124 } | 118 } |
125 | 119 |
126 // Checks to make sure that the values stored in |dictionary| match the values | 120 // Checks to make sure that the values stored in |dictionary| match the values |
(...skipping 14 matching lines...) Expand all Loading... | |
141 CheckBool(dictionary, "themesSynced", types.Has(syncer::THEMES)); | 135 CheckBool(dictionary, "themesSynced", types.Has(syncer::THEMES)); |
142 CheckBool(dictionary, "typedUrlsSynced", types.Has(syncer::TYPED_URLS)); | 136 CheckBool(dictionary, "typedUrlsSynced", types.Has(syncer::TYPED_URLS)); |
143 CheckBool(dictionary, "wifiCredentialsSynced", | 137 CheckBool(dictionary, "wifiCredentialsSynced", |
144 types.Has(syncer::WIFI_CREDENTIALS)); | 138 types.Has(syncer::WIFI_CREDENTIALS)); |
145 } | 139 } |
146 | 140 |
147 } // namespace | 141 } // namespace |
148 | 142 |
149 namespace settings { | 143 namespace settings { |
150 | 144 |
151 class TestingSyncHandler : public SyncHandler { | 145 class TestingPeopleHandler : public PeopleHandler { |
152 public: | 146 public: |
153 TestingSyncHandler(content::WebUI* web_ui, Profile* profile) | 147 TestingPeopleHandler(content::WebUI* web_ui, Profile* profile) |
154 : SyncHandler(profile) { | 148 : PeopleHandler(profile) { |
155 set_web_ui(web_ui); | 149 set_web_ui(web_ui); |
156 } | 150 } |
157 ~TestingSyncHandler() override { | 151 ~TestingPeopleHandler() override { |
158 // TODO(tommycli): SyncHandler needs this call to destruct properly in the | 152 // TODO(tommycli): PeopleHandler needs this call to destruct properly in the |
159 // unit testing context. See the destructor to SyncHandler. This is hacky. | 153 // unit testing context. See the destructor to PeopleHandler. This is hacky. |
160 set_web_ui(nullptr); | 154 set_web_ui(nullptr); |
161 } | 155 } |
162 | 156 |
163 void FocusUI() override {} | 157 void FocusUI() override {} |
164 | 158 |
165 using SyncHandler::is_configuring_sync; | 159 using PeopleHandler::is_configuring_sync; |
166 | 160 |
167 private: | 161 private: |
168 #if !defined(OS_CHROMEOS) | 162 #if !defined(OS_CHROMEOS) |
169 void DisplayGaiaLoginInNewTabOrWindow( | 163 void DisplayGaiaLoginInNewTabOrWindow( |
170 signin_metrics::AccessPoint access_point) override {} | 164 signin_metrics::AccessPoint access_point) override {} |
171 #endif | 165 #endif |
172 | 166 |
173 DISALLOW_COPY_AND_ASSIGN(TestingSyncHandler); | 167 DISALLOW_COPY_AND_ASSIGN(TestingPeopleHandler); |
174 }; | 168 }; |
175 | 169 |
176 // The boolean parameter indicates whether the test is run with ClientOAuth | 170 // The boolean parameter indicates whether the test is run with ClientOAuth |
177 // or not. The test parameter is a bool: whether or not to test with/ | 171 // or not. The test parameter is a bool: whether or not to test with/ |
178 // /ClientLogin enabled or not. | 172 // /ClientLogin enabled or not. |
179 class SyncHandlerTest : public testing::Test { | 173 class PeopleHandlerTest : public testing::Test { |
180 public: | 174 public: |
181 SyncHandlerTest() : error_(GoogleServiceAuthError::NONE) {} | 175 PeopleHandlerTest() : error_(GoogleServiceAuthError::NONE) {} |
182 void SetUp() override { | 176 void SetUp() override { |
183 error_ = GoogleServiceAuthError::AuthErrorNone(); | 177 error_ = GoogleServiceAuthError::AuthErrorNone(); |
184 | 178 |
185 TestingProfile::Builder builder; | 179 TestingProfile::Builder builder; |
186 builder.AddTestingFactory(SigninManagerFactory::GetInstance(), | 180 builder.AddTestingFactory(SigninManagerFactory::GetInstance(), |
187 BuildFakeSigninManagerBase); | 181 BuildFakeSigninManagerBase); |
188 profile_ = builder.Build(); | 182 profile_ = builder.Build(); |
189 | 183 |
190 // Sign in the user. | 184 // Sign in the user. |
191 mock_signin_ = static_cast<SigninManagerBase*>( | 185 mock_signin_ = static_cast<SigninManagerBase*>( |
192 SigninManagerFactory::GetForProfile(profile_.get())); | 186 SigninManagerFactory::GetForProfile(profile_.get())); |
193 std::string username = GetTestUser(); | 187 std::string username = GetTestUser(); |
194 if (!username.empty()) | 188 if (!username.empty()) |
195 mock_signin_->SetAuthenticatedAccountInfo(username, username); | 189 mock_signin_->SetAuthenticatedAccountInfo(username, username); |
196 | 190 |
197 mock_pss_ = static_cast<ProfileSyncServiceMock*>( | 191 mock_pss_ = static_cast<ProfileSyncServiceMock*>( |
198 ProfileSyncServiceFactory::GetInstance()->SetTestingFactoryAndUse( | 192 ProfileSyncServiceFactory::GetInstance()->SetTestingFactoryAndUse( |
199 profile_.get(), | 193 profile_.get(), |
200 ProfileSyncServiceMock::BuildMockProfileSyncService)); | 194 ProfileSyncServiceMock::BuildMockProfileSyncService)); |
201 EXPECT_CALL(*mock_pss_, GetAuthError()).WillRepeatedly(ReturnRef(error_)); | 195 EXPECT_CALL(*mock_pss_, GetAuthError()).WillRepeatedly(ReturnRef(error_)); |
202 ON_CALL(*mock_pss_, GetPassphraseType()).WillByDefault( | 196 ON_CALL(*mock_pss_, GetPassphraseType()) |
203 Return(syncer::IMPLICIT_PASSPHRASE)); | 197 .WillByDefault(Return(syncer::IMPLICIT_PASSPHRASE)); |
204 ON_CALL(*mock_pss_, GetPassphraseTime()).WillByDefault( | 198 ON_CALL(*mock_pss_, GetPassphraseTime()) |
205 Return(base::Time())); | 199 .WillByDefault(Return(base::Time())); |
206 ON_CALL(*mock_pss_, GetExplicitPassphraseTime()).WillByDefault( | 200 ON_CALL(*mock_pss_, GetExplicitPassphraseTime()) |
207 Return(base::Time())); | 201 .WillByDefault(Return(base::Time())); |
208 ON_CALL(*mock_pss_, GetRegisteredDataTypes()) | 202 ON_CALL(*mock_pss_, GetRegisteredDataTypes()) |
209 .WillByDefault(Return(syncer::ModelTypeSet())); | 203 .WillByDefault(Return(syncer::ModelTypeSet())); |
210 | 204 |
211 mock_pss_->Initialize(); | 205 mock_pss_->Initialize(); |
212 | 206 |
213 handler_.reset(new TestingSyncHandler(&web_ui_, profile_.get())); | 207 handler_.reset(new TestingPeopleHandler(&web_ui_, profile_.get())); |
214 } | 208 } |
215 | 209 |
216 // Setup the expectations for calls made when displaying the config page. | 210 // Setup the expectations for calls made when displaying the config page. |
217 void SetDefaultExpectationsForConfigPage() { | 211 void SetDefaultExpectationsForConfigPage() { |
218 EXPECT_CALL(*mock_pss_, CanSyncStart()).WillRepeatedly(Return(true)); | 212 EXPECT_CALL(*mock_pss_, CanSyncStart()).WillRepeatedly(Return(true)); |
219 EXPECT_CALL(*mock_pss_, GetRegisteredDataTypes()) | 213 EXPECT_CALL(*mock_pss_, GetRegisteredDataTypes()) |
220 .WillRepeatedly(Return(GetAllTypes())); | 214 .WillRepeatedly(Return(GetAllTypes())); |
221 EXPECT_CALL(*mock_pss_, GetPreferredDataTypes()) | 215 EXPECT_CALL(*mock_pss_, GetPreferredDataTypes()) |
222 .WillRepeatedly(Return(GetAllTypes())); | 216 .WillRepeatedly(Return(GetAllTypes())); |
223 EXPECT_CALL(*mock_pss_, GetActiveDataTypes()) | 217 EXPECT_CALL(*mock_pss_, GetActiveDataTypes()) |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
261 EXPECT_EQ(1U, web_ui_.call_data().size()); | 255 EXPECT_EQ(1U, web_ui_.call_data().size()); |
262 const content::TestWebUI::CallData& data = *web_ui_.call_data()[0]; | 256 const content::TestWebUI::CallData& data = *web_ui_.call_data()[0]; |
263 EXPECT_EQ("settings.SyncPrivateApi.showSyncSetupPage", | 257 EXPECT_EQ("settings.SyncPrivateApi.showSyncSetupPage", |
264 data.function_name()); | 258 data.function_name()); |
265 | 259 |
266 std::string page; | 260 std::string page; |
267 ASSERT_TRUE(data.arg1()->GetAsString(&page)); | 261 ASSERT_TRUE(data.arg1()->GetAsString(&page)); |
268 EXPECT_EQ(page, "spinner"); | 262 EXPECT_EQ(page, "spinner"); |
269 // Cancelling the spinner dialog will cause CloseSyncSetup(). | 263 // Cancelling the spinner dialog will cause CloseSyncSetup(). |
270 handler_->CloseSyncSetup(); | 264 handler_->CloseSyncSetup(); |
271 EXPECT_EQ(NULL, | 265 EXPECT_EQ(NULL, LoginUIServiceFactory::GetForProfile(profile_.get()) |
272 LoginUIServiceFactory::GetForProfile( | 266 ->current_login_ui()); |
dschuyler
2015/12/10 00:51:48
This is another case where it looks more readable
tommycli
2015/12/10 01:57:02
Done.
| |
273 profile_.get())->current_login_ui()); | |
274 } | 267 } |
275 | 268 |
276 // It's difficult to notify sync listeners when using a ProfileSyncServiceMock | 269 // It's difficult to notify sync listeners when using a ProfileSyncServiceMock |
277 // so this helper routine dispatches an OnStateChanged() notification to the | 270 // so this helper routine dispatches an OnStateChanged() notification to the |
278 // SyncStartupTracker. | 271 // SyncStartupTracker. |
279 void NotifySyncListeners() { | 272 void NotifySyncListeners() { |
280 if (handler_->sync_startup_tracker_) | 273 if (handler_->sync_startup_tracker_) |
281 handler_->sync_startup_tracker_->OnStateChanged(); | 274 handler_->sync_startup_tracker_->OnStateChanged(); |
282 } | 275 } |
283 | 276 |
284 virtual std::string GetTestUser() { | 277 virtual std::string GetTestUser() { return std::string(kTestUser); } |
285 return std::string(kTestUser); | |
286 } | |
287 | 278 |
288 content::TestBrowserThreadBundle thread_bundle_; | 279 content::TestBrowserThreadBundle thread_bundle_; |
289 scoped_ptr<Profile> profile_; | 280 scoped_ptr<Profile> profile_; |
290 ProfileSyncServiceMock* mock_pss_; | 281 ProfileSyncServiceMock* mock_pss_; |
291 GoogleServiceAuthError error_; | 282 GoogleServiceAuthError error_; |
292 SigninManagerBase* mock_signin_; | 283 SigninManagerBase* mock_signin_; |
293 content::TestWebUI web_ui_; | 284 content::TestWebUI web_ui_; |
294 scoped_ptr<TestingSyncHandler> handler_; | 285 scoped_ptr<TestingPeopleHandler> handler_; |
295 }; | 286 }; |
296 | 287 |
297 class SyncHandlerFirstSigninTest : public SyncHandlerTest { | 288 class PeopleHandlerFirstSigninTest : public PeopleHandlerTest { |
298 std::string GetTestUser() override { return std::string(); } | 289 std::string GetTestUser() override { return std::string(); } |
299 }; | 290 }; |
300 | 291 |
301 TEST_F(SyncHandlerTest, Basic) { | 292 TEST_F(PeopleHandlerTest, Basic) {} |
302 } | |
303 | 293 |
304 #if !defined(OS_CHROMEOS) | 294 #if !defined(OS_CHROMEOS) |
305 TEST_F(SyncHandlerFirstSigninTest, DisplayBasicLogin) { | 295 TEST_F(PeopleHandlerFirstSigninTest, DisplayBasicLogin) { |
306 EXPECT_CALL(*mock_pss_, CanSyncStart()).WillRepeatedly(Return(false)); | 296 EXPECT_CALL(*mock_pss_, CanSyncStart()).WillRepeatedly(Return(false)); |
307 EXPECT_CALL(*mock_pss_, IsOAuthRefreshTokenAvailable()) | 297 EXPECT_CALL(*mock_pss_, IsOAuthRefreshTokenAvailable()) |
308 .WillRepeatedly(Return(false)); | 298 .WillRepeatedly(Return(false)); |
309 EXPECT_CALL(*mock_pss_, HasSyncSetupCompleted()) | 299 EXPECT_CALL(*mock_pss_, HasSyncSetupCompleted()) |
310 .WillRepeatedly(Return(false)); | 300 .WillRepeatedly(Return(false)); |
311 // Ensure that the user is not signed in before calling |HandleStartSignin()|. | 301 // Ensure that the user is not signed in before calling |HandleStartSignin()|. |
312 SigninManager* manager = static_cast<SigninManager*>(mock_signin_); | 302 SigninManager* manager = static_cast<SigninManager*>(mock_signin_); |
313 manager->SignOut(signin_metrics::SIGNOUT_TEST); | 303 manager->SignOut(signin_metrics::SIGNOUT_TEST); |
314 handler_->HandleStartSignin(NULL); | 304 handler_->HandleStartSignin(NULL); |
315 | 305 |
316 // Sync setup hands off control to the gaia login tab. | 306 // Sync setup hands off control to the gaia login tab. |
317 EXPECT_EQ(NULL, | 307 EXPECT_EQ(NULL, LoginUIServiceFactory::GetForProfile(profile_.get()) |
318 LoginUIServiceFactory::GetForProfile( | 308 ->current_login_ui()); |
319 profile_.get())->current_login_ui()); | |
320 | 309 |
321 ASSERT_FALSE(handler_->is_configuring_sync()); | 310 ASSERT_FALSE(handler_->is_configuring_sync()); |
322 | 311 |
323 handler_->CloseSyncSetup(); | 312 handler_->CloseSyncSetup(); |
324 EXPECT_EQ(NULL, | 313 EXPECT_EQ(NULL, LoginUIServiceFactory::GetForProfile(profile_.get()) |
325 LoginUIServiceFactory::GetForProfile( | 314 ->current_login_ui()); |
326 profile_.get())->current_login_ui()); | |
327 } | 315 } |
328 | 316 |
329 TEST_F(SyncHandlerTest, ShowSyncSetupWhenNotSignedIn) { | 317 TEST_F(PeopleHandlerTest, ShowSyncSetupWhenNotSignedIn) { |
330 EXPECT_CALL(*mock_pss_, CanSyncStart()).WillRepeatedly(Return(false)); | 318 EXPECT_CALL(*mock_pss_, CanSyncStart()).WillRepeatedly(Return(false)); |
331 EXPECT_CALL(*mock_pss_, IsOAuthRefreshTokenAvailable()) | 319 EXPECT_CALL(*mock_pss_, IsOAuthRefreshTokenAvailable()) |
332 .WillRepeatedly(Return(false)); | 320 .WillRepeatedly(Return(false)); |
333 EXPECT_CALL(*mock_pss_, HasSyncSetupCompleted()) | 321 EXPECT_CALL(*mock_pss_, HasSyncSetupCompleted()) |
334 .WillRepeatedly(Return(false)); | 322 .WillRepeatedly(Return(false)); |
335 handler_->HandleShowSetupUI(NULL); | 323 handler_->HandleShowSetupUI(NULL); |
336 | 324 |
337 // We expect a call to settings.SyncPrivateApi.showSyncSetupPage. | 325 // We expect a call to settings.SyncPrivateApi.showSyncSetupPage. |
338 ASSERT_EQ(1U, web_ui_.call_data().size()); | 326 ASSERT_EQ(1U, web_ui_.call_data().size()); |
339 const content::TestWebUI::CallData& data = *web_ui_.call_data()[0]; | 327 const content::TestWebUI::CallData& data = *web_ui_.call_data()[0]; |
340 EXPECT_EQ("settings.SyncPrivateApi.showSyncSetupPage", data.function_name()); | 328 EXPECT_EQ("settings.SyncPrivateApi.showSyncSetupPage", data.function_name()); |
341 | 329 |
342 ASSERT_FALSE(handler_->is_configuring_sync()); | 330 ASSERT_FALSE(handler_->is_configuring_sync()); |
343 EXPECT_EQ(NULL, | 331 EXPECT_EQ(NULL, LoginUIServiceFactory::GetForProfile(profile_.get()) |
344 LoginUIServiceFactory::GetForProfile( | 332 ->current_login_ui()); |
345 profile_.get())->current_login_ui()); | |
346 } | 333 } |
347 #endif // !defined(OS_CHROMEOS) | 334 #endif // !defined(OS_CHROMEOS) |
348 | 335 |
349 // Verifies that the sync setup is terminated correctly when the | 336 // Verifies that the sync setup is terminated correctly when the |
350 // sync is disabled. | 337 // sync is disabled. |
351 TEST_F(SyncHandlerTest, HandleSetupUIWhenSyncDisabled) { | 338 TEST_F(PeopleHandlerTest, HandleSetupUIWhenSyncDisabled) { |
352 EXPECT_CALL(*mock_pss_, IsManaged()).WillRepeatedly(Return(true)); | 339 EXPECT_CALL(*mock_pss_, IsManaged()).WillRepeatedly(Return(true)); |
353 handler_->HandleShowSetupUI(NULL); | 340 handler_->HandleShowSetupUI(NULL); |
354 | 341 |
355 // Sync setup is closed when sync is disabled. | 342 // Sync setup is closed when sync is disabled. |
356 EXPECT_EQ(NULL, | 343 EXPECT_EQ(NULL, LoginUIServiceFactory::GetForProfile(profile_.get()) |
357 LoginUIServiceFactory::GetForProfile( | 344 ->current_login_ui()); |
358 profile_.get())->current_login_ui()); | |
359 ASSERT_FALSE(handler_->is_configuring_sync()); | 345 ASSERT_FALSE(handler_->is_configuring_sync()); |
360 } | 346 } |
361 | 347 |
362 // Verifies that the handler correctly handles a cancellation when | 348 // Verifies that the handler correctly handles a cancellation when |
363 // it is displaying the spinner to the user. | 349 // it is displaying the spinner to the user. |
364 TEST_F(SyncHandlerTest, DisplayConfigureWithBackendDisabledAndCancel) { | 350 TEST_F(PeopleHandlerTest, DisplayConfigureWithBackendDisabledAndCancel) { |
365 EXPECT_CALL(*mock_pss_, CanSyncStart()).WillRepeatedly(Return(true)); | 351 EXPECT_CALL(*mock_pss_, CanSyncStart()).WillRepeatedly(Return(true)); |
366 EXPECT_CALL(*mock_pss_, IsOAuthRefreshTokenAvailable()) | 352 EXPECT_CALL(*mock_pss_, IsOAuthRefreshTokenAvailable()) |
367 .WillRepeatedly(Return(true)); | 353 .WillRepeatedly(Return(true)); |
368 EXPECT_CALL(*mock_pss_, HasSyncSetupCompleted()) | 354 EXPECT_CALL(*mock_pss_, HasSyncSetupCompleted()) |
369 .WillRepeatedly(Return(false)); | 355 .WillRepeatedly(Return(false)); |
370 error_ = GoogleServiceAuthError::AuthErrorNone(); | 356 error_ = GoogleServiceAuthError::AuthErrorNone(); |
371 EXPECT_CALL(*mock_pss_, IsBackendInitialized()).WillRepeatedly(Return(false)); | 357 EXPECT_CALL(*mock_pss_, IsBackendInitialized()).WillRepeatedly(Return(false)); |
372 | 358 |
373 // We're simulating a user setting up sync, which would cause the backend to | 359 // We're simulating a user setting up sync, which would cause the backend to |
374 // kick off initialization, but not download user data types. The sync | 360 // kick off initialization, but not download user data types. The sync |
375 // backend will try to download control data types (e.g encryption info), but | 361 // backend will try to download control data types (e.g encryption info), but |
376 // that won't finish for this test as we're simulating cancelling while the | 362 // that won't finish for this test as we're simulating cancelling while the |
377 // spinner is showing. | 363 // spinner is showing. |
378 handler_->HandleShowSetupUI(NULL); | 364 handler_->HandleShowSetupUI(NULL); |
379 | 365 |
380 EXPECT_EQ(handler_.get(), | 366 EXPECT_EQ(handler_.get(), LoginUIServiceFactory::GetForProfile(profile_.get()) |
381 LoginUIServiceFactory::GetForProfile( | 367 ->current_login_ui()); |
382 profile_.get())->current_login_ui()); | |
383 | 368 |
384 ExpectSpinnerAndClose(); | 369 ExpectSpinnerAndClose(); |
385 } | 370 } |
386 | 371 |
387 // Verifies that the handler correctly transitions from showing the spinner | 372 // Verifies that the handler correctly transitions from showing the spinner |
388 // to showing a configuration page when sync setup completes successfully. | 373 // to showing a configuration page when sync setup completes successfully. |
389 TEST_F(SyncHandlerTest, | 374 TEST_F(PeopleHandlerTest, |
390 DisplayConfigureWithBackendDisabledAndSyncStartupCompleted) { | 375 DisplayConfigureWithBackendDisabledAndSyncStartupCompleted) { |
391 EXPECT_CALL(*mock_pss_, CanSyncStart()).WillRepeatedly(Return(true)); | 376 EXPECT_CALL(*mock_pss_, CanSyncStart()).WillRepeatedly(Return(true)); |
392 EXPECT_CALL(*mock_pss_, IsOAuthRefreshTokenAvailable()) | 377 EXPECT_CALL(*mock_pss_, IsOAuthRefreshTokenAvailable()) |
393 .WillRepeatedly(Return(true)); | 378 .WillRepeatedly(Return(true)); |
394 EXPECT_CALL(*mock_pss_, HasSyncSetupCompleted()) | 379 EXPECT_CALL(*mock_pss_, HasSyncSetupCompleted()) |
395 .WillRepeatedly(Return(false)); | 380 .WillRepeatedly(Return(false)); |
396 error_ = GoogleServiceAuthError::AuthErrorNone(); | 381 error_ = GoogleServiceAuthError::AuthErrorNone(); |
397 // Sync backend is stopped initially, and will start up. | 382 // Sync backend is stopped initially, and will start up. |
398 EXPECT_CALL(*mock_pss_, IsBackendInitialized()).WillRepeatedly(Return(false)); | 383 EXPECT_CALL(*mock_pss_, IsBackendInitialized()).WillRepeatedly(Return(false)); |
399 SetDefaultExpectationsForConfigPage(); | 384 SetDefaultExpectationsForConfigPage(); |
(...skipping 30 matching lines...) Expand all Loading... | |
430 CheckBool(dictionary, "encryptAllDataAllowed", true); | 415 CheckBool(dictionary, "encryptAllDataAllowed", true); |
431 CheckBool(dictionary, "encryptAllData", false); | 416 CheckBool(dictionary, "encryptAllData", false); |
432 CheckBool(dictionary, "usePassphrase", false); | 417 CheckBool(dictionary, "usePassphrase", false); |
433 } | 418 } |
434 | 419 |
435 // Verifies the case where the user cancels after the sync backend has | 420 // Verifies the case where the user cancels after the sync backend has |
436 // initialized (meaning it already transitioned from the spinner to a proper | 421 // initialized (meaning it already transitioned from the spinner to a proper |
437 // configuration page, tested by | 422 // configuration page, tested by |
438 // DisplayConfigureWithBackendDisabledAndSigninSuccess), but before the user | 423 // DisplayConfigureWithBackendDisabledAndSigninSuccess), but before the user |
439 // before the user has continued on. | 424 // before the user has continued on. |
440 TEST_F(SyncHandlerTest, | 425 TEST_F(PeopleHandlerTest, |
441 DisplayConfigureWithBackendDisabledAndCancelAfterSigninSuccess) { | 426 DisplayConfigureWithBackendDisabledAndCancelAfterSigninSuccess) { |
442 EXPECT_CALL(*mock_pss_, CanSyncStart()).WillRepeatedly(Return(true)); | 427 EXPECT_CALL(*mock_pss_, CanSyncStart()).WillRepeatedly(Return(true)); |
443 EXPECT_CALL(*mock_pss_, IsOAuthRefreshTokenAvailable()) | 428 EXPECT_CALL(*mock_pss_, IsOAuthRefreshTokenAvailable()) |
444 .WillRepeatedly(Return(true)); | 429 .WillRepeatedly(Return(true)); |
445 EXPECT_CALL(*mock_pss_, HasSyncSetupCompleted()) | 430 EXPECT_CALL(*mock_pss_, HasSyncSetupCompleted()) |
446 .WillRepeatedly(Return(false)); | 431 .WillRepeatedly(Return(false)); |
447 error_ = GoogleServiceAuthError::AuthErrorNone(); | 432 error_ = GoogleServiceAuthError::AuthErrorNone(); |
448 EXPECT_CALL(*mock_pss_, IsBackendInitialized()) | 433 EXPECT_CALL(*mock_pss_, IsBackendInitialized()) |
449 .WillOnce(Return(false)) | 434 .WillOnce(Return(false)) |
450 .WillRepeatedly(Return(true)); | 435 .WillRepeatedly(Return(true)); |
451 SetDefaultExpectationsForConfigPage(); | 436 SetDefaultExpectationsForConfigPage(); |
452 handler_->OpenSyncSetup(nullptr); | 437 handler_->OpenSyncSetup(nullptr); |
453 | 438 |
454 // It's important to tell sync the user cancelled the setup flow before we | 439 // It's important to tell sync the user cancelled the setup flow before we |
455 // tell it we're through with the setup progress. | 440 // tell it we're through with the setup progress. |
456 testing::InSequence seq; | 441 testing::InSequence seq; |
457 EXPECT_CALL(*mock_pss_, RequestStop(ProfileSyncService::CLEAR_DATA)); | 442 EXPECT_CALL(*mock_pss_, RequestStop(ProfileSyncService::CLEAR_DATA)); |
458 EXPECT_CALL(*mock_pss_, SetSetupInProgress(false)); | 443 EXPECT_CALL(*mock_pss_, SetSetupInProgress(false)); |
459 | 444 |
460 handler_->CloseSyncSetup(); | 445 handler_->CloseSyncSetup(); |
461 EXPECT_EQ(NULL, | 446 EXPECT_EQ(NULL, LoginUIServiceFactory::GetForProfile(profile_.get()) |
462 LoginUIServiceFactory::GetForProfile( | 447 ->current_login_ui()); |
463 profile_.get())->current_login_ui()); | |
464 } | 448 } |
465 | 449 |
466 TEST_F(SyncHandlerTest, | 450 TEST_F(PeopleHandlerTest, DisplayConfigureWithBackendDisabledAndSigninFailed) { |
467 DisplayConfigureWithBackendDisabledAndSigninFailed) { | |
468 EXPECT_CALL(*mock_pss_, CanSyncStart()).WillRepeatedly(Return(true)); | 451 EXPECT_CALL(*mock_pss_, CanSyncStart()).WillRepeatedly(Return(true)); |
469 EXPECT_CALL(*mock_pss_, IsOAuthRefreshTokenAvailable()) | 452 EXPECT_CALL(*mock_pss_, IsOAuthRefreshTokenAvailable()) |
470 .WillRepeatedly(Return(true)); | 453 .WillRepeatedly(Return(true)); |
471 EXPECT_CALL(*mock_pss_, HasSyncSetupCompleted()) | 454 EXPECT_CALL(*mock_pss_, HasSyncSetupCompleted()) |
472 .WillRepeatedly(Return(false)); | 455 .WillRepeatedly(Return(false)); |
473 error_ = GoogleServiceAuthError::AuthErrorNone(); | 456 error_ = GoogleServiceAuthError::AuthErrorNone(); |
474 EXPECT_CALL(*mock_pss_, IsBackendInitialized()).WillRepeatedly(Return(false)); | 457 EXPECT_CALL(*mock_pss_, IsBackendInitialized()).WillRepeatedly(Return(false)); |
475 | 458 |
476 handler_->OpenSyncSetup(nullptr); | 459 handler_->OpenSyncSetup(nullptr); |
477 const content::TestWebUI::CallData& data = *web_ui_.call_data()[0]; | 460 const content::TestWebUI::CallData& data = *web_ui_.call_data()[0]; |
478 EXPECT_EQ("settings.SyncPrivateApi.showSyncSetupPage", data.function_name()); | 461 EXPECT_EQ("settings.SyncPrivateApi.showSyncSetupPage", data.function_name()); |
479 std::string page; | 462 std::string page; |
480 ASSERT_TRUE(data.arg1()->GetAsString(&page)); | 463 ASSERT_TRUE(data.arg1()->GetAsString(&page)); |
481 EXPECT_EQ(page, "spinner"); | 464 EXPECT_EQ(page, "spinner"); |
482 Mock::VerifyAndClearExpectations(mock_pss_); | 465 Mock::VerifyAndClearExpectations(mock_pss_); |
483 error_ = GoogleServiceAuthError( | 466 error_ = |
484 GoogleServiceAuthError::INVALID_GAIA_CREDENTIALS); | 467 GoogleServiceAuthError(GoogleServiceAuthError::INVALID_GAIA_CREDENTIALS); |
485 EXPECT_CALL(*mock_pss_, GetAuthError()).WillRepeatedly(ReturnRef(error_)); | 468 EXPECT_CALL(*mock_pss_, GetAuthError()).WillRepeatedly(ReturnRef(error_)); |
486 NotifySyncListeners(); | 469 NotifySyncListeners(); |
487 | 470 |
488 // On failure, the dialog will be closed. | 471 // On failure, the dialog will be closed. |
489 EXPECT_EQ(NULL, | 472 EXPECT_EQ(NULL, LoginUIServiceFactory::GetForProfile(profile_.get()) |
490 LoginUIServiceFactory::GetForProfile( | 473 ->current_login_ui()); |
491 profile_.get())->current_login_ui()); | |
492 } | 474 } |
493 | 475 |
494 #if !defined(OS_CHROMEOS) | 476 #if !defined(OS_CHROMEOS) |
495 | 477 |
496 class SyncHandlerNonCrosTest : public SyncHandlerTest { | 478 class PeopleHandlerNonCrosTest : public PeopleHandlerTest { |
497 public: | 479 public: |
498 SyncHandlerNonCrosTest() {} | 480 PeopleHandlerNonCrosTest() {} |
499 }; | 481 }; |
500 | 482 |
501 TEST_F(SyncHandlerNonCrosTest, HandleGaiaAuthFailure) { | 483 TEST_F(PeopleHandlerNonCrosTest, HandleGaiaAuthFailure) { |
502 EXPECT_CALL(*mock_pss_, CanSyncStart()).WillRepeatedly(Return(false)); | 484 EXPECT_CALL(*mock_pss_, CanSyncStart()).WillRepeatedly(Return(false)); |
503 EXPECT_CALL(*mock_pss_, IsOAuthRefreshTokenAvailable()) | 485 EXPECT_CALL(*mock_pss_, IsOAuthRefreshTokenAvailable()) |
504 .WillRepeatedly(Return(false)); | 486 .WillRepeatedly(Return(false)); |
505 EXPECT_CALL(*mock_pss_, HasUnrecoverableError()) | 487 EXPECT_CALL(*mock_pss_, HasUnrecoverableError()) |
506 .WillRepeatedly(Return(false)); | 488 .WillRepeatedly(Return(false)); |
507 EXPECT_CALL(*mock_pss_, HasSyncSetupCompleted()) | 489 EXPECT_CALL(*mock_pss_, HasSyncSetupCompleted()) |
508 .WillRepeatedly(Return(false)); | 490 .WillRepeatedly(Return(false)); |
509 // Open the web UI. | 491 // Open the web UI. |
510 handler_->OpenSyncSetup(nullptr); | 492 handler_->OpenSyncSetup(nullptr); |
511 | 493 |
512 ASSERT_FALSE(handler_->is_configuring_sync()); | 494 ASSERT_FALSE(handler_->is_configuring_sync()); |
513 } | 495 } |
514 | 496 |
515 // TODO(kochi): We need equivalent tests for ChromeOS. | 497 // TODO(kochi): We need equivalent tests for ChromeOS. |
516 TEST_F(SyncHandlerNonCrosTest, UnrecoverableErrorInitializingSync) { | 498 TEST_F(PeopleHandlerNonCrosTest, UnrecoverableErrorInitializingSync) { |
517 EXPECT_CALL(*mock_pss_, CanSyncStart()).WillRepeatedly(Return(false)); | 499 EXPECT_CALL(*mock_pss_, CanSyncStart()).WillRepeatedly(Return(false)); |
518 EXPECT_CALL(*mock_pss_, IsOAuthRefreshTokenAvailable()) | 500 EXPECT_CALL(*mock_pss_, IsOAuthRefreshTokenAvailable()) |
519 .WillRepeatedly(Return(false)); | 501 .WillRepeatedly(Return(false)); |
520 EXPECT_CALL(*mock_pss_, HasSyncSetupCompleted()) | 502 EXPECT_CALL(*mock_pss_, HasSyncSetupCompleted()) |
521 .WillRepeatedly(Return(false)); | 503 .WillRepeatedly(Return(false)); |
522 // Open the web UI. | 504 // Open the web UI. |
523 handler_->OpenSyncSetup(nullptr); | 505 handler_->OpenSyncSetup(nullptr); |
524 | 506 |
525 ASSERT_FALSE(handler_->is_configuring_sync()); | 507 ASSERT_FALSE(handler_->is_configuring_sync()); |
526 } | 508 } |
527 | 509 |
528 TEST_F(SyncHandlerNonCrosTest, GaiaErrorInitializingSync) { | 510 TEST_F(PeopleHandlerNonCrosTest, GaiaErrorInitializingSync) { |
529 EXPECT_CALL(*mock_pss_, CanSyncStart()).WillRepeatedly(Return(false)); | 511 EXPECT_CALL(*mock_pss_, CanSyncStart()).WillRepeatedly(Return(false)); |
530 EXPECT_CALL(*mock_pss_, IsOAuthRefreshTokenAvailable()) | 512 EXPECT_CALL(*mock_pss_, IsOAuthRefreshTokenAvailable()) |
531 .WillRepeatedly(Return(false)); | 513 .WillRepeatedly(Return(false)); |
532 EXPECT_CALL(*mock_pss_, HasSyncSetupCompleted()) | 514 EXPECT_CALL(*mock_pss_, HasSyncSetupCompleted()) |
533 .WillRepeatedly(Return(false)); | 515 .WillRepeatedly(Return(false)); |
534 // Open the web UI. | 516 // Open the web UI. |
535 handler_->OpenSyncSetup(nullptr); | 517 handler_->OpenSyncSetup(nullptr); |
536 | 518 |
537 ASSERT_FALSE(handler_->is_configuring_sync()); | 519 ASSERT_FALSE(handler_->is_configuring_sync()); |
538 } | 520 } |
539 | 521 |
540 #endif // #if !defined(OS_CHROMEOS) | 522 #endif // #if !defined(OS_CHROMEOS) |
541 | 523 |
542 TEST_F(SyncHandlerTest, TestSyncEverything) { | 524 TEST_F(PeopleHandlerTest, TestSyncEverything) { |
543 std::string args = GetConfiguration( | 525 std::string args = GetConfiguration(NULL, SYNC_ALL_DATA, GetAllTypes(), |
544 NULL, SYNC_ALL_DATA, GetAllTypes(), std::string(), ENCRYPT_PASSWORDS); | 526 std::string(), ENCRYPT_PASSWORDS); |
545 base::ListValue list_args; | 527 base::ListValue list_args; |
546 list_args.Append(new base::StringValue(args)); | 528 list_args.Append(new base::StringValue(args)); |
547 EXPECT_CALL(*mock_pss_, IsPassphraseRequiredForDecryption()) | 529 EXPECT_CALL(*mock_pss_, IsPassphraseRequiredForDecryption()) |
548 .WillRepeatedly(Return(false)); | 530 .WillRepeatedly(Return(false)); |
549 EXPECT_CALL(*mock_pss_, IsPassphraseRequired()) | 531 EXPECT_CALL(*mock_pss_, IsPassphraseRequired()).WillRepeatedly(Return(false)); |
550 .WillRepeatedly(Return(false)); | |
551 SetupInitializedProfileSyncService(); | 532 SetupInitializedProfileSyncService(); |
552 EXPECT_CALL(*mock_pss_, OnUserChoseDatatypes(true, _)); | 533 EXPECT_CALL(*mock_pss_, OnUserChoseDatatypes(true, _)); |
553 handler_->HandleConfigure(&list_args); | 534 handler_->HandleConfigure(&list_args); |
554 | 535 |
555 // Ensure that we navigated to the "done" state since we don't need a | 536 // Ensure that we navigated to the "done" state since we don't need a |
556 // passphrase. | 537 // passphrase. |
557 ExpectDone(); | 538 ExpectDone(); |
558 } | 539 } |
559 | 540 |
560 TEST_F(SyncHandlerTest, TestSyncNothing) { | 541 TEST_F(PeopleHandlerTest, TestSyncNothing) { |
561 std::string args = GetConfiguration( | 542 std::string args = GetConfiguration(NULL, SYNC_NOTHING, GetAllTypes(), |
562 NULL, SYNC_NOTHING, GetAllTypes(), std::string(), ENCRYPT_PASSWORDS); | 543 std::string(), ENCRYPT_PASSWORDS); |
563 base::ListValue list_args; | 544 base::ListValue list_args; |
564 list_args.Append(new base::StringValue(args)); | 545 list_args.Append(new base::StringValue(args)); |
565 EXPECT_CALL(*mock_pss_, RequestStop(ProfileSyncService::CLEAR_DATA)); | 546 EXPECT_CALL(*mock_pss_, RequestStop(ProfileSyncService::CLEAR_DATA)); |
566 SetupInitializedProfileSyncService(); | 547 SetupInitializedProfileSyncService(); |
567 handler_->HandleConfigure(&list_args); | 548 handler_->HandleConfigure(&list_args); |
568 | 549 |
569 // We expect a call to settings.SyncPrivateApi.showSyncSetupPage. | 550 // We expect a call to settings.SyncPrivateApi.showSyncSetupPage. |
570 ASSERT_EQ(1U, web_ui_.call_data().size()); | 551 ASSERT_EQ(1U, web_ui_.call_data().size()); |
571 const content::TestWebUI::CallData& data = *web_ui_.call_data()[0]; | 552 const content::TestWebUI::CallData& data = *web_ui_.call_data()[0]; |
572 EXPECT_EQ("settings.SyncPrivateApi.showSyncSetupPage", data.function_name()); | 553 EXPECT_EQ("settings.SyncPrivateApi.showSyncSetupPage", data.function_name()); |
573 } | 554 } |
574 | 555 |
575 TEST_F(SyncHandlerTest, TurnOnEncryptAll) { | 556 TEST_F(PeopleHandlerTest, TurnOnEncryptAll) { |
576 std::string args = GetConfiguration( | 557 std::string args = GetConfiguration(NULL, SYNC_ALL_DATA, GetAllTypes(), |
577 NULL, SYNC_ALL_DATA, GetAllTypes(), std::string(), ENCRYPT_ALL_DATA); | 558 std::string(), ENCRYPT_ALL_DATA); |
578 base::ListValue list_args; | 559 base::ListValue list_args; |
579 list_args.Append(new base::StringValue(args)); | 560 list_args.Append(new base::StringValue(args)); |
580 EXPECT_CALL(*mock_pss_, IsPassphraseRequiredForDecryption()) | 561 EXPECT_CALL(*mock_pss_, IsPassphraseRequiredForDecryption()) |
581 .WillRepeatedly(Return(false)); | 562 .WillRepeatedly(Return(false)); |
582 EXPECT_CALL(*mock_pss_, IsPassphraseRequired()) | 563 EXPECT_CALL(*mock_pss_, IsPassphraseRequired()).WillRepeatedly(Return(false)); |
583 .WillRepeatedly(Return(false)); | |
584 EXPECT_CALL(*mock_pss_, IsEncryptEverythingAllowed()) | 564 EXPECT_CALL(*mock_pss_, IsEncryptEverythingAllowed()) |
585 .WillRepeatedly(Return(true)); | 565 .WillRepeatedly(Return(true)); |
586 SetupInitializedProfileSyncService(); | 566 SetupInitializedProfileSyncService(); |
587 EXPECT_CALL(*mock_pss_, EnableEncryptEverything()); | 567 EXPECT_CALL(*mock_pss_, EnableEncryptEverything()); |
588 EXPECT_CALL(*mock_pss_, OnUserChoseDatatypes(true, _)); | 568 EXPECT_CALL(*mock_pss_, OnUserChoseDatatypes(true, _)); |
589 handler_->HandleConfigure(&list_args); | 569 handler_->HandleConfigure(&list_args); |
590 | 570 |
591 // Ensure that we navigated to the "done" state since we don't need a | 571 // Ensure that we navigated to the "done" state since we don't need a |
592 // passphrase. | 572 // passphrase. |
593 ExpectDone(); | 573 ExpectDone(); |
594 } | 574 } |
595 | 575 |
596 TEST_F(SyncHandlerTest, TestPassphraseStillRequired) { | 576 TEST_F(PeopleHandlerTest, TestPassphraseStillRequired) { |
597 std::string args = GetConfiguration( | 577 std::string args = GetConfiguration(NULL, SYNC_ALL_DATA, GetAllTypes(), |
598 NULL, SYNC_ALL_DATA, GetAllTypes(), std::string(), ENCRYPT_PASSWORDS); | 578 std::string(), ENCRYPT_PASSWORDS); |
599 base::ListValue list_args; | 579 base::ListValue list_args; |
600 list_args.Append(new base::StringValue(args)); | 580 list_args.Append(new base::StringValue(args)); |
601 EXPECT_CALL(*mock_pss_, IsPassphraseRequiredForDecryption()) | 581 EXPECT_CALL(*mock_pss_, IsPassphraseRequiredForDecryption()) |
602 .WillRepeatedly(Return(true)); | 582 .WillRepeatedly(Return(true)); |
603 EXPECT_CALL(*mock_pss_, IsPassphraseRequired()) | 583 EXPECT_CALL(*mock_pss_, IsPassphraseRequired()).WillRepeatedly(Return(true)); |
604 .WillRepeatedly(Return(true)); | |
605 EXPECT_CALL(*mock_pss_, IsUsingSecondaryPassphrase()) | 584 EXPECT_CALL(*mock_pss_, IsUsingSecondaryPassphrase()) |
606 .WillRepeatedly(Return(false)); | 585 .WillRepeatedly(Return(false)); |
607 SetupInitializedProfileSyncService(); | 586 SetupInitializedProfileSyncService(); |
608 EXPECT_CALL(*mock_pss_, OnUserChoseDatatypes(_, _)); | 587 EXPECT_CALL(*mock_pss_, OnUserChoseDatatypes(_, _)); |
609 SetDefaultExpectationsForConfigPage(); | 588 SetDefaultExpectationsForConfigPage(); |
610 | 589 |
611 // We should navigate back to the configure page since we need a passphrase. | 590 // We should navigate back to the configure page since we need a passphrase. |
612 handler_->HandleConfigure(&list_args); | 591 handler_->HandleConfigure(&list_args); |
613 | 592 |
614 ExpectConfig(); | 593 ExpectConfig(); |
615 } | 594 } |
616 | 595 |
617 TEST_F(SyncHandlerTest, SuccessfullySetPassphrase) { | 596 TEST_F(PeopleHandlerTest, SuccessfullySetPassphrase) { |
618 base::DictionaryValue dict; | 597 base::DictionaryValue dict; |
619 dict.SetBoolean("isGooglePassphrase", true); | 598 dict.SetBoolean("isGooglePassphrase", true); |
620 std::string args = GetConfiguration(&dict, | 599 std::string args = GetConfiguration(&dict, SYNC_ALL_DATA, GetAllTypes(), |
621 SYNC_ALL_DATA, | 600 "gaiaPassphrase", ENCRYPT_PASSWORDS); |
622 GetAllTypes(), | |
623 "gaiaPassphrase", | |
624 ENCRYPT_PASSWORDS); | |
625 base::ListValue list_args; | 601 base::ListValue list_args; |
626 list_args.Append(new base::StringValue(args)); | 602 list_args.Append(new base::StringValue(args)); |
627 // Act as if an encryption passphrase is required the first time, then never | 603 // Act as if an encryption passphrase is required the first time, then never |
628 // again after that. | 604 // again after that. |
629 EXPECT_CALL(*mock_pss_, IsPassphraseRequired()).WillOnce(Return(true)); | 605 EXPECT_CALL(*mock_pss_, IsPassphraseRequired()).WillOnce(Return(true)); |
630 EXPECT_CALL(*mock_pss_, IsPassphraseRequiredForDecryption()) | 606 EXPECT_CALL(*mock_pss_, IsPassphraseRequiredForDecryption()) |
631 .WillRepeatedly(Return(false)); | 607 .WillRepeatedly(Return(false)); |
632 EXPECT_CALL(*mock_pss_, IsUsingSecondaryPassphrase()) | 608 EXPECT_CALL(*mock_pss_, IsUsingSecondaryPassphrase()) |
633 .WillRepeatedly(Return(false)); | 609 .WillRepeatedly(Return(false)); |
634 SetupInitializedProfileSyncService(); | 610 SetupInitializedProfileSyncService(); |
635 EXPECT_CALL(*mock_pss_, OnUserChoseDatatypes(_, _)); | 611 EXPECT_CALL(*mock_pss_, OnUserChoseDatatypes(_, _)); |
636 EXPECT_CALL(*mock_pss_, SetDecryptionPassphrase("gaiaPassphrase")). | 612 EXPECT_CALL(*mock_pss_, SetDecryptionPassphrase("gaiaPassphrase")) |
637 WillOnce(Return(true)); | 613 .WillOnce(Return(true)); |
638 | 614 |
639 handler_->HandleConfigure(&list_args); | 615 handler_->HandleConfigure(&list_args); |
640 // We should navigate to "done" page since we finished configuring. | 616 // We should navigate to "done" page since we finished configuring. |
641 ExpectDone(); | 617 ExpectDone(); |
642 } | 618 } |
643 | 619 |
644 TEST_F(SyncHandlerTest, SelectCustomEncryption) { | 620 TEST_F(PeopleHandlerTest, SelectCustomEncryption) { |
645 base::DictionaryValue dict; | 621 base::DictionaryValue dict; |
646 dict.SetBoolean("isGooglePassphrase", false); | 622 dict.SetBoolean("isGooglePassphrase", false); |
647 std::string args = GetConfiguration(&dict, | 623 std::string args = GetConfiguration(&dict, SYNC_ALL_DATA, GetAllTypes(), |
648 SYNC_ALL_DATA, | 624 "custom_passphrase", ENCRYPT_PASSWORDS); |
649 GetAllTypes(), | |
650 "custom_passphrase", | |
651 ENCRYPT_PASSWORDS); | |
652 base::ListValue list_args; | 625 base::ListValue list_args; |
653 list_args.Append(new base::StringValue(args)); | 626 list_args.Append(new base::StringValue(args)); |
654 EXPECT_CALL(*mock_pss_, IsPassphraseRequiredForDecryption()) | 627 EXPECT_CALL(*mock_pss_, IsPassphraseRequiredForDecryption()) |
655 .WillRepeatedly(Return(false)); | 628 .WillRepeatedly(Return(false)); |
656 EXPECT_CALL(*mock_pss_, IsPassphraseRequired()) | 629 EXPECT_CALL(*mock_pss_, IsPassphraseRequired()).WillRepeatedly(Return(false)); |
657 .WillRepeatedly(Return(false)); | |
658 EXPECT_CALL(*mock_pss_, IsUsingSecondaryPassphrase()) | 630 EXPECT_CALL(*mock_pss_, IsUsingSecondaryPassphrase()) |
659 .WillRepeatedly(Return(false)); | 631 .WillRepeatedly(Return(false)); |
660 SetupInitializedProfileSyncService(); | 632 SetupInitializedProfileSyncService(); |
661 EXPECT_CALL(*mock_pss_, OnUserChoseDatatypes(_, _)); | 633 EXPECT_CALL(*mock_pss_, OnUserChoseDatatypes(_, _)); |
662 EXPECT_CALL(*mock_pss_, | 634 EXPECT_CALL(*mock_pss_, |
663 SetEncryptionPassphrase("custom_passphrase", | 635 SetEncryptionPassphrase("custom_passphrase", |
664 ProfileSyncService::EXPLICIT)); | 636 ProfileSyncService::EXPLICIT)); |
665 | 637 |
666 handler_->HandleConfigure(&list_args); | 638 handler_->HandleConfigure(&list_args); |
667 // We should navigate to "done" page since we finished configuring. | 639 // We should navigate to "done" page since we finished configuring. |
668 ExpectDone(); | 640 ExpectDone(); |
669 } | 641 } |
670 | 642 |
671 TEST_F(SyncHandlerTest, UnsuccessfullySetPassphrase) { | 643 TEST_F(PeopleHandlerTest, UnsuccessfullySetPassphrase) { |
672 base::DictionaryValue dict; | 644 base::DictionaryValue dict; |
673 dict.SetBoolean("isGooglePassphrase", true); | 645 dict.SetBoolean("isGooglePassphrase", true); |
674 std::string args = GetConfiguration(&dict, | 646 std::string args = GetConfiguration(&dict, SYNC_ALL_DATA, GetAllTypes(), |
675 SYNC_ALL_DATA, | 647 "invalid_passphrase", ENCRYPT_PASSWORDS); |
676 GetAllTypes(), | |
677 "invalid_passphrase", | |
678 ENCRYPT_PASSWORDS); | |
679 base::ListValue list_args; | 648 base::ListValue list_args; |
680 list_args.Append(new base::StringValue(args)); | 649 list_args.Append(new base::StringValue(args)); |
681 EXPECT_CALL(*mock_pss_, IsPassphraseRequiredForDecryption()) | 650 EXPECT_CALL(*mock_pss_, IsPassphraseRequiredForDecryption()) |
682 .WillRepeatedly(Return(true)); | 651 .WillRepeatedly(Return(true)); |
683 EXPECT_CALL(*mock_pss_, IsPassphraseRequired()) | 652 EXPECT_CALL(*mock_pss_, IsPassphraseRequired()).WillRepeatedly(Return(true)); |
684 .WillRepeatedly(Return(true)); | |
685 EXPECT_CALL(*mock_pss_, IsUsingSecondaryPassphrase()) | 653 EXPECT_CALL(*mock_pss_, IsUsingSecondaryPassphrase()) |
686 .WillRepeatedly(Return(false)); | 654 .WillRepeatedly(Return(false)); |
687 SetupInitializedProfileSyncService(); | 655 SetupInitializedProfileSyncService(); |
688 EXPECT_CALL(*mock_pss_, OnUserChoseDatatypes(_, _)); | 656 EXPECT_CALL(*mock_pss_, OnUserChoseDatatypes(_, _)); |
689 EXPECT_CALL(*mock_pss_, SetDecryptionPassphrase("invalid_passphrase")). | 657 EXPECT_CALL(*mock_pss_, SetDecryptionPassphrase("invalid_passphrase")) |
690 WillOnce(Return(false)); | 658 .WillOnce(Return(false)); |
691 | 659 |
692 SetDefaultExpectationsForConfigPage(); | 660 SetDefaultExpectationsForConfigPage(); |
693 // We should navigate back to the configure page since we need a passphrase. | 661 // We should navigate back to the configure page since we need a passphrase. |
694 handler_->HandleConfigure(&list_args); | 662 handler_->HandleConfigure(&list_args); |
695 | 663 |
696 ExpectConfig(); | 664 ExpectConfig(); |
697 | 665 |
698 // Make sure we display an error message to the user due to the failed | 666 // Make sure we display an error message to the user due to the failed |
699 // passphrase. | 667 // passphrase. |
700 const content::TestWebUI::CallData& data = *web_ui_.call_data()[0]; | 668 const content::TestWebUI::CallData& data = *web_ui_.call_data()[0]; |
701 const base::DictionaryValue* dictionary = nullptr; | 669 const base::DictionaryValue* dictionary = nullptr; |
702 ASSERT_TRUE(data.arg2()->GetAsDictionary(&dictionary)); | 670 ASSERT_TRUE(data.arg2()->GetAsDictionary(&dictionary)); |
703 CheckBool(dictionary, "passphraseFailed", true); | 671 CheckBool(dictionary, "passphraseFailed", true); |
704 } | 672 } |
705 | 673 |
706 // Walks through each user selectable type, and tries to sync just that single | 674 // Walks through each user selectable type, and tries to sync just that single |
707 // data type. | 675 // data type. |
708 TEST_F(SyncHandlerTest, TestSyncIndividualTypes) { | 676 TEST_F(PeopleHandlerTest, TestSyncIndividualTypes) { |
709 syncer::ModelTypeSet user_selectable_types = GetAllTypes(); | 677 syncer::ModelTypeSet user_selectable_types = GetAllTypes(); |
710 syncer::ModelTypeSet::Iterator it; | 678 syncer::ModelTypeSet::Iterator it; |
711 for (it = user_selectable_types.First(); it.Good(); it.Inc()) { | 679 for (it = user_selectable_types.First(); it.Good(); it.Inc()) { |
712 syncer::ModelTypeSet type_to_set; | 680 syncer::ModelTypeSet type_to_set; |
713 type_to_set.Put(it.Get()); | 681 type_to_set.Put(it.Get()); |
714 std::string args = GetConfiguration(NULL, | 682 std::string args = GetConfiguration(NULL, CHOOSE_WHAT_TO_SYNC, type_to_set, |
715 CHOOSE_WHAT_TO_SYNC, | 683 std::string(), ENCRYPT_PASSWORDS); |
716 type_to_set, | |
717 std::string(), | |
718 ENCRYPT_PASSWORDS); | |
719 base::ListValue list_args; | 684 base::ListValue list_args; |
720 list_args.Append(new base::StringValue(args)); | 685 list_args.Append(new base::StringValue(args)); |
721 EXPECT_CALL(*mock_pss_, IsPassphraseRequiredForDecryption()) | 686 EXPECT_CALL(*mock_pss_, IsPassphraseRequiredForDecryption()) |
722 .WillRepeatedly(Return(false)); | 687 .WillRepeatedly(Return(false)); |
723 EXPECT_CALL(*mock_pss_, IsPassphraseRequired()) | 688 EXPECT_CALL(*mock_pss_, IsPassphraseRequired()) |
724 .WillRepeatedly(Return(false)); | 689 .WillRepeatedly(Return(false)); |
725 SetupInitializedProfileSyncService(); | 690 SetupInitializedProfileSyncService(); |
726 EXPECT_CALL(*mock_pss_, | 691 EXPECT_CALL(*mock_pss_, |
727 OnUserChoseDatatypes(false, ModelTypeSetMatches(type_to_set))); | 692 OnUserChoseDatatypes(false, ModelTypeSetMatches(type_to_set))); |
728 handler_->HandleConfigure(&list_args); | 693 handler_->HandleConfigure(&list_args); |
729 | 694 |
730 ExpectDone(); | 695 ExpectDone(); |
731 Mock::VerifyAndClearExpectations(mock_pss_); | 696 Mock::VerifyAndClearExpectations(mock_pss_); |
732 web_ui_.ClearTrackedCalls(); | 697 web_ui_.ClearTrackedCalls(); |
733 } | 698 } |
734 } | 699 } |
735 | 700 |
736 TEST_F(SyncHandlerTest, TestSyncAllManually) { | 701 TEST_F(PeopleHandlerTest, TestSyncAllManually) { |
737 std::string args = GetConfiguration(NULL, | 702 std::string args = GetConfiguration(NULL, CHOOSE_WHAT_TO_SYNC, GetAllTypes(), |
738 CHOOSE_WHAT_TO_SYNC, | 703 std::string(), ENCRYPT_PASSWORDS); |
739 GetAllTypes(), | |
740 std::string(), | |
741 ENCRYPT_PASSWORDS); | |
742 base::ListValue list_args; | 704 base::ListValue list_args; |
743 list_args.Append(new base::StringValue(args)); | 705 list_args.Append(new base::StringValue(args)); |
744 EXPECT_CALL(*mock_pss_, IsPassphraseRequiredForDecryption()) | 706 EXPECT_CALL(*mock_pss_, IsPassphraseRequiredForDecryption()) |
745 .WillRepeatedly(Return(false)); | 707 .WillRepeatedly(Return(false)); |
746 EXPECT_CALL(*mock_pss_, IsPassphraseRequired()) | 708 EXPECT_CALL(*mock_pss_, IsPassphraseRequired()).WillRepeatedly(Return(false)); |
747 .WillRepeatedly(Return(false)); | |
748 SetupInitializedProfileSyncService(); | 709 SetupInitializedProfileSyncService(); |
749 EXPECT_CALL(*mock_pss_, | 710 EXPECT_CALL(*mock_pss_, |
750 OnUserChoseDatatypes(false, ModelTypeSetMatches(GetAllTypes()))); | 711 OnUserChoseDatatypes(false, ModelTypeSetMatches(GetAllTypes()))); |
751 handler_->HandleConfigure(&list_args); | 712 handler_->HandleConfigure(&list_args); |
752 | 713 |
753 ExpectDone(); | 714 ExpectDone(); |
754 } | 715 } |
755 | 716 |
756 TEST_F(SyncHandlerTest, ShowSyncSetup) { | 717 TEST_F(PeopleHandlerTest, ShowSyncSetup) { |
757 EXPECT_CALL(*mock_pss_, IsPassphraseRequired()) | 718 EXPECT_CALL(*mock_pss_, IsPassphraseRequired()).WillRepeatedly(Return(false)); |
758 .WillRepeatedly(Return(false)); | |
759 EXPECT_CALL(*mock_pss_, IsUsingSecondaryPassphrase()) | 719 EXPECT_CALL(*mock_pss_, IsUsingSecondaryPassphrase()) |
760 .WillRepeatedly(Return(false)); | 720 .WillRepeatedly(Return(false)); |
761 SetupInitializedProfileSyncService(); | 721 SetupInitializedProfileSyncService(); |
762 // This should display the sync setup dialog (not login). | 722 // This should display the sync setup dialog (not login). |
763 SetDefaultExpectationsForConfigPage(); | 723 SetDefaultExpectationsForConfigPage(); |
764 handler_->OpenSyncSetup(nullptr); | 724 handler_->OpenSyncSetup(nullptr); |
765 | 725 |
766 ExpectConfig(); | 726 ExpectConfig(); |
767 } | 727 } |
768 | 728 |
769 // We do not display signin on chromeos in the case of auth error. | 729 // We do not display signin on chromeos in the case of auth error. |
770 TEST_F(SyncHandlerTest, ShowSigninOnAuthError) { | 730 TEST_F(PeopleHandlerTest, ShowSigninOnAuthError) { |
771 // Initialize the system to a signed in state, but with an auth error. | 731 // Initialize the system to a signed in state, but with an auth error. |
772 error_ = GoogleServiceAuthError( | 732 error_ = |
773 GoogleServiceAuthError::INVALID_GAIA_CREDENTIALS); | 733 GoogleServiceAuthError(GoogleServiceAuthError::INVALID_GAIA_CREDENTIALS); |
774 | 734 |
775 SetupInitializedProfileSyncService(); | 735 SetupInitializedProfileSyncService(); |
776 mock_signin_->SetAuthenticatedAccountInfo(kTestUser, kTestUser); | 736 mock_signin_->SetAuthenticatedAccountInfo(kTestUser, kTestUser); |
777 FakeAuthStatusProvider provider( | 737 FakeAuthStatusProvider provider( |
778 SigninErrorControllerFactory::GetForProfile(profile_.get())); | 738 SigninErrorControllerFactory::GetForProfile(profile_.get())); |
779 provider.SetAuthError(kTestUser, error_); | 739 provider.SetAuthError(kTestUser, error_); |
780 EXPECT_CALL(*mock_pss_, CanSyncStart()).WillRepeatedly(Return(true)); | 740 EXPECT_CALL(*mock_pss_, CanSyncStart()).WillRepeatedly(Return(true)); |
781 EXPECT_CALL(*mock_pss_, IsOAuthRefreshTokenAvailable()) | 741 EXPECT_CALL(*mock_pss_, IsOAuthRefreshTokenAvailable()) |
782 .WillRepeatedly(Return(true)); | 742 .WillRepeatedly(Return(true)); |
783 EXPECT_CALL(*mock_pss_, IsPassphraseRequired()) | 743 EXPECT_CALL(*mock_pss_, IsPassphraseRequired()).WillRepeatedly(Return(false)); |
784 .WillRepeatedly(Return(false)); | |
785 EXPECT_CALL(*mock_pss_, IsUsingSecondaryPassphrase()) | 744 EXPECT_CALL(*mock_pss_, IsUsingSecondaryPassphrase()) |
786 .WillRepeatedly(Return(false)); | 745 .WillRepeatedly(Return(false)); |
787 EXPECT_CALL(*mock_pss_, IsBackendInitialized()).WillRepeatedly(Return(false)); | 746 EXPECT_CALL(*mock_pss_, IsBackendInitialized()).WillRepeatedly(Return(false)); |
788 | 747 |
789 #if defined(OS_CHROMEOS) | 748 #if defined(OS_CHROMEOS) |
790 // On ChromeOS, auth errors are ignored - instead we just try to start the | 749 // On ChromeOS, auth errors are ignored - instead we just try to start the |
791 // sync backend (which will fail due to the auth error). This should only | 750 // sync backend (which will fail due to the auth error). This should only |
792 // happen if the user manually navigates to chrome://settings/syncSetup - | 751 // happen if the user manually navigates to chrome://settings/syncSetup - |
793 // clicking on the button in the UI will sign the user out rather than | 752 // clicking on the button in the UI will sign the user out rather than |
794 // displaying a spinner. Should be no visible UI on ChromeOS in this case. | 753 // displaying a spinner. Should be no visible UI on ChromeOS in this case. |
795 EXPECT_EQ(NULL, LoginUIServiceFactory::GetForProfile( | 754 EXPECT_EQ(NULL, LoginUIServiceFactory::GetForProfile(profile_.get()) |
796 profile_.get())->current_login_ui()); | 755 ->current_login_ui()); |
797 #else | 756 #else |
798 | 757 |
799 // On ChromeOS, this should display the spinner while we try to startup the | 758 // On ChromeOS, this should display the spinner while we try to startup the |
800 // sync backend, and on desktop this displays the login dialog. | 759 // sync backend, and on desktop this displays the login dialog. |
801 handler_->OpenSyncSetup(nullptr); | 760 handler_->OpenSyncSetup(nullptr); |
802 | 761 |
803 // Sync setup is closed when re-auth is in progress. | 762 // Sync setup is closed when re-auth is in progress. |
804 EXPECT_EQ(NULL, | 763 EXPECT_EQ(NULL, LoginUIServiceFactory::GetForProfile(profile_.get()) |
805 LoginUIServiceFactory::GetForProfile( | 764 ->current_login_ui()); |
806 profile_.get())->current_login_ui()); | |
807 | 765 |
808 ASSERT_FALSE(handler_->is_configuring_sync()); | 766 ASSERT_FALSE(handler_->is_configuring_sync()); |
809 #endif | 767 #endif |
810 } | 768 } |
811 | 769 |
812 TEST_F(SyncHandlerTest, ShowSetupSyncEverything) { | 770 TEST_F(PeopleHandlerTest, ShowSetupSyncEverything) { |
813 EXPECT_CALL(*mock_pss_, IsPassphraseRequired()) | 771 EXPECT_CALL(*mock_pss_, IsPassphraseRequired()).WillRepeatedly(Return(false)); |
814 .WillRepeatedly(Return(false)); | |
815 EXPECT_CALL(*mock_pss_, IsUsingSecondaryPassphrase()) | 772 EXPECT_CALL(*mock_pss_, IsUsingSecondaryPassphrase()) |
816 .WillRepeatedly(Return(false)); | 773 .WillRepeatedly(Return(false)); |
817 SetupInitializedProfileSyncService(); | 774 SetupInitializedProfileSyncService(); |
818 SetDefaultExpectationsForConfigPage(); | 775 SetDefaultExpectationsForConfigPage(); |
819 // This should display the sync setup dialog (not login). | 776 // This should display the sync setup dialog (not login). |
820 handler_->OpenSyncSetup(nullptr); | 777 handler_->OpenSyncSetup(nullptr); |
821 | 778 |
822 ExpectConfig(); | 779 ExpectConfig(); |
823 const content::TestWebUI::CallData& data = *web_ui_.call_data()[0]; | 780 const content::TestWebUI::CallData& data = *web_ui_.call_data()[0]; |
824 const base::DictionaryValue* dictionary = nullptr; | 781 const base::DictionaryValue* dictionary = nullptr; |
825 ASSERT_TRUE(data.arg2()->GetAsDictionary(&dictionary)); | 782 ASSERT_TRUE(data.arg2()->GetAsDictionary(&dictionary)); |
826 CheckBool(dictionary, "syncAllDataTypes", true); | 783 CheckBool(dictionary, "syncAllDataTypes", true); |
827 CheckBool(dictionary, "appsRegistered", true); | 784 CheckBool(dictionary, "appsRegistered", true); |
828 CheckBool(dictionary, "autofillRegistered", true); | 785 CheckBool(dictionary, "autofillRegistered", true); |
829 CheckBool(dictionary, "bookmarksRegistered", true); | 786 CheckBool(dictionary, "bookmarksRegistered", true); |
830 CheckBool(dictionary, "extensionsRegistered", true); | 787 CheckBool(dictionary, "extensionsRegistered", true); |
831 CheckBool(dictionary, "passwordsRegistered", true); | 788 CheckBool(dictionary, "passwordsRegistered", true); |
832 CheckBool(dictionary, "preferencesRegistered", true); | 789 CheckBool(dictionary, "preferencesRegistered", true); |
833 CheckBool(dictionary, "wifiCredentialsRegistered", true); | 790 CheckBool(dictionary, "wifiCredentialsRegistered", true); |
834 CheckBool(dictionary, "tabsRegistered", true); | 791 CheckBool(dictionary, "tabsRegistered", true); |
835 CheckBool(dictionary, "themesRegistered", true); | 792 CheckBool(dictionary, "themesRegistered", true); |
836 CheckBool(dictionary, "typedUrlsRegistered", true); | 793 CheckBool(dictionary, "typedUrlsRegistered", true); |
837 CheckBool(dictionary, "showPassphrase", false); | 794 CheckBool(dictionary, "showPassphrase", false); |
838 CheckBool(dictionary, "usePassphrase", false); | 795 CheckBool(dictionary, "usePassphrase", false); |
839 CheckBool(dictionary, "passphraseFailed", false); | 796 CheckBool(dictionary, "passphraseFailed", false); |
840 CheckBool(dictionary, "encryptAllData", false); | 797 CheckBool(dictionary, "encryptAllData", false); |
841 CheckConfigDataTypeArguments(dictionary, SYNC_ALL_DATA, GetAllTypes()); | 798 CheckConfigDataTypeArguments(dictionary, SYNC_ALL_DATA, GetAllTypes()); |
842 } | 799 } |
843 | 800 |
844 TEST_F(SyncHandlerTest, ShowSetupManuallySyncAll) { | 801 TEST_F(PeopleHandlerTest, ShowSetupManuallySyncAll) { |
845 EXPECT_CALL(*mock_pss_, IsPassphraseRequired()) | 802 EXPECT_CALL(*mock_pss_, IsPassphraseRequired()).WillRepeatedly(Return(false)); |
846 .WillRepeatedly(Return(false)); | |
847 EXPECT_CALL(*mock_pss_, IsUsingSecondaryPassphrase()) | 803 EXPECT_CALL(*mock_pss_, IsUsingSecondaryPassphrase()) |
848 .WillRepeatedly(Return(false)); | 804 .WillRepeatedly(Return(false)); |
849 SetupInitializedProfileSyncService(); | 805 SetupInitializedProfileSyncService(); |
850 sync_driver::SyncPrefs sync_prefs(profile_->GetPrefs()); | 806 sync_driver::SyncPrefs sync_prefs(profile_->GetPrefs()); |
851 sync_prefs.SetKeepEverythingSynced(false); | 807 sync_prefs.SetKeepEverythingSynced(false); |
852 SetDefaultExpectationsForConfigPage(); | 808 SetDefaultExpectationsForConfigPage(); |
853 // This should display the sync setup dialog (not login). | 809 // This should display the sync setup dialog (not login). |
854 handler_->OpenSyncSetup(nullptr); | 810 handler_->OpenSyncSetup(nullptr); |
855 | 811 |
856 ExpectConfig(); | 812 ExpectConfig(); |
857 const content::TestWebUI::CallData& data = *web_ui_.call_data()[0]; | 813 const content::TestWebUI::CallData& data = *web_ui_.call_data()[0]; |
858 const base::DictionaryValue* dictionary = nullptr; | 814 const base::DictionaryValue* dictionary = nullptr; |
859 ASSERT_TRUE(data.arg2()->GetAsDictionary(&dictionary)); | 815 ASSERT_TRUE(data.arg2()->GetAsDictionary(&dictionary)); |
860 CheckConfigDataTypeArguments(dictionary, CHOOSE_WHAT_TO_SYNC, GetAllTypes()); | 816 CheckConfigDataTypeArguments(dictionary, CHOOSE_WHAT_TO_SYNC, GetAllTypes()); |
861 } | 817 } |
862 | 818 |
863 TEST_F(SyncHandlerTest, ShowSetupSyncForAllTypesIndividually) { | 819 TEST_F(PeopleHandlerTest, ShowSetupSyncForAllTypesIndividually) { |
864 syncer::ModelTypeSet user_selectable_types = GetAllTypes(); | 820 syncer::ModelTypeSet user_selectable_types = GetAllTypes(); |
865 syncer::ModelTypeSet::Iterator it; | 821 syncer::ModelTypeSet::Iterator it; |
866 for (it = user_selectable_types.First(); it.Good(); it.Inc()) { | 822 for (it = user_selectable_types.First(); it.Good(); it.Inc()) { |
867 EXPECT_CALL(*mock_pss_, IsPassphraseRequired()) | 823 EXPECT_CALL(*mock_pss_, IsPassphraseRequired()) |
868 .WillRepeatedly(Return(false)); | 824 .WillRepeatedly(Return(false)); |
869 EXPECT_CALL(*mock_pss_, IsUsingSecondaryPassphrase()) | 825 EXPECT_CALL(*mock_pss_, IsUsingSecondaryPassphrase()) |
870 .WillRepeatedly(Return(false)); | 826 .WillRepeatedly(Return(false)); |
871 SetupInitializedProfileSyncService(); | 827 SetupInitializedProfileSyncService(); |
872 sync_driver::SyncPrefs sync_prefs(profile_->GetPrefs()); | 828 sync_driver::SyncPrefs sync_prefs(profile_->GetPrefs()); |
873 sync_prefs.SetKeepEverythingSynced(false); | 829 sync_prefs.SetKeepEverythingSynced(false); |
874 SetDefaultExpectationsForConfigPage(); | 830 SetDefaultExpectationsForConfigPage(); |
875 syncer::ModelTypeSet types; | 831 syncer::ModelTypeSet types; |
876 types.Put(it.Get()); | 832 types.Put(it.Get()); |
877 EXPECT_CALL(*mock_pss_, GetPreferredDataTypes()). | 833 EXPECT_CALL(*mock_pss_, GetPreferredDataTypes()) |
878 WillRepeatedly(Return(types)); | 834 .WillRepeatedly(Return(types)); |
879 | 835 |
880 // This should display the sync setup dialog (not login). | 836 // This should display the sync setup dialog (not login). |
881 handler_->OpenSyncSetup(nullptr); | 837 handler_->OpenSyncSetup(nullptr); |
882 | 838 |
883 ExpectConfig(); | 839 ExpectConfig(); |
884 // Close the config overlay. | 840 // Close the config overlay. |
885 LoginUIServiceFactory::GetForProfile(profile_.get())->LoginUIClosed( | 841 LoginUIServiceFactory::GetForProfile(profile_.get()) |
886 handler_.get()); | 842 ->LoginUIClosed(handler_.get()); |
887 const content::TestWebUI::CallData& data = *web_ui_.call_data()[0]; | 843 const content::TestWebUI::CallData& data = *web_ui_.call_data()[0]; |
888 const base::DictionaryValue* dictionary = nullptr; | 844 const base::DictionaryValue* dictionary = nullptr; |
889 ASSERT_TRUE(data.arg2()->GetAsDictionary(&dictionary)); | 845 ASSERT_TRUE(data.arg2()->GetAsDictionary(&dictionary)); |
890 CheckConfigDataTypeArguments(dictionary, CHOOSE_WHAT_TO_SYNC, types); | 846 CheckConfigDataTypeArguments(dictionary, CHOOSE_WHAT_TO_SYNC, types); |
891 Mock::VerifyAndClearExpectations(mock_pss_); | 847 Mock::VerifyAndClearExpectations(mock_pss_); |
892 // Clean up so we can loop back to display the dialog again. | 848 // Clean up so we can loop back to display the dialog again. |
893 web_ui_.ClearTrackedCalls(); | 849 web_ui_.ClearTrackedCalls(); |
894 } | 850 } |
895 } | 851 } |
896 | 852 |
897 TEST_F(SyncHandlerTest, ShowSetupGaiaPassphraseRequired) { | 853 TEST_F(PeopleHandlerTest, ShowSetupGaiaPassphraseRequired) { |
898 EXPECT_CALL(*mock_pss_, IsPassphraseRequired()) | 854 EXPECT_CALL(*mock_pss_, IsPassphraseRequired()).WillRepeatedly(Return(true)); |
899 .WillRepeatedly(Return(true)); | |
900 EXPECT_CALL(*mock_pss_, IsUsingSecondaryPassphrase()) | 855 EXPECT_CALL(*mock_pss_, IsUsingSecondaryPassphrase()) |
901 .WillRepeatedly(Return(false)); | 856 .WillRepeatedly(Return(false)); |
902 SetupInitializedProfileSyncService(); | 857 SetupInitializedProfileSyncService(); |
903 SetDefaultExpectationsForConfigPage(); | 858 SetDefaultExpectationsForConfigPage(); |
904 | 859 |
905 // This should display the sync setup dialog (not login). | 860 // This should display the sync setup dialog (not login). |
906 handler_->OpenSyncSetup(nullptr); | 861 handler_->OpenSyncSetup(nullptr); |
907 | 862 |
908 ExpectConfig(); | 863 ExpectConfig(); |
909 const content::TestWebUI::CallData& data = *web_ui_.call_data()[0]; | 864 const content::TestWebUI::CallData& data = *web_ui_.call_data()[0]; |
910 const base::DictionaryValue* dictionary = nullptr; | 865 const base::DictionaryValue* dictionary = nullptr; |
911 ASSERT_TRUE(data.arg2()->GetAsDictionary(&dictionary)); | 866 ASSERT_TRUE(data.arg2()->GetAsDictionary(&dictionary)); |
912 CheckBool(dictionary, "showPassphrase", true); | 867 CheckBool(dictionary, "showPassphrase", true); |
913 CheckBool(dictionary, "usePassphrase", false); | 868 CheckBool(dictionary, "usePassphrase", false); |
914 CheckBool(dictionary, "passphraseFailed", false); | 869 CheckBool(dictionary, "passphraseFailed", false); |
915 } | 870 } |
916 | 871 |
917 TEST_F(SyncHandlerTest, ShowSetupCustomPassphraseRequired) { | 872 TEST_F(PeopleHandlerTest, ShowSetupCustomPassphraseRequired) { |
918 EXPECT_CALL(*mock_pss_, IsPassphraseRequired()) | 873 EXPECT_CALL(*mock_pss_, IsPassphraseRequired()).WillRepeatedly(Return(true)); |
919 .WillRepeatedly(Return(true)); | |
920 EXPECT_CALL(*mock_pss_, IsUsingSecondaryPassphrase()) | 874 EXPECT_CALL(*mock_pss_, IsUsingSecondaryPassphrase()) |
921 .WillRepeatedly(Return(true)); | 875 .WillRepeatedly(Return(true)); |
922 EXPECT_CALL(*mock_pss_, GetPassphraseType()) | 876 EXPECT_CALL(*mock_pss_, GetPassphraseType()) |
923 .WillRepeatedly(Return(syncer::CUSTOM_PASSPHRASE)); | 877 .WillRepeatedly(Return(syncer::CUSTOM_PASSPHRASE)); |
924 SetupInitializedProfileSyncService(); | 878 SetupInitializedProfileSyncService(); |
925 SetDefaultExpectationsForConfigPage(); | 879 SetDefaultExpectationsForConfigPage(); |
926 | 880 |
927 // This should display the sync setup dialog (not login). | 881 // This should display the sync setup dialog (not login). |
928 handler_->OpenSyncSetup(nullptr); | 882 handler_->OpenSyncSetup(nullptr); |
929 | 883 |
930 ExpectConfig(); | 884 ExpectConfig(); |
931 const content::TestWebUI::CallData& data = *web_ui_.call_data()[0]; | 885 const content::TestWebUI::CallData& data = *web_ui_.call_data()[0]; |
932 const base::DictionaryValue* dictionary = nullptr; | 886 const base::DictionaryValue* dictionary = nullptr; |
933 ASSERT_TRUE(data.arg2()->GetAsDictionary(&dictionary)); | 887 ASSERT_TRUE(data.arg2()->GetAsDictionary(&dictionary)); |
934 CheckBool(dictionary, "showPassphrase", true); | 888 CheckBool(dictionary, "showPassphrase", true); |
935 CheckBool(dictionary, "usePassphrase", true); | 889 CheckBool(dictionary, "usePassphrase", true); |
936 CheckBool(dictionary, "passphraseFailed", false); | 890 CheckBool(dictionary, "passphraseFailed", false); |
937 } | 891 } |
938 | 892 |
939 TEST_F(SyncHandlerTest, ShowSetupEncryptAll) { | 893 TEST_F(PeopleHandlerTest, ShowSetupEncryptAll) { |
940 EXPECT_CALL(*mock_pss_, IsPassphraseRequired()) | 894 EXPECT_CALL(*mock_pss_, IsPassphraseRequired()).WillRepeatedly(Return(false)); |
941 .WillRepeatedly(Return(false)); | |
942 EXPECT_CALL(*mock_pss_, IsUsingSecondaryPassphrase()) | 895 EXPECT_CALL(*mock_pss_, IsUsingSecondaryPassphrase()) |
943 .WillRepeatedly(Return(false)); | 896 .WillRepeatedly(Return(false)); |
944 SetupInitializedProfileSyncService(); | 897 SetupInitializedProfileSyncService(); |
945 SetDefaultExpectationsForConfigPage(); | 898 SetDefaultExpectationsForConfigPage(); |
946 EXPECT_CALL(*mock_pss_, IsEncryptEverythingEnabled()) | 899 EXPECT_CALL(*mock_pss_, IsEncryptEverythingEnabled()) |
947 .WillRepeatedly(Return(true)); | 900 .WillRepeatedly(Return(true)); |
948 | 901 |
949 // This should display the sync setup dialog (not login). | 902 // This should display the sync setup dialog (not login). |
950 handler_->OpenSyncSetup(nullptr); | 903 handler_->OpenSyncSetup(nullptr); |
951 | 904 |
952 ExpectConfig(); | 905 ExpectConfig(); |
953 const content::TestWebUI::CallData& data = *web_ui_.call_data()[0]; | 906 const content::TestWebUI::CallData& data = *web_ui_.call_data()[0]; |
954 const base::DictionaryValue* dictionary = nullptr; | 907 const base::DictionaryValue* dictionary = nullptr; |
955 ASSERT_TRUE(data.arg2()->GetAsDictionary(&dictionary)); | 908 ASSERT_TRUE(data.arg2()->GetAsDictionary(&dictionary)); |
956 CheckBool(dictionary, "encryptAllData", true); | 909 CheckBool(dictionary, "encryptAllData", true); |
957 } | 910 } |
958 | 911 |
959 TEST_F(SyncHandlerTest, ShowSetupEncryptAllDisallowed) { | 912 TEST_F(PeopleHandlerTest, ShowSetupEncryptAllDisallowed) { |
960 EXPECT_CALL(*mock_pss_, IsPassphraseRequired()) | 913 EXPECT_CALL(*mock_pss_, IsPassphraseRequired()).WillRepeatedly(Return(false)); |
961 .WillRepeatedly(Return(false)); | |
962 EXPECT_CALL(*mock_pss_, IsUsingSecondaryPassphrase()) | 914 EXPECT_CALL(*mock_pss_, IsUsingSecondaryPassphrase()) |
963 .WillRepeatedly(Return(false)); | 915 .WillRepeatedly(Return(false)); |
964 SetupInitializedProfileSyncService(); | 916 SetupInitializedProfileSyncService(); |
965 SetDefaultExpectationsForConfigPage(); | 917 SetDefaultExpectationsForConfigPage(); |
966 EXPECT_CALL(*mock_pss_, IsEncryptEverythingAllowed()) | 918 EXPECT_CALL(*mock_pss_, IsEncryptEverythingAllowed()) |
967 .WillRepeatedly(Return(false)); | 919 .WillRepeatedly(Return(false)); |
968 | 920 |
969 // This should display the sync setup dialog (not login). | 921 // This should display the sync setup dialog (not login). |
970 handler_->OpenSyncSetup(nullptr); | 922 handler_->OpenSyncSetup(nullptr); |
971 | 923 |
972 ExpectConfig(); | 924 ExpectConfig(); |
973 const content::TestWebUI::CallData& data = *web_ui_.call_data()[0]; | 925 const content::TestWebUI::CallData& data = *web_ui_.call_data()[0]; |
974 const base::DictionaryValue* dictionary = nullptr; | 926 const base::DictionaryValue* dictionary = nullptr; |
975 ASSERT_TRUE(data.arg2()->GetAsDictionary(&dictionary)); | 927 ASSERT_TRUE(data.arg2()->GetAsDictionary(&dictionary)); |
976 CheckBool(dictionary, "encryptAllData", false); | 928 CheckBool(dictionary, "encryptAllData", false); |
977 CheckBool(dictionary, "encryptAllDataAllowed", false); | 929 CheckBool(dictionary, "encryptAllDataAllowed", false); |
978 } | 930 } |
979 | 931 |
980 TEST_F(SyncHandlerTest, TurnOnEncryptAllDisallowed) { | 932 TEST_F(PeopleHandlerTest, TurnOnEncryptAllDisallowed) { |
981 std::string args = GetConfiguration( | 933 std::string args = GetConfiguration(NULL, SYNC_ALL_DATA, GetAllTypes(), |
982 NULL, SYNC_ALL_DATA, GetAllTypes(), std::string(), ENCRYPT_ALL_DATA); | 934 std::string(), ENCRYPT_ALL_DATA); |
983 base::ListValue list_args; | 935 base::ListValue list_args; |
984 list_args.Append(new base::StringValue(args)); | 936 list_args.Append(new base::StringValue(args)); |
985 EXPECT_CALL(*mock_pss_, IsPassphraseRequiredForDecryption()) | 937 EXPECT_CALL(*mock_pss_, IsPassphraseRequiredForDecryption()) |
986 .WillRepeatedly(Return(false)); | 938 .WillRepeatedly(Return(false)); |
987 EXPECT_CALL(*mock_pss_, IsPassphraseRequired()) | 939 EXPECT_CALL(*mock_pss_, IsPassphraseRequired()).WillRepeatedly(Return(false)); |
988 .WillRepeatedly(Return(false)); | |
989 SetupInitializedProfileSyncService(); | 940 SetupInitializedProfileSyncService(); |
990 EXPECT_CALL(*mock_pss_, IsEncryptEverythingAllowed()) | 941 EXPECT_CALL(*mock_pss_, IsEncryptEverythingAllowed()) |
991 .WillRepeatedly(Return(false)); | 942 .WillRepeatedly(Return(false)); |
992 EXPECT_CALL(*mock_pss_, EnableEncryptEverything()).Times(0); | 943 EXPECT_CALL(*mock_pss_, EnableEncryptEverything()).Times(0); |
993 EXPECT_CALL(*mock_pss_, OnUserChoseDatatypes(true, _)); | 944 EXPECT_CALL(*mock_pss_, OnUserChoseDatatypes(true, _)); |
994 handler_->HandleConfigure(&list_args); | 945 handler_->HandleConfigure(&list_args); |
995 | 946 |
996 // Ensure that we navigated to the "done" state since we don't need a | 947 // Ensure that we navigated to the "done" state since we don't need a |
997 // passphrase. | 948 // passphrase. |
998 ExpectDone(); | 949 ExpectDone(); |
999 } | 950 } |
1000 | 951 |
1001 } // namespace settings | 952 } // namespace settings |
OLD | NEW |