| 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 "net/url_request/url_request_throttler_manager.h" | 5 #include "net/url_request/url_request_throttler_manager.h" |
| 6 | 6 |
| 7 #include "base/memory/scoped_ptr.h" | 7 #include "base/memory/scoped_ptr.h" |
| 8 #include "base/metrics/histogram.h" | 8 #include "base/metrics/histogram.h" |
| 9 #include "base/metrics/histogram_samples.h" | 9 #include "base/metrics/histogram_samples.h" |
| 10 #include "base/metrics/statistics_recorder.h" | 10 #include "base/metrics/statistics_recorder.h" |
| 11 #include "base/pickle.h" | 11 #include "base/pickle.h" |
| 12 #include "base/stl_util.h" | 12 #include "base/stl_util.h" |
| 13 #include "base/strings/string_number_conversions.h" | 13 #include "base/strings/string_number_conversions.h" |
| 14 #include "base/strings/stringprintf.h" | 14 #include "base/strings/stringprintf.h" |
| 15 #include "base/time/time.h" | 15 #include "base/time/time.h" |
| 16 #include "net/base/load_flags.h" | 16 #include "net/base/load_flags.h" |
| 17 #include "net/base/request_priority.h" |
| 17 #include "net/base/test_completion_callback.h" | 18 #include "net/base/test_completion_callback.h" |
| 18 #include "net/url_request/url_request_context.h" | 19 #include "net/url_request/url_request_context.h" |
| 19 #include "net/url_request/url_request_test_util.h" | 20 #include "net/url_request/url_request_test_util.h" |
| 20 #include "net/url_request/url_request_throttler_header_interface.h" | 21 #include "net/url_request/url_request_throttler_header_interface.h" |
| 21 #include "net/url_request/url_request_throttler_test_support.h" | 22 #include "net/url_request/url_request_throttler_test_support.h" |
| 22 #include "testing/gtest/include/gtest/gtest.h" | 23 #include "testing/gtest/include/gtest/gtest.h" |
| 23 | 24 |
| 24 using base::TimeDelta; | 25 using base::TimeDelta; |
| 25 using base::TimeTicks; | 26 using base::TimeTicks; |
| 26 | 27 |
| (...skipping 138 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 165 } | 166 } |
| 166 GURL url; | 167 GURL url; |
| 167 std::string result; | 168 std::string result; |
| 168 int line; | 169 int line; |
| 169 }; | 170 }; |
| 170 | 171 |
| 171 } // namespace | 172 } // namespace |
| 172 | 173 |
| 173 class URLRequestThrottlerEntryTest : public testing::Test { | 174 class URLRequestThrottlerEntryTest : public testing::Test { |
| 174 protected: | 175 protected: |
| 175 URLRequestThrottlerEntryTest() : request_(GURL(), NULL, &context_, NULL) { | 176 URLRequestThrottlerEntryTest() |
| 176 } | 177 : request_(GURL(), DEFAULT_PRIORITY, NULL, &context_) {} |
| 177 | 178 |
| 178 virtual void SetUp(); | 179 virtual void SetUp(); |
| 179 virtual void TearDown(); | 180 virtual void TearDown(); |
| 180 | 181 |
| 181 // After calling this function, histogram snapshots in |samples_| contain | 182 // After calling this function, histogram snapshots in |samples_| contain |
| 182 // only the delta caused by the test case currently running. | 183 // only the delta caused by the test case currently running. |
| 183 void CalculateHistogramDeltas(); | 184 void CalculateHistogramDeltas(); |
| 184 | 185 |
| 185 TimeTicks now_; | 186 TimeTicks now_; |
| 186 MockURLRequestThrottlerManager manager_; // Dummy object, not used. | 187 MockURLRequestThrottlerManager manager_; // Dummy object, not used. |
| (...skipping 197 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 384 ASSERT_FALSE(MockURLRequestThrottlerEntry::ExplicitUserRequest(0)); | 385 ASSERT_FALSE(MockURLRequestThrottlerEntry::ExplicitUserRequest(0)); |
| 385 ASSERT_TRUE(MockURLRequestThrottlerEntry::ExplicitUserRequest( | 386 ASSERT_TRUE(MockURLRequestThrottlerEntry::ExplicitUserRequest( |
| 386 LOAD_MAYBE_USER_GESTURE)); | 387 LOAD_MAYBE_USER_GESTURE)); |
| 387 ASSERT_FALSE(MockURLRequestThrottlerEntry::ExplicitUserRequest( | 388 ASSERT_FALSE(MockURLRequestThrottlerEntry::ExplicitUserRequest( |
| 388 ~LOAD_MAYBE_USER_GESTURE)); | 389 ~LOAD_MAYBE_USER_GESTURE)); |
| 389 } | 390 } |
| 390 | 391 |
| 391 class URLRequestThrottlerManagerTest : public testing::Test { | 392 class URLRequestThrottlerManagerTest : public testing::Test { |
| 392 protected: | 393 protected: |
| 393 URLRequestThrottlerManagerTest() | 394 URLRequestThrottlerManagerTest() |
| 394 : request_(GURL(), NULL, &context_, NULL) { | 395 : request_(GURL(), DEFAULT_PRIORITY, NULL, &context_) {} |
| 395 } | |
| 396 | 396 |
| 397 virtual void SetUp() { | 397 virtual void SetUp() { |
| 398 request_.set_load_flags(0); | 398 request_.set_load_flags(0); |
| 399 } | 399 } |
| 400 | 400 |
| 401 // context_ must be declared before request_. | 401 // context_ must be declared before request_. |
| 402 TestURLRequestContext context_; | 402 TestURLRequestContext context_; |
| 403 TestURLRequest request_; | 403 TestURLRequest request_; |
| 404 }; | 404 }; |
| 405 | 405 |
| (...skipping 151 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 557 FAIL(); | 557 FAIL(); |
| 558 } | 558 } |
| 559 | 559 |
| 560 scoped_refptr<net::URLRequestThrottlerEntryInterface> entry_after = | 560 scoped_refptr<net::URLRequestThrottlerEntryInterface> entry_after = |
| 561 manager.RegisterRequestUrl(GURL("http://www.example.com/")); | 561 manager.RegisterRequestUrl(GURL("http://www.example.com/")); |
| 562 EXPECT_FALSE(entry_after->ShouldRejectRequest(request_)); | 562 EXPECT_FALSE(entry_after->ShouldRejectRequest(request_)); |
| 563 } | 563 } |
| 564 } | 564 } |
| 565 | 565 |
| 566 } // namespace net | 566 } // namespace net |
| OLD | NEW |