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