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 1052 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1063 capturer.Wait(); | 1063 capturer.Wait(); |
1064 | 1064 |
1065 // The fact that there was a pending entry shouldn't interfere with the | 1065 // The fact that there was a pending entry shouldn't interfere with the |
1066 // classification. | 1066 // classification. |
1067 EXPECT_EQ(NAVIGATION_TYPE_IN_PAGE, capturer.details().type); | 1067 EXPECT_EQ(NAVIGATION_TYPE_IN_PAGE, capturer.details().type); |
1068 } | 1068 } |
1069 | 1069 |
1070 ResourceDispatcherHost::Get()->SetDelegate(nullptr); | 1070 ResourceDispatcherHost::Get()->SetDelegate(nullptr); |
1071 } | 1071 } |
1072 | 1072 |
| 1073 namespace { |
| 1074 |
| 1075 class FailureWatcher : public WebContentsObserver { |
| 1076 public: |
| 1077 // Observes failure for the specified |node|. |
| 1078 explicit FailureWatcher(FrameTreeNode* node) |
| 1079 : WebContentsObserver( |
| 1080 node->current_frame_host()->delegate()->GetAsWebContents()), |
| 1081 frame_tree_node_id_(node->frame_tree_node_id()), |
| 1082 message_loop_runner_(new MessageLoopRunner) {} |
| 1083 |
| 1084 void Wait() { |
| 1085 message_loop_runner_->Run(); |
| 1086 } |
| 1087 |
| 1088 private: |
| 1089 void DidFailLoad(RenderFrameHost* render_frame_host, |
| 1090 const GURL& validated_url, |
| 1091 int error_code, |
| 1092 const base::string16& error_description) override { |
| 1093 RenderFrameHostImpl* rfh = |
| 1094 static_cast<RenderFrameHostImpl*>(render_frame_host); |
| 1095 if (rfh->frame_tree_node()->frame_tree_node_id() != frame_tree_node_id_) |
| 1096 return; |
| 1097 |
| 1098 message_loop_runner_->Quit(); |
| 1099 } |
| 1100 |
| 1101 void DidFailProvisionalLoad( |
| 1102 RenderFrameHost* render_frame_host, |
| 1103 const GURL& validated_url, |
| 1104 int error_code, |
| 1105 const base::string16& error_description) override { |
| 1106 RenderFrameHostImpl* rfh = |
| 1107 static_cast<RenderFrameHostImpl*>(render_frame_host); |
| 1108 if (rfh->frame_tree_node()->frame_tree_node_id() != frame_tree_node_id_) |
| 1109 return; |
| 1110 |
| 1111 message_loop_runner_->Quit(); |
| 1112 } |
| 1113 |
| 1114 // The id of the FrameTreeNode whose navigations to observe. |
| 1115 int frame_tree_node_id_; |
| 1116 |
| 1117 // The MessageLoopRunner used to spin the message loop. |
| 1118 scoped_refptr<MessageLoopRunner> message_loop_runner_; |
| 1119 }; |
| 1120 |
| 1121 } // namespace |
| 1122 |
| 1123 IN_PROC_BROWSER_TEST_F(NavigationControllerBrowserTest, |
| 1124 StopCausesFailureDespiteJavaScriptURL) { |
| 1125 NavigationControllerImpl& controller = |
| 1126 static_cast<NavigationControllerImpl&>( |
| 1127 shell()->web_contents()->GetController()); |
| 1128 |
| 1129 FrameTreeNode* root = |
| 1130 static_cast<WebContentsImpl*>(shell()->web_contents())-> |
| 1131 GetFrameTree()->root(); |
| 1132 |
| 1133 // Start with a normal page. |
| 1134 GURL url1(embedded_test_server()->GetURL( |
| 1135 "/navigation_controller/simple_page_1.html")); |
| 1136 EXPECT_TRUE(NavigateToURL(shell(), url1)); |
| 1137 |
| 1138 // Have the user decide to go to a different page which is very slow. |
| 1139 StallDelegate stall_delegate; |
| 1140 ResourceDispatcherHost::Get()->SetDelegate(&stall_delegate); |
| 1141 GURL url2(embedded_test_server()->GetURL( |
| 1142 "/navigation_controller/simple_page_2.html")); |
| 1143 controller.LoadURL(url2, Referrer(), ui::PAGE_TRANSITION_LINK, std::string()); |
| 1144 |
| 1145 // That should be the pending entry. |
| 1146 NavigationEntryImpl* entry = controller.GetPendingEntry(); |
| 1147 ASSERT_NE(nullptr, entry); |
| 1148 EXPECT_EQ(url2, entry->GetURL()); |
| 1149 |
| 1150 // Loading a JavaScript URL shouldn't affect the ability to stop. |
| 1151 { |
| 1152 FailureWatcher watcher(root); |
| 1153 GURL js("javascript:(function(){})()"); |
| 1154 controller.LoadURL(js, Referrer(), ui::PAGE_TRANSITION_LINK, std::string()); |
| 1155 // This LoadURL ends up purging the pending entry, which is why this is |
| 1156 // tricky. |
| 1157 EXPECT_EQ(nullptr, controller.GetPendingEntry()); |
| 1158 shell()->web_contents()->Stop(); |
| 1159 watcher.Wait(); |
| 1160 } |
| 1161 |
| 1162 ResourceDispatcherHost::Get()->SetDelegate(nullptr); |
| 1163 } |
| 1164 |
1073 } // namespace content | 1165 } // namespace content |
OLD | NEW |