| 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" | 10 #include "chrome/browser/signin/fake_profile_oauth2_token_service_builder.h" |
| (...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 95 content::RenderProcessHost* process = contents->GetRenderProcessHost(); | 95 content::RenderProcessHost* process = contents->GetRenderProcessHost(); |
| 96 return ContentInfo(contents, process->GetID(), | 96 return ContentInfo(contents, process->GetID(), |
| 97 process->GetStoragePartition()); | 97 process->GetStoragePartition()); |
| 98 } | 98 } |
| 99 | 99 |
| 100 // Returns a new WebUI object for the WebContents from |arg0|. | 100 // Returns a new WebUI object for the WebContents from |arg0|. |
| 101 ACTION(ReturnNewWebUI) { | 101 ACTION(ReturnNewWebUI) { |
| 102 return new content::WebUIController(arg0); | 102 return new content::WebUIController(arg0); |
| 103 } | 103 } |
| 104 | 104 |
| 105 GURL GetSigninPromoURL() { |
| 106 return signin::GetPromoURL( |
| 107 signin_metrics::AccessPoint::ACCESS_POINT_START_PAGE, |
| 108 signin_metrics::Reason::REASON_SIGNIN_PRIMARY_ACCOUNT, false); |
| 109 } |
| 110 |
| 105 // Mock the TestChromeWebUIControllerFactory::WebUIProvider to prove that we are | 111 // Mock the TestChromeWebUIControllerFactory::WebUIProvider to prove that we are |
| 106 // not called as expected. | 112 // not called as expected. |
| 107 class FooWebUIProvider | 113 class FooWebUIProvider |
| 108 : public TestChromeWebUIControllerFactory::WebUIProvider { | 114 : public TestChromeWebUIControllerFactory::WebUIProvider { |
| 109 public: | 115 public: |
| 110 MOCK_METHOD2(NewWebUI, content::WebUIController*(content::WebUI* web_ui, | 116 MOCK_METHOD2(NewWebUI, content::WebUIController*(content::WebUI* web_ui, |
| 111 const GURL& url)); | 117 const GURL& url)); |
| 112 }; | 118 }; |
| 113 | 119 |
| 114 class MockLoginUIObserver : public LoginUIService::Observer { | 120 class MockLoginUIObserver : public LoginUIService::Observer { |
| (...skipping 22 matching lines...) Expand all Loading... |
| 137 const std::string& gaia_id, | 143 const std::string& gaia_id, |
| 138 const std::string& password, | 144 const std::string& password, |
| 139 const std::string& session_index, | 145 const std::string& session_index, |
| 140 const std::string& auth_code, | 146 const std::string& auth_code, |
| 141 const std::string& signin_scoped_device_id, | 147 const std::string& signin_scoped_device_id, |
| 142 bool choose_what_to_sync, | 148 bool choose_what_to_sync, |
| 143 bool confirm_untrusted_signin); | 149 bool confirm_untrusted_signin); |
| 144 | 150 |
| 145 MOCK_METHOD1(OnClientOAuthSuccess, void(const ClientOAuthResult& result)); | 151 MOCK_METHOD1(OnClientOAuthSuccess, void(const ClientOAuthResult& result)); |
| 146 MOCK_METHOD1(OnClientOAuthFailure, void(const GoogleServiceAuthError& error)); | 152 MOCK_METHOD1(OnClientOAuthFailure, void(const GoogleServiceAuthError& error)); |
| 147 MOCK_METHOD6(CreateSyncStarter, | 153 MOCK_METHOD7(CreateSyncStarter, |
| 148 void(Browser*, | 154 void(Browser*, |
| 149 content::WebContents*, | 155 content::WebContents*, |
| 150 const GURL&, | 156 const GURL&, |
| 157 const GURL&, |
| 151 const std::string&, | 158 const std::string&, |
| 152 OneClickSigninSyncStarter::StartSyncMode, | 159 OneClickSigninSyncStarter::StartSyncMode, |
| 153 OneClickSigninSyncStarter::ConfirmationRequired)); | 160 OneClickSigninSyncStarter::ConfirmationRequired)); |
| 154 | 161 |
| 155 private: | 162 private: |
| 156 DISALLOW_COPY_AND_ASSIGN(MockInlineSigninHelper); | 163 DISALLOW_COPY_AND_ASSIGN(MockInlineSigninHelper); |
| 157 }; | 164 }; |
| 158 | 165 |
| 159 MockInlineSigninHelper::MockInlineSigninHelper( | 166 MockInlineSigninHelper::MockInlineSigninHelper( |
| 160 base::WeakPtr<InlineLoginHandlerImpl> handler, | 167 base::WeakPtr<InlineLoginHandlerImpl> handler, |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 193 const GURL& current_url, | 200 const GURL& current_url, |
| 194 const std::string& email, | 201 const std::string& email, |
| 195 const std::string& gaia_id, | 202 const std::string& gaia_id, |
| 196 const std::string& password, | 203 const std::string& password, |
| 197 const std::string& session_index, | 204 const std::string& session_index, |
| 198 const std::string& auth_code, | 205 const std::string& auth_code, |
| 199 const std::string& signin_scoped_device_id, | 206 const std::string& signin_scoped_device_id, |
| 200 bool choose_what_to_sync, | 207 bool choose_what_to_sync, |
| 201 bool confirm_untrusted_signin); | 208 bool confirm_untrusted_signin); |
| 202 | 209 |
| 203 MOCK_METHOD6(CreateSyncStarter, | 210 MOCK_METHOD7(CreateSyncStarter, |
| 204 void(Browser*, | 211 void(Browser*, |
| 205 content::WebContents*, | 212 content::WebContents*, |
| 206 const GURL&, | 213 const GURL&, |
| 214 const GURL&, |
| 207 const std::string&, | 215 const std::string&, |
| 208 OneClickSigninSyncStarter::StartSyncMode, | 216 OneClickSigninSyncStarter::StartSyncMode, |
| 209 OneClickSigninSyncStarter::ConfirmationRequired)); | 217 OneClickSigninSyncStarter::ConfirmationRequired)); |
| 210 | 218 |
| 211 private: | 219 private: |
| 212 DISALLOW_COPY_AND_ASSIGN(MockSyncStarterInlineSigninHelper); | 220 DISALLOW_COPY_AND_ASSIGN(MockSyncStarterInlineSigninHelper); |
| 213 }; | 221 }; |
| 214 | 222 |
| 215 MockSyncStarterInlineSigninHelper::MockSyncStarterInlineSigninHelper( | 223 MockSyncStarterInlineSigninHelper::MockSyncStarterInlineSigninHelper( |
| 216 base::WeakPtr<InlineLoginHandlerImpl> handler, | 224 base::WeakPtr<InlineLoginHandlerImpl> handler, |
| (...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 296 } | 304 } |
| 297 | 305 |
| 298 #if defined(OS_LINUX) || defined(OS_WIN) | 306 #if defined(OS_LINUX) || defined(OS_WIN) |
| 299 // crbug.com/422868 | 307 // crbug.com/422868 |
| 300 #define MAYBE_DifferentStorageId DISABLED_DifferentStorageId | 308 #define MAYBE_DifferentStorageId DISABLED_DifferentStorageId |
| 301 #else | 309 #else |
| 302 #define MAYBE_DifferentStorageId DifferentStorageId | 310 #define MAYBE_DifferentStorageId DifferentStorageId |
| 303 #endif | 311 #endif |
| 304 IN_PROC_BROWSER_TEST_F(InlineLoginUIBrowserTest, MAYBE_DifferentStorageId) { | 312 IN_PROC_BROWSER_TEST_F(InlineLoginUIBrowserTest, MAYBE_DifferentStorageId) { |
| 305 if (switches::IsEnableWebviewBasedSignin()) { | 313 if (switches::IsEnableWebviewBasedSignin()) { |
| 306 ContentInfo info = NavigateAndGetInfo( | 314 ContentInfo info = |
| 307 browser(), | 315 NavigateAndGetInfo(browser(), GetSigninPromoURL(), CURRENT_TAB); |
| 308 signin::GetPromoURL(signin_metrics::SOURCE_START_PAGE, false), | |
| 309 CURRENT_TAB); | |
| 310 WaitUntilUIReady(browser()); | 316 WaitUntilUIReady(browser()); |
| 311 | 317 |
| 312 // Make sure storage partition of embedded webview is different from | 318 // Make sure storage partition of embedded webview is different from |
| 313 // parent. | 319 // parent. |
| 314 std::set<content::WebContents*> set; | 320 std::set<content::WebContents*> set; |
| 315 GuestViewManager* manager = GuestViewManager::FromBrowserContext( | 321 GuestViewManager* manager = GuestViewManager::FromBrowserContext( |
| 316 info.contents->GetBrowserContext()); | 322 info.contents->GetBrowserContext()); |
| 317 manager->ForEachGuest(info.contents, base::Bind(&AddToSet, &set)); | 323 manager->ForEachGuest(info.contents, base::Bind(&AddToSet, &set)); |
| 318 ASSERT_EQ(1u, set.size()); | 324 ASSERT_EQ(1u, set.size()); |
| 319 content::WebContents* webview_contents = *set.begin(); | 325 content::WebContents* webview_contents = *set.begin(); |
| 320 content::RenderProcessHost* process = | 326 content::RenderProcessHost* process = |
| 321 webview_contents->GetRenderProcessHost(); | 327 webview_contents->GetRenderProcessHost(); |
| 322 ASSERT_NE(info.pid, process->GetID()); | 328 ASSERT_NE(info.pid, process->GetID()); |
| 323 ASSERT_NE(info.storage_partition, process->GetStoragePartition()); | 329 ASSERT_NE(info.storage_partition, process->GetStoragePartition()); |
| 324 } else { | 330 } else { |
| 325 GURL test_url = ui_test_utils::GetTestUrl( | 331 GURL test_url = ui_test_utils::GetTestUrl( |
| 326 base::FilePath(base::FilePath::kCurrentDirectory), | 332 base::FilePath(base::FilePath::kCurrentDirectory), |
| 327 base::FilePath(FILE_PATH_LITERAL("title1.html"))); | 333 base::FilePath(FILE_PATH_LITERAL("title1.html"))); |
| 328 | 334 |
| 329 ContentInfo info1 = | 335 ContentInfo info1 = |
| 330 NavigateAndGetInfo(browser(), test_url, CURRENT_TAB); | 336 NavigateAndGetInfo(browser(), test_url, CURRENT_TAB); |
| 331 ContentInfo info2 = NavigateAndGetInfo( | 337 ContentInfo info2 = |
| 332 browser(), | 338 NavigateAndGetInfo(browser(), GetSigninPromoURL(), CURRENT_TAB); |
| 333 signin::GetPromoURL(signin_metrics::SOURCE_START_PAGE, false), | |
| 334 CURRENT_TAB); | |
| 335 NavigateAndGetInfo(browser(), test_url, CURRENT_TAB); | 339 NavigateAndGetInfo(browser(), test_url, CURRENT_TAB); |
| 336 ContentInfo info3 = NavigateAndGetInfo( | 340 ContentInfo info3 = |
| 337 browser(), | 341 NavigateAndGetInfo(browser(), GetSigninPromoURL(), NEW_FOREGROUND_TAB); |
| 338 signin::GetPromoURL(signin_metrics::SOURCE_START_PAGE, false), | |
| 339 NEW_FOREGROUND_TAB); | |
| 340 | 342 |
| 341 // The info for signin should be the same. | 343 // The info for signin should be the same. |
| 342 ASSERT_EQ(info2.storage_partition, info3.storage_partition); | 344 ASSERT_EQ(info2.storage_partition, info3.storage_partition); |
| 343 // The info for test_url and signin should be different. | 345 // The info for test_url and signin should be different. |
| 344 ASSERT_NE(info1.storage_partition, info2.storage_partition); | 346 ASSERT_NE(info1.storage_partition, info2.storage_partition); |
| 345 } | 347 } |
| 346 } | 348 } |
| 347 | 349 |
| 348 IN_PROC_BROWSER_TEST_F(InlineLoginUIBrowserTest, OneProcessLimit) { | 350 IN_PROC_BROWSER_TEST_F(InlineLoginUIBrowserTest, OneProcessLimit) { |
| 349 GURL test_url_1 = ui_test_utils::GetTestUrl( | 351 GURL test_url_1 = ui_test_utils::GetTestUrl( |
| 350 base::FilePath(base::FilePath::kCurrentDirectory), | 352 base::FilePath(base::FilePath::kCurrentDirectory), |
| 351 base::FilePath(FILE_PATH_LITERAL("title1.html"))); | 353 base::FilePath(FILE_PATH_LITERAL("title1.html"))); |
| 352 GURL test_url_2 = ui_test_utils::GetTestUrl( | 354 GURL test_url_2 = ui_test_utils::GetTestUrl( |
| 353 base::FilePath(base::FilePath::kCurrentDirectory), | 355 base::FilePath(base::FilePath::kCurrentDirectory), |
| 354 base::FilePath(FILE_PATH_LITERAL("data:text/html,Hello world!"))); | 356 base::FilePath(FILE_PATH_LITERAL("data:text/html,Hello world!"))); |
| 355 | 357 |
| 356 // Even when the process limit is set to one, the signin process should | 358 // Even when the process limit is set to one, the signin process should |
| 357 // still be given its own process and storage partition. | 359 // still be given its own process and storage partition. |
| 358 content::RenderProcessHost::SetMaxRendererProcessCount(1); | 360 content::RenderProcessHost::SetMaxRendererProcessCount(1); |
| 359 | 361 |
| 360 ContentInfo info1 = | 362 ContentInfo info1 = |
| 361 NavigateAndGetInfo(browser(), test_url_1, CURRENT_TAB); | 363 NavigateAndGetInfo(browser(), test_url_1, CURRENT_TAB); |
| 362 ContentInfo info2 = | 364 ContentInfo info2 = |
| 363 NavigateAndGetInfo(browser(), test_url_2, CURRENT_TAB); | 365 NavigateAndGetInfo(browser(), test_url_2, CURRENT_TAB); |
| 364 ContentInfo info3 = NavigateAndGetInfo( | 366 ContentInfo info3 = |
| 365 browser(), | 367 NavigateAndGetInfo(browser(), GetSigninPromoURL(), CURRENT_TAB); |
| 366 signin::GetPromoURL(signin_metrics::SOURCE_START_PAGE, false), | |
| 367 CURRENT_TAB); | |
| 368 | 368 |
| 369 ASSERT_EQ(info1.pid, info2.pid); | 369 ASSERT_EQ(info1.pid, info2.pid); |
| 370 ASSERT_NE(info1.pid, info3.pid); | 370 ASSERT_NE(info1.pid, info3.pid); |
| 371 } | 371 } |
| 372 | 372 |
| 373 #if !defined(OS_CHROMEOS) | 373 #if !defined(OS_CHROMEOS) |
| 374 | 374 |
| 375 IN_PROC_BROWSER_TEST_F(InlineLoginUIBrowserTest, CanOfferNoProfile) { | 375 IN_PROC_BROWSER_TEST_F(InlineLoginUIBrowserTest, CanOfferNoProfile) { |
| 376 std::string error_message; | 376 std::string error_message; |
| 377 EXPECT_FALSE(InlineLoginHandlerImpl::CanOffer( | 377 EXPECT_FALSE(InlineLoginHandlerImpl::CanOffer( |
| (...skipping 202 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 580 SimulateStartAuthCodeForOAuth2TokenExchangeSuccess( | 580 SimulateStartAuthCodeForOAuth2TokenExchangeSuccess( |
| 581 "{\"access_token\": \"access_token\", \"expires_in\": 1234567890," | 581 "{\"access_token\": \"access_token\", \"expires_in\": 1234567890," |
| 582 " \"refresh_token\": \"refresh_token\"}"); | 582 " \"refresh_token\": \"refresh_token\"}"); |
| 583 } | 583 } |
| 584 | 584 |
| 585 // Test signin helper creates sync starter with correct confirmation when | 585 // Test signin helper creates sync starter with correct confirmation when |
| 586 // signing in with default sync options. | 586 // signing in with default sync options. |
| 587 IN_PROC_BROWSER_TEST_F(InlineLoginHelperBrowserTest, | 587 IN_PROC_BROWSER_TEST_F(InlineLoginHelperBrowserTest, |
| 588 SigninCreatesSyncStarter1) { | 588 SigninCreatesSyncStarter1) { |
| 589 // See Source enum in components/signin/core/browser/signin_metrics.h for | 589 // See Source enum in components/signin/core/browser/signin_metrics.h for |
| 590 // possible values of source=. | 590 // possible values of access_point=, reason=. |
| 591 GURL url("chrome://chrome-signin/?source=0"); | 591 GURL url("chrome://chrome-signin/?access_point=0&reason=0"); |
| 592 base::WeakPtr<InlineLoginHandlerImpl> handler; | 592 base::WeakPtr<InlineLoginHandlerImpl> handler; |
| 593 // MockSyncStarterInlineSigninHelper will delete itself when done using | 593 // MockSyncStarterInlineSigninHelper will delete itself when done using |
| 594 // base::ThreadTaskRunnerHandle::DeleteSoon(), so need to delete here. But | 594 // base::ThreadTaskRunnerHandle::DeleteSoon(), so need to delete here. But |
| 595 // do need the RunUntilIdle() at the end. | 595 // do need the RunUntilIdle() at the end. |
| 596 MockSyncStarterInlineSigninHelper* helper = | 596 MockSyncStarterInlineSigninHelper* helper = |
| 597 new MockSyncStarterInlineSigninHelper( | 597 new MockSyncStarterInlineSigninHelper( |
| 598 handler, | 598 handler, |
| 599 browser()->profile()->GetRequestContext(), | 599 browser()->profile()->GetRequestContext(), |
| 600 browser()->profile(), | 600 browser()->profile(), |
| 601 url, | 601 url, |
| 602 "foo@gmail.com", | 602 "foo@gmail.com", |
| 603 "gaiaid-12345", | 603 "gaiaid-12345", |
| 604 "password", | 604 "password", |
| 605 "", // session index | 605 "", // session index |
| 606 "auth_code", // auth code | 606 "auth_code", // auth code |
| 607 std::string(), | 607 std::string(), |
| 608 false, // choose what to sync | 608 false, // choose what to sync |
| 609 false); // confirm untrusted signin | 609 false); // confirm untrusted signin |
| 610 EXPECT_CALL(*helper, CreateSyncStarter( | 610 EXPECT_CALL( |
| 611 _, _, _, "refresh_token", | 611 *helper, |
| 612 OneClickSigninSyncStarter::CONFIRM_SYNC_SETTINGS_FIRST, | 612 CreateSyncStarter(_, _, _, _, "refresh_token", |
| 613 OneClickSigninSyncStarter::CONFIRM_AFTER_SIGNIN)); | 613 OneClickSigninSyncStarter::CONFIRM_SYNC_SETTINGS_FIRST, |
| 614 OneClickSigninSyncStarter::CONFIRM_AFTER_SIGNIN)); |
| 614 | 615 |
| 615 SimulateOnClientOAuthSuccess(helper, "refresh_token"); | 616 SimulateOnClientOAuthSuccess(helper, "refresh_token"); |
| 616 base::MessageLoop::current()->RunUntilIdle(); | 617 base::MessageLoop::current()->RunUntilIdle(); |
| 617 } | 618 } |
| 618 | 619 |
| 619 // Test signin helper creates sync starter with correct confirmation when | 620 // Test signin helper creates sync starter with correct confirmation when |
| 620 // signing in and choosing what to sync first. | 621 // signing in and choosing what to sync first. |
| 621 IN_PROC_BROWSER_TEST_F(InlineLoginHelperBrowserTest, | 622 IN_PROC_BROWSER_TEST_F(InlineLoginHelperBrowserTest, |
| 622 SigninCreatesSyncStarter2) { | 623 SigninCreatesSyncStarter2) { |
| 623 // See Source enum in components/signin/core/browser/signin_metrics.h for | 624 // See Source enum in components/signin/core/browser/signin_metrics.h for |
| 624 // possible values of source=. | 625 // possible values of access_point=, reason=. |
| 625 const GURL url("chrome://chrome-signin/?source=0"); | 626 const GURL url("chrome://chrome-signin/?access_point=0&reason=0"); |
| 626 base::WeakPtr<InlineLoginHandlerImpl> handler; | 627 base::WeakPtr<InlineLoginHandlerImpl> handler; |
| 627 // MockSyncStarterInlineSigninHelper will delete itself when done using | 628 // MockSyncStarterInlineSigninHelper will delete itself when done using |
| 628 // base::ThreadTaskRunnerHandle::DeleteSoon(), so need to delete here. But | 629 // base::ThreadTaskRunnerHandle::DeleteSoon(), so need to delete here. But |
| 629 // do need the RunUntilIdle() at the end. | 630 // do need the RunUntilIdle() at the end. |
| 630 MockSyncStarterInlineSigninHelper* helper = | 631 MockSyncStarterInlineSigninHelper* helper = |
| 631 new MockSyncStarterInlineSigninHelper( | 632 new MockSyncStarterInlineSigninHelper( |
| 632 handler, | 633 handler, |
| 633 browser()->profile()->GetRequestContext(), | 634 browser()->profile()->GetRequestContext(), |
| 634 browser()->profile(), | 635 browser()->profile(), |
| 635 url, | 636 url, |
| 636 "foo@gmail.com", | 637 "foo@gmail.com", |
| 637 "gaiaid-12345", | 638 "gaiaid-12345", |
| 638 "password", | 639 "password", |
| 639 "", // session index | 640 "", // session index |
| 640 "auth_code", // auth code | 641 "auth_code", // auth code |
| 641 std::string(), | 642 std::string(), |
| 642 true, // choose what to sync | 643 true, // choose what to sync |
| 643 false); // confirm untrusted signin | 644 false); // confirm untrusted signin |
| 644 EXPECT_CALL(*helper, CreateSyncStarter( | 645 EXPECT_CALL(*helper, CreateSyncStarter( |
| 645 _, _, _, "refresh_token", | 646 _, _, _, _, "refresh_token", |
| 646 OneClickSigninSyncStarter::CONFIGURE_SYNC_FIRST, | 647 OneClickSigninSyncStarter::CONFIGURE_SYNC_FIRST, |
| 647 OneClickSigninSyncStarter::CONFIRM_AFTER_SIGNIN)); | 648 OneClickSigninSyncStarter::CONFIRM_AFTER_SIGNIN)); |
| 648 | 649 |
| 649 SimulateOnClientOAuthSuccess(helper, "refresh_token"); | 650 SimulateOnClientOAuthSuccess(helper, "refresh_token"); |
| 650 base::MessageLoop::current()->RunUntilIdle(); | 651 base::MessageLoop::current()->RunUntilIdle(); |
| 651 } | 652 } |
| 652 | 653 |
| 653 // Test signin helper creates sync starter with correct confirmation when | 654 // Test signin helper creates sync starter with correct confirmation when |
| 654 // signing in with an untrusted sign occurs. | 655 // signing in with an untrusted sign occurs. |
| 655 IN_PROC_BROWSER_TEST_F(InlineLoginHelperBrowserTest, | 656 IN_PROC_BROWSER_TEST_F(InlineLoginHelperBrowserTest, |
| 656 SigninCreatesSyncStarter3) { | 657 SigninCreatesSyncStarter3) { |
| 657 // See Source enum in components/signin/core/browser/signin_metrics.h for | 658 // See Source enum in components/signin/core/browser/signin_metrics.h for |
| 658 // possible values of source=. | 659 // possible values of access_point=, reason=. |
| 659 GURL url("chrome://chrome-signin/?source=0"); | 660 GURL url("chrome://chrome-signin/?access_point=0&reason=0"); |
| 660 base::WeakPtr<InlineLoginHandlerImpl> handler; | 661 base::WeakPtr<InlineLoginHandlerImpl> handler; |
| 661 // MockSyncStarterInlineSigninHelper will delete itself when done using | 662 // MockSyncStarterInlineSigninHelper will delete itself when done using |
| 662 // base::ThreadTaskRunnerHandle::DeleteSoon(), so need to delete here. But | 663 // base::ThreadTaskRunnerHandle::DeleteSoon(), so need to delete here. But |
| 663 // do need the RunUntilIdle() at the end. | 664 // do need the RunUntilIdle() at the end. |
| 664 MockSyncStarterInlineSigninHelper* helper = | 665 MockSyncStarterInlineSigninHelper* helper = |
| 665 new MockSyncStarterInlineSigninHelper( | 666 new MockSyncStarterInlineSigninHelper( |
| 666 handler, | 667 handler, |
| 667 browser()->profile()->GetRequestContext(), | 668 browser()->profile()->GetRequestContext(), |
| 668 browser()->profile(), | 669 browser()->profile(), |
| 669 url, | 670 url, |
| 670 "foo@gmail.com", | 671 "foo@gmail.com", |
| 671 "gaiaid-12345", | 672 "gaiaid-12345", |
| 672 "password", | 673 "password", |
| 673 "", // session index | 674 "", // session index |
| 674 "auth_code", // auth code | 675 "auth_code", // auth code |
| 675 std::string(), | 676 std::string(), |
| 676 false, // choose what to sync | 677 false, // choose what to sync |
| 677 true); // confirm untrusted signin | 678 true); // confirm untrusted signin |
| 678 EXPECT_CALL(*helper, CreateSyncStarter( | 679 EXPECT_CALL( |
| 679 _, _, _, "refresh_token", | 680 *helper, |
| 680 OneClickSigninSyncStarter::CONFIRM_SYNC_SETTINGS_FIRST, | 681 CreateSyncStarter(_, _, _, _, "refresh_token", |
| 681 OneClickSigninSyncStarter::CONFIRM_UNTRUSTED_SIGNIN)); | 682 OneClickSigninSyncStarter::CONFIRM_SYNC_SETTINGS_FIRST, |
| 683 OneClickSigninSyncStarter::CONFIRM_UNTRUSTED_SIGNIN)); |
| 682 | 684 |
| 683 SimulateOnClientOAuthSuccess(helper, "refresh_token"); | 685 SimulateOnClientOAuthSuccess(helper, "refresh_token"); |
| 684 base::MessageLoop::current()->RunUntilIdle(); | 686 base::MessageLoop::current()->RunUntilIdle(); |
| 685 } | 687 } |
| 686 | 688 |
| 687 // Test signin helper creates sync starter with correct confirmation during | 689 // Test signin helper creates sync starter with correct confirmation during |
| 688 // re-auth. | 690 // re-auth. |
| 689 IN_PROC_BROWSER_TEST_F(InlineLoginHelperBrowserTest, | 691 IN_PROC_BROWSER_TEST_F(InlineLoginHelperBrowserTest, |
| 690 SigninCreatesSyncStarter4) { | 692 SigninCreatesSyncStarter4) { |
| 691 // 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 |
| 692 // possible values of source=. | 694 // possible values of access_point=, reason=. |
| 693 const GURL url("chrome://chrome-signin/?source=3"); | 695 const GURL url("chrome://chrome-signin/?access_point=3&reason=0"); |
| 694 base::WeakPtr<InlineLoginHandlerImpl> handler; | 696 base::WeakPtr<InlineLoginHandlerImpl> handler; |
| 695 // MockSyncStarterInlineSigninHelper will delete itself when done using | 697 // MockSyncStarterInlineSigninHelper will delete itself when done using |
| 696 // base::ThreadTaskRunnerHandle::DeleteSoon(), so need to delete here. But | 698 // base::ThreadTaskRunnerHandle::DeleteSoon(), so need to delete here. But |
| 697 // do need the RunUntilIdle() at the end. | 699 // do need the RunUntilIdle() at the end. |
| 698 MockSyncStarterInlineSigninHelper* helper = | 700 MockSyncStarterInlineSigninHelper* helper = |
| 699 new MockSyncStarterInlineSigninHelper( | 701 new MockSyncStarterInlineSigninHelper( |
| 700 handler, | 702 handler, |
| 701 browser()->profile()->GetRequestContext(), | 703 browser()->profile()->GetRequestContext(), |
| 702 browser()->profile(), | 704 browser()->profile(), |
| 703 url, | 705 url, |
| 704 "foo@gmail.com", | 706 "foo@gmail.com", |
| 705 "gaiaid-12345", | 707 "gaiaid-12345", |
| 706 "password", | 708 "password", |
| 707 "", // session index | 709 "", // session index |
| 708 "auth_code", // auth code | 710 "auth_code", // auth code |
| 709 std::string(), | 711 std::string(), |
| 710 false, // choose what to sync | 712 false, // choose what to sync |
| 711 false); // confirm untrusted signin | 713 false); // confirm untrusted signin |
| 712 | 714 |
| 713 // Even though "choose what to sync" is false, the source of the URL is | 715 // 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. | 716 // settings, which means the user wants to CONFIGURE_SYNC_FIRST. |
| 715 EXPECT_CALL(*helper, CreateSyncStarter( | 717 EXPECT_CALL(*helper, CreateSyncStarter( |
| 716 _, _, _, "refresh_token", | 718 _, _, _, _, "refresh_token", |
| 717 OneClickSigninSyncStarter::CONFIGURE_SYNC_FIRST, | 719 OneClickSigninSyncStarter::CONFIGURE_SYNC_FIRST, |
| 718 OneClickSigninSyncStarter::CONFIRM_AFTER_SIGNIN)); | 720 OneClickSigninSyncStarter::CONFIRM_AFTER_SIGNIN)); |
| 719 | 721 |
| 720 SimulateOnClientOAuthSuccess(helper, "refresh_token"); | 722 SimulateOnClientOAuthSuccess(helper, "refresh_token"); |
| 721 base::MessageLoop::current()->RunUntilIdle(); | 723 base::MessageLoop::current()->RunUntilIdle(); |
| 722 } | 724 } |
| 723 | 725 |
| 724 // Test signin helper does not create sync starter when reauthenticating. | 726 // Test signin helper does not create sync starter when reauthenticating. |
| 725 IN_PROC_BROWSER_TEST_F(InlineLoginHelperBrowserTest, | 727 IN_PROC_BROWSER_TEST_F(InlineLoginHelperBrowserTest, |
| 726 ReauthCallsUpdateCredentials) { | 728 ReauthCallsUpdateCredentials) { |
| 727 ASSERT_EQ(0ul, token_service()->GetAccounts().size()); | 729 ASSERT_EQ(0ul, token_service()->GetAccounts().size()); |
| 728 | 730 |
| 729 // See Source enum in components/signin/core/browser/signin_metrics.h for | 731 // See Source enum in components/signin/core/browser/signin_metrics.h for |
| 730 // possible values of source=. | 732 // possible values of access_point=, reason=. |
| 731 GURL url("chrome://chrome-signin/?source=11"); | 733 GURL url("chrome://chrome-signin/?access_point=3&reason=2"); |
| 732 base::WeakPtr<InlineLoginHandlerImpl> handler; | 734 base::WeakPtr<InlineLoginHandlerImpl> handler; |
| 733 InlineSigninHelper helper(handler, | 735 InlineSigninHelper helper(handler, |
| 734 browser()->profile()->GetRequestContext(), | 736 browser()->profile()->GetRequestContext(), |
| 735 browser()->profile(), | 737 browser()->profile(), |
| 736 url, | 738 url, |
| 737 "foo@gmail.com", | 739 "foo@gmail.com", |
| 738 "gaiaid-12345", | 740 "gaiaid-12345", |
| 739 "password", | 741 "password", |
| 740 "", // session index | 742 "", // session index |
| 741 "auth_code", // auth code | 743 "auth_code", // auth code |
| 742 std::string(), | 744 std::string(), |
| 743 false, // choose what to sync | 745 false, // choose what to sync |
| 744 false); // confirm untrusted signin | 746 false); // confirm untrusted signin |
| 745 SimulateOnClientOAuthSuccess(&helper, "refresh_token"); | 747 SimulateOnClientOAuthSuccess(&helper, "refresh_token"); |
| 746 ASSERT_EQ(1ul, token_service()->GetAccounts().size()); | 748 ASSERT_EQ(1ul, token_service()->GetAccounts().size()); |
| 747 base::MessageLoop::current()->RunUntilIdle(); | 749 base::MessageLoop::current()->RunUntilIdle(); |
| 748 } | 750 } |
| 749 | 751 |
| 750 // Test signin helper does not create sync starter when adding another account | 752 // Test signin helper does not create sync starter when adding another account |
| 751 // to profile. | 753 // to profile. |
| 752 IN_PROC_BROWSER_TEST_F(InlineLoginHelperBrowserTest, | 754 IN_PROC_BROWSER_TEST_F(InlineLoginHelperBrowserTest, |
| 753 AddAccountsCallsUpdateCredentials) { | 755 AddAccountsCallsUpdateCredentials) { |
| 754 ASSERT_EQ(0ul, token_service()->GetAccounts().size()); | 756 ASSERT_EQ(0ul, token_service()->GetAccounts().size()); |
| 755 | 757 |
| 756 // See Source enum in components/signin/core/browser/signin_metrics.h for | 758 // See Source enum in components/signin/core/browser/signin_metrics.h for |
| 757 // possible values of source=. | 759 // possible values of access_point=, reason=. |
| 758 GURL url("chrome://chrome-signin/?source=9"); | 760 GURL url("chrome://chrome-signin/?access_point=10&reason=1"); |
| 759 base::WeakPtr<InlineLoginHandlerImpl> handler; | 761 base::WeakPtr<InlineLoginHandlerImpl> handler; |
| 760 InlineSigninHelper helper(handler, | 762 InlineSigninHelper helper(handler, |
| 761 browser()->profile()->GetRequestContext(), | 763 browser()->profile()->GetRequestContext(), |
| 762 browser()->profile(), | 764 browser()->profile(), |
| 763 url, | 765 url, |
| 764 "foo@gmail.com", | 766 "foo@gmail.com", |
| 765 "gaiaid-12345", | 767 "gaiaid-12345", |
| 766 "password", | 768 "password", |
| 767 "", // session index | 769 "", // session index |
| 768 "auth_code", // auth code | 770 "auth_code", // auth code |
| (...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 825 IN_PROC_BROWSER_TEST_F(InlineLoginUISafeIframeBrowserTest, Basic) { | 827 IN_PROC_BROWSER_TEST_F(InlineLoginUISafeIframeBrowserTest, Basic) { |
| 826 const GURL kUrl(kFooWebUIURL); | 828 const GURL kUrl(kFooWebUIURL); |
| 827 EXPECT_CALL(foo_provider(), NewWebUI(_, ::testing::Eq(kUrl))) | 829 EXPECT_CALL(foo_provider(), NewWebUI(_, ::testing::Eq(kUrl))) |
| 828 .WillOnce(ReturnNewWebUI()); | 830 .WillOnce(ReturnNewWebUI()); |
| 829 ui_test_utils::NavigateToURL(browser(), GURL(kFooWebUIURL)); | 831 ui_test_utils::NavigateToURL(browser(), GURL(kFooWebUIURL)); |
| 830 } | 832 } |
| 831 | 833 |
| 832 // Make sure that the foo webui handler does not get created when we try to | 834 // Make sure that the foo webui handler does not get created when we try to |
| 833 // load it inside the iframe of the login ui. | 835 // load it inside the iframe of the login ui. |
| 834 IN_PROC_BROWSER_TEST_F(InlineLoginUISafeIframeBrowserTest, NoWebUIInIframe) { | 836 IN_PROC_BROWSER_TEST_F(InlineLoginUISafeIframeBrowserTest, NoWebUIInIframe) { |
| 835 GURL url = signin::GetPromoURL(signin_metrics::SOURCE_START_PAGE, false). | 837 GURL url = GetSigninPromoURL().Resolve( |
| 836 Resolve("?source=0&frameUrl=chrome://foo"); | 838 "?source=0&access_point=0&reason=0&frameUrl=chrome://foo"); |
| 837 EXPECT_CALL(foo_provider(), NewWebUI(_, _)).Times(0); | 839 EXPECT_CALL(foo_provider(), NewWebUI(_, _)).Times(0); |
| 838 ui_test_utils::NavigateToURL(browser(), url); | 840 ui_test_utils::NavigateToURL(browser(), url); |
| 839 } | 841 } |
| 840 | 842 |
| 841 // Flaky on CrOS, http://crbug.com/364759. | 843 // Flaky on CrOS, http://crbug.com/364759. |
| 842 #if defined(OS_CHROMEOS) | 844 #if defined(OS_CHROMEOS) |
| 843 #define MAYBE_TopFrameNavigationDisallowed DISABLED_TopFrameNavigationDisallowed | 845 #define MAYBE_TopFrameNavigationDisallowed DISABLED_TopFrameNavigationDisallowed |
| 844 #else | 846 #else |
| 845 #define MAYBE_TopFrameNavigationDisallowed TopFrameNavigationDisallowed | 847 #define MAYBE_TopFrameNavigationDisallowed TopFrameNavigationDisallowed |
| 846 #endif | 848 #endif |
| 847 | 849 |
| 848 // Make sure that the gaia iframe cannot trigger top-frame navigation. | 850 // Make sure that the gaia iframe cannot trigger top-frame navigation. |
| 849 // TODO(guohui): flaky on trybot crbug/364759. | 851 // TODO(guohui): flaky on trybot crbug/364759. |
| 850 IN_PROC_BROWSER_TEST_F(InlineLoginUISafeIframeBrowserTest, | 852 IN_PROC_BROWSER_TEST_F(InlineLoginUISafeIframeBrowserTest, |
| 851 MAYBE_TopFrameNavigationDisallowed) { | 853 MAYBE_TopFrameNavigationDisallowed) { |
| 852 // Loads into gaia iframe a web page that attempts to deframe on load. | 854 // Loads into gaia iframe a web page that attempts to deframe on load. |
| 853 GURL deframe_url(embedded_test_server()->GetURL("/login/deframe.html")); | 855 GURL deframe_url(embedded_test_server()->GetURL("/login/deframe.html")); |
| 854 GURL url(net::AppendOrReplaceQueryParameter( | 856 GURL url(net::AppendOrReplaceQueryParameter(GetSigninPromoURL(), "frameUrl", |
| 855 signin::GetPromoURL(signin_metrics::SOURCE_START_PAGE, false), | 857 deframe_url.spec())); |
| 856 "frameUrl", deframe_url.spec())); | |
| 857 ui_test_utils::NavigateToURL(browser(), url); | 858 ui_test_utils::NavigateToURL(browser(), url); |
| 858 WaitUntilUIReady(browser()); | 859 WaitUntilUIReady(browser()); |
| 859 | 860 |
| 860 content::WebContents* contents = | 861 content::WebContents* contents = |
| 861 browser()->tab_strip_model()->GetActiveWebContents(); | 862 browser()->tab_strip_model()->GetActiveWebContents(); |
| 862 EXPECT_EQ(url, contents->GetVisibleURL()); | 863 EXPECT_EQ(url, contents->GetVisibleURL()); |
| 863 | 864 |
| 864 content::NavigationController& controller = contents->GetController(); | 865 content::NavigationController& controller = contents->GetController(); |
| 865 EXPECT_TRUE(controller.GetPendingEntry() == NULL); | 866 EXPECT_TRUE(controller.GetPendingEntry() == NULL); |
| 866 } | 867 } |
| 867 | 868 |
| 868 // Flaky on CrOS, http://crbug.com/364759. | 869 // Flaky on CrOS, http://crbug.com/364759. |
| 869 // Also flaky on Mac, http://crbug.com/442674. | 870 // Also flaky on Mac, http://crbug.com/442674. |
| 870 // Also flaky on Linux which is just too flaky | 871 // Also flaky on Linux which is just too flaky |
| 871 IN_PROC_BROWSER_TEST_F(InlineLoginUISafeIframeBrowserTest, | 872 IN_PROC_BROWSER_TEST_F(InlineLoginUISafeIframeBrowserTest, |
| 872 DISABLED_NavigationToOtherChromeURLDisallowed) { | 873 DISABLED_NavigationToOtherChromeURLDisallowed) { |
| 873 ui_test_utils::NavigateToURL( | 874 ui_test_utils::NavigateToURL(browser(), GetSigninPromoURL()); |
| 874 browser(), signin::GetPromoURL(signin_metrics::SOURCE_START_PAGE, false)); | |
| 875 WaitUntilUIReady(browser()); | 875 WaitUntilUIReady(browser()); |
| 876 | 876 |
| 877 content::WebContents* contents = | 877 content::WebContents* contents = |
| 878 browser()->tab_strip_model()->GetActiveWebContents(); | 878 browser()->tab_strip_model()->GetActiveWebContents(); |
| 879 ASSERT_TRUE(content::ExecuteScript( | 879 ASSERT_TRUE(content::ExecuteScript( |
| 880 contents, "window.location.href = 'chrome://foo'")); | 880 contents, "window.location.href = 'chrome://foo'")); |
| 881 | 881 |
| 882 content::TestNavigationObserver navigation_observer(contents, 1); | 882 content::TestNavigationObserver navigation_observer(contents, 1); |
| 883 navigation_observer.Wait(); | 883 navigation_observer.Wait(); |
| 884 | 884 |
| 885 EXPECT_EQ(GURL("about:blank"), contents->GetVisibleURL()); | 885 EXPECT_EQ(GURL("about:blank"), contents->GetVisibleURL()); |
| 886 } | 886 } |
| 887 | 887 |
| 888 #if !defined(OS_CHROMEOS) | 888 #if !defined(OS_CHROMEOS) |
| 889 IN_PROC_BROWSER_TEST_F(InlineLoginUISafeIframeBrowserTest, | 889 IN_PROC_BROWSER_TEST_F(InlineLoginUISafeIframeBrowserTest, |
| 890 ConfirmationRequiredForNonsecureSignin) { | 890 ConfirmationRequiredForNonsecureSignin) { |
| 891 FakeGaia fake_gaia; | 891 FakeGaia fake_gaia; |
| 892 fake_gaia.Initialize(); | 892 fake_gaia.Initialize(); |
| 893 | 893 |
| 894 embedded_test_server()->RegisterRequestHandler( | 894 embedded_test_server()->RegisterRequestHandler( |
| 895 base::Bind(&FakeGaia::HandleRequest, | 895 base::Bind(&FakeGaia::HandleRequest, |
| 896 base::Unretained(&fake_gaia))); | 896 base::Unretained(&fake_gaia))); |
| 897 fake_gaia.SetFakeMergeSessionParams( | 897 fake_gaia.SetFakeMergeSessionParams( |
| 898 "email@gmail.com", "fake-sid-cookie", "fake-lsid-cookie"); | 898 "email@gmail.com", "fake-sid-cookie", "fake-lsid-cookie"); |
| 899 | 899 |
| 900 // Navigates to the Chrome signin page which loads the fake gaia auth page. | 900 // Navigates to the Chrome signin page which loads the fake gaia auth page. |
| 901 // Since the fake gaia auth page is served over HTTP, thus expects to see an | 901 // Since the fake gaia auth page is served over HTTP, thus expects to see an |
| 902 // untrusted signin confirmation dialog upon submitting credentials below. | 902 // untrusted signin confirmation dialog upon submitting credentials below. |
| 903 ui_test_utils::NavigateToURL( | 903 ui_test_utils::NavigateToURL(browser(), GetSigninPromoURL()); |
| 904 browser(), signin::GetPromoURL(signin_metrics::SOURCE_START_PAGE, false)); | |
| 905 WaitUntilUIReady(browser()); | 904 WaitUntilUIReady(browser()); |
| 906 | 905 |
| 907 MockLoginUIObserver observer; | 906 MockLoginUIObserver observer; |
| 908 LoginUIServiceFactory::GetForProfile(browser()->profile()) | 907 LoginUIServiceFactory::GetForProfile(browser()->profile()) |
| 909 ->AddObserver(&observer); | 908 ->AddObserver(&observer); |
| 910 base::RunLoop run_loop; | 909 base::RunLoop run_loop; |
| 911 EXPECT_CALL(observer, OnUntrustedLoginUIShown()) | 910 EXPECT_CALL(observer, OnUntrustedLoginUIShown()) |
| 912 .WillOnce(InvokeWithoutArgs(&run_loop, &base::RunLoop::Quit)); | 911 .WillOnce(InvokeWithoutArgs(&run_loop, &base::RunLoop::Quit)); |
| 913 | 912 |
| 914 ExecuteJsToSigninInSigninFrame(browser(), "email@gmail.com", "password"); | 913 ExecuteJsToSigninInSigninFrame(browser(), "email@gmail.com", "password"); |
| 915 run_loop.Run(); | 914 run_loop.Run(); |
| 916 base::MessageLoop::current()->RunUntilIdle(); | 915 base::MessageLoop::current()->RunUntilIdle(); |
| 917 } | 916 } |
| 918 #endif // OS_CHROMEOS | 917 #endif // OS_CHROMEOS |
| OLD | NEW |