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 "content/browser/frame_host/navigation_controller_impl.h" | 5 #include "content/browser/frame_host/navigation_controller_impl.h" |
| 6 | 6 |
| 7 #include <stdint.h> | 7 #include <stdint.h> |
| 8 #include <utility> | 8 #include <utility> |
| 9 | 9 |
| 10 #include "base/bind.h" | 10 #include "base/bind.h" |
| (...skipping 461 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 472 | 472 |
| 473 namespace { | 473 namespace { |
| 474 | 474 |
| 475 int RendererHistoryLength(Shell* shell) { | 475 int RendererHistoryLength(Shell* shell) { |
| 476 int value = 0; | 476 int value = 0; |
| 477 EXPECT_TRUE(ExecuteScriptAndExtractInt( | 477 EXPECT_TRUE(ExecuteScriptAndExtractInt( |
| 478 shell, "domAutomationController.send(history.length)", &value)); | 478 shell, "domAutomationController.send(history.length)", &value)); |
| 479 return value; | 479 return value; |
| 480 } | 480 } |
| 481 | 481 |
| 482 // Similar to the ones from content_browser_test_utils. | 482 // Similar to the ones from content_browser_test_utils. |
|
Charlie Reis
2016/08/08 22:06:15
Let's change the comment to:
Does a renderer-initi
nasko
2016/08/08 22:39:47
Argh! Should've caught that one. Thanks!
| |
| 483 bool NavigateToURLAndReplace(Shell* shell, const GURL& url) { | 483 bool RendererLocationReplace(Shell* shell, const GURL& url) { |
| 484 WebContents* web_contents = shell->web_contents(); | 484 WebContents* web_contents = shell->web_contents(); |
| 485 WaitForLoadStop(web_contents); | 485 WaitForLoadStop(web_contents); |
| 486 TestNavigationObserver same_tab_observer(web_contents, 1); | 486 TestNavigationObserver same_tab_observer(web_contents, 1); |
| 487 NavigationController::LoadURLParams params(url); | 487 EXPECT_TRUE( |
| 488 params.should_replace_current_entry = true; | 488 ExecuteScript(shell, "window.location.replace('" + url.spec() + "');")); |
| 489 web_contents->GetController().LoadURLWithParams(params); | |
| 490 web_contents->Focus(); | |
| 491 same_tab_observer.Wait(); | 489 same_tab_observer.Wait(); |
| 492 if (!IsLastCommittedEntryOfPageType(web_contents, PAGE_TYPE_NORMAL)) | 490 if (!IsLastCommittedEntryOfPageType(web_contents, PAGE_TYPE_NORMAL)) |
| 493 return false; | 491 return false; |
| 494 return web_contents->GetLastCommittedURL() == url; | 492 return web_contents->GetLastCommittedURL() == url; |
| 495 } | 493 } |
| 496 | 494 |
| 497 } // namespace | 495 } // namespace |
| 498 | 496 |
| 499 // When loading a new page to replace an old page in the history list, make sure | 497 // When loading a new page to replace an old page in the history list, make sure |
| 500 // that the browser and renderer agree, and that both get it right. | 498 // that the browser and renderer agree, and that both get it right. |
| 501 IN_PROC_BROWSER_TEST_F(NavigationControllerBrowserTest, | 499 IN_PROC_BROWSER_TEST_F(NavigationControllerBrowserTest, |
| 502 CorrectLengthWithCurrentItemReplacement) { | 500 CorrectLengthWithCurrentItemReplacement) { |
| 503 NavigationController& controller = | 501 NavigationController& controller = |
| 504 shell()->web_contents()->GetController(); | 502 shell()->web_contents()->GetController(); |
| 505 | 503 |
| 506 EXPECT_TRUE(NavigateToURL(shell(), GURL("data:text/html,page1"))); | 504 EXPECT_TRUE(NavigateToURL(shell(), GURL("data:text/html,page1"))); |
| 507 EXPECT_EQ(1, controller.GetEntryCount()); | 505 EXPECT_EQ(1, controller.GetEntryCount()); |
| 508 EXPECT_EQ(1, RendererHistoryLength(shell())); | 506 EXPECT_EQ(1, RendererHistoryLength(shell())); |
| 509 | 507 |
| 510 EXPECT_TRUE(NavigateToURLAndReplace(shell(), GURL("data:text/html,page1a"))); | 508 EXPECT_TRUE(RendererLocationReplace(shell(), GURL("data:text/html,page1a"))); |
| 511 EXPECT_EQ(1, controller.GetEntryCount()); | 509 EXPECT_EQ(1, controller.GetEntryCount()); |
| 512 EXPECT_EQ(1, RendererHistoryLength(shell())); | 510 EXPECT_EQ(1, RendererHistoryLength(shell())); |
| 513 | 511 |
| 514 // Now create two more entries and go back, to test replacing an entry without | 512 // Now create two more entries and go back, to test replacing an entry without |
| 515 // pruning the forward history. | 513 // pruning the forward history. |
| 516 EXPECT_TRUE(NavigateToURL(shell(), GURL("data:text/html,page2"))); | 514 EXPECT_TRUE(NavigateToURL(shell(), GURL("data:text/html,page2"))); |
| 517 EXPECT_EQ(2, controller.GetEntryCount()); | 515 EXPECT_EQ(2, controller.GetEntryCount()); |
| 518 EXPECT_EQ(2, RendererHistoryLength(shell())); | 516 EXPECT_EQ(2, RendererHistoryLength(shell())); |
| 519 | 517 |
| 520 EXPECT_TRUE(NavigateToURL(shell(), GURL("data:text/html,page3"))); | 518 EXPECT_TRUE(NavigateToURL(shell(), GURL("data:text/html,page3"))); |
| 521 EXPECT_EQ(3, controller.GetEntryCount()); | 519 EXPECT_EQ(3, controller.GetEntryCount()); |
| 522 EXPECT_EQ(3, RendererHistoryLength(shell())); | 520 EXPECT_EQ(3, RendererHistoryLength(shell())); |
| 523 | 521 |
| 524 controller.GoBack(); | 522 controller.GoBack(); |
| 525 EXPECT_TRUE(WaitForLoadStop(shell()->web_contents())); | 523 EXPECT_TRUE(WaitForLoadStop(shell()->web_contents())); |
| 526 controller.GoBack(); | 524 controller.GoBack(); |
| 527 EXPECT_TRUE(WaitForLoadStop(shell()->web_contents())); | 525 EXPECT_TRUE(WaitForLoadStop(shell()->web_contents())); |
| 528 EXPECT_TRUE(controller.CanGoForward()); | 526 EXPECT_TRUE(controller.CanGoForward()); |
| 529 | 527 |
| 530 EXPECT_TRUE(NavigateToURLAndReplace(shell(), GURL("data:text/html,page1b"))); | 528 EXPECT_TRUE(RendererLocationReplace(shell(), GURL("data:text/html,page1b"))); |
| 531 EXPECT_EQ(3, controller.GetEntryCount()); | 529 EXPECT_EQ(3, controller.GetEntryCount()); |
| 532 EXPECT_EQ(3, RendererHistoryLength(shell())); | 530 EXPECT_EQ(3, RendererHistoryLength(shell())); |
| 533 EXPECT_TRUE(controller.CanGoForward()); | 531 EXPECT_TRUE(controller.CanGoForward()); |
| 534 | 532 |
| 535 // Note that there's no way to access the renderer's notion of the history | 533 // Note that there's no way to access the renderer's notion of the history |
| 536 // offset via JavaScript. Checking just the history length, though, is enough; | 534 // offset via JavaScript. Checking just the history length, though, is enough; |
| 537 // if the replacement failed, there would be a new history entry and thus an | 535 // if the replacement failed, there would be a new history entry and thus an |
| 538 // incorrect length. | 536 // incorrect length. |
| 539 } | 537 } |
| 540 | 538 |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 574 const GURL page_url = embedded_test_server()->GetURL( | 572 const GURL page_url = embedded_test_server()->GetURL( |
| 575 "/navigation_controller/simple_page_1.html"); | 573 "/navigation_controller/simple_page_1.html"); |
| 576 | 574 |
| 577 // Use data scheme first so that the next page will be loaded | 575 // Use data scheme first so that the next page will be loaded |
| 578 // in a separate site instance. | 576 // in a separate site instance. |
| 579 EXPECT_TRUE(NavigateToURL(shell(), GURL("data:text/html,page1"))); | 577 EXPECT_TRUE(NavigateToURL(shell(), GURL("data:text/html,page1"))); |
| 580 EXPECT_EQ(1, controller.GetEntryCount()); | 578 EXPECT_EQ(1, controller.GetEntryCount()); |
| 581 EXPECT_NE(-1, shell()->web_contents()->GetMaxPageID()); | 579 EXPECT_NE(-1, shell()->web_contents()->GetMaxPageID()); |
| 582 | 580 |
| 583 // Now navigate and replace the current entry. | 581 // Now navigate and replace the current entry. |
| 584 NavigateToURLAndReplace(shell(), page_url); | 582 RendererLocationReplace(shell(), page_url); |
| 585 EXPECT_EQ(1, controller.GetEntryCount()); | 583 EXPECT_EQ(1, controller.GetEntryCount()); |
| 586 | 584 |
| 587 // Page ID should be updated. | 585 // Page ID should be updated. |
| 588 EXPECT_NE(-1, shell()->web_contents()->GetMaxPageID()); | 586 EXPECT_NE(-1, shell()->web_contents()->GetMaxPageID()); |
| 589 | 587 |
| 590 // Reload the page and verify that we don't hit | 588 // Reload the page and verify that we don't hit |
| 591 // a DCHECK in |RenderFrameImpl::NavigateInternal|. | 589 // a DCHECK in |RenderFrameImpl::NavigateInternal|. |
| 592 controller.Reload(false); | 590 controller.Reload(false); |
| 593 EXPECT_TRUE(WaitForLoadStop(shell()->web_contents())); | 591 EXPECT_TRUE(WaitForLoadStop(shell()->web_contents())); |
| 594 | 592 |
| (...skipping 373 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 968 // Make a new entry ... | 966 // Make a new entry ... |
| 969 NavigateToURL(shell(), GURL(url::kAboutBlankURL)); | 967 NavigateToURL(shell(), GURL(url::kAboutBlankURL)); |
| 970 EXPECT_EQ(3, controller.GetEntryCount()); | 968 EXPECT_EQ(3, controller.GetEntryCount()); |
| 971 | 969 |
| 972 // ... and replace it with a failed load. | 970 // ... and replace it with a failed load. |
| 973 // TODO(creis): Make this be NEW_PAGE along with the other location.replace | 971 // TODO(creis): Make this be NEW_PAGE along with the other location.replace |
| 974 // cases. There isn't much impact to having this be EXISTING_PAGE for now. | 972 // cases. There isn't much impact to having this be EXISTING_PAGE for now. |
| 975 // See https://crbug.com/596707. | 973 // See https://crbug.com/596707. |
| 976 { | 974 { |
| 977 FrameNavigateParamsCapturer capturer(root); | 975 FrameNavigateParamsCapturer capturer(root); |
| 978 NavigateToURLAndReplace(shell(), error_url); | 976 RendererLocationReplace(shell(), error_url); |
| 979 capturer.Wait(); | 977 capturer.Wait(); |
| 980 EXPECT_EQ(NAVIGATION_TYPE_EXISTING_PAGE, capturer.details().type); | 978 EXPECT_EQ(NAVIGATION_TYPE_EXISTING_PAGE, capturer.details().type); |
| 981 NavigationEntry* entry = controller.GetLastCommittedEntry(); | 979 NavigationEntry* entry = controller.GetLastCommittedEntry(); |
| 982 EXPECT_EQ(PAGE_TYPE_ERROR, entry->GetPageType()); | 980 EXPECT_EQ(PAGE_TYPE_ERROR, entry->GetPageType()); |
| 983 EXPECT_EQ(3, controller.GetEntryCount()); | 981 EXPECT_EQ(3, controller.GetEntryCount()); |
| 984 } | 982 } |
| 985 | 983 |
| 986 // Make a new web ui page to force a process swap ... | 984 // Make a new web ui page to force a process swap ... |
| 987 GURL web_ui_page(std::string(kChromeUIScheme) + "://" + | 985 GURL web_ui_page(std::string(kChromeUIScheme) + "://" + |
| 988 std::string(kChromeUIGpuHost)); | 986 std::string(kChromeUIGpuHost)); |
| 989 NavigateToURL(shell(), web_ui_page); | 987 NavigateToURL(shell(), web_ui_page); |
| 990 EXPECT_EQ(4, controller.GetEntryCount()); | 988 EXPECT_EQ(4, controller.GetEntryCount()); |
| 991 | 989 |
| 992 // ... and replace it with a failed load. (It is NEW_PAGE for the reason noted | 990 // ... and replace it with a failed load. (It is NEW_PAGE for the reason noted |
| 993 // above.) | 991 // above.) |
| 994 { | 992 { |
| 995 FrameNavigateParamsCapturer capturer(root); | 993 FrameNavigateParamsCapturer capturer(root); |
| 996 NavigateToURLAndReplace(shell(), error_url); | 994 RendererLocationReplace(shell(), error_url); |
| 997 capturer.Wait(); | 995 capturer.Wait(); |
| 998 EXPECT_EQ(NAVIGATION_TYPE_NEW_PAGE, capturer.details().type); | 996 EXPECT_EQ(NAVIGATION_TYPE_NEW_PAGE, capturer.details().type); |
| 999 NavigationEntry* entry = controller.GetLastCommittedEntry(); | 997 NavigationEntry* entry = controller.GetLastCommittedEntry(); |
| 1000 EXPECT_EQ(PAGE_TYPE_ERROR, entry->GetPageType()); | 998 EXPECT_EQ(PAGE_TYPE_ERROR, entry->GetPageType()); |
| 1001 EXPECT_EQ(4, controller.GetEntryCount()); | 999 EXPECT_EQ(4, controller.GetEntryCount()); |
| 1002 } | 1000 } |
| 1003 } | 1001 } |
| 1004 | 1002 |
| 1005 // Various tests for navigation type classifications. TODO(avi): It's rather | 1003 // Various tests for navigation type classifications. TODO(avi): It's rather |
| 1006 // bogus that the same info is in two different enums; http://crbug.com/453555. | 1004 // bogus that the same info is in two different enums; http://crbug.com/453555. |
| (...skipping 4603 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 5610 if (SiteIsolationPolicy::UseSubframeNavigationEntries()) { | 5608 if (SiteIsolationPolicy::UseSubframeNavigationEntries()) { |
| 5611 EXPECT_EQ(1U, nav_entry->root_node()->children.size()); | 5609 EXPECT_EQ(1U, nav_entry->root_node()->children.size()); |
| 5612 EXPECT_EQ(tree_node, nav_entry->root_node()->children[0]); | 5610 EXPECT_EQ(tree_node, nav_entry->root_node()->children[0]); |
| 5613 } | 5611 } |
| 5614 | 5612 |
| 5615 EXPECT_TRUE(ExecuteScript(root, kRemoveFrameScript)); | 5613 EXPECT_TRUE(ExecuteScript(root, kRemoveFrameScript)); |
| 5616 EXPECT_EQ(0U, root->child_count()); | 5614 EXPECT_EQ(0U, root->child_count()); |
| 5617 } | 5615 } |
| 5618 | 5616 |
| 5619 } // namespace content | 5617 } // namespace content |
| OLD | NEW |