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

Side by Side Diff: chrome/browser/ui/webui/sync_setup_handler_unittest.cc

Issue 9956097: suppress user/password dialog when re-enabling sync (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: More OS_CHROMEOS guard for compilation. Created 8 years, 8 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) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "chrome/browser/ui/webui/sync_setup_handler.h" 5 #include "chrome/browser/ui/webui/sync_setup_handler.h"
6 6
7 #include <vector> 7 #include <vector>
8 8
9 #include "base/memory/scoped_ptr.h" 9 #include "base/memory/scoped_ptr.h"
10 #include "base/stl_util.h" 10 #include "base/stl_util.h"
(...skipping 190 matching lines...) Expand 10 before | Expand all | Expand 10 after
201 EXPECT_EQ(page, "done"); 201 EXPECT_EQ(page, "done");
202 } 202 }
203 203
204 scoped_ptr<Profile> profile_; 204 scoped_ptr<Profile> profile_;
205 ProfileSyncServiceMock* mock_pss_; 205 ProfileSyncServiceMock* mock_pss_;
206 SigninManagerMock* mock_signin_; 206 SigninManagerMock* mock_signin_;
207 TestWebUI web_ui_; 207 TestWebUI web_ui_;
208 scoped_ptr<TestingSyncSetupHandler> handler_; 208 scoped_ptr<TestingSyncSetupHandler> handler_;
209 }; 209 };
210 210
211 #if !defined(OS_CHROMEOS)
211 static void CheckInt(const DictionaryValue* dictionary, 212 static void CheckInt(const DictionaryValue* dictionary,
212 const std::string& key, 213 const std::string& key,
213 int expected_value) { 214 int expected_value) {
214 int actual_value; 215 int actual_value;
215 EXPECT_TRUE(dictionary->GetInteger(key, &actual_value)) << 216 EXPECT_TRUE(dictionary->GetInteger(key, &actual_value)) <<
216 "Did not expect to find value for " << key;; 217 "Did not expect to find value for " << key;;
217 EXPECT_EQ(actual_value, expected_value) << 218 EXPECT_EQ(actual_value, expected_value) <<
218 "Mismatch found for " << key;; 219 "Mismatch found for " << key;;
219 } 220 }
221 #endif
220 222
221 static void CheckBool(const DictionaryValue* dictionary, 223 static void CheckBool(const DictionaryValue* dictionary,
222 const std::string& key, 224 const std::string& key,
223 bool expected_value, 225 bool expected_value,
224 bool is_optional) { 226 bool is_optional) {
225 if (is_optional && !expected_value) { 227 if (is_optional && !expected_value) {
226 EXPECT_FALSE(dictionary->HasKey(key)) << 228 EXPECT_FALSE(dictionary->HasKey(key)) <<
227 "Did not expect to find value for " << key;; 229 "Did not expect to find value for " << key;;
228 } else { 230 } else {
229 bool actual_value; 231 bool actual_value;
230 EXPECT_TRUE(dictionary->GetBoolean(key, &actual_value)) << 232 EXPECT_TRUE(dictionary->GetBoolean(key, &actual_value)) <<
231 "No value found for " << key; 233 "No value found for " << key;
232 EXPECT_EQ(actual_value, expected_value) << 234 EXPECT_EQ(actual_value, expected_value) <<
233 "Mismatch found for " << key; 235 "Mismatch found for " << key;
234 } 236 }
235 } 237 }
236 238
237 static void CheckBool(const DictionaryValue* dictionary, 239 static void CheckBool(const DictionaryValue* dictionary,
238 const std::string& key, 240 const std::string& key,
239 bool expected_value) { 241 bool expected_value) {
240 return CheckBool(dictionary, key, expected_value, false); 242 return CheckBool(dictionary, key, expected_value, false);
241 } 243 }
242 244
245 #if !defined(OS_CHROMEOS)
243 static void CheckString(const DictionaryValue* dictionary, 246 static void CheckString(const DictionaryValue* dictionary,
244 const std::string& key, 247 const std::string& key,
245 const std::string& expected_value, 248 const std::string& expected_value,
246 bool is_optional) { 249 bool is_optional) {
247 if (is_optional && expected_value.empty()) { 250 if (is_optional && expected_value.empty()) {
248 EXPECT_FALSE(dictionary->HasKey(key)) << 251 EXPECT_FALSE(dictionary->HasKey(key)) <<
249 "Did not expect to find value for " << key; 252 "Did not expect to find value for " << key;
250 } else { 253 } else {
251 std::string actual_value; 254 std::string actual_value;
252 EXPECT_TRUE(dictionary->GetString(key, &actual_value)) << 255 EXPECT_TRUE(dictionary->GetString(key, &actual_value)) <<
253 "No value found for " << key; 256 "No value found for " << key;
254 EXPECT_EQ(actual_value, expected_value) << 257 EXPECT_EQ(actual_value, expected_value) <<
255 "Mismatch found for " << key; 258 "Mismatch found for " << key;
256 } 259 }
257 } 260 }
261 #endif
258 262
263 #if !defined(OS_CHROMEOS)
259 // Validates that the expected args are being passed off to javascript. 264 // Validates that the expected args are being passed off to javascript.
260 static void CheckShowSyncSetupArgs(const DictionaryValue* dictionary, 265 static void CheckShowSyncSetupArgs(const DictionaryValue* dictionary,
261 std::string error_message, 266 std::string error_message,
262 bool fatal_error, 267 bool fatal_error,
263 int error, 268 int error,
264 std::string user, 269 std::string user,
265 bool user_is_editable, 270 bool user_is_editable,
266 std::string captcha_url) { 271 std::string captcha_url) {
267 // showSyncSetupPage() expects to be passed a dictionary with the following 272 // showSyncSetupPage() expects to be passed a dictionary with the following
268 // named values set: 273 // named values set:
269 // error_message: custom error message to display. 274 // error_message: custom error message to display.
270 // fatalError: true if there was a fatal error while logging in. 275 // fatalError: true if there was a fatal error while logging in.
271 // error: GoogleServiceAuthError from previous login attempt (0 if none). 276 // error: GoogleServiceAuthError from previous login attempt (0 if none).
272 // user: The email the user most recently entered. 277 // user: The email the user most recently entered.
273 // editable_user: Whether the username field should be editable. 278 // editable_user: Whether the username field should be editable.
274 // captchaUrl: The captcha image to display to the user (empty if none). 279 // captchaUrl: The captcha image to display to the user (empty if none).
275 // 280 //
276 // The code below validates these arguments. 281 // The code below validates these arguments.
277 282
278 CheckString(dictionary, "error_message", error_message, true); 283 CheckString(dictionary, "error_message", error_message, true);
279 CheckString(dictionary, "user", user, false); 284 CheckString(dictionary, "user", user, false);
280 CheckString(dictionary, "captchaUrl", captcha_url, false); 285 CheckString(dictionary, "captchaUrl", captcha_url, false);
281 CheckInt(dictionary, "error", error); 286 CheckInt(dictionary, "error", error);
282 CheckBool(dictionary, "fatalError", fatal_error, true); 287 CheckBool(dictionary, "fatalError", fatal_error, true);
283 CheckBool(dictionary, "editable_user", user_is_editable); 288 CheckBool(dictionary, "editable_user", user_is_editable);
284 } 289 }
290 #endif
285 291
286 TEST_F(SyncSetupHandlerTest, Basic) { 292 TEST_F(SyncSetupHandlerTest, Basic) {
287 } 293 }
288 294
295 #if !defined(OS_CHROMEOS)
289 TEST_F(SyncSetupHandlerTest, DisplayBasicLogin) { 296 TEST_F(SyncSetupHandlerTest, DisplayBasicLogin) {
290 EXPECT_CALL(*mock_pss_, AreCredentialsAvailable()) 297 EXPECT_CALL(*mock_pss_, AreCredentialsAvailable())
291 .WillRepeatedly(Return(false)); 298 .WillRepeatedly(Return(false));
292 EXPECT_CALL(*mock_pss_, HasSyncSetupCompleted()) 299 EXPECT_CALL(*mock_pss_, HasSyncSetupCompleted())
293 .WillRepeatedly(Return(false)); 300 .WillRepeatedly(Return(false));
294 handler_->OpenSyncSetup(false); 301 handler_->OpenSyncSetup(false);
295 EXPECT_EQ(&web_ui_, 302 EXPECT_EQ(&web_ui_,
296 LoginUIServiceFactory::GetForProfile( 303 LoginUIServiceFactory::GetForProfile(
297 profile_.get())->current_login_ui()); 304 profile_.get())->current_login_ui());
298 ASSERT_EQ(1U, web_ui_.call_data().size()); 305 ASSERT_EQ(1U, web_ui_.call_data().size());
(...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after
411 EXPECT_EQ("SyncSetupOverlay.showSyncSetupPage", data.function_name); 418 EXPECT_EQ("SyncSetupOverlay.showSyncSetupPage", data.function_name);
412 std::string page; 419 std::string page;
413 ASSERT_TRUE(data.arg1->GetAsString(&page)); 420 ASSERT_TRUE(data.arg1->GetAsString(&page));
414 EXPECT_EQ(page, "login"); 421 EXPECT_EQ(page, "login");
415 // Now make sure that the appropriate params are being passed. 422 // Now make sure that the appropriate params are being passed.
416 DictionaryValue* dictionary; 423 DictionaryValue* dictionary;
417 ASSERT_TRUE(data.arg2->GetAsDictionary(&dictionary)); 424 ASSERT_TRUE(data.arg2->GetAsDictionary(&dictionary));
418 CheckShowSyncSetupArgs( 425 CheckShowSyncSetupArgs(
419 dictionary, "", true, GoogleServiceAuthError::NONE, "", true, ""); 426 dictionary, "", true, GoogleServiceAuthError::NONE, "", true, "");
420 } 427 }
428 #endif // !OS_CHROMEOS
421 429
430 #if !defined(OS_CHROMEOS)
431 // TODO(kochi): We need equivalent tests for ChromeOS.
422 TEST_F(SyncSetupHandlerTest, UnrecoverableErrorInitializingSync) { 432 TEST_F(SyncSetupHandlerTest, UnrecoverableErrorInitializingSync) {
423 EXPECT_CALL(*mock_pss_, AreCredentialsAvailable()) 433 EXPECT_CALL(*mock_pss_, AreCredentialsAvailable())
424 .WillRepeatedly(Return(false)); 434 .WillRepeatedly(Return(false));
425 EXPECT_CALL(*mock_pss_, HasSyncSetupCompleted()) 435 EXPECT_CALL(*mock_pss_, HasSyncSetupCompleted())
426 .WillRepeatedly(Return(false)); 436 .WillRepeatedly(Return(false));
427 // Open the web UI. 437 // Open the web UI.
428 handler_->OpenSyncSetup(false); 438 handler_->OpenSyncSetup(false);
429 ASSERT_EQ(1U, web_ui_.call_data().size()); 439 ASSERT_EQ(1U, web_ui_.call_data().size());
430 // Fake a successful GAIA request (gaia credentials valid, but signin not 440 // Fake a successful GAIA request (gaia credentials valid, but signin not
431 // complete yet). 441 // complete yet).
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after
486 std::string page; 496 std::string page;
487 ASSERT_TRUE(data.arg1->GetAsString(&page)); 497 ASSERT_TRUE(data.arg1->GetAsString(&page));
488 EXPECT_EQ(page, "login"); 498 EXPECT_EQ(page, "login");
489 // Now make sure that the appropriate params are being passed. 499 // Now make sure that the appropriate params are being passed.
490 DictionaryValue* dictionary; 500 DictionaryValue* dictionary;
491 ASSERT_TRUE(data.arg2->GetAsDictionary(&dictionary)); 501 ASSERT_TRUE(data.arg2->GetAsDictionary(&dictionary));
492 CheckShowSyncSetupArgs( 502 CheckShowSyncSetupArgs(
493 dictionary, "", false, GoogleServiceAuthError::SERVICE_UNAVAILABLE, 503 dictionary, "", false, GoogleServiceAuthError::SERVICE_UNAVAILABLE,
494 kTestUser, true, ""); 504 kTestUser, true, "");
495 } 505 }
506 #endif // !OS_CHROMEOS
496 507
497 TEST_F(SyncSetupHandlerTest, TestSyncEverything) { 508 TEST_F(SyncSetupHandlerTest, TestSyncEverything) {
498 std::string args = 509 std::string args =
499 "{\"syncAllDataTypes\":true," 510 "{\"syncAllDataTypes\":true,"
500 "\"sync_apps\":true," 511 "\"sync_apps\":true,"
501 "\"sync_autofill\":true," 512 "\"sync_autofill\":true,"
502 "\"sync_bookmarks\":true," 513 "\"sync_bookmarks\":true,"
503 "\"sync_extensions\":true," 514 "\"sync_extensions\":true,"
504 "\"sync_passwords\":true," 515 "\"sync_passwords\":true,"
505 "\"sync_preferences\":true," 516 "\"sync_preferences\":true,"
(...skipping 410 matching lines...) Expand 10 before | Expand all | Expand 10 after
916 927
917 // This should display the sync setup dialog (not login). 928 // This should display the sync setup dialog (not login).
918 handler_->OpenSyncSetup(false); 929 handler_->OpenSyncSetup(false);
919 930
920 ExpectConfig(); 931 ExpectConfig();
921 const TestWebUI::CallData& data = web_ui_.call_data()[0]; 932 const TestWebUI::CallData& data = web_ui_.call_data()[0];
922 DictionaryValue* dictionary; 933 DictionaryValue* dictionary;
923 ASSERT_TRUE(data.arg2->GetAsDictionary(&dictionary)); 934 ASSERT_TRUE(data.arg2->GetAsDictionary(&dictionary));
924 CheckBool(dictionary, "encryptAllData", true); 935 CheckBool(dictionary, "encryptAllData", true);
925 } 936 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698