| OLD | NEW |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "base/command_line.h" | 5 #include "base/command_line.h" |
| 6 #include "base/macros.h" | 6 #include "base/macros.h" |
| 7 #include "base/memory/ptr_util.h" | 7 #include "base/memory/ptr_util.h" |
| 8 #include "base/memory/ref_counted.h" | 8 #include "base/memory/ref_counted.h" |
| 9 #include "base/run_loop.h" | 9 #include "base/run_loop.h" |
| 10 #include "base/strings/utf_string_conversions.h" | 10 #include "base/strings/utf_string_conversions.h" |
| 11 #include "build/build_config.h" | 11 #include "build/build_config.h" |
| 12 #include "chrome/browser/content_settings/cookie_settings_factory.h" | 12 #include "chrome/browser/content_settings/cookie_settings_factory.h" |
| 13 #include "chrome/browser/profiles/profile.h" |
| 14 #include "chrome/browser/profiles/profile_attributes_entry.h" |
| 15 #include "chrome/browser/profiles/profile_attributes_storage.h" |
| 16 #include "chrome/browser/profiles/profile_manager.h" |
| 13 #include "chrome/browser/signin/fake_profile_oauth2_token_service_builder.h" | 17 #include "chrome/browser/signin/fake_profile_oauth2_token_service_builder.h" |
| 14 #include "chrome/browser/signin/fake_signin_manager_builder.h" | 18 #include "chrome/browser/signin/fake_signin_manager_builder.h" |
| 15 #include "chrome/browser/signin/profile_oauth2_token_service_factory.h" | 19 #include "chrome/browser/signin/profile_oauth2_token_service_factory.h" |
| 16 #include "chrome/browser/signin/signin_manager_factory.h" | 20 #include "chrome/browser/signin/signin_manager_factory.h" |
| 17 #include "chrome/browser/signin/signin_promo.h" | 21 #include "chrome/browser/signin/signin_promo.h" |
| 18 #include "chrome/browser/ui/browser.h" | 22 #include "chrome/browser/ui/browser.h" |
| 23 #include "chrome/browser/ui/browser_list.h" |
| 19 #include "chrome/browser/ui/tabs/tab_strip_model.h" | 24 #include "chrome/browser/ui/tabs/tab_strip_model.h" |
| 20 #include "chrome/browser/ui/webui/signin/inline_login_handler_impl.h" | 25 #include "chrome/browser/ui/webui/signin/inline_login_handler_impl.h" |
| 21 #include "chrome/browser/ui/webui/signin/inline_login_ui.h" | 26 #include "chrome/browser/ui/webui/signin/inline_login_ui.h" |
| 22 #include "chrome/browser/ui/webui/signin/login_ui_service.h" | 27 #include "chrome/browser/ui/webui/signin/login_ui_service.h" |
| 23 #include "chrome/browser/ui/webui/signin/login_ui_service_factory.h" | 28 #include "chrome/browser/ui/webui/signin/login_ui_service_factory.h" |
| 24 #include "chrome/browser/ui/webui/signin/login_ui_test_utils.h" | 29 #include "chrome/browser/ui/webui/signin/login_ui_test_utils.h" |
| 25 #include "chrome/common/chrome_switches.h" | 30 #include "chrome/common/chrome_switches.h" |
| 26 #include "chrome/common/url_constants.h" | 31 #include "chrome/common/url_constants.h" |
| 27 #include "chrome/grit/chromium_strings.h" | 32 #include "chrome/grit/chromium_strings.h" |
| 28 #include "chrome/grit/generated_resources.h" | 33 #include "chrome/grit/generated_resources.h" |
| (...skipping 154 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 183 profile, | 188 profile, |
| 184 Profile::CreateStatus::CREATE_STATUS_INITIALIZED, | 189 Profile::CreateStatus::CREATE_STATUS_INITIALIZED, |
| 185 current_url, | 190 current_url, |
| 186 email, | 191 email, |
| 187 gaia_id, | 192 gaia_id, |
| 188 password, | 193 password, |
| 189 session_index, | 194 session_index, |
| 190 auth_code, | 195 auth_code, |
| 191 signin_scoped_device_id, | 196 signin_scoped_device_id, |
| 192 choose_what_to_sync, | 197 choose_what_to_sync, |
| 193 confirm_untrusted_signin) {} | 198 confirm_untrusted_signin, |
| 199 false) {} |
| 194 | 200 |
| 195 // This class is used to mock out virtual methods with side effects so that | 201 // This class is used to mock out virtual methods with side effects so that |
| 196 // tests below can ensure they are called without causing side effects. | 202 // tests below can ensure they are called without causing side effects. |
| 197 class MockSyncStarterInlineSigninHelper : public InlineSigninHelper { | 203 class MockSyncStarterInlineSigninHelper : public InlineSigninHelper { |
| 198 public: | 204 public: |
| 199 MockSyncStarterInlineSigninHelper( | 205 MockSyncStarterInlineSigninHelper( |
| 200 base::WeakPtr<InlineLoginHandlerImpl> handler, | 206 base::WeakPtr<InlineLoginHandlerImpl> handler, |
| 201 net::URLRequestContextGetter* getter, | 207 net::URLRequestContextGetter* getter, |
| 202 Profile* profile, | 208 Profile* profile, |
| 203 const GURL& current_url, | 209 const GURL& current_url, |
| 204 const std::string& email, | 210 const std::string& email, |
| 205 const std::string& gaia_id, | 211 const std::string& gaia_id, |
| 206 const std::string& password, | 212 const std::string& password, |
| 207 const std::string& session_index, | 213 const std::string& session_index, |
| 208 const std::string& auth_code, | 214 const std::string& auth_code, |
| 209 const std::string& signin_scoped_device_id, | 215 const std::string& signin_scoped_device_id, |
| 210 bool choose_what_to_sync, | 216 bool choose_what_to_sync, |
| 211 bool confirm_untrusted_signin); | 217 bool confirm_untrusted_signin, |
| 218 bool is_force_sign_in_with_usermanager); |
| 212 | 219 |
| 213 MOCK_METHOD8(CreateSyncStarter, | 220 MOCK_METHOD8(CreateSyncStarter, |
| 214 void(Browser*, | 221 void(Browser*, |
| 215 content::WebContents*, | 222 content::WebContents*, |
| 216 const GURL&, | 223 const GURL&, |
| 217 const GURL&, | 224 const GURL&, |
| 218 const std::string&, | 225 const std::string&, |
| 219 OneClickSigninSyncStarter::ProfileMode, | 226 OneClickSigninSyncStarter::ProfileMode, |
| 220 OneClickSigninSyncStarter::StartSyncMode, | 227 OneClickSigninSyncStarter::StartSyncMode, |
| 221 OneClickSigninSyncStarter::ConfirmationRequired)); | 228 OneClickSigninSyncStarter::ConfirmationRequired)); |
| 222 | 229 |
| 223 private: | 230 private: |
| 224 DISALLOW_COPY_AND_ASSIGN(MockSyncStarterInlineSigninHelper); | 231 DISALLOW_COPY_AND_ASSIGN(MockSyncStarterInlineSigninHelper); |
| 225 }; | 232 }; |
| 226 | 233 |
| 227 MockSyncStarterInlineSigninHelper::MockSyncStarterInlineSigninHelper( | 234 MockSyncStarterInlineSigninHelper::MockSyncStarterInlineSigninHelper( |
| 228 base::WeakPtr<InlineLoginHandlerImpl> handler, | 235 base::WeakPtr<InlineLoginHandlerImpl> handler, |
| 229 net::URLRequestContextGetter* getter, | 236 net::URLRequestContextGetter* getter, |
| 230 Profile* profile, | 237 Profile* profile, |
| 231 const GURL& current_url, | 238 const GURL& current_url, |
| 232 const std::string& email, | 239 const std::string& email, |
| 233 const std::string& gaia_id, | 240 const std::string& gaia_id, |
| 234 const std::string& password, | 241 const std::string& password, |
| 235 const std::string& session_index, | 242 const std::string& session_index, |
| 236 const std::string& auth_code, | 243 const std::string& auth_code, |
| 237 const std::string& signin_scoped_device_id, | 244 const std::string& signin_scoped_device_id, |
| 238 bool choose_what_to_sync, | 245 bool choose_what_to_sync, |
| 239 bool confirm_untrusted_signin) | 246 bool confirm_untrusted_signin, |
| 247 bool is_force_sign_in_with_usermanager) |
| 240 : InlineSigninHelper(handler, | 248 : InlineSigninHelper(handler, |
| 241 getter, | 249 getter, |
| 242 profile, | 250 profile, |
| 243 Profile::CreateStatus::CREATE_STATUS_INITIALIZED, | 251 Profile::CreateStatus::CREATE_STATUS_INITIALIZED, |
| 244 current_url, | 252 current_url, |
| 245 email, | 253 email, |
| 246 gaia_id, | 254 gaia_id, |
| 247 password, | 255 password, |
| 248 session_index, | 256 session_index, |
| 249 auth_code, | 257 auth_code, |
| 250 signin_scoped_device_id, | 258 signin_scoped_device_id, |
| 251 choose_what_to_sync, | 259 choose_what_to_sync, |
| 252 confirm_untrusted_signin) {} | 260 confirm_untrusted_signin, |
| 261 is_force_sign_in_with_usermanager) {} |
| 253 | 262 |
| 254 } // namespace | 263 } // namespace |
| 255 | 264 |
| 256 class InlineLoginUIBrowserTest : public InProcessBrowserTest { | 265 class InlineLoginUIBrowserTest : public InProcessBrowserTest { |
| 257 public: | 266 public: |
| 258 InlineLoginUIBrowserTest() {} | 267 InlineLoginUIBrowserTest() {} |
| 259 | 268 |
| 260 void SetUpSigninManager(const std::string& username); | 269 void SetUpSigninManager(const std::string& username); |
| 261 void EnableSigninAllowed(bool enable); | 270 void EnableSigninAllowed(bool enable); |
| 262 void EnableOneClick(bool enable); | 271 void EnableOneClick(bool enable); |
| (...skipping 310 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 573 SigninCreatesSyncStarter1) { | 582 SigninCreatesSyncStarter1) { |
| 574 // See Source enum in components/signin/core/browser/signin_metrics.h for | 583 // See Source enum in components/signin/core/browser/signin_metrics.h for |
| 575 // possible values of access_point=, reason=. | 584 // possible values of access_point=, reason=. |
| 576 GURL url("chrome://chrome-signin/?access_point=0&reason=0"); | 585 GURL url("chrome://chrome-signin/?access_point=0&reason=0"); |
| 577 base::WeakPtr<InlineLoginHandlerImpl> handler; | 586 base::WeakPtr<InlineLoginHandlerImpl> handler; |
| 578 // MockSyncStarterInlineSigninHelper will delete itself when done using | 587 // MockSyncStarterInlineSigninHelper will delete itself when done using |
| 579 // base::ThreadTaskRunnerHandle::DeleteSoon(), so need to delete here. But | 588 // base::ThreadTaskRunnerHandle::DeleteSoon(), so need to delete here. But |
| 580 // do need the RunUntilIdle() at the end. | 589 // do need the RunUntilIdle() at the end. |
| 581 MockSyncStarterInlineSigninHelper* helper = | 590 MockSyncStarterInlineSigninHelper* helper = |
| 582 new MockSyncStarterInlineSigninHelper( | 591 new MockSyncStarterInlineSigninHelper( |
| 583 handler, | 592 handler, browser()->profile()->GetRequestContext(), |
| 584 browser()->profile()->GetRequestContext(), | 593 browser()->profile(), url, "foo@gmail.com", "gaiaid-12345", |
| 585 browser()->profile(), | |
| 586 url, | |
| 587 "foo@gmail.com", | |
| 588 "gaiaid-12345", | |
| 589 "password", | 594 "password", |
| 590 "", // session index | 595 "", // session index |
| 591 "auth_code", // auth code | 596 "auth_code", // auth code |
| 592 std::string(), | 597 std::string(), |
| 593 false, // choose what to sync | 598 false, // choose what to sync |
| 594 false); // confirm untrusted signin | 599 false, // confirm untrusted signin |
| 600 false); |
| 595 EXPECT_CALL( | 601 EXPECT_CALL( |
| 596 *helper, | 602 *helper, |
| 597 CreateSyncStarter(_, _, _, _, "refresh_token", | 603 CreateSyncStarter(_, _, _, _, "refresh_token", |
| 598 OneClickSigninSyncStarter::CURRENT_PROFILE, | 604 OneClickSigninSyncStarter::CURRENT_PROFILE, |
| 599 OneClickSigninSyncStarter::CONFIRM_SYNC_SETTINGS_FIRST, | 605 OneClickSigninSyncStarter::CONFIRM_SYNC_SETTINGS_FIRST, |
| 600 OneClickSigninSyncStarter::CONFIRM_AFTER_SIGNIN)); | 606 OneClickSigninSyncStarter::CONFIRM_AFTER_SIGNIN)); |
| 601 | 607 |
| 608 ProfileAttributesEntry* entry; |
| 609 ASSERT_TRUE(g_browser_process->profile_manager() |
| 610 ->GetProfileAttributesStorage() |
| 611 .GetProfileAttributesWithPath(browser()->profile()->GetPath(), |
| 612 &entry)); |
| 613 entry->SetIsSigninRequired(true); |
| 614 |
| 615 ASSERT_EQ(1ul, BrowserList::GetInstance()->size()); |
| 602 SimulateOnClientOAuthSuccess(helper, "refresh_token"); | 616 SimulateOnClientOAuthSuccess(helper, "refresh_token"); |
| 603 base::RunLoop().RunUntilIdle(); | 617 base::RunLoop().RunUntilIdle(); |
| 618 ASSERT_EQ(1ul, BrowserList::GetInstance()->size()); |
| 619 // if |force_sign_in_with_user_manager| is false, the profile should be |
| 620 // unlocked early and InlineLoginHelper won't try to do it again |
| 621 ASSERT_TRUE(entry->IsSigninRequired()); |
| 604 } | 622 } |
| 605 | 623 |
| 606 // Test signin helper creates sync starter with correct confirmation when | 624 // Test signin helper creates sync starter with correct confirmation when |
| 607 // signing in and choosing what to sync first. | 625 // signing in and choosing what to sync first. |
| 608 IN_PROC_BROWSER_TEST_F(InlineLoginHelperBrowserTest, | 626 IN_PROC_BROWSER_TEST_F(InlineLoginHelperBrowserTest, |
| 609 SigninCreatesSyncStarter2) { | 627 SigninCreatesSyncStarter2) { |
| 610 // See Source enum in components/signin/core/browser/signin_metrics.h for | 628 // See Source enum in components/signin/core/browser/signin_metrics.h for |
| 611 // possible values of access_point=, reason=. | 629 // possible values of access_point=, reason=. |
| 612 const GURL url("chrome://chrome-signin/?access_point=0&reason=0"); | 630 const GURL url("chrome://chrome-signin/?access_point=0&reason=0"); |
| 613 base::WeakPtr<InlineLoginHandlerImpl> handler; | 631 base::WeakPtr<InlineLoginHandlerImpl> handler; |
| 614 // MockSyncStarterInlineSigninHelper will delete itself when done using | 632 // MockSyncStarterInlineSigninHelper will delete itself when done using |
| 615 // base::ThreadTaskRunnerHandle::DeleteSoon(), so need to delete here. But | 633 // base::ThreadTaskRunnerHandle::DeleteSoon(), so need to delete here. But |
| 616 // do need the RunUntilIdle() at the end. | 634 // do need the RunUntilIdle() at the end. |
| 617 MockSyncStarterInlineSigninHelper* helper = | 635 MockSyncStarterInlineSigninHelper* helper = |
| 618 new MockSyncStarterInlineSigninHelper( | 636 new MockSyncStarterInlineSigninHelper( |
| 619 handler, | 637 handler, browser()->profile()->GetRequestContext(), |
| 620 browser()->profile()->GetRequestContext(), | 638 browser()->profile(), url, "foo@gmail.com", "gaiaid-12345", |
| 621 browser()->profile(), | |
| 622 url, | |
| 623 "foo@gmail.com", | |
| 624 "gaiaid-12345", | |
| 625 "password", | 639 "password", |
| 626 "", // session index | 640 "", // session index |
| 627 "auth_code", // auth code | 641 "auth_code", // auth code |
| 628 std::string(), | 642 std::string(), |
| 629 true, // choose what to sync | 643 true, // choose what to sync |
| 630 false); // confirm untrusted signin | 644 false, // confirm untrusted signin |
| 645 false); |
| 631 EXPECT_CALL(*helper, CreateSyncStarter( | 646 EXPECT_CALL(*helper, CreateSyncStarter( |
| 632 _, _, _, _, "refresh_token", | 647 _, _, _, _, "refresh_token", |
| 633 OneClickSigninSyncStarter::CURRENT_PROFILE, | 648 OneClickSigninSyncStarter::CURRENT_PROFILE, |
| 634 OneClickSigninSyncStarter::CONFIGURE_SYNC_FIRST, | 649 OneClickSigninSyncStarter::CONFIGURE_SYNC_FIRST, |
| 635 OneClickSigninSyncStarter::CONFIRM_AFTER_SIGNIN)); | 650 OneClickSigninSyncStarter::CONFIRM_AFTER_SIGNIN)); |
| 636 | 651 |
| 637 SimulateOnClientOAuthSuccess(helper, "refresh_token"); | 652 SimulateOnClientOAuthSuccess(helper, "refresh_token"); |
| 638 base::RunLoop().RunUntilIdle(); | 653 base::RunLoop().RunUntilIdle(); |
| 639 } | 654 } |
| 640 | 655 |
| 641 // Test signin helper creates sync starter with correct confirmation when | 656 // Test signin helper creates sync starter with correct confirmation when |
| 642 // signing in with an untrusted sign occurs. | 657 // signing in with an untrusted sign occurs. |
| 643 IN_PROC_BROWSER_TEST_F(InlineLoginHelperBrowserTest, | 658 IN_PROC_BROWSER_TEST_F(InlineLoginHelperBrowserTest, |
| 644 SigninCreatesSyncStarter3) { | 659 SigninCreatesSyncStarter3) { |
| 645 // See Source enum in components/signin/core/browser/signin_metrics.h for | 660 // See Source enum in components/signin/core/browser/signin_metrics.h for |
| 646 // possible values of access_point=, reason=. | 661 // possible values of access_point=, reason=. |
| 647 GURL url("chrome://chrome-signin/?access_point=0&reason=0"); | 662 GURL url("chrome://chrome-signin/?access_point=0&reason=0"); |
| 648 base::WeakPtr<InlineLoginHandlerImpl> handler; | 663 base::WeakPtr<InlineLoginHandlerImpl> handler; |
| 649 // MockSyncStarterInlineSigninHelper will delete itself when done using | 664 // MockSyncStarterInlineSigninHelper will delete itself when done using |
| 650 // base::ThreadTaskRunnerHandle::DeleteSoon(), so need to delete here. But | 665 // base::ThreadTaskRunnerHandle::DeleteSoon(), so need to delete here. But |
| 651 // do need the RunUntilIdle() at the end. | 666 // do need the RunUntilIdle() at the end. |
| 652 MockSyncStarterInlineSigninHelper* helper = | 667 MockSyncStarterInlineSigninHelper* helper = |
| 653 new MockSyncStarterInlineSigninHelper( | 668 new MockSyncStarterInlineSigninHelper( |
| 654 handler, | 669 handler, browser()->profile()->GetRequestContext(), |
| 655 browser()->profile()->GetRequestContext(), | 670 browser()->profile(), url, "foo@gmail.com", "gaiaid-12345", |
| 656 browser()->profile(), | |
| 657 url, | |
| 658 "foo@gmail.com", | |
| 659 "gaiaid-12345", | |
| 660 "password", | 671 "password", |
| 661 "", // session index | 672 "", // session index |
| 662 "auth_code", // auth code | 673 "auth_code", // auth code |
| 663 std::string(), | 674 std::string(), |
| 664 false, // choose what to sync | 675 false, // choose what to sync |
| 665 true); // confirm untrusted signin | 676 true, // confirm untrusted signin |
| 677 false); |
| 666 EXPECT_CALL( | 678 EXPECT_CALL( |
| 667 *helper, | 679 *helper, |
| 668 CreateSyncStarter(_, _, _, _, "refresh_token", | 680 CreateSyncStarter(_, _, _, _, "refresh_token", |
| 669 OneClickSigninSyncStarter::CURRENT_PROFILE, | 681 OneClickSigninSyncStarter::CURRENT_PROFILE, |
| 670 OneClickSigninSyncStarter::CONFIRM_SYNC_SETTINGS_FIRST, | 682 OneClickSigninSyncStarter::CONFIRM_SYNC_SETTINGS_FIRST, |
| 671 OneClickSigninSyncStarter::CONFIRM_UNTRUSTED_SIGNIN)); | 683 OneClickSigninSyncStarter::CONFIRM_UNTRUSTED_SIGNIN)); |
| 672 | 684 |
| 673 SimulateOnClientOAuthSuccess(helper, "refresh_token"); | 685 SimulateOnClientOAuthSuccess(helper, "refresh_token"); |
| 674 base::RunLoop().RunUntilIdle(); | 686 base::RunLoop().RunUntilIdle(); |
| 675 } | 687 } |
| 676 | 688 |
| 677 // Test signin helper creates sync starter with correct confirmation during | 689 // Test signin helper creates sync starter with correct confirmation during |
| 678 // re-auth. | 690 // re-auth. |
| 679 IN_PROC_BROWSER_TEST_F(InlineLoginHelperBrowserTest, | 691 IN_PROC_BROWSER_TEST_F(InlineLoginHelperBrowserTest, |
| 680 SigninCreatesSyncStarter4) { | 692 SigninCreatesSyncStarter4) { |
| 681 // See Source enum in components/signin/core/browser/signin_metrics.h for | 693 // See Source enum in components/signin/core/browser/signin_metrics.h for |
| 682 // possible values of access_point=, reason=. | 694 // possible values of access_point=, reason=. |
| 683 const GURL url("chrome://chrome-signin/?access_point=3&reason=0"); | 695 const GURL url("chrome://chrome-signin/?access_point=3&reason=0"); |
| 684 base::WeakPtr<InlineLoginHandlerImpl> handler; | 696 base::WeakPtr<InlineLoginHandlerImpl> handler; |
| 685 // MockSyncStarterInlineSigninHelper will delete itself when done using | 697 // MockSyncStarterInlineSigninHelper will delete itself when done using |
| 686 // base::ThreadTaskRunnerHandle::DeleteSoon(), so need to delete here. But | 698 // base::ThreadTaskRunnerHandle::DeleteSoon(), so need to delete here. But |
| 687 // do need the RunUntilIdle() at the end. | 699 // do need the RunUntilIdle() at the end. |
| 688 MockSyncStarterInlineSigninHelper* helper = | 700 MockSyncStarterInlineSigninHelper* helper = |
| 689 new MockSyncStarterInlineSigninHelper( | 701 new MockSyncStarterInlineSigninHelper( |
| 690 handler, | 702 handler, browser()->profile()->GetRequestContext(), |
| 691 browser()->profile()->GetRequestContext(), | 703 browser()->profile(), url, "foo@gmail.com", "gaiaid-12345", |
| 692 browser()->profile(), | |
| 693 url, | |
| 694 "foo@gmail.com", | |
| 695 "gaiaid-12345", | |
| 696 "password", | 704 "password", |
| 697 "", // session index | 705 "", // session index |
| 698 "auth_code", // auth code | 706 "auth_code", // auth code |
| 699 std::string(), | 707 std::string(), |
| 700 false, // choose what to sync | 708 false, // choose what to sync |
| 701 false); // confirm untrusted signin | 709 false, // confirm untrusted signin |
| 710 false); |
| 702 | 711 |
| 703 // Even though "choose what to sync" is false, the source of the URL is | 712 // Even though "choose what to sync" is false, the source of the URL is |
| 704 // settings, which means the user wants to CONFIGURE_SYNC_FIRST. | 713 // settings, which means the user wants to CONFIGURE_SYNC_FIRST. |
| 705 EXPECT_CALL(*helper, CreateSyncStarter( | 714 EXPECT_CALL(*helper, CreateSyncStarter( |
| 706 _, _, _, _, "refresh_token", | 715 _, _, _, _, "refresh_token", |
| 707 OneClickSigninSyncStarter::CURRENT_PROFILE, | 716 OneClickSigninSyncStarter::CURRENT_PROFILE, |
| 708 OneClickSigninSyncStarter::CONFIGURE_SYNC_FIRST, | 717 OneClickSigninSyncStarter::CONFIGURE_SYNC_FIRST, |
| 709 OneClickSigninSyncStarter::CONFIRM_AFTER_SIGNIN)); | 718 OneClickSigninSyncStarter::CONFIRM_AFTER_SIGNIN)); |
| 710 | 719 |
| 711 SimulateOnClientOAuthSuccess(helper, "refresh_token"); | 720 SimulateOnClientOAuthSuccess(helper, "refresh_token"); |
| 712 base::RunLoop().RunUntilIdle(); | 721 base::RunLoop().RunUntilIdle(); |
| 713 } | 722 } |
| 714 | 723 |
| 715 // Test signin helper does not create sync starter when reauthenticating. | 724 // Test signin helper does not create sync starter when reauthenticating. |
| 716 IN_PROC_BROWSER_TEST_F(InlineLoginHelperBrowserTest, | 725 IN_PROC_BROWSER_TEST_F(InlineLoginHelperBrowserTest, |
| 717 ReauthCallsUpdateCredentials) { | 726 ReauthCallsUpdateCredentials) { |
| 718 ASSERT_EQ(0ul, token_service()->GetAccounts().size()); | 727 ASSERT_EQ(0ul, token_service()->GetAccounts().size()); |
| 719 | 728 |
| 720 // See Source enum in components/signin/core/browser/signin_metrics.h for | 729 // See Source enum in components/signin/core/browser/signin_metrics.h for |
| 721 // possible values of access_point=, reason=. | 730 // possible values of access_point=, reason=. |
| 722 GURL url("chrome://chrome-signin/?access_point=3&reason=2"); | 731 GURL url("chrome://chrome-signin/?access_point=3&reason=2"); |
| 723 base::WeakPtr<InlineLoginHandlerImpl> handler; | 732 base::WeakPtr<InlineLoginHandlerImpl> handler; |
| 724 InlineSigninHelper helper(handler, browser()->profile()->GetRequestContext(), | 733 InlineSigninHelper helper(handler, browser()->profile()->GetRequestContext(), |
| 725 browser()->profile(), | 734 browser()->profile(), |
| 726 Profile::CreateStatus::CREATE_STATUS_INITIALIZED, | 735 Profile::CreateStatus::CREATE_STATUS_INITIALIZED, |
| 727 url, "foo@gmail.com", "gaiaid-12345", "password", | 736 url, "foo@gmail.com", "gaiaid-12345", "password", |
| 728 "", // session index | 737 "", // session index |
| 729 "auth_code", // auth code | 738 "auth_code", // auth code |
| 730 std::string(), | 739 std::string(), |
| 731 false, // choose what to sync | 740 false, // choose what to sync |
| 732 false); // confirm untrusted signin | 741 false, // confirm untrusted signin |
| 742 false); |
| 733 SimulateOnClientOAuthSuccess(&helper, "refresh_token"); | 743 SimulateOnClientOAuthSuccess(&helper, "refresh_token"); |
| 734 ASSERT_EQ(1ul, token_service()->GetAccounts().size()); | 744 ASSERT_EQ(1ul, token_service()->GetAccounts().size()); |
| 735 base::RunLoop().RunUntilIdle(); | 745 base::RunLoop().RunUntilIdle(); |
| 736 } | 746 } |
| 737 | 747 |
| 738 // Test signin helper does not create sync starter when adding another account | 748 // Test signin helper does not create sync starter when adding another account |
| 739 // to profile. | 749 // to profile. |
| 740 IN_PROC_BROWSER_TEST_F(InlineLoginHelperBrowserTest, | 750 IN_PROC_BROWSER_TEST_F(InlineLoginHelperBrowserTest, |
| 741 AddAccountsCallsUpdateCredentials) { | 751 AddAccountsCallsUpdateCredentials) { |
| 742 ASSERT_EQ(0ul, token_service()->GetAccounts().size()); | 752 ASSERT_EQ(0ul, token_service()->GetAccounts().size()); |
| 743 | 753 |
| 744 // See Source enum in components/signin/core/browser/signin_metrics.h for | 754 // See Source enum in components/signin/core/browser/signin_metrics.h for |
| 745 // possible values of access_point=, reason=. | 755 // possible values of access_point=, reason=. |
| 746 GURL url("chrome://chrome-signin/?access_point=10&reason=1"); | 756 GURL url("chrome://chrome-signin/?access_point=10&reason=1"); |
| 747 base::WeakPtr<InlineLoginHandlerImpl> handler; | 757 base::WeakPtr<InlineLoginHandlerImpl> handler; |
| 748 InlineSigninHelper helper(handler, browser()->profile()->GetRequestContext(), | 758 InlineSigninHelper helper(handler, browser()->profile()->GetRequestContext(), |
| 749 browser()->profile(), | 759 browser()->profile(), |
| 750 Profile::CreateStatus::CREATE_STATUS_INITIALIZED, | 760 Profile::CreateStatus::CREATE_STATUS_INITIALIZED, |
| 751 url, "foo@gmail.com", "gaiaid-12345", "password", | 761 url, "foo@gmail.com", "gaiaid-12345", "password", |
| 752 "", // session index | 762 "", // session index |
| 753 "auth_code", // auth code | 763 "auth_code", // auth code |
| 754 std::string(), | 764 std::string(), |
| 755 false, // choose what to sync | 765 false, // choose what to sync |
| 756 false); // confirm untrusted signin | 766 false, // confirm untrusted signin |
| 767 false); |
| 757 SimulateOnClientOAuthSuccess(&helper, "refresh_token"); | 768 SimulateOnClientOAuthSuccess(&helper, "refresh_token"); |
| 758 ASSERT_EQ(1ul, token_service()->GetAccounts().size()); | 769 ASSERT_EQ(1ul, token_service()->GetAccounts().size()); |
| 759 base::RunLoop().RunUntilIdle(); | 770 base::RunLoop().RunUntilIdle(); |
| 760 } | 771 } |
| 761 | 772 |
| 773 IN_PROC_BROWSER_TEST_F(InlineLoginHelperBrowserTest, |
| 774 ForceSigninWithUserManager) { |
| 775 GURL url("chrome://chrome-signin/?access_point=0&reason=0"); |
| 776 base::WeakPtr<InlineLoginHandlerImpl> handler; |
| 777 // MockSyncStarterInlineSigninHelper will delete itself when done using |
| 778 // base::ThreadTaskRunnerHandle::DeleteSoon(), so need to delete here. But |
| 779 // do need the RunUntilIdle() at the end. |
| 780 MockSyncStarterInlineSigninHelper* helper = |
| 781 new MockSyncStarterInlineSigninHelper( |
| 782 handler, browser()->profile()->GetRequestContext(), |
| 783 browser()->profile(), url, "foo@gmail.com", "gaiaid-12345", |
| 784 "password", "", "auth_code", std::string(), false, false, true); |
| 785 EXPECT_CALL( |
| 786 *helper, |
| 787 CreateSyncStarter(_, _, _, _, "refresh_token", |
| 788 OneClickSigninSyncStarter::CURRENT_PROFILE, |
| 789 OneClickSigninSyncStarter::CONFIRM_SYNC_SETTINGS_FIRST, |
| 790 OneClickSigninSyncStarter::CONFIRM_AFTER_SIGNIN)); |
| 791 |
| 792 ProfileAttributesEntry* entry; |
| 793 ASSERT_TRUE(g_browser_process->profile_manager() |
| 794 ->GetProfileAttributesStorage() |
| 795 .GetProfileAttributesWithPath(browser()->profile()->GetPath(), |
| 796 &entry)); |
| 797 entry->SetIsSigninRequired(true); |
| 798 |
| 799 ASSERT_EQ(1ul, BrowserList::GetInstance()->size()); |
| 800 SimulateOnClientOAuthSuccess(helper, "refresh_token"); |
| 801 base::RunLoop().RunUntilIdle(); |
| 802 ASSERT_EQ(2ul, BrowserList::GetInstance()->size()); |
| 803 ASSERT_FALSE(entry->IsSigninRequired()); |
| 804 } |
| 805 |
| 762 class InlineLoginUISafeIframeBrowserTest : public InProcessBrowserTest { | 806 class InlineLoginUISafeIframeBrowserTest : public InProcessBrowserTest { |
| 763 public: | 807 public: |
| 764 FooWebUIProvider& foo_provider() { return foo_provider_; } | 808 FooWebUIProvider& foo_provider() { return foo_provider_; } |
| 765 | 809 |
| 766 private: | 810 private: |
| 767 void SetUp() override { | 811 void SetUp() override { |
| 768 // Don't spin up the IO thread yet since no threads are allowed while | 812 // Don't spin up the IO thread yet since no threads are allowed while |
| 769 // spawning sandbox host process. See crbug.com/322732. | 813 // spawning sandbox host process. See crbug.com/322732. |
| 770 ASSERT_TRUE(embedded_test_server()->InitializeAndListen()); | 814 ASSERT_TRUE(embedded_test_server()->InitializeAndListen()); |
| 771 | 815 |
| (...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 851 content::WebContents* contents = | 895 content::WebContents* contents = |
| 852 browser()->tab_strip_model()->GetActiveWebContents(); | 896 browser()->tab_strip_model()->GetActiveWebContents(); |
| 853 ASSERT_TRUE(content::ExecuteScript( | 897 ASSERT_TRUE(content::ExecuteScript( |
| 854 contents, "window.location.href = 'chrome://foo'")); | 898 contents, "window.location.href = 'chrome://foo'")); |
| 855 | 899 |
| 856 content::TestNavigationObserver navigation_observer(contents, 1); | 900 content::TestNavigationObserver navigation_observer(contents, 1); |
| 857 navigation_observer.Wait(); | 901 navigation_observer.Wait(); |
| 858 | 902 |
| 859 EXPECT_EQ(GURL("about:blank"), contents->GetVisibleURL()); | 903 EXPECT_EQ(GURL("about:blank"), contents->GetVisibleURL()); |
| 860 } | 904 } |
| OLD | NEW |