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

Unified Diff: net/url_request/url_request_throttler_unittest.cc

Issue 7582004: Add load flag indicating a request is probably the result of a user gesture. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Merge to lkgr. Created 9 years, 4 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
« no previous file with comments | « net/url_request/url_request_throttler_simulation_unittest.cc ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 8e9734f3cd037498d99ff3415f1b993892e32ec6..4c8f49276de7cac52e30d39c17f5e3fbb484c22e 100644
--- a/net/url_request/url_request_throttler_unittest.cc
+++ b/net/url_request/url_request_throttler_unittest.cc
@@ -10,6 +10,7 @@
#include "base/stringprintf.h"
#include "base/string_number_conversions.h"
#include "base/time.h"
+#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_throttler_header_interface.h"
@@ -67,6 +68,10 @@ class MockURLRequestThrottlerEntry : public URLRequestThrottlerEntry {
return &mock_backoff_entry_;
}
+ static bool ExplicitUserRequest(int load_flags) {
+ return URLRequestThrottlerEntry::ExplicitUserRequest(load_flags);
+ }
+
void ResetToBlank(const TimeTicks& time_now) {
fake_time_now_ = time_now;
mock_backoff_entry_.set_fake_now(time_now);
@@ -229,19 +234,22 @@ 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_->IsDuringExponentialBackoff());
+ EXPECT_TRUE(entry_->ShouldRejectRequest(0));
+
+ // Also end-to-end test the load flags exceptions.
+ EXPECT_FALSE(entry_->ShouldRejectRequest(LOAD_MAYBE_USER_GESTURE));
CalculateHistogramDeltas();
- ASSERT_EQ(0, samples_["Throttling.RequestThrottled"].counts(0));
+ ASSERT_EQ(1, samples_["Throttling.RequestThrottled"].counts(0));
ASSERT_EQ(1, samples_["Throttling.RequestThrottled"].counts(1));
}
TEST_F(URLRequestThrottlerEntryTest, InterfaceNotDuringExponentialBackoff) {
entry_->set_exponential_backoff_release_time(entry_->fake_time_now_);
- EXPECT_FALSE(entry_->IsDuringExponentialBackoff());
+ EXPECT_FALSE(entry_->ShouldRejectRequest(0));
entry_->set_exponential_backoff_release_time(
entry_->fake_time_now_ - TimeDelta::FromMilliseconds(1));
- EXPECT_FALSE(entry_->IsDuringExponentialBackoff());
+ EXPECT_FALSE(entry_->ShouldRejectRequest(0));
CalculateHistogramDeltas();
ASSERT_EQ(2, samples_["Throttling.RequestThrottled"].counts(0));
@@ -377,6 +385,14 @@ TEST_F(URLRequestThrottlerEntryTest, SlidingWindow) {
EXPECT_EQ(time_4, entry_->sliding_window_release_time());
}
+TEST_F(URLRequestThrottlerEntryTest, ExplicitUserRequest) {
+ ASSERT_FALSE(MockURLRequestThrottlerEntry::ExplicitUserRequest(0));
+ ASSERT_TRUE(MockURLRequestThrottlerEntry::ExplicitUserRequest(
+ LOAD_MAYBE_USER_GESTURE));
+ ASSERT_FALSE(MockURLRequestThrottlerEntry::ExplicitUserRequest(
+ ~LOAD_MAYBE_USER_GESTURE));
+}
+
TEST(URLRequestThrottlerManager, IsUrlStandardised) {
MockURLRequestThrottlerManager manager;
GurlAndString test_values[] = {
@@ -444,13 +460,13 @@ TEST(URLRequestThrottlerManager, IsHostBeingRegistered) {
void ExpectEntryAllowsAllOnErrorIfOptedOut(
net::URLRequestThrottlerEntryInterface* entry,
bool opted_out) {
- EXPECT_FALSE(entry->IsDuringExponentialBackoff());
+ EXPECT_FALSE(entry->ShouldRejectRequest(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->IsDuringExponentialBackoff());
+ EXPECT_NE(opted_out, entry->ShouldRejectRequest(0));
if (opted_out) {
// We're not mocking out GetTimeNow() in this scenario
@@ -510,7 +526,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->IsDuringExponentialBackoff());
+ EXPECT_TRUE(entry_before->ShouldRejectRequest(0));
switch (i) {
case 0:
@@ -528,7 +544,7 @@ TEST(URLRequestThrottlerManager, ClearOnNetworkChange) {
scoped_refptr<net::URLRequestThrottlerEntryInterface> entry_after =
manager.RegisterRequestUrl(GURL("http://www.example.com/"));
- EXPECT_FALSE(entry_after->IsDuringExponentialBackoff());
+ EXPECT_FALSE(entry_after->ShouldRejectRequest(0));
}
}
« no previous file with comments | « net/url_request/url_request_throttler_simulation_unittest.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698