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

Unified Diff: net/http/http_util_unittest.cc

Issue 706203003: Update from https://crrev.com/303153 (Closed) Base URL: git@github.com:domokit/mojo.git@master
Patch Set: Created 6 years, 1 month 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/http/http_util.cc ('k') | net/http/transport_security_state_static.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: net/http/http_util_unittest.cc
diff --git a/net/http/http_util_unittest.cc b/net/http/http_util_unittest.cc
index acb26930a0bee227ba111a760fe0e4c6c48dc31b..e20bbdcef2c390e209ebcbcf7176417b0e00a791 100644
--- a/net/http/http_util_unittest.cc
+++ b/net/http/http_util_unittest.cc
@@ -872,6 +872,49 @@ TEST(HttpUtilTest, ParseRanges) {
}
}
+TEST(HttpUtilTest, ParseRetryAfterHeader) {
+ base::Time::Exploded now_exploded = { 2014, 11, -1, 5, 22, 39, 30, 0 };
+ base::Time now = base::Time::FromUTCExploded(now_exploded);
+
+ base::Time::Exploded later_exploded = { 2015, 1, -1, 1, 12, 34, 56, 0 };
+ base::Time later = base::Time::FromUTCExploded(later_exploded);
+
+ const struct {
+ const char* retry_after_string;
+ bool expected_return_value;
+ base::TimeDelta expected_retry_after;
+ } tests[] = {
+ { "", false, base::TimeDelta() },
+ { "-3", false, base::TimeDelta() },
+ { "-2", false, base::TimeDelta() },
+ { "-1", false, base::TimeDelta() },
+ { "0", true, base::TimeDelta::FromSeconds(0) },
+ { "1", true, base::TimeDelta::FromSeconds(1) },
+ { "2", true, base::TimeDelta::FromSeconds(2) },
+ { "3", true, base::TimeDelta::FromSeconds(3) },
+ { "60", true, base::TimeDelta::FromSeconds(60) },
+ { "3600", true, base::TimeDelta::FromSeconds(3600) },
+ { "86400", true, base::TimeDelta::FromSeconds(86400) },
+ { "Thu, 1 Jan 2015 12:34:56 GMT", true, later - now },
+ { "Mon, 1 Jan 1900 12:34:56 GMT", false, base::TimeDelta() }
+ };
+
+ for (size_t i = 0; i < arraysize(tests); ++i) {
+ base::TimeDelta retry_after;
+ bool return_value = HttpUtil::ParseRetryAfterHeader(
+ tests[i].retry_after_string, now, &retry_after);
+ EXPECT_EQ(tests[i].expected_return_value, return_value)
+ << "Test case " << i << ": expected " << tests[i].expected_return_value
+ << " but got " << return_value << ".";
+ if (tests[i].expected_return_value && return_value) {
+ EXPECT_EQ(tests[i].expected_retry_after, retry_after)
+ << "Test case " << i << ": expected "
+ << tests[i].expected_retry_after.InSeconds() << "s but got "
+ << retry_after.InSeconds() << "s.";
+ }
+ }
+}
+
namespace {
void CheckCurrentNameValuePair(HttpUtil::NameValuePairsIterator* parser,
bool expect_valid,
« no previous file with comments | « net/http/http_util.cc ('k') | net/http/transport_security_state_static.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698