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 140 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 151 EXPECT_TRUE(NavigateToURL(shell(), web_ui_page)); | 151 EXPECT_TRUE(NavigateToURL(shell(), web_ui_page)); |
| 152 EXPECT_EQ(BINDINGS_POLICY_WEB_UI, | 152 EXPECT_EQ(BINDINGS_POLICY_WEB_UI, |
| 153 shell()->web_contents()->GetRenderViewHost()->GetEnabledBindings()); | 153 shell()->web_contents()->GetRenderViewHost()->GetEnabledBindings()); |
| 154 | 154 |
| 155 ShellAddedObserver observer; | 155 ShellAddedObserver observer; |
| 156 std::string page_url = embedded_test_server()->GetURL( | 156 std::string page_url = embedded_test_server()->GetURL( |
| 157 "/navigation_controller/simple_page_1.html").spec(); | 157 "/navigation_controller/simple_page_1.html").spec(); |
| 158 EXPECT_TRUE(ExecuteScript(shell()->web_contents(), | 158 EXPECT_TRUE(ExecuteScript(shell()->web_contents(), |
| 159 "window.open('" + page_url + "', '_blank')")); | 159 "window.open('" + page_url + "', '_blank')")); |
| 160 Shell* shell2 = observer.GetShell(); | 160 Shell* shell2 = observer.GetShell(); |
| 161 WaitForLoadStop(shell2->web_contents()); | 161 EXPECT_TRUE(WaitForLoadStop(shell2->web_contents())); |
| 162 | 162 |
| 163 EXPECT_EQ(1, shell2->web_contents()->GetController().GetEntryCount()); | 163 EXPECT_EQ(1, shell2->web_contents()->GetController().GetEntryCount()); |
| 164 EXPECT_EQ(1, RendererHistoryLength(shell2)); | 164 EXPECT_EQ(1, RendererHistoryLength(shell2)); |
| 165 | 165 |
| 166 // Again, as above, there's no way to access the renderer's notion of the | 166 // Again, as above, there's no way to access the renderer's notion of the |
| 167 // history offset via JavaScript. Checking just the history length, again, | 167 // history offset via JavaScript. Checking just the history length, again, |
| 168 // will have to suffice. | 168 // will have to suffice. |
| 169 } | 169 } |
| 170 | 170 |
| 171 namespace { | 171 namespace { |
| 172 | 172 |
| 173 struct FrameNavigateParamsCapturer : public WebContentsObserver { | 173 class FrameNavigateParamsCapturer : public WebContentsObserver { |
| 174 public: | 174 public: |
| 175 // Observes navigation for the specified |node|. | 175 // Observes navigation for the specified |node|. |
| 176 explicit FrameNavigateParamsCapturer(FrameTreeNode* node) | 176 explicit FrameNavigateParamsCapturer(FrameTreeNode* node) |
| 177 : WebContentsObserver( | 177 : WebContentsObserver( |
| 178 node->current_frame_host()->delegate()->GetAsWebContents()), | 178 node->current_frame_host()->delegate()->GetAsWebContents()), |
| 179 frame_tree_node_id_(node->frame_tree_node_id()), | 179 frame_tree_node_id_(node->frame_tree_node_id()), |
| 180 message_loop_runner_(new MessageLoopRunner) {} | 180 message_loop_runner_(new MessageLoopRunner) {} |
| 181 | 181 |
| 182 void Wait() { | 182 void Wait() { |
| 183 message_loop_runner_->Run(); | 183 message_loop_runner_->Run(); |
| (...skipping 11 matching lines...) Expand all Loading... | |
| 195 void DidNavigateAnyFrame(RenderFrameHost* render_frame_host, | 195 void DidNavigateAnyFrame(RenderFrameHost* render_frame_host, |
| 196 const LoadCommittedDetails& details, | 196 const LoadCommittedDetails& details, |
| 197 const FrameNavigateParams& params) override { | 197 const FrameNavigateParams& params) override { |
| 198 RenderFrameHostImpl* rfh = | 198 RenderFrameHostImpl* rfh = |
| 199 static_cast<RenderFrameHostImpl*>(render_frame_host); | 199 static_cast<RenderFrameHostImpl*>(render_frame_host); |
| 200 if (rfh->frame_tree_node()->frame_tree_node_id() != frame_tree_node_id_) | 200 if (rfh->frame_tree_node()->frame_tree_node_id() != frame_tree_node_id_) |
| 201 return; | 201 return; |
| 202 | 202 |
| 203 params_ = params; | 203 params_ = params; |
| 204 details_ = details; | 204 details_ = details; |
| 205 if (!web_contents()->IsLoading()) | |
| 206 message_loop_runner_->Quit(); | |
| 207 } | |
| 208 | |
| 209 void DidStopLoading(RenderViewHost* render_view_host) override { | |
| 205 message_loop_runner_->Quit(); | 210 message_loop_runner_->Quit(); |
| 206 } | 211 } |
| 207 | 212 |
| 208 // The id of the FrameTreeNode whose navigations to observe. | 213 // The id of the FrameTreeNode whose navigations to observe. |
| 209 int frame_tree_node_id_; | 214 int frame_tree_node_id_; |
| 210 | 215 |
| 211 // The params of the last navigation. | 216 // The params of the last navigation. |
| 212 FrameNavigateParams params_; | 217 FrameNavigateParams params_; |
| 213 | 218 |
| 214 // The details of the last navigation. | 219 // The details of the last navigation. |
| 215 LoadCommittedDetails details_; | 220 LoadCommittedDetails details_; |
| 216 | 221 |
| 217 // The MessageLoopRunner used to spin the message loop. | 222 // The MessageLoopRunner used to spin the message loop. |
| 218 scoped_refptr<MessageLoopRunner> message_loop_runner_; | 223 scoped_refptr<MessageLoopRunner> message_loop_runner_; |
| 219 }; | 224 }; |
| 220 | 225 |
| 221 struct LoadCommittedCapturer : public WebContentsObserver { | 226 class LoadCommittedCapturer : public WebContentsObserver { |
| 222 public: | 227 public: |
| 223 // Observes the load commit for the specified |node|. | 228 // Observes the load commit for the specified |node|. |
| 224 explicit LoadCommittedCapturer(FrameTreeNode* node) | 229 explicit LoadCommittedCapturer(FrameTreeNode* node) |
| 225 : WebContentsObserver( | 230 : WebContentsObserver( |
| 226 node->current_frame_host()->delegate()->GetAsWebContents()), | 231 node->current_frame_host()->delegate()->GetAsWebContents()), |
| 227 frame_tree_node_id_(node->frame_tree_node_id()), | 232 frame_tree_node_id_(node->frame_tree_node_id()), |
| 228 message_loop_runner_(new MessageLoopRunner) {} | 233 message_loop_runner_(new MessageLoopRunner) {} |
| 229 | 234 |
| 230 // Observes the load commit for the next created frame in the specified | 235 // Observes the load commit for the next created frame in the specified |
| 231 // |web_contents|. | 236 // |web_contents|. |
| (...skipping 24 matching lines...) Expand all Loading... | |
| 256 RenderFrameHost* render_frame_host, | 261 RenderFrameHost* render_frame_host, |
| 257 const GURL& url, | 262 const GURL& url, |
| 258 ui::PageTransition transition_type) override { | 263 ui::PageTransition transition_type) override { |
| 259 DCHECK_NE(0, frame_tree_node_id_); | 264 DCHECK_NE(0, frame_tree_node_id_); |
| 260 RenderFrameHostImpl* rfh = | 265 RenderFrameHostImpl* rfh = |
| 261 static_cast<RenderFrameHostImpl*>(render_frame_host); | 266 static_cast<RenderFrameHostImpl*>(render_frame_host); |
| 262 if (rfh->frame_tree_node()->frame_tree_node_id() != frame_tree_node_id_) | 267 if (rfh->frame_tree_node()->frame_tree_node_id() != frame_tree_node_id_) |
| 263 return; | 268 return; |
| 264 | 269 |
| 265 transition_type_ = transition_type; | 270 transition_type_ = transition_type; |
| 271 if (!web_contents()->IsLoading()) | |
| 272 message_loop_runner_->Quit(); | |
| 273 } | |
| 274 | |
| 275 void DidStopLoading(RenderViewHost* render_view_host) override { | |
| 266 message_loop_runner_->Quit(); | 276 message_loop_runner_->Quit(); |
| 267 } | 277 } |
| 268 | 278 |
| 269 // The id of the FrameTreeNode whose navigations to observe. | 279 // The id of the FrameTreeNode whose navigations to observe. |
| 270 int frame_tree_node_id_; | 280 int frame_tree_node_id_; |
| 271 | 281 |
| 272 // The transition_type of the last navigation. | 282 // The transition_type of the last navigation. |
| 273 ui::PageTransition transition_type_; | 283 ui::PageTransition transition_type_; |
| 274 | 284 |
| 275 // The MessageLoopRunner used to spin the message loop. | 285 // The MessageLoopRunner used to spin the message loop. |
| 276 scoped_refptr<MessageLoopRunner> message_loop_runner_; | 286 scoped_refptr<MessageLoopRunner> message_loop_runner_; |
| 277 }; | 287 }; |
| 278 | 288 |
| 279 } // namespace | 289 } // namespace |
| 280 | 290 |
| 281 // Verify that the distinction between manual and auto subframes is properly set | 291 // Various tests for navigation type classifications. TODO(avi): It's rather |
| 282 // for subframe navigations. TODO(avi): It's rather bogus that the same info is | 292 // bogus that the same info is in two different enums; http://crbug.com/453555. |
| 283 // in two different enums; http://crbug.com/453555. | 293 |
| 294 // Verify that navigations for NAVIGATION_TYPE_NEW_PAGE are correctly | |
| 295 // classified. | |
| 296 IN_PROC_BROWSER_TEST_F(NavigationControllerBrowserTest, | |
| 297 NavigationTypeClassification_NewPage) { | |
| 298 NavigateToURL(shell(), GURL("about:blank")); | |
| 299 | |
| 300 FrameTreeNode* root = | |
| 301 static_cast<WebContentsImpl*>(shell()->web_contents())-> | |
| 302 GetFrameTree()->root(); | |
| 303 | |
| 304 { | |
| 305 // Simple load. | |
| 306 FrameNavigateParamsCapturer capturer(root); | |
| 307 GURL frame_url(embedded_test_server()->GetURL( | |
| 308 "/navigation_controller/page_with_links.html")); | |
| 309 NavigateFrameToURL(root, frame_url); | |
| 310 capturer.Wait(); | |
| 311 // TODO(avi,creis): Why is this (and quite a few others below) a "link" | |
| 312 // transition? Lots of these transitions should be cleaned up. | |
| 313 EXPECT_EQ(ui::PAGE_TRANSITION_LINK, capturer.params().transition); | |
| 314 EXPECT_EQ(NAVIGATION_TYPE_NEW_PAGE, capturer.details().type); | |
| 315 } | |
| 316 | |
| 317 { | |
| 318 // Load via a fragment link click. | |
| 319 FrameNavigateParamsCapturer capturer(root); | |
| 320 std::string script = "document.getElementById('fraglink').click()"; | |
| 321 EXPECT_TRUE(content::ExecuteScript(root->current_frame_host(), script)); | |
| 322 capturer.Wait(); | |
| 323 EXPECT_EQ(ui::PAGE_TRANSITION_LINK, capturer.params().transition); | |
| 324 // TODO(avi,creis): Why is this not NAVIGATION_TYPE_IN_PAGE? It makes sense | |
|
Charlie Reis
2015/03/09 20:39:58
Yes, I think we'll probably accept the current beh
Avi (use Gerrit)
2015/03/09 21:35:56
Acknowledged.
| |
| 325 // if NEW_PAGE means "new NavEntry". | |
| 326 EXPECT_EQ(NAVIGATION_TYPE_NEW_PAGE, capturer.details().type); | |
| 327 } | |
| 328 | |
| 329 { | |
| 330 // Load via link click. | |
| 331 FrameNavigateParamsCapturer capturer(root); | |
| 332 std::string script = "document.getElementById('thelink').click()"; | |
| 333 EXPECT_TRUE(content::ExecuteScript(root->current_frame_host(), script)); | |
| 334 capturer.Wait(); | |
| 335 EXPECT_EQ(ui::PAGE_TRANSITION_LINK, capturer.params().transition); | |
| 336 EXPECT_EQ(NAVIGATION_TYPE_NEW_PAGE, capturer.details().type); | |
| 337 } | |
| 338 | |
| 339 { | |
| 340 // location.assign(). | |
| 341 FrameNavigateParamsCapturer capturer(root); | |
| 342 GURL frame_url(embedded_test_server()->GetURL( | |
| 343 "/navigation_controller/simple_page_2.html")); | |
| 344 std::string script = "location.assign('" + frame_url.spec() + "')"; | |
| 345 EXPECT_TRUE(content::ExecuteScript(root->current_frame_host(), script)); | |
| 346 capturer.Wait(); | |
| 347 EXPECT_EQ(ui::PAGE_TRANSITION_LINK | ui::PAGE_TRANSITION_CLIENT_REDIRECT, | |
|
Charlie Reis
2015/03/09 20:39:58
This gets treated as a client redirect? I'm somew
Avi (use Gerrit)
2015/03/09 21:35:56
I don't know what their intention is. It might be
Charlie Reis
2015/03/09 22:04:05
Agreed. (I also don't know the answer to line 311
| |
| 348 capturer.params().transition); | |
| 349 EXPECT_EQ(NAVIGATION_TYPE_NEW_PAGE, capturer.details().type); | |
| 350 } | |
| 351 | |
| 352 { | |
| 353 // history.pushState(). | |
| 354 FrameNavigateParamsCapturer capturer(root); | |
| 355 std::string script = | |
| 356 "history.pushState({}, 'page 1', 'simple_page_1.html')"; | |
| 357 EXPECT_TRUE(content::ExecuteScript(root->current_frame_host(), script)); | |
| 358 capturer.Wait(); | |
| 359 EXPECT_EQ(ui::PAGE_TRANSITION_LINK | ui::PAGE_TRANSITION_CLIENT_REDIRECT, | |
| 360 capturer.params().transition); | |
| 361 EXPECT_EQ(NAVIGATION_TYPE_NEW_PAGE, capturer.details().type); | |
| 362 } | |
| 363 } | |
| 364 | |
| 365 // Verify that navigations for NAVIGATION_TYPE_EXISTING_PAGE are correctly | |
| 366 // classified. | |
| 367 IN_PROC_BROWSER_TEST_F(NavigationControllerBrowserTest, | |
| 368 NavigationTypeClassification_ExistingPage) { | |
| 369 GURL url1(embedded_test_server()->GetURL( | |
| 370 "/navigation_controller/simple_page_1.html")); | |
| 371 NavigateToURL(shell(), url1); | |
| 372 GURL url2(embedded_test_server()->GetURL( | |
| 373 "/navigation_controller/simple_page_2.html")); | |
| 374 NavigateToURL(shell(), url2); | |
| 375 | |
| 376 FrameTreeNode* root = | |
| 377 static_cast<WebContentsImpl*>(shell()->web_contents())-> | |
| 378 GetFrameTree()->root(); | |
| 379 | |
| 380 { | |
| 381 // Back. | |
| 382 FrameNavigateParamsCapturer capturer(root); | |
| 383 shell()->web_contents()->GetController().GoBack(); | |
| 384 capturer.Wait(); | |
| 385 EXPECT_EQ(ui::PAGE_TRANSITION_TYPED | |
| 386 | ui::PAGE_TRANSITION_FORWARD_BACK | |
| 387 | ui::PAGE_TRANSITION_FROM_ADDRESS_BAR, | |
| 388 capturer.params().transition); | |
| 389 EXPECT_EQ(NAVIGATION_TYPE_EXISTING_PAGE, capturer.details().type); | |
| 390 } | |
| 391 | |
| 392 { | |
| 393 // Forward. | |
| 394 FrameNavigateParamsCapturer capturer(root); | |
| 395 shell()->web_contents()->GetController().GoForward(); | |
| 396 capturer.Wait(); | |
| 397 EXPECT_EQ(ui::PAGE_TRANSITION_TYPED | |
| 398 | ui::PAGE_TRANSITION_FORWARD_BACK | |
| 399 | ui::PAGE_TRANSITION_FROM_ADDRESS_BAR, | |
| 400 capturer.params().transition); | |
| 401 EXPECT_EQ(NAVIGATION_TYPE_EXISTING_PAGE, capturer.details().type); | |
| 402 } | |
| 403 | |
| 404 { | |
| 405 // Reload. | |
|
Charlie Reis
2015/03/09 20:39:58
Can we also test a browser-initiated reload? I wo
Avi (use Gerrit)
2015/03/09 21:35:56
Done.
Also, haha it's PAGE_TRANSITION_RELOAD, whi
| |
| 406 FrameNavigateParamsCapturer capturer(root); | |
| 407 EXPECT_TRUE(content::ExecuteScript(root->current_frame_host(), | |
| 408 "location.reload()")); | |
| 409 capturer.Wait(); | |
| 410 EXPECT_EQ(ui::PAGE_TRANSITION_LINK | ui::PAGE_TRANSITION_CLIENT_REDIRECT, | |
|
Charlie Reis
2015/03/09 20:39:58
Wow, this is a client redirect too? I guess that
Avi (use Gerrit)
2015/03/09 21:35:56
Again, it's not clear how intentional this is.
| |
| 411 capturer.params().transition); | |
| 412 EXPECT_EQ(NAVIGATION_TYPE_EXISTING_PAGE, capturer.details().type); | |
| 413 } | |
| 414 | |
| 415 { | |
| 416 // location.replace(). | |
| 417 FrameNavigateParamsCapturer capturer(root); | |
| 418 GURL frame_url(embedded_test_server()->GetURL( | |
| 419 "/navigation_controller/simple_page_1.html")); | |
| 420 std::string script = "location.replace('" + frame_url.spec() + "')"; | |
| 421 EXPECT_TRUE(content::ExecuteScript(root->current_frame_host(), script)); | |
| 422 capturer.Wait(); | |
| 423 EXPECT_EQ(ui::PAGE_TRANSITION_LINK | ui::PAGE_TRANSITION_CLIENT_REDIRECT, | |
| 424 capturer.params().transition); | |
| 425 EXPECT_EQ(NAVIGATION_TYPE_EXISTING_PAGE, capturer.details().type); | |
| 426 } | |
| 427 } | |
| 428 | |
| 429 // Verify that navigations for NAVIGATION_TYPE_SAME_PAGE are correctly | |
| 430 // classified. | |
| 431 IN_PROC_BROWSER_TEST_F(NavigationControllerBrowserTest, | |
| 432 NavigationTypeClassification_SamePage) { | |
| 433 GURL url1(embedded_test_server()->GetURL( | |
| 434 "/navigation_controller/simple_page_1.html")); | |
| 435 NavigateToURL(shell(), url1); | |
| 436 | |
| 437 FrameTreeNode* root = | |
| 438 static_cast<WebContentsImpl*>(shell()->web_contents())-> | |
| 439 GetFrameTree()->root(); | |
| 440 | |
| 441 { | |
| 442 // Simple load. | |
| 443 FrameNavigateParamsCapturer capturer(root); | |
| 444 GURL frame_url(embedded_test_server()->GetURL( | |
| 445 "/navigation_controller/simple_page_1.html")); | |
| 446 NavigateFrameToURL(root, frame_url); | |
| 447 capturer.Wait(); | |
| 448 EXPECT_EQ(ui::PAGE_TRANSITION_LINK, capturer.params().transition); | |
| 449 EXPECT_EQ(NAVIGATION_TYPE_SAME_PAGE, capturer.details().type); | |
| 450 } | |
| 451 } | |
| 452 | |
| 453 // Verify that navigations for NAVIGATION_TYPE_IN_PAGE are correctly | |
| 454 // classified. | |
| 455 IN_PROC_BROWSER_TEST_F(NavigationControllerBrowserTest, | |
| 456 NavigationTypeClassification_InPage) { | |
| 457 GURL url1(embedded_test_server()->GetURL( | |
| 458 "/navigation_controller/simple_page_1.html")); | |
| 459 NavigateToURL(shell(), url1); | |
| 460 | |
| 461 FrameTreeNode* root = | |
| 462 static_cast<WebContentsImpl*>(shell()->web_contents())-> | |
| 463 GetFrameTree()->root(); | |
| 464 | |
| 465 { | |
| 466 // history.replaceState(). | |
| 467 FrameNavigateParamsCapturer capturer(root); | |
| 468 std::string script = | |
| 469 "history.replaceState({}, 'page 1', 'simple_page_2.html')"; | |
| 470 EXPECT_TRUE(content::ExecuteScript(root->current_frame_host(), script)); | |
| 471 capturer.Wait(); | |
| 472 EXPECT_EQ(ui::PAGE_TRANSITION_LINK, capturer.params().transition); | |
| 473 // TODO(avi,creis): Huh? Why is this not NAVIGATION_TYPE_EXISTING_PAGE like | |
|
Charlie Reis
2015/03/09 20:39:58
Ok, let's think this through.
history.replaceStat
Avi (use Gerrit)
2015/03/09 21:35:56
Acknowledged.
| |
| 474 // location.replace()? | |
| 475 EXPECT_EQ(NAVIGATION_TYPE_IN_PAGE, capturer.details().type); | |
| 476 } | |
| 477 | |
| 478 // OK. Now that that weird case is out of the way, let's have the real tests. | |
| 479 | |
| 480 // Back and forward across a fragment navigation. | |
| 481 | |
| 482 GURL url2(embedded_test_server()->GetURL( | |
| 483 "/navigation_controller/page_with_links.html")); | |
| 484 NavigateToURL(shell(), url2); | |
| 485 std::string script = "document.getElementById('fraglink').click()"; | |
| 486 EXPECT_TRUE(content::ExecuteScript(root->current_frame_host(), script)); | |
| 487 EXPECT_TRUE(WaitForLoadStop(shell()->web_contents())); | |
| 488 | |
| 489 { | |
| 490 // Back. | |
| 491 FrameNavigateParamsCapturer capturer(root); | |
| 492 shell()->web_contents()->GetController().GoBack(); | |
| 493 capturer.Wait(); | |
| 494 EXPECT_EQ(ui::PAGE_TRANSITION_TYPED | |
| 495 | ui::PAGE_TRANSITION_FORWARD_BACK | |
| 496 | ui::PAGE_TRANSITION_FROM_ADDRESS_BAR, | |
| 497 capturer.params().transition); | |
| 498 EXPECT_EQ(NAVIGATION_TYPE_IN_PAGE, capturer.details().type); | |
| 499 } | |
| 500 | |
| 501 { | |
| 502 // Forward. | |
| 503 FrameNavigateParamsCapturer capturer(root); | |
| 504 shell()->web_contents()->GetController().GoForward(); | |
| 505 capturer.Wait(); | |
| 506 EXPECT_EQ(ui::PAGE_TRANSITION_LINK | ui::PAGE_TRANSITION_FORWARD_BACK, | |
| 507 capturer.params().transition); | |
| 508 EXPECT_EQ(NAVIGATION_TYPE_IN_PAGE, capturer.details().type); | |
| 509 } | |
| 510 | |
| 511 // Back and forward across a pushState-created navigation. | |
| 512 | |
| 513 NavigateToURL(shell(), url1); | |
| 514 script = "history.pushState({}, 'page 2', 'simple_page_2.html')"; | |
| 515 EXPECT_TRUE(content::ExecuteScript(root->current_frame_host(), script)); | |
| 516 EXPECT_TRUE(WaitForLoadStop(shell()->web_contents())); | |
| 517 | |
| 518 { | |
| 519 // Back. | |
| 520 FrameNavigateParamsCapturer capturer(root); | |
| 521 shell()->web_contents()->GetController().GoBack(); | |
| 522 capturer.Wait(); | |
| 523 EXPECT_EQ(ui::PAGE_TRANSITION_TYPED | |
| 524 | ui::PAGE_TRANSITION_FORWARD_BACK | |
| 525 | ui::PAGE_TRANSITION_FROM_ADDRESS_BAR, | |
| 526 capturer.params().transition); | |
| 527 EXPECT_EQ(NAVIGATION_TYPE_IN_PAGE, capturer.details().type); | |
| 528 } | |
| 529 | |
| 530 { | |
| 531 // Forward. | |
| 532 FrameNavigateParamsCapturer capturer(root); | |
| 533 shell()->web_contents()->GetController().GoForward(); | |
| 534 capturer.Wait(); | |
| 535 EXPECT_EQ(ui::PAGE_TRANSITION_LINK | ui::PAGE_TRANSITION_FORWARD_BACK, | |
| 536 capturer.params().transition); | |
| 537 EXPECT_EQ(NAVIGATION_TYPE_IN_PAGE, capturer.details().type); | |
| 538 } | |
| 539 } | |
| 540 | |
| 541 // Verify that navigations for NAVIGATION_TYPE_NEW_SUBFRAME and | |
| 542 // NAVIGATION_TYPE_AUTO_SUBFRAME are properly classified. | |
| 284 IN_PROC_BROWSER_TEST_F(NavigationControllerBrowserTest, | 543 IN_PROC_BROWSER_TEST_F(NavigationControllerBrowserTest, |
| 285 NavigationTypeClassification_NewAndAutoSubframe) { | 544 NavigationTypeClassification_NewAndAutoSubframe) { |
| 286 GURL main_url(embedded_test_server()->GetURL( | 545 GURL main_url(embedded_test_server()->GetURL( |
| 287 "/navigation_controller/page_with_iframe.html")); | 546 "/navigation_controller/page_with_iframe.html")); |
| 288 NavigateToURL(shell(), main_url); | 547 NavigateToURL(shell(), main_url); |
| 289 | 548 |
| 290 // It is safe to obtain the root frame tree node here, as it doesn't change. | 549 // It is safe to obtain the root frame tree node here, as it doesn't change. |
| 291 FrameTreeNode* root = | 550 FrameTreeNode* root = |
| 292 static_cast<WebContentsImpl*>(shell()->web_contents())-> | 551 static_cast<WebContentsImpl*>(shell()->web_contents())-> |
| 293 GetFrameTree()->root(); | 552 GetFrameTree()->root(); |
| 294 | 553 |
| 295 ASSERT_EQ(1U, root->child_count()); | 554 ASSERT_EQ(1U, root->child_count()); |
| 296 ASSERT_NE(nullptr, root->child_at(0)); | 555 ASSERT_NE(nullptr, root->child_at(0)); |
| 297 | 556 |
| 298 { | 557 { |
| 299 // Navigate the iframe to a new URL; expect a manual subframe transition. | 558 // Simple load. |
| 300 FrameNavigateParamsCapturer capturer(root->child_at(0)); | 559 FrameNavigateParamsCapturer capturer(root->child_at(0)); |
| 301 GURL frame_url(embedded_test_server()->GetURL( | 560 GURL frame_url(embedded_test_server()->GetURL( |
| 302 "/navigation_controller/simple_page_1.html")); | 561 "/navigation_controller/simple_page_1.html")); |
| 303 NavigateFrameToURL(root->child_at(0), frame_url); | 562 NavigateFrameToURL(root->child_at(0), frame_url); |
| 304 capturer.Wait(); | 563 capturer.Wait(); |
| 305 EXPECT_EQ(ui::PAGE_TRANSITION_MANUAL_SUBFRAME, | 564 EXPECT_EQ(ui::PAGE_TRANSITION_MANUAL_SUBFRAME, |
| 306 capturer.params().transition); | 565 capturer.params().transition); |
| 307 EXPECT_EQ(NAVIGATION_TYPE_NEW_SUBFRAME, capturer.details().type); | 566 EXPECT_EQ(NAVIGATION_TYPE_NEW_SUBFRAME, capturer.details().type); |
| 308 } | 567 } |
| 309 | 568 |
| 310 { | 569 { |
| 311 // Do a history navigation; expect an auto subframe transition. | 570 // Back. |
| 312 FrameNavigateParamsCapturer capturer(root->child_at(0)); | 571 FrameNavigateParamsCapturer capturer(root->child_at(0)); |
| 313 shell()->web_contents()->GetController().GoBack(); | 572 shell()->web_contents()->GetController().GoBack(); |
| 314 capturer.Wait(); | 573 capturer.Wait(); |
| 315 EXPECT_EQ(ui::PAGE_TRANSITION_AUTO_SUBFRAME, capturer.params().transition); | 574 EXPECT_EQ(ui::PAGE_TRANSITION_AUTO_SUBFRAME, capturer.params().transition); |
| 316 EXPECT_EQ(NAVIGATION_TYPE_AUTO_SUBFRAME, capturer.details().type); | 575 EXPECT_EQ(NAVIGATION_TYPE_AUTO_SUBFRAME, capturer.details().type); |
| 317 } | 576 } |
| 318 | 577 |
| 319 { | 578 { |
| 320 // Do a history navigation; expect an auto subframe transition. | 579 // Forward. |
| 321 FrameNavigateParamsCapturer capturer(root->child_at(0)); | 580 FrameNavigateParamsCapturer capturer(root->child_at(0)); |
| 322 shell()->web_contents()->GetController().GoForward(); | 581 shell()->web_contents()->GetController().GoForward(); |
| 323 capturer.Wait(); | 582 capturer.Wait(); |
| 324 EXPECT_EQ(ui::PAGE_TRANSITION_AUTO_SUBFRAME, capturer.params().transition); | 583 EXPECT_EQ(ui::PAGE_TRANSITION_AUTO_SUBFRAME, capturer.params().transition); |
| 325 EXPECT_EQ(NAVIGATION_TYPE_AUTO_SUBFRAME, capturer.details().type); | 584 EXPECT_EQ(NAVIGATION_TYPE_AUTO_SUBFRAME, capturer.details().type); |
| 326 } | 585 } |
| 327 | 586 |
| 328 { | 587 { |
| 329 // Navigate the iframe to a new URL; expect a manual subframe transition. | 588 // Simple load. |
| 330 FrameNavigateParamsCapturer capturer(root->child_at(0)); | 589 FrameNavigateParamsCapturer capturer(root->child_at(0)); |
| 331 GURL frame_url(embedded_test_server()->GetURL( | 590 GURL frame_url(embedded_test_server()->GetURL( |
| 332 "/navigation_controller/simple_page_2.html")); | 591 "/navigation_controller/page_with_links.html")); |
| 333 NavigateFrameToURL(root->child_at(0), frame_url); | 592 NavigateFrameToURL(root->child_at(0), frame_url); |
| 334 capturer.Wait(); | 593 capturer.Wait(); |
| 335 EXPECT_EQ(ui::PAGE_TRANSITION_MANUAL_SUBFRAME, | 594 EXPECT_EQ(ui::PAGE_TRANSITION_MANUAL_SUBFRAME, |
| 336 capturer.params().transition); | 595 capturer.params().transition); |
| 337 EXPECT_EQ(NAVIGATION_TYPE_NEW_SUBFRAME, capturer.details().type); | 596 EXPECT_EQ(NAVIGATION_TYPE_NEW_SUBFRAME, capturer.details().type); |
| 338 } | 597 } |
| 339 | 598 |
| 340 { | 599 { |
| 341 // Use location.assign(); expect a manual subframe transition. | 600 // Load via a fragment link click. |
| 601 FrameNavigateParamsCapturer capturer(root->child_at(0)); | |
| 602 std::string script = "document.getElementById('fraglink').click()"; | |
| 603 EXPECT_TRUE(content::ExecuteScript(root->child_at(0)->current_frame_host(), | |
| 604 script)); | |
| 605 capturer.Wait(); | |
| 606 EXPECT_EQ(ui::PAGE_TRANSITION_MANUAL_SUBFRAME, | |
| 607 capturer.params().transition); | |
| 608 EXPECT_EQ(NAVIGATION_TYPE_NEW_SUBFRAME, capturer.details().type); | |
| 609 } | |
| 610 | |
| 611 { | |
| 612 // location.assign(). | |
| 342 FrameNavigateParamsCapturer capturer(root->child_at(0)); | 613 FrameNavigateParamsCapturer capturer(root->child_at(0)); |
| 343 GURL frame_url(embedded_test_server()->GetURL( | 614 GURL frame_url(embedded_test_server()->GetURL( |
| 344 "/navigation_controller/simple_page_1.html")); | 615 "/navigation_controller/simple_page_1.html")); |
| 345 std::string script = "location.assign('" + frame_url.spec() + "')"; | 616 std::string script = "location.assign('" + frame_url.spec() + "')"; |
| 346 EXPECT_TRUE(content::ExecuteScript(root->child_at(0)->current_frame_host(), | 617 EXPECT_TRUE(content::ExecuteScript(root->child_at(0)->current_frame_host(), |
| 347 script)); | 618 script)); |
| 348 capturer.Wait(); | 619 capturer.Wait(); |
| 349 EXPECT_EQ(ui::PAGE_TRANSITION_MANUAL_SUBFRAME, | 620 EXPECT_EQ(ui::PAGE_TRANSITION_MANUAL_SUBFRAME, |
| 350 capturer.params().transition); | 621 capturer.params().transition); |
| 351 EXPECT_EQ(NAVIGATION_TYPE_NEW_SUBFRAME, capturer.details().type); | 622 EXPECT_EQ(NAVIGATION_TYPE_NEW_SUBFRAME, capturer.details().type); |
| 352 } | 623 } |
| 353 | 624 |
| 354 { | 625 { |
| 355 // Use location.replace(); expect an auto subframe transition. (Replacements | 626 // location.replace(). |
| 356 // aren't "navigation" so we only see the frame load committing.) | |
| 357 LoadCommittedCapturer capturer(root->child_at(0)); | 627 LoadCommittedCapturer capturer(root->child_at(0)); |
| 358 GURL frame_url(embedded_test_server()->GetURL( | 628 GURL frame_url(embedded_test_server()->GetURL( |
| 359 "/navigation_controller/simple_page_2.html")); | 629 "/navigation_controller/simple_page_2.html")); |
| 360 std::string script = "location.replace('" + frame_url.spec() + "')"; | 630 std::string script = "location.replace('" + frame_url.spec() + "')"; |
| 361 EXPECT_TRUE(content::ExecuteScript(root->child_at(0)->current_frame_host(), | 631 EXPECT_TRUE(content::ExecuteScript(root->child_at(0)->current_frame_host(), |
| 362 script)); | 632 script)); |
| 363 capturer.Wait(); | 633 capturer.Wait(); |
| 364 EXPECT_EQ(ui::PAGE_TRANSITION_AUTO_SUBFRAME, capturer.transition_type()); | 634 EXPECT_EQ(ui::PAGE_TRANSITION_AUTO_SUBFRAME, capturer.transition_type()); |
| 365 } | 635 } |
| 366 | 636 |
| 367 { | 637 { |
| 368 // Use history.pushState(); expect a manual subframe transition. | 638 // history.pushState(). |
| 369 FrameNavigateParamsCapturer capturer(root->child_at(0)); | 639 FrameNavigateParamsCapturer capturer(root->child_at(0)); |
| 370 std::string script = | 640 std::string script = |
| 371 "history.pushState({}, 'page 1', 'simple_page_1.html')"; | 641 "history.pushState({}, 'page 1', 'simple_page_1.html')"; |
| 372 EXPECT_TRUE(content::ExecuteScript(root->child_at(0)->current_frame_host(), | 642 EXPECT_TRUE(content::ExecuteScript(root->child_at(0)->current_frame_host(), |
| 373 script)); | 643 script)); |
| 374 capturer.Wait(); | 644 capturer.Wait(); |
| 375 EXPECT_EQ(ui::PAGE_TRANSITION_MANUAL_SUBFRAME, | 645 EXPECT_EQ(ui::PAGE_TRANSITION_MANUAL_SUBFRAME, |
| 376 capturer.params().transition); | 646 capturer.params().transition); |
| 377 EXPECT_EQ(NAVIGATION_TYPE_NEW_SUBFRAME, capturer.details().type); | 647 EXPECT_EQ(NAVIGATION_TYPE_NEW_SUBFRAME, capturer.details().type); |
| 378 } | 648 } |
| 379 | 649 |
| 380 { | 650 { |
| 381 // Use history.replaceState(); expect an auto subframe transition. | 651 // history.replaceState(). |
| 382 // (Replacements aren't "navigation" so we only see the frame load | |
| 383 // committing.) | |
| 384 LoadCommittedCapturer capturer(root->child_at(0)); | 652 LoadCommittedCapturer capturer(root->child_at(0)); |
| 385 std::string script = | 653 std::string script = |
| 386 "history.replaceState({}, 'page 2', 'simple_page_2.html')"; | 654 "history.replaceState({}, 'page 2', 'simple_page_2.html')"; |
| 387 EXPECT_TRUE(content::ExecuteScript(root->child_at(0)->current_frame_host(), | 655 EXPECT_TRUE(content::ExecuteScript(root->child_at(0)->current_frame_host(), |
| 388 script)); | 656 script)); |
| 389 capturer.Wait(); | 657 capturer.Wait(); |
| 390 EXPECT_EQ(ui::PAGE_TRANSITION_AUTO_SUBFRAME, capturer.transition_type()); | 658 EXPECT_EQ(ui::PAGE_TRANSITION_AUTO_SUBFRAME, capturer.transition_type()); |
| 391 } | 659 } |
| 392 | 660 |
| 393 { | 661 { |
| 394 // Reload the subframe; expect an auto subframe transition. (Reloads aren't | 662 // Reload. |
| 395 // "navigation" so we only see the frame load committing.) | |
| 396 LoadCommittedCapturer capturer(root->child_at(0)); | 663 LoadCommittedCapturer capturer(root->child_at(0)); |
| 397 EXPECT_TRUE(content::ExecuteScript(root->child_at(0)->current_frame_host(), | 664 EXPECT_TRUE(content::ExecuteScript(root->child_at(0)->current_frame_host(), |
| 398 "location.reload()")); | 665 "location.reload()")); |
| 399 capturer.Wait(); | 666 capturer.Wait(); |
| 400 EXPECT_EQ(ui::PAGE_TRANSITION_AUTO_SUBFRAME, capturer.transition_type()); | 667 EXPECT_EQ(ui::PAGE_TRANSITION_AUTO_SUBFRAME, capturer.transition_type()); |
| 401 } | 668 } |
| 402 | 669 |
| 403 { | 670 { |
| 404 // Create an iframe; expect an auto subframe transition. (Initial frame | 671 // Create an iframe. |
| 405 // creation isn't "navigation" so we only see the frame load committing.) | |
| 406 LoadCommittedCapturer capturer(shell()->web_contents()); | 672 LoadCommittedCapturer capturer(shell()->web_contents()); |
| 407 GURL frame_url(embedded_test_server()->GetURL( | 673 GURL frame_url(embedded_test_server()->GetURL( |
| 408 "/navigation_controller/simple_page_1.html")); | 674 "/navigation_controller/simple_page_1.html")); |
| 409 std::string script = "var iframe = document.createElement('iframe');" | 675 std::string script = "var iframe = document.createElement('iframe');" |
| 410 "iframe.src = '" + frame_url.spec() + "';" | 676 "iframe.src = '" + frame_url.spec() + "';" |
| 411 "document.body.appendChild(iframe);"; | 677 "document.body.appendChild(iframe);"; |
| 412 EXPECT_TRUE(content::ExecuteScript(root->current_frame_host(), script)); | 678 EXPECT_TRUE(content::ExecuteScript(root->current_frame_host(), script)); |
| 413 capturer.Wait(); | 679 capturer.Wait(); |
| 414 EXPECT_EQ(ui::PAGE_TRANSITION_AUTO_SUBFRAME, capturer.transition_type()); | 680 EXPECT_EQ(ui::PAGE_TRANSITION_AUTO_SUBFRAME, capturer.transition_type()); |
| 415 } | 681 } |
| 416 } | 682 } |
| 417 | 683 |
| 418 } // namespace content | 684 } // namespace content |
| OLD | NEW |