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

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

Issue 1991153002: Reload cache control test: add more tests (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: disable NavigateToSame if browser-side navigation is enabled Created 4 years 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 | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2016 The Chromium Authors. All rights reserved. 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 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include <memory> 5 #include <memory>
6 #include <string>
7 #include <vector>
6 8
7 #include "base/bind.h" 9 #include "base/bind.h"
8 #include "base/bind_helpers.h" 10 #include "base/bind_helpers.h"
11 #include "base/command_line.h"
12 #include "base/macros.h"
13 #include "base/synchronization/lock.h"
14 #include "content/public/common/content_switches.h"
9 #include "content/public/test/content_browser_test.h" 15 #include "content/public/test/content_browser_test.h"
10 #include "content/public/test/content_browser_test_utils.h" 16 #include "content/public/test/content_browser_test_utils.h"
11 #include "content/shell/browser/shell.h" 17 #include "content/shell/browser/shell.h"
12 #include "net/test/embedded_test_server/embedded_test_server.h" 18 #include "net/test/embedded_test_server/embedded_test_server.h"
13 #include "net/test/embedded_test_server/http_request.h" 19 #include "net/test/embedded_test_server/http_request.h"
14 #include "net/test/embedded_test_server/http_response.h" 20 #include "net/test/embedded_test_server/http_response.h"
15 #include "testing/gtest/include/gtest/gtest.h" 21 #include "testing/gtest/include/gtest/gtest.h"
16 #include "url/gurl.h" 22 #include "url/gurl.h"
17 23
18 namespace content { 24 namespace content {
19 25
20 namespace { 26 namespace {
21 27
22 using net::test_server::HttpRequest; 28 using net::test_server::HttpRequest;
23 using net::test_server::HttpResponse; 29 using net::test_server::HttpResponse;
24 30
25 const char kReloadTestPath[] = "/loader/reload.html"; 31 const char kReloadTestPath[] = "/loader/reload.html";
26 const char kReloadImagePath[] = "/loader/empty16x16.png"; 32 const char kReloadImagePath[] = "/loader/empty16x16.png";
27 33
28 const char kNoCacheControl[] = ""; 34 const char kNoCacheControl[] = "";
29 const char kMaxAgeCacheControl[] = "max-age=0"; 35 const char kMaxAgeCacheControl[] = "max-age=0";
30 const char kNoCacheCacheControl[] = "no-cache"; 36 const char kNoCacheCacheControl[] = "no-cache";
31 37
32 struct RequestLog { 38 struct RequestLog {
33 std::string relative_url; 39 std::string relative_url;
34 std::string cache_control; 40 std::string cache_control;
35 }; 41 };
36 42
43 // Tests end to end behaviors between Blink and content around reload variants.
37 class ReloadCacheControlBrowserTest : public ContentBrowserTest { 44 class ReloadCacheControlBrowserTest : public ContentBrowserTest {
38 protected: 45 protected:
39 ReloadCacheControlBrowserTest() {} 46 ReloadCacheControlBrowserTest() {}
40 ~ReloadCacheControlBrowserTest() override = default; 47 ~ReloadCacheControlBrowserTest() override = default;
41 48
42 void SetUpOnMainThread() override { 49 void SetUpOnMainThread() override {
43 SetUpTestServerOnMainThread(); 50 SetUpTestServerOnMainThread();
44 } 51 }
45 52
46 void SetUpTestServerOnMainThread() { 53 void SetUpTestServerOnMainThread() {
47 // ContentBrowserTest creates embedded_test_server instance with 54 // ContentBrowserTest creates embedded_test_server instance with
48 // a registered HandleFileRequest for "content/test/data". 55 // a registered HandleFileRequest for "content/test/data".
49 // Because the handler is registered as the first handler, MonitorHandler 56 // Because the handler is registered as the first handler, MonitorHandler
50 // is needed to capture all requests. 57 // is needed to capture all requests.
51 embedded_test_server()->RegisterRequestMonitor(base::Bind( 58 embedded_test_server()->RegisterRequestMonitor(base::Bind(
52 &ReloadCacheControlBrowserTest::MonitorRequestHandler, 59 &ReloadCacheControlBrowserTest::MonitorRequestHandler,
53 base::Unretained(this))); 60 base::Unretained(this)));
54 61
55 ASSERT_TRUE(embedded_test_server()->Start()); 62 ASSERT_TRUE(embedded_test_server()->Start());
56 } 63 }
57 64
58 protected: 65 protected:
59 std::vector<RequestLog> request_log_; 66 std::vector<RequestLog> request_log_;
67 base::Lock request_log_lock_;
60 68
61 private: 69 private:
62 void MonitorRequestHandler(const HttpRequest& request) { 70 void MonitorRequestHandler(const HttpRequest& request) {
63 RequestLog log; 71 RequestLog log;
64 log.relative_url = request.relative_url; 72 log.relative_url = request.relative_url;
65 auto cache_control = request.headers.find("Cache-Control"); 73 auto cache_control = request.headers.find("Cache-Control");
66 log.cache_control = cache_control == request.headers.end() 74 log.cache_control = cache_control == request.headers.end()
67 ? kNoCacheControl 75 ? kNoCacheControl
68 : cache_control->second; 76 : cache_control->second;
77 base::AutoLock lock(request_log_lock_);
69 request_log_.push_back(log); 78 request_log_.push_back(log);
70 } 79 }
71 80
72 DISALLOW_COPY_AND_ASSIGN(ReloadCacheControlBrowserTest); 81 DISALLOW_COPY_AND_ASSIGN(ReloadCacheControlBrowserTest);
73 }; 82 };
74 83
75 IN_PROC_BROWSER_TEST_F(ReloadCacheControlBrowserTest, NormalReload) { 84 IN_PROC_BROWSER_TEST_F(ReloadCacheControlBrowserTest, NormalReload) {
76 GURL url(embedded_test_server()->GetURL(kReloadTestPath)); 85 GURL url(embedded_test_server()->GetURL(kReloadTestPath));
77 86
78 EXPECT_TRUE(NavigateToURL(shell(), url)); 87 EXPECT_TRUE(NavigateToURL(shell(), url));
79 ReloadBlockUntilNavigationsComplete(shell(), 1); 88 ReloadBlockUntilNavigationsComplete(shell(), 1);
80 89
81 ASSERT_EQ(4UL, request_log_.size()); 90 {
82 EXPECT_EQ(kReloadTestPath, request_log_[0].relative_url); 91 base::AutoLock lock(request_log_lock_);
83 EXPECT_EQ(kNoCacheControl, request_log_[0].cache_control); 92 ASSERT_EQ(4UL, request_log_.size());
84 EXPECT_EQ(kReloadImagePath, request_log_[1].relative_url); 93 EXPECT_EQ(kReloadTestPath, request_log_[0].relative_url);
85 EXPECT_EQ(kNoCacheControl, request_log_[1].cache_control); 94 EXPECT_EQ(kNoCacheControl, request_log_[0].cache_control);
95 EXPECT_EQ(kReloadImagePath, request_log_[1].relative_url);
96 EXPECT_EQ(kNoCacheControl, request_log_[1].cache_control);
86 97
87 EXPECT_EQ(kReloadTestPath, request_log_[2].relative_url); 98 EXPECT_EQ(kReloadTestPath, request_log_[2].relative_url);
88 EXPECT_EQ(kMaxAgeCacheControl, request_log_[2].cache_control); 99 EXPECT_EQ(kMaxAgeCacheControl, request_log_[2].cache_control);
89 EXPECT_EQ(kReloadImagePath, request_log_[3].relative_url); 100 EXPECT_EQ(kReloadImagePath, request_log_[3].relative_url);
90 EXPECT_EQ(kNoCacheControl, request_log_[3].cache_control); 101 EXPECT_EQ(kNoCacheControl, request_log_[3].cache_control);
102 }
103
104 shell()->ShowDevTools();
105 ReloadBlockUntilNavigationsComplete(shell(), 1);
106
107 {
108 base::AutoLock lock(request_log_lock_);
109 ASSERT_EQ(6UL, request_log_.size());
110 EXPECT_EQ(kReloadTestPath, request_log_[4].relative_url);
111 EXPECT_EQ(kMaxAgeCacheControl, request_log_[4].cache_control);
112 EXPECT_EQ(kReloadImagePath, request_log_[5].relative_url);
113 EXPECT_EQ(kNoCacheControl, request_log_[5].cache_control);
114 }
115
116 shell()->CloseDevTools();
117 ReloadBlockUntilNavigationsComplete(shell(), 1);
118
119 {
120 base::AutoLock lock(request_log_lock_);
121 ASSERT_EQ(8UL, request_log_.size());
122 EXPECT_EQ(kReloadTestPath, request_log_[6].relative_url);
123 EXPECT_EQ(kMaxAgeCacheControl, request_log_[6].cache_control);
124 EXPECT_EQ(kReloadImagePath, request_log_[7].relative_url);
125 EXPECT_EQ(kNoCacheControl, request_log_[7].cache_control);
126 }
91 } 127 }
92 128
93 IN_PROC_BROWSER_TEST_F(ReloadCacheControlBrowserTest, BypassingReload) { 129 IN_PROC_BROWSER_TEST_F(ReloadCacheControlBrowserTest, BypassingReload) {
94 GURL url(embedded_test_server()->GetURL(kReloadTestPath)); 130 GURL url(embedded_test_server()->GetURL(kReloadTestPath));
95 131
96 EXPECT_TRUE(NavigateToURL(shell(), url)); 132 EXPECT_TRUE(NavigateToURL(shell(), url));
97 ReloadBypassingCacheBlockUntilNavigationsComplete(shell(), 1); 133 ReloadBypassingCacheBlockUntilNavigationsComplete(shell(), 1);
98 134
99 ASSERT_EQ(4UL, request_log_.size()); 135 {
100 EXPECT_EQ(kReloadTestPath, request_log_[0].relative_url); 136 base::AutoLock lock(request_log_lock_);
101 EXPECT_EQ(kNoCacheControl, request_log_[0].cache_control); 137 ASSERT_EQ(4UL, request_log_.size());
102 EXPECT_EQ(kReloadImagePath, request_log_[1].relative_url); 138 EXPECT_EQ(kReloadTestPath, request_log_[0].relative_url);
103 EXPECT_EQ(kNoCacheControl, request_log_[1].cache_control); 139 EXPECT_EQ(kNoCacheControl, request_log_[0].cache_control);
140 EXPECT_EQ(kReloadImagePath, request_log_[1].relative_url);
141 EXPECT_EQ(kNoCacheControl, request_log_[1].cache_control);
104 142
105 EXPECT_EQ(kReloadTestPath, request_log_[2].relative_url); 143 EXPECT_EQ(kReloadTestPath, request_log_[2].relative_url);
106 EXPECT_EQ(kNoCacheCacheControl, request_log_[2].cache_control); 144 EXPECT_EQ(kNoCacheCacheControl, request_log_[2].cache_control);
107 EXPECT_EQ(kReloadImagePath, request_log_[3].relative_url); 145 EXPECT_EQ(kReloadImagePath, request_log_[3].relative_url);
108 EXPECT_EQ(kNoCacheCacheControl, request_log_[3].cache_control); 146 EXPECT_EQ(kNoCacheCacheControl, request_log_[3].cache_control);
147 }
148
149 shell()->ShowDevTools();
150 ReloadBypassingCacheBlockUntilNavigationsComplete(shell(), 1);
151
152 {
153 base::AutoLock lock(request_log_lock_);
154 ASSERT_EQ(6UL, request_log_.size());
155 EXPECT_EQ(kReloadTestPath, request_log_[4].relative_url);
156 EXPECT_EQ(kNoCacheCacheControl, request_log_[4].cache_control);
157 EXPECT_EQ(kReloadImagePath, request_log_[5].relative_url);
158 EXPECT_EQ(kNoCacheCacheControl, request_log_[5].cache_control);
159 }
160
161 shell()->CloseDevTools();
162 ReloadBypassingCacheBlockUntilNavigationsComplete(shell(), 1);
163
164 {
165 base::AutoLock lock(request_log_lock_);
166 ASSERT_EQ(8UL, request_log_.size());
167 EXPECT_EQ(kReloadTestPath, request_log_[6].relative_url);
168 EXPECT_EQ(kNoCacheCacheControl, request_log_[6].cache_control);
169 EXPECT_EQ(kReloadImagePath, request_log_[7].relative_url);
170 EXPECT_EQ(kNoCacheCacheControl, request_log_[7].cache_control);
171 }
109 } 172 }
110 173
111 // TODO(toyoshim): Add another set of reload tests with DevTools open. 174 IN_PROC_BROWSER_TEST_F(ReloadCacheControlBrowserTest, NavigateToSame) {
175 GURL url(embedded_test_server()->GetURL(kReloadTestPath));
176
177 EXPECT_TRUE(NavigateToURL(shell(), url));
178 EXPECT_TRUE(NavigateToURL(shell(), url));
179
180 // The first navigation is just a normal load.
181 {
182 base::AutoLock lock(request_log_lock_);
183 ASSERT_EQ(4UL, request_log_.size());
184 EXPECT_EQ(kReloadTestPath, request_log_[0].relative_url);
185 EXPECT_EQ(kNoCacheControl, request_log_[0].cache_control);
186 EXPECT_EQ(kReloadImagePath, request_log_[1].relative_url);
187 EXPECT_EQ(kNoCacheControl, request_log_[1].cache_control);
188 }
189
190 // TODO(crbug.com/671545): This test does not work correctly if browser-side
191 // navigation is enabled.
192 if (base::CommandLine::ForCurrentProcess()->HasSwitch(
193 switches::kEnableBrowserSideNavigation))
194 return;
195
196 // The second navigation is the same page navigation. This should be handled
197 // as a reload, revalidating the main resource, but following cache protocols
198 // for others.
199 {
200 base::AutoLock lock(request_log_lock_);
201 EXPECT_EQ(kReloadTestPath, request_log_[2].relative_url);
202 EXPECT_EQ(kMaxAgeCacheControl, request_log_[2].cache_control);
203 EXPECT_EQ(kReloadImagePath, request_log_[3].relative_url);
204 EXPECT_EQ(kNoCacheControl, request_log_[3].cache_control);
205 }
206
207 shell()->ShowDevTools();
208 EXPECT_TRUE(NavigateToURL(shell(), url));
209
210 {
211 base::AutoLock lock(request_log_lock_);
212 ASSERT_EQ(6UL, request_log_.size());
213 EXPECT_EQ(kReloadTestPath, request_log_[4].relative_url);
214 EXPECT_EQ(kMaxAgeCacheControl, request_log_[4].cache_control);
215 EXPECT_EQ(kReloadImagePath, request_log_[5].relative_url);
216 EXPECT_EQ(kNoCacheControl, request_log_[5].cache_control);
217 }
218
219 shell()->CloseDevTools();
220 EXPECT_TRUE(NavigateToURL(shell(), url));
221
222 {
223 base::AutoLock lock(request_log_lock_);
224 ASSERT_EQ(8UL, request_log_.size());
225 EXPECT_EQ(kReloadTestPath, request_log_[6].relative_url);
226 EXPECT_EQ(kMaxAgeCacheControl, request_log_[6].cache_control);
227 EXPECT_EQ(kReloadImagePath, request_log_[7].relative_url);
228 EXPECT_EQ(kNoCacheControl, request_log_[7].cache_control);
229 }
230 }
112 231
113 } // namespace 232 } // namespace
114 233
115 } // namespace content 234 } // namespace content
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698