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

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

Issue 2484613002: Migrate more tests to ScopedFeatureList. (Closed)
Patch Set: rebase Created 4 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 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/feature_list.h"
10 #include "base/files/file_path.h" 9 #include "base/files/file_path.h"
10 #include "base/test/scoped_feature_list.h"
11 #include "content/public/common/content_features.h" 11 #include "content/public/common/content_features.h"
12 #include "content/public/test/content_browser_test.h" 12 #include "content/public/test/content_browser_test.h"
13 #include "content/public/test/content_browser_test_utils.h" 13 #include "content/public/test/content_browser_test_utils.h"
14 #include "content/shell/browser/shell.h" 14 #include "content/shell/browser/shell.h"
15 #include "net/test/embedded_test_server/embedded_test_server.h" 15 #include "net/test/embedded_test_server/embedded_test_server.h"
16 #include "net/test/embedded_test_server/http_request.h" 16 #include "net/test/embedded_test_server/http_request.h"
17 #include "net/test/embedded_test_server/http_response.h" 17 #include "net/test/embedded_test_server/http_response.h"
18 #include "testing/gtest/include/gtest/gtest.h" 18 #include "testing/gtest/include/gtest/gtest.h"
19 #include "url/gurl.h" 19 #include "url/gurl.h"
20 20
(...skipping 17 matching lines...) Expand all
38 }; 38 };
39 39
40 class ReloadCacheControlBrowserTest : public ContentBrowserTest { 40 class ReloadCacheControlBrowserTest : public ContentBrowserTest {
41 protected: 41 protected:
42 ReloadCacheControlBrowserTest() = default; 42 ReloadCacheControlBrowserTest() = default;
43 ~ReloadCacheControlBrowserTest() override = default; 43 ~ReloadCacheControlBrowserTest() override = default;
44 44
45 void SetUpOnMainThread() override { 45 void SetUpOnMainThread() override {
46 // TODO(toyoshim): Tests in this file depend on current reload behavior, 46 // TODO(toyoshim): Tests in this file depend on current reload behavior,
47 // and should be modified when we enable the new reload behavior. 47 // and should be modified when we enable the new reload behavior.
48 base::FeatureList::ClearInstanceForTesting(); 48 scoped_feature_list_.InitAndDisableFeature(
49 std::unique_ptr<base::FeatureList> feature_list(new base::FeatureList); 49 features::kNonValidatingReloadOnNormalReload);
50 feature_list->InitializeFromCommandLine(
51 std::string(), features::kNonValidatingReloadOnNormalReload.name);
52 base::FeatureList::SetInstance(std::move(feature_list));
53 50
54 SetUpTestServerOnMainThread(); 51 SetUpTestServerOnMainThread();
55 } 52 }
56 53
57 void SetUpTestServerOnMainThread() { 54 void SetUpTestServerOnMainThread() {
58 // ContentBrowserTest creates embedded_test_server instance with 55 // ContentBrowserTest creates embedded_test_server instance with
59 // a registered HandleFileRequest for "content/test/data". 56 // a registered HandleFileRequest for "content/test/data".
60 // Because the handler is registered as the first handler, MonitorHandler 57 // Because the handler is registered as the first handler, MonitorHandler
61 // is needed to capture all requests. 58 // is needed to capture all requests.
62 embedded_test_server()->RegisterRequestMonitor(base::Bind( 59 embedded_test_server()->RegisterRequestMonitor(base::Bind(
(...skipping 10 matching lines...) Expand all
73 void MonitorRequestHandler(const HttpRequest& request) { 70 void MonitorRequestHandler(const HttpRequest& request) {
74 RequestLog log; 71 RequestLog log;
75 log.relative_url = request.relative_url; 72 log.relative_url = request.relative_url;
76 auto cache_control = request.headers.find("Cache-Control"); 73 auto cache_control = request.headers.find("Cache-Control");
77 log.cache_control = cache_control == request.headers.end() 74 log.cache_control = cache_control == request.headers.end()
78 ? kNoCacheControl 75 ? kNoCacheControl
79 : cache_control->second; 76 : cache_control->second;
80 request_log_.push_back(log); 77 request_log_.push_back(log);
81 } 78 }
82 79
80 base::test::ScopedFeatureList scoped_feature_list_;
81
83 DISALLOW_COPY_AND_ASSIGN(ReloadCacheControlBrowserTest); 82 DISALLOW_COPY_AND_ASSIGN(ReloadCacheControlBrowserTest);
84 }; 83 };
85 84
86 class ReloadCacheControlWithAnExperimentBrowserTest 85 class ReloadCacheControlWithAnExperimentBrowserTest
87 : public ReloadCacheControlBrowserTest { 86 : public ReloadCacheControlBrowserTest {
88 protected: 87 protected:
89 ReloadCacheControlWithAnExperimentBrowserTest() = default; 88 ReloadCacheControlWithAnExperimentBrowserTest() = default;
90 ~ReloadCacheControlWithAnExperimentBrowserTest() override = default; 89 ~ReloadCacheControlWithAnExperimentBrowserTest() override = default;
91 90
92 void SetUpOnMainThread() override { 91 void SetUpOnMainThread() override {
93 base::FeatureList::ClearInstanceForTesting(); 92 scoped_feature_list_.InitAndEnableFeature(
94 std::unique_ptr<base::FeatureList> feature_list(new base::FeatureList); 93 features::kNonValidatingReloadOnNormalReload);
95 feature_list->InitializeFromCommandLine(
96 features::kNonValidatingReloadOnNormalReload.name, std::string());
97 base::FeatureList::SetInstance(std::move(feature_list));
98 94
99 SetUpTestServerOnMainThread(); 95 SetUpTestServerOnMainThread();
100 } 96 }
101 97
98 base::test::ScopedFeatureList scoped_feature_list_;
99
102 DISALLOW_COPY_AND_ASSIGN(ReloadCacheControlWithAnExperimentBrowserTest); 100 DISALLOW_COPY_AND_ASSIGN(ReloadCacheControlWithAnExperimentBrowserTest);
103 }; 101 };
104 102
105 IN_PROC_BROWSER_TEST_F(ReloadCacheControlBrowserTest, NormalReload) { 103 IN_PROC_BROWSER_TEST_F(ReloadCacheControlBrowserTest, NormalReload) {
106 GURL url(embedded_test_server()->GetURL(kReloadTestPath)); 104 GURL url(embedded_test_server()->GetURL(kReloadTestPath));
107 105
108 EXPECT_TRUE(NavigateToURL(shell(), url)); 106 EXPECT_TRUE(NavigateToURL(shell(), url));
109 ReloadBlockUntilNavigationsComplete(shell(), 1); 107 ReloadBlockUntilNavigationsComplete(shell(), 1);
110 108
111 ASSERT_EQ(4UL, request_log_.size()); 109 ASSERT_EQ(4UL, request_log_.size());
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
155 EXPECT_EQ(kMaxAgeCacheControl, request_log_[2].cache_control); 153 EXPECT_EQ(kMaxAgeCacheControl, request_log_[2].cache_control);
156 EXPECT_EQ(kReloadImagePath, request_log_[3].relative_url); 154 EXPECT_EQ(kReloadImagePath, request_log_[3].relative_url);
157 EXPECT_EQ(kNoCacheControl, request_log_[3].cache_control); 155 EXPECT_EQ(kNoCacheControl, request_log_[3].cache_control);
158 } 156 }
159 157
160 // TODO(toyoshim): Add another set of reload tests with DevTools open. 158 // TODO(toyoshim): Add another set of reload tests with DevTools open.
161 159
162 } // namespace 160 } // namespace
163 161
164 } // namespace content 162 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698