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/command_line.h" | 5 #include "base/command_line.h" |
6 #include "base/macros.h" | 6 #include "base/macros.h" |
7 #include "base/test/histogram_tester.h" | 7 #include "base/test/histogram_tester.h" |
8 #include "base/time/time.h" | 8 #include "base/time/time.h" |
9 #include "content/browser/frame_host/navigation_controller_impl.h" | 9 #include "content/browser/frame_host/navigation_controller_impl.h" |
10 #include "content/browser/frame_host/navigation_entry_impl.h" | 10 #include "content/browser/frame_host/navigation_entry_impl.h" |
11 #include "content/browser/frame_host/navigation_request.h" | 11 #include "content/browser/frame_host/navigation_request.h" |
12 #include "content/browser/frame_host/navigation_request_info.h" | 12 #include "content/browser/frame_host/navigation_request_info.h" |
13 #include "content/browser/frame_host/navigator.h" | 13 #include "content/browser/frame_host/navigator.h" |
14 #include "content/browser/frame_host/navigator_impl.h" | 14 #include "content/browser/frame_host/navigator_impl.h" |
15 #include "content/browser/frame_host/render_frame_host_manager.h" | 15 #include "content/browser/frame_host/render_frame_host_manager.h" |
| 16 #include "content/browser/loader/navigation_url_loader.h" |
| 17 #include "content/browser/loader/navigation_url_loader_factory.h" |
16 #include "content/browser/site_instance_impl.h" | 18 #include "content/browser/site_instance_impl.h" |
17 #include "content/common/navigation_params.h" | 19 #include "content/common/navigation_params.h" |
18 #include "content/public/browser/stream_handle.h" | 20 #include "content/public/browser/stream_handle.h" |
19 #include "content/public/common/content_switches.h" | 21 #include "content/public/common/content_switches.h" |
20 #include "content/public/common/url_constants.h" | 22 #include "content/public/common/url_constants.h" |
21 #include "content/public/common/url_utils.h" | 23 #include "content/public/common/url_utils.h" |
22 #include "content/test/test_render_frame_host.h" | 24 #include "content/test/test_render_frame_host.h" |
23 #include "content/test/test_web_contents.h" | 25 #include "content/test/test_web_contents.h" |
24 #include "net/base/load_flags.h" | 26 #include "net/base/load_flags.h" |
25 #include "net/http/http_response_headers.h" | 27 #include "net/http/http_response_headers.h" |
| 28 #include "net/url_request/redirect_info.h" |
26 #include "ui/base/page_transition_types.h" | 29 #include "ui/base/page_transition_types.h" |
27 | 30 |
28 namespace content { | 31 namespace content { |
29 | 32 |
30 namespace { | 33 namespace { |
31 | 34 |
32 // Mocked out stream handle to commit the navigation with. | 35 // Mocked out stream handle to commit the navigation with. |
33 class TestStreamHandle : public StreamHandle { | 36 class TestStreamHandle : public StreamHandle { |
34 public: | 37 public: |
35 TestStreamHandle() : url_("test:stream") {} | 38 TestStreamHandle() : url_("test:stream") {} |
36 | 39 |
37 virtual const GURL& GetURL() override { | 40 virtual const GURL& GetURL() override { |
38 return url_; | 41 return url_; |
39 } | 42 } |
40 | 43 |
41 virtual void AddCloseListener(const base::Closure& callback) override { | 44 virtual void AddCloseListener(const base::Closure& callback) override { |
42 NOTREACHED(); | 45 NOTREACHED(); |
43 } | 46 } |
44 | 47 |
45 private: | 48 private: |
46 GURL url_; | 49 GURL url_; |
47 | 50 |
48 DISALLOW_COPY_AND_ASSIGN(TestStreamHandle); | 51 DISALLOW_COPY_AND_ASSIGN(TestStreamHandle); |
49 }; | 52 }; |
50 | 53 |
| 54 class TestNavigationURLLoader : public NavigationURLLoader { |
| 55 public: |
| 56 TestNavigationURLLoader(const CommonNavigationParams& common_params, |
| 57 scoped_ptr<NavigationRequestInfo> request_info, |
| 58 NavigationURLLoader::Delegate* delegate) |
| 59 : common_params_(common_params), |
| 60 request_info_(request_info.Pass()), |
| 61 delegate_(delegate) { |
| 62 } |
| 63 |
| 64 virtual ~TestNavigationURLLoader() { |
| 65 // Record the number of times a loader was canceled before ResponseStarted |
| 66 // or RequestFailed was returned. |
| 67 if (delegate_) |
| 68 cancel_count_++; |
| 69 } |
| 70 |
| 71 // NavigationURLLoader implementation. |
| 72 virtual void FollowRedirect() override { |
| 73 redirect_count_++; |
| 74 } |
| 75 |
| 76 const CommonNavigationParams& common_params() const { return common_params_; } |
| 77 NavigationRequestInfo* request_info() const { return request_info_.get(); } |
| 78 |
| 79 void CallOnRequestRedirected(const net::RedirectInfo& redirect_info, |
| 80 ResourceResponse* response) { |
| 81 delegate_->OnRequestRedirected(redirect_info, response); |
| 82 } |
| 83 |
| 84 void CallOnResponseStarted(ResourceResponse* response, |
| 85 scoped_ptr<StreamHandle> body) { |
| 86 delegate_->OnResponseStarted(response, body.Pass()); |
| 87 } |
| 88 |
| 89 static int redirect_count() { return redirect_count_; } |
| 90 static int cancel_count() { return cancel_count_; } |
| 91 |
| 92 private: |
| 93 static int redirect_count_; |
| 94 static int cancel_count_; |
| 95 |
| 96 CommonNavigationParams common_params_; |
| 97 scoped_ptr<NavigationRequestInfo> request_info_; |
| 98 NavigationURLLoader::Delegate* delegate_; |
| 99 }; |
| 100 |
| 101 int TestNavigationURLLoader::redirect_count_ = 0; |
| 102 int TestNavigationURLLoader::cancel_count_ = 0; |
| 103 |
| 104 class TestNavigationURLLoaderFactory : public NavigationURLLoaderFactory { |
| 105 public: |
| 106 // NavigationURLLoaderFactory implementation. |
| 107 virtual scoped_ptr<NavigationURLLoader> CreateLoader( |
| 108 BrowserContext* browser_context, |
| 109 int64 frame_tree_node_id, |
| 110 const CommonNavigationParams& common_params, |
| 111 scoped_ptr<NavigationRequestInfo> request_info, |
| 112 ResourceRequestBody* request_body, |
| 113 NavigationURLLoader::Delegate* delegate) override { |
| 114 return scoped_ptr<NavigationURLLoader>(new TestNavigationURLLoader( |
| 115 common_params, request_info.Pass(), delegate)); |
| 116 } |
| 117 }; |
| 118 |
51 } | 119 } |
52 | 120 |
53 class NavigatorTest | 121 class NavigatorTest |
54 : public RenderViewHostImplTestHarness { | 122 : public RenderViewHostImplTestHarness { |
55 public: | 123 public: |
| 124 virtual void SetUp() override { |
| 125 RenderViewHostImplTestHarness::SetUp(); |
| 126 loader_factory_.reset(new TestNavigationURLLoaderFactory); |
| 127 NavigationURLLoader::SetFactoryForTesting(loader_factory_.get()); |
| 128 } |
| 129 |
| 130 virtual void TearDown() override { |
| 131 NavigationURLLoader::SetFactoryForTesting(nullptr); |
| 132 loader_factory_.reset(); |
| 133 RenderViewHostImplTestHarness::TearDown(); |
| 134 } |
| 135 |
56 NavigationRequest* GetNavigationRequestForFrameTreeNode( | 136 NavigationRequest* GetNavigationRequestForFrameTreeNode( |
57 FrameTreeNode* frame_tree_node) const { | 137 FrameTreeNode* frame_tree_node) const { |
58 NavigatorImpl* navigator = | 138 NavigatorImpl* navigator = |
59 static_cast<NavigatorImpl*>(frame_tree_node->navigator()); | 139 static_cast<NavigatorImpl*>(frame_tree_node->navigator()); |
60 return navigator->navigation_request_map_.get( | 140 return navigator->navigation_request_map_.get( |
61 frame_tree_node->frame_tree_node_id()); | 141 frame_tree_node->frame_tree_node_id()); |
62 } | 142 } |
63 | 143 |
| 144 TestNavigationURLLoader* GetLoaderForNavigationRequest( |
| 145 NavigationRequest* request) const { |
| 146 return static_cast<TestNavigationURLLoader*>(request->loader_for_testing()); |
| 147 } |
| 148 |
64 void EnableBrowserSideNavigation() { | 149 void EnableBrowserSideNavigation() { |
65 CommandLine::ForCurrentProcess()->AppendSwitch( | 150 CommandLine::ForCurrentProcess()->AppendSwitch( |
66 switches::kEnableBrowserSideNavigation); | 151 switches::kEnableBrowserSideNavigation); |
67 } | 152 } |
68 | 153 |
69 void SendRequestNavigation(FrameTreeNode* node, | 154 void SendRequestNavigation(FrameTreeNode* node, |
70 const GURL& url) { | 155 const GURL& url) { |
71 SendRequestNavigationWithParameters( | 156 SendRequestNavigationWithParameters( |
72 node, url, Referrer(), ui::PAGE_TRANSITION_LINK, | 157 node, url, Referrer(), ui::PAGE_TRANSITION_LINK, |
73 NavigationController::NO_RELOAD); | 158 NavigationController::NO_RELOAD); |
(...skipping 10 matching lines...) Expand all Loading... |
84 NavigationController::CreateNavigationEntry( | 169 NavigationController::CreateNavigationEntry( |
85 url, | 170 url, |
86 referrer, | 171 referrer, |
87 transition_type, | 172 transition_type, |
88 false, | 173 false, |
89 std::string(), | 174 std::string(), |
90 controller().GetBrowserContext()))); | 175 controller().GetBrowserContext()))); |
91 static_cast<NavigatorImpl*>(node->navigator())->RequestNavigation( | 176 static_cast<NavigatorImpl*>(node->navigator())->RequestNavigation( |
92 node, *entry, reload_type, base::TimeTicks::Now()); | 177 node, *entry, reload_type, base::TimeTicks::Now()); |
93 } | 178 } |
| 179 |
| 180 private: |
| 181 scoped_ptr<TestNavigationURLLoaderFactory> loader_factory_; |
94 }; | 182 }; |
95 | 183 |
96 // PlzNavigate: Test that a proper NavigationRequest is created by | 184 // PlzNavigate: Test that a proper NavigationRequest is created by |
97 // BeginNavigation. | 185 // BeginNavigation. |
98 // Note that all PlzNavigate methods on the browser side require the use of the | 186 // Note that all PlzNavigate methods on the browser side require the use of the |
99 // flag kEnableBrowserSideNavigation. | 187 // flag kEnableBrowserSideNavigation. |
100 TEST_F(NavigatorTest, BrowserSideNavigationBeginNavigation) { | 188 TEST_F(NavigatorTest, BrowserSideNavigationBeginNavigation) { |
101 const GURL kUrl1("http://www.google.com/"); | 189 const GURL kUrl1("http://www.google.com/"); |
102 const GURL kUrl2("http://www.chromium.org/"); | 190 const GURL kUrl2("http://www.chromium.org/"); |
103 const GURL kUrl3("http://www.gmail.com/"); | 191 const GURL kUrl3("http://www.gmail.com/"); |
104 | 192 |
105 contents()->NavigateAndCommit(kUrl1); | 193 contents()->NavigateAndCommit(kUrl1); |
106 | 194 |
107 EnableBrowserSideNavigation(); | 195 EnableBrowserSideNavigation(); |
108 | 196 |
109 // Add a subframe. | 197 // Add a subframe. |
110 TestRenderFrameHost* subframe_rfh = static_cast<TestRenderFrameHost*>( | 198 TestRenderFrameHost* subframe_rfh = static_cast<TestRenderFrameHost*>( |
111 contents()->GetFrameTree()->AddFrame( | 199 contents()->GetFrameTree()->AddFrame( |
112 contents()->GetFrameTree()->root(), 14, "Child")); | 200 contents()->GetFrameTree()->root(), 14, "Child")); |
113 | 201 |
114 FrameTreeNode* subframe_node = subframe_rfh->frame_tree_node(); | 202 FrameTreeNode* subframe_node = subframe_rfh->frame_tree_node(); |
115 SendRequestNavigation(subframe_rfh->frame_tree_node(), kUrl2); | 203 SendRequestNavigation(subframe_rfh->frame_tree_node(), kUrl2); |
116 // There is no previous renderer in the subframe, so BeginNavigation is | 204 // There is no previous renderer in the subframe, so BeginNavigation is |
117 // handled already. | 205 // handled already. |
118 NavigationRequest* subframe_request = | 206 NavigationRequest* subframe_request = |
119 GetNavigationRequestForFrameTreeNode(subframe_node); | 207 GetNavigationRequestForFrameTreeNode(subframe_node); |
| 208 TestNavigationURLLoader* subframe_loader = |
| 209 GetLoaderForNavigationRequest(subframe_request); |
120 ASSERT_TRUE(subframe_request); | 210 ASSERT_TRUE(subframe_request); |
121 EXPECT_EQ(kUrl2, subframe_request->common_params().url); | 211 EXPECT_EQ(kUrl2, subframe_request->common_params().url); |
| 212 EXPECT_EQ(kUrl2, subframe_loader->common_params().url); |
122 // First party for cookies url should be that of the main frame. | 213 // First party for cookies url should be that of the main frame. |
123 EXPECT_EQ(kUrl1, subframe_request->info_for_test()->first_party_for_cookies); | 214 EXPECT_EQ(kUrl1, subframe_loader->request_info()->first_party_for_cookies); |
124 EXPECT_FALSE(subframe_request->info_for_test()->is_main_frame); | 215 EXPECT_FALSE(subframe_loader->request_info()->is_main_frame); |
125 EXPECT_TRUE(subframe_request->info_for_test()->parent_is_main_frame); | 216 EXPECT_TRUE(subframe_loader->request_info()->parent_is_main_frame); |
126 | 217 |
127 FrameTreeNode* main_frame_node = | 218 FrameTreeNode* main_frame_node = |
128 contents()->GetMainFrame()->frame_tree_node(); | 219 contents()->GetMainFrame()->frame_tree_node(); |
129 SendRequestNavigation(main_frame_node, kUrl3); | 220 SendRequestNavigation(main_frame_node, kUrl3); |
130 // Simulate a BeginNavigation IPC on the main frame. | 221 // Simulate a BeginNavigation IPC on the main frame. |
131 contents()->GetMainFrame()->SendBeginNavigationWithURL(kUrl3); | 222 contents()->GetMainFrame()->SendBeginNavigationWithURL(kUrl3); |
132 NavigationRequest* main_request = | 223 NavigationRequest* main_request = |
133 GetNavigationRequestForFrameTreeNode(main_frame_node); | 224 GetNavigationRequestForFrameTreeNode(main_frame_node); |
| 225 TestNavigationURLLoader* main_loader = |
| 226 GetLoaderForNavigationRequest(main_request); |
134 ASSERT_TRUE(main_request); | 227 ASSERT_TRUE(main_request); |
135 EXPECT_EQ(kUrl3, main_request->common_params().url); | 228 EXPECT_EQ(kUrl3, main_request->common_params().url); |
136 EXPECT_EQ(kUrl3, main_request->info_for_test()->first_party_for_cookies); | 229 EXPECT_EQ(kUrl3, main_loader->common_params().url); |
137 EXPECT_TRUE(main_request->info_for_test()->is_main_frame); | 230 EXPECT_EQ(kUrl3, main_loader->request_info()->first_party_for_cookies); |
138 EXPECT_FALSE(main_request->info_for_test()->parent_is_main_frame); | 231 EXPECT_TRUE(main_loader->request_info()->is_main_frame); |
| 232 EXPECT_FALSE(main_loader->request_info()->parent_is_main_frame); |
139 } | 233 } |
140 | 234 |
141 // PlzNavigate: Test that RequestNavigation creates a NavigationRequest and that | 235 // PlzNavigate: Test that RequestNavigation creates a NavigationRequest and that |
142 // RenderFrameHost is not modified when the navigation commits. | 236 // RenderFrameHost is not modified when the navigation commits. |
143 TEST_F(NavigatorTest, BrowserSideNavigationRequestNavigationNoLiveRenderer) { | 237 TEST_F(NavigatorTest, BrowserSideNavigationRequestNavigationNoLiveRenderer) { |
144 const GURL kUrl("http://www.google.com/"); | 238 const GURL kUrl("http://www.google.com/"); |
145 | 239 |
146 EnableBrowserSideNavigation(); | 240 EnableBrowserSideNavigation(); |
147 EXPECT_FALSE(main_test_rfh()->render_view_host()->IsRenderViewLive()); | 241 EXPECT_FALSE(main_test_rfh()->render_view_host()->IsRenderViewLive()); |
148 FrameTreeNode* node = main_test_rfh()->frame_tree_node(); | 242 FrameTreeNode* node = main_test_rfh()->frame_tree_node(); |
149 SendRequestNavigation(node, kUrl); | 243 SendRequestNavigation(node, kUrl); |
150 NavigationRequest* main_request = GetNavigationRequestForFrameTreeNode(node); | 244 NavigationRequest* main_request = GetNavigationRequestForFrameTreeNode(node); |
151 // A NavigationRequest should have been generated. | 245 // A NavigationRequest should have been generated. |
152 EXPECT_TRUE(main_request != NULL); | 246 EXPECT_TRUE(main_request != NULL); |
153 RenderFrameHostImpl* rfh = main_test_rfh(); | 247 RenderFrameHostImpl* rfh = main_test_rfh(); |
154 | 248 |
155 // Now commit the same url. | 249 // Now return the response without any redirects. This will cause the |
| 250 // navigation to commit at the same URL. |
156 scoped_refptr<ResourceResponse> response(new ResourceResponse); | 251 scoped_refptr<ResourceResponse> response(new ResourceResponse); |
157 node->navigator()->CommitNavigation( | 252 GetLoaderForNavigationRequest(main_request)->CallOnResponseStarted( |
158 node, response.get(), scoped_ptr<StreamHandle>(new TestStreamHandle)); | 253 response.get(), scoped_ptr<StreamHandle>(new TestStreamHandle)); |
159 main_request = GetNavigationRequestForFrameTreeNode(node); | 254 main_request = GetNavigationRequestForFrameTreeNode(node); |
160 | 255 |
161 // The main RFH should not have been changed, and the renderer should have | 256 // The main RFH should not have been changed, and the renderer should have |
162 // been initialized. | 257 // been initialized. |
163 EXPECT_EQ(rfh, main_test_rfh()); | 258 EXPECT_EQ(rfh, main_test_rfh()); |
164 EXPECT_TRUE(main_test_rfh()->IsRenderFrameLive()); | 259 EXPECT_TRUE(main_test_rfh()->IsRenderFrameLive()); |
165 EXPECT_TRUE(main_test_rfh()->render_view_host()->IsRenderViewLive()); | 260 EXPECT_TRUE(main_test_rfh()->render_view_host()->IsRenderViewLive()); |
166 } | 261 } |
167 | 262 |
168 // PlzNavigate: Test that commiting an HTTP 204 or HTTP 205 response cancels the | 263 // PlzNavigate: Test that commiting an HTTP 204 or HTTP 205 response cancels the |
(...skipping 14 matching lines...) Expand all Loading... |
183 SendRequestNavigation(node, kUrl2); | 278 SendRequestNavigation(node, kUrl2); |
184 main_test_rfh()->SendBeginNavigationWithURL(kUrl2); | 279 main_test_rfh()->SendBeginNavigationWithURL(kUrl2); |
185 NavigationRequest* main_request = GetNavigationRequestForFrameTreeNode(node); | 280 NavigationRequest* main_request = GetNavigationRequestForFrameTreeNode(node); |
186 ASSERT_TRUE(main_request); | 281 ASSERT_TRUE(main_request); |
187 | 282 |
188 // Commit an HTTP 204 response. | 283 // Commit an HTTP 204 response. |
189 scoped_refptr<ResourceResponse> response(new ResourceResponse); | 284 scoped_refptr<ResourceResponse> response(new ResourceResponse); |
190 const char kNoContentHeaders[] = "HTTP/1.1 204 No Content\0\0"; | 285 const char kNoContentHeaders[] = "HTTP/1.1 204 No Content\0\0"; |
191 response->head.headers = new net::HttpResponseHeaders( | 286 response->head.headers = new net::HttpResponseHeaders( |
192 std::string(kNoContentHeaders, arraysize(kNoContentHeaders))); | 287 std::string(kNoContentHeaders, arraysize(kNoContentHeaders))); |
193 node->navigator()->CommitNavigation( | 288 GetLoaderForNavigationRequest(main_request)->CallOnResponseStarted( |
194 node, response.get(), scoped_ptr<StreamHandle>(new TestStreamHandle)); | 289 response.get(), scoped_ptr<StreamHandle>(new TestStreamHandle)); |
195 | 290 |
196 // There should be no pending RenderFrameHost; the navigation was aborted. | 291 // There should be no pending RenderFrameHost; the navigation was aborted. |
197 EXPECT_FALSE(GetNavigationRequestForFrameTreeNode(node)); | 292 EXPECT_FALSE(GetNavigationRequestForFrameTreeNode(node)); |
198 EXPECT_FALSE(node->render_manager()->pending_frame_host()); | 293 EXPECT_FALSE(node->render_manager()->pending_frame_host()); |
199 | 294 |
200 // Now, repeat the test with 205 Reset Content. | 295 // Now, repeat the test with 205 Reset Content. |
201 | 296 |
202 // Navigate to a different site again. | 297 // Navigate to a different site again. |
203 SendRequestNavigation(node, kUrl2); | 298 SendRequestNavigation(node, kUrl2); |
204 main_test_rfh()->SendBeginNavigationWithURL(kUrl2); | 299 main_test_rfh()->SendBeginNavigationWithURL(kUrl2); |
205 main_request = GetNavigationRequestForFrameTreeNode(node); | 300 main_request = GetNavigationRequestForFrameTreeNode(node); |
206 ASSERT_TRUE(main_request); | 301 ASSERT_TRUE(main_request); |
207 | 302 |
208 // Commit an HTTP 205 response. | 303 // Commit an HTTP 205 response. |
209 response = new ResourceResponse; | 304 response = new ResourceResponse; |
210 const char kResetContentHeaders[] = "HTTP/1.1 205 Reset Content\0\0"; | 305 const char kResetContentHeaders[] = "HTTP/1.1 205 Reset Content\0\0"; |
211 response->head.headers = new net::HttpResponseHeaders( | 306 response->head.headers = new net::HttpResponseHeaders( |
212 std::string(kResetContentHeaders, arraysize(kResetContentHeaders))); | 307 std::string(kResetContentHeaders, arraysize(kResetContentHeaders))); |
213 node->navigator()->CommitNavigation( | 308 GetLoaderForNavigationRequest(main_request)->CallOnResponseStarted( |
214 node, response.get(), scoped_ptr<StreamHandle>(new TestStreamHandle)); | 309 response.get(), scoped_ptr<StreamHandle>(new TestStreamHandle)); |
215 | 310 |
216 // There should be no pending RenderFrameHost; the navigation was aborted. | 311 // There should be no pending RenderFrameHost; the navigation was aborted. |
217 EXPECT_FALSE(GetNavigationRequestForFrameTreeNode(node)); | 312 EXPECT_FALSE(GetNavigationRequestForFrameTreeNode(node)); |
218 EXPECT_FALSE(node->render_manager()->pending_frame_host()); | 313 EXPECT_FALSE(node->render_manager()->pending_frame_host()); |
219 } | 314 } |
220 | 315 |
221 // PlzNavigate: Test that a new RenderFrameHost is created when doing a cross | 316 // PlzNavigate: Test that a new RenderFrameHost is created when doing a cross |
222 // site navigation. | 317 // site navigation. |
223 TEST_F(NavigatorTest, BrowserSideNavigationCrossSiteNavigation) { | 318 TEST_F(NavigatorTest, BrowserSideNavigationCrossSiteNavigation) { |
224 const GURL kUrl1("http://www.chromium.org/"); | 319 const GURL kUrl1("http://www.chromium.org/"); |
225 const GURL kUrl2("http://www.google.com/"); | 320 const GURL kUrl2("http://www.google.com/"); |
226 | 321 |
227 contents()->NavigateAndCommit(kUrl1); | 322 contents()->NavigateAndCommit(kUrl1); |
228 RenderFrameHostImpl* rfh = main_test_rfh(); | 323 RenderFrameHostImpl* rfh = main_test_rfh(); |
229 EXPECT_EQ(RenderFrameHostImpl::STATE_DEFAULT, rfh->rfh_state()); | 324 EXPECT_EQ(RenderFrameHostImpl::STATE_DEFAULT, rfh->rfh_state()); |
230 FrameTreeNode* node = main_test_rfh()->frame_tree_node(); | 325 FrameTreeNode* node = main_test_rfh()->frame_tree_node(); |
231 | 326 |
232 EnableBrowserSideNavigation(); | 327 EnableBrowserSideNavigation(); |
233 | 328 |
234 // Navigate to a different site. | 329 // Navigate to a different site. |
235 SendRequestNavigation(node, kUrl2); | 330 SendRequestNavigation(node, kUrl2); |
236 main_test_rfh()->SendBeginNavigationWithURL(kUrl2); | 331 main_test_rfh()->SendBeginNavigationWithURL(kUrl2); |
237 NavigationRequest* main_request = GetNavigationRequestForFrameTreeNode(node); | 332 NavigationRequest* main_request = GetNavigationRequestForFrameTreeNode(node); |
238 ASSERT_TRUE(main_request); | 333 ASSERT_TRUE(main_request); |
239 | 334 |
240 scoped_refptr<ResourceResponse> response(new ResourceResponse); | 335 scoped_refptr<ResourceResponse> response(new ResourceResponse); |
241 node->navigator()->CommitNavigation( | 336 GetLoaderForNavigationRequest(main_request)->CallOnResponseStarted( |
242 node, response.get(), scoped_ptr<StreamHandle>(new TestStreamHandle)); | 337 response.get(), scoped_ptr<StreamHandle>(new TestStreamHandle)); |
243 RenderFrameHostImpl* pending_rfh = | 338 RenderFrameHostImpl* pending_rfh = |
244 node->render_manager()->pending_frame_host(); | 339 node->render_manager()->pending_frame_host(); |
245 ASSERT_TRUE(pending_rfh); | 340 ASSERT_TRUE(pending_rfh); |
| 341 EXPECT_NE(pending_rfh, rfh); |
| 342 EXPECT_TRUE(pending_rfh->IsRenderFrameLive()); |
| 343 EXPECT_TRUE(pending_rfh->render_view_host()->IsRenderViewLive()); |
| 344 } |
| 345 |
| 346 // PlzNavigate: Test that redirects are followed. |
| 347 TEST_F(NavigatorTest, BrowserSideNavigationRedirectCrossSite) { |
| 348 const GURL kUrl1("http://www.chromium.org/"); |
| 349 const GURL kUrl2("http://www.google.com/"); |
| 350 |
| 351 contents()->NavigateAndCommit(kUrl1); |
| 352 RenderFrameHostImpl* rfh = main_test_rfh(); |
| 353 EXPECT_EQ(RenderFrameHostImpl::STATE_DEFAULT, rfh->rfh_state()); |
| 354 FrameTreeNode* node = main_test_rfh()->frame_tree_node(); |
| 355 |
| 356 EnableBrowserSideNavigation(); |
| 357 |
| 358 // Navigate to a URL on the same site. |
| 359 SendRequestNavigation(node, kUrl1); |
| 360 main_test_rfh()->SendBeginNavigationWithURL(kUrl1); |
| 361 NavigationRequest* main_request = GetNavigationRequestForFrameTreeNode(node); |
| 362 ASSERT_TRUE(main_request); |
| 363 |
| 364 // It then redirects to another site. |
| 365 net::RedirectInfo redirect_info; |
| 366 redirect_info.status_code = 302; |
| 367 redirect_info.new_method = "GET"; |
| 368 redirect_info.new_url = kUrl2; |
| 369 redirect_info.new_first_party_for_cookies = kUrl2; |
| 370 scoped_refptr<ResourceResponse> response(new ResourceResponse); |
| 371 GetLoaderForNavigationRequest(main_request)->CallOnRequestRedirected( |
| 372 redirect_info, response.get()); |
| 373 |
| 374 // The redirect should have been followed. |
| 375 EXPECT_EQ(1, TestNavigationURLLoader::redirect_count()); |
| 376 |
| 377 // Then it commits. |
| 378 response = new ResourceResponse; |
| 379 GetLoaderForNavigationRequest(main_request)->CallOnResponseStarted( |
| 380 response.get(), scoped_ptr<StreamHandle>(new TestStreamHandle)); |
| 381 RenderFrameHostImpl* pending_rfh = |
| 382 node->render_manager()->pending_frame_host(); |
| 383 ASSERT_TRUE(pending_rfh); |
246 EXPECT_NE(pending_rfh, rfh); | 384 EXPECT_NE(pending_rfh, rfh); |
247 EXPECT_TRUE(pending_rfh->IsRenderFrameLive()); | 385 EXPECT_TRUE(pending_rfh->IsRenderFrameLive()); |
248 EXPECT_TRUE(pending_rfh->render_view_host()->IsRenderViewLive()); | 386 EXPECT_TRUE(pending_rfh->render_view_host()->IsRenderViewLive()); |
249 } | 387 } |
250 | 388 |
251 // PlzNavigate: Test that a navigation is cancelled if another request has been | 389 // PlzNavigate: Test that a navigation is cancelled if another request has been |
252 // issued in the meantime. | 390 // issued in the meantime. |
253 TEST_F(NavigatorTest, BrowserSideNavigationReplacePendingNavigation) { | 391 TEST_F(NavigatorTest, BrowserSideNavigationReplacePendingNavigation) { |
254 const GURL kUrl0("http://www.wikipedia.org/"); | 392 const GURL kUrl0("http://www.wikipedia.org/"); |
255 const GURL kUrl0_site = SiteInstance::GetSiteForURL(browser_context(), kUrl0); | 393 const GURL kUrl0_site = SiteInstance::GetSiteForURL(browser_context(), kUrl0); |
(...skipping 17 matching lines...) Expand all Loading... |
273 // Request navigation to the 2nd URL; the NavigationRequest must have been | 411 // Request navigation to the 2nd URL; the NavigationRequest must have been |
274 // replaced by a new one with a different URL. | 412 // replaced by a new one with a different URL. |
275 SendRequestNavigation(node, kUrl2); | 413 SendRequestNavigation(node, kUrl2); |
276 main_test_rfh()->SendBeginNavigationWithURL(kUrl2); | 414 main_test_rfh()->SendBeginNavigationWithURL(kUrl2); |
277 NavigationRequest* request2 = GetNavigationRequestForFrameTreeNode(node); | 415 NavigationRequest* request2 = GetNavigationRequestForFrameTreeNode(node); |
278 ASSERT_TRUE(request2); | 416 ASSERT_TRUE(request2); |
279 EXPECT_EQ(kUrl2, request2->common_params().url); | 417 EXPECT_EQ(kUrl2, request2->common_params().url); |
280 | 418 |
281 // Confirm that the commit corresonds to the new request. | 419 // Confirm that the commit corresonds to the new request. |
282 scoped_refptr<ResourceResponse> response(new ResourceResponse); | 420 scoped_refptr<ResourceResponse> response(new ResourceResponse); |
283 node->navigator()->CommitNavigation( | 421 GetLoaderForNavigationRequest(request2)->CallOnResponseStarted( |
284 node, response.get(), scoped_ptr<StreamHandle>(new TestStreamHandle)); | 422 response.get(), scoped_ptr<StreamHandle>(new TestStreamHandle)); |
285 RenderFrameHostImpl* pending_rfh = | 423 RenderFrameHostImpl* pending_rfh = |
286 node->render_manager()->pending_frame_host(); | 424 node->render_manager()->pending_frame_host(); |
287 ASSERT_TRUE(pending_rfh); | 425 ASSERT_TRUE(pending_rfh); |
288 EXPECT_EQ(kUrl2_site, pending_rfh->GetSiteInstance()->GetSiteURL()); | 426 EXPECT_EQ(kUrl2_site, pending_rfh->GetSiteInstance()->GetSiteURL()); |
289 } | 427 } |
290 | 428 |
291 // PlzNavigate: Tests that the navigation histograms are correctly tracked both | 429 // PlzNavigate: Tests that the navigation histograms are correctly tracked both |
292 // when PlzNavigate is enabled and disabled, and also ignores in-tab renderer | 430 // when PlzNavigate is enabled and disabled, and also ignores in-tab renderer |
293 // initiated navigation for the non-enabled case. | 431 // initiated navigation for the non-enabled case. |
294 // Note: the related histogram, Navigation.TimeToURLJobStart, cannot be tracked | 432 // Note: the related histogram, Navigation.TimeToURLJobStart, cannot be tracked |
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
342 NavigationController::RELOAD_IGNORING_CACHE); | 480 NavigationController::RELOAD_IGNORING_CACHE); |
343 contents()->GetMainFrame()->SendBeginNavigationWithURL(kUrl); | 481 contents()->GetMainFrame()->SendBeginNavigationWithURL(kUrl); |
344 // A NavigationRequest should have been generated. | 482 // A NavigationRequest should have been generated. |
345 main_request = GetNavigationRequestForFrameTreeNode(node); | 483 main_request = GetNavigationRequestForFrameTreeNode(node); |
346 ASSERT_TRUE(main_request != NULL); | 484 ASSERT_TRUE(main_request != NULL); |
347 EXPECT_EQ(FrameMsg_Navigate_Type::RELOAD_IGNORING_CACHE, | 485 EXPECT_EQ(FrameMsg_Navigate_Type::RELOAD_IGNORING_CACHE, |
348 main_request->common_params().navigation_type); | 486 main_request->common_params().navigation_type); |
349 } | 487 } |
350 | 488 |
351 } // namespace content | 489 } // namespace content |
OLD | NEW |