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/navigation_controller_impl.h" | 8 #include "content/browser/frame_host/navigation_controller_impl.h" |
8 #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" |
9 #include "content/public/browser/web_contents.h" | 11 #include "content/public/browser/web_contents.h" |
| 12 #include "content/public/browser/web_contents_observer.h" |
10 #include "content/public/test/browser_test_utils.h" | 13 #include "content/public/test/browser_test_utils.h" |
11 #include "content/public/test/content_browser_test.h" | 14 #include "content/public/test/content_browser_test.h" |
12 #include "content/public/test/content_browser_test_utils.h" | 15 #include "content/public/test/content_browser_test_utils.h" |
| 16 #include "content/public/test/test_utils.h" |
13 #include "content/shell/browser/shell.h" | 17 #include "content/shell/browser/shell.h" |
| 18 #include "content/test/content_browser_test_utils_internal.h" |
| 19 #include "net/dns/mock_host_resolver.h" |
| 20 #include "net/test/embedded_test_server/embedded_test_server.h" |
14 | 21 |
15 namespace content { | 22 namespace content { |
16 | 23 |
17 class NavigationControllerBrowserTest : public ContentBrowserTest { | 24 class NavigationControllerBrowserTest : public ContentBrowserTest { |
| 25 protected: |
| 26 void SetUpOnMainThread() override { |
| 27 host_resolver()->AddRule("*", "127.0.0.1"); |
| 28 ASSERT_TRUE(embedded_test_server()->InitializeAndWaitUntilReady()); |
| 29 } |
18 }; | 30 }; |
19 | 31 |
20 IN_PROC_BROWSER_TEST_F(NavigationControllerBrowserTest, LoadDataWithBaseURL) { | 32 IN_PROC_BROWSER_TEST_F(NavigationControllerBrowserTest, LoadDataWithBaseURL) { |
21 const GURL base_url("http://baseurl"); | 33 const GURL base_url("http://baseurl"); |
22 const GURL history_url("http://historyurl"); | 34 const GURL history_url("http://historyurl"); |
23 const std::string data = "<html><body>foo</body></html>"; | 35 const std::string data = "<html><body>foo</body></html>"; |
24 | 36 |
25 const NavigationController& controller = | 37 const NavigationController& controller = |
26 shell()->web_contents()->GetController(); | 38 shell()->web_contents()->GetController(); |
27 // Load data. Blocks until it is done. | 39 // Load data. Blocks until it is done. |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
69 // Now try to go back. This should not hang. | 81 // Now try to go back. This should not hang. |
70 ASSERT_TRUE(controller.CanGoBack()); | 82 ASSERT_TRUE(controller.CanGoBack()); |
71 controller.GoBack(); | 83 controller.GoBack(); |
72 EXPECT_TRUE(WaitForLoadStop(shell()->web_contents())); | 84 EXPECT_TRUE(WaitForLoadStop(shell()->web_contents())); |
73 | 85 |
74 // This should have successfully gone back. | 86 // This should have successfully gone back. |
75 EXPECT_EQ(GURL(base::StringPrintf("data:text/html,page%d", kMaxEntryCount)), | 87 EXPECT_EQ(GURL(base::StringPrintf("data:text/html,page%d", kMaxEntryCount)), |
76 controller.GetLastCommittedEntry()->GetURL()); | 88 controller.GetLastCommittedEntry()->GetURL()); |
77 } | 89 } |
78 | 90 |
| 91 struct FrameNavigateParamsCapturer : public WebContentsObserver { |
| 92 public: |
| 93 explicit FrameNavigateParamsCapturer(FrameTreeNode* node) |
| 94 : WebContentsObserver( |
| 95 node->current_frame_host()->delegate()->GetAsWebContents()), |
| 96 frame_tree_node_id_(node->frame_tree_node_id()), |
| 97 message_loop_runner_(new MessageLoopRunner) {} |
| 98 |
| 99 void Wait() { |
| 100 message_loop_runner_->Run(); |
| 101 } |
| 102 |
| 103 const FrameNavigateParams& params() const { |
| 104 return params_; |
| 105 } |
| 106 |
| 107 const LoadCommittedDetails& details() const { |
| 108 return details_; |
| 109 } |
| 110 |
| 111 private: |
| 112 void DidNavigateAnyFrame(RenderFrameHost* render_frame_host, |
| 113 const LoadCommittedDetails& details, |
| 114 const FrameNavigateParams& params) override { |
| 115 RenderFrameHostImpl* rfh = |
| 116 static_cast<RenderFrameHostImpl*>(render_frame_host); |
| 117 if (rfh->frame_tree_node()->frame_tree_node_id() != frame_tree_node_id_) |
| 118 return; |
| 119 |
| 120 params_ = params; |
| 121 details_ = details; |
| 122 message_loop_runner_->Quit(); |
| 123 } |
| 124 |
| 125 // The id of the FrameTreeNode whose navigations to observe. |
| 126 int frame_tree_node_id_; |
| 127 |
| 128 // The params of the last navigation. |
| 129 FrameNavigateParams params_; |
| 130 |
| 131 // The details of the last navigation. |
| 132 LoadCommittedDetails details_; |
| 133 |
| 134 // The MessageLoopRunner used to spin the message loop. |
| 135 scoped_refptr<MessageLoopRunner> message_loop_runner_; |
| 136 }; |
| 137 |
| 138 // Verify that the distinction between manual and auto subframes is properly set |
| 139 // for subframe navigations. TODO(avi): It's rather bogus that the same info is |
| 140 // in two different enums; http://crbug.com/453555. |
| 141 IN_PROC_BROWSER_TEST_F(NavigationControllerBrowserTest, |
| 142 ManualAndAutoSubframeNavigationClassification) { |
| 143 GURL main_url( |
| 144 embedded_test_server()->GetURL("/frame_tree/page_with_one_frame.html")); |
| 145 NavigateToURL(shell(), main_url); |
| 146 |
| 147 // It is safe to obtain the root frame tree node here, as it doesn't change. |
| 148 FrameTreeNode* root = |
| 149 static_cast<WebContentsImpl*>(shell()->web_contents())-> |
| 150 GetFrameTree()->root(); |
| 151 |
| 152 ASSERT_EQ(1U, root->child_count()); |
| 153 ASSERT_NE(nullptr, root->child_at(0)); |
| 154 |
| 155 { |
| 156 // Navigate the iframe to a new URL; expect a manual subframe transition. |
| 157 FrameNavigateParamsCapturer capturer(root->child_at(0)); |
| 158 GURL frame_url( |
| 159 embedded_test_server()->GetURL("/frame_tree/2-1.html")); |
| 160 NavigateFrameToURL(root->child_at(0), frame_url); |
| 161 capturer.Wait(); |
| 162 EXPECT_EQ(ui::PAGE_TRANSITION_MANUAL_SUBFRAME, |
| 163 capturer.params().transition); |
| 164 EXPECT_EQ(NAVIGATION_TYPE_NEW_SUBFRAME, capturer.details().type); |
| 165 } |
| 166 |
| 167 { |
| 168 // History navigations should result in an auto subframe transition. |
| 169 FrameNavigateParamsCapturer capturer(root->child_at(0)); |
| 170 shell()->web_contents()->GetController().GoBack(); |
| 171 capturer.Wait(); |
| 172 EXPECT_EQ(ui::PAGE_TRANSITION_AUTO_SUBFRAME, capturer.params().transition); |
| 173 EXPECT_EQ(NAVIGATION_TYPE_AUTO_SUBFRAME, capturer.details().type); |
| 174 } |
| 175 |
| 176 { |
| 177 // History navigations should result in an auto subframe transition. |
| 178 FrameNavigateParamsCapturer capturer(root->child_at(0)); |
| 179 shell()->web_contents()->GetController().GoForward(); |
| 180 capturer.Wait(); |
| 181 EXPECT_EQ(ui::PAGE_TRANSITION_AUTO_SUBFRAME, capturer.params().transition); |
| 182 EXPECT_EQ(NAVIGATION_TYPE_AUTO_SUBFRAME, capturer.details().type); |
| 183 } |
| 184 |
| 185 { |
| 186 // Navigate the iframe to a new URL; expect a manual subframe transition. |
| 187 FrameNavigateParamsCapturer capturer(root->child_at(0)); |
| 188 GURL frame_url( |
| 189 embedded_test_server()->GetURL("/frame_tree/2-3.html")); |
| 190 NavigateFrameToURL(root->child_at(0), frame_url); |
| 191 capturer.Wait(); |
| 192 EXPECT_EQ(ui::PAGE_TRANSITION_MANUAL_SUBFRAME, |
| 193 capturer.params().transition); |
| 194 EXPECT_EQ(NAVIGATION_TYPE_NEW_SUBFRAME, capturer.details().type); |
| 195 } |
| 196 } |
| 197 |
79 } // namespace content | 198 } // namespace content |
80 | |
OLD | NEW |