| 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/http/http_status_code.h" | 17 #include "net/http/http_status_code.h" |
| 18 #include "net/url_request/test_url_fetcher_factory.h" | 18 #include "net/url_request/test_url_fetcher_factory.h" |
| 19 #include "net/url_request/url_request.h" | 19 #include "net/url_request/url_request.h" |
| 20 #include "net/url_request/url_request_context_getter.h" | 20 #include "net/url_request/url_request_context_getter.h" |
| 21 #include "net/url_request/url_request_status.h" | 21 #include "net/url_request/url_request_status.h" |
| 22 #include "testing/gmock/include/gmock/gmock.h" | 22 #include "testing/gmock/include/gmock/gmock.h" |
| (...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 69 | 69 |
| 70 // Bring in the State enum. | 70 // Bring in the State enum. |
| 71 using WalletSigninHelper::State; | 71 using WalletSigninHelper::State; |
| 72 using WalletSigninHelper::IDLE; | 72 using WalletSigninHelper::IDLE; |
| 73 }; | 73 }; |
| 74 | 74 |
| 75 } // namespace | 75 } // namespace |
| 76 | 76 |
| 77 class WalletSigninHelperTest : public testing::Test { | 77 class WalletSigninHelperTest : public testing::Test { |
| 78 public: | 78 public: |
| 79 WalletSigninHelperTest() : io_thread_(content::BrowserThread::IO) {} | 79 WalletSigninHelperTest() {} |
| 80 | 80 |
| 81 virtual void SetUp() OVERRIDE { | 81 virtual void SetUp() OVERRIDE { |
| 82 io_thread_.StartIOThread(); | |
| 83 profile_.CreateRequestContext(); | |
| 84 signin_helper_.reset(new WalletSigninHelperForTesting( | 82 signin_helper_.reset(new WalletSigninHelperForTesting( |
| 85 &mock_delegate_, | 83 &mock_delegate_, |
| 86 profile_.GetRequestContext())); | 84 browser_context_.GetRequestContext())); |
| 87 EXPECT_EQ(WalletSigninHelperForTesting::IDLE, state()); | 85 EXPECT_EQ(WalletSigninHelperForTesting::IDLE, state()); |
| 88 } | 86 } |
| 89 | 87 |
| 90 virtual void TearDown() OVERRIDE { | 88 virtual void TearDown() OVERRIDE { |
| 91 signin_helper_.reset(); | 89 signin_helper_.reset(); |
| 92 profile_.ResetRequestContext(); | |
| 93 io_thread_.Stop(); | |
| 94 } | 90 } |
| 95 | 91 |
| 96 protected: | 92 protected: |
| 97 // Sets up a response for the mock URLFetcher and completes the request. | 93 // Sets up a response for the mock URLFetcher and completes the request. |
| 98 void SetUpFetcherResponseAndCompleteRequest( | 94 void SetUpFetcherResponseAndCompleteRequest( |
| 99 const std::string& url, | 95 const std::string& url, |
| 100 int response_code, | 96 int response_code, |
| 101 const net::ResponseCookies& cookies, | 97 const net::ResponseCookies& cookies, |
| 102 const std::string& response_string) { | 98 const std::string& response_string) { |
| 103 net::TestURLFetcher* fetcher = factory_.GetFetcherByID(0); | 99 net::TestURLFetcher* fetcher = factory_.GetFetcherByID(0); |
| (...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 181 } | 177 } |
| 182 | 178 |
| 183 WalletSigninHelperForTesting::State state() const { | 179 WalletSigninHelperForTesting::State state() const { |
| 184 return signin_helper_->state(); | 180 return signin_helper_->state(); |
| 185 } | 181 } |
| 186 | 182 |
| 187 scoped_ptr<WalletSigninHelperForTesting> signin_helper_; | 183 scoped_ptr<WalletSigninHelperForTesting> signin_helper_; |
| 188 MockWalletSigninHelperDelegate mock_delegate_; | 184 MockWalletSigninHelperDelegate mock_delegate_; |
| 189 | 185 |
| 190 private: | 186 private: |
| 191 // The profile's request context must be released on the IO thread. | |
| 192 content::TestBrowserThread io_thread_; | |
| 193 net::TestURLFetcherFactory factory_; | 187 net::TestURLFetcherFactory factory_; |
| 194 TestingProfile profile_; | 188 content::TestBrowserContext browser_context_; |
| 195 }; | 189 }; |
| 196 | 190 |
| 197 TEST_F(WalletSigninHelperTest, PassiveSigninSuccessful) { | 191 TEST_F(WalletSigninHelperTest, PassiveSigninSuccessful) { |
| 198 EXPECT_CALL(mock_delegate_, OnPassiveSigninSuccess("user@gmail.com")); | 192 EXPECT_CALL(mock_delegate_, OnPassiveSigninSuccess("user@gmail.com")); |
| 199 signin_helper_->StartPassiveSignin(); | 193 signin_helper_->StartPassiveSignin(); |
| 200 MockSuccessfulPassiveSignInResponse(); | 194 MockSuccessfulPassiveSignInResponse(); |
| 201 MockSuccessfulGetAccountInfoResponse("user@gmail.com"); | 195 MockSuccessfulGetAccountInfoResponse("user@gmail.com"); |
| 202 } | 196 } |
| 203 | 197 |
| 204 TEST_F(WalletSigninHelperTest, PassiveSigninFailedSignin404) { | 198 TEST_F(WalletSigninHelperTest, PassiveSigninFailedSignin404) { |
| (...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 266 signin_helper_->StartAutomaticSignin("123SID", "123LSID"); | 260 signin_helper_->StartAutomaticSignin("123SID", "123LSID"); |
| 267 MockSuccessfulGaiaUserInfoResponse("user@gmail.com"); | 261 MockSuccessfulGaiaUserInfoResponse("user@gmail.com"); |
| 268 MockSuccessfulOAuthLoginResponse(); | 262 MockSuccessfulOAuthLoginResponse(); |
| 269 MockFailedPassiveSignInResponseNo(); | 263 MockFailedPassiveSignInResponseNo(); |
| 270 } | 264 } |
| 271 | 265 |
| 272 // TODO(aruslan): http://crbug.com/188317 Need more tests. | 266 // TODO(aruslan): http://crbug.com/188317 Need more tests. |
| 273 | 267 |
| 274 } // namespace wallet | 268 } // namespace wallet |
| 275 } // namespace autofill | 269 } // namespace autofill |
| OLD | NEW |