Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(75)

Side by Side Diff: content/browser/frame_host/navigator_impl_unittest.cc

Issue 701953006: PlzNavigate: Speculatively spawns a renderer process for navigations. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Addressed CR comments. Created 5 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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/macros.h" 6 #include "base/macros.h"
6 #include "base/time/time.h" 7 #include "base/time/time.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"
9 #include "content/browser/frame_host/navigation_request.h" 10 #include "content/browser/frame_host/navigation_request.h"
10 #include "content/browser/frame_host/navigation_request_info.h" 11 #include "content/browser/frame_host/navigation_request_info.h"
11 #include "content/browser/frame_host/navigator.h" 12 #include "content/browser/frame_host/navigator.h"
12 #include "content/browser/frame_host/navigator_impl.h" 13 #include "content/browser/frame_host/navigator_impl.h"
13 #include "content/browser/frame_host/render_frame_host_manager.h" 14 #include "content/browser/frame_host/render_frame_host_manager.h"
14 #include "content/browser/site_instance_impl.h" 15 #include "content/browser/site_instance_impl.h"
15 #include "content/browser/streams/stream.h" 16 #include "content/browser/streams/stream.h"
16 #include "content/common/navigation_params.h" 17 #include "content/common/navigation_params.h"
17 #include "content/public/browser/stream_handle.h" 18 #include "content/public/browser/stream_handle.h"
19 #include "content/public/common/content_switches.h"
18 #include "content/public/common/url_constants.h" 20 #include "content/public/common/url_constants.h"
19 #include "content/public/common/url_utils.h" 21 #include "content/public/common/url_utils.h"
22 #include "content/public/test/mock_render_process_host.h"
20 #include "content/test/browser_side_navigation_test_utils.h" 23 #include "content/test/browser_side_navigation_test_utils.h"
21 #include "content/test/test_navigation_url_loader.h" 24 #include "content/test/test_navigation_url_loader.h"
22 #include "content/test/test_render_frame_host.h" 25 #include "content/test/test_render_frame_host.h"
23 #include "content/test/test_web_contents.h" 26 #include "content/test/test_web_contents.h"
24 #include "net/base/load_flags.h" 27 #include "net/base/load_flags.h"
25 #include "net/http/http_response_headers.h" 28 #include "net/http/http_response_headers.h"
26 #include "net/url_request/redirect_info.h" 29 #include "net/url_request/redirect_info.h"
27 #include "ui/base/page_transition_types.h" 30 #include "ui/base/page_transition_types.h"
28 #include "url/url_constants.h" 31 #include "url/url_constants.h"
29 32
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
66 controller().GetBrowserContext()))); 69 controller().GetBrowserContext())));
67 static_cast<NavigatorImpl*>(node->navigator())->RequestNavigation( 70 static_cast<NavigatorImpl*>(node->navigator())->RequestNavigation(
68 node, *entry, reload_type, base::TimeTicks::Now()); 71 node, *entry, reload_type, base::TimeTicks::Now());
69 } 72 }
70 73
71 NavigationRequest* GetNavigationRequestForFrameTreeNode( 74 NavigationRequest* GetNavigationRequestForFrameTreeNode(
72 FrameTreeNode* frame_tree_node) { 75 FrameTreeNode* frame_tree_node) {
73 return static_cast<NavigatorImpl*>(frame_tree_node->navigator()) 76 return static_cast<NavigatorImpl*>(frame_tree_node->navigator())
74 ->GetNavigationRequestForNodeForTesting(frame_tree_node); 77 ->GetNavigationRequestForNodeForTesting(frame_tree_node);
75 } 78 }
79
80 TestRenderFrameHost* GetSpeculativeRenderFrameHost(FrameTreeNode* node) {
81 return static_cast<TestRenderFrameHost*>(
82 node->render_manager()->speculative_render_frame_host_.get());
83 }
84
85 // Checks if this RenderFrameHost sent a single FrameMsg_CommitNavigation
86 // since the last clearing of the sink.
87 // Note: user must call ClearMessages on the sink before the commit happens.
nasko 2015/01/06 00:03:17 nit: s/user/caller/
carlosk 2015/01/08 16:05:55 Done. I also updated the whole comment to (hopeful
nasko 2015/01/08 23:36:36 Acknowledged.
88 bool DidRenderFrameHostCommit(RenderFrameHostImpl* rfh) {
89 MockRenderProcessHost* rph =
90 static_cast<MockRenderProcessHost*>(rfh->GetProcess());
91 const FrameMsg_CommitNavigation* commitMessage =
nasko 2015/01/06 00:03:17 Don't use camelCase for variables, use hacker_case
carlosk 2015/01/08 16:05:55 Done.
92 static_cast<const FrameMsg_CommitNavigation*>(
93 rph->sink().GetUniqueMessageMatching(
94 FrameMsg_CommitNavigation::ID));
95 return commitMessage && rfh->GetRoutingID() == commitMessage->routing_id();
96 }
76 }; 97 };
77 98
99 // PlzNavigate: Test final state after a complete navigation (to avoid repeating
100 // these checks in other tests).
101 TEST_F(NavigatorTestWithBrowserSideNavigation, NavigationFinishedState) {
102 const GURL kUrl("http://chromium.org/");
103 contents()->NavigateAndCommit(kUrl);
104 ASSERT_TRUE(main_test_rfh());
105 EXPECT_EQ(RenderFrameHostImpl::STATE_DEFAULT, main_test_rfh()->rfh_state());
106 EXPECT_EQ(SiteInstanceImpl::GetSiteForURL(browser_context(), kUrl),
107 main_test_rfh()->GetSiteInstance()->GetSiteURL());
108
109 // After a navigation is finished no speculative RenderFrameHost should
110 // exist.
111 FrameTreeNode* node = main_test_rfh()->frame_tree_node();
112 EXPECT_FALSE(GetSpeculativeRenderFrameHost(node));
113
114 // With PlzNavigate enabled a pending RenderFrameHost should never exist.
115 EXPECT_FALSE(node->render_manager()->pending_frame_host());
nasko 2015/01/06 00:03:17 This feels like a useless check. Pending RFH is al
carlosk 2015/01/08 16:05:55 That's exactly why this check is here: to confirm
116 }
117
78 // PlzNavigate: Test that a proper NavigationRequest is created by 118 // PlzNavigate: Test that a proper NavigationRequest is created by
79 // BeginNavigation. 119 // BeginNavigation.
80 // Note that all PlzNavigate methods on the browser side require the use of the 120 // Note that all PlzNavigate methods on the browser side require the use of the
81 // flag kEnableBrowserSideNavigation. 121 // flag kEnableBrowserSideNavigation.
82 TEST_F(NavigatorTestWithBrowserSideNavigation, BeginNavigation) { 122 TEST_F(NavigatorTestWithBrowserSideNavigation, BeginNavigation) {
83 const GURL kUrl1("http://www.google.com/"); 123 const GURL kUrl1("http://www.google.com/");
84 const GURL kUrl2("http://www.chromium.org/"); 124 const GURL kUrl2("http://www.chromium.org/");
85 const GURL kUrl3("http://www.gmail.com/"); 125 const GURL kUrl3("http://www.gmail.com/");
86 126
87 contents()->NavigateAndCommit(kUrl1); 127 contents()->NavigateAndCommit(kUrl1);
88 128
89 // Add a subframe. 129 // Add a subframe.
90 FrameTreeNode* root = contents()->GetFrameTree()->root(); 130 FrameTreeNode* root_node = contents()->GetFrameTree()->root();
91 TestRenderFrameHost* subframe_rfh = static_cast<TestRenderFrameHost*>( 131 TestRenderFrameHost* subframe_rfh =
92 contents()->GetFrameTree()->AddFrame( 132 static_cast<TestRenderFrameHost*>(contents()->GetFrameTree()->AddFrame(
93 root, root->current_frame_host()->GetProcess()->GetID(), 14, 133 root_node, root_node->current_frame_host()->GetProcess()->GetID(), 14,
94 "Child")); 134 "Child"));
95 EXPECT_TRUE(subframe_rfh); 135 ASSERT_TRUE(subframe_rfh);
96 136
97 FrameTreeNode* subframe_node = subframe_rfh->frame_tree_node(); 137 FrameTreeNode* subframe_node = subframe_rfh->frame_tree_node();
98 SendRequestNavigation(subframe_rfh->frame_tree_node(), kUrl2); 138 SendRequestNavigation(subframe_node, kUrl2);
99 // There is no previous renderer in the subframe, so BeginNavigation is 139 // There is no previous renderer in the subframe, so BeginNavigation is
100 // handled already. 140 // handled already.
101 NavigationRequest* subframe_request = 141 NavigationRequest* subframe_request =
102 GetNavigationRequestForFrameTreeNode(subframe_node); 142 GetNavigationRequestForFrameTreeNode(subframe_node);
103 TestNavigationURLLoader* subframe_loader = 143 TestNavigationURLLoader* subframe_loader =
104 GetLoaderForNavigationRequest(subframe_request); 144 GetLoaderForNavigationRequest(subframe_request);
105 ASSERT_TRUE(subframe_request); 145 ASSERT_TRUE(subframe_request);
106 EXPECT_EQ(kUrl2, subframe_request->common_params().url); 146 EXPECT_EQ(kUrl2, subframe_request->common_params().url);
107 EXPECT_EQ(kUrl2, subframe_loader->common_params().url); 147 EXPECT_EQ(kUrl2, subframe_loader->common_params().url);
108 // First party for cookies url should be that of the main frame. 148 // First party for cookies url should be that of the main frame.
109 EXPECT_EQ(kUrl1, subframe_loader->request_info()->first_party_for_cookies); 149 EXPECT_EQ(kUrl1, subframe_loader->request_info()->first_party_for_cookies);
110 EXPECT_FALSE(subframe_loader->request_info()->is_main_frame); 150 EXPECT_FALSE(subframe_loader->request_info()->is_main_frame);
111 EXPECT_TRUE(subframe_loader->request_info()->parent_is_main_frame); 151 EXPECT_TRUE(subframe_loader->request_info()->parent_is_main_frame);
152 EXPECT_FALSE(GetSpeculativeRenderFrameHost(root_node));
112 153
113 SendRequestNavigation(root, kUrl3); 154 // Subframe navigations should never create a speculative RenderFrameHost,
155 // unless site-per-process is enabled. In that case as the subframe navigation
156 // is to a different site and is still ongoing, it should have one.
157 if (base::CommandLine::ForCurrentProcess()->HasSwitch(
158 switches::kSitePerProcess)) {
159 EXPECT_TRUE(GetSpeculativeRenderFrameHost(subframe_node));
160 } else {
161 EXPECT_FALSE(GetSpeculativeRenderFrameHost(subframe_node));
162 }
163
164 SendRequestNavigation(root_node, kUrl3);
114 // Simulate a BeginNavigation IPC on the main frame. 165 // Simulate a BeginNavigation IPC on the main frame.
115 contents()->GetMainFrame()->SendBeginNavigationWithURL(kUrl3); 166 main_test_rfh()->SendBeginNavigationWithURL(kUrl3);
116 NavigationRequest* main_request = GetNavigationRequestForFrameTreeNode(root); 167 NavigationRequest* main_request =
168 GetNavigationRequestForFrameTreeNode(root_node);
117 TestNavigationURLLoader* main_loader = 169 TestNavigationURLLoader* main_loader =
118 GetLoaderForNavigationRequest(main_request); 170 GetLoaderForNavigationRequest(main_request);
119 ASSERT_TRUE(main_request); 171 ASSERT_TRUE(main_request);
120 EXPECT_EQ(kUrl3, main_request->common_params().url); 172 EXPECT_EQ(kUrl3, main_request->common_params().url);
121 EXPECT_EQ(kUrl3, main_loader->common_params().url); 173 EXPECT_EQ(kUrl3, main_loader->common_params().url);
122 EXPECT_EQ(kUrl3, main_loader->request_info()->first_party_for_cookies); 174 EXPECT_EQ(kUrl3, main_loader->request_info()->first_party_for_cookies);
123 EXPECT_TRUE(main_loader->request_info()->is_main_frame); 175 EXPECT_TRUE(main_loader->request_info()->is_main_frame);
124 EXPECT_FALSE(main_loader->request_info()->parent_is_main_frame); 176 EXPECT_FALSE(main_loader->request_info()->parent_is_main_frame);
177
178 // Main frame navigation to a different site should use a speculative
179 // RenderFrameHost.
180 EXPECT_TRUE(GetSpeculativeRenderFrameHost(root_node));
181
182 // The above situation regarding subframe navigations is valid here.
nasko 2015/01/06 00:03:17 This seems invalid, since top-level navigation wil
carlosk 2015/01/08 16:05:55 That's not the case here because the main frame na
nasko 2015/01/08 23:36:37 Please add a comment saying that the main frame ha
carlosk 2015/01/09 14:48:51 Done.
183 if (base::CommandLine::ForCurrentProcess()->HasSwitch(
184 switches::kSitePerProcess)) {
185 EXPECT_TRUE(GetSpeculativeRenderFrameHost(subframe_node));
186 } else {
187 EXPECT_FALSE(GetSpeculativeRenderFrameHost(subframe_node));
188 }
125 } 189 }
126 190
127 // PlzNavigate: Test that RequestNavigation creates a NavigationRequest and that 191 // PlzNavigate: Test that RequestNavigation creates a NavigationRequest and that
128 // RenderFrameHost is not modified when the navigation commits. 192 // RenderFrameHost is not modified when the navigation commits.
129 TEST_F(NavigatorTestWithBrowserSideNavigation, NoLiveRenderer) { 193 TEST_F(NavigatorTestWithBrowserSideNavigation, NoLiveRenderer) {
130 const GURL kUrl("http://www.google.com/"); 194 const GURL kUrl("http://www.google.com/");
131 195
132 EXPECT_FALSE(main_test_rfh()->render_view_host()->IsRenderViewLive()); 196 EXPECT_FALSE(main_test_rfh()->render_view_host()->IsRenderViewLive());
133 FrameTreeNode* node = main_test_rfh()->frame_tree_node(); 197 RenderFrameHostImpl* rfh = main_test_rfh();
198 FrameTreeNode* node = rfh->frame_tree_node();
134 SendRequestNavigation(node, kUrl); 199 SendRequestNavigation(node, kUrl);
200
201 // A NavigationRequest should have been generated.
135 NavigationRequest* main_request = GetNavigationRequestForFrameTreeNode(node); 202 NavigationRequest* main_request = GetNavigationRequestForFrameTreeNode(node);
136 // A NavigationRequest should have been generated.
137 EXPECT_TRUE(main_request != NULL); 203 EXPECT_TRUE(main_request != NULL);
138 RenderFrameHostImpl* rfh = main_test_rfh(); 204
205 // As we're re-using the current RenderFrameHost, no speculative one should be
206 // created.
207 EXPECT_FALSE(GetSpeculativeRenderFrameHost(node));
139 208
140 // Now return the response without any redirects. This will cause the 209 // Now return the response without any redirects. This will cause the
141 // navigation to commit at the same URL. 210 // navigation to commit at the same URL.
142 scoped_refptr<ResourceResponse> response(new ResourceResponse); 211 scoped_refptr<ResourceResponse> response(new ResourceResponse);
143 GetLoaderForNavigationRequest(main_request)->CallOnResponseStarted( 212 GetLoaderForNavigationRequest(main_request)->CallOnResponseStarted(
144 response, MakeEmptyStream()); 213 response, MakeEmptyStream());
145 main_request = GetNavigationRequestForFrameTreeNode(node); 214 main_request = GetNavigationRequestForFrameTreeNode(node);
146 215
147 // The main RFH should not have been changed, and the renderer should have 216 // The main RFH should not have been changed, and the renderer should have
148 // been initialized. 217 // been initialized.
149 EXPECT_EQ(rfh, main_test_rfh()); 218 EXPECT_EQ(rfh, main_test_rfh());
150 EXPECT_TRUE(main_test_rfh()->IsRenderFrameLive()); 219 EXPECT_TRUE(main_test_rfh()->IsRenderFrameLive());
151 EXPECT_TRUE(main_test_rfh()->render_view_host()->IsRenderViewLive()); 220 EXPECT_TRUE(main_test_rfh()->render_view_host()->IsRenderViewLive());
152 } 221 }
153 222
154 // PlzNavigate: Test that commiting an HTTP 204 or HTTP 205 response cancels the 223 // PlzNavigate: Test that committing an HTTP 204 or HTTP 205 response cancels
155 // navigation. 224 // the navigation.
156 TEST_F(NavigatorTestWithBrowserSideNavigation, NoContent) { 225 TEST_F(NavigatorTestWithBrowserSideNavigation, NoContent) {
157 const GURL kUrl1("http://www.chromium.org/"); 226 const GURL kUrl1("http://www.chromium.org/");
158 const GURL kUrl2("http://www.google.com/"); 227 const GURL kUrl2("http://www.google.com/");
159 228
160 // Load a URL. 229 // Load a URL.
161 contents()->NavigateAndCommit(kUrl1); 230 contents()->NavigateAndCommit(kUrl1);
162 RenderFrameHostImpl* rfh = main_test_rfh();
163 EXPECT_EQ(RenderFrameHostImpl::STATE_DEFAULT, rfh->rfh_state());
164 FrameTreeNode* node = main_test_rfh()->frame_tree_node(); 231 FrameTreeNode* node = main_test_rfh()->frame_tree_node();
165 232
166 // Navigate to a different site. 233 // Navigate to a different site.
167 SendRequestNavigation(node, kUrl2); 234 process()->sink().ClearMessages();
nasko 2015/01/06 00:03:17 Why move away from this method? I like the fact th
carlosk 2015/01/08 16:05:55 The problem was that calling SendRequestNavigation
235 contents()->GetController().LoadURL(kUrl2, Referrer(),
236 ui::PAGE_TRANSITION_LINK, std::string());
168 main_test_rfh()->SendBeginNavigationWithURL(kUrl2); 237 main_test_rfh()->SendBeginNavigationWithURL(kUrl2);
238
169 NavigationRequest* main_request = GetNavigationRequestForFrameTreeNode(node); 239 NavigationRequest* main_request = GetNavigationRequestForFrameTreeNode(node);
170 ASSERT_TRUE(main_request); 240 ASSERT_TRUE(main_request);
171 241
242 // Navigations to a different site do create a speculative RenderFrameHost.
243 EXPECT_TRUE(GetSpeculativeRenderFrameHost(node));
244
172 // Commit an HTTP 204 response. 245 // Commit an HTTP 204 response.
173 scoped_refptr<ResourceResponse> response(new ResourceResponse); 246 scoped_refptr<ResourceResponse> response(new ResourceResponse);
174 const char kNoContentHeaders[] = "HTTP/1.1 204 No Content\0\0"; 247 const char kNoContentHeaders[] = "HTTP/1.1 204 No Content\0\0";
175 response->head.headers = new net::HttpResponseHeaders( 248 response->head.headers = new net::HttpResponseHeaders(
176 std::string(kNoContentHeaders, arraysize(kNoContentHeaders))); 249 std::string(kNoContentHeaders, arraysize(kNoContentHeaders)));
177 GetLoaderForNavigationRequest(main_request)->CallOnResponseStarted( 250 GetLoaderForNavigationRequest(main_request)->CallOnResponseStarted(
178 response, MakeEmptyStream()); 251 response, MakeEmptyStream());
179 252
180 // There should be no pending RenderFrameHost; the navigation was aborted. 253 // There should be no pending nor speculative RenderFrameHost; the navigation
254 // was aborted.
255 EXPECT_FALSE(DidRenderFrameHostCommit(main_test_rfh()));
181 EXPECT_FALSE(GetNavigationRequestForFrameTreeNode(node)); 256 EXPECT_FALSE(GetNavigationRequestForFrameTreeNode(node));
182 EXPECT_FALSE(node->render_manager()->pending_frame_host()); 257 EXPECT_FALSE(node->render_manager()->pending_frame_host());
258 EXPECT_FALSE(GetSpeculativeRenderFrameHost(node));
183 259
184 // Now, repeat the test with 205 Reset Content. 260 // Now, repeat the test with 205 Reset Content.
185 261
186 // Navigate to a different site again. 262 // Navigate to a different site again.
187 SendRequestNavigation(node, kUrl2); 263 process()->sink().ClearMessages();
264 contents()->GetController().LoadURL(kUrl2, Referrer(),
265 ui::PAGE_TRANSITION_LINK, std::string());
188 main_test_rfh()->SendBeginNavigationWithURL(kUrl2); 266 main_test_rfh()->SendBeginNavigationWithURL(kUrl2);
267
189 main_request = GetNavigationRequestForFrameTreeNode(node); 268 main_request = GetNavigationRequestForFrameTreeNode(node);
190 ASSERT_TRUE(main_request); 269 ASSERT_TRUE(main_request);
270 EXPECT_TRUE(GetSpeculativeRenderFrameHost(node));
191 271
192 // Commit an HTTP 205 response. 272 // Commit an HTTP 205 response.
193 response = new ResourceResponse; 273 response = new ResourceResponse;
194 const char kResetContentHeaders[] = "HTTP/1.1 205 Reset Content\0\0"; 274 const char kResetContentHeaders[] = "HTTP/1.1 205 Reset Content\0\0";
195 response->head.headers = new net::HttpResponseHeaders( 275 response->head.headers = new net::HttpResponseHeaders(
196 std::string(kResetContentHeaders, arraysize(kResetContentHeaders))); 276 std::string(kResetContentHeaders, arraysize(kResetContentHeaders)));
197 GetLoaderForNavigationRequest(main_request)->CallOnResponseStarted( 277 GetLoaderForNavigationRequest(main_request)->CallOnResponseStarted(
198 response, MakeEmptyStream()); 278 response, MakeEmptyStream());
199 279
200 // There should be no pending RenderFrameHost; the navigation was aborted. 280 // There should be no pending nor speculative RenderFrameHost; the navigation
281 // was aborted.
282 EXPECT_FALSE(DidRenderFrameHostCommit(main_test_rfh()));
201 EXPECT_FALSE(GetNavigationRequestForFrameTreeNode(node)); 283 EXPECT_FALSE(GetNavigationRequestForFrameTreeNode(node));
202 EXPECT_FALSE(node->render_manager()->pending_frame_host()); 284 EXPECT_FALSE(node->render_manager()->pending_frame_host());
285 EXPECT_FALSE(GetSpeculativeRenderFrameHost(node));
203 } 286 }
204 287
205 // PlzNavigate: Test that a new RenderFrameHost is created when doing a cross 288 // PlzNavigate: Test that a new RenderFrameHost is created when doing a cross
206 // site navigation. 289 // site navigation.
207 TEST_F(NavigatorTestWithBrowserSideNavigation, CrossSiteNavigation) { 290 TEST_F(NavigatorTestWithBrowserSideNavigation, CrossSiteNavigation) {
208 const GURL kUrl1("http://www.chromium.org/"); 291 const GURL kUrl1("http://www.chromium.org/");
209 const GURL kUrl2("http://www.google.com/"); 292 const GURL kUrl2("http://www.google.com/");
210 293
211 contents()->NavigateAndCommit(kUrl1); 294 contents()->NavigateAndCommit(kUrl1);
212 RenderFrameHostImpl* rfh = main_test_rfh(); 295 RenderFrameHostImpl* initial_rfh = main_test_rfh();
213 EXPECT_EQ(RenderFrameHostImpl::STATE_DEFAULT, rfh->rfh_state());
nasko 2015/01/06 00:03:17 Any reason for removing this check?
carlosk 2015/01/08 16:05:55 Yes. I moved all the repeating post-navigation che
214 FrameTreeNode* node = main_test_rfh()->frame_tree_node(); 296 FrameTreeNode* node = main_test_rfh()->frame_tree_node();
215 297
216 // Navigate to a different site. 298 // Navigate to a different site.
217 SendRequestNavigation(node, kUrl2); 299 process()->sink().ClearMessages();
300 contents()->GetController().LoadURL(kUrl2, Referrer(),
301 ui::PAGE_TRANSITION_LINK, std::string());
218 main_test_rfh()->SendBeginNavigationWithURL(kUrl2); 302 main_test_rfh()->SendBeginNavigationWithURL(kUrl2);
219 NavigationRequest* main_request = GetNavigationRequestForFrameTreeNode(node); 303 NavigationRequest* main_request = GetNavigationRequestForFrameTreeNode(node);
220 ASSERT_TRUE(main_request); 304 ASSERT_TRUE(main_request);
305 EXPECT_TRUE(GetSpeculativeRenderFrameHost(node));
221 306
222 scoped_refptr<ResourceResponse> response(new ResourceResponse); 307 scoped_refptr<ResourceResponse> response(new ResourceResponse);
223 GetLoaderForNavigationRequest(main_request)->CallOnResponseStarted( 308 GetLoaderForNavigationRequest(main_request)->CallOnResponseStarted(
224 response, MakeEmptyStream()); 309 response, MakeEmptyStream());
225 RenderFrameHostImpl* pending_rfh = 310 TestRenderFrameHost* speculative_rfh = GetSpeculativeRenderFrameHost(node);
226 node->render_manager()->pending_frame_host(); 311 ASSERT_TRUE(speculative_rfh);
227 ASSERT_TRUE(pending_rfh); 312 EXPECT_TRUE(DidRenderFrameHostCommit(speculative_rfh));
228 EXPECT_NE(pending_rfh, rfh); 313 EXPECT_FALSE(DidRenderFrameHostCommit(main_test_rfh()));
229 EXPECT_TRUE(pending_rfh->IsRenderFrameLive()); 314
230 EXPECT_TRUE(pending_rfh->render_view_host()->IsRenderViewLive()); 315 speculative_rfh->SendNavigate(0, kUrl2);
316
317 RenderFrameHostImpl* final_rfh = main_test_rfh();
318 ASSERT_TRUE(final_rfh);
nasko 2015/01/06 00:03:17 EXPECT_EQ(speculative_rfh, final_rfh)?
carlosk 2015/01/08 16:05:55 Done.
319 EXPECT_NE(initial_rfh, final_rfh);
320 EXPECT_TRUE(final_rfh->IsRenderFrameLive());
321 EXPECT_TRUE(final_rfh->render_view_host()->IsRenderViewLive());
322 EXPECT_FALSE(GetSpeculativeRenderFrameHost(node));
231 } 323 }
232 324
233 // PlzNavigate: Test that redirects are followed. 325 // PlzNavigate: Test that redirects are followed and the speculative renderer
326 // logic behaves as expected.
234 TEST_F(NavigatorTestWithBrowserSideNavigation, RedirectCrossSite) { 327 TEST_F(NavigatorTestWithBrowserSideNavigation, RedirectCrossSite) {
235 const GURL kUrl1("http://www.chromium.org/"); 328 const GURL kUrl1("http://www.chromium.org/");
236 const GURL kUrl2("http://www.google.com/"); 329 const GURL kUrl2("http://www.google.com/");
237 330
238 contents()->NavigateAndCommit(kUrl1); 331 contents()->NavigateAndCommit(kUrl1);
239 RenderFrameHostImpl* rfh = main_test_rfh(); 332 RenderFrameHostImpl* rfh = main_test_rfh();
240 EXPECT_EQ(RenderFrameHostImpl::STATE_DEFAULT, rfh->rfh_state());
241 FrameTreeNode* node = main_test_rfh()->frame_tree_node(); 333 FrameTreeNode* node = main_test_rfh()->frame_tree_node();
242 334
243 // Navigate to a URL on the same site. 335 // Navigate to a URL on the same site.
244 SendRequestNavigation(node, kUrl1); 336 process()->sink().ClearMessages();
337 contents()->GetController().LoadURL(kUrl1, Referrer(),
338 ui::PAGE_TRANSITION_LINK, std::string());
245 main_test_rfh()->SendBeginNavigationWithURL(kUrl1); 339 main_test_rfh()->SendBeginNavigationWithURL(kUrl1);
246 NavigationRequest* main_request = GetNavigationRequestForFrameTreeNode(node); 340 NavigationRequest* main_request = GetNavigationRequestForFrameTreeNode(node);
247 ASSERT_TRUE(main_request); 341 ASSERT_TRUE(main_request);
342 EXPECT_FALSE(GetSpeculativeRenderFrameHost(node));
248 343
249 // It then redirects to another site. 344 // It then redirects to another site.
250 net::RedirectInfo redirect_info; 345 net::RedirectInfo redirect_info;
251 redirect_info.status_code = 302; 346 redirect_info.status_code = 302;
252 redirect_info.new_method = "GET"; 347 redirect_info.new_method = "GET";
253 redirect_info.new_url = kUrl2; 348 redirect_info.new_url = kUrl2;
254 redirect_info.new_first_party_for_cookies = kUrl2; 349 redirect_info.new_first_party_for_cookies = kUrl2;
255 scoped_refptr<ResourceResponse> response(new ResourceResponse); 350 scoped_refptr<ResourceResponse> response(new ResourceResponse);
256 GetLoaderForNavigationRequest(main_request)->CallOnRequestRedirected( 351 GetLoaderForNavigationRequest(main_request)->CallOnRequestRedirected(
257 redirect_info, response); 352 redirect_info, response);
258 353
259 // The redirect should have been followed. 354 // The redirect should have been followed.
260 EXPECT_EQ(1, GetLoaderForNavigationRequest(main_request)->redirect_count()); 355 EXPECT_EQ(1, GetLoaderForNavigationRequest(main_request)->redirect_count());
356 EXPECT_FALSE(GetSpeculativeRenderFrameHost(node));
261 357
262 // Then it commits. 358 // Then it commits.
263 response = new ResourceResponse; 359 response = new ResourceResponse;
264 GetLoaderForNavigationRequest(main_request)->CallOnResponseStarted( 360 GetLoaderForNavigationRequest(main_request)->CallOnResponseStarted(
265 response, MakeEmptyStream()); 361 response, MakeEmptyStream());
266 RenderFrameHostImpl* pending_rfh = 362 TestRenderFrameHost* final_speculative_rfh =
267 node->render_manager()->pending_frame_host(); 363 GetSpeculativeRenderFrameHost(node);
268 ASSERT_TRUE(pending_rfh); 364 EXPECT_TRUE(final_speculative_rfh);
269 EXPECT_NE(pending_rfh, rfh); 365 EXPECT_TRUE(DidRenderFrameHostCommit(final_speculative_rfh));
270 EXPECT_TRUE(pending_rfh->IsRenderFrameLive()); 366
271 EXPECT_TRUE(pending_rfh->render_view_host()->IsRenderViewLive()); 367 // And commits provisional load.
368 final_speculative_rfh->SendNavigate(0, kUrl2);
369 RenderFrameHostImpl* final_rfh = main_test_rfh();
370 ASSERT_TRUE(final_rfh);
371 EXPECT_NE(rfh, final_rfh);
372 EXPECT_EQ(final_speculative_rfh, final_rfh);
373 EXPECT_TRUE(final_rfh->IsRenderFrameLive());
374 EXPECT_TRUE(final_rfh->render_view_host()->IsRenderViewLive());
375 EXPECT_FALSE(GetSpeculativeRenderFrameHost(node));
272 } 376 }
273 377
274 // PlzNavigate: Test that a navigation is cancelled if another request has been 378 // PlzNavigate: Test that a navigation is canceled if another request has been
275 // issued in the meantime. 379 // issued in the meantime. Also confirms that the speculative renderer is
380 // correctly updated in the process.
276 TEST_F(NavigatorTestWithBrowserSideNavigation, ReplacePendingNavigation) { 381 TEST_F(NavigatorTestWithBrowserSideNavigation, ReplacePendingNavigation) {
277 const GURL kUrl0("http://www.wikipedia.org/"); 382 const GURL kUrl0("http://www.wikipedia.org/");
278 const GURL kUrl0_site = SiteInstance::GetSiteForURL(browser_context(), kUrl0);
279 const GURL kUrl1("http://www.chromium.org/"); 383 const GURL kUrl1("http://www.chromium.org/");
384 const GURL kUrl1_site = SiteInstance::GetSiteForURL(browser_context(), kUrl1);
280 const GURL kUrl2("http://www.google.com/"); 385 const GURL kUrl2("http://www.google.com/");
281 const GURL kUrl2_site = SiteInstance::GetSiteForURL(browser_context(), kUrl2); 386 const GURL kUrl2_site = SiteInstance::GetSiteForURL(browser_context(), kUrl2);
282 387
283 // Initialization. 388 // Initialization.
284 contents()->NavigateAndCommit(kUrl0); 389 contents()->NavigateAndCommit(kUrl0);
285 FrameTreeNode* node = main_test_rfh()->frame_tree_node(); 390 FrameTreeNode* node = main_test_rfh()->frame_tree_node();
286 EXPECT_EQ(kUrl0_site, main_test_rfh()->GetSiteInstance()->GetSiteURL());
287 391
288 // Request navigation to the 1st URL. 392 // Request navigation to the 1st URL.
289 SendRequestNavigation(node, kUrl1); 393 process()->sink().ClearMessages();
394 contents()->GetController().LoadURL(kUrl1, Referrer(),
395 ui::PAGE_TRANSITION_LINK, std::string());
290 main_test_rfh()->SendBeginNavigationWithURL(kUrl1); 396 main_test_rfh()->SendBeginNavigationWithURL(kUrl1);
291 NavigationRequest* request1 = GetNavigationRequestForFrameTreeNode(node); 397 NavigationRequest* request1 = GetNavigationRequestForFrameTreeNode(node);
292 ASSERT_TRUE(request1); 398 ASSERT_TRUE(request1);
293 EXPECT_EQ(kUrl1, request1->common_params().url); 399 EXPECT_EQ(kUrl1, request1->common_params().url);
294 base::WeakPtr<TestNavigationURLLoader> loader1 = 400 base::WeakPtr<TestNavigationURLLoader> loader1 =
295 GetLoaderForNavigationRequest(request1)->AsWeakPtr(); 401 GetLoaderForNavigationRequest(request1)->AsWeakPtr();
296 402
403 // Confirm a speculative RFH was created.
404 TestRenderFrameHost* speculative_rfh = GetSpeculativeRenderFrameHost(node);
405 ASSERT_TRUE(speculative_rfh);
406 int32 site_instance_id_1 = speculative_rfh->GetSiteInstance()->GetId();
407 EXPECT_EQ(kUrl1_site, speculative_rfh->GetSiteInstance()->GetSiteURL());
408
297 // Request navigation to the 2nd URL; the NavigationRequest must have been 409 // Request navigation to the 2nd URL; the NavigationRequest must have been
298 // replaced by a new one with a different URL. 410 // replaced by a new one with a different URL.
299 SendRequestNavigation(node, kUrl2); 411 contents()->GetController().LoadURL(kUrl2, Referrer(),
412 ui::PAGE_TRANSITION_LINK, std::string());
300 main_test_rfh()->SendBeginNavigationWithURL(kUrl2); 413 main_test_rfh()->SendBeginNavigationWithURL(kUrl2);
301 NavigationRequest* request2 = GetNavigationRequestForFrameTreeNode(node); 414 NavigationRequest* request2 = GetNavigationRequestForFrameTreeNode(node);
302 ASSERT_TRUE(request2); 415 ASSERT_TRUE(request2);
303 EXPECT_EQ(kUrl2, request2->common_params().url); 416 EXPECT_EQ(kUrl2, request2->common_params().url);
304 417
305 // Confirm that the first loader got destroyed. 418 // Confirm that the first loader got destroyed.
306 EXPECT_FALSE(loader1); 419 EXPECT_FALSE(loader1);
307 420
308 // Confirm that the commit corresponds to the new request. 421 // Confirm that a new speculative RFH was created.
422 speculative_rfh = GetSpeculativeRenderFrameHost(node);
423 ASSERT_TRUE(speculative_rfh);
424 int32 site_instance_id_2 = speculative_rfh->GetSiteInstance()->GetId();
425 EXPECT_NE(site_instance_id_1, site_instance_id_2);
426
427 // Commit.
309 scoped_refptr<ResourceResponse> response(new ResourceResponse); 428 scoped_refptr<ResourceResponse> response(new ResourceResponse);
310 GetLoaderForNavigationRequest(request2)->CallOnResponseStarted( 429 GetLoaderForNavigationRequest(request2)->CallOnResponseStarted(
311 response, MakeEmptyStream()); 430 response, MakeEmptyStream());
312 RenderFrameHostImpl* pending_rfh = 431 EXPECT_TRUE(DidRenderFrameHostCommit(speculative_rfh));
313 node->render_manager()->pending_frame_host(); 432 EXPECT_FALSE(DidRenderFrameHostCommit(main_test_rfh()));
314 ASSERT_TRUE(pending_rfh); 433
315 EXPECT_EQ(kUrl2_site, pending_rfh->GetSiteInstance()->GetSiteURL()); 434 // And commit provisional load.
435 speculative_rfh->SendNavigate(0, kUrl2);
436
437 // Confirm that the commit corresponds to the new request.
438 ASSERT_TRUE(main_test_rfh());
439 EXPECT_EQ(kUrl2_site, main_test_rfh()->GetSiteInstance()->GetSiteURL());
440
441 // Confirm that the committed RFH is the new speculative one.
442 EXPECT_EQ(site_instance_id_2, main_test_rfh()->GetSiteInstance()->GetId());
316 } 443 }
317 444
318 // PlzNavigate: Test that a reload navigation is properly signaled to the 445 // PlzNavigate: Test that a reload navigation is properly signaled to the
319 // renderer when the navigation can commit. 446 // renderer when the navigation can commit. Speculative renderers should not be
447 // created at any step.
320 TEST_F(NavigatorTestWithBrowserSideNavigation, Reload) { 448 TEST_F(NavigatorTestWithBrowserSideNavigation, Reload) {
321 const GURL kUrl("http://www.google.com/"); 449 const GURL kUrl("http://www.google.com/");
322 contents()->NavigateAndCommit(kUrl); 450 contents()->NavigateAndCommit(kUrl);
323 451
324 FrameTreeNode* node = main_test_rfh()->frame_tree_node(); 452 FrameTreeNode* node = main_test_rfh()->frame_tree_node();
325 SendRequestNavigationWithParameters( 453 SendRequestNavigationWithParameters(
326 node, kUrl, Referrer(), ui::PAGE_TRANSITION_LINK, 454 node, kUrl, Referrer(), ui::PAGE_TRANSITION_LINK,
327 NavigationController::RELOAD); 455 NavigationController::RELOAD);
328 contents()->GetMainFrame()->SendBeginNavigationWithURL(kUrl); 456 main_test_rfh()->SendBeginNavigationWithURL(kUrl);
329 // A NavigationRequest should have been generated. 457 // A NavigationRequest should have been generated.
330 NavigationRequest* main_request = 458 NavigationRequest* main_request =
331 GetNavigationRequestForFrameTreeNode(node); 459 GetNavigationRequestForFrameTreeNode(node);
332 ASSERT_TRUE(main_request != NULL); 460 ASSERT_TRUE(main_request != NULL);
333 EXPECT_EQ(FrameMsg_Navigate_Type::RELOAD, 461 EXPECT_EQ(FrameMsg_Navigate_Type::RELOAD,
334 main_request->common_params().navigation_type); 462 main_request->common_params().navigation_type);
335 int page_id = contents()->GetMaxPageIDForSiteInstance( 463 EXPECT_FALSE(GetSpeculativeRenderFrameHost(node));
336 main_test_rfh()->GetSiteInstance()) + 1; 464
337 main_test_rfh()->SendNavigate(page_id, kUrl); 465 main_test_rfh()->SendNavigate(0, kUrl);
466 EXPECT_FALSE(GetSpeculativeRenderFrameHost(node));
338 467
339 // Now do a shift+reload. 468 // Now do a shift+reload.
340 SendRequestNavigationWithParameters( 469 SendRequestNavigationWithParameters(
341 node, kUrl, Referrer(), ui::PAGE_TRANSITION_LINK, 470 node, kUrl, Referrer(), ui::PAGE_TRANSITION_LINK,
342 NavigationController::RELOAD_IGNORING_CACHE); 471 NavigationController::RELOAD_IGNORING_CACHE);
343 contents()->GetMainFrame()->SendBeginNavigationWithURL(kUrl); 472 main_test_rfh()->SendBeginNavigationWithURL(kUrl);
344 // A NavigationRequest should have been generated. 473 // A NavigationRequest should have been generated.
345 main_request = GetNavigationRequestForFrameTreeNode(node); 474 main_request = GetNavigationRequestForFrameTreeNode(node);
346 ASSERT_TRUE(main_request != NULL); 475 ASSERT_TRUE(main_request != NULL);
347 EXPECT_EQ(FrameMsg_Navigate_Type::RELOAD_IGNORING_CACHE, 476 EXPECT_EQ(FrameMsg_Navigate_Type::RELOAD_IGNORING_CACHE,
348 main_request->common_params().navigation_type); 477 main_request->common_params().navigation_type);
478 EXPECT_FALSE(GetSpeculativeRenderFrameHost(node));
479 }
480
481 // PlzNavigate: Confirm that a speculative RenderFrameHost is used when
482 // navigating from one site to the another.
483 TEST_F(NavigatorTestWithBrowserSideNavigation,
484 SpeculativeRendererWorksBaseCase) {
485 // Navigate to an initial site.
486 const GURL kUrlInit("http://wikipedia.org/");
487 contents()->NavigateAndCommit(kUrlInit);
488 FrameTreeNode* node = main_test_rfh()->frame_tree_node();
489
490 // Begin navigating to another site.
491 const GURL kUrl("http://google.com/");
492 process()->sink().ClearMessages();
493 contents()->GetController().LoadURL(kUrl, Referrer(),
494 ui::PAGE_TRANSITION_LINK, std::string());
495 main_test_rfh()->SendBeginNavigationWithURL(kUrl);
496 TestRenderFrameHost* speculative_rfh = GetSpeculativeRenderFrameHost(node);
497 ASSERT_TRUE(speculative_rfh);
498 EXPECT_NE(speculative_rfh, main_test_rfh());
499 EXPECT_EQ(SiteInstanceImpl::GetSiteForURL(browser_context(), kUrl),
500 speculative_rfh->GetSiteInstance()->GetSiteURL());
501 EXPECT_FALSE(node->render_manager()->pending_frame_host());
502 int32 site_instance_id = speculative_rfh->GetSiteInstance()->GetId();
503
504 // Ask Navigator to commit the navigation by simulating a call to
505 // OnResponseStarted.
506 scoped_refptr<ResourceResponse> response(new ResourceResponse);
507 GetLoaderForNavigationRequest(GetNavigationRequestForFrameTreeNode(node))
508 ->CallOnResponseStarted(response, MakeEmptyStream());
509 speculative_rfh = GetSpeculativeRenderFrameHost(node);
510 ASSERT_TRUE(speculative_rfh);
511 EXPECT_TRUE(DidRenderFrameHostCommit(speculative_rfh));
512 EXPECT_EQ(site_instance_id, speculative_rfh->GetSiteInstance()->GetId());
513 EXPECT_FALSE(node->render_manager()->pending_frame_host());
514
515 // Invoke OnDidCommitProvisionalLoad.
516 speculative_rfh->SendNavigate(0, kUrl);
517 EXPECT_EQ(site_instance_id, main_test_rfh()->GetSiteInstance()->GetId());
518 EXPECT_FALSE(GetSpeculativeRenderFrameHost(node));
519 EXPECT_FALSE(node->render_manager()->pending_frame_host());
520 }
521
522 // PlzNavigate: Confirm that a speculative RenderFrameHost is thrown away when
523 // the final URL's site differs from the initial one due to redirects.
524 TEST_F(NavigatorTestWithBrowserSideNavigation,
525 SpeculativeRendererDiscardedAfterRedirectToAnotherSite) {
526 // Navigate to an initial site.
527 const GURL kUrlInit("http://wikipedia.org/");
528 contents()->NavigateAndCommit(kUrlInit);
529 FrameTreeNode* node = main_test_rfh()->frame_tree_node();
530 int32 init_site_instance_id = main_test_rfh()->GetSiteInstance()->GetId();
531
532 // Begin navigating to another site.
533 const GURL kUrl("http://google.com/");
534 process()->sink().ClearMessages();
535 contents()->GetController().LoadURL(kUrl, Referrer(),
536 ui::PAGE_TRANSITION_LINK, std::string());
537 main_test_rfh()->SendBeginNavigationWithURL(kUrl);
538 TestRenderFrameHost* speculative_rfh = GetSpeculativeRenderFrameHost(node);
539 int32 site_instance_id = speculative_rfh->GetSiteInstance()->GetId();
540 EXPECT_EQ(init_site_instance_id, main_test_rfh()->GetSiteInstance()->GetId());
541 ASSERT_TRUE(speculative_rfh);
542 EXPECT_NE(speculative_rfh, main_test_rfh());
543 EXPECT_EQ(SiteInstanceImpl::GetSiteForURL(browser_context(), kUrl),
544 speculative_rfh->GetSiteInstance()->GetSiteURL());
545
546 // It then redirects to yet another site.
547 NavigationRequest* main_request = GetNavigationRequestForFrameTreeNode(node);
548 ASSERT_TRUE(main_request);
549 const GURL kUrlRedirect("https://www.google.com/");
550 net::RedirectInfo redirect_info;
551 redirect_info.status_code = 302;
552 redirect_info.new_method = "GET";
553 redirect_info.new_url = kUrlRedirect;
554 redirect_info.new_first_party_for_cookies = kUrlRedirect;
555 scoped_refptr<ResourceResponse> response(new ResourceResponse);
556 GetLoaderForNavigationRequest(main_request)
557 ->CallOnRequestRedirected(redirect_info, response);
558 EXPECT_EQ(init_site_instance_id, main_test_rfh()->GetSiteInstance()->GetId());
559 speculative_rfh = GetSpeculativeRenderFrameHost(node);
560 ASSERT_TRUE(speculative_rfh);
561
562 // TODO(carlosk): once the speculative RenderFrameHost updates with redirects
563 // this next check will be changed to verify that it actually happens.
564 EXPECT_EQ(site_instance_id, speculative_rfh->GetSiteInstance()->GetId());
565
566 // Commit the navigation with Navigator by simulating the call to
567 // OnResponseStarted.
568 response = new ResourceResponse;
569 GetLoaderForNavigationRequest(main_request)
570 ->CallOnResponseStarted(response, MakeEmptyStream());
571 speculative_rfh = GetSpeculativeRenderFrameHost(node);
572 EXPECT_TRUE(DidRenderFrameHostCommit(speculative_rfh));
573 EXPECT_EQ(init_site_instance_id, main_test_rfh()->GetSiteInstance()->GetId());
574
575 // Once commit happens the speculative RenderFrameHost is already updated to
576 // match the known final SiteInstance.
577 ASSERT_TRUE(speculative_rfh);
578 EXPECT_EQ(SiteInstanceImpl::GetSiteForURL(browser_context(), kUrlRedirect),
579 speculative_rfh->GetSiteInstance()->GetSiteURL());
580 int32 redirect_site_instance_id = speculative_rfh->GetSiteInstance()->GetId();
581
582 // Invoke OnDidCommitProvisionalLoad.
583 speculative_rfh->SendNavigate(0, kUrlRedirect);
584
585 // Check that the speculative RenderFrameHost was swapped in.
586 EXPECT_EQ(redirect_site_instance_id,
587 main_test_rfh()->GetSiteInstance()->GetId());
588 EXPECT_FALSE(GetSpeculativeRenderFrameHost(node));
589 }
590
591 // PlzNavigate: Verify that a previously swapped out RenderFrameHost is
592 // correctly reused when spawning a speculative RenderFrameHost in a navigation
593 // using the same SiteInstance.
594 TEST_F(NavigatorTestWithBrowserSideNavigation,
595 SpeculativeRendererReuseSwappedOutRFH) {
596 // Navigate to an initial site.
597 const GURL kUrl1("http://wikipedia.org/");
598 contents()->NavigateAndCommit(kUrl1);
599 RenderFrameHostImpl* rfh1 = main_test_rfh();
600 FrameTreeNode* node = rfh1->frame_tree_node();
601 RenderFrameHostManager* rfhm = node->render_manager();
602
603 // Increment active frame count to cause the RenderFrameHost to be swapped out
604 // (instead of immediately destroyed).
605 rfh1->GetSiteInstance()->increment_active_frame_count();
606
607 // Navigate to another site to swap out the initial RenderFrameHost.
608 const GURL kUrl2("http://chromium.org/");
609 contents()->NavigateAndCommit(kUrl2);
610 ASSERT_NE(rfh1, main_test_rfh());
611 EXPECT_NE(RenderFrameHostImpl::STATE_DEFAULT, rfh1->rfh_state());
612 EXPECT_EQ(RenderFrameHostImpl::STATE_DEFAULT, main_test_rfh()->rfh_state());
613 EXPECT_TRUE(rfhm->IsOnSwappedOutList(rfh1));
614
615 // Now go back to the initial site so that the swapped out RenderFrameHost
616 // should be reused.
617 process()->sink().ClearMessages();
618 static_cast<MockRenderProcessHost*>(rfh1->GetProcess())
619 ->sink()
620 .ClearMessages();
621 contents()->GetController().LoadURL(kUrl1, Referrer(),
622 ui::PAGE_TRANSITION_LINK, std::string());
623 main_test_rfh()->SendBeginNavigationWithURL(kUrl1);
624 EXPECT_EQ(rfh1, GetSpeculativeRenderFrameHost(node));
625 EXPECT_NE(RenderFrameHostImpl::STATE_DEFAULT,
626 GetSpeculativeRenderFrameHost(node)->rfh_state());
627
628 scoped_refptr<ResourceResponse> response(new ResourceResponse);
629 GetLoaderForNavigationRequest(GetNavigationRequestForFrameTreeNode(node))
630 ->CallOnResponseStarted(response, MakeEmptyStream());
631 EXPECT_EQ(rfh1, GetSpeculativeRenderFrameHost(node));
632 EXPECT_EQ(RenderFrameHostImpl::STATE_DEFAULT,
633 GetSpeculativeRenderFrameHost(node)->rfh_state());
634 EXPECT_TRUE(DidRenderFrameHostCommit(rfh1));
635 EXPECT_FALSE(DidRenderFrameHostCommit(main_test_rfh()));
636
637 contents()->CommitPendingNavigation();
638 EXPECT_EQ(rfh1, main_test_rfh());
639 EXPECT_EQ(RenderFrameHostImpl::STATE_DEFAULT, rfh1->rfh_state());
640 EXPECT_FALSE(rfhm->IsOnSwappedOutList(rfh1));
349 } 641 }
350 642
351 } // namespace content 643 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698