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

Side by Side Diff: content/browser/loader/reload_cache_control_browsertest.cc

Issue 1905873002: Add content_browsertests for testing cache control flags (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: remove ResourceFetcher change temporarily, fix a nit of #19 Created 4 years, 7 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 unified diff | Download patch
« no previous file with comments | « no previous file | content/content_tests.gypi » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 // Copyright 2016 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #include <memory>
6
7 #include "base/bind.h"
8 #include "base/bind_helpers.h"
9 #include "base/files/file_path.h"
10 #include "content/public/test/content_browser_test.h"
11 #include "content/public/test/content_browser_test_utils.h"
12 #include "content/shell/browser/shell.h"
13 #include "net/test/embedded_test_server/embedded_test_server.h"
14 #include "net/test/embedded_test_server/http_request.h"
15 #include "net/test/embedded_test_server/http_response.h"
16 #include "testing/gtest/include/gtest/gtest.h"
17 #include "url/gurl.h"
18
19 namespace content {
20
21 namespace {
22
23 using net::test_server::HttpRequest;
24 using net::test_server::HttpResponse;
25
26 const char kReloadTestPath[] = "/loader/reload.html";
27 const char kReloadImagePath[] = "/loader/empty16x16.png";
28
29 const char kNoCacheControl[] = "";
30 const char kMaxAgeCacheControl[] = "max-age=0";
31 const char kNoCacheCacheControl[] = "no-cache";
32
33 struct RequestLog {
34 std::string relative_url;
35 std::string cache_control;
36 };
37
38 class ReloadCacheControlBrowserTest : public ContentBrowserTest {
39 protected:
40 ReloadCacheControlBrowserTest() = default;
41 ~ReloadCacheControlBrowserTest() override = default;
42
43 void SetUpOnMainThread() override {
44 // ContentBrowserTest creates embedded_test_server instance with
45 // a registered HandleFileRequest for "content/test/data".
46 // Because the handler is registered as the first handler, MonitorHandler
47 // is needed to capture all requests.
48 embedded_test_server()->RegisterRequestMonitor(base::Bind(
49 &ReloadCacheControlBrowserTest::MonitorRequestHandler, this));
50
51 ASSERT_TRUE(embedded_test_server()->Start());
52 }
53
54 protected:
55 std::vector<RequestLog> request_log_;
56
57 private:
58 void MonitorRequestHandler(const HttpRequest& request) {
59 RequestLog log;
60 log.relative_url = request.relative_url;
61 auto cache_control = request.headers.find("Cache-Control");
62 log.cache_control = cache_control == request.headers.end()
63 ? kNoCacheControl
64 : cache_control->second;
65 request_log_.push_back(log);
66 }
67
68 DISALLOW_COPY_AND_ASSIGN(ReloadCacheControlBrowserTest);
69 };
70
71 IN_PROC_BROWSER_TEST_F(ReloadCacheControlBrowserTest, NormalReload) {
72 GURL url(embedded_test_server()->GetURL(kReloadTestPath));
73
74 EXPECT_TRUE(NavigateToURL(shell(), url));
75 ReloadBlockUntilNavigationsComplete(shell(), 1);
76
77 ASSERT_EQ(4UL, request_log_.size());
78 EXPECT_EQ(kReloadTestPath, request_log_[0].relative_url);
79 EXPECT_EQ(kNoCacheControl, request_log_[0].cache_control);
80 EXPECT_EQ(kReloadImagePath, request_log_[1].relative_url);
81 EXPECT_EQ(kNoCacheControl, request_log_[1].cache_control);
82
83 EXPECT_EQ(kReloadTestPath, request_log_[2].relative_url);
84 EXPECT_EQ(kMaxAgeCacheControl, request_log_[2].cache_control);
85 EXPECT_EQ(kReloadImagePath, request_log_[3].relative_url);
86 EXPECT_EQ(kMaxAgeCacheControl, request_log_[3].cache_control);
87 }
88
89 IN_PROC_BROWSER_TEST_F(ReloadCacheControlBrowserTest, BypassingReload) {
90 GURL url(embedded_test_server()->GetURL(kReloadTestPath));
91
92 EXPECT_TRUE(NavigateToURL(shell(), url));
93 ReloadBypassingCacheBlockUntilNavigationsComplete(shell(), 1);
94
95 ASSERT_EQ(4UL, request_log_.size());
96 EXPECT_EQ(kReloadTestPath, request_log_[0].relative_url);
97 EXPECT_EQ(kNoCacheControl, request_log_[0].cache_control);
98 EXPECT_EQ(kReloadImagePath, request_log_[1].relative_url);
99 EXPECT_EQ(kNoCacheControl, request_log_[1].cache_control);
100
101 EXPECT_EQ(kReloadTestPath, request_log_[2].relative_url);
102 EXPECT_EQ(kNoCacheCacheControl, request_log_[2].cache_control);
103 EXPECT_EQ(kReloadImagePath, request_log_[3].relative_url);
104 EXPECT_EQ(kNoCacheCacheControl, request_log_[3].cache_control);
105 }
106
107 } // namespace
108
109 } // namespace content
OLDNEW
« no previous file with comments | « no previous file | content/content_tests.gypi » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698