OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 <memory> | 5 #include <memory> |
6 | 6 |
7 #include "base/metrics/histogram_samples.h" | 7 #include "base/metrics/histogram_samples.h" |
8 #include "base/pickle.h" | 8 #include "base/pickle.h" |
9 #include "base/stl_util.h" | 9 #include "base/stl_util.h" |
10 #include "base/strings/string_number_conversions.h" | 10 #include "base/strings/string_number_conversions.h" |
11 #include "base/test/histogram_tester.h" | 11 #include "base/test/histogram_tester.h" |
12 #include "base/time/time.h" | 12 #include "base/time/time.h" |
13 #include "net/base/load_flags.h" | 13 #include "net/base/load_flags.h" |
14 #include "net/base/request_priority.h" | 14 #include "net/base/request_priority.h" |
15 #include "net/base/test_completion_callback.h" | 15 #include "net/base/test_completion_callback.h" |
| 16 #include "net/traffic_annotation/network_traffic_annotation_test_helper.h" |
16 #include "net/url_request/url_request.h" | 17 #include "net/url_request/url_request.h" |
17 #include "net/url_request/url_request_context.h" | 18 #include "net/url_request/url_request_context.h" |
18 #include "net/url_request/url_request_test_util.h" | 19 #include "net/url_request/url_request_test_util.h" |
19 #include "net/url_request/url_request_throttler_manager.h" | 20 #include "net/url_request/url_request_throttler_manager.h" |
20 #include "net/url_request/url_request_throttler_test_support.h" | 21 #include "net/url_request/url_request_throttler_test_support.h" |
21 #include "testing/gtest/include/gtest/gtest.h" | 22 #include "testing/gtest/include/gtest/gtest.h" |
22 | 23 |
23 using base::TimeDelta; | 24 using base::TimeDelta; |
24 using base::TimeTicks; | 25 using base::TimeTicks; |
25 | 26 |
(...skipping 127 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
153 GURL url; | 154 GURL url; |
154 std::string result; | 155 std::string result; |
155 int line; | 156 int line; |
156 }; | 157 }; |
157 | 158 |
158 } // namespace | 159 } // namespace |
159 | 160 |
160 class URLRequestThrottlerEntryTest : public testing::Test { | 161 class URLRequestThrottlerEntryTest : public testing::Test { |
161 protected: | 162 protected: |
162 URLRequestThrottlerEntryTest() | 163 URLRequestThrottlerEntryTest() |
163 : request_(context_.CreateRequest(GURL(), DEFAULT_PRIORITY, NULL)) {} | 164 : request_(context_.CreateRequest(GURL(), |
| 165 DEFAULT_PRIORITY, |
| 166 NULL, |
| 167 TRAFFIC_ANNOTATION_FOR_TESTS)) {} |
164 | 168 |
165 void SetUp() override; | 169 void SetUp() override; |
166 | 170 |
167 TimeTicks now_; | 171 TimeTicks now_; |
168 MockURLRequestThrottlerManager manager_; // Dummy object, not used. | 172 MockURLRequestThrottlerManager manager_; // Dummy object, not used. |
169 scoped_refptr<MockURLRequestThrottlerEntry> entry_; | 173 scoped_refptr<MockURLRequestThrottlerEntry> entry_; |
170 | 174 |
171 TestURLRequestContext context_; | 175 TestURLRequestContext context_; |
172 std::unique_ptr<URLRequest> request_; | 176 std::unique_ptr<URLRequest> request_; |
173 }; | 177 }; |
(...skipping 127 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
301 | 305 |
302 for (int i = 0; i < (max_send + 1) / 2; ++i) | 306 for (int i = 0; i < (max_send + 1) / 2; ++i) |
303 EXPECT_EQ(0, entry_->ReserveSendingTimeForNextRequest(TimeTicks())); | 307 EXPECT_EQ(0, entry_->ReserveSendingTimeForNextRequest(TimeTicks())); |
304 | 308 |
305 EXPECT_EQ(time_4, entry_->sliding_window_release_time()); | 309 EXPECT_EQ(time_4, entry_->sliding_window_release_time()); |
306 } | 310 } |
307 | 311 |
308 class URLRequestThrottlerManagerTest : public testing::Test { | 312 class URLRequestThrottlerManagerTest : public testing::Test { |
309 protected: | 313 protected: |
310 URLRequestThrottlerManagerTest() | 314 URLRequestThrottlerManagerTest() |
311 : request_(context_.CreateRequest(GURL(), DEFAULT_PRIORITY, NULL)) {} | 315 : request_(context_.CreateRequest(GURL(), |
| 316 DEFAULT_PRIORITY, |
| 317 NULL, |
| 318 TRAFFIC_ANNOTATION_FOR_TESTS)) {} |
312 | 319 |
313 void SetUp() override { request_->SetLoadFlags(0); } | 320 void SetUp() override { request_->SetLoadFlags(0); } |
314 | 321 |
315 void ExpectEntryAllowsAllOnErrorIfOptedOut( | 322 void ExpectEntryAllowsAllOnErrorIfOptedOut( |
316 URLRequestThrottlerEntryInterface* entry, | 323 URLRequestThrottlerEntryInterface* entry, |
317 bool opted_out, | 324 bool opted_out, |
318 const URLRequest& request) { | 325 const URLRequest& request) { |
319 EXPECT_FALSE(entry->ShouldRejectRequest(request)); | 326 EXPECT_FALSE(entry->ShouldRejectRequest(request)); |
320 for (int i = 0; i < 10; ++i) { | 327 for (int i = 0; i < 10; ++i) { |
321 entry->UpdateWithResponse(503); | 328 entry->UpdateWithResponse(503); |
(...skipping 127 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
449 FAIL(); | 456 FAIL(); |
450 } | 457 } |
451 | 458 |
452 scoped_refptr<URLRequestThrottlerEntryInterface> entry_after = | 459 scoped_refptr<URLRequestThrottlerEntryInterface> entry_after = |
453 manager.RegisterRequestUrl(GURL("http://www.example.com/")); | 460 manager.RegisterRequestUrl(GURL("http://www.example.com/")); |
454 EXPECT_FALSE(entry_after->ShouldRejectRequest(*request_)); | 461 EXPECT_FALSE(entry_after->ShouldRejectRequest(*request_)); |
455 } | 462 } |
456 } | 463 } |
457 | 464 |
458 } // namespace net | 465 } // namespace net |
OLD | NEW |