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 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 50 "var f = document.createElement('iframe');" | 50 "var f = document.createElement('iframe');" |
| 51 "f.name = 'foo-frame-name';" | 51 "f.name = 'foo-frame-name';" |
| 52 "document.body.appendChild(f);"; | 52 "document.body.appendChild(f);"; |
| 53 static std::string kAddFrameScript = | 53 static std::string kAddFrameScript = |
| 54 "var f = document.createElement('iframe');" | 54 "var f = document.createElement('iframe');" |
| 55 "document.body.appendChild(f);"; | 55 "document.body.appendChild(f);"; |
| 56 static std::string kRemoveFrameScript = | 56 static std::string kRemoveFrameScript = |
| 57 "var f = document.querySelector('iframe');" | 57 "var f = document.querySelector('iframe');" |
| 58 "f.parentNode.removeChild(f);"; | 58 "f.parentNode.removeChild(f);"; |
| 59 | 59 |
| 60 class RenderProcessGoneObserver : public content::WebContentsObserver { | |
|
Charlie Reis
2016/08/10 17:03:09
Can we use RenderProcessHostWatcher from browser_t
nasko
2016/08/10 18:08:51
I tried to find it, but couldn't, so put this one
| |
| 61 public: | |
| 62 RenderProcessGoneObserver(content::WebContents* web_contents) | |
| 63 : content::WebContentsObserver(web_contents), | |
| 64 status_(base::TerminationStatus::TERMINATION_STATUS_MAX_ENUM) {} | |
| 65 ~RenderProcessGoneObserver() override {} | |
| 66 | |
| 67 void RenderProcessGone(base::TerminationStatus status) override { | |
| 68 status_ = status; | |
| 69 } | |
| 70 | |
| 71 base::TerminationStatus status() { return status_; } | |
| 72 | |
| 73 bool is_gone() { | |
| 74 return status_ != base::TerminationStatus::TERMINATION_STATUS_MAX_ENUM; | |
| 75 } | |
| 76 | |
| 77 private: | |
| 78 base::TerminationStatus status_; | |
| 79 }; | |
| 80 | |
| 60 } // namespace | 81 } // namespace |
| 61 | 82 |
| 62 namespace content { | 83 namespace content { |
| 63 | 84 |
| 64 class NavigationControllerBrowserTest : public ContentBrowserTest { | 85 class NavigationControllerBrowserTest : public ContentBrowserTest { |
| 65 protected: | 86 protected: |
| 66 void SetUpOnMainThread() override { | 87 void SetUpOnMainThread() override { |
| 67 host_resolver()->AddRule("*", "127.0.0.1"); | 88 host_resolver()->AddRule("*", "127.0.0.1"); |
| 68 ASSERT_TRUE(embedded_test_server()->Start()); | 89 ASSERT_TRUE(embedded_test_server()->Start()); |
| 69 } | 90 } |
| (...skipping 5539 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 5609 EXPECT_EQ(1U, root->child_count()); | 5630 EXPECT_EQ(1U, root->child_count()); |
| 5610 if (SiteIsolationPolicy::UseSubframeNavigationEntries()) { | 5631 if (SiteIsolationPolicy::UseSubframeNavigationEntries()) { |
| 5611 EXPECT_EQ(1U, nav_entry->root_node()->children.size()); | 5632 EXPECT_EQ(1U, nav_entry->root_node()->children.size()); |
| 5612 EXPECT_EQ(tree_node, nav_entry->root_node()->children[0]); | 5633 EXPECT_EQ(tree_node, nav_entry->root_node()->children[0]); |
| 5613 } | 5634 } |
| 5614 | 5635 |
| 5615 EXPECT_TRUE(ExecuteScript(root, kRemoveFrameScript)); | 5636 EXPECT_TRUE(ExecuteScript(root, kRemoveFrameScript)); |
| 5616 EXPECT_EQ(0U, root->child_count()); | 5637 EXPECT_EQ(0U, root->child_count()); |
| 5617 } | 5638 } |
| 5618 | 5639 |
| 5640 // Test that navigations classified as SAME_PAGE properly update all the | |
| 5641 // members of FrameNavigationEntry. If not, it is possible to get mismatch | |
|
Charlie Reis
2016/08/10 17:03:09
nit: a mismatch
nasko
2016/08/10 18:08:51
Done.
| |
| 5642 // between the origin and URL of a document as seen in | |
| 5643 // https://crbug.com/630103. | |
| 5644 IN_PROC_BROWSER_TEST_F(NavigationControllerBrowserTest, | |
| 5645 EnsureSamePageNavigationUpdatesFrameNavigationEntry) { | |
| 5646 WebContentsImpl* web_contents = | |
| 5647 static_cast<WebContentsImpl*>(shell()->web_contents()); | |
| 5648 FrameTreeNode* root = web_contents->GetFrameTree()->root(); | |
| 5649 | |
| 5650 // Navigate to a simple page and then perform an in-page navigation. | |
| 5651 GURL start_url(embedded_test_server()->GetURL("/title1.html")); | |
| 5652 EXPECT_TRUE(NavigateToURL(shell(), start_url)); | |
| 5653 | |
| 5654 GURL same_page_url(embedded_test_server()->GetURL("/title1.html#foo")); | |
| 5655 EXPECT_TRUE(NavigateToURL(shell(), same_page_url)); | |
| 5656 EXPECT_EQ(2, web_contents->GetController().GetEntryCount()); | |
| 5657 | |
| 5658 // Replace the URL of the current NavigationEntry with one that will cause | |
| 5659 // a server redirect when loaded. | |
| 5660 { | |
| 5661 GURL redirect_dest_url( | |
| 5662 embedded_test_server()->GetURL("b.com", "/simple1.html")); | |
| 5663 TestNavigationObserver observer(web_contents); | |
| 5664 std::string script = "history.replaceState({}, '', '/server-redirect?" + | |
| 5665 redirect_dest_url.spec() + "')"; | |
| 5666 EXPECT_TRUE(ExecuteScript(root, script)); | |
| 5667 observer.Wait(); | |
| 5668 } | |
| 5669 | |
| 5670 // Simulate the user hitting Enter in the omnibox without changing the URL. | |
| 5671 { | |
| 5672 TestNavigationObserver observer(web_contents); | |
| 5673 web_contents->GetController().LoadURL(web_contents->GetLastCommittedURL(), | |
| 5674 Referrer(), ui::PAGE_TRANSITION_LINK, | |
| 5675 std::string()); | |
| 5676 observer.Wait(); | |
| 5677 } | |
| 5678 | |
| 5679 // The renderer process has a CHECK to ensure there are no mismatches between | |
| 5680 // origin and URL, so going back in history should succeed without a process | |
| 5681 // crash. | |
| 5682 RenderProcessGoneObserver process_observer(web_contents); | |
| 5683 { | |
| 5684 TestNavigationObserver observer(web_contents); | |
| 5685 web_contents->GetController().GoBack(); | |
| 5686 observer.Wait(); | |
| 5687 } | |
| 5688 EXPECT_TRUE(!process_observer.is_gone()) << "Exit status: " | |
|
Charlie Reis
2016/08/10 17:03:09
Hmm. It would be nice to verify this beyond avoid
nasko
2016/08/10 18:08:51
I've made it use suborigins on the same site, so w
Charlie Reis
2016/08/10 18:36:16
Thanks for adding the origin check-- that helps.
nasko
2016/08/10 19:42:52
Done.
| |
| 5689 << process_observer.status(); | |
| 5690 } | |
| 5691 | |
| 5619 } // namespace content | 5692 } // namespace content |
| OLD | NEW |