Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(607)

Unified Diff: net/url_request/url_request_throttler_unittest.cc

Issue 10440119: Introduce a delegate to avoid hardcoding "chrome-extension" in net/. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Pure merge to LKGR Created 8 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
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 0d018cd78b8e030a1406ce81ebc75b72abb2865c..dbb669195d66de34b3bfbacbc5180b77babba990 100644
--- a/net/url_request/url_request_throttler_unittest.cc
+++ b/net/url_request/url_request_throttler_unittest.cc
@@ -13,6 +13,7 @@
#include "net/base/load_flags.h"
#include "net/base/test_completion_callback.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"
@@ -107,7 +108,10 @@ class MockURLRequestThrottlerEntry : public URLRequestThrottlerEntry {
class MockURLRequestThrottlerManager : public URLRequestThrottlerManager {
public:
- MockURLRequestThrottlerManager() : create_entry_index_(0) {}
+ MockURLRequestThrottlerManager()
+ : URLRequestThrottlerManager(&delegate_),
+ create_entry_index_(0) {
+ }
// Method to process the URL using URLRequestThrottlerManager protected
// method.
@@ -136,6 +140,7 @@ class MockURLRequestThrottlerManager : public URLRequestThrottlerManager {
private:
int create_entry_index_;
+ TestURLRequestThrottlerManagerDelegate delegate_;
};
struct TimeAndBool {
@@ -234,10 +239,10 @@ std::ostream& operator<<(std::ostream& out, const base::TimeTicks& time) {
TEST_F(URLRequestThrottlerEntryTest, InterfaceDuringExponentialBackoff) {
entry_->set_exponential_backoff_release_time(
entry_->fake_time_now_ + TimeDelta::FromMilliseconds(1));
- EXPECT_TRUE(entry_->ShouldRejectRequest(0));
+ EXPECT_TRUE(entry_->ShouldRejectRequest(NULL, 0));
// Also end-to-end test the load flags exceptions.
- EXPECT_FALSE(entry_->ShouldRejectRequest(LOAD_MAYBE_USER_GESTURE));
+ EXPECT_FALSE(entry_->ShouldRejectRequest(NULL, LOAD_MAYBE_USER_GESTURE));
CalculateHistogramDeltas();
ASSERT_EQ(1, samples_["Throttling.RequestThrottled"].counts(0));
@@ -246,10 +251,10 @@ TEST_F(URLRequestThrottlerEntryTest, InterfaceDuringExponentialBackoff) {
TEST_F(URLRequestThrottlerEntryTest, InterfaceNotDuringExponentialBackoff) {
entry_->set_exponential_backoff_release_time(entry_->fake_time_now_);
- EXPECT_FALSE(entry_->ShouldRejectRequest(0));
+ EXPECT_FALSE(entry_->ShouldRejectRequest(NULL, 0));
entry_->set_exponential_backoff_release_time(
entry_->fake_time_now_ - TimeDelta::FromMilliseconds(1));
- EXPECT_FALSE(entry_->ShouldRejectRequest(0));
+ EXPECT_FALSE(entry_->ShouldRejectRequest(NULL, 0));
CalculateHistogramDeltas();
ASSERT_EQ(2, samples_["Throttling.RequestThrottled"].counts(0));
@@ -278,10 +283,6 @@ TEST_F(URLRequestThrottlerEntryTest, InterfaceUpdateSuccessThenFailure) {
EXPECT_GT(entry_->GetExponentialBackoffReleaseTime(), entry_->fake_time_now_)
<< "This scenario should add delay";
entry_->UpdateWithResponse("", &success_response);
-
- CalculateHistogramDeltas();
- ASSERT_EQ(1, samples_["Throttling.FailureCountAtSuccess"].counts(1));
- ASSERT_EQ(1, samples_["Throttling.PerceivedDowntime"].TotalCount());
}
TEST_F(URLRequestThrottlerEntryTest, IsEntryReallyOutdated) {
@@ -438,13 +439,13 @@ TEST(URLRequestThrottlerManager, IsHostBeingRegistered) {
void ExpectEntryAllowsAllOnErrorIfOptedOut(
net::URLRequestThrottlerEntryInterface* entry,
bool opted_out) {
- EXPECT_FALSE(entry->ShouldRejectRequest(0));
+ EXPECT_FALSE(entry->ShouldRejectRequest(NULL, 0));
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("", &failure_adapter);
}
- EXPECT_NE(opted_out, entry->ShouldRejectRequest(0));
+ EXPECT_NE(opted_out, entry->ShouldRejectRequest(NULL, 0));
if (opted_out) {
// We're not mocking out GetTimeNow() in this scenario
@@ -504,7 +505,7 @@ TEST(URLRequestThrottlerManager, ClearOnNetworkChange) {
// Host doesn't really matter in this scenario so we skip it.
entry_before->UpdateWithResponse("", &failure_adapter);
}
- EXPECT_TRUE(entry_before->ShouldRejectRequest(0));
+ EXPECT_TRUE(entry_before->ShouldRejectRequest(NULL, 0));
switch (i) {
case 0:
@@ -524,7 +525,7 @@ TEST(URLRequestThrottlerManager, ClearOnNetworkChange) {
scoped_refptr<net::URLRequestThrottlerEntryInterface> entry_after =
manager.RegisterRequestUrl(GURL("http://www.example.com/"));
- EXPECT_FALSE(entry_after->ShouldRejectRequest(0));
+ EXPECT_FALSE(entry_after->ShouldRejectRequest(NULL, 0));
}
}

Powered by Google App Engine
This is Rietveld 408576698