| 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/pickle.h" | 9 #include "base/pickle.h" |
| 10 #include "base/stringprintf.h" | 10 #include "base/stringprintf.h" |
| (...skipping 149 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 160 } | 160 } |
| 161 GURL url; | 161 GURL url; |
| 162 std::string result; | 162 std::string result; |
| 163 int line; | 163 int line; |
| 164 }; | 164 }; |
| 165 | 165 |
| 166 } // namespace | 166 } // namespace |
| 167 | 167 |
| 168 class URLRequestThrottlerEntryTest : public testing::Test { | 168 class URLRequestThrottlerEntryTest : public testing::Test { |
| 169 protected: | 169 protected: |
| 170 URLRequestThrottlerEntryTest() : request_(GURL(), NULL) { | 170 URLRequestThrottlerEntryTest() : request_(GURL(), NULL, &context_) { |
| 171 } | 171 } |
| 172 | 172 |
| 173 virtual void SetUp(); | 173 virtual void SetUp(); |
| 174 | 174 |
| 175 // After calling this function, histogram snapshots in |samples_| contain | 175 // After calling this function, histogram snapshots in |samples_| contain |
| 176 // only the delta caused by the test case currently running. | 176 // only the delta caused by the test case currently running. |
| 177 void CalculateHistogramDeltas(); | 177 void CalculateHistogramDeltas(); |
| 178 | 178 |
| 179 TimeTicks now_; | 179 TimeTicks now_; |
| 180 MockURLRequestThrottlerManager manager_; // Dummy object, not used. | 180 MockURLRequestThrottlerManager manager_; // Dummy object, not used. |
| 181 scoped_refptr<MockURLRequestThrottlerEntry> entry_; | 181 scoped_refptr<MockURLRequestThrottlerEntry> entry_; |
| 182 | 182 |
| 183 std::map<std::string, Histogram::SampleSet> original_samples_; | 183 std::map<std::string, Histogram::SampleSet> original_samples_; |
| 184 std::map<std::string, Histogram::SampleSet> samples_; | 184 std::map<std::string, Histogram::SampleSet> samples_; |
| 185 | 185 |
| 186 // Order matters: context_ must be declared before request_. |
| 187 TestURLRequestContext context_; |
| 186 TestURLRequest request_; | 188 TestURLRequest request_; |
| 187 }; | 189 }; |
| 188 | 190 |
| 189 // List of all histograms we care about in these unit tests. | 191 // List of all histograms we care about in these unit tests. |
| 190 const char* kHistogramNames[] = { | 192 const char* kHistogramNames[] = { |
| 191 "Throttling.FailureCountAtSuccess", | 193 "Throttling.FailureCountAtSuccess", |
| 192 "Throttling.PerceivedDowntime", | 194 "Throttling.PerceivedDowntime", |
| 193 "Throttling.RequestThrottled", | 195 "Throttling.RequestThrottled", |
| 194 "Throttling.SiteOptedOut", | 196 "Throttling.SiteOptedOut", |
| 195 }; | 197 }; |
| (...skipping 176 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 372 ASSERT_FALSE(MockURLRequestThrottlerEntry::ExplicitUserRequest(0)); | 374 ASSERT_FALSE(MockURLRequestThrottlerEntry::ExplicitUserRequest(0)); |
| 373 ASSERT_TRUE(MockURLRequestThrottlerEntry::ExplicitUserRequest( | 375 ASSERT_TRUE(MockURLRequestThrottlerEntry::ExplicitUserRequest( |
| 374 LOAD_MAYBE_USER_GESTURE)); | 376 LOAD_MAYBE_USER_GESTURE)); |
| 375 ASSERT_FALSE(MockURLRequestThrottlerEntry::ExplicitUserRequest( | 377 ASSERT_FALSE(MockURLRequestThrottlerEntry::ExplicitUserRequest( |
| 376 ~LOAD_MAYBE_USER_GESTURE)); | 378 ~LOAD_MAYBE_USER_GESTURE)); |
| 377 } | 379 } |
| 378 | 380 |
| 379 class URLRequestThrottlerManagerTest : public testing::Test { | 381 class URLRequestThrottlerManagerTest : public testing::Test { |
| 380 protected: | 382 protected: |
| 381 URLRequestThrottlerManagerTest() | 383 URLRequestThrottlerManagerTest() |
| 382 : request_(GURL(), NULL) { | 384 : request_(GURL(), NULL, &context_) { |
| 383 } | 385 } |
| 384 | 386 |
| 385 virtual void SetUp() { | 387 virtual void SetUp() { |
| 386 request_.set_load_flags(0); | 388 request_.set_load_flags(0); |
| 387 } | 389 } |
| 388 | 390 |
| 391 // context_ must be declared before request_. |
| 392 TestURLRequestContext context_; |
| 389 TestURLRequest request_; | 393 TestURLRequest request_; |
| 390 }; | 394 }; |
| 391 | 395 |
| 392 TEST_F(URLRequestThrottlerManagerTest, IsUrlStandardised) { | 396 TEST_F(URLRequestThrottlerManagerTest, IsUrlStandardised) { |
| 393 MockURLRequestThrottlerManager manager; | 397 MockURLRequestThrottlerManager manager; |
| 394 GurlAndString test_values[] = { | 398 GurlAndString test_values[] = { |
| 395 GurlAndString(GURL("http://www.example.com"), | 399 GurlAndString(GURL("http://www.example.com"), |
| 396 std::string("http://www.example.com/"), | 400 std::string("http://www.example.com/"), |
| 397 __LINE__), | 401 __LINE__), |
| 398 GurlAndString(GURL("http://www.Example.com"), | 402 GurlAndString(GURL("http://www.Example.com"), |
| (...skipping 142 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 541 FAIL(); | 545 FAIL(); |
| 542 } | 546 } |
| 543 | 547 |
| 544 scoped_refptr<net::URLRequestThrottlerEntryInterface> entry_after = | 548 scoped_refptr<net::URLRequestThrottlerEntryInterface> entry_after = |
| 545 manager.RegisterRequestUrl(GURL("http://www.example.com/")); | 549 manager.RegisterRequestUrl(GURL("http://www.example.com/")); |
| 546 EXPECT_FALSE(entry_after->ShouldRejectRequest(request_)); | 550 EXPECT_FALSE(entry_after->ShouldRejectRequest(request_)); |
| 547 } | 551 } |
| 548 } | 552 } |
| 549 | 553 |
| 550 } // namespace net | 554 } // namespace net |
| OLD | NEW |