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

Side by Side Diff: components/ntp_snippets/remote/remote_suggestions_fetcher_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 2016 The Chromium Authors. All rights reserved. 1 // Copyright 2016 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/ntp_snippets/remote/remote_suggestions_fetcher.h" 5 #include "components/ntp_snippets/remote/remote_suggestions_fetcher.h"
6 6
7 #include <deque> 7 #include <deque>
8 #include <map> 8 #include <map>
9 #include <utility> 9 #include <utility>
10 #include <vector> 10 #include <vector>
(...skipping 12 matching lines...) Expand all
23 #include "components/ntp_snippets/remote/remote_suggestion.h" 23 #include "components/ntp_snippets/remote/remote_suggestion.h"
24 #include "components/ntp_snippets/remote/request_params.h" 24 #include "components/ntp_snippets/remote/request_params.h"
25 #include "components/ntp_snippets/remote/test_utils.h" 25 #include "components/ntp_snippets/remote/test_utils.h"
26 #include "components/ntp_snippets/user_classifier.h" 26 #include "components/ntp_snippets/user_classifier.h"
27 #include "components/prefs/testing_pref_service.h" 27 #include "components/prefs/testing_pref_service.h"
28 #include "components/signin/core/browser/fake_profile_oauth2_token_service.h" 28 #include "components/signin/core/browser/fake_profile_oauth2_token_service.h"
29 #include "components/signin/core/browser/fake_signin_manager.h" 29 #include "components/signin/core/browser/fake_signin_manager.h"
30 #include "components/variations/entropy_provider.h" 30 #include "components/variations/entropy_provider.h"
31 #include "components/variations/variations_params_manager.h" 31 #include "components/variations/variations_params_manager.h"
32 #include "google_apis/gaia/fake_oauth2_token_service_delegate.h" 32 #include "google_apis/gaia/fake_oauth2_token_service_delegate.h"
33 #include "net/traffic_annotation/network_traffic_annotation_test_helper.h"
33 #include "net/url_request/test_url_fetcher_factory.h" 34 #include "net/url_request/test_url_fetcher_factory.h"
34 #include "net/url_request/url_request_test_util.h" 35 #include "net/url_request/url_request_test_util.h"
35 #include "testing/gmock/include/gmock/gmock.h" 36 #include "testing/gmock/include/gmock/gmock.h"
36 #include "testing/gtest/include/gtest/gtest.h" 37 #include "testing/gtest/include/gtest/gtest.h"
37 38
38 namespace ntp_snippets { 39 namespace ntp_snippets {
39 40
40 namespace { 41 namespace {
41 42
42 using testing::_; 43 using testing::_;
(...skipping 132 matching lines...) Expand 10 before | Expand all | Expand 10 after
175 ~DelegateCallingTestURLFetcherFactory() override { 176 ~DelegateCallingTestURLFetcherFactory() override {
176 while (!fetchers_.empty()) { 177 while (!fetchers_.empty()) {
177 DropAndCallDelegate(fetchers_.front()); 178 DropAndCallDelegate(fetchers_.front());
178 } 179 }
179 } 180 }
180 181
181 std::unique_ptr<net::URLFetcher> CreateURLFetcher( 182 std::unique_ptr<net::URLFetcher> CreateURLFetcher(
182 int id, 183 int id,
183 const GURL& url, 184 const GURL& url,
184 net::URLFetcher::RequestType request_type, 185 net::URLFetcher::RequestType request_type,
185 net::URLFetcherDelegate* d) override { 186 net::URLFetcherDelegate* d,
187 net::NetworkTrafficAnnotationTag traffic_annotation) override {
186 if (GetFetcherByID(id)) { 188 if (GetFetcherByID(id)) {
187 LOG(WARNING) << "The ID " << id << " was already assigned to a fetcher." 189 LOG(WARNING) << "The ID " << id << " was already assigned to a fetcher."
188 << "Its delegate will thereforde be called right now."; 190 << "Its delegate will thereforde be called right now.";
189 DropAndCallDelegate(id); 191 DropAndCallDelegate(id);
190 } 192 }
191 fetchers_.push_back(id); 193 fetchers_.push_back(id);
192 return TestURLFetcherFactory::CreateURLFetcher(id, url, request_type, d); 194 return TestURLFetcherFactory::CreateURLFetcher(id, url, request_type, d,
195 traffic_annotation);
193 } 196 }
194 197
195 // Returns the raw pointer of the last created URL fetcher. 198 // Returns the raw pointer of the last created URL fetcher.
196 // If it was destroyed or no fetcher was created, it will return a nulltpr. 199 // If it was destroyed or no fetcher was created, it will return a nulltpr.
197 net::TestURLFetcher* GetLastCreatedFetcher() { 200 net::TestURLFetcher* GetLastCreatedFetcher() {
198 if (fetchers_.empty()) { 201 if (fetchers_.empty()) {
199 return nullptr; 202 return nullptr;
200 } 203 }
201 return GetFetcherByID(fetchers_.front()); 204 return GetFetcherByID(fetchers_.front());
202 } 205 }
(...skipping 25 matching lines...) Expand all
228 std::deque<int> fetchers_; // std::queue doesn't support std::find. 231 std::deque<int> fetchers_; // std::queue doesn't support std::find.
229 }; 232 };
230 233
231 // Factory for FakeURLFetcher objects that always generate errors. 234 // Factory for FakeURLFetcher objects that always generate errors.
232 class FailingFakeURLFetcherFactory : public net::URLFetcherFactory { 235 class FailingFakeURLFetcherFactory : public net::URLFetcherFactory {
233 public: 236 public:
234 std::unique_ptr<net::URLFetcher> CreateURLFetcher( 237 std::unique_ptr<net::URLFetcher> CreateURLFetcher(
235 int id, 238 int id,
236 const GURL& url, 239 const GURL& url,
237 net::URLFetcher::RequestType request_type, 240 net::URLFetcher::RequestType request_type,
238 net::URLFetcherDelegate* d) override { 241 net::URLFetcherDelegate* d,
242 net::NetworkTrafficAnnotationTag traffic_annotation) override {
239 return base::MakeUnique<net::FakeURLFetcher>( 243 return base::MakeUnique<net::FakeURLFetcher>(
240 url, d, /*response_data=*/std::string(), net::HTTP_NOT_FOUND, 244 url, d, /*response_data=*/std::string(), net::HTTP_NOT_FOUND,
241 net::URLRequestStatus::FAILED); 245 net::URLRequestStatus::FAILED);
242 } 246 }
243 }; 247 };
244 248
245 void ParseJson(const std::string& json, 249 void ParseJson(const std::string& json,
246 const SuccessCallback& success_callback, 250 const SuccessCallback& success_callback,
247 const ErrorCallback& error_callback) { 251 const ErrorCallback& error_callback) {
248 base::JSONReader json_reader; 252 base::JSONReader json_reader;
(...skipping 742 matching lines...) Expand 10 before | Expand all | Expand 10 after
991 fetched_categories) { 995 fetched_categories) {
992 if (fetched_categories) { 996 if (fetched_categories) {
993 // Matchers above aren't any more precise than this, so this is sufficient 997 // Matchers above aren't any more precise than this, so this is sufficient
994 // for test-failure diagnostics. 998 // for test-failure diagnostics.
995 return os << "list with " << fetched_categories->size() << " elements"; 999 return os << "list with " << fetched_categories->size() << " elements";
996 } 1000 }
997 return os << "null"; 1001 return os << "null";
998 } 1002 }
999 1003
1000 } // namespace ntp_snippets 1004 } // namespace ntp_snippets
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698