| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 <string> | 5 #include <string> |
| 6 | 6 |
| 7 #include "base/message_loop/message_loop.h" | 7 #include "base/message_loop/message_loop.h" |
| 8 #include "base/prefs/pref_service.h" | 8 #include "base/prefs/pref_service.h" |
| 9 #include "base/strings/stringprintf.h" | 9 #include "base/strings/stringprintf.h" |
| 10 #include "base/synchronization/waitable_event.h" | 10 #include "base/synchronization/waitable_event.h" |
| 11 #include "chrome/browser/browser_process.h" | 11 #include "chrome/browser/browser_process.h" |
| 12 #include "chrome/browser/chrome_notification_types.h" | 12 #include "chrome/browser/chrome_notification_types.h" |
| 13 #include "chrome/browser/chromeos/login/signin/oauth2_login_manager.h" | 13 #include "chrome/browser/chromeos/login/signin/oauth2_login_manager.h" |
| 14 #include "chrome/browser/chromeos/login/signin/oauth2_login_manager_factory.h" | 14 #include "chrome/browser/chromeos/login/signin/oauth2_login_manager_factory.h" |
| 15 #include "chrome/browser/chromeos/login/signin_specifics.h" | 15 #include "chrome/browser/chromeos/login/signin_specifics.h" |
| 16 #include "chrome/browser/chromeos/login/startup_utils.h" |
| 16 #include "chrome/browser/chromeos/login/test/oobe_base_test.h" | 17 #include "chrome/browser/chromeos/login/test/oobe_base_test.h" |
| 17 #include "chrome/browser/chromeos/login/wizard_controller.h" | 18 #include "chrome/browser/chromeos/login/wizard_controller.h" |
| 18 #include "chrome/browser/profiles/profile_manager.h" | 19 #include "chrome/browser/profiles/profile_manager.h" |
| 19 #include "chrome/browser/signin/profile_oauth2_token_service_factory.h" | 20 #include "chrome/browser/signin/profile_oauth2_token_service_factory.h" |
| 20 #include "chrome/browser/ui/browser.h" | 21 #include "chrome/browser/ui/browser.h" |
| 21 #include "chrome/browser/ui/browser_tabstrip.h" | 22 #include "chrome/browser/ui/browser_tabstrip.h" |
| 22 #include "chrome/browser/ui/scoped_tabbed_browser_displayer.h" | 23 #include "chrome/browser/ui/scoped_tabbed_browser_displayer.h" |
| 23 #include "chrome/browser/ui/tabs/tab_strip_model.h" | 24 #include "chrome/browser/ui/tabs/tab_strip_model.h" |
| 24 #include "chrome/browser/ui/webui/chromeos/login/signin_screen_handler.h" | 25 #include "chrome/browser/ui/webui/chromeos/login/signin_screen_handler.h" |
| 25 #include "chrome/common/chrome_switches.h" | 26 #include "chrome/common/chrome_switches.h" |
| (...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 123 std::set<OAuth2LoginManager::SessionRestoreState> states_; | 124 std::set<OAuth2LoginManager::SessionRestoreState> states_; |
| 124 bool waiting_for_state_; | 125 bool waiting_for_state_; |
| 125 OAuth2LoginManager::SessionRestoreState final_state_; | 126 OAuth2LoginManager::SessionRestoreState final_state_; |
| 126 scoped_refptr<content::MessageLoopRunner> runner_; | 127 scoped_refptr<content::MessageLoopRunner> runner_; |
| 127 | 128 |
| 128 DISALLOW_COPY_AND_ASSIGN(OAuth2LoginManagerStateWaiter); | 129 DISALLOW_COPY_AND_ASSIGN(OAuth2LoginManagerStateWaiter); |
| 129 }; | 130 }; |
| 130 | 131 |
| 131 } // namespace | 132 } // namespace |
| 132 | 133 |
| 133 class OAuth2Test : public OobeBaseTest { | 134 // Boolean parameter is used to run this test for webview (true) and for |
| 135 // iframe (false) GAIA sign in. |
| 136 class OAuth2Test : public OobeBaseTest, |
| 137 public testing::WithParamInterface<bool> { |
| 134 protected: | 138 protected: |
| 135 OAuth2Test() {} | 139 OAuth2Test() { set_use_webview(GetParam()); } |
| 136 | 140 |
| 137 void SetUpCommandLine(base::CommandLine* command_line) override { | 141 void SetUpCommandLine(base::CommandLine* command_line) override { |
| 138 OobeBaseTest::SetUpCommandLine(command_line); | 142 OobeBaseTest::SetUpCommandLine(command_line); |
| 139 | 143 |
| 140 // Disable sync sinc we don't really need this for these tests and it also | 144 // Disable sync sinc we don't really need this for these tests and it also |
| 141 // makes OAuth2Test.MergeSession test flaky http://crbug.com/408867. | 145 // makes OAuth2Test.MergeSession test flaky http://crbug.com/408867. |
| 142 command_line->AppendSwitch(switches::kDisableSync); | 146 command_line->AppendSwitch(switches::kDisableSync); |
| 143 } | 147 } |
| 144 | 148 |
| 145 void SetupGaiaServerForNewAccount() { | 149 void SetupGaiaServerForNewAccount() { |
| (...skipping 174 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 320 states.insert(OAuth2LoginManager::SESSION_RESTORE_FAILED); | 324 states.insert(OAuth2LoginManager::SESSION_RESTORE_FAILED); |
| 321 states.insert(OAuth2LoginManager::SESSION_RESTORE_CONNECTION_FAILED); | 325 states.insert(OAuth2LoginManager::SESSION_RESTORE_CONNECTION_FAILED); |
| 322 OAuth2LoginManagerStateWaiter merge_session_waiter(profile()); | 326 OAuth2LoginManagerStateWaiter merge_session_waiter(profile()); |
| 323 merge_session_waiter.WaitForStates(states); | 327 merge_session_waiter.WaitForStates(states); |
| 324 EXPECT_EQ(merge_session_waiter.final_state(), final_state); | 328 EXPECT_EQ(merge_session_waiter.final_state(), final_state); |
| 325 } | 329 } |
| 326 | 330 |
| 327 void StartNewUserSession(bool wait_for_merge) { | 331 void StartNewUserSession(bool wait_for_merge) { |
| 328 SetupGaiaServerForNewAccount(); | 332 SetupGaiaServerForNewAccount(); |
| 329 SimulateNetworkOnline(); | 333 SimulateNetworkOnline(); |
| 330 chromeos::WizardController::SkipPostLoginScreensForTesting(); | 334 WaitForGaiaPageLoad(); |
| 331 chromeos::WizardController* wizard_controller = | |
| 332 chromeos::WizardController::default_controller(); | |
| 333 wizard_controller->SkipToLoginForTesting(LoginScreenContext()); | |
| 334 | 335 |
| 335 content::WindowedNotificationObserver( | 336 content::WindowedNotificationObserver session_start_waiter( |
| 336 chrome::NOTIFICATION_LOGIN_OR_LOCK_WEBUI_VISIBLE, | 337 chrome::NOTIFICATION_SESSION_STARTED, |
| 337 content::NotificationService::AllSources()).Wait(); | 338 content::NotificationService::AllSources()); |
| 338 | 339 |
| 339 // Use capitalized and dotted user name on purpose to make sure | 340 // Use capitalized and dotted user name on purpose to make sure |
| 340 // our email normalization kicks in. | 341 // our email normalization kicks in. |
| 341 GetLoginDisplay()->ShowSigninScreenForCreds(kTestRawAccountId, | 342 GetLoginDisplay()->ShowSigninScreenForCreds(kTestRawAccountId, |
| 342 kTestAccountPassword); | 343 kTestAccountPassword); |
| 343 | 344 session_start_waiter.Wait(); |
| 344 content::WindowedNotificationObserver( | |
| 345 chrome::NOTIFICATION_SESSION_STARTED, | |
| 346 content::NotificationService::AllSources()).Wait(); | |
| 347 | 345 |
| 348 if (wait_for_merge) { | 346 if (wait_for_merge) { |
| 349 // Wait for the session merge to finish. | 347 // Wait for the session merge to finish. |
| 350 WaitForMergeSessionCompletion(OAuth2LoginManager::SESSION_RESTORE_DONE); | 348 WaitForMergeSessionCompletion(OAuth2LoginManager::SESSION_RESTORE_DONE); |
| 351 } | 349 } |
| 352 } | 350 } |
| 353 | 351 |
| 354 DISALLOW_COPY_AND_ASSIGN(OAuth2Test); | 352 DISALLOW_COPY_AND_ASSIGN(OAuth2Test); |
| 355 }; | 353 }; |
| 356 | 354 |
| (...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 407 } | 405 } |
| 408 | 406 |
| 409 scoped_refptr<net::URLRequestContextGetter> context_; | 407 scoped_refptr<net::URLRequestContextGetter> context_; |
| 410 net::CookieList cookie_list_; | 408 net::CookieList cookie_list_; |
| 411 scoped_refptr<content::MessageLoopRunner> runner_; | 409 scoped_refptr<content::MessageLoopRunner> runner_; |
| 412 | 410 |
| 413 DISALLOW_COPY_AND_ASSIGN(CookieReader); | 411 DISALLOW_COPY_AND_ASSIGN(CookieReader); |
| 414 }; | 412 }; |
| 415 | 413 |
| 416 // PRE_MergeSession is testing merge session for a new profile. | 414 // PRE_MergeSession is testing merge session for a new profile. |
| 417 IN_PROC_BROWSER_TEST_F(OAuth2Test, PRE_PRE_PRE_MergeSession) { | 415 IN_PROC_BROWSER_TEST_P(OAuth2Test, PRE_PRE_PRE_MergeSession) { |
| 418 StartNewUserSession(true); | 416 StartNewUserSession(true); |
| 419 // Check for existance of refresh token. | 417 // Check for existance of refresh token. |
| 420 ProfileOAuth2TokenService* token_service = | 418 ProfileOAuth2TokenService* token_service = |
| 421 ProfileOAuth2TokenServiceFactory::GetForProfile( | 419 ProfileOAuth2TokenServiceFactory::GetForProfile( |
| 422 profile()); | 420 profile()); |
| 423 EXPECT_TRUE(token_service->RefreshTokenIsAvailable(kTestAccountId)); | 421 EXPECT_TRUE(token_service->RefreshTokenIsAvailable(kTestAccountId)); |
| 424 | 422 |
| 425 EXPECT_EQ(GetOAuthStatusFromLocalState(kTestAccountId), | 423 EXPECT_EQ(GetOAuthStatusFromLocalState(kTestAccountId), |
| 426 user_manager::User::OAUTH2_TOKEN_STATUS_VALID); | 424 user_manager::User::OAUTH2_TOKEN_STATUS_VALID); |
| 427 | |
| 428 scoped_refptr<CookieReader> cookie_reader(new CookieReader()); | 425 scoped_refptr<CookieReader> cookie_reader(new CookieReader()); |
| 429 cookie_reader->ReadCookies(profile()); | 426 cookie_reader->ReadCookies(profile()); |
| 430 EXPECT_EQ(cookie_reader->GetCookieValue("SID"), kTestSessionSIDCookie); | 427 EXPECT_EQ(cookie_reader->GetCookieValue("SID"), kTestSessionSIDCookie); |
| 431 EXPECT_EQ(cookie_reader->GetCookieValue("LSID"), kTestSessionLSIDCookie); | 428 EXPECT_EQ(cookie_reader->GetCookieValue("LSID"), kTestSessionLSIDCookie); |
| 432 } | 429 } |
| 433 | 430 |
| 434 // MergeSession test is running merge session process for an existing profile | 431 // MergeSession test is running merge session process for an existing profile |
| 435 // that was generated in PRE_PRE_PRE_MergeSession test. In this test, we | 432 // that was generated in PRE_PRE_PRE_MergeSession test. In this test, we |
| 436 // are not running /MergeSession process since the /ListAccounts call confirms | 433 // are not running /MergeSession process since the /ListAccounts call confirms |
| 437 // that the session is not stale. | 434 // that the session is not stale. |
| 438 IN_PROC_BROWSER_TEST_F(OAuth2Test, PRE_PRE_MergeSession) { | 435 IN_PROC_BROWSER_TEST_P(OAuth2Test, PRE_PRE_MergeSession) { |
| 439 SetupGaiaServerForUnexpiredAccount(); | 436 SetupGaiaServerForUnexpiredAccount(); |
| 440 SimulateNetworkOnline(); | 437 SimulateNetworkOnline(); |
| 441 LoginAsExistingUser(); | 438 LoginAsExistingUser(); |
| 442 scoped_refptr<CookieReader> cookie_reader(new CookieReader()); | 439 scoped_refptr<CookieReader> cookie_reader(new CookieReader()); |
| 443 cookie_reader->ReadCookies(profile()); | 440 cookie_reader->ReadCookies(profile()); |
| 444 // These are still cookie values form the initial session since | 441 // These are still cookie values form the initial session since |
| 445 // /ListAccounts | 442 // /ListAccounts |
| 446 EXPECT_EQ(cookie_reader->GetCookieValue("SID"), kTestSessionSIDCookie); | 443 EXPECT_EQ(cookie_reader->GetCookieValue("SID"), kTestSessionSIDCookie); |
| 447 EXPECT_EQ(cookie_reader->GetCookieValue("LSID"), kTestSessionLSIDCookie); | 444 EXPECT_EQ(cookie_reader->GetCookieValue("LSID"), kTestSessionLSIDCookie); |
| 448 } | 445 } |
| 449 | 446 |
| 450 // MergeSession test is running merge session process for an existing profile | 447 // MergeSession test is running merge session process for an existing profile |
| 451 // that was generated in PRE_PRE_MergeSession test. | 448 // that was generated in PRE_PRE_MergeSession test. |
| 452 IN_PROC_BROWSER_TEST_F(OAuth2Test, PRE_MergeSession) { | 449 IN_PROC_BROWSER_TEST_P(OAuth2Test, PRE_MergeSession) { |
| 453 SetupGaiaServerForExpiredAccount(); | 450 SetupGaiaServerForExpiredAccount(); |
| 454 SimulateNetworkOnline(); | 451 SimulateNetworkOnline(); |
| 455 LoginAsExistingUser(); | 452 LoginAsExistingUser(); |
| 456 scoped_refptr<CookieReader> cookie_reader(new CookieReader()); | 453 scoped_refptr<CookieReader> cookie_reader(new CookieReader()); |
| 457 cookie_reader->ReadCookies(profile()); | 454 cookie_reader->ReadCookies(profile()); |
| 458 // These should be cookie values that we generated by calling /MergeSession, | 455 // These should be cookie values that we generated by calling /MergeSession, |
| 459 // since /ListAccounts should have tell us that the initial session cookies | 456 // since /ListAccounts should have tell us that the initial session cookies |
| 460 // are stale. | 457 // are stale. |
| 461 EXPECT_EQ(cookie_reader->GetCookieValue("SID"), kTestSession2SIDCookie); | 458 EXPECT_EQ(cookie_reader->GetCookieValue("SID"), kTestSession2SIDCookie); |
| 462 EXPECT_EQ(cookie_reader->GetCookieValue("LSID"), kTestSession2LSIDCookie); | 459 EXPECT_EQ(cookie_reader->GetCookieValue("LSID"), kTestSession2LSIDCookie); |
| 463 } | 460 } |
| 464 | 461 |
| 465 // MergeSession test is attempting to merge session for an existing profile | 462 // MergeSession test is attempting to merge session for an existing profile |
| 466 // that was generated in PRE_PRE_MergeSession test. This attempt should fail | 463 // that was generated in PRE_PRE_MergeSession test. This attempt should fail |
| 467 // since FakeGaia instance isn't configured to return relevant tokens/cookies. | 464 // since FakeGaia instance isn't configured to return relevant tokens/cookies. |
| 468 IN_PROC_BROWSER_TEST_F(OAuth2Test, MergeSession) { | 465 IN_PROC_BROWSER_TEST_P(OAuth2Test, MergeSession) { |
| 469 SimulateNetworkOnline(); | 466 SimulateNetworkOnline(); |
| 470 | 467 |
| 471 content::WindowedNotificationObserver( | 468 content::WindowedNotificationObserver( |
| 472 chrome::NOTIFICATION_LOGIN_OR_LOCK_WEBUI_VISIBLE, | 469 chrome::NOTIFICATION_LOGIN_OR_LOCK_WEBUI_VISIBLE, |
| 473 content::NotificationService::AllSources()).Wait(); | 470 content::NotificationService::AllSources()).Wait(); |
| 474 | 471 |
| 475 JsExpect("!!document.querySelector('#account-picker')"); | 472 JsExpect("!!document.querySelector('#account-picker')"); |
| 476 JsExpect("!!document.querySelector('#pod-row')"); | 473 JsExpect("!!document.querySelector('#pod-row')"); |
| 477 | 474 |
| 478 EXPECT_EQ(GetOAuthStatusFromLocalState(kTestAccountId), | 475 EXPECT_EQ(GetOAuthStatusFromLocalState(kTestAccountId), |
| (...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 528 http_response->set_content_type("text/html"); | 525 http_response->set_content_type("text/html"); |
| 529 http_response->set_content(kRandomPageContent); | 526 http_response->set_content(kRandomPageContent); |
| 530 } else { | 527 } else { |
| 531 return scoped_ptr<HttpResponse>(); // Request not understood. | 528 return scoped_ptr<HttpResponse>(); // Request not understood. |
| 532 } | 529 } |
| 533 | 530 |
| 534 return http_response.Pass(); | 531 return http_response.Pass(); |
| 535 } | 532 } |
| 536 | 533 |
| 537 // True if we have already served the test page. | 534 // True if we have already served the test page. |
| 538 bool IsPageRequested () { | 535 bool IsPageRequested() { return start_event_.IsSignaled(); } |
| 539 return start_event_.IsSignaled(); | |
| 540 } | |
| 541 | 536 |
| 542 // Waits until we receive a request to serve the test page. | 537 // Waits until we receive a request to serve the test page. |
| 543 void WaitForPageRequest() { | 538 void WaitForPageRequest() { |
| 544 // If we have already served the request, bail out. | 539 // If we have already served the request, bail out. |
| 545 if (start_event_.IsSignaled()) | 540 if (start_event_.IsSignaled()) |
| 546 return; | 541 return; |
| 547 | 542 |
| 548 runner_ = new content::MessageLoopRunner; | 543 runner_ = new content::MessageLoopRunner; |
| 549 runner_->Run(); | 544 runner_->Run(); |
| 550 } | 545 } |
| (...skipping 141 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 692 | 687 |
| 693 Browser* FindOrCreateVisibleBrowser(Profile* profile) { | 688 Browser* FindOrCreateVisibleBrowser(Profile* profile) { |
| 694 chrome::ScopedTabbedBrowserDisplayer displayer( | 689 chrome::ScopedTabbedBrowserDisplayer displayer( |
| 695 profile, chrome::GetActiveDesktop()); | 690 profile, chrome::GetActiveDesktop()); |
| 696 Browser* browser = displayer.browser(); | 691 Browser* browser = displayer.browser(); |
| 697 if (browser->tab_strip_model()->count() == 0) | 692 if (browser->tab_strip_model()->count() == 0) |
| 698 chrome::AddTabAt(browser, GURL(), -1, true); | 693 chrome::AddTabAt(browser, GURL(), -1, true); |
| 699 return browser; | 694 return browser; |
| 700 } | 695 } |
| 701 | 696 |
| 702 IN_PROC_BROWSER_TEST_F(MergeSessionTest, PageThrottle) { | 697 IN_PROC_BROWSER_TEST_P(MergeSessionTest, PageThrottle) { |
| 703 StartNewUserSession(false); | 698 StartNewUserSession(false); |
| 704 | 699 |
| 705 // Try to open a page from google.com. | 700 // Try to open a page from google.com. |
| 706 Browser* browser = | 701 Browser* browser = |
| 707 FindOrCreateVisibleBrowser(profile()); | 702 FindOrCreateVisibleBrowser(profile()); |
| 708 ui_test_utils::NavigateToURLWithDisposition( | 703 ui_test_utils::NavigateToURLWithDisposition( |
| 709 browser, | 704 browser, |
| 710 fake_google_page_url_, | 705 fake_google_page_url_, |
| 711 CURRENT_TAB, ui_test_utils::BROWSER_TEST_NONE); | 706 CURRENT_TAB, ui_test_utils::BROWSER_TEST_NONE); |
| 712 | 707 |
| (...skipping 22 matching lines...) Expand all Loading... |
| 735 AppModalDialog* dialog = ui_test_utils::WaitForAppModalDialog(); | 730 AppModalDialog* dialog = ui_test_utils::WaitForAppModalDialog(); |
| 736 ASSERT_TRUE(dialog->IsJavaScriptModalDialog()); | 731 ASSERT_TRUE(dialog->IsJavaScriptModalDialog()); |
| 737 JavaScriptAppModalDialog* js_dialog = | 732 JavaScriptAppModalDialog* js_dialog = |
| 738 static_cast<JavaScriptAppModalDialog*>(dialog); | 733 static_cast<JavaScriptAppModalDialog*>(dialog); |
| 739 js_dialog->native_dialog()->AcceptAppModalDialog(); | 734 js_dialog->native_dialog()->AcceptAppModalDialog(); |
| 740 | 735 |
| 741 ui_test_utils::GetCurrentTabTitle(browser, &title); | 736 ui_test_utils::GetCurrentTabTitle(browser, &title); |
| 742 DVLOG(1) << "Loaded page at the end : " << title; | 737 DVLOG(1) << "Loaded page at the end : " << title; |
| 743 } | 738 } |
| 744 | 739 |
| 745 IN_PROC_BROWSER_TEST_F(MergeSessionTest, XHRThrottle) { | 740 IN_PROC_BROWSER_TEST_P(MergeSessionTest, XHRThrottle) { |
| 746 StartNewUserSession(false); | 741 StartNewUserSession(false); |
| 747 | 742 |
| 748 // Wait until we get send merge session request. | 743 // Wait until we get send merge session request. |
| 749 WaitForMergeSessionToStart(); | 744 WaitForMergeSessionToStart(); |
| 750 | 745 |
| 751 // Reset ExtensionBrowserTest::observer_ to the right browser object. | 746 // Reset ExtensionBrowserTest::observer_ to the right browser object. |
| 752 Browser* browser = FindOrCreateVisibleBrowser(profile()); | 747 Browser* browser = FindOrCreateVisibleBrowser(profile()); |
| 753 observer_.reset(new ExtensionTestNotificationObserver(browser)); | 748 observer_.reset(new ExtensionTestNotificationObserver(browser)); |
| 754 | 749 |
| 755 // Run background page tests. The tests will just wait for XHR request | 750 // Run background page tests. The tests will just wait for XHR request |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 789 ASSERT_TRUE(non_google_xhr_listener->WaitUntilSatisfied()); | 784 ASSERT_TRUE(non_google_xhr_listener->WaitUntilSatisfied()); |
| 790 | 785 |
| 791 if (!catcher.GetNextResult()) { | 786 if (!catcher.GetNextResult()) { |
| 792 std::string message = catcher.message(); | 787 std::string message = catcher.message(); |
| 793 ADD_FAILURE() << "Tests failed: " << message; | 788 ADD_FAILURE() << "Tests failed: " << message; |
| 794 } | 789 } |
| 795 | 790 |
| 796 EXPECT_TRUE(fake_google_.IsPageRequested()); | 791 EXPECT_TRUE(fake_google_.IsPageRequested()); |
| 797 } | 792 } |
| 798 | 793 |
| 794 INSTANTIATE_TEST_CASE_P(OAuth2Suite, OAuth2Test, testing::Bool()); |
| 795 INSTANTIATE_TEST_CASE_P(MergeSessionSuite, MergeSessionTest, testing::Bool()); |
| 796 |
| 799 } // namespace chromeos | 797 } // namespace chromeos |
| OLD | NEW |