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

Side by Side Diff: google_apis/gaia/oauth2_access_token_fetcher_impl_unittest.cc

Issue 2890293005: Network traffic annotation stored in url_request. (Closed)
Patch Set: Created 3 years, 7 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
OLDNEW
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 // A complete set of unit tests for OAuth2AccessTokenFetcherImpl. 5 // A complete set of unit tests for OAuth2AccessTokenFetcherImpl.
6 6
7 #include "google_apis/gaia/oauth2_access_token_fetcher_impl.h" 7 #include "google_apis/gaia/oauth2_access_token_fetcher_impl.h"
8 8
9 #include <memory> 9 #include <memory>
10 #include <string> 10 #include <string>
11 11
12 #include "base/run_loop.h" 12 #include "base/run_loop.h"
13 #include "base/test/scoped_task_environment.h" 13 #include "base/test/scoped_task_environment.h"
14 #include "base/threading/thread_task_runner_handle.h" 14 #include "base/threading/thread_task_runner_handle.h"
15 #include "build/build_config.h" 15 #include "build/build_config.h"
16 #include "google_apis/gaia/gaia_urls.h" 16 #include "google_apis/gaia/gaia_urls.h"
17 #include "google_apis/gaia/google_service_auth_error.h" 17 #include "google_apis/gaia/google_service_auth_error.h"
18 #include "google_apis/gaia/oauth2_access_token_consumer.h" 18 #include "google_apis/gaia/oauth2_access_token_consumer.h"
19 #include "net/base/net_errors.h" 19 #include "net/base/net_errors.h"
20 #include "net/http/http_status_code.h" 20 #include "net/http/http_status_code.h"
21 #include "net/traffic_annotation/network_traffic_annotation_test_helper.h"
21 #include "net/url_request/test_url_fetcher_factory.h" 22 #include "net/url_request/test_url_fetcher_factory.h"
22 #include "net/url_request/url_fetcher.h" 23 #include "net/url_request/url_fetcher.h"
23 #include "net/url_request/url_fetcher_delegate.h" 24 #include "net/url_request/url_fetcher_delegate.h"
24 #include "net/url_request/url_fetcher_factory.h" 25 #include "net/url_request/url_fetcher_factory.h"
25 #include "net/url_request/url_request.h" 26 #include "net/url_request/url_request.h"
26 #include "net/url_request/url_request_status.h" 27 #include "net/url_request/url_request_status.h"
27 #include "net/url_request/url_request_test_util.h" 28 #include "net/url_request/url_request_test_util.h"
28 #include "testing/gmock/include/gmock/gmock.h" 29 #include "testing/gmock/include/gmock/gmock.h"
29 #include "testing/gtest/include/gtest/gtest.h" 30 #include "testing/gtest/include/gtest/gtest.h"
30 #include "url/gurl.h" 31 #include "url/gurl.h"
(...skipping 27 matching lines...) Expand all
58 "{" 59 "{"
59 " \"error\": \"invalid_grant\"" 60 " \"error\": \"invalid_grant\""
60 "}"; 61 "}";
61 62
62 class MockUrlFetcherFactory : public ScopedURLFetcherFactory, 63 class MockUrlFetcherFactory : public ScopedURLFetcherFactory,
63 public URLFetcherFactory { 64 public URLFetcherFactory {
64 public: 65 public:
65 MockUrlFetcherFactory() : ScopedURLFetcherFactory(this) {} 66 MockUrlFetcherFactory() : ScopedURLFetcherFactory(this) {}
66 virtual ~MockUrlFetcherFactory() {} 67 virtual ~MockUrlFetcherFactory() {}
67 68
68 MOCK_METHOD4(CreateURLFetcherMock, 69 MOCK_METHOD5(
69 URLFetcher*(int id, 70 CreateURLFetcherMock,
70 const GURL& url, 71 URLFetcher*(int id,
71 URLFetcher::RequestType request_type, 72 const GURL& url,
72 URLFetcherDelegate* d)); 73 URLFetcher::RequestType request_type,
74 URLFetcherDelegate* d,
75 net::NetworkTrafficAnnotationTag traffic_annotation));
73 76
74 std::unique_ptr<URLFetcher> CreateURLFetcher( 77 std::unique_ptr<URLFetcher> CreateURLFetcher(
75 int id, 78 int id,
76 const GURL& url, 79 const GURL& url,
77 URLFetcher::RequestType request_type, 80 URLFetcher::RequestType request_type,
78 URLFetcherDelegate* d) override { 81 URLFetcherDelegate* d,
82 net::NetworkTrafficAnnotationTag traffic_annotation) override {
79 return std::unique_ptr<URLFetcher>( 83 return std::unique_ptr<URLFetcher>(
80 CreateURLFetcherMock(id, url, request_type, d)); 84 CreateURLFetcherMock(id, url, request_type, d, traffic_annotation));
81 } 85 }
82 }; 86 };
83 87
84 class MockOAuth2AccessTokenConsumer : public OAuth2AccessTokenConsumer { 88 class MockOAuth2AccessTokenConsumer : public OAuth2AccessTokenConsumer {
85 public: 89 public:
86 MockOAuth2AccessTokenConsumer() {} 90 MockOAuth2AccessTokenConsumer() {}
87 ~MockOAuth2AccessTokenConsumer() {} 91 ~MockOAuth2AccessTokenConsumer() {}
88 92
89 MOCK_METHOD2(OnGetTokenSuccess, 93 MOCK_METHOD2(OnGetTokenSuccess,
90 void(const std::string& access_token, 94 void(const std::string& access_token,
(...skipping 21 matching lines...) Expand all
112 TestURLFetcher* url_fetcher = new TestURLFetcher(0, url, &fetcher_); 116 TestURLFetcher* url_fetcher = new TestURLFetcher(0, url, &fetcher_);
113 net::Error error = fetch_succeeds ? net::OK : net::ERR_FAILED; 117 net::Error error = fetch_succeeds ? net::OK : net::ERR_FAILED;
114 url_fetcher->set_status(URLRequestStatus::FromError(error)); 118 url_fetcher->set_status(URLRequestStatus::FromError(error));
115 119
116 if (response_code != 0) 120 if (response_code != 0)
117 url_fetcher->set_response_code(response_code); 121 url_fetcher->set_response_code(response_code);
118 122
119 if (!body.empty()) 123 if (!body.empty())
120 url_fetcher->SetResponseString(body); 124 url_fetcher->SetResponseString(body);
121 125
122 EXPECT_CALL(factory_, CreateURLFetcherMock(_, url, _, _)) 126 EXPECT_CALL(factory_, CreateURLFetcherMock(_, url, _, _, _))
123 .WillOnce(Return(url_fetcher)); 127 .WillOnce(Return(url_fetcher));
124 return url_fetcher; 128 return url_fetcher;
125 } 129 }
126 130
127 protected: 131 protected:
128 base::test::ScopedTaskEnvironment scoped_task_environment_; 132 base::test::ScopedTaskEnvironment scoped_task_environment_;
129 MockUrlFetcherFactory factory_; 133 MockUrlFetcherFactory factory_;
130 MockOAuth2AccessTokenConsumer consumer_; 134 MockOAuth2AccessTokenConsumer consumer_;
131 scoped_refptr<net::TestURLRequestContextGetter> request_context_getter_; 135 scoped_refptr<net::TestURLRequestContextGetter> request_context_getter_;
132 OAuth2AccessTokenFetcherImpl fetcher_; 136 OAuth2AccessTokenFetcherImpl fetcher_;
(...skipping 135 matching lines...) Expand 10 before | Expand all | Expand 10 after
268 TestURLFetcher url_fetcher(0, GURL("http://www.google.com"), NULL); 272 TestURLFetcher url_fetcher(0, GURL("http://www.google.com"), NULL);
269 url_fetcher.SetResponseString(kValidFailureTokenResponse); 273 url_fetcher.SetResponseString(kValidFailureTokenResponse);
270 274
271 std::string error; 275 std::string error;
272 EXPECT_TRUE( 276 EXPECT_TRUE(
273 OAuth2AccessTokenFetcherImpl::ParseGetAccessTokenFailureResponse( 277 OAuth2AccessTokenFetcherImpl::ParseGetAccessTokenFailureResponse(
274 &url_fetcher, &error)); 278 &url_fetcher, &error));
275 EXPECT_EQ("invalid_grant", error); 279 EXPECT_EQ("invalid_grant", error);
276 } 280 }
277 } 281 }
OLDNEW
« no previous file with comments | « google_apis/gaia/mock_url_fetcher_factory.h ('k') | google_apis/gaia/oauth2_api_call_flow_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698