Chromium Code Reviews| 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 "content/public/test/content_browser_test.h" | 9 #include "content/public/test/content_browser_test.h" |
| 10 #include "content/public/test/content_browser_test_utils.h" | 10 #include "content/public/test/content_browser_test_utils.h" |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 49 // Because the handler is registered as the first handler, MonitorHandler | 49 // Because the handler is registered as the first handler, MonitorHandler |
| 50 // is needed to capture all requests. | 50 // is needed to capture all requests. |
| 51 embedded_test_server()->RegisterRequestMonitor(base::Bind( | 51 embedded_test_server()->RegisterRequestMonitor(base::Bind( |
| 52 &ReloadCacheControlBrowserTest::MonitorRequestHandler, | 52 &ReloadCacheControlBrowserTest::MonitorRequestHandler, |
| 53 base::Unretained(this))); | 53 base::Unretained(this))); |
| 54 | 54 |
| 55 ASSERT_TRUE(embedded_test_server()->Start()); | 55 ASSERT_TRUE(embedded_test_server()->Start()); |
| 56 } | 56 } |
| 57 | 57 |
| 58 protected: | 58 protected: |
| 59 std::vector<RequestLog> request_log_; | 59 std::vector<RequestLog> request_log_; |
|
mmenke
2016/12/02 20:16:49
While you're here, mind including string and vecto
Takashi Toyoshima
2016/12/05 06:39:13
Done.
| |
| 60 | 60 |
| 61 private: | 61 private: |
| 62 void MonitorRequestHandler(const HttpRequest& request) { | 62 void MonitorRequestHandler(const HttpRequest& request) { |
| 63 RequestLog log; | 63 RequestLog log; |
| 64 log.relative_url = request.relative_url; | 64 log.relative_url = request.relative_url; |
| 65 auto cache_control = request.headers.find("Cache-Control"); | 65 auto cache_control = request.headers.find("Cache-Control"); |
| 66 log.cache_control = cache_control == request.headers.end() | 66 log.cache_control = cache_control == request.headers.end() |
| 67 ? kNoCacheControl | 67 ? kNoCacheControl |
| 68 : cache_control->second; | 68 : cache_control->second; |
| 69 request_log_.push_back(log); | 69 request_log_.push_back(log); |
| 70 } | 70 } |
| 71 | 71 |
| 72 DISALLOW_COPY_AND_ASSIGN(ReloadCacheControlBrowserTest); | 72 DISALLOW_COPY_AND_ASSIGN(ReloadCacheControlBrowserTest); |
|
mmenke
2016/12/02 20:16:49
And macros.h
Takashi Toyoshima
2016/12/05 06:39:13
Done.
| |
| 73 }; | 73 }; |
| 74 | 74 |
| 75 IN_PROC_BROWSER_TEST_F(ReloadCacheControlBrowserTest, NormalReload) { | 75 IN_PROC_BROWSER_TEST_F(ReloadCacheControlBrowserTest, NormalReload) { |
| 76 GURL url(embedded_test_server()->GetURL(kReloadTestPath)); | 76 GURL url(embedded_test_server()->GetURL(kReloadTestPath)); |
| 77 | 77 |
| 78 EXPECT_TRUE(NavigateToURL(shell(), url)); | 78 EXPECT_TRUE(NavigateToURL(shell(), url)); |
| 79 ReloadBlockUntilNavigationsComplete(shell(), 1); | 79 ReloadBlockUntilNavigationsComplete(shell(), 1); |
| 80 | 80 |
| 81 ASSERT_EQ(4UL, request_log_.size()); | 81 ASSERT_EQ(4UL, request_log_.size()); |
| 82 EXPECT_EQ(kReloadTestPath, request_log_[0].relative_url); | 82 EXPECT_EQ(kReloadTestPath, request_log_[0].relative_url); |
| 83 EXPECT_EQ(kNoCacheControl, request_log_[0].cache_control); | 83 EXPECT_EQ(kNoCacheControl, request_log_[0].cache_control); |
| 84 EXPECT_EQ(kReloadImagePath, request_log_[1].relative_url); | 84 EXPECT_EQ(kReloadImagePath, request_log_[1].relative_url); |
| 85 EXPECT_EQ(kNoCacheControl, request_log_[1].cache_control); | 85 EXPECT_EQ(kNoCacheControl, request_log_[1].cache_control); |
| 86 | 86 |
| 87 EXPECT_EQ(kReloadTestPath, request_log_[2].relative_url); | 87 EXPECT_EQ(kReloadTestPath, request_log_[2].relative_url); |
| 88 EXPECT_EQ(kMaxAgeCacheControl, request_log_[2].cache_control); | 88 EXPECT_EQ(kMaxAgeCacheControl, request_log_[2].cache_control); |
| 89 EXPECT_EQ(kReloadImagePath, request_log_[3].relative_url); | 89 EXPECT_EQ(kReloadImagePath, request_log_[3].relative_url); |
| 90 EXPECT_EQ(kNoCacheControl, request_log_[3].cache_control); | 90 EXPECT_EQ(kNoCacheControl, request_log_[3].cache_control); |
|
mmenke
2016/12/02 20:16:49
These tests don't seem to be threadsafe - there's
Takashi Toyoshima
2016/12/05 06:39:13
Thanks. I introduced request_log_lock_.
| |
| 91 | |
| 92 shell()->ShowDevTools(); | |
| 93 ReloadBlockUntilNavigationsComplete(shell(), 1); | |
| 94 | |
| 95 ASSERT_EQ(6UL, request_log_.size()); | |
| 96 EXPECT_EQ(kReloadTestPath, request_log_[4].relative_url); | |
| 97 EXPECT_EQ(kMaxAgeCacheControl, request_log_[4].cache_control); | |
| 98 EXPECT_EQ(kReloadImagePath, request_log_[5].relative_url); | |
| 99 EXPECT_EQ(kNoCacheControl, request_log_[5].cache_control); | |
| 100 | |
| 101 shell()->CloseDevTools(); | |
| 102 ReloadBlockUntilNavigationsComplete(shell(), 1); | |
| 103 | |
| 104 ASSERT_EQ(8UL, request_log_.size()); | |
| 105 EXPECT_EQ(kReloadTestPath, request_log_[6].relative_url); | |
| 106 EXPECT_EQ(kMaxAgeCacheControl, request_log_[6].cache_control); | |
| 107 EXPECT_EQ(kReloadImagePath, request_log_[7].relative_url); | |
| 108 EXPECT_EQ(kNoCacheControl, request_log_[7].cache_control); | |
| 91 } | 109 } |
| 92 | 110 |
| 93 IN_PROC_BROWSER_TEST_F(ReloadCacheControlBrowserTest, BypassingReload) { | 111 IN_PROC_BROWSER_TEST_F(ReloadCacheControlBrowserTest, BypassingReload) { |
| 94 GURL url(embedded_test_server()->GetURL(kReloadTestPath)); | 112 GURL url(embedded_test_server()->GetURL(kReloadTestPath)); |
| 95 | 113 |
| 96 EXPECT_TRUE(NavigateToURL(shell(), url)); | 114 EXPECT_TRUE(NavigateToURL(shell(), url)); |
| 97 ReloadBypassingCacheBlockUntilNavigationsComplete(shell(), 1); | 115 ReloadBypassingCacheBlockUntilNavigationsComplete(shell(), 1); |
| 98 | 116 |
| 99 ASSERT_EQ(4UL, request_log_.size()); | 117 ASSERT_EQ(4UL, request_log_.size()); |
| 100 EXPECT_EQ(kReloadTestPath, request_log_[0].relative_url); | 118 EXPECT_EQ(kReloadTestPath, request_log_[0].relative_url); |
| 101 EXPECT_EQ(kNoCacheControl, request_log_[0].cache_control); | 119 EXPECT_EQ(kNoCacheControl, request_log_[0].cache_control); |
| 102 EXPECT_EQ(kReloadImagePath, request_log_[1].relative_url); | 120 EXPECT_EQ(kReloadImagePath, request_log_[1].relative_url); |
| 103 EXPECT_EQ(kNoCacheControl, request_log_[1].cache_control); | 121 EXPECT_EQ(kNoCacheControl, request_log_[1].cache_control); |
| 104 | 122 |
| 105 EXPECT_EQ(kReloadTestPath, request_log_[2].relative_url); | 123 EXPECT_EQ(kReloadTestPath, request_log_[2].relative_url); |
| 106 EXPECT_EQ(kNoCacheCacheControl, request_log_[2].cache_control); | 124 EXPECT_EQ(kNoCacheCacheControl, request_log_[2].cache_control); |
| 107 EXPECT_EQ(kReloadImagePath, request_log_[3].relative_url); | 125 EXPECT_EQ(kReloadImagePath, request_log_[3].relative_url); |
| 108 EXPECT_EQ(kNoCacheCacheControl, request_log_[3].cache_control); | 126 EXPECT_EQ(kNoCacheCacheControl, request_log_[3].cache_control); |
| 127 | |
| 128 shell()->ShowDevTools(); | |
| 129 ReloadBypassingCacheBlockUntilNavigationsComplete(shell(), 1); | |
| 130 | |
| 131 ASSERT_EQ(6UL, request_log_.size()); | |
| 132 EXPECT_EQ(kReloadTestPath, request_log_[4].relative_url); | |
| 133 EXPECT_EQ(kNoCacheCacheControl, request_log_[4].cache_control); | |
| 134 EXPECT_EQ(kReloadImagePath, request_log_[5].relative_url); | |
| 135 EXPECT_EQ(kNoCacheCacheControl, request_log_[5].cache_control); | |
| 136 | |
| 137 shell()->CloseDevTools(); | |
| 138 ReloadBypassingCacheBlockUntilNavigationsComplete(shell(), 1); | |
| 139 | |
| 140 ASSERT_EQ(8UL, request_log_.size()); | |
| 141 EXPECT_EQ(kReloadTestPath, request_log_[6].relative_url); | |
| 142 EXPECT_EQ(kNoCacheCacheControl, request_log_[6].cache_control); | |
| 143 EXPECT_EQ(kReloadImagePath, request_log_[7].relative_url); | |
| 144 EXPECT_EQ(kNoCacheCacheControl, request_log_[7].cache_control); | |
| 109 } | 145 } |
| 110 | 146 |
| 111 // TODO(toyoshim): Add another set of reload tests with DevTools open. | 147 IN_PROC_BROWSER_TEST_F(ReloadCacheControlBrowserTest, NavigateToSame) { |
| 148 GURL url(embedded_test_server()->GetURL(kReloadTestPath)); | |
| 149 | |
| 150 EXPECT_TRUE(NavigateToURL(shell(), url)); | |
| 151 EXPECT_TRUE(NavigateToURL(shell(), url)); | |
| 152 | |
| 153 ASSERT_EQ(4UL, request_log_.size()); | |
| 154 | |
| 155 // The first navigation is just a normal load. | |
| 156 EXPECT_EQ(kReloadTestPath, request_log_[0].relative_url); | |
| 157 EXPECT_EQ(kNoCacheControl, request_log_[0].cache_control); | |
| 158 EXPECT_EQ(kReloadImagePath, request_log_[1].relative_url); | |
| 159 EXPECT_EQ(kNoCacheControl, request_log_[1].cache_control); | |
|
mmenke
2016/12/02 20:16:49
I assume we have plenty of tests for has navigatio
Takashi Toyoshima
2016/12/05 06:39:13
Yes, PlzNavigate team have many navigation related
| |
| 160 | |
| 161 // The second navigation is the same page navigation. This should be handled | |
| 162 // as a reload, revalidating the main resource, but following cache protocols | |
| 163 // for others. | |
| 164 EXPECT_EQ(kReloadTestPath, request_log_[2].relative_url); | |
| 165 EXPECT_EQ(kMaxAgeCacheControl, request_log_[2].cache_control); | |
| 166 EXPECT_EQ(kReloadImagePath, request_log_[3].relative_url); | |
| 167 EXPECT_EQ(kNoCacheControl, request_log_[3].cache_control); | |
| 168 | |
| 169 shell()->ShowDevTools(); | |
| 170 EXPECT_TRUE(NavigateToURL(shell(), url)); | |
| 171 | |
| 172 ASSERT_EQ(6UL, request_log_.size()); | |
| 173 EXPECT_EQ(kReloadTestPath, request_log_[4].relative_url); | |
| 174 EXPECT_EQ(kMaxAgeCacheControl, request_log_[4].cache_control); | |
| 175 EXPECT_EQ(kReloadImagePath, request_log_[5].relative_url); | |
| 176 EXPECT_EQ(kNoCacheControl, request_log_[5].cache_control); | |
| 177 | |
| 178 shell()->CloseDevTools(); | |
| 179 EXPECT_TRUE(NavigateToURL(shell(), url)); | |
| 180 | |
| 181 ASSERT_EQ(8UL, request_log_.size()); | |
| 182 EXPECT_EQ(kReloadTestPath, request_log_[6].relative_url); | |
| 183 EXPECT_EQ(kMaxAgeCacheControl, request_log_[6].cache_control); | |
| 184 EXPECT_EQ(kReloadImagePath, request_log_[7].relative_url); | |
| 185 EXPECT_EQ(kNoCacheControl, request_log_[7].cache_control); | |
| 186 } | |
| 112 | 187 |
| 113 } // namespace | 188 } // namespace |
| 114 | 189 |
| 115 } // namespace content | 190 } // namespace content |
| OLD | NEW |