OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 "base/bind.h" | 5 #include "base/bind.h" |
6 #include "base/command_line.h" | 6 #include "base/command_line.h" |
7 #include "base/strings/stringprintf.h" | 7 #include "base/strings/stringprintf.h" |
8 #include "content/browser/frame_host/frame_navigation_entry.h" | 8 #include "content/browser/frame_host/frame_navigation_entry.h" |
9 #include "content/browser/frame_host/frame_tree.h" | 9 #include "content/browser/frame_host/frame_tree.h" |
10 #include "content/browser/frame_host/navigation_controller_impl.h" | 10 #include "content/browser/frame_host/navigation_controller_impl.h" |
(...skipping 1189 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1200 forward_load_observer.Wait(); | 1200 forward_load_observer.Wait(); |
1201 | 1201 |
1202 // Make sure the URL is correct for both the entry and the main frame, and | 1202 // Make sure the URL is correct for both the entry and the main frame, and |
1203 // that the process hasn't been killed for showing a spoof. | 1203 // that the process hasn't been killed for showing a spoof. |
1204 EXPECT_TRUE(root->current_frame_host()->IsRenderFrameLive()); | 1204 EXPECT_TRUE(root->current_frame_host()->IsRenderFrameLive()); |
1205 EXPECT_EQ(url3, shell()->web_contents()->GetLastCommittedURL()); | 1205 EXPECT_EQ(url3, shell()->web_contents()->GetLastCommittedURL()); |
1206 EXPECT_EQ(url3, root->current_url()); | 1206 EXPECT_EQ(url3, root->current_url()); |
1207 } | 1207 } |
1208 } | 1208 } |
1209 | 1209 |
1210 namespace { | |
1211 | |
1212 class FailureWatcher : public WebContentsObserver { | |
1213 public: | |
1214 // Observes failure for the specified |node|. | |
1215 explicit FailureWatcher(FrameTreeNode* node) | |
1216 : WebContentsObserver( | |
1217 node->current_frame_host()->delegate()->GetAsWebContents()), | |
1218 frame_tree_node_id_(node->frame_tree_node_id()), | |
1219 message_loop_runner_(new MessageLoopRunner) {} | |
1220 | |
1221 void Wait() { | |
1222 message_loop_runner_->Run(); | |
1223 } | |
1224 | |
1225 private: | |
1226 void DidFailLoad(RenderFrameHost* render_frame_host, | |
1227 const GURL& validated_url, | |
1228 int error_code, | |
1229 const base::string16& error_description) override { | |
1230 RenderFrameHostImpl* rfh = | |
1231 static_cast<RenderFrameHostImpl*>(render_frame_host); | |
1232 if (rfh->frame_tree_node()->frame_tree_node_id() != frame_tree_node_id_) | |
1233 return; | |
1234 | |
1235 message_loop_runner_->Quit(); | |
1236 } | |
1237 | |
1238 void DidFailProvisionalLoad( | |
1239 RenderFrameHost* render_frame_host, | |
1240 const GURL& validated_url, | |
1241 int error_code, | |
1242 const base::string16& error_description) override { | |
1243 RenderFrameHostImpl* rfh = | |
1244 static_cast<RenderFrameHostImpl*>(render_frame_host); | |
1245 if (rfh->frame_tree_node()->frame_tree_node_id() != frame_tree_node_id_) | |
1246 return; | |
1247 | |
1248 message_loop_runner_->Quit(); | |
1249 } | |
1250 | |
1251 // The id of the FrameTreeNode whose navigations to observe. | |
1252 int frame_tree_node_id_; | |
1253 | |
1254 // The MessageLoopRunner used to spin the message loop. | |
1255 scoped_refptr<MessageLoopRunner> message_loop_runner_; | |
1256 }; | |
1257 | |
1258 } // namespace | |
1259 | |
1260 IN_PROC_BROWSER_TEST_F(NavigationControllerBrowserTest, | |
1261 StopCausesFailureDespiteJavaScriptURL) { | |
1262 NavigationControllerImpl& controller = | |
1263 static_cast<NavigationControllerImpl&>( | |
1264 shell()->web_contents()->GetController()); | |
1265 | |
1266 FrameTreeNode* root = | |
1267 static_cast<WebContentsImpl*>(shell()->web_contents())-> | |
1268 GetFrameTree()->root(); | |
1269 | |
1270 // Start with a normal page. | |
1271 GURL url1(embedded_test_server()->GetURL( | |
1272 "/navigation_controller/simple_page_1.html")); | |
1273 EXPECT_TRUE(NavigateToURL(shell(), url1)); | |
1274 | |
1275 // Have the user decide to go to a different page which is very slow. | |
1276 StallDelegate stall_delegate; | |
1277 ResourceDispatcherHost::Get()->SetDelegate(&stall_delegate); | |
1278 GURL url2(embedded_test_server()->GetURL( | |
1279 "/navigation_controller/simple_page_2.html")); | |
1280 controller.LoadURL(url2, Referrer(), ui::PAGE_TRANSITION_LINK, std::string()); | |
1281 | |
1282 // That should be the pending entry. | |
1283 NavigationEntryImpl* entry = controller.GetPendingEntry(); | |
1284 ASSERT_NE(nullptr, entry); | |
1285 EXPECT_EQ(url2, entry->GetURL()); | |
1286 | |
1287 // Loading a JavaScript URL shouldn't affect the ability to stop. | |
1288 { | |
1289 FailureWatcher watcher(root); | |
1290 GURL js("javascript:(function(){})()"); | |
1291 controller.LoadURL(js, Referrer(), ui::PAGE_TRANSITION_LINK, std::string()); | |
1292 // This LoadURL ends up purging the pending entry, which is why this is | |
1293 // tricky. | |
1294 EXPECT_EQ(nullptr, controller.GetPendingEntry()); | |
1295 shell()->web_contents()->Stop(); | |
1296 watcher.Wait(); | |
1297 } | |
1298 | |
1299 ResourceDispatcherHost::Get()->SetDelegate(nullptr); | |
1300 } | |
1301 | |
1302 } // namespace content | 1210 } // namespace content |
OLD | NEW |