| 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 3104a6048dadb50f540206e32e5386f82b591304..fcfe6844f6e83e88c32d6f79ad5ccf700d9bbb21 100644
|
| --- a/net/url_request/url_request_throttler_unittest.cc
|
| +++ b/net/url_request/url_request_throttler_unittest.cc
|
| @@ -18,7 +18,6 @@
|
| #include "net/url_request/url_request.h"
|
| #include "net/url_request/url_request_context.h"
|
| #include "net/url_request/url_request_test_util.h"
|
| -#include "net/url_request/url_request_throttler_header_interface.h"
|
| #include "net/url_request/url_request_throttler_test_support.h"
|
| #include "testing/gtest/include/gtest/gtest.h"
|
|
|
| @@ -235,30 +234,26 @@ TEST_F(URLRequestThrottlerEntryTest, InterfaceNotDuringExponentialBackoff) {
|
| }
|
|
|
| TEST_F(URLRequestThrottlerEntryTest, InterfaceUpdateFailure) {
|
| - MockURLRequestThrottlerHeaderAdapter failure_response(503);
|
| - entry_->UpdateWithResponse(std::string(), &failure_response);
|
| + entry_->UpdateWithResponse(503);
|
| EXPECT_GT(entry_->GetExponentialBackoffReleaseTime(),
|
| entry_->ImplGetTimeNow())
|
| << "A failure should increase the release_time";
|
| }
|
|
|
| TEST_F(URLRequestThrottlerEntryTest, InterfaceUpdateSuccess) {
|
| - MockURLRequestThrottlerHeaderAdapter success_response(200);
|
| - entry_->UpdateWithResponse(std::string(), &success_response);
|
| + entry_->UpdateWithResponse(200);
|
| EXPECT_EQ(entry_->GetExponentialBackoffReleaseTime(),
|
| entry_->ImplGetTimeNow())
|
| << "A success should not add any delay";
|
| }
|
|
|
| TEST_F(URLRequestThrottlerEntryTest, InterfaceUpdateSuccessThenFailure) {
|
| - MockURLRequestThrottlerHeaderAdapter failure_response(503);
|
| - MockURLRequestThrottlerHeaderAdapter success_response(200);
|
| - entry_->UpdateWithResponse(std::string(), &success_response);
|
| - entry_->UpdateWithResponse(std::string(), &failure_response);
|
| + entry_->UpdateWithResponse(200);
|
| + entry_->UpdateWithResponse(503);
|
| EXPECT_GT(entry_->GetExponentialBackoffReleaseTime(),
|
| entry_->ImplGetTimeNow())
|
| << "This scenario should add delay";
|
| - entry_->UpdateWithResponse(std::string(), &success_response);
|
| + entry_->UpdateWithResponse(200);
|
| }
|
|
|
| TEST_F(URLRequestThrottlerEntryTest, IsEntryReallyOutdated) {
|
| @@ -283,8 +278,7 @@ TEST_F(URLRequestThrottlerEntryTest, IsEntryReallyOutdated) {
|
|
|
| TEST_F(URLRequestThrottlerEntryTest, MaxAllowedBackoff) {
|
| for (int i = 0; i < 30; ++i) {
|
| - MockURLRequestThrottlerHeaderAdapter response_adapter(503);
|
| - entry_->UpdateWithResponse(std::string(), &response_adapter);
|
| + entry_->UpdateWithResponse(503);
|
| }
|
|
|
| TimeDelta delay = entry_->GetExponentialBackoffReleaseTime() - now_;
|
| @@ -293,9 +287,8 @@ TEST_F(URLRequestThrottlerEntryTest, MaxAllowedBackoff) {
|
| }
|
|
|
| TEST_F(URLRequestThrottlerEntryTest, MalformedContent) {
|
| - MockURLRequestThrottlerHeaderAdapter response_adapter(503);
|
| for (int i = 0; i < 5; ++i)
|
| - entry_->UpdateWithResponse(std::string(), &response_adapter);
|
| + entry_->UpdateWithResponse(503);
|
|
|
| TimeTicks release_after_failures = entry_->GetExponentialBackoffReleaseTime();
|
|
|
| @@ -305,8 +298,7 @@ TEST_F(URLRequestThrottlerEntryTest, MalformedContent) {
|
| // is what happens in practice (if a body is received, then a non-500
|
| // response must also have been received).
|
| entry_->ReceivedContentWasMalformed(200);
|
| - MockURLRequestThrottlerHeaderAdapter success_adapter(200);
|
| - entry_->UpdateWithResponse(std::string(), &success_adapter);
|
| + entry_->UpdateWithResponse(200);
|
| EXPECT_GT(entry_->GetExponentialBackoffReleaseTime(), release_after_failures);
|
| }
|
|
|
| @@ -361,10 +353,8 @@ class URLRequestThrottlerManagerTest : public testing::Test {
|
| const URLRequest& request) {
|
| EXPECT_FALSE(entry->ShouldRejectRequest(request,
|
| context_.network_delegate()));
|
| - MockURLRequestThrottlerHeaderAdapter failure_adapter(503);
|
| for (int i = 0; i < 10; ++i) {
|
| - // Host doesn't really matter in this scenario so we skip it.
|
| - entry->UpdateWithResponse(std::string(), &failure_adapter);
|
| + entry->UpdateWithResponse(503);
|
| }
|
| EXPECT_NE(opted_out, entry->ShouldRejectRequest(
|
| request, context_.network_delegate()));
|
| @@ -452,40 +442,25 @@ TEST_F(URLRequestThrottlerManagerTest, IsHostBeingRegistered) {
|
| EXPECT_EQ(3, manager.GetNumberOfEntries());
|
| }
|
|
|
| -TEST_F(URLRequestThrottlerManagerTest, OptOutHeader) {
|
| +TEST_F(URLRequestThrottlerManagerTest, LocalHostOptedOut) {
|
| MockURLRequestThrottlerManager manager;
|
| - scoped_refptr<URLRequestThrottlerEntryInterface> entry =
|
| - manager.RegisterRequestUrl(GURL("http://www.google.com/yodude"));
|
| -
|
| - // Fake a response with the opt-out header.
|
| - MockURLRequestThrottlerHeaderAdapter response_adapter(
|
| - std::string(),
|
| - MockURLRequestThrottlerEntry::kExponentialThrottlingDisableValue,
|
| - 200);
|
| - entry->UpdateWithResponse("www.google.com", &response_adapter);
|
| -
|
| - // Ensure that the same entry on error always allows everything.
|
| - ExpectEntryAllowsAllOnErrorIfOptedOut(entry.get(), true, *request_);
|
| -
|
| - // Ensure that a freshly created entry (for a different URL on an
|
| - // already opted-out host) also gets "always allow" behavior.
|
| - scoped_refptr<URLRequestThrottlerEntryInterface> other_entry =
|
| - manager.RegisterRequestUrl(GURL("http://www.google.com/bingobob"));
|
| - ExpectEntryAllowsAllOnErrorIfOptedOut(other_entry.get(), true, *request_);
|
| -
|
| - // Fake a response with the opt-out header incorrectly specified.
|
| - scoped_refptr<URLRequestThrottlerEntryInterface> no_opt_out_entry =
|
| - manager.RegisterRequestUrl(GURL("http://www.nike.com/justdoit"));
|
| - MockURLRequestThrottlerHeaderAdapter wrong_adapter(
|
| - std::string(), "yesplease", 200);
|
| - no_opt_out_entry->UpdateWithResponse("www.nike.com", &wrong_adapter);
|
| - ExpectEntryAllowsAllOnErrorIfOptedOut(
|
| - no_opt_out_entry.get(), false, *request_);
|
| -
|
| // A localhost entry should always be opted out.
|
| scoped_refptr<URLRequestThrottlerEntryInterface> localhost_entry =
|
| manager.RegisterRequestUrl(GURL("http://localhost/hello"));
|
| - ExpectEntryAllowsAllOnErrorIfOptedOut(localhost_entry.get(), true, *request_);
|
| + EXPECT_FALSE(localhost_entry->ShouldRejectRequest(
|
| + (*request_), context_.network_delegate()));
|
| + for (int i = 0; i < 10; ++i) {
|
| + localhost_entry->UpdateWithResponse(503);
|
| + }
|
| + EXPECT_FALSE(localhost_entry->ShouldRejectRequest(
|
| + (*request_), context_.network_delegate()));
|
| +
|
| + // We're not mocking out GetTimeNow() in this scenario
|
| + // so add a 100 ms buffer to avoid flakiness (that should always
|
| + // give enough time to get from the TimeTicks::Now() call here
|
| + // to the TimeTicks::Now() call in the entry class).
|
| + EXPECT_GT(TimeTicks::Now() + TimeDelta::FromMilliseconds(100),
|
| + localhost_entry->GetExponentialBackoffReleaseTime());
|
| }
|
|
|
| TEST_F(URLRequestThrottlerManagerTest, ClearOnNetworkChange) {
|
| @@ -493,10 +468,8 @@ TEST_F(URLRequestThrottlerManagerTest, ClearOnNetworkChange) {
|
| MockURLRequestThrottlerManager manager;
|
| scoped_refptr<URLRequestThrottlerEntryInterface> entry_before =
|
| manager.RegisterRequestUrl(GURL("http://www.example.com/"));
|
| - MockURLRequestThrottlerHeaderAdapter failure_adapter(503);
|
| for (int j = 0; j < 10; ++j) {
|
| - // Host doesn't really matter in this scenario so we skip it.
|
| - entry_before->UpdateWithResponse(std::string(), &failure_adapter);
|
| + entry_before->UpdateWithResponse(503);
|
| }
|
| EXPECT_TRUE(entry_before->ShouldRejectRequest(*request_,
|
| context_.network_delegate()));
|
|
|