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