| Index: net/url_request/url_request_throttler_unittest.cc
|
| diff --git a/net/url_request/url_request_throttler_unittest.cc b/net/url_request/url_request_throttler_unittest.cc
|
| index 7d4e739edc6134e8f98d5f35702e38e0d5b7754c..86c3f2a40244385b4598562c6ea08a4ec56bf8e2 100644
|
| --- a/net/url_request/url_request_throttler_unittest.cc
|
| +++ b/net/url_request/url_request_throttler_unittest.cc
|
| @@ -19,23 +19,53 @@ using base::TimeTicks;
|
| namespace {
|
| class MockURLRequestThrottlerManager;
|
|
|
| +class MockBackoffEntry : public net::BackoffEntry {
|
| +public:
|
| + MockBackoffEntry(const net::BackoffEntry::Policy* policy)
|
| + : net::BackoffEntry(policy), fake_now_(TimeTicks()) {
|
| + }
|
| +
|
| + TimeTicks GetTimeNow() const {
|
| + return fake_now_;
|
| + }
|
| +
|
| + void SetFakeNow(TimeTicks now) {
|
| + fake_now_ = now;
|
| + }
|
| +
|
| +private:
|
| + TimeTicks fake_now_;
|
| +};
|
| +
|
| class MockURLRequestThrottlerEntry : public net::URLRequestThrottlerEntry {
|
| public :
|
| - MockURLRequestThrottlerEntry() {}
|
| + MockURLRequestThrottlerEntry() : mock_backoff_entry_(&backoff_policy_) {}
|
| MockURLRequestThrottlerEntry(
|
| const TimeTicks& exponential_backoff_release_time,
|
| const TimeTicks& sliding_window_release_time,
|
| const TimeTicks& fake_now)
|
| - : fake_time_now_(fake_now) {
|
| + : fake_time_now_(fake_now),
|
| + mock_backoff_entry_(&backoff_policy_) {
|
| + mock_backoff_entry_.SetFakeNow(fake_now);
|
| set_exponential_backoff_release_time(exponential_backoff_release_time);
|
| set_sliding_window_release_time(sliding_window_release_time);
|
| }
|
| virtual ~MockURLRequestThrottlerEntry() {}
|
|
|
| + const net::BackoffEntry* GetBackoffEntry() const {
|
| + return &mock_backoff_entry_;
|
| + }
|
| +
|
| + net::BackoffEntry* GetBackoffEntry() {
|
| + return &mock_backoff_entry_;
|
| + }
|
| +
|
| void ResetToBlank(const TimeTicks& time_now) {
|
| fake_time_now_ = time_now;
|
| - set_exponential_backoff_release_time(time_now);
|
| - set_failure_count(0);
|
| + mock_backoff_entry_.SetFakeNow(time_now);
|
| +
|
| + GetBackoffEntry()->SetCustomReleaseTime(time_now);
|
| + GetBackoffEntry()->InformOfRequest(true); // Sets failure count to 0.
|
| set_sliding_window_release_time(time_now);
|
| }
|
|
|
| @@ -44,8 +74,7 @@ class MockURLRequestThrottlerEntry : public net::URLRequestThrottlerEntry {
|
|
|
| void set_exponential_backoff_release_time(
|
| const base::TimeTicks& release_time) {
|
| - net::URLRequestThrottlerEntry::set_exponential_backoff_release_time(
|
| - release_time);
|
| + GetBackoffEntry()->SetCustomReleaseTime(release_time);
|
| }
|
|
|
| base::TimeTicks sliding_window_release_time() const {
|
| @@ -59,6 +88,7 @@ class MockURLRequestThrottlerEntry : public net::URLRequestThrottlerEntry {
|
| }
|
|
|
| TimeTicks fake_time_now_;
|
| + MockBackoffEntry mock_backoff_entry_;
|
| };
|
|
|
| class MockURLRequestThrottlerHeaderAdapter
|
| @@ -226,7 +256,8 @@ TEST_F(URLRequestThrottlerEntryTest, IsEntryReallyOutdated) {
|
| TimeAndBool(now_, false, __LINE__),
|
| TimeAndBool(now_ - kFiveMs, false, __LINE__),
|
| TimeAndBool(now_ + kFiveMs, false, __LINE__),
|
| - TimeAndBool(now_ - lifetime, false, __LINE__),
|
| + TimeAndBool(now_ - (lifetime - kFiveMs), false, __LINE__),
|
| + TimeAndBool(now_ - lifetime, true, __LINE__),
|
| TimeAndBool(now_ - (lifetime + kFiveMs), true, __LINE__)};
|
|
|
| for (unsigned int i = 0; i < arraysize(test_values); ++i) {
|
| @@ -294,26 +325,25 @@ TEST(URLRequestThrottlerManager, IsUrlStandardised) {
|
| MockURLRequestThrottlerManager manager;
|
| GurlAndString test_values[] = {
|
| GurlAndString(GURL("http://www.example.com"),
|
| - std::string("GOOGYhttp://www.example.com/MONSTA"),
|
| + std::string("http://www.example.com/"),
|
| __LINE__),
|
| GurlAndString(GURL("http://www.Example.com"),
|
| - std::string("GOOGYhttp://www.example.com/MONSTA"),
|
| + std::string("http://www.example.com/"),
|
| __LINE__),
|
| GurlAndString(GURL("http://www.ex4mple.com/Pr4c71c41"),
|
| - std::string("GOOGYhttp://www.ex4mple.com/pr4c71c41MONSTA"),
|
| + std::string("http://www.ex4mple.com/pr4c71c41"),
|
| + __LINE__),
|
| + GurlAndString(GURL("http://www.example.com/0/token/false"),
|
| + std::string("http://www.example.com/0/token/false"),
|
| __LINE__),
|
| - GurlAndString(
|
| - GURL("http://www.example.com/0/token/false"),
|
| - std::string("GOOGYhttp://www.example.com/0/token/falseMONSTA"),
|
| - __LINE__),
|
| GurlAndString(GURL("http://www.example.com/index.php?code=javascript"),
|
| - std::string("GOOGYhttp://www.example.com/index.phpMONSTA"),
|
| + std::string("http://www.example.com/index.php"),
|
| __LINE__),
|
| GurlAndString(GURL("http://www.example.com/index.php?code=1#superEntry"),
|
| - std::string("GOOGYhttp://www.example.com/index.phpMONSTA"),
|
| + std::string("http://www.example.com/index.php"),
|
| __LINE__),
|
| GurlAndString(GURL("http://www.example.com:1234/"),
|
| - std::string("GOOGYhttp://www.example.com:1234/MONSTA"),
|
| + std::string("http://www.example.com:1234/"),
|
| __LINE__)};
|
|
|
| for (unsigned int i = 0; i < arraysize(test_values); ++i) {
|
| @@ -351,65 +381,3 @@ TEST(URLRequestThrottlerManager, IsHostBeingRegistered) {
|
|
|
| EXPECT_EQ(3, manager.GetNumberOfEntries());
|
| }
|
| -
|
| -class DummyResponseHeaders : public net::URLRequestThrottlerHeaderInterface {
|
| - public:
|
| - DummyResponseHeaders(int response_code) : response_code_(response_code) {}
|
| -
|
| - std::string GetNormalizedValue(const std::string& key) const {
|
| - return "";
|
| - }
|
| -
|
| - // Returns the HTTP response code associated with the request.
|
| - int GetResponseCode() const {
|
| - return response_code_;
|
| - }
|
| -
|
| - private:
|
| - int response_code_;
|
| -};
|
| -
|
| -TEST(URLRequestThrottlerManager, StressTest) {
|
| - MockURLRequestThrottlerManager manager;
|
| -
|
| - for (int i = 0; i < 10000; ++i) {
|
| - // Make some entries duplicates or triplicates.
|
| - int entry_number = i + 2;
|
| - if (i % 17 == 0) {
|
| - entry_number = i - 1;
|
| - } else if ((i - 1) % 17 == 0) {
|
| - entry_number = i - 2;
|
| - } else if (i % 13 == 0) {
|
| - entry_number = i - 1;
|
| - }
|
| -
|
| - scoped_refptr<net::URLRequestThrottlerEntryInterface> entry =
|
| - manager.RegisterRequestUrl(GURL(StringPrintf(
|
| - "http://bingourl.com/%d", entry_number)));
|
| - entry->IsDuringExponentialBackoff();
|
| - entry->GetExponentialBackoffReleaseTime();
|
| -
|
| - DummyResponseHeaders headers(i % 7 == 0 ? 500 : 200);
|
| - entry->UpdateWithResponse(&headers);
|
| - entry->SetEntryLifetimeMsForTest(1);
|
| -
|
| - entry->IsDuringExponentialBackoff();
|
| - entry->GetExponentialBackoffReleaseTime();
|
| - entry->ReserveSendingTimeForNextRequest(base::TimeTicks::Now());
|
| -
|
| - if (i % 11 == 0) {
|
| - manager.DoGarbageCollectEntries();
|
| - }
|
| - }
|
| -}
|
| -
|
| -// TODO(joi): Remove the debug-only condition after M11 branch point.
|
| -#if defined(GTEST_HAS_DEATH_TEST) && !defined(NDEBUG)
|
| -TEST(URLRequestThrottlerManager, NullHandlingTest) {
|
| - MockURLRequestThrottlerManager manager;
|
| - manager.OverrideEntryForTests(GURL("http://www.foo.com/"), NULL);
|
| - ASSERT_DEATH({
|
| - manager.DoGarbageCollectEntries();
|
| - }, "");
|
| -}
|
| -#endif // defined(GTEST_HAS_DEATH_TEST) && !defined(NDEBUG)
|
|
|