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

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

Issue 2541363002: Reload Reloaded: remove experimental flag that has been enabled by default (Closed)
Patch Set: 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
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 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/bind_helpers.h" 8 #include "base/bind_helpers.h"
9 #include "base/files/file_path.h"
10 #include "base/test/scoped_feature_list.h"
11 #include "content/public/common/content_features.h"
12 #include "content/public/test/content_browser_test.h" 9 #include "content/public/test/content_browser_test.h"
13 #include "content/public/test/content_browser_test_utils.h" 10 #include "content/public/test/content_browser_test_utils.h"
14 #include "content/shell/browser/shell.h" 11 #include "content/shell/browser/shell.h"
15 #include "net/test/embedded_test_server/embedded_test_server.h" 12 #include "net/test/embedded_test_server/embedded_test_server.h"
16 #include "net/test/embedded_test_server/http_request.h" 13 #include "net/test/embedded_test_server/http_request.h"
17 #include "net/test/embedded_test_server/http_response.h" 14 #include "net/test/embedded_test_server/http_response.h"
18 #include "testing/gtest/include/gtest/gtest.h" 15 #include "testing/gtest/include/gtest/gtest.h"
19 #include "url/gurl.h" 16 #include "url/gurl.h"
20 17
21 namespace content { 18 namespace content {
(...skipping 10 matching lines...) Expand all
32 const char kMaxAgeCacheControl[] = "max-age=0"; 29 const char kMaxAgeCacheControl[] = "max-age=0";
33 const char kNoCacheCacheControl[] = "no-cache"; 30 const char kNoCacheCacheControl[] = "no-cache";
34 31
35 struct RequestLog { 32 struct RequestLog {
36 std::string relative_url; 33 std::string relative_url;
37 std::string cache_control; 34 std::string cache_control;
38 }; 35 };
39 36
40 class ReloadCacheControlBrowserTest : public ContentBrowserTest { 37 class ReloadCacheControlBrowserTest : public ContentBrowserTest {
41 protected: 38 protected:
42 ReloadCacheControlBrowserTest() { 39 ReloadCacheControlBrowserTest() {}
43 // TODO(toyoshim): Tests in this file depend on current reload behavior,
44 // and should be modified when we enable the new reload behavior.
45 scoped_feature_list_.InitAndDisableFeature(
46 features::kNonValidatingReloadOnNormalReload);
47 }
48 ~ReloadCacheControlBrowserTest() override = default; 40 ~ReloadCacheControlBrowserTest() override = default;
49 41
50 void SetUpOnMainThread() override { 42 void SetUpOnMainThread() override {
51 SetUpTestServerOnMainThread(); 43 SetUpTestServerOnMainThread();
52 } 44 }
53 45
54 void SetUpTestServerOnMainThread() { 46 void SetUpTestServerOnMainThread() {
55 // ContentBrowserTest creates embedded_test_server instance with 47 // ContentBrowserTest creates embedded_test_server instance with
56 // a registered HandleFileRequest for "content/test/data". 48 // a registered HandleFileRequest for "content/test/data".
57 // Because the handler is registered as the first handler, MonitorHandler 49 // Because the handler is registered as the first handler, MonitorHandler
(...skipping 12 matching lines...) Expand all
70 void MonitorRequestHandler(const HttpRequest& request) { 62 void MonitorRequestHandler(const HttpRequest& request) {
71 RequestLog log; 63 RequestLog log;
72 log.relative_url = request.relative_url; 64 log.relative_url = request.relative_url;
73 auto cache_control = request.headers.find("Cache-Control"); 65 auto cache_control = request.headers.find("Cache-Control");
74 log.cache_control = cache_control == request.headers.end() 66 log.cache_control = cache_control == request.headers.end()
75 ? kNoCacheControl 67 ? kNoCacheControl
76 : cache_control->second; 68 : cache_control->second;
77 request_log_.push_back(log); 69 request_log_.push_back(log);
78 } 70 }
79 71
80 base::test::ScopedFeatureList scoped_feature_list_;
81
82 DISALLOW_COPY_AND_ASSIGN(ReloadCacheControlBrowserTest); 72 DISALLOW_COPY_AND_ASSIGN(ReloadCacheControlBrowserTest);
83 }; 73 };
84 74
85 class ReloadCacheControlWithAnExperimentBrowserTest
86 : public ReloadCacheControlBrowserTest {
87 protected:
88 ReloadCacheControlWithAnExperimentBrowserTest() {
89 scoped_feature_list_.InitAndEnableFeature(
90 features::kNonValidatingReloadOnNormalReload);
91 }
92 ~ReloadCacheControlWithAnExperimentBrowserTest() override = default;
93
94 void SetUpOnMainThread() override {
95 SetUpTestServerOnMainThread();
96 }
97
98 base::test::ScopedFeatureList scoped_feature_list_;
99
100 DISALLOW_COPY_AND_ASSIGN(ReloadCacheControlWithAnExperimentBrowserTest);
101 };
102
103 IN_PROC_BROWSER_TEST_F(ReloadCacheControlBrowserTest, NormalReload) { 75 IN_PROC_BROWSER_TEST_F(ReloadCacheControlBrowserTest, NormalReload) {
104 GURL url(embedded_test_server()->GetURL(kReloadTestPath)); 76 GURL url(embedded_test_server()->GetURL(kReloadTestPath));
105 77
106 EXPECT_TRUE(NavigateToURL(shell(), url)); 78 EXPECT_TRUE(NavigateToURL(shell(), url));
107 ReloadBlockUntilNavigationsComplete(shell(), 1); 79 ReloadBlockUntilNavigationsComplete(shell(), 1);
108 80
109 ASSERT_EQ(4UL, request_log_.size()); 81 ASSERT_EQ(4UL, request_log_.size());
110 EXPECT_EQ(kReloadTestPath, request_log_[0].relative_url); 82 EXPECT_EQ(kReloadTestPath, request_log_[0].relative_url);
111 EXPECT_EQ(kNoCacheControl, request_log_[0].cache_control); 83 EXPECT_EQ(kNoCacheControl, request_log_[0].cache_control);
112 EXPECT_EQ(kReloadImagePath, request_log_[1].relative_url); 84 EXPECT_EQ(kReloadImagePath, request_log_[1].relative_url);
113 EXPECT_EQ(kNoCacheControl, request_log_[1].cache_control); 85 EXPECT_EQ(kNoCacheControl, request_log_[1].cache_control);
114 86
115 EXPECT_EQ(kReloadTestPath, request_log_[2].relative_url); 87 EXPECT_EQ(kReloadTestPath, request_log_[2].relative_url);
116 EXPECT_EQ(kMaxAgeCacheControl, request_log_[2].cache_control); 88 EXPECT_EQ(kMaxAgeCacheControl, request_log_[2].cache_control);
117 EXPECT_EQ(kReloadImagePath, request_log_[3].relative_url); 89 EXPECT_EQ(kReloadImagePath, request_log_[3].relative_url);
118 EXPECT_EQ(kMaxAgeCacheControl, request_log_[3].cache_control); 90 EXPECT_EQ(kNoCacheControl, request_log_[3].cache_control);
119 } 91 }
120 92
121 IN_PROC_BROWSER_TEST_F(ReloadCacheControlBrowserTest, BypassingReload) { 93 IN_PROC_BROWSER_TEST_F(ReloadCacheControlBrowserTest, BypassingReload) {
122 GURL url(embedded_test_server()->GetURL(kReloadTestPath)); 94 GURL url(embedded_test_server()->GetURL(kReloadTestPath));
123 95
124 EXPECT_TRUE(NavigateToURL(shell(), url)); 96 EXPECT_TRUE(NavigateToURL(shell(), url));
125 ReloadBypassingCacheBlockUntilNavigationsComplete(shell(), 1); 97 ReloadBypassingCacheBlockUntilNavigationsComplete(shell(), 1);
126 98
127 ASSERT_EQ(4UL, request_log_.size()); 99 ASSERT_EQ(4UL, request_log_.size());
128 EXPECT_EQ(kReloadTestPath, request_log_[0].relative_url); 100 EXPECT_EQ(kReloadTestPath, request_log_[0].relative_url);
129 EXPECT_EQ(kNoCacheControl, request_log_[0].cache_control); 101 EXPECT_EQ(kNoCacheControl, request_log_[0].cache_control);
130 EXPECT_EQ(kReloadImagePath, request_log_[1].relative_url); 102 EXPECT_EQ(kReloadImagePath, request_log_[1].relative_url);
131 EXPECT_EQ(kNoCacheControl, request_log_[1].cache_control); 103 EXPECT_EQ(kNoCacheControl, request_log_[1].cache_control);
132 104
133 EXPECT_EQ(kReloadTestPath, request_log_[2].relative_url); 105 EXPECT_EQ(kReloadTestPath, request_log_[2].relative_url);
134 EXPECT_EQ(kNoCacheCacheControl, request_log_[2].cache_control); 106 EXPECT_EQ(kNoCacheCacheControl, request_log_[2].cache_control);
135 EXPECT_EQ(kReloadImagePath, request_log_[3].relative_url); 107 EXPECT_EQ(kReloadImagePath, request_log_[3].relative_url);
136 EXPECT_EQ(kNoCacheCacheControl, request_log_[3].cache_control); 108 EXPECT_EQ(kNoCacheCacheControl, request_log_[3].cache_control);
137 } 109 }
138 110
139 IN_PROC_BROWSER_TEST_F(ReloadCacheControlWithAnExperimentBrowserTest,
140 ReloadMainResource) {
141 GURL url(embedded_test_server()->GetURL(kReloadTestPath));
142
143 EXPECT_TRUE(NavigateToURL(shell(), url));
144 ReloadBlockUntilNavigationsComplete(shell(), 1);
145
146 ASSERT_EQ(4UL, request_log_.size());
147 EXPECT_EQ(kReloadTestPath, request_log_[0].relative_url);
148 EXPECT_EQ(kNoCacheControl, request_log_[0].cache_control);
149 EXPECT_EQ(kReloadImagePath, request_log_[1].relative_url);
150 EXPECT_EQ(kNoCacheControl, request_log_[1].cache_control);
151
152 EXPECT_EQ(kReloadTestPath, request_log_[2].relative_url);
153 EXPECT_EQ(kMaxAgeCacheControl, request_log_[2].cache_control);
154 EXPECT_EQ(kReloadImagePath, request_log_[3].relative_url);
155 EXPECT_EQ(kNoCacheControl, request_log_[3].cache_control);
156 }
157
158 // TODO(toyoshim): Add another set of reload tests with DevTools open. 111 // TODO(toyoshim): Add another set of reload tests with DevTools open.
159 112
160 } // namespace 113 } // namespace
161 114
162 } // namespace content 115 } // namespace content
OLDNEW
« no previous file with comments | « content/browser/frame_host/navigator_impl_unittest.cc ('k') | content/child/runtime_features.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698