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