| Index: content/browser/loader/reload_cache_control_browsertest.cc
|
| diff --git a/content/browser/loader/reload_cache_control_browsertest.cc b/content/browser/loader/reload_cache_control_browsertest.cc
|
| index 38586762a6eea3fa9c68ce15ff2ad8a2b795f68e..070c677ac01b32055222dbf4b52cca73417c4957 100644
|
| --- a/content/browser/loader/reload_cache_control_browsertest.cc
|
| +++ b/content/browser/loader/reload_cache_control_browsertest.cc
|
| @@ -22,10 +22,12 @@ namespace content {
|
|
|
| namespace {
|
|
|
| +using net::test_server::BasicHttpResponse;
|
| using net::test_server::HttpRequest;
|
| using net::test_server::HttpResponse;
|
|
|
| const char kReloadTestPath[] = "/loader/reload.html";
|
| +const char kPseudoReloadTestPath[] = "/loader/_reload.html";
|
| const char kReloadImagePath[] = "/loader/empty16x16.png";
|
|
|
| const char kNoCacheControl[] = "";
|
| @@ -35,6 +37,8 @@ const char kNoCacheCacheControl[] = "no-cache";
|
| struct RequestLog {
|
| std::string relative_url;
|
| std::string cache_control;
|
| + bool has_if_none_match;
|
| + bool has_if_modified_since;
|
| };
|
|
|
| class ReloadCacheControlBrowserTest : public ContentBrowserTest {
|
| @@ -47,8 +51,11 @@ class ReloadCacheControlBrowserTest : public ContentBrowserTest {
|
| // a registered HandleFileRequest for "content/test/data".
|
| // Because the handler is registered as the first handler, MonitorHandler
|
| // is needed to capture all requests.
|
| - embedded_test_server()->RegisterRequestMonitor(base::Bind(
|
| - &ReloadCacheControlBrowserTest::MonitorRequestHandler, this));
|
| + embedded_test_server()->RegisterRequestMonitor(
|
| + base::Bind(&ReloadCacheControlBrowserTest::RequestMonitor, this));
|
| +
|
| + embedded_test_server()->RegisterRequestHandler(
|
| + base::Bind(&ReloadCacheControlBrowserTest::RequestHandler, this));
|
|
|
| ASSERT_TRUE(embedded_test_server()->Start());
|
| }
|
| @@ -57,16 +64,32 @@ class ReloadCacheControlBrowserTest : public ContentBrowserTest {
|
| std::vector<RequestLog> request_log_;
|
|
|
| private:
|
| - void MonitorRequestHandler(const HttpRequest& request) {
|
| + void RequestMonitor(const HttpRequest& request) {
|
| RequestLog log;
|
| log.relative_url = request.relative_url;
|
| - auto cache_control = request.headers.find("Cache-Control");
|
| + const auto cache_control = request.headers.find("Cache-Control");
|
| log.cache_control = cache_control == request.headers.end()
|
| ? kNoCacheControl
|
| : cache_control->second;
|
| + log.has_if_none_match =
|
| + request.headers.find("If-None-Match") != request.headers.end();
|
| + log.has_if_modified_since =
|
| + request.headers.find("If-Modified-Since") != request.headers.end();
|
| request_log_.push_back(log);
|
| }
|
|
|
| + std::unique_ptr<HttpResponse> RequestHandler(const HttpRequest& request) {
|
| + if (request.relative_url != kPseudoReloadTestPath)
|
| + return nullptr;
|
| +
|
| + std::unique_ptr<BasicHttpResponse> response(new BasicHttpResponse);
|
| + response->set_code(net::HTTP_OK);
|
| + response->set_content_type("text/html; charset=utf-8");
|
| + response->AddCustomHeader("Last-Modified", "Tue, 15 Nov 1994 12:45:26 GMT");
|
| + response->set_content("<html></html>");
|
| + return std::move(response);
|
| + }
|
| +
|
| DISALLOW_COPY_AND_ASSIGN(ReloadCacheControlBrowserTest);
|
| };
|
|
|
| @@ -98,13 +121,44 @@ IN_PROC_BROWSER_TEST_F(ReloadCacheControlBrowserTest, NormalReload) {
|
| ASSERT_EQ(4UL, request_log_.size());
|
| EXPECT_EQ(kReloadTestPath, request_log_[0].relative_url);
|
| EXPECT_EQ(kNoCacheControl, request_log_[0].cache_control);
|
| + EXPECT_FALSE(request_log_[0].has_if_none_match);
|
| + EXPECT_FALSE(request_log_[0].has_if_modified_since);
|
| EXPECT_EQ(kReloadImagePath, request_log_[1].relative_url);
|
| EXPECT_EQ(kNoCacheControl, request_log_[1].cache_control);
|
| + EXPECT_FALSE(request_log_[1].has_if_none_match);
|
| + EXPECT_FALSE(request_log_[1].has_if_modified_since);
|
|
|
| + // The test server uses ETag to serve files by default, and it results in
|
| + // using If-None-Match header for reloads.
|
| EXPECT_EQ(kReloadTestPath, request_log_[2].relative_url);
|
| EXPECT_EQ(kMaxAgeCacheControl, request_log_[2].cache_control);
|
| + EXPECT_TRUE(request_log_[2].has_if_none_match);
|
| + EXPECT_FALSE(request_log_[2].has_if_modified_since);
|
| EXPECT_EQ(kReloadImagePath, request_log_[3].relative_url);
|
| EXPECT_EQ(kMaxAgeCacheControl, request_log_[3].cache_control);
|
| + EXPECT_TRUE(request_log_[3].has_if_none_match);
|
| + EXPECT_FALSE(request_log_[3].has_if_modified_since);
|
| +}
|
| +
|
| +IN_PROC_BROWSER_TEST_F(ReloadCacheControlBrowserTest, ReloadWithLastModified) {
|
| + GURL url(embedded_test_server()->GetURL(kPseudoReloadTestPath));
|
| +
|
| + EXPECT_TRUE(NavigateToURL(shell(), url));
|
| + ReloadBlockUntilNavigationsComplete(shell(), 1);
|
| +
|
| + ASSERT_EQ(2UL, request_log_.size());
|
| + EXPECT_EQ(kPseudoReloadTestPath, request_log_[0].relative_url);
|
| + EXPECT_EQ(kNoCacheControl, request_log_[0].cache_control);
|
| + EXPECT_FALSE(request_log_[0].has_if_none_match);
|
| + EXPECT_FALSE(request_log_[0].has_if_modified_since);
|
| +
|
| + // kPseudoReloadTestPath is handled by RequestHandler() that returns
|
| + // a content with Last-Modified header, and it results in using
|
| + // using If-Modified-Since header for reloads.
|
| + EXPECT_EQ(kPseudoReloadTestPath, request_log_[1].relative_url);
|
| + EXPECT_EQ(kMaxAgeCacheControl, request_log_[1].cache_control);
|
| + EXPECT_FALSE(request_log_[1].has_if_none_match);
|
| + EXPECT_TRUE(request_log_[1].has_if_modified_since);
|
| }
|
|
|
| IN_PROC_BROWSER_TEST_F(ReloadCacheControlBrowserTest, BypassingReload) {
|
| @@ -116,13 +170,24 @@ IN_PROC_BROWSER_TEST_F(ReloadCacheControlBrowserTest, BypassingReload) {
|
| ASSERT_EQ(4UL, request_log_.size());
|
| EXPECT_EQ(kReloadTestPath, request_log_[0].relative_url);
|
| EXPECT_EQ(kNoCacheControl, request_log_[0].cache_control);
|
| + EXPECT_FALSE(request_log_[0].has_if_none_match);
|
| + EXPECT_FALSE(request_log_[0].has_if_modified_since);
|
| EXPECT_EQ(kReloadImagePath, request_log_[1].relative_url);
|
| EXPECT_EQ(kNoCacheControl, request_log_[1].cache_control);
|
| + EXPECT_FALSE(request_log_[1].has_if_none_match);
|
| + EXPECT_FALSE(request_log_[1].has_if_modified_since);
|
|
|
| + // Bypassing reload should not use If-None-Match and If-Modified-Since headers
|
| + // because such requests imply no cache system exist and have no chance to
|
| + // handle 304 responses.
|
| EXPECT_EQ(kReloadTestPath, request_log_[2].relative_url);
|
| EXPECT_EQ(kNoCacheCacheControl, request_log_[2].cache_control);
|
| + EXPECT_FALSE(request_log_[2].has_if_none_match);
|
| + EXPECT_FALSE(request_log_[2].has_if_modified_since);
|
| EXPECT_EQ(kReloadImagePath, request_log_[3].relative_url);
|
| EXPECT_EQ(kNoCacheCacheControl, request_log_[3].cache_control);
|
| + EXPECT_FALSE(request_log_[3].has_if_none_match);
|
| + EXPECT_FALSE(request_log_[3].has_if_modified_since);
|
| }
|
|
|
| IN_PROC_BROWSER_TEST_F(ReloadCacheControlWithAnExperimentBrowserTest,
|
| @@ -135,13 +200,21 @@ IN_PROC_BROWSER_TEST_F(ReloadCacheControlWithAnExperimentBrowserTest,
|
| ASSERT_EQ(4UL, request_log_.size());
|
| EXPECT_EQ(kReloadTestPath, request_log_[0].relative_url);
|
| EXPECT_EQ(kNoCacheControl, request_log_[0].cache_control);
|
| + EXPECT_FALSE(request_log_[0].has_if_none_match);
|
| + EXPECT_FALSE(request_log_[0].has_if_modified_since);
|
| EXPECT_EQ(kReloadImagePath, request_log_[1].relative_url);
|
| EXPECT_EQ(kNoCacheControl, request_log_[1].cache_control);
|
| + EXPECT_FALSE(request_log_[1].has_if_none_match);
|
| + EXPECT_FALSE(request_log_[1].has_if_modified_since);
|
|
|
| EXPECT_EQ(kReloadTestPath, request_log_[2].relative_url);
|
| EXPECT_EQ(kMaxAgeCacheControl, request_log_[2].cache_control);
|
| + EXPECT_TRUE(request_log_[2].has_if_none_match);
|
| + EXPECT_FALSE(request_log_[2].has_if_modified_since);
|
| EXPECT_EQ(kReloadImagePath, request_log_[3].relative_url);
|
| EXPECT_EQ(kNoCacheControl, request_log_[3].cache_control);
|
| + EXPECT_TRUE(request_log_[3].has_if_none_match);
|
| + EXPECT_FALSE(request_log_[3].has_if_modified_since);
|
| }
|
|
|
| // TODO(toyoshim): Add another set of reload tests with DevTools open.
|
|
|