| Index: content/browser/loader/reload_cache_control_browsertest.cc
|
| diff --git a/content/browser/loader/reload_cache_control_browsertest.cc b/content/browser/loader/reload_cache_control_browsertest.cc
|
| index 5affe6942b66386a7170ea7ad9dda39711ed3f09..93288ac72326334ac774d86dd69e704372e76a3d 100644
|
| --- a/content/browser/loader/reload_cache_control_browsertest.cc
|
| +++ b/content/browser/loader/reload_cache_control_browsertest.cc
|
| @@ -3,9 +3,15 @@
|
| // found in the LICENSE file.
|
|
|
| #include <memory>
|
| +#include <string>
|
| +#include <vector>
|
|
|
| #include "base/bind.h"
|
| #include "base/bind_helpers.h"
|
| +#include "base/command_line.h"
|
| +#include "base/macros.h"
|
| +#include "base/synchronization/lock.h"
|
| +#include "content/public/common/content_switches.h"
|
| #include "content/public/test/content_browser_test.h"
|
| #include "content/public/test/content_browser_test_utils.h"
|
| #include "content/shell/browser/shell.h"
|
| @@ -34,6 +40,7 @@ struct RequestLog {
|
| std::string cache_control;
|
| };
|
|
|
| +// Tests end to end behaviors between Blink and content around reload variants.
|
| class ReloadCacheControlBrowserTest : public ContentBrowserTest {
|
| protected:
|
| ReloadCacheControlBrowserTest() {}
|
| @@ -57,6 +64,7 @@ class ReloadCacheControlBrowserTest : public ContentBrowserTest {
|
|
|
| protected:
|
| std::vector<RequestLog> request_log_;
|
| + base::Lock request_log_lock_;
|
|
|
| private:
|
| void MonitorRequestHandler(const HttpRequest& request) {
|
| @@ -66,6 +74,7 @@ class ReloadCacheControlBrowserTest : public ContentBrowserTest {
|
| log.cache_control = cache_control == request.headers.end()
|
| ? kNoCacheControl
|
| : cache_control->second;
|
| + base::AutoLock lock(request_log_lock_);
|
| request_log_.push_back(log);
|
| }
|
|
|
| @@ -78,16 +87,43 @@ IN_PROC_BROWSER_TEST_F(ReloadCacheControlBrowserTest, NormalReload) {
|
| EXPECT_TRUE(NavigateToURL(shell(), url));
|
| ReloadBlockUntilNavigationsComplete(shell(), 1);
|
|
|
| - ASSERT_EQ(4UL, request_log_.size());
|
| - EXPECT_EQ(kReloadTestPath, request_log_[0].relative_url);
|
| - EXPECT_EQ(kNoCacheControl, request_log_[0].cache_control);
|
| - EXPECT_EQ(kReloadImagePath, request_log_[1].relative_url);
|
| - EXPECT_EQ(kNoCacheControl, request_log_[1].cache_control);
|
| + {
|
| + base::AutoLock lock(request_log_lock_);
|
| + ASSERT_EQ(4UL, request_log_.size());
|
| + EXPECT_EQ(kReloadTestPath, request_log_[0].relative_url);
|
| + EXPECT_EQ(kNoCacheControl, request_log_[0].cache_control);
|
| + EXPECT_EQ(kReloadImagePath, request_log_[1].relative_url);
|
| + EXPECT_EQ(kNoCacheControl, request_log_[1].cache_control);
|
| +
|
| + EXPECT_EQ(kReloadTestPath, request_log_[2].relative_url);
|
| + EXPECT_EQ(kMaxAgeCacheControl, request_log_[2].cache_control);
|
| + EXPECT_EQ(kReloadImagePath, request_log_[3].relative_url);
|
| + EXPECT_EQ(kNoCacheControl, request_log_[3].cache_control);
|
| + }
|
| +
|
| + shell()->ShowDevTools();
|
| + ReloadBlockUntilNavigationsComplete(shell(), 1);
|
| +
|
| + {
|
| + base::AutoLock lock(request_log_lock_);
|
| + ASSERT_EQ(6UL, request_log_.size());
|
| + EXPECT_EQ(kReloadTestPath, request_log_[4].relative_url);
|
| + EXPECT_EQ(kMaxAgeCacheControl, request_log_[4].cache_control);
|
| + EXPECT_EQ(kReloadImagePath, request_log_[5].relative_url);
|
| + EXPECT_EQ(kNoCacheControl, request_log_[5].cache_control);
|
| + }
|
|
|
| - EXPECT_EQ(kReloadTestPath, request_log_[2].relative_url);
|
| - EXPECT_EQ(kMaxAgeCacheControl, request_log_[2].cache_control);
|
| - EXPECT_EQ(kReloadImagePath, request_log_[3].relative_url);
|
| - EXPECT_EQ(kNoCacheControl, request_log_[3].cache_control);
|
| + shell()->CloseDevTools();
|
| + ReloadBlockUntilNavigationsComplete(shell(), 1);
|
| +
|
| + {
|
| + base::AutoLock lock(request_log_lock_);
|
| + ASSERT_EQ(8UL, request_log_.size());
|
| + EXPECT_EQ(kReloadTestPath, request_log_[6].relative_url);
|
| + EXPECT_EQ(kMaxAgeCacheControl, request_log_[6].cache_control);
|
| + EXPECT_EQ(kReloadImagePath, request_log_[7].relative_url);
|
| + EXPECT_EQ(kNoCacheControl, request_log_[7].cache_control);
|
| + }
|
| }
|
|
|
| IN_PROC_BROWSER_TEST_F(ReloadCacheControlBrowserTest, BypassingReload) {
|
| @@ -96,19 +132,102 @@ IN_PROC_BROWSER_TEST_F(ReloadCacheControlBrowserTest, BypassingReload) {
|
| EXPECT_TRUE(NavigateToURL(shell(), url));
|
| ReloadBypassingCacheBlockUntilNavigationsComplete(shell(), 1);
|
|
|
| - ASSERT_EQ(4UL, request_log_.size());
|
| - EXPECT_EQ(kReloadTestPath, request_log_[0].relative_url);
|
| - EXPECT_EQ(kNoCacheControl, request_log_[0].cache_control);
|
| - EXPECT_EQ(kReloadImagePath, request_log_[1].relative_url);
|
| - EXPECT_EQ(kNoCacheControl, request_log_[1].cache_control);
|
| + {
|
| + base::AutoLock lock(request_log_lock_);
|
| + ASSERT_EQ(4UL, request_log_.size());
|
| + EXPECT_EQ(kReloadTestPath, request_log_[0].relative_url);
|
| + EXPECT_EQ(kNoCacheControl, request_log_[0].cache_control);
|
| + EXPECT_EQ(kReloadImagePath, request_log_[1].relative_url);
|
| + EXPECT_EQ(kNoCacheControl, request_log_[1].cache_control);
|
| +
|
| + EXPECT_EQ(kReloadTestPath, request_log_[2].relative_url);
|
| + EXPECT_EQ(kNoCacheCacheControl, request_log_[2].cache_control);
|
| + EXPECT_EQ(kReloadImagePath, request_log_[3].relative_url);
|
| + EXPECT_EQ(kNoCacheCacheControl, request_log_[3].cache_control);
|
| + }
|
|
|
| - EXPECT_EQ(kReloadTestPath, request_log_[2].relative_url);
|
| - EXPECT_EQ(kNoCacheCacheControl, request_log_[2].cache_control);
|
| - EXPECT_EQ(kReloadImagePath, request_log_[3].relative_url);
|
| - EXPECT_EQ(kNoCacheCacheControl, request_log_[3].cache_control);
|
| + shell()->ShowDevTools();
|
| + ReloadBypassingCacheBlockUntilNavigationsComplete(shell(), 1);
|
| +
|
| + {
|
| + base::AutoLock lock(request_log_lock_);
|
| + ASSERT_EQ(6UL, request_log_.size());
|
| + EXPECT_EQ(kReloadTestPath, request_log_[4].relative_url);
|
| + EXPECT_EQ(kNoCacheCacheControl, request_log_[4].cache_control);
|
| + EXPECT_EQ(kReloadImagePath, request_log_[5].relative_url);
|
| + EXPECT_EQ(kNoCacheCacheControl, request_log_[5].cache_control);
|
| + }
|
| +
|
| + shell()->CloseDevTools();
|
| + ReloadBypassingCacheBlockUntilNavigationsComplete(shell(), 1);
|
| +
|
| + {
|
| + base::AutoLock lock(request_log_lock_);
|
| + ASSERT_EQ(8UL, request_log_.size());
|
| + EXPECT_EQ(kReloadTestPath, request_log_[6].relative_url);
|
| + EXPECT_EQ(kNoCacheCacheControl, request_log_[6].cache_control);
|
| + EXPECT_EQ(kReloadImagePath, request_log_[7].relative_url);
|
| + EXPECT_EQ(kNoCacheCacheControl, request_log_[7].cache_control);
|
| + }
|
| }
|
|
|
| -// TODO(toyoshim): Add another set of reload tests with DevTools open.
|
| +IN_PROC_BROWSER_TEST_F(ReloadCacheControlBrowserTest, NavigateToSame) {
|
| + GURL url(embedded_test_server()->GetURL(kReloadTestPath));
|
| +
|
| + EXPECT_TRUE(NavigateToURL(shell(), url));
|
| + EXPECT_TRUE(NavigateToURL(shell(), url));
|
| +
|
| + // The first navigation is just a normal load.
|
| + {
|
| + base::AutoLock lock(request_log_lock_);
|
| + ASSERT_EQ(4UL, request_log_.size());
|
| + EXPECT_EQ(kReloadTestPath, request_log_[0].relative_url);
|
| + EXPECT_EQ(kNoCacheControl, request_log_[0].cache_control);
|
| + EXPECT_EQ(kReloadImagePath, request_log_[1].relative_url);
|
| + EXPECT_EQ(kNoCacheControl, request_log_[1].cache_control);
|
| + }
|
| +
|
| + // TODO(crbug.com/671545): This test does not work correctly if browser-side
|
| + // navigation is enabled.
|
| + if (base::CommandLine::ForCurrentProcess()->HasSwitch(
|
| + switches::kEnableBrowserSideNavigation))
|
| + return;
|
| +
|
| + // The second navigation is the same page navigation. This should be handled
|
| + // as a reload, revalidating the main resource, but following cache protocols
|
| + // for others.
|
| + {
|
| + base::AutoLock lock(request_log_lock_);
|
| + EXPECT_EQ(kReloadTestPath, request_log_[2].relative_url);
|
| + EXPECT_EQ(kMaxAgeCacheControl, request_log_[2].cache_control);
|
| + EXPECT_EQ(kReloadImagePath, request_log_[3].relative_url);
|
| + EXPECT_EQ(kNoCacheControl, request_log_[3].cache_control);
|
| + }
|
| +
|
| + shell()->ShowDevTools();
|
| + EXPECT_TRUE(NavigateToURL(shell(), url));
|
| +
|
| + {
|
| + base::AutoLock lock(request_log_lock_);
|
| + ASSERT_EQ(6UL, request_log_.size());
|
| + EXPECT_EQ(kReloadTestPath, request_log_[4].relative_url);
|
| + EXPECT_EQ(kMaxAgeCacheControl, request_log_[4].cache_control);
|
| + EXPECT_EQ(kReloadImagePath, request_log_[5].relative_url);
|
| + EXPECT_EQ(kNoCacheControl, request_log_[5].cache_control);
|
| + }
|
| +
|
| + shell()->CloseDevTools();
|
| + EXPECT_TRUE(NavigateToURL(shell(), url));
|
| +
|
| + {
|
| + base::AutoLock lock(request_log_lock_);
|
| + ASSERT_EQ(8UL, request_log_.size());
|
| + EXPECT_EQ(kReloadTestPath, request_log_[6].relative_url);
|
| + EXPECT_EQ(kMaxAgeCacheControl, request_log_[6].cache_control);
|
| + EXPECT_EQ(kReloadImagePath, request_log_[7].relative_url);
|
| + EXPECT_EQ(kNoCacheControl, request_log_[7].cache_control);
|
| + }
|
| +}
|
|
|
| } // namespace
|
|
|
|
|