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