Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(5)

Side by Side Diff: components/autofill/content/browser/wallet/wallet_signin_helper_unittest.cc

Issue 17465003: Fix most tests in //components/autofill/content to not depend on //chrome. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Remove IO thread, seems not needed. Created 7 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
68 68
69 // Bring in the State enum. 69 // Bring in the State enum.
70 using WalletSigninHelper::State; 70 using WalletSigninHelper::State;
71 using WalletSigninHelper::IDLE; 71 using WalletSigninHelper::IDLE;
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() {}
79 79
80 virtual void SetUp() OVERRIDE { 80 virtual void SetUp() OVERRIDE {
81 io_thread_.StartIOThread();
82 profile_.CreateRequestContext();
83 signin_helper_.reset(new WalletSigninHelperForTesting( 81 signin_helper_.reset(new WalletSigninHelperForTesting(
84 &mock_delegate_, 82 &mock_delegate_,
85 profile_.GetRequestContext())); 83 browser_context_.GetRequestContext()));
86 EXPECT_EQ(WalletSigninHelperForTesting::IDLE, state()); 84 EXPECT_EQ(WalletSigninHelperForTesting::IDLE, state());
87 } 85 }
88 86
89 virtual void TearDown() OVERRIDE { 87 virtual void TearDown() OVERRIDE {
90 signin_helper_.reset(); 88 signin_helper_.reset();
91 profile_.ResetRequestContext();
92 io_thread_.Stop();
93 } 89 }
94 90
95 protected: 91 protected:
96 // Sets up a response for the mock URLFetcher and completes the request. 92 // Sets up a response for the mock URLFetcher and completes the request.
97 void SetUpFetcherResponseAndCompleteRequest( 93 void SetUpFetcherResponseAndCompleteRequest(
98 const std::string& url, 94 const std::string& url,
99 int response_code, 95 int response_code,
100 const net::ResponseCookies& cookies, 96 const net::ResponseCookies& cookies,
101 const std::string& response_string) { 97 const std::string& response_string) {
102 net::TestURLFetcher* fetcher = factory_.GetFetcherByID(0); 98 net::TestURLFetcher* fetcher = factory_.GetFetcherByID(0);
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after
173 } 169 }
174 170
175 WalletSigninHelperForTesting::State state() const { 171 WalletSigninHelperForTesting::State state() const {
176 return signin_helper_->state(); 172 return signin_helper_->state();
177 } 173 }
178 174
179 scoped_ptr<WalletSigninHelperForTesting> signin_helper_; 175 scoped_ptr<WalletSigninHelperForTesting> signin_helper_;
180 MockWalletSigninHelperDelegate mock_delegate_; 176 MockWalletSigninHelperDelegate mock_delegate_;
181 177
182 private: 178 private:
183 // The profile's request context must be released on the IO thread.
184 content::TestBrowserThread io_thread_;
185 net::TestURLFetcherFactory factory_; 179 net::TestURLFetcherFactory factory_;
186 TestingProfile profile_; 180 content::TestBrowserContext browser_context_;
187 }; 181 };
188 182
189 TEST_F(WalletSigninHelperTest, PassiveSigninSuccessful) { 183 TEST_F(WalletSigninHelperTest, PassiveSigninSuccessful) {
190 EXPECT_CALL(mock_delegate_, OnPassiveSigninSuccess("user@gmail.com")); 184 EXPECT_CALL(mock_delegate_, OnPassiveSigninSuccess("user@gmail.com"));
191 signin_helper_->StartPassiveSignin(); 185 signin_helper_->StartPassiveSignin();
192 MockSuccessfulPassiveAuthUrlMergeAndRedirectResponse(); 186 MockSuccessfulPassiveAuthUrlMergeAndRedirectResponse();
193 MockSuccessfulGetAccountInfoResponse("user@gmail.com"); 187 MockSuccessfulGetAccountInfoResponse("user@gmail.com");
194 } 188 }
195 189
196 TEST_F(WalletSigninHelperTest, PassiveSigninFailedSignin) { 190 TEST_F(WalletSigninHelperTest, PassiveSigninFailedSignin) {
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
244 signin_helper_->StartAutomaticSignin("123SID", "123LSID"); 238 signin_helper_->StartAutomaticSignin("123SID", "123LSID");
245 MockSuccessfulGaiaUserInfoResponse("user@gmail.com"); 239 MockSuccessfulGaiaUserInfoResponse("user@gmail.com");
246 MockSuccessfulOAuthLoginResponse(); 240 MockSuccessfulOAuthLoginResponse();
247 MockFailedPassiveAuthUrlMergeAndRedirectResponse404(); 241 MockFailedPassiveAuthUrlMergeAndRedirectResponse404();
248 } 242 }
249 243
250 // TODO(aruslan): http://crbug.com/188317 Need more tests. 244 // TODO(aruslan): http://crbug.com/188317 Need more tests.
251 245
252 } // namespace wallet 246 } // namespace wallet
253 } // namespace autofill 247 } // namespace autofill
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698