| 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 "components/autofill/content/browser/wallet/wallet_signin_helper.h" | 5 #include "components/autofill/content/browser/wallet/wallet_signin_helper.h" |
| 6 | 6 |
| 7 #include "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/bind_helpers.h" | 8 #include "base/bind_helpers.h" |
| 9 #include "base/strings/stringprintf.h" | 9 #include "base/strings/stringprintf.h" |
| 10 #include "chrome/test/base/testing_profile.h" | |
| 11 #include "components/autofill/content/browser/wallet/wallet_service_url.h" | 10 #include "components/autofill/content/browser/wallet/wallet_service_url.h" |
| 12 #include "components/autofill/content/browser/wallet/wallet_signin_helper_delega
te.h" | 11 #include "components/autofill/content/browser/wallet/wallet_signin_helper_delega
te.h" |
| 12 #include "content/public/test/test_browser_context.h" |
| 13 #include "content/public/test/test_browser_thread.h" | 13 #include "content/public/test/test_browser_thread.h" |
| 14 #include "google_apis/gaia/gaia_constants.h" | 14 #include "google_apis/gaia/gaia_constants.h" |
| 15 #include "google_apis/gaia/gaia_urls.h" | 15 #include "google_apis/gaia/gaia_urls.h" |
| 16 #include "google_apis/gaia/google_service_auth_error.h" | 16 #include "google_apis/gaia/google_service_auth_error.h" |
| 17 #include "net/url_request/test_url_fetcher_factory.h" | 17 #include "net/url_request/test_url_fetcher_factory.h" |
| 18 #include "net/url_request/url_request.h" | 18 #include "net/url_request/url_request.h" |
| 19 #include "net/url_request/url_request_context_getter.h" | 19 #include "net/url_request/url_request_context_getter.h" |
| 20 #include "net/url_request/url_request_status.h" | 20 #include "net/url_request/url_request_status.h" |
| 21 #include "testing/gmock/include/gmock/gmock.h" | 21 #include "testing/gmock/include/gmock/gmock.h" |
| 22 #include "testing/gtest/include/gtest/gtest.h" | 22 #include "testing/gtest/include/gtest/gtest.h" |
| (...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 72 }; | 72 }; |
| 73 | 73 |
| 74 } // namespace | 74 } // namespace |
| 75 | 75 |
| 76 class WalletSigninHelperTest : public testing::Test { | 76 class WalletSigninHelperTest : public testing::Test { |
| 77 public: | 77 public: |
| 78 WalletSigninHelperTest() : io_thread_(content::BrowserThread::IO) {} | 78 WalletSigninHelperTest() : io_thread_(content::BrowserThread::IO) {} |
| 79 | 79 |
| 80 virtual void SetUp() OVERRIDE { | 80 virtual void SetUp() OVERRIDE { |
| 81 io_thread_.StartIOThread(); | 81 io_thread_.StartIOThread(); |
| 82 profile_.CreateRequestContext(); | |
| 83 signin_helper_.reset(new WalletSigninHelperForTesting( | 82 signin_helper_.reset(new WalletSigninHelperForTesting( |
| 84 &mock_delegate_, | 83 &mock_delegate_, |
| 85 profile_.GetRequestContext())); | 84 browser_context_.GetRequestContext())); |
| 86 EXPECT_EQ(WalletSigninHelperForTesting::IDLE, state()); | 85 EXPECT_EQ(WalletSigninHelperForTesting::IDLE, state()); |
| 87 } | 86 } |
| 88 | 87 |
| 89 virtual void TearDown() OVERRIDE { | 88 virtual void TearDown() OVERRIDE { |
| 90 signin_helper_.reset(); | 89 signin_helper_.reset(); |
| 91 profile_.ResetRequestContext(); | |
| 92 io_thread_.Stop(); | 90 io_thread_.Stop(); |
| 93 } | 91 } |
| 94 | 92 |
| 95 protected: | 93 protected: |
| 96 // Sets up a response for the mock URLFetcher and completes the request. | 94 // Sets up a response for the mock URLFetcher and completes the request. |
| 97 void SetUpFetcherResponseAndCompleteRequest( | 95 void SetUpFetcherResponseAndCompleteRequest( |
| 98 const std::string& url, | 96 const std::string& url, |
| 99 int response_code, | 97 int response_code, |
| 100 const net::ResponseCookies& cookies, | 98 const net::ResponseCookies& cookies, |
| 101 const std::string& response_string) { | 99 const std::string& response_string) { |
| (...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 173 } | 171 } |
| 174 | 172 |
| 175 WalletSigninHelperForTesting::State state() const { | 173 WalletSigninHelperForTesting::State state() const { |
| 176 return signin_helper_->state(); | 174 return signin_helper_->state(); |
| 177 } | 175 } |
| 178 | 176 |
| 179 scoped_ptr<WalletSigninHelperForTesting> signin_helper_; | 177 scoped_ptr<WalletSigninHelperForTesting> signin_helper_; |
| 180 MockWalletSigninHelperDelegate mock_delegate_; | 178 MockWalletSigninHelperDelegate mock_delegate_; |
| 181 | 179 |
| 182 private: | 180 private: |
| 183 // The profile's request context must be released on the IO thread. | |
| 184 content::TestBrowserThread io_thread_; | 181 content::TestBrowserThread io_thread_; |
| 185 net::TestURLFetcherFactory factory_; | 182 net::TestURLFetcherFactory factory_; |
| 186 TestingProfile profile_; | 183 content::TestBrowserContext browser_context_; |
| 187 }; | 184 }; |
| 188 | 185 |
| 189 TEST_F(WalletSigninHelperTest, PassiveSigninSuccessful) { | 186 TEST_F(WalletSigninHelperTest, PassiveSigninSuccessful) { |
| 190 EXPECT_CALL(mock_delegate_, OnPassiveSigninSuccess("user@gmail.com")); | 187 EXPECT_CALL(mock_delegate_, OnPassiveSigninSuccess("user@gmail.com")); |
| 191 signin_helper_->StartPassiveSignin(); | 188 signin_helper_->StartPassiveSignin(); |
| 192 MockSuccessfulPassiveAuthUrlMergeAndRedirectResponse(); | 189 MockSuccessfulPassiveAuthUrlMergeAndRedirectResponse(); |
| 193 MockSuccessfulGetAccountInfoResponse("user@gmail.com"); | 190 MockSuccessfulGetAccountInfoResponse("user@gmail.com"); |
| 194 } | 191 } |
| 195 | 192 |
| 196 TEST_F(WalletSigninHelperTest, PassiveSigninFailedSignin) { | 193 TEST_F(WalletSigninHelperTest, PassiveSigninFailedSignin) { |
| (...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 244 signin_helper_->StartAutomaticSignin("123SID", "123LSID"); | 241 signin_helper_->StartAutomaticSignin("123SID", "123LSID"); |
| 245 MockSuccessfulGaiaUserInfoResponse("user@gmail.com"); | 242 MockSuccessfulGaiaUserInfoResponse("user@gmail.com"); |
| 246 MockSuccessfulOAuthLoginResponse(); | 243 MockSuccessfulOAuthLoginResponse(); |
| 247 MockFailedPassiveAuthUrlMergeAndRedirectResponse404(); | 244 MockFailedPassiveAuthUrlMergeAndRedirectResponse404(); |
| 248 } | 245 } |
| 249 | 246 |
| 250 // TODO(aruslan): http://crbug.com/188317 Need more tests. | 247 // TODO(aruslan): http://crbug.com/188317 Need more tests. |
| 251 | 248 |
| 252 } // namespace wallet | 249 } // namespace wallet |
| 253 } // namespace autofill | 250 } // namespace autofill |
| OLD | NEW |