Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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 <stddef.h> | 5 #include <stddef.h> |
| 6 #include <utility> | 6 #include <utility> |
| 7 | 7 |
| 8 #include "base/base64.h" | 8 #include "base/base64.h" |
| 9 #include "base/bind.h" | 9 #include "base/bind.h" |
| 10 #include "base/bind_helpers.h" | 10 #include "base/bind_helpers.h" |
| (...skipping 1186 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1197 num_to_wait_for_ = num_to_wait_for; | 1197 num_to_wait_for_ = num_to_wait_for; |
| 1198 RunMessageLoop(); | 1198 RunMessageLoop(); |
| 1199 } | 1199 } |
| 1200 num_to_wait_for_ = 0; | 1200 num_to_wait_for_ = 0; |
| 1201 } | 1201 } |
| 1202 | 1202 |
| 1203 private: | 1203 private: |
| 1204 int num_finished_; | 1204 int num_finished_; |
| 1205 int num_to_wait_for_; | 1205 int num_to_wait_for_; |
| 1206 }; | 1206 }; |
| 1207 | |
| 1208 class LoadFinishedObserver : public content::WebContentsObserver { | |
| 1209 public: | |
| 1210 explicit LoadFinishedObserver(WebContents* web_contents) | |
| 1211 : WebContentsObserver(web_contents), | |
| 1212 num_finished_(0), | |
| 1213 num_to_wait_for_(0) {} | |
| 1214 | |
| 1215 ~LoadFinishedObserver() override {} | |
| 1216 | |
| 1217 void DidStopLoading() override { | |
| 1218 num_finished_++; | |
| 1219 if (num_finished_ >= num_to_wait_for_ && num_to_wait_for_ != 0) { | |
| 1220 base::MessageLoop::current()->QuitNow(); | |
| 1221 } | |
| 1222 } | |
| 1223 | |
| 1224 void WaitForLoadsToFinish(int num_to_wait_for) { | |
|
nasko
2017/05/24 14:20:03
nit: Arguably, there are no other callers other th
clamy
2017/05/24 18:34:38
Done.
| |
| 1225 if (num_finished_ < num_to_wait_for) { | |
| 1226 num_to_wait_for_ = num_to_wait_for; | |
| 1227 RunMessageLoop(); | |
| 1228 } | |
| 1229 num_to_wait_for_ = 0; | |
| 1230 } | |
| 1231 | |
| 1232 private: | |
| 1233 int num_finished_; | |
| 1234 int num_to_wait_for_; | |
| 1235 }; | |
| 1236 | |
| 1207 } // namespace | 1237 } // namespace |
| 1208 | 1238 |
| 1209 IN_PROC_BROWSER_TEST_F(DevToolsProtocolTest, PageStopLoading) { | 1239 IN_PROC_BROWSER_TEST_F(DevToolsProtocolTest, PageStopLoading) { |
| 1210 ASSERT_TRUE(embedded_test_server()->Start()); | 1240 ASSERT_TRUE(embedded_test_server()->Start()); |
| 1211 | 1241 |
| 1212 // Navigate to about:blank first so we can make sure there is a target page we | 1242 // Navigate to about:blank first so we can make sure there is a target page we |
| 1213 // can attach to, and have Page.setControlNavigations complete before we start | 1243 // can attach to, and have Page.setControlNavigations complete before we start |
| 1214 // the navigations we're interested in. | 1244 // the navigations we're interested in. |
| 1215 NavigateToURLBlockUntilNavigationsComplete(shell(), GURL("about:blank"), 1); | 1245 NavigateToURLBlockUntilNavigationsComplete(shell(), GURL("about:blank"), 1); |
| 1216 Attach(); | 1246 Attach(); |
| 1217 | 1247 |
| 1218 std::unique_ptr<base::DictionaryValue> params(new base::DictionaryValue()); | 1248 std::unique_ptr<base::DictionaryValue> params(new base::DictionaryValue()); |
| 1219 params->SetBoolean("enabled", true); | 1249 params->SetBoolean("enabled", true); |
| 1220 SendCommand("Page.setControlNavigations", std::move(params), true); | 1250 SendCommand("Page.setControlNavigations", std::move(params), true); |
| 1221 | 1251 |
| 1222 NavigationFinishedObserver navigation_finished_observer( | 1252 LoadFinishedObserver load_finished_observer(shell()->web_contents()); |
| 1223 shell()->web_contents()); | |
| 1224 | 1253 |
| 1225 // The page will try to navigate twice, however since | 1254 // The page will try to navigate twice, however since |
| 1226 // Page.setControlNavigations is true, it'll wait for confirmation before | 1255 // Page.setControlNavigations is true, it'll wait for confirmation before |
| 1227 // committing to the navigation. | 1256 // committing to the navigation. |
| 1228 GURL test_url = embedded_test_server()->GetURL( | 1257 GURL test_url = embedded_test_server()->GetURL( |
| 1229 "/devtools/control_navigations/meta_tag.html"); | 1258 "/devtools/control_navigations/meta_tag.html"); |
| 1230 shell()->LoadURL(test_url); | 1259 shell()->LoadURL(test_url); |
| 1231 | 1260 |
| 1232 // Stop all navigations. | 1261 // Stop all navigations. |
| 1233 SendCommand("Page.stopLoading", nullptr); | 1262 SendCommand("Page.stopLoading", nullptr); |
| 1234 | 1263 |
| 1235 // Wait for the initial navigation to finish. | 1264 // Wait for the initial navigation to finish. |
| 1236 navigation_finished_observer.WaitForNavigationsToFinish(1); | 1265 load_finished_observer.WaitForLoadsToFinish(1); |
| 1237 } | 1266 } |
| 1238 | 1267 |
| 1239 IN_PROC_BROWSER_TEST_F(DevToolsProtocolTest, ControlNavigationsMainFrame) { | 1268 IN_PROC_BROWSER_TEST_F(DevToolsProtocolTest, ControlNavigationsMainFrame) { |
| 1240 ASSERT_TRUE(embedded_test_server()->Start()); | 1269 ASSERT_TRUE(embedded_test_server()->Start()); |
| 1241 | 1270 |
| 1242 // Navigate to about:blank first so we can make sure there is a target page we | 1271 // Navigate to about:blank first so we can make sure there is a target page we |
| 1243 // can attach to, and have Page.setControlNavigations complete before we start | 1272 // can attach to, and have Page.setControlNavigations complete before we start |
| 1244 // the navigations we're interested in. | 1273 // the navigations we're interested in. |
| 1245 NavigateToURLBlockUntilNavigationsComplete(shell(), GURL("about:blank"), 1); | 1274 NavigateToURLBlockUntilNavigationsComplete(shell(), GURL("about:blank"), 1); |
| 1246 Attach(); | 1275 Attach(); |
| (...skipping 567 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1814 EXPECT_EQ("polyglottal", value); | 1843 EXPECT_EQ("polyglottal", value); |
| 1815 found++; | 1844 found++; |
| 1816 } else { | 1845 } else { |
| 1817 FAIL(); | 1846 FAIL(); |
| 1818 } | 1847 } |
| 1819 } | 1848 } |
| 1820 EXPECT_EQ(2u, found); | 1849 EXPECT_EQ(2u, found); |
| 1821 } | 1850 } |
| 1822 | 1851 |
| 1823 } // namespace content | 1852 } // namespace content |
| OLD | NEW |