| 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), num_finished_(0) {} |
| 1212 |
| 1213 ~LoadFinishedObserver() override {} |
| 1214 |
| 1215 void DidStopLoading() override { |
| 1216 num_finished_++; |
| 1217 if (run_loop_.running()) |
| 1218 run_loop_.Quit(); |
| 1219 } |
| 1220 |
| 1221 void WaitForLoadToFinish() { |
| 1222 if (num_finished_ == 0) |
| 1223 run_loop_.Run(); |
| 1224 } |
| 1225 |
| 1226 private: |
| 1227 int num_finished_; |
| 1228 base::RunLoop run_loop_; |
| 1229 }; |
| 1230 |
| 1207 } // namespace | 1231 } // namespace |
| 1208 | 1232 |
| 1209 IN_PROC_BROWSER_TEST_F(DevToolsProtocolTest, PageStopLoading) { | 1233 IN_PROC_BROWSER_TEST_F(DevToolsProtocolTest, PageStopLoading) { |
| 1210 ASSERT_TRUE(embedded_test_server()->Start()); | 1234 ASSERT_TRUE(embedded_test_server()->Start()); |
| 1211 | 1235 |
| 1212 // Navigate to about:blank first so we can make sure there is a target page we | 1236 // 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 | 1237 // can attach to, and have Page.setControlNavigations complete before we start |
| 1214 // the navigations we're interested in. | 1238 // the navigations we're interested in. |
| 1215 NavigateToURLBlockUntilNavigationsComplete(shell(), GURL("about:blank"), 1); | 1239 NavigateToURLBlockUntilNavigationsComplete(shell(), GURL("about:blank"), 1); |
| 1216 Attach(); | 1240 Attach(); |
| 1217 | 1241 |
| 1218 std::unique_ptr<base::DictionaryValue> params(new base::DictionaryValue()); | 1242 std::unique_ptr<base::DictionaryValue> params(new base::DictionaryValue()); |
| 1219 params->SetBoolean("enabled", true); | 1243 params->SetBoolean("enabled", true); |
| 1220 SendCommand("Page.setControlNavigations", std::move(params), true); | 1244 SendCommand("Page.setControlNavigations", std::move(params), true); |
| 1221 | 1245 |
| 1222 NavigationFinishedObserver navigation_finished_observer( | 1246 LoadFinishedObserver load_finished_observer(shell()->web_contents()); |
| 1223 shell()->web_contents()); | |
| 1224 | 1247 |
| 1225 // The page will try to navigate twice, however since | 1248 // The page will try to navigate twice, however since |
| 1226 // Page.setControlNavigations is true, it'll wait for confirmation before | 1249 // Page.setControlNavigations is true, it'll wait for confirmation before |
| 1227 // committing to the navigation. | 1250 // committing to the navigation. |
| 1228 GURL test_url = embedded_test_server()->GetURL( | 1251 GURL test_url = embedded_test_server()->GetURL( |
| 1229 "/devtools/control_navigations/meta_tag.html"); | 1252 "/devtools/control_navigations/meta_tag.html"); |
| 1230 shell()->LoadURL(test_url); | 1253 shell()->LoadURL(test_url); |
| 1231 | 1254 |
| 1232 // Stop all navigations. | 1255 // Stop all navigations. |
| 1233 SendCommand("Page.stopLoading", nullptr); | 1256 SendCommand("Page.stopLoading", nullptr); |
| 1234 | 1257 |
| 1235 // Wait for the initial navigation to finish. | 1258 // Wait for the initial navigation to finish. |
| 1236 navigation_finished_observer.WaitForNavigationsToFinish(1); | 1259 load_finished_observer.WaitForLoadToFinish(); |
| 1237 } | 1260 } |
| 1238 | 1261 |
| 1239 IN_PROC_BROWSER_TEST_F(DevToolsProtocolTest, ControlNavigationsMainFrame) { | 1262 IN_PROC_BROWSER_TEST_F(DevToolsProtocolTest, ControlNavigationsMainFrame) { |
| 1240 ASSERT_TRUE(embedded_test_server()->Start()); | 1263 ASSERT_TRUE(embedded_test_server()->Start()); |
| 1241 | 1264 |
| 1242 // Navigate to about:blank first so we can make sure there is a target page we | 1265 // 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 | 1266 // can attach to, and have Page.setControlNavigations complete before we start |
| 1244 // the navigations we're interested in. | 1267 // the navigations we're interested in. |
| 1245 NavigateToURLBlockUntilNavigationsComplete(shell(), GURL("about:blank"), 1); | 1268 NavigateToURLBlockUntilNavigationsComplete(shell(), GURL("about:blank"), 1); |
| 1246 Attach(); | 1269 Attach(); |
| (...skipping 567 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1814 EXPECT_EQ("polyglottal", value); | 1837 EXPECT_EQ("polyglottal", value); |
| 1815 found++; | 1838 found++; |
| 1816 } else { | 1839 } else { |
| 1817 FAIL(); | 1840 FAIL(); |
| 1818 } | 1841 } |
| 1819 } | 1842 } |
| 1820 EXPECT_EQ(2u, found); | 1843 EXPECT_EQ(2u, found); |
| 1821 } | 1844 } |
| 1822 | 1845 |
| 1823 } // namespace content | 1846 } // namespace content |
| OLD | NEW |