diff options
author | tfarina@chromium.org <tfarina@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-07-04 02:52:56 +0000 |
---|---|---|
committer | tfarina@chromium.org <tfarina@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-07-04 02:52:56 +0000 |
commit | 79c4a0cf855838b5c30ef2d13621a7f2ea8f3048 (patch) | |
tree | bfa658a3baa8f208a70360339e6b18f9e37f1164 /google_apis | |
parent | f9380385b001d9aaab6b82d4bd01f0bd24cd52a1 (diff) | |
download | chromium_src-79c4a0cf855838b5c30ef2d13621a7f2ea8f3048.zip chromium_src-79c4a0cf855838b5c30ef2d13621a7f2ea8f3048.tar.gz chromium_src-79c4a0cf855838b5c30ef2d13621a7f2ea8f3048.tar.bz2 |
google_apis: Break the dependency on TestingProfile from chrome.
TestingProfile was only being used in order to retrieve a
net::TestURLRequestContextGetter. google_apis tests can do this themselves
using a combination of MessageLoop and MessageLoopProxy.
This one more step forward on moving these tests to a google_apis_unittests
target.
BUG=255301
TEST=unit_tests
R=joi@chromium.org
Review URL: https://chromiumcodereview.appspot.com/18285002
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@210115 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'google_apis')
-rw-r--r-- | google_apis/gaia/DEPS | 1 | ||||
-rw-r--r-- | google_apis/gaia/gaia_auth_fetcher_unittest.cc | 70 | ||||
-rw-r--r-- | google_apis/gaia/gaia_oauth_client_unittest.cc | 28 | ||||
-rw-r--r-- | google_apis/gaia/oauth2_access_token_fetcher_unittest.cc | 10 | ||||
-rw-r--r-- | google_apis/gaia/oauth2_api_call_flow_unittest.cc | 17 |
5 files changed, 63 insertions, 63 deletions
diff --git a/google_apis/gaia/DEPS b/google_apis/gaia/DEPS index 6fb8e99..e88533d 100644 --- a/google_apis/gaia/DEPS +++ b/google_apis/gaia/DEPS @@ -1,6 +1,5 @@ specific_include_rules = { ".*_[a-z]*test\.cc": [ - "+chrome/test/base/testing_profile.h", "+content/public/test/test_browser_thread.h", ] } diff --git a/google_apis/gaia/gaia_auth_fetcher_unittest.cc b/google_apis/gaia/gaia_auth_fetcher_unittest.cc index 336a9bc..5cce72b 100644 --- a/google_apis/gaia/gaia_auth_fetcher_unittest.cc +++ b/google_apis/gaia/gaia_auth_fetcher_unittest.cc @@ -11,7 +11,6 @@ #include "base/message_loop.h" #include "base/strings/stringprintf.h" #include "base/values.h" -#include "chrome/test/base/testing_profile.h" #include "google_apis/gaia/gaia_auth_consumer.h" #include "google_apis/gaia/gaia_auth_fetcher.h" #include "google_apis/gaia/gaia_urls.h" @@ -25,6 +24,7 @@ #include "net/url_request/test_url_fetcher_factory.h" #include "net/url_request/url_fetcher_delegate.h" #include "net/url_request/url_request_status.h" +#include "net/url_request/url_request_test_util.h" #include "testing/gmock/include/gmock/gmock.h" #include "testing/gtest/include/gtest/gtest.h" @@ -164,9 +164,18 @@ class GaiaAuthFetcherTest : public testing::Test { GURL merge_session_source_; GURL uberauth_token_source_; GURL oauth_login_gurl_; - TestingProfile profile_; + protected: + net::TestURLRequestContextGetter* GetRequestContext() { + if (!request_context_getter_) { + request_context_getter_ = new net::TestURLRequestContextGetter( + message_loop_.message_loop_proxy()); + } + return request_context_getter_; + } + base::MessageLoop message_loop_; + scoped_refptr<net::TestURLRequestContextGetter> request_context_getter_; }; class MockGaiaConsumer : public GaiaAuthConsumer { @@ -232,8 +241,7 @@ TEST_F(GaiaAuthFetcherTest, LoginNetFailure) { EXPECT_CALL(consumer, OnClientLoginFailure(expected_error)) .Times(1); - GaiaAuthFetcher auth(&consumer, std::string(), - profile_.GetRequestContext()); + GaiaAuthFetcher auth(&consumer, std::string(), GetRequestContext()); MockFetcher mock_fetcher( client_login_source_, status, 0, net::ResponseCookies(), std::string(), @@ -252,8 +260,7 @@ TEST_F(GaiaAuthFetcherTest, TokenNetFailure) { EXPECT_CALL(consumer, OnIssueAuthTokenFailure(_, expected_error)) .Times(1); - GaiaAuthFetcher auth(&consumer, std::string(), - profile_.GetRequestContext()); + GaiaAuthFetcher auth(&consumer, std::string(), GetRequestContext()); MockFetcher mock_fetcher( issue_auth_token_source_, status, 0, cookies_, std::string(), @@ -273,8 +280,7 @@ TEST_F(GaiaAuthFetcherTest, LoginDenied) { EXPECT_CALL(consumer, OnClientLoginFailure(expected_error)) .Times(1); - GaiaAuthFetcher auth(&consumer, std::string(), - profile_.GetRequestContext()); + GaiaAuthFetcher auth(&consumer, std::string(), GetRequestContext()); MockFetcher mock_fetcher( client_login_source_, status, net::HTTP_FORBIDDEN, cookies_, data, @@ -321,8 +327,7 @@ TEST_F(GaiaAuthFetcherTest, OnlineLogin) { EXPECT_CALL(consumer, OnClientLoginSuccess(result)) .Times(1); - GaiaAuthFetcher auth(&consumer, std::string(), - profile_.GetRequestContext()); + GaiaAuthFetcher auth(&consumer, std::string(), GetRequestContext()); net::URLRequestStatus status(net::URLRequestStatus::SUCCESS, 0); MockFetcher mock_fetcher( client_login_source_, status, net::HTTP_OK, cookies_, data, @@ -335,8 +340,7 @@ TEST_F(GaiaAuthFetcherTest, WorkingIssueAuthToken) { EXPECT_CALL(consumer, OnIssueAuthTokenSuccess(_, "token")) .Times(1); - GaiaAuthFetcher auth(&consumer, std::string(), - profile_.GetRequestContext()); + GaiaAuthFetcher auth(&consumer, std::string(), GetRequestContext()); net::URLRequestStatus status(net::URLRequestStatus::SUCCESS, 0); MockFetcher mock_fetcher( issue_auth_token_source_, status, net::HTTP_OK, cookies_, "token", @@ -367,8 +371,7 @@ TEST_F(GaiaAuthFetcherTest, TwoFactorLogin) { EXPECT_CALL(consumer, OnClientLoginFailure(error)) .Times(1); - GaiaAuthFetcher auth(&consumer, std::string(), - profile_.GetRequestContext()); + GaiaAuthFetcher auth(&consumer, std::string(), GetRequestContext()); net::URLRequestStatus status(net::URLRequestStatus::SUCCESS, 0); MockFetcher mock_fetcher( client_login_source_, status, net::HTTP_FORBIDDEN, cookies_, response, @@ -474,8 +477,7 @@ TEST_F(GaiaAuthFetcherTest, FullLogin) { MockURLFetcherFactory<MockFetcher> factory; - GaiaAuthFetcher auth(&consumer, std::string(), - profile_.GetRequestContext()); + GaiaAuthFetcher auth(&consumer, std::string(), GetRequestContext()); auth.StartClientLogin("username", "password", "service", @@ -492,8 +494,7 @@ TEST_F(GaiaAuthFetcherTest, FullLoginFailure) { MockURLFetcherFactory<MockFetcher> factory; factory.set_success(false); - GaiaAuthFetcher auth(&consumer, std::string(), - profile_.GetRequestContext()); + GaiaAuthFetcher auth(&consumer, std::string(), GetRequestContext()); auth.StartClientLogin("username", "password", "service", @@ -509,8 +510,7 @@ TEST_F(GaiaAuthFetcherTest, ClientFetchPending) { net::TestURLFetcherFactory factory; - GaiaAuthFetcher auth(&consumer, std::string(), - profile_.GetRequestContext()); + GaiaAuthFetcher auth(&consumer, std::string(), GetRequestContext()); auth.StartClientLogin("username", "password", "service", @@ -534,8 +534,7 @@ TEST_F(GaiaAuthFetcherTest, FullTokenSuccess) { .Times(1); net::TestURLFetcherFactory factory; - GaiaAuthFetcher auth(&consumer, std::string(), - profile_.GetRequestContext()); + GaiaAuthFetcher auth(&consumer, std::string(), GetRequestContext()); auth.StartIssueAuthToken("sid", "lsid", "service"); EXPECT_TRUE(auth.HasPendingFetch()); @@ -555,8 +554,7 @@ TEST_F(GaiaAuthFetcherTest, FullTokenFailure) { net::TestURLFetcherFactory factory; - GaiaAuthFetcher auth(&consumer, std::string(), - profile_.GetRequestContext()); + GaiaAuthFetcher auth(&consumer, std::string(), GetRequestContext()); auth.StartIssueAuthToken("sid", "lsid", "service"); EXPECT_TRUE(auth.HasPendingFetch()); @@ -578,8 +576,7 @@ TEST_F(GaiaAuthFetcherTest, OAuthLoginTokenSuccess) { GaiaAuthConsumer::ClientOAuthResult("rt1", "at1", 3600))).Times(1); net::TestURLFetcherFactory factory; - GaiaAuthFetcher auth(&consumer, std::string(), - profile_.GetRequestContext()); + GaiaAuthFetcher auth(&consumer, std::string(), GetRequestContext()); auth.StartLsoForOAuthLoginTokenExchange("lso_token"); net::TestURLFetcher* fetcher = factory.GetFetcherByID(0); EXPECT_TRUE(NULL != fetcher); @@ -611,8 +608,7 @@ TEST_F(GaiaAuthFetcherTest, OAuthLoginTokenSuccess) { TEST_F(GaiaAuthFetcherTest, OAuthLoginTokenWithCookies) { MockGaiaConsumer consumer; net::TestURLFetcherFactory factory; - GaiaAuthFetcher auth(&consumer, std::string(), - profile_.GetRequestContext()); + GaiaAuthFetcher auth(&consumer, std::string(), GetRequestContext()); auth.StartCookieForOAuthLoginTokenExchange("0"); net::TestURLFetcher* fetcher = factory.GetFetcherByID(0); EXPECT_TRUE(NULL != fetcher); @@ -625,8 +621,7 @@ TEST_F(GaiaAuthFetcherTest, OAuthLoginTokenClientLoginToOAuth2Failure) { .Times(1); net::TestURLFetcherFactory factory; - GaiaAuthFetcher auth(&consumer, std::string(), - profile_.GetRequestContext()); + GaiaAuthFetcher auth(&consumer, std::string(), GetRequestContext()); auth.StartLsoForOAuthLoginTokenExchange("lso_token"); net::ResponseCookies cookies; @@ -649,8 +644,7 @@ TEST_F(GaiaAuthFetcherTest, OAuthLoginTokenOAuth2TokenPairFailure) { .Times(1); net::TestURLFetcherFactory factory; - GaiaAuthFetcher auth(&consumer, std::string(), - profile_.GetRequestContext()); + GaiaAuthFetcher auth(&consumer, std::string(), GetRequestContext()); auth.StartLsoForOAuthLoginTokenExchange("lso_token"); net::ResponseCookies cookies; @@ -685,8 +679,7 @@ TEST_F(GaiaAuthFetcherTest, MergeSessionSuccess) { net::TestURLFetcherFactory factory; - GaiaAuthFetcher auth(&consumer, std::string(), - profile_.GetRequestContext()); + GaiaAuthFetcher auth(&consumer, std::string(), GetRequestContext()); auth.StartMergeSession("myubertoken"); EXPECT_TRUE(auth.HasPendingFetch()); @@ -706,8 +699,7 @@ TEST_F(GaiaAuthFetcherTest, MergeSessionSuccessRedirect) { net::TestURLFetcherFactory factory; - GaiaAuthFetcher auth(&consumer, std::string(), - profile_.GetRequestContext()); + GaiaAuthFetcher auth(&consumer, std::string(), GetRequestContext()); auth.StartMergeSession("myubertoken"); // Make sure the fetcher created has the expected flags. Set its url() @@ -736,8 +728,7 @@ TEST_F(GaiaAuthFetcherTest, UberAuthTokenSuccess) { net::TestURLFetcherFactory factory; - GaiaAuthFetcher auth(&consumer, std::string(), - profile_.GetRequestContext()); + GaiaAuthFetcher auth(&consumer, std::string(), GetRequestContext()); auth.StartTokenFetchForUberAuthExchange("myAccessToken"); EXPECT_TRUE(auth.HasPendingFetch()); @@ -804,8 +795,7 @@ TEST_F(GaiaAuthFetcherTest, StartOAuthLogin) { EXPECT_CALL(consumer, OnClientLoginSuccess(result)) .Times(1); - GaiaAuthFetcher auth(&consumer, std::string(), - profile_.GetRequestContext()); + GaiaAuthFetcher auth(&consumer, std::string(), GetRequestContext()); net::URLRequestStatus status(net::URLRequestStatus::SUCCESS, 0); MockFetcher mock_fetcher( oauth_login_gurl_, status, net::HTTP_OK, cookies_, data, diff --git a/google_apis/gaia/gaia_oauth_client_unittest.cc b/google_apis/gaia/gaia_oauth_client_unittest.cc index acb366a..921a61a 100644 --- a/google_apis/gaia/gaia_oauth_client_unittest.cc +++ b/google_apis/gaia/gaia_oauth_client_unittest.cc @@ -10,7 +10,6 @@ #include "base/message_loop.h" #include "base/strings/string_number_conversions.h" #include "base/values.h" -#include "chrome/test/base/testing_profile.h" #include "google_apis/gaia/gaia_oauth_client.h" #include "googleurl/src/gurl.h" #include "net/base/net_errors.h" @@ -18,6 +17,7 @@ #include "net/url_request/test_url_fetcher_factory.h" #include "net/url_request/url_fetcher_delegate.h" #include "net/url_request/url_request_status.h" +#include "net/url_request/url_request_test_util.h" #include "testing/gmock/include/gmock/gmock.h" #include "testing/gtest/include/gtest/gtest.h" @@ -163,9 +163,17 @@ class GaiaOAuthClientTest : public testing::Test { client_info_.redirect_uri = "test_redirect_uri"; }; - TestingProfile profile_; protected: + net::TestURLRequestContextGetter* GetRequestContext() { + if (!request_context_getter_) { + request_context_getter_ = new net::TestURLRequestContextGetter( + message_loop_.message_loop_proxy()); + } + return request_context_getter_; + } + base::MessageLoop message_loop_; + scoped_refptr<net::TestURLRequestContextGetter> request_context_getter_; OAuthClientInfo client_info_; }; @@ -211,7 +219,7 @@ TEST_F(GaiaOAuthClientTest, NetworkFailure) { factory.set_response_code(response_code); factory.set_max_failure_count(4); - GaiaOAuthClient auth(profile_.GetRequestContext()); + GaiaOAuthClient auth(GetRequestContext()); auth.GetTokensFromAuthCode(client_info_, "auth_code", 2, &delegate); } @@ -227,7 +235,7 @@ TEST_F(GaiaOAuthClientTest, NetworkFailureRecover) { factory.set_max_failure_count(4); factory.set_results(kDummyGetTokensResult); - GaiaOAuthClient auth(profile_.GetRequestContext()); + GaiaOAuthClient auth(GetRequestContext()); auth.GetTokensFromAuthCode(client_info_, "auth_code", -1, &delegate); } @@ -242,7 +250,7 @@ TEST_F(GaiaOAuthClientTest, OAuthFailure) { factory.set_max_failure_count(-1); factory.set_results(kDummyGetTokensResult); - GaiaOAuthClient auth(profile_.GetRequestContext()); + GaiaOAuthClient auth(GetRequestContext()); auth.GetTokensFromAuthCode(client_info_, "auth_code", -1, &delegate); } @@ -255,7 +263,7 @@ TEST_F(GaiaOAuthClientTest, GetTokensSuccess) { MockOAuthFetcherFactory factory; factory.set_results(kDummyGetTokensResult); - GaiaOAuthClient auth(profile_.GetRequestContext()); + GaiaOAuthClient auth(GetRequestContext()); auth.GetTokensFromAuthCode(client_info_, "auth_code", -1, &delegate); } @@ -268,7 +276,7 @@ TEST_F(GaiaOAuthClientTest, RefreshTokenSuccess) { factory.set_results(kDummyRefreshTokenResult); factory.set_complete_immediately(false); - GaiaOAuthClient auth(profile_.GetRequestContext()); + GaiaOAuthClient auth(GetRequestContext()); auth.RefreshToken(client_info_, "refresh_token", std::vector<std::string>(), -1, &delegate); EXPECT_THAT(factory.get_url_fetcher()->upload_data(), @@ -285,7 +293,7 @@ TEST_F(GaiaOAuthClientTest, RefreshTokenDownscopingSuccess) { factory.set_results(kDummyRefreshTokenResult); factory.set_complete_immediately(false); - GaiaOAuthClient auth(profile_.GetRequestContext()); + GaiaOAuthClient auth(GetRequestContext()); auth.RefreshToken(client_info_, "refresh_token", std::vector<std::string>(1, "scope4test"), -1, &delegate); EXPECT_THAT(factory.get_url_fetcher()->upload_data(), @@ -301,7 +309,7 @@ TEST_F(GaiaOAuthClientTest, GetUserEmail) { MockOAuthFetcherFactory factory; factory.set_results(kDummyUserInfoResult); - GaiaOAuthClient auth(profile_.GetRequestContext()); + GaiaOAuthClient auth(GetRequestContext()); auth.GetUserEmail("access_token", 1, &delegate); } @@ -315,7 +323,7 @@ TEST_F(GaiaOAuthClientTest, GetTokenInfo) { MockOAuthFetcherFactory factory; factory.set_results(kDummyTokenInfoResult); - GaiaOAuthClient auth(profile_.GetRequestContext()); + GaiaOAuthClient auth(GetRequestContext()); auth.GetTokenInfo("access_token", 1, &delegate); std::string issued_to; diff --git a/google_apis/gaia/oauth2_access_token_fetcher_unittest.cc b/google_apis/gaia/oauth2_access_token_fetcher_unittest.cc index 3b2d451..2d4166e 100644 --- a/google_apis/gaia/oauth2_access_token_fetcher_unittest.cc +++ b/google_apis/gaia/oauth2_access_token_fetcher_unittest.cc @@ -8,7 +8,6 @@ #include "base/memory/scoped_ptr.h" #include "base/message_loop.h" -#include "chrome/test/base/testing_profile.h" #include "content/public/test/test_browser_thread.h" #include "google_apis/gaia/gaia_urls.h" #include "google_apis/gaia/google_service_auth_error.h" @@ -22,6 +21,7 @@ #include "net/url_request/url_fetcher_factory.h" #include "net/url_request/url_request.h" #include "net/url_request/url_request_status.h" +#include "net/url_request/url_request_test_util.h" #include "testing/gmock/include/gmock/gmock.h" #include "testing/gtest/include/gtest/gtest.h" @@ -85,10 +85,12 @@ class OAuth2AccessTokenFetcherTest : public testing::Test { public: OAuth2AccessTokenFetcherTest() : ui_thread_(BrowserThread::UI, &message_loop_), - fetcher_(&consumer_, profile_.GetRequestContext()) { + request_context_getter_(new net::TestURLRequestContextGetter( + message_loop_.message_loop_proxy())), + fetcher_(&consumer_, request_context_getter_) { } - virtual ~OAuth2AccessTokenFetcherTest() { } + virtual ~OAuth2AccessTokenFetcherTest() {} virtual TestURLFetcher* SetupGetAccessToken( bool fetch_succeeds, int response_code, const std::string& body) { @@ -114,7 +116,7 @@ class OAuth2AccessTokenFetcherTest : public testing::Test { content::TestBrowserThread ui_thread_; MockUrlFetcherFactory factory_; MockOAuth2AccessTokenConsumer consumer_; - TestingProfile profile_; + scoped_refptr<net::TestURLRequestContextGetter> request_context_getter_; OAuth2AccessTokenFetcher fetcher_; }; diff --git a/google_apis/gaia/oauth2_api_call_flow_unittest.cc b/google_apis/gaia/oauth2_api_call_flow_unittest.cc index bdfbff6..7d8d138 100644 --- a/google_apis/gaia/oauth2_api_call_flow_unittest.cc +++ b/google_apis/gaia/oauth2_api_call_flow_unittest.cc @@ -8,8 +8,8 @@ #include <vector> #include "base/memory/scoped_ptr.h" +#include "base/message_loop/message_loop.h" #include "base/time/time.h" -#include "chrome/test/base/testing_profile.h" #include "google_apis/gaia/gaia_urls.h" #include "google_apis/gaia/google_service_auth_error.h" #include "google_apis/gaia/oauth2_access_token_consumer.h" @@ -23,6 +23,7 @@ #include "net/url_request/url_fetcher_factory.h" #include "net/url_request/url_request.h" #include "net/url_request/url_request_status.h" +#include "net/url_request/url_request_test_util.h" #include "testing/gmock/include/gmock/gmock.h" #include "testing/gtest/include/gtest/gtest.h" @@ -144,13 +145,13 @@ class OAuth2ApiCallFlowTest : public testing::Test { void CreateFlow(const std::string& refresh_token, const std::string& access_token, const std::vector<std::string>& scopes) { + scoped_refptr<net::TestURLRequestContextGetter> request_context_getter = + new net::TestURLRequestContextGetter( + message_loop_.message_loop_proxy()); flow_.reset(new MockApiCallFlow( - profile_.GetRequestContext(), - refresh_token, - access_token, - scopes)); - access_token_fetcher_.reset(new MockAccessTokenFetcher( - flow_.get(), profile_.GetRequestContext())); + request_context_getter, refresh_token, access_token, scopes)); + access_token_fetcher_.reset( + new MockAccessTokenFetcher(flow_.get(), request_context_getter)); } TestURLFetcher* SetupApiCall(bool succeeds, net::HttpStatusCode status) { @@ -168,7 +169,7 @@ class OAuth2ApiCallFlowTest : public testing::Test { MockUrlFetcherFactory factory_; scoped_ptr<MockApiCallFlow> flow_; scoped_ptr<MockAccessTokenFetcher> access_token_fetcher_; - TestingProfile profile_; + base::MessageLoop message_loop_; }; TEST_F(OAuth2ApiCallFlowTest, FirstApiCallSucceeds) { |