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 TestURLRequestContext context_; |
186 TestURLRequest request_; | 187 TestURLRequest request_; |
187 }; | 188 }; |
188 | 189 |
189 // List of all histograms we care about in these unit tests. | 190 // List of all histograms we care about in these unit tests. |
190 const char* kHistogramNames[] = { | 191 const char* kHistogramNames[] = { |
191 "Throttling.FailureCountAtSuccess", | 192 "Throttling.FailureCountAtSuccess", |
192 "Throttling.PerceivedDowntime", | 193 "Throttling.PerceivedDowntime", |
193 "Throttling.RequestThrottled", | 194 "Throttling.RequestThrottled", |
194 "Throttling.SiteOptedOut", | 195 "Throttling.SiteOptedOut", |
195 }; | 196 }; |
(...skipping 176 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
372 ASSERT_FALSE(MockURLRequestThrottlerEntry::ExplicitUserRequest(0)); | 373 ASSERT_FALSE(MockURLRequestThrottlerEntry::ExplicitUserRequest(0)); |
373 ASSERT_TRUE(MockURLRequestThrottlerEntry::ExplicitUserRequest( | 374 ASSERT_TRUE(MockURLRequestThrottlerEntry::ExplicitUserRequest( |
374 LOAD_MAYBE_USER_GESTURE)); | 375 LOAD_MAYBE_USER_GESTURE)); |
375 ASSERT_FALSE(MockURLRequestThrottlerEntry::ExplicitUserRequest( | 376 ASSERT_FALSE(MockURLRequestThrottlerEntry::ExplicitUserRequest( |
376 ~LOAD_MAYBE_USER_GESTURE)); | 377 ~LOAD_MAYBE_USER_GESTURE)); |
377 } | 378 } |
378 | 379 |
379 class URLRequestThrottlerManagerTest : public testing::Test { | 380 class URLRequestThrottlerManagerTest : public testing::Test { |
380 protected: | 381 protected: |
381 URLRequestThrottlerManagerTest() | 382 URLRequestThrottlerManagerTest() |
382 : request_(GURL(), NULL) { | 383 : request_(GURL(), NULL, &context_) { |
383 } | 384 } |
384 | 385 |
385 virtual void SetUp() { | 386 virtual void SetUp() { |
386 request_.set_load_flags(0); | 387 request_.set_load_flags(0); |
387 } | 388 } |
388 | 389 |
| 390 // context_ must be declared before request_. |
| 391 TestURLRequestContext context_; |
389 TestURLRequest request_; | 392 TestURLRequest request_; |
390 }; | 393 }; |
391 | 394 |
392 TEST_F(URLRequestThrottlerManagerTest, IsUrlStandardised) { | 395 TEST_F(URLRequestThrottlerManagerTest, IsUrlStandardised) { |
393 MockURLRequestThrottlerManager manager; | 396 MockURLRequestThrottlerManager manager; |
394 GurlAndString test_values[] = { | 397 GurlAndString test_values[] = { |
395 GurlAndString(GURL("http://www.example.com"), | 398 GurlAndString(GURL("http://www.example.com"), |
396 std::string("http://www.example.com/"), | 399 std::string("http://www.example.com/"), |
397 __LINE__), | 400 __LINE__), |
398 GurlAndString(GURL("http://www.Example.com"), | 401 GurlAndString(GURL("http://www.Example.com"), |
(...skipping 142 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
541 FAIL(); | 544 FAIL(); |
542 } | 545 } |
543 | 546 |
544 scoped_refptr<net::URLRequestThrottlerEntryInterface> entry_after = | 547 scoped_refptr<net::URLRequestThrottlerEntryInterface> entry_after = |
545 manager.RegisterRequestUrl(GURL("http://www.example.com/")); | 548 manager.RegisterRequestUrl(GURL("http://www.example.com/")); |
546 EXPECT_FALSE(entry_after->ShouldRejectRequest(request_)); | 549 EXPECT_FALSE(entry_after->ShouldRejectRequest(request_)); |
547 } | 550 } |
548 } | 551 } |
549 | 552 |
550 } // namespace net | 553 } // namespace net |
OLD | NEW |