Chromium Code Reviews| 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/strings/stringprintf.h" | 6 #include "base/strings/stringprintf.h" |
| 7 #include "content/browser/frame_host/frame_tree.h" | 7 #include "content/browser/frame_host/frame_tree.h" |
| 8 #include "content/browser/frame_host/navigation_controller_impl.h" | 8 #include "content/browser/frame_host/navigation_controller_impl.h" |
| 9 #include "content/browser/frame_host/navigation_entry_impl.h" | 9 #include "content/browser/frame_host/navigation_entry_impl.h" |
| 10 #include "content/browser/web_contents/web_contents_impl.h" | 10 #include "content/browser/web_contents/web_contents_impl.h" |
| (...skipping 199 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 210 // The params of the last navigation. | 210 // The params of the last navigation. |
| 211 FrameNavigateParams params_; | 211 FrameNavigateParams params_; |
| 212 | 212 |
| 213 // The details of the last navigation. | 213 // The details of the last navigation. |
| 214 LoadCommittedDetails details_; | 214 LoadCommittedDetails details_; |
| 215 | 215 |
| 216 // The MessageLoopRunner used to spin the message loop. | 216 // The MessageLoopRunner used to spin the message loop. |
| 217 scoped_refptr<MessageLoopRunner> message_loop_runner_; | 217 scoped_refptr<MessageLoopRunner> message_loop_runner_; |
| 218 }; | 218 }; |
| 219 | 219 |
| 220 struct LoadCommittedCapturer : public WebContentsObserver { | |
| 221 public: | |
| 222 explicit LoadCommittedCapturer(FrameTreeNode* node) | |
| 223 : WebContentsObserver( | |
| 224 node->current_frame_host()->delegate()->GetAsWebContents()), | |
| 225 frame_tree_node_id_(node->frame_tree_node_id()), | |
| 226 message_loop_runner_(new MessageLoopRunner) {} | |
| 227 | |
| 228 void Wait() { | |
| 229 message_loop_runner_->Run(); | |
| 230 } | |
| 231 | |
| 232 ui::PageTransition transition_type() const { | |
| 233 return transition_type_; | |
| 234 } | |
| 235 | |
| 236 private: | |
| 237 void DidCommitProvisionalLoadForFrame( | |
| 238 RenderFrameHost* render_frame_host, | |
| 239 const GURL& url, | |
| 240 ui::PageTransition transition_type) override { | |
| 241 RenderFrameHostImpl* rfh = | |
| 242 static_cast<RenderFrameHostImpl*>(render_frame_host); | |
| 243 if (rfh->frame_tree_node()->frame_tree_node_id() != frame_tree_node_id_) | |
| 244 return; | |
| 245 | |
| 246 transition_type_ = transition_type; | |
| 247 message_loop_runner_->Quit(); | |
| 248 } | |
| 249 | |
| 250 // The id of the FrameTreeNode whose navigations to observe. | |
| 251 int frame_tree_node_id_; | |
| 252 | |
| 253 // The transition_type of the last navigation. | |
| 254 ui::PageTransition transition_type_; | |
| 255 | |
| 256 // The MessageLoopRunner used to spin the message loop. | |
| 257 scoped_refptr<MessageLoopRunner> message_loop_runner_; | |
| 258 }; | |
| 259 | |
| 220 } // namespace | 260 } // namespace |
| 221 | 261 |
| 222 // Verify that the distinction between manual and auto subframes is properly set | 262 // Verify that the distinction between manual and auto subframes is properly set |
| 223 // for subframe navigations. TODO(avi): It's rather bogus that the same info is | 263 // for subframe navigations. TODO(avi): It's rather bogus that the same info is |
| 224 // in two different enums; http://crbug.com/453555. | 264 // in two different enums; http://crbug.com/453555. |
| 225 IN_PROC_BROWSER_TEST_F(NavigationControllerBrowserTest, | 265 IN_PROC_BROWSER_TEST_F(NavigationControllerBrowserTest, |
| 226 ManualAndAutoSubframeNavigationClassification) { | 266 ManualAndAutoSubframeNavigationClassification) { |
| 227 GURL main_url( | 267 GURL main_url(embedded_test_server()->GetURL( |
| 228 embedded_test_server()->GetURL("/frame_tree/page_with_one_frame.html")); | 268 "/navigation_controller/page_with_iframe.html")); |
| 229 NavigateToURL(shell(), main_url); | 269 NavigateToURL(shell(), main_url); |
| 230 | 270 |
| 231 // It is safe to obtain the root frame tree node here, as it doesn't change. | 271 // It is safe to obtain the root frame tree node here, as it doesn't change. |
| 232 FrameTreeNode* root = | 272 FrameTreeNode* root = |
| 233 static_cast<WebContentsImpl*>(shell()->web_contents())-> | 273 static_cast<WebContentsImpl*>(shell()->web_contents())-> |
| 234 GetFrameTree()->root(); | 274 GetFrameTree()->root(); |
| 235 | 275 |
| 236 ASSERT_EQ(1U, root->child_count()); | 276 ASSERT_EQ(1U, root->child_count()); |
| 237 ASSERT_NE(nullptr, root->child_at(0)); | 277 ASSERT_NE(nullptr, root->child_at(0)); |
| 238 | 278 |
| 239 { | 279 { |
| 240 // Navigate the iframe to a new URL; expect a manual subframe transition. | 280 // Navigate the iframe to a new URL; expect a manual subframe transition. |
| 241 FrameNavigateParamsCapturer capturer(root->child_at(0)); | 281 FrameNavigateParamsCapturer capturer(root->child_at(0)); |
| 242 GURL frame_url( | 282 GURL frame_url(embedded_test_server()->GetURL( |
| 243 embedded_test_server()->GetURL("/frame_tree/2-1.html")); | 283 "/navigation_controller/simple_page_1.html")); |
| 244 NavigateFrameToURL(root->child_at(0), frame_url); | 284 NavigateFrameToURL(root->child_at(0), frame_url); |
| 245 capturer.Wait(); | 285 capturer.Wait(); |
| 246 EXPECT_EQ(ui::PAGE_TRANSITION_MANUAL_SUBFRAME, | 286 EXPECT_EQ(ui::PAGE_TRANSITION_MANUAL_SUBFRAME, |
| 247 capturer.params().transition); | 287 capturer.params().transition); |
| 248 EXPECT_EQ(NAVIGATION_TYPE_NEW_SUBFRAME, capturer.details().type); | 288 EXPECT_EQ(NAVIGATION_TYPE_NEW_SUBFRAME, capturer.details().type); |
| 249 } | 289 } |
| 250 | 290 |
| 251 { | 291 { |
| 252 // History navigations should result in an auto subframe transition. | 292 // Do a history navigation; expect an auto subframe transition. |
| 253 FrameNavigateParamsCapturer capturer(root->child_at(0)); | 293 FrameNavigateParamsCapturer capturer(root->child_at(0)); |
| 254 shell()->web_contents()->GetController().GoBack(); | 294 shell()->web_contents()->GetController().GoBack(); |
| 255 capturer.Wait(); | 295 capturer.Wait(); |
| 256 EXPECT_EQ(ui::PAGE_TRANSITION_AUTO_SUBFRAME, capturer.params().transition); | 296 EXPECT_EQ(ui::PAGE_TRANSITION_AUTO_SUBFRAME, capturer.params().transition); |
| 257 EXPECT_EQ(NAVIGATION_TYPE_AUTO_SUBFRAME, capturer.details().type); | 297 EXPECT_EQ(NAVIGATION_TYPE_AUTO_SUBFRAME, capturer.details().type); |
| 258 } | 298 } |
| 259 | 299 |
| 260 { | 300 { |
| 261 // History navigations should result in an auto subframe transition. | 301 // Do a history navigation; expect an auto subframe transition. |
| 262 FrameNavigateParamsCapturer capturer(root->child_at(0)); | 302 FrameNavigateParamsCapturer capturer(root->child_at(0)); |
| 263 shell()->web_contents()->GetController().GoForward(); | 303 shell()->web_contents()->GetController().GoForward(); |
| 264 capturer.Wait(); | 304 capturer.Wait(); |
| 265 EXPECT_EQ(ui::PAGE_TRANSITION_AUTO_SUBFRAME, capturer.params().transition); | 305 EXPECT_EQ(ui::PAGE_TRANSITION_AUTO_SUBFRAME, capturer.params().transition); |
| 266 EXPECT_EQ(NAVIGATION_TYPE_AUTO_SUBFRAME, capturer.details().type); | 306 EXPECT_EQ(NAVIGATION_TYPE_AUTO_SUBFRAME, capturer.details().type); |
| 267 } | 307 } |
| 268 | 308 |
| 269 { | 309 { |
| 270 // Navigate the iframe to a new URL; expect a manual subframe transition. | 310 // Navigate the iframe to a new URL; expect a manual subframe transition. |
| 271 FrameNavigateParamsCapturer capturer(root->child_at(0)); | 311 FrameNavigateParamsCapturer capturer(root->child_at(0)); |
| 272 GURL frame_url( | 312 GURL frame_url(embedded_test_server()->GetURL( |
| 273 embedded_test_server()->GetURL("/frame_tree/2-3.html")); | 313 "/navigation_controller/simple_page_2.html")); |
| 274 NavigateFrameToURL(root->child_at(0), frame_url); | 314 NavigateFrameToURL(root->child_at(0), frame_url); |
| 275 capturer.Wait(); | 315 capturer.Wait(); |
| 276 EXPECT_EQ(ui::PAGE_TRANSITION_MANUAL_SUBFRAME, | 316 EXPECT_EQ(ui::PAGE_TRANSITION_MANUAL_SUBFRAME, |
| 277 capturer.params().transition); | 317 capturer.params().transition); |
| 278 EXPECT_EQ(NAVIGATION_TYPE_NEW_SUBFRAME, capturer.details().type); | 318 EXPECT_EQ(NAVIGATION_TYPE_NEW_SUBFRAME, capturer.details().type); |
| 279 } | 319 } |
| 320 | |
| 321 { | |
| 322 // Reload the subframe; expect an auto subframe transition. (Reloads aren't | |
| 323 // "navigation" so we only see the frame load committing.) | |
| 324 LoadCommittedCapturer capturer(root->child_at(0)); | |
| 325 EXPECT_TRUE(content::ExecuteScript(root->child_at(0)->current_frame_host(), | |
| 326 "location.reload()")); | |
| 327 capturer.Wait(); | |
| 328 EXPECT_EQ(ui::PAGE_TRANSITION_AUTO_SUBFRAME, capturer.transition_type()); | |
| 329 } | |
|
Charlie Reis
2015/02/18 17:57:37
We should add a case for location.replace in the s
Avi (use Gerrit)
2015/02/18 18:33:12
More tests are always awesome. Let me try to make
| |
| 280 } | 330 } |
| 281 | 331 |
| 282 } // namespace content | 332 } // namespace content |
| OLD | NEW |