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

Side by Side Diff: chrome/browser/ui/webui/signin/signin_create_profile_handler_unittest.cc

Issue 2041513002: Remove ListValue::Append(new {Fundamental,String}Value(...)) usage in //chrome (part 2) (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2016 The Chromium Authors. All rights reserved. 1 // Copyright 2016 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/signin/signin_create_profile_handler.h" 5 #include "chrome/browser/ui/webui/signin/signin_create_profile_handler.h"
6 6
7 #include "base/strings/utf_string_conversions.h" 7 #include "base/strings/utf_string_conversions.h"
8 #include "chrome/browser/prefs/browser_prefs.h" 8 #include "chrome/browser/prefs/browser_prefs.h"
9 #include "chrome/browser/profiles/profile.h" 9 #include "chrome/browser/profiles/profile.h"
10 #include "chrome/browser/profiles/profile_attributes_entry.h" 10 #include "chrome/browser/profiles/profile_attributes_entry.h"
(...skipping 320 matching lines...) Expand 10 before | Expand all | Expand 10 after
331 &TestSigninCreateProfileHandler::RealDoCreateProfile)); 331 &TestSigninCreateProfileHandler::RealDoCreateProfile));
332 332
333 // Expect no calls to register a supervised user. 333 // Expect no calls to register a supervised user.
334 EXPECT_CALL(*handler(), RegisterSupervisedUser(_, _, _, _)).Times(0); 334 EXPECT_CALL(*handler(), RegisterSupervisedUser(_, _, _, _)).Times(0);
335 335
336 // Expect a new browser window for the new profile to be opened. 336 // Expect a new browser window for the new profile to be opened.
337 EXPECT_CALL(*handler(), OpenNewWindowForProfile(_, _)); 337 EXPECT_CALL(*handler(), OpenNewWindowForProfile(_, _));
338 338
339 // Create a non-supervised profile. 339 // Create a non-supervised profile.
340 base::ListValue list_args; 340 base::ListValue list_args;
341 list_args.Append(new base::StringValue(kTestProfileName)); 341 list_args.AppendString(kTestProfileName);
342 list_args.Append(new base::StringValue(profiles::GetDefaultAvatarIconUrl(0))); 342 list_args.AppendString(profiles::GetDefaultAvatarIconUrl(0));
343 list_args.Append(new base::FundamentalValue(false)); // create_shortcut 343 list_args.AppendBoolean(false); // create_shortcut
344 list_args.Append(new base::FundamentalValue(false)); // is_supervised 344 list_args.AppendBoolean(false); // is_supervised
345 handler()->CreateProfile(&list_args); 345 handler()->CreateProfile(&list_args);
346 346
347 // Expect a JS callbacks with the new profile information. 347 // Expect a JS callbacks with the new profile information.
348 EXPECT_EQ(1U, web_ui()->call_data().size()); 348 EXPECT_EQ(1U, web_ui()->call_data().size());
349 349
350 EXPECT_EQ(kTestWebUIResponse, web_ui()->call_data()[0]->function_name()); 350 EXPECT_EQ(kTestWebUIResponse, web_ui()->call_data()[0]->function_name());
351 351
352 std::string callback_name; 352 std::string callback_name;
353 ASSERT_TRUE(web_ui()->call_data()[0]->arg1()->GetAsString(&callback_name)); 353 ASSERT_TRUE(web_ui()->call_data()[0]->arg1()->GetAsString(&callback_name));
354 EXPECT_EQ("create-profile-success", callback_name); 354 EXPECT_EQ("create-profile-success", callback_name);
(...skipping 22 matching lines...) Expand all
377 .WillOnce(Invoke( 377 .WillOnce(Invoke(
378 handler(), 378 handler(),
379 &TestSigninCreateProfileHandler::RealRegisterSupervisedUser)); 379 &TestSigninCreateProfileHandler::RealRegisterSupervisedUser));
380 380
381 // Expect no new browser window for the new supervised profile to be opened. 381 // Expect no new browser window for the new supervised profile to be opened.
382 EXPECT_CALL(*handler(), OpenNewWindowForProfile(_, _)).Times(0); 382 EXPECT_CALL(*handler(), OpenNewWindowForProfile(_, _)).Times(0);
383 383
384 // Create a supervised profile. 384 // Create a supervised profile.
385 base::ListValue list_args; 385 base::ListValue list_args;
386 list_args.Clear(); 386 list_args.Clear();
387 list_args.Append(new base::StringValue(kSupervisedUsername1)); 387 list_args.AppendString(kSupervisedUsername1);
388 list_args.Append(new base::StringValue(profiles::GetDefaultAvatarIconUrl(0))); 388 list_args.AppendString(profiles::GetDefaultAvatarIconUrl(0));
389 list_args.Append(new base::FundamentalValue(false)); // create_shortcut 389 list_args.AppendBoolean(false); // create_shortcut
390 list_args.Append(new base::FundamentalValue(true)); // is_supervised 390 list_args.AppendBoolean(true); // is_supervised
391 list_args.Append(new base::StringValue("")); // supervised_user_id 391 list_args.AppendString(""); // supervised_user_id
392 list_args.Append(new base::StringValue(custodian()->GetPath().value())); 392 list_args.AppendString(custodian()->GetPath().value());
393 handler()->CreateProfile(&list_args); 393 handler()->CreateProfile(&list_args);
394 394
395 // Expect a JS callbacks with the new profile information. 395 // Expect a JS callbacks with the new profile information.
396 EXPECT_EQ(1U, web_ui()->call_data().size()); 396 EXPECT_EQ(1U, web_ui()->call_data().size());
397 397
398 EXPECT_EQ(kTestWebUIResponse, web_ui()->call_data()[0]->function_name()); 398 EXPECT_EQ(kTestWebUIResponse, web_ui()->call_data()[0]->function_name());
399 399
400 std::string callback_name; 400 std::string callback_name;
401 ASSERT_TRUE(web_ui()->call_data()[0]->arg1()->GetAsString(&callback_name)); 401 ASSERT_TRUE(web_ui()->call_data()[0]->arg1()->GetAsString(&callback_name));
402 EXPECT_EQ("create-profile-success", callback_name); 402 EXPECT_EQ("create-profile-success", callback_name);
(...skipping 22 matching lines...) Expand all
425 .WillOnce(Invoke( 425 .WillOnce(Invoke(
426 handler(), 426 handler(),
427 &TestSigninCreateProfileHandler::RealRegisterSupervisedUser)); 427 &TestSigninCreateProfileHandler::RealRegisterSupervisedUser));
428 428
429 // Expect a new browser window for the new profile to be opened. 429 // Expect a new browser window for the new profile to be opened.
430 EXPECT_CALL(*handler(), OpenNewWindowForProfile(_, _)); 430 EXPECT_CALL(*handler(), OpenNewWindowForProfile(_, _));
431 431
432 // Import a supervised profile. 432 // Import a supervised profile.
433 base::ListValue list_args; 433 base::ListValue list_args;
434 list_args.Clear(); 434 list_args.Clear();
435 list_args.Append(new base::StringValue(kSupervisedUsername1)); 435 list_args.AppendString(kSupervisedUsername1);
436 list_args.Append(new base::StringValue(profiles::GetDefaultAvatarIconUrl(0))); 436 list_args.AppendString(profiles::GetDefaultAvatarIconUrl(0));
437 list_args.Append(new base::FundamentalValue(false)); // create_shortcut 437 list_args.AppendBoolean(false); // create_shortcut
438 list_args.Append(new base::FundamentalValue(true)); // is_supervised 438 list_args.AppendBoolean(true); // is_supervised
439 list_args.Append( 439 list_args.AppendString(
440 new base::StringValue(kSupervisedUserId1)); // supervised_user_id 440 kSupervisedUserId1); // supervised_user_id
441 list_args.Append(new base::StringValue(custodian()->GetPath().value())); 441 list_args.AppendString(custodian()->GetPath().value());
442 handler()->CreateProfile(&list_args); 442 handler()->CreateProfile(&list_args);
443 443
444 // Expect a JS callbacks with the new profile information. 444 // Expect a JS callbacks with the new profile information.
445 EXPECT_EQ(1U, web_ui()->call_data().size()); 445 EXPECT_EQ(1U, web_ui()->call_data().size());
446 446
447 EXPECT_EQ(kTestWebUIResponse, web_ui()->call_data()[0]->function_name()); 447 EXPECT_EQ(kTestWebUIResponse, web_ui()->call_data()[0]->function_name());
448 448
449 std::string callback_name; 449 std::string callback_name;
450 ASSERT_TRUE(web_ui()->call_data()[0]->arg1()->GetAsString(&callback_name)); 450 ASSERT_TRUE(web_ui()->call_data()[0]->arg1()->GetAsString(&callback_name));
451 EXPECT_EQ("create-profile-success", callback_name); 451 EXPECT_EQ("create-profile-success", callback_name);
452 452
453 const base::DictionaryValue* profile; 453 const base::DictionaryValue* profile;
454 ASSERT_TRUE(web_ui()->call_data()[0]->arg2()->GetAsDictionary(&profile)); 454 ASSERT_TRUE(web_ui()->call_data()[0]->arg2()->GetAsDictionary(&profile));
455 std::string profile_name; 455 std::string profile_name;
456 ASSERT_TRUE(profile->GetString("name", &profile_name)); 456 ASSERT_TRUE(profile->GetString("name", &profile_name));
457 EXPECT_NE("", profile_name); 457 EXPECT_NE("", profile_name);
458 std::string profile_path; 458 std::string profile_path;
459 ASSERT_TRUE(profile->GetString("filePath", &profile_path)); 459 ASSERT_TRUE(profile->GetString("filePath", &profile_path));
460 EXPECT_NE("", profile_path); 460 EXPECT_NE("", profile_path);
461 bool is_supervised; 461 bool is_supervised;
462 ASSERT_TRUE(profile->GetBoolean("isSupervised", &is_supervised)); 462 ASSERT_TRUE(profile->GetBoolean("isSupervised", &is_supervised));
463 ASSERT_TRUE(is_supervised); 463 ASSERT_TRUE(is_supervised);
464 } 464 }
465 465
466 TEST_F(SigninCreateProfileHandlerTest, ImportSupervisedUserAlreadyOnDevice) { 466 TEST_F(SigninCreateProfileHandlerTest, ImportSupervisedUserAlreadyOnDevice) {
467 // Import a supervised profile whose already on the current device. 467 // Import a supervised profile whose already on the current device.
468 base::ListValue list_args; 468 base::ListValue list_args;
469 list_args.Clear(); 469 list_args.Clear();
470 list_args.Append(new base::StringValue(kSupervisedUsername2)); 470 list_args.AppendString(kSupervisedUsername2);
471 list_args.Append(new base::StringValue(profiles::GetDefaultAvatarIconUrl(0))); 471 list_args.AppendString(profiles::GetDefaultAvatarIconUrl(0));
472 list_args.Append(new base::FundamentalValue(false)); 472 list_args.AppendBoolean(false);
473 list_args.Append(new base::FundamentalValue(true)); 473 list_args.AppendBoolean(true);
474 list_args.Append(new base::StringValue(kSupervisedUserId2)); 474 list_args.AppendString(kSupervisedUserId2);
475 list_args.Append(new base::StringValue(custodian()->GetPath().value())); 475 list_args.AppendString(custodian()->GetPath().value());
476 handler()->CreateProfile(&list_args); 476 handler()->CreateProfile(&list_args);
477 477
478 // Expect a JS callbacks containing an error message. 478 // Expect a JS callbacks containing an error message.
479 EXPECT_EQ(1U, web_ui()->call_data().size()); 479 EXPECT_EQ(1U, web_ui()->call_data().size());
480 480
481 EXPECT_EQ(kTestWebUIResponse, web_ui()->call_data()[0]->function_name()); 481 EXPECT_EQ(kTestWebUIResponse, web_ui()->call_data()[0]->function_name());
482 482
483 std::string callback_name; 483 std::string callback_name;
484 ASSERT_TRUE(web_ui()->call_data()[0]->arg1()->GetAsString(&callback_name)); 484 ASSERT_TRUE(web_ui()->call_data()[0]->arg1()->GetAsString(&callback_name));
485 EXPECT_EQ("create-profile-error", callback_name); 485 EXPECT_EQ("create-profile-error", callback_name);
(...skipping 10 matching lines...) Expand all
496 SupervisedUserSyncService* sync_service_ = 496 SupervisedUserSyncService* sync_service_ =
497 SupervisedUserSyncServiceFactory::GetForProfile(custodian()); 497 SupervisedUserSyncServiceFactory::GetForProfile(custodian());
498 sync_service_->StopSyncing(syncer::SUPERVISED_USERS); 498 sync_service_->StopSyncing(syncer::SUPERVISED_USERS);
499 499
500 // Sign out the custodian. 500 // Sign out the custodian.
501 signin_manager()->ForceSignOut(); 501 signin_manager()->ForceSignOut();
502 502
503 // Create a supervised profile. 503 // Create a supervised profile.
504 base::ListValue list_args; 504 base::ListValue list_args;
505 list_args.Clear(); 505 list_args.Clear();
506 list_args.Append(new base::StringValue(kSupervisedUsername1)); 506 list_args.AppendString(kSupervisedUsername1);
507 list_args.Append(new base::StringValue(profiles::GetDefaultAvatarIconUrl(0))); 507 list_args.AppendString(profiles::GetDefaultAvatarIconUrl(0));
508 list_args.Append(new base::FundamentalValue(false)); // create_shortcut 508 list_args.AppendBoolean(false); // create_shortcut
509 list_args.Append(new base::FundamentalValue(true)); // is_supervised 509 list_args.AppendBoolean(true); // is_supervised
510 list_args.Append(new base::StringValue("")); // supervised_user_id 510 list_args.AppendString(""); // supervised_user_id
511 list_args.Append(new base::StringValue(custodian()->GetPath().value())); 511 list_args.AppendString(custodian()->GetPath().value());
512 handler()->CreateProfile(&list_args); 512 handler()->CreateProfile(&list_args);
513 513
514 // Expect a JS callbacks containing an error message. 514 // Expect a JS callbacks containing an error message.
515 EXPECT_EQ(1U, web_ui()->call_data().size()); 515 EXPECT_EQ(1U, web_ui()->call_data().size());
516 516
517 EXPECT_EQ(kTestWebUIResponse, web_ui()->call_data()[0]->function_name()); 517 EXPECT_EQ(kTestWebUIResponse, web_ui()->call_data()[0]->function_name());
518 518
519 std::string callback_name; 519 std::string callback_name;
520 ASSERT_TRUE(web_ui()->call_data()[0]->arg1()->GetAsString(&callback_name)); 520 ASSERT_TRUE(web_ui()->call_data()[0]->arg1()->GetAsString(&callback_name));
521 EXPECT_EQ("create-profile-error", callback_name); 521 EXPECT_EQ("create-profile-error", callback_name);
522 522
523 base::string16 expected_error_message = l10n_util::GetStringUTF16( 523 base::string16 expected_error_message = l10n_util::GetStringUTF16(
524 IDS_PROFILES_CREATE_CUSTODIAN_ACCOUNT_DETAILS_OUT_OF_DATE_ERROR); 524 IDS_PROFILES_CREATE_CUSTODIAN_ACCOUNT_DETAILS_OUT_OF_DATE_ERROR);
525 base::string16 error_message; 525 base::string16 error_message;
526 ASSERT_TRUE(web_ui()->call_data()[0]->arg2()->GetAsString(&error_message)); 526 ASSERT_TRUE(web_ui()->call_data()[0]->arg2()->GetAsString(&error_message));
527 EXPECT_EQ(expected_error_message, error_message); 527 EXPECT_EQ(expected_error_message, error_message);
528 } 528 }
529 529
530 TEST_F(SigninCreateProfileHandlerTest, CustodianHasAuthError) { 530 TEST_F(SigninCreateProfileHandlerTest, CustodianHasAuthError) {
531 // Set an Auth Error for the custodian. 531 // Set an Auth Error for the custodian.
532 const GoogleServiceAuthError error( 532 const GoogleServiceAuthError error(
533 GoogleServiceAuthError::INVALID_GAIA_CREDENTIALS); 533 GoogleServiceAuthError::INVALID_GAIA_CREDENTIALS);
534 FakeAuthStatusProvider provider( 534 FakeAuthStatusProvider provider(
535 SigninErrorControllerFactory::GetForProfile(custodian())); 535 SigninErrorControllerFactory::GetForProfile(custodian()));
536 provider.SetAuthError(kTestGaiaId1, error); 536 provider.SetAuthError(kTestGaiaId1, error);
537 537
538 // Create a supervised profile. 538 // Create a supervised profile.
539 base::ListValue list_args; 539 base::ListValue list_args;
540 list_args.Clear(); 540 list_args.Clear();
541 list_args.Append(new base::StringValue(kSupervisedUsername1)); 541 list_args.AppendString(kSupervisedUsername1);
542 list_args.Append(new base::StringValue(profiles::GetDefaultAvatarIconUrl(0))); 542 list_args.AppendString(profiles::GetDefaultAvatarIconUrl(0));
543 list_args.Append(new base::FundamentalValue(false)); // create_shortcut 543 list_args.AppendBoolean(false); // create_shortcut
544 list_args.Append(new base::FundamentalValue(true)); // is_supervised 544 list_args.AppendBoolean(true); // is_supervised
545 list_args.Append(new base::StringValue("")); // supervised_user_id 545 list_args.AppendString(""); // supervised_user_id
546 list_args.Append(new base::StringValue(custodian()->GetPath().value())); 546 list_args.AppendString(custodian()->GetPath().value());
547 handler()->CreateProfile(&list_args); 547 handler()->CreateProfile(&list_args);
548 548
549 // Expect a JS callbacks containing an error message. 549 // Expect a JS callbacks containing an error message.
550 EXPECT_EQ(1U, web_ui()->call_data().size()); 550 EXPECT_EQ(1U, web_ui()->call_data().size());
551 551
552 EXPECT_EQ(kTestWebUIResponse, web_ui()->call_data()[0]->function_name()); 552 EXPECT_EQ(kTestWebUIResponse, web_ui()->call_data()[0]->function_name());
553 553
554 std::string callback_name; 554 std::string callback_name;
555 ASSERT_TRUE(web_ui()->call_data()[0]->arg1()->GetAsString(&callback_name)); 555 ASSERT_TRUE(web_ui()->call_data()[0]->arg1()->GetAsString(&callback_name));
556 EXPECT_EQ("create-profile-error", callback_name); 556 EXPECT_EQ("create-profile-error", callback_name);
557 557
558 base::string16 expected_error_message = l10n_util::GetStringUTF16( 558 base::string16 expected_error_message = l10n_util::GetStringUTF16(
559 IDS_PROFILES_CREATE_CUSTODIAN_ACCOUNT_DETAILS_OUT_OF_DATE_ERROR); 559 IDS_PROFILES_CREATE_CUSTODIAN_ACCOUNT_DETAILS_OUT_OF_DATE_ERROR);
560 base::string16 error_message; 560 base::string16 error_message;
561 ASSERT_TRUE(web_ui()->call_data()[0]->arg2()->GetAsString(&error_message)); 561 ASSERT_TRUE(web_ui()->call_data()[0]->arg2()->GetAsString(&error_message));
562 EXPECT_EQ(expected_error_message, error_message); 562 EXPECT_EQ(expected_error_message, error_message);
563 } 563 }
564 564
565 TEST_F(SigninCreateProfileHandlerTest, NotAllowedToCreateSupervisedUser) { 565 TEST_F(SigninCreateProfileHandlerTest, NotAllowedToCreateSupervisedUser) {
566 // Custodian is not permitted to create supervised users. 566 // Custodian is not permitted to create supervised users.
567 custodian()->GetPrefs()->SetBoolean(prefs::kSupervisedUserCreationAllowed, 567 custodian()->GetPrefs()->SetBoolean(prefs::kSupervisedUserCreationAllowed,
568 false); 568 false);
569 569
570 // Create a supervised profile. 570 // Create a supervised profile.
571 base::ListValue list_args; 571 base::ListValue list_args;
572 list_args.Clear(); 572 list_args.Clear();
573 list_args.Append(new base::StringValue(kSupervisedUsername1)); 573 list_args.AppendString(kSupervisedUsername1);
574 list_args.Append(new base::StringValue(profiles::GetDefaultAvatarIconUrl(0))); 574 list_args.AppendString(profiles::GetDefaultAvatarIconUrl(0));
575 list_args.Append(new base::FundamentalValue(false)); // create_shortcut 575 list_args.AppendBoolean(false); // create_shortcut
576 list_args.Append(new base::FundamentalValue(true)); // is_supervised 576 list_args.AppendBoolean(true); // is_supervised
577 list_args.Append(new base::StringValue("")); // supervised_user_id 577 list_args.AppendString(""); // supervised_user_id
578 list_args.Append(new base::StringValue(custodian()->GetPath().value())); 578 list_args.AppendString(custodian()->GetPath().value());
579 handler()->CreateProfile(&list_args); 579 handler()->CreateProfile(&list_args);
580 580
581 // Expect nothing to happen. 581 // Expect nothing to happen.
582 EXPECT_EQ(0U, web_ui()->call_data().size()); 582 EXPECT_EQ(0U, web_ui()->call_data().size());
583 } 583 }
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698