| OLD | NEW |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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> | 6 #include <string> |
| 7 #include <utility> | 7 #include <utility> |
| 8 | 8 |
| 9 #include "base/bind.h" | 9 #include "base/bind.h" |
| 10 #include "base/bind_helpers.h" | 10 #include "base/bind_helpers.h" |
| 11 #include "base/feature_list.h" | |
| 12 #include "base/macros.h" | 11 #include "base/macros.h" |
| 13 #include "base/run_loop.h" | 12 #include "base/run_loop.h" |
| 14 #include "base/strings/string16.h" | 13 #include "base/strings/string16.h" |
| 15 #include "base/strings/string_piece.h" | 14 #include "base/strings/string_piece.h" |
| 16 #include "base/strings/stringprintf.h" | 15 #include "base/strings/stringprintf.h" |
| 17 #include "base/strings/utf_string_conversions.h" | 16 #include "base/strings/utf_string_conversions.h" |
| 17 #include "base/test/scoped_feature_list.h" |
| 18 #include "content/public/common/browser_side_navigation_policy.h" | 18 #include "content/public/common/browser_side_navigation_policy.h" |
| 19 #include "content/public/common/content_features.h" |
| 19 #include "content/public/test/browser_test_utils.h" | 20 #include "content/public/test/browser_test_utils.h" |
| 20 #include "content/public/test/content_browser_test.h" | 21 #include "content/public/test/content_browser_test.h" |
| 21 #include "content/public/test/content_browser_test_utils.h" | 22 #include "content/public/test/content_browser_test_utils.h" |
| 22 #include "content/shell/browser/shell.h" | 23 #include "content/shell/browser/shell.h" |
| 23 #include "net/test/embedded_test_server/embedded_test_server.h" | 24 #include "net/test/embedded_test_server/embedded_test_server.h" |
| 24 #include "net/test/embedded_test_server/http_request.h" | 25 #include "net/test/embedded_test_server/http_request.h" |
| 25 #include "net/test/embedded_test_server/http_response.h" | 26 #include "net/test/embedded_test_server/http_response.h" |
| 26 #include "testing/gtest/include/gtest/gtest.h" | 27 #include "testing/gtest/include/gtest/gtest.h" |
| 27 #include "url/gurl.h" | 28 #include "url/gurl.h" |
| 28 | 29 |
| 29 namespace content { | 30 namespace content { |
| 30 | 31 |
| 31 namespace { | 32 namespace { |
| 32 | 33 |
| 33 using net::test_server::HttpResponse; | 34 using net::test_server::HttpResponse; |
| 34 using net::test_server::HttpRequest; | 35 using net::test_server::HttpRequest; |
| 35 using net::test_server::BasicHttpResponse; | 36 using net::test_server::BasicHttpResponse; |
| 36 | 37 |
| 37 const char kCountedHtmlPath[] = "/counted.html"; | 38 const char kCountedHtmlPath[] = "/counted.html"; |
| 38 const char kCookieHtmlPath[] = "/cookie.html"; | 39 const char kCookieHtmlPath[] = "/cookie.html"; |
| 39 | 40 |
| 40 class AsyncRevalidationManagerBrowserTest : public ContentBrowserTest { | 41 class AsyncRevalidationManagerBrowserTest : public ContentBrowserTest { |
| 41 protected: | 42 protected: |
| 42 AsyncRevalidationManagerBrowserTest() {} | 43 AsyncRevalidationManagerBrowserTest() {} |
| 43 ~AsyncRevalidationManagerBrowserTest() override {} | 44 ~AsyncRevalidationManagerBrowserTest() override {} |
| 44 | 45 |
| 45 void SetUp() override { | 46 void SetUp() override { |
| 46 base::FeatureList::ClearInstanceForTesting(); | 47 scoped_feature_list_.InitAndEnableFeature(features::kStaleWhileRevalidate); |
| 47 std::unique_ptr<base::FeatureList> feature_list(new base::FeatureList); | |
| 48 feature_list->InitializeFromCommandLine( | |
| 49 "StaleWhileRevalidate2", std::string()); | |
| 50 base::FeatureList::SetInstance(std::move(feature_list)); | |
| 51 | 48 |
| 52 ASSERT_TRUE(embedded_test_server()->InitializeAndListen()); | 49 ASSERT_TRUE(embedded_test_server()->InitializeAndListen()); |
| 53 ContentBrowserTest::SetUp(); | 50 ContentBrowserTest::SetUp(); |
| 54 } | 51 } |
| 55 | 52 |
| 56 void SetUpOnMainThread() override { | 53 void SetUpOnMainThread() override { |
| 57 embedded_test_server()->StartAcceptingConnections(); | 54 embedded_test_server()->StartAcceptingConnections(); |
| 58 } | 55 } |
| 59 | 56 |
| 60 base::RunLoop* run_loop() { return &run_loop_; } | 57 base::RunLoop* run_loop() { return &run_loop_; } |
| (...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 144 // A validator is needed for revalidations, and hence | 141 // A validator is needed for revalidations, and hence |
| 145 // stale-while-revalidate, to work. | 142 // stale-while-revalidate, to work. |
| 146 std::string etag = base::StringPrintf( | 143 std::string etag = base::StringPrintf( |
| 147 "\"AsyncRevalidationManagerBrowserTest%d\"", requests_counted_); | 144 "\"AsyncRevalidationManagerBrowserTest%d\"", requests_counted_); |
| 148 http_response->AddCustomHeader("ETag", etag); | 145 http_response->AddCustomHeader("ETag", etag); |
| 149 return http_response; | 146 return http_response; |
| 150 } | 147 } |
| 151 | 148 |
| 152 base::RunLoop run_loop_; | 149 base::RunLoop run_loop_; |
| 153 int requests_counted_ = 0; | 150 int requests_counted_ = 0; |
| 151 base::test::ScopedFeatureList scoped_feature_list_; |
| 154 | 152 |
| 155 DISALLOW_COPY_AND_ASSIGN(AsyncRevalidationManagerBrowserTest); | 153 DISALLOW_COPY_AND_ASSIGN(AsyncRevalidationManagerBrowserTest); |
| 156 }; | 154 }; |
| 157 | 155 |
| 158 // Verify that the "Cache-Control: stale-while-revalidate" directive correctly | 156 // Verify that the "Cache-Control: stale-while-revalidate" directive correctly |
| 159 // triggers an async revalidation. | 157 // triggers an async revalidation. |
| 160 IN_PROC_BROWSER_TEST_F(AsyncRevalidationManagerBrowserTest, | 158 IN_PROC_BROWSER_TEST_F(AsyncRevalidationManagerBrowserTest, |
| 161 StaleWhileRevalidateIsApplied) { | 159 StaleWhileRevalidateIsApplied) { |
| 162 // PlzNavigate: Stale while revalidate is disabled. | 160 // PlzNavigate: Stale while revalidate is disabled. |
| 163 // TODO(clamy): Re-enable the test when there is support. | 161 // TODO(clamy): Re-enable the test when there is support. |
| (...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 232 NavigateToURL(shell(), GURL("about:blank")); | 230 NavigateToURL(shell(), GURL("about:blank")); |
| 233 | 231 |
| 234 // The page will load from the cache, then when the async revalidation | 232 // The page will load from the cache, then when the async revalidation |
| 235 // completes the cookie will update. | 233 // completes the cookie will update. |
| 236 EXPECT_TRUE(TitleBecomes(url, "PASS")); | 234 EXPECT_TRUE(TitleBecomes(url, "PASS")); |
| 237 } | 235 } |
| 238 | 236 |
| 239 } // namespace | 237 } // namespace |
| 240 | 238 |
| 241 } // namespace content | 239 } // namespace content |
| OLD | NEW |