Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(208)

Side by Side Diff: content/browser/frame_host/navigation_controller_impl_browsertest.cc

Issue 1002803002: Classify navigations without page id in parallel to the existing classifier. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: intended Created 5 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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
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 LOG(ERROR) << "FailureWatcher::DidFailLoad";
Charlie Reis 2015/04/24 22:02:02 nit: Let's remove the LOG statements.
Avi (use Gerrit) 2015/04/24 22:17:15 Gah, part of my debugging via lots of log statemen
1094 RenderFrameHostImpl* rfh =
1095 static_cast<RenderFrameHostImpl*>(render_frame_host);
1096 if (rfh->frame_tree_node()->frame_tree_node_id() != frame_tree_node_id_)
1097 return;
1098
1099 message_loop_runner_->Quit();
1100 }
1101
1102 void DidFailProvisionalLoad(
1103 RenderFrameHost* render_frame_host,
1104 const GURL& validated_url,
1105 int error_code,
1106 const base::string16& error_description) override {
1107 LOG(ERROR) << "FailureWatcher::DidFailProvisionalLoad";
1108 RenderFrameHostImpl* rfh =
1109 static_cast<RenderFrameHostImpl*>(render_frame_host);
1110 if (rfh->frame_tree_node()->frame_tree_node_id() != frame_tree_node_id_)
1111 return;
1112
1113 message_loop_runner_->Quit();
1114 }
1115
1116 // The id of the FrameTreeNode whose navigations to observe.
1117 int frame_tree_node_id_;
1118
1119 // The MessageLoopRunner used to spin the message loop.
1120 scoped_refptr<MessageLoopRunner> message_loop_runner_;
1121 };
1122
1123 } // namespace
1124
1125 IN_PROC_BROWSER_TEST_F(NavigationControllerBrowserTest,
1126 StopCausesFailureDespiteJavaScriptURL) {
1127 NavigationControllerImpl& controller =
1128 static_cast<NavigationControllerImpl&>(
1129 shell()->web_contents()->GetController());
1130
1131 FrameTreeNode* root =
1132 static_cast<WebContentsImpl*>(shell()->web_contents())->
1133 GetFrameTree()->root();
1134
1135 // Start with a normal page.
1136 GURL url1(embedded_test_server()->GetURL(
1137 "/navigation_controller/simple_page_1.html"));
1138 EXPECT_TRUE(NavigateToURL(shell(), url1));
1139
1140 // Have the user decide to go to a different page which is very slow.
1141 StallDelegate stall_delegate;
1142 ResourceDispatcherHost::Get()->SetDelegate(&stall_delegate);
1143 GURL url2(embedded_test_server()->GetURL(
1144 "/navigation_controller/simple_page_2.html"));
1145 controller.LoadURL(url2, Referrer(), ui::PAGE_TRANSITION_LINK, std::string());
1146
1147 // That should be the pending entry.
1148 NavigationEntryImpl* entry = controller.GetPendingEntry();
1149 ASSERT_NE(nullptr, entry);
1150 EXPECT_EQ(url2, entry->GetURL());
1151
1152 // Loading a JavaScript URL shouldn't affect the ability to stop.
1153 {
1154 FailureWatcher watcher(root);
1155 GURL js("javascript:(function(){})()");
1156 controller.LoadURL(js, Referrer(), ui::PAGE_TRANSITION_LINK, std::string());
1157 shell()->web_contents()->Stop();
Charlie Reis 2015/04/24 22:02:02 Maybe we can add an EXPECT that the pending entry
Avi (use Gerrit) 2015/04/24 22:17:15 Done.
1158 watcher.Wait();
1159 }
1160
1161 ResourceDispatcherHost::Get()->SetDelegate(nullptr);
1162 }
1163
1073 } // namespace content 1164 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698