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