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

Side by Side Diff: content/common/throttling_url_loader_unittest.cc

Issue 2893233002: Network traffic annotation added to URLLoaderImpl. (Closed)
Patch Set: Comment addressed, Merged. Created 3 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
« no previous file with comments | « content/common/throttling_url_loader.cc ('k') | content/common/typemaps.gni » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2017 The Chromium Authors. All rights reserved. 1 // Copyright 2017 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 "content/common/throttling_url_loader.h" 5 #include "content/common/throttling_url_loader.h"
6 #include "base/logging.h" 6 #include "base/logging.h"
7 #include "base/macros.h" 7 #include "base/macros.h"
8 #include "base/message_loop/message_loop.h" 8 #include "base/message_loop/message_loop.h"
9 #include "base/run_loop.h" 9 #include "base/run_loop.h"
10 #include "content/common/url_loader.mojom.h" 10 #include "content/common/url_loader.mojom.h"
11 #include "content/common/url_loader_factory.mojom.h" 11 #include "content/common/url_loader_factory.mojom.h"
12 #include "content/public/common/url_loader_throttle.h" 12 #include "content/public/common/url_loader_throttle.h"
13 #include "net/traffic_annotation/network_traffic_annotation_test_helper.h"
13 #include "testing/gtest/include/gtest/gtest.h" 14 #include "testing/gtest/include/gtest/gtest.h"
14 15
15 namespace content { 16 namespace content {
16 namespace { 17 namespace {
17 18
18 class TestURLLoaderFactory : public mojom::URLLoaderFactory { 19 class TestURLLoaderFactory : public mojom::URLLoaderFactory {
19 public: 20 public:
20 TestURLLoaderFactory() : binding_(this) { 21 TestURLLoaderFactory() : binding_(this) {
21 binding_.Bind(mojo::MakeRequest(&factory_ptr_)); 22 binding_.Bind(mojo::MakeRequest(&factory_ptr_));
22 } 23 }
(...skipping 20 matching lines...) Expand all
43 client_ptr_->OnComplete(data); 44 client_ptr_->OnComplete(data);
44 } 45 }
45 46
46 private: 47 private:
47 // mojom::URLLoaderFactory implementation. 48 // mojom::URLLoaderFactory implementation.
48 void CreateLoaderAndStart(mojom::URLLoaderAssociatedRequest request, 49 void CreateLoaderAndStart(mojom::URLLoaderAssociatedRequest request,
49 int32_t routing_id, 50 int32_t routing_id,
50 int32_t request_id, 51 int32_t request_id,
51 uint32_t options, 52 uint32_t options,
52 const ResourceRequest& url_request, 53 const ResourceRequest& url_request,
53 mojom::URLLoaderClientPtr client) override { 54 mojom::URLLoaderClientPtr client,
55 const net::MutableNetworkTrafficAnnotationTag&
56 traffic_annotation) override {
54 create_loader_and_start_called_++; 57 create_loader_and_start_called_++;
55 58
56 client_ptr_ = std::move(client); 59 client_ptr_ = std::move(client);
57 } 60 }
58 61
59 void SyncLoad(int32_t routing_id, 62 void SyncLoad(int32_t routing_id,
60 int32_t request_id, 63 int32_t request_id,
61 const ResourceRequest& request, 64 const ResourceRequest& request,
62 SyncLoadCallback callback) override { 65 SyncLoadCallback callback) override {
63 NOTREACHED(); 66 NOTREACHED();
(...skipping 138 matching lines...) Expand 10 before | Expand all | Expand 10 after
202 throttle_ = throttle.get(); 205 throttle_ = throttle.get();
203 206
204 throttles_.push_back(std::move(throttle)); 207 throttles_.push_back(std::move(throttle));
205 } 208 }
206 209
207 void CreateLoaderAndStart() { 210 void CreateLoaderAndStart() {
208 auto request = base::MakeUnique<ResourceRequest>(); 211 auto request = base::MakeUnique<ResourceRequest>();
209 request->url = GURL("http://example.org"); 212 request->url = GURL("http://example.org");
210 loader_ = ThrottlingURLLoader::CreateLoaderAndStart( 213 loader_ = ThrottlingURLLoader::CreateLoaderAndStart(
211 factory_.factory_ptr().get(), std::move(throttles_), 0, 0, 0, 214 factory_.factory_ptr().get(), std::move(throttles_), 0, 0, 0,
212 std::move(request), &client_); 215 std::move(request), &client_,
216 net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS));
213 factory_.factory_ptr().FlushForTesting(); 217 factory_.factory_ptr().FlushForTesting();
214 } 218 }
215 219
216 // Be the first member so it is destroyed last. 220 // Be the first member so it is destroyed last.
217 base::MessageLoop message_loop_; 221 base::MessageLoop message_loop_;
218 222
219 std::unique_ptr<ThrottlingURLLoader> loader_; 223 std::unique_ptr<ThrottlingURLLoader> loader_;
220 std::vector<std::unique_ptr<URLLoaderThrottle>> throttles_; 224 std::vector<std::unique_ptr<URLLoaderThrottle>> throttles_;
221 225
222 TestURLLoaderFactory factory_; 226 TestURLLoaderFactory factory_;
(...skipping 328 matching lines...) Expand 10 before | Expand all | Expand 10 after
551 EXPECT_EQ(0u, throttle_->will_redirect_request_called()); 555 EXPECT_EQ(0u, throttle_->will_redirect_request_called());
552 EXPECT_EQ(1u, throttle_->will_process_response_called()); 556 EXPECT_EQ(1u, throttle_->will_process_response_called());
553 557
554 EXPECT_EQ(0u, client_.on_received_response_called()); 558 EXPECT_EQ(0u, client_.on_received_response_called());
555 EXPECT_EQ(0u, client_.on_received_redirect_called()); 559 EXPECT_EQ(0u, client_.on_received_redirect_called());
556 EXPECT_EQ(1u, client_.on_complete_called()); 560 EXPECT_EQ(1u, client_.on_complete_called());
557 } 561 }
558 562
559 } // namespace 563 } // namespace
560 } // namespace content 564 } // namespace content
OLDNEW
« no previous file with comments | « content/common/throttling_url_loader.cc ('k') | content/common/typemaps.gni » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698