| 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" |
| (...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 98 login_manager->AddObserver(this); | 98 login_manager->AddObserver(this); |
| 99 runner_ = new content::MessageLoopRunner; | 99 runner_ = new content::MessageLoopRunner; |
| 100 runner_->Run(); | 100 runner_->Run(); |
| 101 login_manager->RemoveObserver(this); | 101 login_manager->RemoveObserver(this); |
| 102 } | 102 } |
| 103 | 103 |
| 104 OAuth2LoginManager::SessionRestoreState final_state() { return final_state_; } | 104 OAuth2LoginManager::SessionRestoreState final_state() { return final_state_; } |
| 105 | 105 |
| 106 private: | 106 private: |
| 107 // OAuth2LoginManager::Observer overrides. | 107 // OAuth2LoginManager::Observer overrides. |
| 108 virtual void OnSessionRestoreStateChanged( | 108 void OnSessionRestoreStateChanged( |
| 109 Profile* user_profile, | 109 Profile* user_profile, |
| 110 OAuth2LoginManager::SessionRestoreState state) override { | 110 OAuth2LoginManager::SessionRestoreState state) override { |
| 111 if (!waiting_for_state_) | 111 if (!waiting_for_state_) |
| 112 return; | 112 return; |
| 113 | 113 |
| 114 if (states_.find(state) == states_.end()) | 114 if (states_.find(state) == states_.end()) |
| 115 return; | 115 return; |
| 116 | 116 |
| 117 final_state_ = state; | 117 final_state_ = state; |
| 118 waiting_for_state_ = false; | 118 waiting_for_state_ = false; |
| 119 runner_->Quit(); | 119 runner_->Quit(); |
| 120 } | 120 } |
| 121 | 121 |
| 122 Profile* profile_; | 122 Profile* profile_; |
| 123 std::set<OAuth2LoginManager::SessionRestoreState> states_; | 123 std::set<OAuth2LoginManager::SessionRestoreState> states_; |
| 124 bool waiting_for_state_; | 124 bool waiting_for_state_; |
| 125 OAuth2LoginManager::SessionRestoreState final_state_; | 125 OAuth2LoginManager::SessionRestoreState final_state_; |
| 126 scoped_refptr<content::MessageLoopRunner> runner_; | 126 scoped_refptr<content::MessageLoopRunner> runner_; |
| 127 | 127 |
| 128 DISALLOW_COPY_AND_ASSIGN(OAuth2LoginManagerStateWaiter); | 128 DISALLOW_COPY_AND_ASSIGN(OAuth2LoginManagerStateWaiter); |
| 129 }; | 129 }; |
| 130 | 130 |
| 131 } // namespace | 131 } // namespace |
| 132 | 132 |
| 133 class OAuth2Test : public OobeBaseTest { | 133 class OAuth2Test : public OobeBaseTest { |
| 134 protected: | 134 protected: |
| 135 OAuth2Test() {} | 135 OAuth2Test() {} |
| 136 | 136 |
| 137 virtual void SetUpCommandLine(base::CommandLine* command_line) override { | 137 void SetUpCommandLine(base::CommandLine* command_line) override { |
| 138 OobeBaseTest::SetUpCommandLine(command_line); | 138 OobeBaseTest::SetUpCommandLine(command_line); |
| 139 | 139 |
| 140 // 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 |
| 141 // makes OAuth2Test.MergeSession test flaky http://crbug.com/408867. | 141 // makes OAuth2Test.MergeSession test flaky http://crbug.com/408867. |
| 142 command_line->AppendSwitch(switches::kDisableSync); | 142 command_line->AppendSwitch(switches::kDisableSync); |
| 143 } | 143 } |
| 144 | 144 |
| 145 void SetupGaiaServerForNewAccount() { | 145 void SetupGaiaServerForNewAccount() { |
| 146 FakeGaia::MergeSessionParams params; | 146 FakeGaia::MergeSessionParams params; |
| 147 params.auth_sid_cookie = kTestAuthSIDCookie; | 147 params.auth_sid_cookie = kTestAuthSIDCookie; |
| (...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 222 user_id, &oauth_token_status)) { | 222 user_id, &oauth_token_status)) { |
| 223 user_manager::User::OAuthTokenStatus result = | 223 user_manager::User::OAuthTokenStatus result = |
| 224 static_cast<user_manager::User::OAuthTokenStatus>(oauth_token_status); | 224 static_cast<user_manager::User::OAuthTokenStatus>(oauth_token_status); |
| 225 return result; | 225 return result; |
| 226 } | 226 } |
| 227 return user_manager::User::OAUTH_TOKEN_STATUS_UNKNOWN; | 227 return user_manager::User::OAUTH_TOKEN_STATUS_UNKNOWN; |
| 228 } | 228 } |
| 229 | 229 |
| 230 protected: | 230 protected: |
| 231 // OobeBaseTest overrides. | 231 // OobeBaseTest overrides. |
| 232 virtual Profile* profile() override { | 232 Profile* profile() override { |
| 233 if (user_manager::UserManager::Get()->GetActiveUser()) | 233 if (user_manager::UserManager::Get()->GetActiveUser()) |
| 234 return ProfileManager::GetPrimaryUserProfile(); | 234 return ProfileManager::GetPrimaryUserProfile(); |
| 235 | 235 |
| 236 return OobeBaseTest::profile(); | 236 return OobeBaseTest::profile(); |
| 237 } | 237 } |
| 238 | 238 |
| 239 bool AddUserToSession(const std::string& username, | 239 bool AddUserToSession(const std::string& username, |
| 240 const std::string& password) { | 240 const std::string& password) { |
| 241 ExistingUserController* controller = | 241 ExistingUserController* controller = |
| 242 ExistingUserController::current_controller(); | 242 ExistingUserController::current_controller(); |
| (...skipping 337 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 580 // If we have already served the request, bail out. | 580 // If we have already served the request, bail out. |
| 581 if (start_event_.IsSignaled()) | 581 if (start_event_.IsSignaled()) |
| 582 return; | 582 return; |
| 583 | 583 |
| 584 runner_ = new content::MessageLoopRunner; | 584 runner_ = new content::MessageLoopRunner; |
| 585 runner_->Run(); | 585 runner_->Run(); |
| 586 } | 586 } |
| 587 | 587 |
| 588 private: | 588 private: |
| 589 // FakeGaia overrides. | 589 // FakeGaia overrides. |
| 590 virtual void HandleMergeSession(const HttpRequest& request, | 590 void HandleMergeSession(const HttpRequest& request, |
| 591 BasicHttpResponse* http_response) override { | 591 BasicHttpResponse* http_response) override { |
| 592 start_event_.Signal(); | 592 start_event_.Signal(); |
| 593 content::BrowserThread::PostTask( | 593 content::BrowserThread::PostTask( |
| 594 content::BrowserThread::UI, FROM_HERE, | 594 content::BrowserThread::UI, FROM_HERE, |
| 595 base::Bind(&DelayedFakeGaia::QuitRunnerOnUIThread, | 595 base::Bind(&DelayedFakeGaia::QuitRunnerOnUIThread, |
| 596 base::Unretained(this))); | 596 base::Unretained(this))); |
| 597 blocking_event_.Wait(); | 597 blocking_event_.Wait(); |
| 598 FakeGaia::HandleMergeSession(request, http_response); | 598 FakeGaia::HandleMergeSession(request, http_response); |
| 599 } | 599 } |
| 600 | 600 |
| 601 void QuitRunnerOnUIThread() { | 601 void QuitRunnerOnUIThread() { |
| 602 if (runner_.get()) | 602 if (runner_.get()) |
| 603 runner_->Quit(); | 603 runner_->Quit(); |
| 604 } | 604 } |
| 605 | 605 |
| 606 base::WaitableEvent blocking_event_; | 606 base::WaitableEvent blocking_event_; |
| 607 base::WaitableEvent start_event_; | 607 base::WaitableEvent start_event_; |
| 608 scoped_refptr<content::MessageLoopRunner> runner_; | 608 scoped_refptr<content::MessageLoopRunner> runner_; |
| 609 | 609 |
| 610 DISALLOW_COPY_AND_ASSIGN(DelayedFakeGaia); | 610 DISALLOW_COPY_AND_ASSIGN(DelayedFakeGaia); |
| 611 }; | 611 }; |
| 612 | 612 |
| 613 class MergeSessionTest : public OAuth2Test { | 613 class MergeSessionTest : public OAuth2Test { |
| 614 protected: | 614 protected: |
| 615 MergeSessionTest() : delayed_fake_gaia_(new DelayedFakeGaia()) { | 615 MergeSessionTest() : delayed_fake_gaia_(new DelayedFakeGaia()) { |
| 616 fake_gaia_.reset(delayed_fake_gaia_); | 616 fake_gaia_.reset(delayed_fake_gaia_); |
| 617 } | 617 } |
| 618 | 618 |
| 619 virtual void SetUpCommandLine(base::CommandLine* command_line) override { | 619 void SetUpCommandLine(base::CommandLine* command_line) override { |
| 620 OAuth2Test::SetUpCommandLine(command_line); | 620 OAuth2Test::SetUpCommandLine(command_line); |
| 621 | 621 |
| 622 // Get fake URL for fake google.com. | 622 // Get fake URL for fake google.com. |
| 623 const GURL& server_url = embedded_test_server()->base_url(); | 623 const GURL& server_url = embedded_test_server()->base_url(); |
| 624 std::string google_host("www.google.com"); | 624 std::string google_host("www.google.com"); |
| 625 GURL::Replacements replace_google_host; | 625 GURL::Replacements replace_google_host; |
| 626 replace_google_host.SetHostStr(google_host); | 626 replace_google_host.SetHostStr(google_host); |
| 627 GURL google_url = server_url.ReplaceComponents(replace_google_host); | 627 GURL google_url = server_url.ReplaceComponents(replace_google_host); |
| 628 fake_google_page_url_ = google_url.Resolve(kHelloPagePath); | 628 fake_google_page_url_ = google_url.Resolve(kHelloPagePath); |
| 629 | 629 |
| 630 std::string non_google_host("www.somethingelse.org"); | 630 std::string non_google_host("www.somethingelse.org"); |
| 631 GURL::Replacements replace_non_google_host; | 631 GURL::Replacements replace_non_google_host; |
| 632 replace_non_google_host.SetHostStr(non_google_host); | 632 replace_non_google_host.SetHostStr(non_google_host); |
| 633 GURL non_google_url = server_url.ReplaceComponents(replace_non_google_host); | 633 GURL non_google_url = server_url.ReplaceComponents(replace_non_google_host); |
| 634 non_google_page_url_ = non_google_url.Resolve(kRandomPagePath); | 634 non_google_page_url_ = non_google_url.Resolve(kRandomPagePath); |
| 635 } | 635 } |
| 636 | 636 |
| 637 virtual void SetUp() override { | 637 void SetUp() override { |
| 638 embedded_test_server()->RegisterRequestHandler( | 638 embedded_test_server()->RegisterRequestHandler( |
| 639 base::Bind(&FakeGoogle::HandleRequest, | 639 base::Bind(&FakeGoogle::HandleRequest, |
| 640 base::Unretained(&fake_google_))); | 640 base::Unretained(&fake_google_))); |
| 641 OAuth2Test::SetUp(); | 641 OAuth2Test::SetUp(); |
| 642 } | 642 } |
| 643 | 643 |
| 644 protected: | 644 protected: |
| 645 void UnblockMergeSession() { | 645 void UnblockMergeSession() { |
| 646 delayed_fake_gaia_->UnblockMergeSession(); | 646 delayed_fake_gaia_->UnblockMergeSession(); |
| 647 } | 647 } |
| (...skipping 144 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 792 | 792 |
| 793 if (!catcher.GetNextResult()) { | 793 if (!catcher.GetNextResult()) { |
| 794 std::string message = catcher.message(); | 794 std::string message = catcher.message(); |
| 795 ADD_FAILURE() << "Tests failed: " << message; | 795 ADD_FAILURE() << "Tests failed: " << message; |
| 796 } | 796 } |
| 797 | 797 |
| 798 EXPECT_TRUE(fake_google_.IsPageRequested()); | 798 EXPECT_TRUE(fake_google_.IsPageRequested()); |
| 799 } | 799 } |
| 800 | 800 |
| 801 } // namespace chromeos | 801 } // namespace chromeos |
| OLD | NEW |