| 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/prefs/pref_service.h" | 6 #include "base/prefs/pref_service.h" |
| 7 #include "base/prefs/scoped_user_pref_update.h" | 7 #include "base/prefs/scoped_user_pref_update.h" |
| 8 #include "base/strings/utf_string_conversions.h" | 8 #include "base/strings/utf_string_conversions.h" |
| 9 #include "chrome/browser/content_settings/cookie_settings_factory.h" | 9 #include "chrome/browser/content_settings/cookie_settings_factory.h" |
| 10 #include "chrome/browser/signin/fake_profile_oauth2_token_service_builder.h" |
| 11 #include "chrome/browser/signin/fake_signin_manager_builder.h" |
| 12 #include "chrome/browser/signin/profile_oauth2_token_service_factory.h" |
| 10 #include "chrome/browser/signin/signin_manager_factory.h" | 13 #include "chrome/browser/signin/signin_manager_factory.h" |
| 11 #include "chrome/browser/signin/signin_promo.h" | 14 #include "chrome/browser/signin/signin_promo.h" |
| 12 #include "chrome/browser/ui/browser.h" | 15 #include "chrome/browser/ui/browser.h" |
| 13 #include "chrome/browser/ui/tabs/tab_strip_model.h" | 16 #include "chrome/browser/ui/tabs/tab_strip_model.h" |
| 14 #include "chrome/browser/ui/webui/signin/inline_login_handler_impl.h" | 17 #include "chrome/browser/ui/webui/signin/inline_login_handler_impl.h" |
| 15 #include "chrome/browser/ui/webui/signin/inline_login_ui.h" | 18 #include "chrome/browser/ui/webui/signin/inline_login_ui.h" |
| 16 #include "chrome/browser/ui/webui/signin/login_ui_service.h" | 19 #include "chrome/browser/ui/webui/signin/login_ui_service.h" |
| 17 #include "chrome/browser/ui/webui/signin/login_ui_service_factory.h" | 20 #include "chrome/browser/ui/webui/signin/login_ui_service_factory.h" |
| 18 #include "chrome/browser/ui/webui/signin/login_ui_test_utils.h" | 21 #include "chrome/browser/ui/webui/signin/login_ui_test_utils.h" |
| 19 #include "chrome/common/chrome_switches.h" | 22 #include "chrome/common/chrome_switches.h" |
| 20 #include "chrome/common/url_constants.h" | 23 #include "chrome/common/url_constants.h" |
| 21 #include "chrome/grit/chromium_strings.h" | 24 #include "chrome/grit/chromium_strings.h" |
| 22 #include "chrome/grit/generated_resources.h" | 25 #include "chrome/grit/generated_resources.h" |
| 23 #include "chrome/test/base/in_process_browser_test.h" | 26 #include "chrome/test/base/in_process_browser_test.h" |
| 24 #include "chrome/test/base/test_browser_window.h" | 27 #include "chrome/test/base/test_browser_window.h" |
| 25 #include "chrome/test/base/test_chrome_web_ui_controller_factory.h" | 28 #include "chrome/test/base/test_chrome_web_ui_controller_factory.h" |
| 26 #include "chrome/test/base/testing_browser_process.h" | 29 #include "chrome/test/base/testing_browser_process.h" |
| 27 #include "chrome/test/base/ui_test_utils.h" | 30 #include "chrome/test/base/ui_test_utils.h" |
| 28 #include "components/content_settings/core/browser/cookie_settings.h" | 31 #include "components/content_settings/core/browser/cookie_settings.h" |
| 29 #include "components/guest_view/browser/guest_view_manager.h" | 32 #include "components/guest_view/browser/guest_view_manager.h" |
| 33 #include "components/keyed_service/content/browser_context_dependency_manager.h" |
| 34 #include "components/signin/core/browser/fake_profile_oauth2_token_service.h" |
| 30 #include "components/signin/core/browser/signin_manager.h" | 35 #include "components/signin/core/browser/signin_manager.h" |
| 31 #include "components/signin/core/common/profile_management_switches.h" | 36 #include "components/signin/core/common/profile_management_switches.h" |
| 32 #include "components/signin/core/common/signin_pref_names.h" | 37 #include "components/signin/core/common/signin_pref_names.h" |
| 33 #include "content/public/browser/render_frame_host.h" | 38 #include "content/public/browser/render_frame_host.h" |
| 34 #include "content/public/browser/render_process_host.h" | 39 #include "content/public/browser/render_process_host.h" |
| 35 #include "content/public/browser/session_storage_namespace.h" | 40 #include "content/public/browser/session_storage_namespace.h" |
| 36 #include "content/public/browser/storage_partition.h" | 41 #include "content/public/browser/storage_partition.h" |
| 37 #include "content/public/browser/web_contents.h" | 42 #include "content/public/browser/web_contents.h" |
| 38 #include "content/public/browser/web_ui_controller.h" | 43 #include "content/public/browser/web_ui_controller.h" |
| 39 #include "content/public/common/url_constants.h" | 44 #include "content/public/common/url_constants.h" |
| 40 #include "content/public/test/browser_test_utils.h" | 45 #include "content/public/test/browser_test_utils.h" |
| 41 #include "content/public/test/test_navigation_observer.h" | 46 #include "content/public/test/test_navigation_observer.h" |
| 42 #include "google_apis/gaia/fake_gaia.h" | 47 #include "google_apis/gaia/fake_gaia.h" |
| 43 #include "google_apis/gaia/gaia_switches.h" | 48 #include "google_apis/gaia/gaia_switches.h" |
| 49 #include "google_apis/gaia/gaia_urls.h" |
| 44 #include "net/base/url_util.h" | 50 #include "net/base/url_util.h" |
| 45 #include "net/test/embedded_test_server/embedded_test_server.h" | 51 #include "net/test/embedded_test_server/embedded_test_server.h" |
| 46 #include "net/test/embedded_test_server/http_request.h" | 52 #include "net/test/embedded_test_server/http_request.h" |
| 47 #include "net/test/embedded_test_server/http_response.h" | 53 #include "net/test/embedded_test_server/http_response.h" |
| 54 #include "net/url_request/test_url_fetcher_factory.h" |
| 55 #include "net/url_request/url_request_status.h" |
| 48 #include "testing/gmock/include/gmock/gmock.h" | 56 #include "testing/gmock/include/gmock/gmock.h" |
| 49 #include "testing/gtest/include/gtest/gtest.h" | 57 #include "testing/gtest/include/gtest/gtest.h" |
| 50 #include "ui/base/l10n/l10n_util.h" | 58 #include "ui/base/l10n/l10n_util.h" |
| 51 | 59 |
| 52 using ::testing::_; | 60 using ::testing::_; |
| 53 using ::testing::AtLeast; | 61 using ::testing::AtLeast; |
| 54 using ::testing::Invoke; | 62 using ::testing::Invoke; |
| 55 using ::testing::InvokeWithoutArgs; | 63 using ::testing::InvokeWithoutArgs; |
| 56 using ::testing::Return; | 64 using ::testing::Return; |
| 57 | 65 |
| (...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 109 }; | 117 }; |
| 110 | 118 |
| 111 const char kFooWebUIURL[] = "chrome://foo/"; | 119 const char kFooWebUIURL[] = "chrome://foo/"; |
| 112 | 120 |
| 113 bool AddToSet(std::set<content::WebContents*>* set, | 121 bool AddToSet(std::set<content::WebContents*>* set, |
| 114 content::WebContents* web_contents) { | 122 content::WebContents* web_contents) { |
| 115 set->insert(web_contents); | 123 set->insert(web_contents); |
| 116 return false; | 124 return false; |
| 117 } | 125 } |
| 118 | 126 |
| 127 // This class is used to mock out virtual methods with side effects so that |
| 128 // tests below can ensure they are called without causing side effects. |
| 129 class MockInlineSigninHelper : public InlineSigninHelper { |
| 130 public: |
| 131 MockInlineSigninHelper( |
| 132 base::WeakPtr<InlineLoginHandlerImpl> handler, |
| 133 net::URLRequestContextGetter* getter, |
| 134 Profile* profile, |
| 135 const GURL& current_url, |
| 136 const std::string& email, |
| 137 const std::string& gaia_id, |
| 138 const std::string& password, |
| 139 const std::string& session_index, |
| 140 const std::string& auth_code, |
| 141 const std::string& signin_scoped_device_id, |
| 142 bool choose_what_to_sync, |
| 143 bool confirm_untrusted_signin); |
| 144 |
| 145 MOCK_METHOD1(OnClientOAuthSuccess, void(const ClientOAuthResult& result)); |
| 146 MOCK_METHOD1(OnClientOAuthFailure, void(const GoogleServiceAuthError& error)); |
| 147 MOCK_METHOD6(CreateSyncStarter, |
| 148 void(Browser*, |
| 149 content::WebContents*, |
| 150 const GURL&, |
| 151 const std::string&, |
| 152 OneClickSigninSyncStarter::StartSyncMode, |
| 153 OneClickSigninSyncStarter::ConfirmationRequired)); |
| 154 |
| 155 private: |
| 156 DISALLOW_COPY_AND_ASSIGN(MockInlineSigninHelper); |
| 157 }; |
| 158 |
| 159 MockInlineSigninHelper::MockInlineSigninHelper( |
| 160 base::WeakPtr<InlineLoginHandlerImpl> handler, |
| 161 net::URLRequestContextGetter* getter, |
| 162 Profile* profile, |
| 163 const GURL& current_url, |
| 164 const std::string& email, |
| 165 const std::string& gaia_id, |
| 166 const std::string& password, |
| 167 const std::string& session_index, |
| 168 const std::string& auth_code, |
| 169 const std::string& signin_scoped_device_id, |
| 170 bool choose_what_to_sync, |
| 171 bool confirm_untrusted_signin) |
| 172 : InlineSigninHelper(handler, |
| 173 getter, |
| 174 profile, |
| 175 current_url, |
| 176 email, |
| 177 gaia_id, |
| 178 password, |
| 179 session_index, |
| 180 auth_code, |
| 181 signin_scoped_device_id, |
| 182 choose_what_to_sync, |
| 183 confirm_untrusted_signin) {} |
| 184 |
| 185 // This class is used to mock out virtual methods with side effects so that |
| 186 // tests below can ensure they are called without causing side effects. |
| 187 class MockSyncStarterInlineSigninHelper : public InlineSigninHelper { |
| 188 public: |
| 189 MockSyncStarterInlineSigninHelper( |
| 190 base::WeakPtr<InlineLoginHandlerImpl> handler, |
| 191 net::URLRequestContextGetter* getter, |
| 192 Profile* profile, |
| 193 const GURL& current_url, |
| 194 const std::string& email, |
| 195 const std::string& gaia_id, |
| 196 const std::string& password, |
| 197 const std::string& session_index, |
| 198 const std::string& auth_code, |
| 199 const std::string& signin_scoped_device_id, |
| 200 bool choose_what_to_sync, |
| 201 bool confirm_untrusted_signin); |
| 202 |
| 203 MOCK_METHOD6(CreateSyncStarter, |
| 204 void(Browser*, |
| 205 content::WebContents*, |
| 206 const GURL&, |
| 207 const std::string&, |
| 208 OneClickSigninSyncStarter::StartSyncMode, |
| 209 OneClickSigninSyncStarter::ConfirmationRequired)); |
| 210 |
| 211 private: |
| 212 DISALLOW_COPY_AND_ASSIGN(MockSyncStarterInlineSigninHelper); |
| 213 }; |
| 214 |
| 215 MockSyncStarterInlineSigninHelper::MockSyncStarterInlineSigninHelper( |
| 216 base::WeakPtr<InlineLoginHandlerImpl> handler, |
| 217 net::URLRequestContextGetter* getter, |
| 218 Profile* profile, |
| 219 const GURL& current_url, |
| 220 const std::string& email, |
| 221 const std::string& gaia_id, |
| 222 const std::string& password, |
| 223 const std::string& session_index, |
| 224 const std::string& auth_code, |
| 225 const std::string& signin_scoped_device_id, |
| 226 bool choose_what_to_sync, |
| 227 bool confirm_untrusted_signin) |
| 228 : InlineSigninHelper(handler, |
| 229 getter, |
| 230 profile, |
| 231 current_url, |
| 232 email, |
| 233 gaia_id, |
| 234 password, |
| 235 session_index, |
| 236 auth_code, |
| 237 signin_scoped_device_id, |
| 238 choose_what_to_sync, |
| 239 confirm_untrusted_signin) {} |
| 240 |
| 119 } // namespace | 241 } // namespace |
| 120 | 242 |
| 121 class InlineLoginUIBrowserTest : public InProcessBrowserTest { | 243 class InlineLoginUIBrowserTest : public InProcessBrowserTest { |
| 122 public: | 244 public: |
| 123 InlineLoginUIBrowserTest() {} | 245 InlineLoginUIBrowserTest() {} |
| 124 | 246 |
| 125 void SetUpSigninManager(const std::string& username); | 247 void SetUpSigninManager(const std::string& username); |
| 126 void EnableSigninAllowed(bool enable); | 248 void EnableSigninAllowed(bool enable); |
| 127 void EnableOneClick(bool enable); | 249 void EnableOneClick(bool enable); |
| 128 void AddEmailToOneClickRejectedList(const std::string& email); | 250 void AddEmailToOneClickRejectedList(const std::string& email); |
| (...skipping 194 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 323 AllowSigninCookies(false); | 445 AllowSigninCookies(false); |
| 324 EnableSigninAllowed(true); | 446 EnableSigninAllowed(true); |
| 325 | 447 |
| 326 std::string error_message; | 448 std::string error_message; |
| 327 EXPECT_FALSE(InlineLoginHandlerImpl::CanOffer( | 449 EXPECT_FALSE(InlineLoginHandlerImpl::CanOffer( |
| 328 browser()->profile(), InlineLoginHandlerImpl::CAN_OFFER_FOR_ALL, | 450 browser()->profile(), InlineLoginHandlerImpl::CAN_OFFER_FOR_ALL, |
| 329 "12345", "user@gmail.com", &error_message)); | 451 "12345", "user@gmail.com", &error_message)); |
| 330 EXPECT_EQ("", error_message); | 452 EXPECT_EQ("", error_message); |
| 331 } | 453 } |
| 332 | 454 |
| 455 class InlineLoginHelperBrowserTest : public InProcessBrowserTest { |
| 456 public: |
| 457 InlineLoginHelperBrowserTest() {} |
| 458 |
| 459 void SetUpInProcessBrowserTestFixture() override { |
| 460 InProcessBrowserTest::SetUpInProcessBrowserTestFixture(); |
| 461 |
| 462 will_create_browser_context_services_subscription_ = |
| 463 BrowserContextDependencyManager::GetInstance() |
| 464 ->RegisterWillCreateBrowserContextServicesCallbackForTesting( |
| 465 base::Bind(&InlineLoginHelperBrowserTest:: |
| 466 OnWillCreateBrowserContextServices, |
| 467 base::Unretained(this))) |
| 468 .Pass(); |
| 469 } |
| 470 |
| 471 void OnWillCreateBrowserContextServices(content::BrowserContext* context) { |
| 472 // Replace the signin manager and token service with fakes. Do this ahead of |
| 473 // creating the browser so that a bunch of classes don't register as |
| 474 // observers and end up needing to unregister when the fake is substituted. |
| 475 SigninManagerFactory::GetInstance()->SetTestingFactory( |
| 476 context, &BuildFakeSigninManagerBase); |
| 477 ProfileOAuth2TokenServiceFactory::GetInstance()->SetTestingFactory( |
| 478 context, &BuildFakeProfileOAuth2TokenService); |
| 479 } |
| 480 |
| 481 void SetUpOnMainThread() override { |
| 482 InProcessBrowserTest::SetUpOnMainThread(); |
| 483 |
| 484 // Grab references to the fake signin manager and token service. |
| 485 Profile* profile = browser()->profile(); |
| 486 signin_manager_ = static_cast<FakeSigninManagerForTesting*>( |
| 487 SigninManagerFactory::GetInstance()->GetForProfile(profile)); |
| 488 ASSERT_TRUE(signin_manager_); |
| 489 token_service_ = static_cast<FakeProfileOAuth2TokenService*>( |
| 490 ProfileOAuth2TokenServiceFactory::GetInstance()->GetForProfile( |
| 491 profile)); |
| 492 ASSERT_TRUE(token_service_); |
| 493 } |
| 494 |
| 495 void SimulateStartCookieForOAuthLoginTokenExchangeSuccess( |
| 496 const std::string& cookie_string) { |
| 497 net::TestURLFetcher* fetcher = url_fetcher_factory_.GetFetcherByID(0); |
| 498 ASSERT_TRUE(fetcher); |
| 499 net::ResponseCookies cookies; |
| 500 cookies.push_back(cookie_string); |
| 501 fetcher->set_status(net::URLRequestStatus()); |
| 502 fetcher->set_response_code(net::HTTP_OK); |
| 503 fetcher->set_cookies(cookies); |
| 504 fetcher->delegate()->OnURLFetchComplete(fetcher); |
| 505 } |
| 506 |
| 507 void SimulateStartAuthCodeForOAuth2TokenExchangeSuccess( |
| 508 const std::string& json_response) { |
| 509 net::TestURLFetcher* fetcher = url_fetcher_factory_.GetFetcherByID(0); |
| 510 ASSERT_TRUE(fetcher); |
| 511 fetcher->set_status(net::URLRequestStatus()); |
| 512 fetcher->set_response_code(net::HTTP_OK); |
| 513 fetcher->SetResponseString(json_response); |
| 514 fetcher->delegate()->OnURLFetchComplete(fetcher); |
| 515 } |
| 516 |
| 517 void SimulateOnClientOAuthSuccess(GaiaAuthConsumer* consumer, |
| 518 const std::string& refresh_token) { |
| 519 GaiaAuthConsumer::ClientOAuthResult result; |
| 520 result.refresh_token = refresh_token; |
| 521 consumer->OnClientOAuthSuccess(result); |
| 522 } |
| 523 |
| 524 FakeSigninManagerForTesting* signin_manager() { return signin_manager_; } |
| 525 FakeProfileOAuth2TokenService* token_service() { return token_service_; } |
| 526 |
| 527 private: |
| 528 net::TestURLFetcherFactory url_fetcher_factory_; |
| 529 FakeSigninManagerForTesting* signin_manager_; |
| 530 FakeProfileOAuth2TokenService* token_service_; |
| 531 scoped_ptr<base::CallbackList<void(content::BrowserContext*)>::Subscription> |
| 532 will_create_browser_context_services_subscription_; |
| 533 |
| 534 DISALLOW_COPY_AND_ASSIGN(InlineLoginHelperBrowserTest); |
| 535 }; |
| 536 |
| 537 // Test signin helper calls correct fetcher methods when called with a |
| 538 // session index. |
| 539 IN_PROC_BROWSER_TEST_F(InlineLoginHelperBrowserTest, WithSessionIndex) { |
| 540 base::WeakPtr<InlineLoginHandlerImpl> handler; |
| 541 MockInlineSigninHelper helper(handler, |
| 542 browser()->profile()->GetRequestContext(), |
| 543 browser()->profile(), |
| 544 GURL(), |
| 545 "foo@gmail.com", |
| 546 "gaiaid-12345", |
| 547 "password", |
| 548 "0", // session index from above |
| 549 std::string(), // auth code |
| 550 std::string(), |
| 551 false, // choose what to sync |
| 552 false); // confirm untrusted signin |
| 553 EXPECT_CALL(helper, OnClientOAuthSuccess(_)); |
| 554 |
| 555 SimulateStartCookieForOAuthLoginTokenExchangeSuccess( |
| 556 "secure; httponly; oauth_code=code"); |
| 557 SimulateStartAuthCodeForOAuth2TokenExchangeSuccess( |
| 558 "{\"access_token\": \"access_token\", \"expires_in\": 1234567890," |
| 559 " \"refresh_token\": \"refresh_token\"}"); |
| 560 } |
| 561 |
| 562 // Test signin helper calls correct fetcher methods when called with an |
| 563 // auth code. |
| 564 IN_PROC_BROWSER_TEST_F(InlineLoginHelperBrowserTest, WithAuthCode) { |
| 565 base::WeakPtr<InlineLoginHandlerImpl> handler; |
| 566 MockInlineSigninHelper helper(handler, |
| 567 browser()->profile()->GetRequestContext(), |
| 568 browser()->profile(), |
| 569 GURL(), |
| 570 "foo@gmail.com", |
| 571 "gaiaid-12345", |
| 572 "password", |
| 573 "", // session index |
| 574 "auth_code", // auth code |
| 575 std::string(), |
| 576 false, // choose what to sync |
| 577 false); // confirm untrusted signin |
| 578 EXPECT_CALL(helper, OnClientOAuthSuccess(_)); |
| 579 |
| 580 SimulateStartAuthCodeForOAuth2TokenExchangeSuccess( |
| 581 "{\"access_token\": \"access_token\", \"expires_in\": 1234567890," |
| 582 " \"refresh_token\": \"refresh_token\"}"); |
| 583 } |
| 584 |
| 585 // Test signin helper creates sync starter with correct confirmation when |
| 586 // signing in with default sync options. |
| 587 IN_PROC_BROWSER_TEST_F(InlineLoginHelperBrowserTest, |
| 588 SigninCreatesSyncStarter1) { |
| 589 // See Source enum in components/signin/core/browser/signin_metrics.h for |
| 590 // possible values of source=. |
| 591 GURL url("chrome://chrome-signin/?source=0"); |
| 592 base::WeakPtr<InlineLoginHandlerImpl> handler; |
| 593 // MockSyncStarterInlineSigninHelper will delete itself when done using |
| 594 // base::ThreadTaskRunnerHandle::DeleteSoon(), so need to delete here. But |
| 595 // do need the RunUntilIdle() at the end. |
| 596 MockSyncStarterInlineSigninHelper* helper = |
| 597 new MockSyncStarterInlineSigninHelper( |
| 598 handler, |
| 599 browser()->profile()->GetRequestContext(), |
| 600 browser()->profile(), |
| 601 url, |
| 602 "foo@gmail.com", |
| 603 "gaiaid-12345", |
| 604 "password", |
| 605 "", // session index |
| 606 "auth_code", // auth code |
| 607 std::string(), |
| 608 false, // choose what to sync |
| 609 false); // confirm untrusted signin |
| 610 EXPECT_CALL(*helper, CreateSyncStarter( |
| 611 _, _, _, "refresh_token", |
| 612 OneClickSigninSyncStarter::CONFIRM_SYNC_SETTINGS_FIRST, |
| 613 OneClickSigninSyncStarter::CONFIRM_AFTER_SIGNIN)); |
| 614 |
| 615 SimulateOnClientOAuthSuccess(helper, "refresh_token"); |
| 616 base::MessageLoop::current()->RunUntilIdle(); |
| 617 } |
| 618 |
| 619 // Test signin helper creates sync starter with correct confirmation when |
| 620 // signing in and choosing what to sync first. |
| 621 IN_PROC_BROWSER_TEST_F(InlineLoginHelperBrowserTest, |
| 622 SigninCreatesSyncStarter2) { |
| 623 // See Source enum in components/signin/core/browser/signin_metrics.h for |
| 624 // possible values of source=. |
| 625 const GURL url("chrome://chrome-signin/?source=0"); |
| 626 base::WeakPtr<InlineLoginHandlerImpl> handler; |
| 627 // MockSyncStarterInlineSigninHelper will delete itself when done using |
| 628 // base::ThreadTaskRunnerHandle::DeleteSoon(), so need to delete here. But |
| 629 // do need the RunUntilIdle() at the end. |
| 630 MockSyncStarterInlineSigninHelper* helper = |
| 631 new MockSyncStarterInlineSigninHelper( |
| 632 handler, |
| 633 browser()->profile()->GetRequestContext(), |
| 634 browser()->profile(), |
| 635 url, |
| 636 "foo@gmail.com", |
| 637 "gaiaid-12345", |
| 638 "password", |
| 639 "", // session index |
| 640 "auth_code", // auth code |
| 641 std::string(), |
| 642 true, // choose what to sync |
| 643 false); // confirm untrusted signin |
| 644 EXPECT_CALL(*helper, CreateSyncStarter( |
| 645 _, _, _, "refresh_token", |
| 646 OneClickSigninSyncStarter::CONFIGURE_SYNC_FIRST, |
| 647 OneClickSigninSyncStarter::CONFIRM_AFTER_SIGNIN)); |
| 648 |
| 649 SimulateOnClientOAuthSuccess(helper, "refresh_token"); |
| 650 base::MessageLoop::current()->RunUntilIdle(); |
| 651 } |
| 652 |
| 653 // Test signin helper creates sync starter with correct confirmation when |
| 654 // signing in with an untrusted sign occurs. |
| 655 IN_PROC_BROWSER_TEST_F(InlineLoginHelperBrowserTest, |
| 656 SigninCreatesSyncStarter3) { |
| 657 // See Source enum in components/signin/core/browser/signin_metrics.h for |
| 658 // possible values of source=. |
| 659 GURL url("chrome://chrome-signin/?source=0"); |
| 660 base::WeakPtr<InlineLoginHandlerImpl> handler; |
| 661 // MockSyncStarterInlineSigninHelper will delete itself when done using |
| 662 // base::ThreadTaskRunnerHandle::DeleteSoon(), so need to delete here. But |
| 663 // do need the RunUntilIdle() at the end. |
| 664 MockSyncStarterInlineSigninHelper* helper = |
| 665 new MockSyncStarterInlineSigninHelper( |
| 666 handler, |
| 667 browser()->profile()->GetRequestContext(), |
| 668 browser()->profile(), |
| 669 url, |
| 670 "foo@gmail.com", |
| 671 "gaiaid-12345", |
| 672 "password", |
| 673 "", // session index |
| 674 "auth_code", // auth code |
| 675 std::string(), |
| 676 false, // choose what to sync |
| 677 true); // confirm untrusted signin |
| 678 EXPECT_CALL(*helper, CreateSyncStarter( |
| 679 _, _, _, "refresh_token", |
| 680 OneClickSigninSyncStarter::CONFIRM_SYNC_SETTINGS_FIRST, |
| 681 OneClickSigninSyncStarter::CONFIRM_UNTRUSTED_SIGNIN)); |
| 682 |
| 683 SimulateOnClientOAuthSuccess(helper, "refresh_token"); |
| 684 base::MessageLoop::current()->RunUntilIdle(); |
| 685 } |
| 686 |
| 687 // Test signin helper creates sync starter with correct confirmation during |
| 688 // re-auth. |
| 689 IN_PROC_BROWSER_TEST_F(InlineLoginHelperBrowserTest, |
| 690 SigninCreatesSyncStarter4) { |
| 691 // See Source enum in components/signin/core/browser/signin_metrics.h for |
| 692 // possible values of source=. |
| 693 const GURL url("chrome://chrome-signin/?source=3"); |
| 694 base::WeakPtr<InlineLoginHandlerImpl> handler; |
| 695 // MockSyncStarterInlineSigninHelper will delete itself when done using |
| 696 // base::ThreadTaskRunnerHandle::DeleteSoon(), so need to delete here. But |
| 697 // do need the RunUntilIdle() at the end. |
| 698 MockSyncStarterInlineSigninHelper* helper = |
| 699 new MockSyncStarterInlineSigninHelper( |
| 700 handler, |
| 701 browser()->profile()->GetRequestContext(), |
| 702 browser()->profile(), |
| 703 url, |
| 704 "foo@gmail.com", |
| 705 "gaiaid-12345", |
| 706 "password", |
| 707 "", // session index |
| 708 "auth_code", // auth code |
| 709 std::string(), |
| 710 false, // choose what to sync |
| 711 false); // confirm untrusted signin |
| 712 |
| 713 // Even though "choose what to sync" is false, the source of the URL is |
| 714 // settings, which means the user wants to CONFIGURE_SYNC_FIRST. |
| 715 EXPECT_CALL(*helper, CreateSyncStarter( |
| 716 _, _, _, "refresh_token", |
| 717 OneClickSigninSyncStarter::CONFIGURE_SYNC_FIRST, |
| 718 OneClickSigninSyncStarter::CONFIRM_AFTER_SIGNIN)); |
| 719 |
| 720 SimulateOnClientOAuthSuccess(helper, "refresh_token"); |
| 721 base::MessageLoop::current()->RunUntilIdle(); |
| 722 } |
| 723 |
| 724 // Test signin helper does not create sync starter when reauthenticating. |
| 725 IN_PROC_BROWSER_TEST_F(InlineLoginHelperBrowserTest, |
| 726 ReauthCallsUpdateCredentials) { |
| 727 ASSERT_EQ(0ul, token_service()->GetAccounts().size()); |
| 728 |
| 729 // See Source enum in components/signin/core/browser/signin_metrics.h for |
| 730 // possible values of source=. |
| 731 GURL url("chrome://chrome-signin/?source=11"); |
| 732 base::WeakPtr<InlineLoginHandlerImpl> handler; |
| 733 InlineSigninHelper helper(handler, |
| 734 browser()->profile()->GetRequestContext(), |
| 735 browser()->profile(), |
| 736 url, |
| 737 "foo@gmail.com", |
| 738 "gaiaid-12345", |
| 739 "password", |
| 740 "", // session index |
| 741 "auth_code", // auth code |
| 742 std::string(), |
| 743 false, // choose what to sync |
| 744 false); // confirm untrusted signin |
| 745 SimulateOnClientOAuthSuccess(&helper, "refresh_token"); |
| 746 ASSERT_EQ(1ul, token_service()->GetAccounts().size()); |
| 747 base::MessageLoop::current()->RunUntilIdle(); |
| 748 } |
| 749 |
| 750 // Test signin helper does not create sync starter when adding another account |
| 751 // to profile. |
| 752 IN_PROC_BROWSER_TEST_F(InlineLoginHelperBrowserTest, |
| 753 AddAccountsCallsUpdateCredentials) { |
| 754 ASSERT_EQ(0ul, token_service()->GetAccounts().size()); |
| 755 |
| 756 // See Source enum in components/signin/core/browser/signin_metrics.h for |
| 757 // possible values of source=. |
| 758 GURL url("chrome://chrome-signin/?source=9"); |
| 759 base::WeakPtr<InlineLoginHandlerImpl> handler; |
| 760 InlineSigninHelper helper(handler, |
| 761 browser()->profile()->GetRequestContext(), |
| 762 browser()->profile(), |
| 763 url, |
| 764 "foo@gmail.com", |
| 765 "gaiaid-12345", |
| 766 "password", |
| 767 "", // session index |
| 768 "auth_code", // auth code |
| 769 std::string(), |
| 770 false, // choose what to sync |
| 771 false); // confirm untrusted signin |
| 772 SimulateOnClientOAuthSuccess(&helper, "refresh_token"); |
| 773 ASSERT_EQ(1ul, token_service()->GetAccounts().size()); |
| 774 base::MessageLoop::current()->RunUntilIdle(); |
| 775 } |
| 776 |
| 333 #endif // OS_CHROMEOS | 777 #endif // OS_CHROMEOS |
| 334 | 778 |
| 335 class InlineLoginUISafeIframeBrowserTest : public InProcessBrowserTest { | 779 class InlineLoginUISafeIframeBrowserTest : public InProcessBrowserTest { |
| 336 public: | 780 public: |
| 337 FooWebUIProvider& foo_provider() { return foo_provider_; } | 781 FooWebUIProvider& foo_provider() { return foo_provider_; } |
| 338 | 782 |
| 339 private: | 783 private: |
| 340 void SetUp() override { | 784 void SetUp() override { |
| 341 ASSERT_TRUE(embedded_test_server()->InitializeAndWaitUntilReady()); | 785 ASSERT_TRUE(embedded_test_server()->InitializeAndWaitUntilReady()); |
| 342 | 786 |
| (...skipping 124 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 467 ->AddObserver(&observer); | 911 ->AddObserver(&observer); |
| 468 base::RunLoop run_loop; | 912 base::RunLoop run_loop; |
| 469 EXPECT_CALL(observer, OnUntrustedLoginUIShown()) | 913 EXPECT_CALL(observer, OnUntrustedLoginUIShown()) |
| 470 .WillOnce(InvokeWithoutArgs(&run_loop, &base::RunLoop::Quit)); | 914 .WillOnce(InvokeWithoutArgs(&run_loop, &base::RunLoop::Quit)); |
| 471 | 915 |
| 472 ExecuteJsToSigninInSigninFrame(browser(), "email@gmail.com", "password"); | 916 ExecuteJsToSigninInSigninFrame(browser(), "email@gmail.com", "password"); |
| 473 run_loop.Run(); | 917 run_loop.Run(); |
| 474 base::MessageLoop::current()->RunUntilIdle(); | 918 base::MessageLoop::current()->RunUntilIdle(); |
| 475 } | 919 } |
| 476 #endif // OS_CHROMEOS | 920 #endif // OS_CHROMEOS |
| OLD | NEW |