| OLD | NEW |
| 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" |
| 9 #include "base/files/file_path.h" | 10 #include "base/files/file_path.h" |
| 11 #include "content/public/common/content_features.h" |
| 10 #include "content/public/test/content_browser_test.h" | 12 #include "content/public/test/content_browser_test.h" |
| 11 #include "content/public/test/content_browser_test_utils.h" | 13 #include "content/public/test/content_browser_test_utils.h" |
| 12 #include "content/shell/browser/shell.h" | 14 #include "content/shell/browser/shell.h" |
| 13 #include "net/test/embedded_test_server/embedded_test_server.h" | 15 #include "net/test/embedded_test_server/embedded_test_server.h" |
| 14 #include "net/test/embedded_test_server/http_request.h" | 16 #include "net/test/embedded_test_server/http_request.h" |
| 15 #include "net/test/embedded_test_server/http_response.h" | 17 #include "net/test/embedded_test_server/http_response.h" |
| 16 #include "testing/gtest/include/gtest/gtest.h" | 18 #include "testing/gtest/include/gtest/gtest.h" |
| 17 #include "url/gurl.h" | 19 #include "url/gurl.h" |
| 18 | 20 |
| 19 namespace content { | 21 namespace content { |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 61 auto cache_control = request.headers.find("Cache-Control"); | 63 auto cache_control = request.headers.find("Cache-Control"); |
| 62 log.cache_control = cache_control == request.headers.end() | 64 log.cache_control = cache_control == request.headers.end() |
| 63 ? kNoCacheControl | 65 ? kNoCacheControl |
| 64 : cache_control->second; | 66 : cache_control->second; |
| 65 request_log_.push_back(log); | 67 request_log_.push_back(log); |
| 66 } | 68 } |
| 67 | 69 |
| 68 DISALLOW_COPY_AND_ASSIGN(ReloadCacheControlBrowserTest); | 70 DISALLOW_COPY_AND_ASSIGN(ReloadCacheControlBrowserTest); |
| 69 }; | 71 }; |
| 70 | 72 |
| 73 class ReloadCacheControlWithAnExperimentBrowserTest |
| 74 : public ReloadCacheControlBrowserTest { |
| 75 protected: |
| 76 ReloadCacheControlWithAnExperimentBrowserTest() = default; |
| 77 ~ReloadCacheControlWithAnExperimentBrowserTest() override = default; |
| 78 |
| 79 void SetUpOnMainThread() override { |
| 80 base::FeatureList::ClearInstanceForTesting(); |
| 81 std::unique_ptr<base::FeatureList> feature_list(new base::FeatureList); |
| 82 feature_list->InitializeFromCommandLine( |
| 83 features::kNonValidatingReloadOnNormalReload.name, std::string()); |
| 84 base::FeatureList::SetInstance(std::move(feature_list)); |
| 85 |
| 86 ReloadCacheControlBrowserTest::SetUpOnMainThread(); |
| 87 } |
| 88 |
| 89 DISALLOW_COPY_AND_ASSIGN(ReloadCacheControlWithAnExperimentBrowserTest); |
| 90 }; |
| 91 |
| 71 IN_PROC_BROWSER_TEST_F(ReloadCacheControlBrowserTest, NormalReload) { | 92 IN_PROC_BROWSER_TEST_F(ReloadCacheControlBrowserTest, NormalReload) { |
| 72 GURL url(embedded_test_server()->GetURL(kReloadTestPath)); | 93 GURL url(embedded_test_server()->GetURL(kReloadTestPath)); |
| 73 | 94 |
| 74 EXPECT_TRUE(NavigateToURL(shell(), url)); | 95 EXPECT_TRUE(NavigateToURL(shell(), url)); |
| 75 ReloadBlockUntilNavigationsComplete(shell(), 1); | 96 ReloadBlockUntilNavigationsComplete(shell(), 1); |
| 76 | 97 |
| 77 ASSERT_EQ(4UL, request_log_.size()); | 98 ASSERT_EQ(4UL, request_log_.size()); |
| 78 EXPECT_EQ(kReloadTestPath, request_log_[0].relative_url); | 99 EXPECT_EQ(kReloadTestPath, request_log_[0].relative_url); |
| 79 EXPECT_EQ(kNoCacheControl, request_log_[0].cache_control); | 100 EXPECT_EQ(kNoCacheControl, request_log_[0].cache_control); |
| 80 EXPECT_EQ(kReloadImagePath, request_log_[1].relative_url); | 101 EXPECT_EQ(kReloadImagePath, request_log_[1].relative_url); |
| (...skipping 16 matching lines...) Expand all Loading... |
| 97 EXPECT_EQ(kNoCacheControl, request_log_[0].cache_control); | 118 EXPECT_EQ(kNoCacheControl, request_log_[0].cache_control); |
| 98 EXPECT_EQ(kReloadImagePath, request_log_[1].relative_url); | 119 EXPECT_EQ(kReloadImagePath, request_log_[1].relative_url); |
| 99 EXPECT_EQ(kNoCacheControl, request_log_[1].cache_control); | 120 EXPECT_EQ(kNoCacheControl, request_log_[1].cache_control); |
| 100 | 121 |
| 101 EXPECT_EQ(kReloadTestPath, request_log_[2].relative_url); | 122 EXPECT_EQ(kReloadTestPath, request_log_[2].relative_url); |
| 102 EXPECT_EQ(kNoCacheCacheControl, request_log_[2].cache_control); | 123 EXPECT_EQ(kNoCacheCacheControl, request_log_[2].cache_control); |
| 103 EXPECT_EQ(kReloadImagePath, request_log_[3].relative_url); | 124 EXPECT_EQ(kReloadImagePath, request_log_[3].relative_url); |
| 104 EXPECT_EQ(kNoCacheCacheControl, request_log_[3].cache_control); | 125 EXPECT_EQ(kNoCacheCacheControl, request_log_[3].cache_control); |
| 105 } | 126 } |
| 106 | 127 |
| 128 IN_PROC_BROWSER_TEST_F(ReloadCacheControlWithAnExperimentBrowserTest, |
| 129 ReloadMainResource) { |
| 130 GURL url(embedded_test_server()->GetURL(kReloadTestPath)); |
| 131 |
| 132 EXPECT_TRUE(NavigateToURL(shell(), url)); |
| 133 ReloadBlockUntilNavigationsComplete(shell(), 1); |
| 134 |
| 135 ASSERT_EQ(4UL, request_log_.size()); |
| 136 EXPECT_EQ(kReloadTestPath, request_log_[0].relative_url); |
| 137 EXPECT_EQ(kNoCacheControl, request_log_[0].cache_control); |
| 138 EXPECT_EQ(kReloadImagePath, request_log_[1].relative_url); |
| 139 EXPECT_EQ(kNoCacheControl, request_log_[1].cache_control); |
| 140 |
| 141 EXPECT_EQ(kReloadTestPath, request_log_[2].relative_url); |
| 142 EXPECT_EQ(kMaxAgeCacheControl, request_log_[2].cache_control); |
| 143 EXPECT_EQ(kReloadImagePath, request_log_[3].relative_url); |
| 144 EXPECT_EQ(kNoCacheControl, request_log_[3].cache_control); |
| 145 } |
| 146 |
| 147 // TODO(toyoshim): Add another set of reload tests with DevTools open. |
| 148 |
| 107 } // namespace | 149 } // namespace |
| 108 | 150 |
| 109 } // namespace content | 151 } // namespace content |
| OLD | NEW |