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

Side by Side Diff: content/browser/tab_contents/render_view_host_manager_unittest.cc

Issue 9473001: Extract minimal RenderViewHost interface for embedders, leaving (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Merge to LKGR. Created 8 years, 9 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 | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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/utf_string_conversions.h" 5 #include "base/utf_string_conversions.h"
6 #include "content/browser/browser_thread_impl.h" 6 #include "content/browser/browser_thread_impl.h"
7 #include "content/browser/browser_url_handler.h" 7 #include "content/browser/browser_url_handler.h"
8 #include "content/browser/mock_content_browser_client.h" 8 #include "content/browser/mock_content_browser_client.h"
9 #include "content/browser/renderer_host/test_render_view_host.h" 9 #include "content/browser/renderer_host/test_render_view_host.h"
10 #include "content/browser/site_instance_impl.h" 10 #include "content/browser/site_instance_impl.h"
(...skipping 132 matching lines...) Expand 10 before | Expand all | Expand 10 after
143 controller().LoadURL( 143 controller().LoadURL(
144 url, content::Referrer(), content::PAGE_TRANSITION_LINK, std::string()); 144 url, content::Referrer(), content::PAGE_TRANSITION_LINK, std::string());
145 TestRenderViewHost* old_rvh = rvh(); 145 TestRenderViewHost* old_rvh = rvh();
146 146
147 // Simulate the ShouldClose_ACK that is received from the current renderer 147 // Simulate the ShouldClose_ACK that is received from the current renderer
148 // for a cross-site navigation. 148 // for a cross-site navigation.
149 if (old_rvh != active_rvh()) 149 if (old_rvh != active_rvh())
150 old_rvh->SendShouldCloseACK(true); 150 old_rvh->SendShouldCloseACK(true);
151 151
152 // Commit the navigation with a new page ID. 152 // Commit the navigation with a new page ID.
153 int32 max_page_id = 153 int32 max_page_id = contents()->GetMaxPageIDForSiteInstance(
154 contents()->GetMaxPageIDForSiteInstance(active_rvh()->site_instance()); 154 active_rvh()->GetSiteInstance());
155 active_rvh()->SendNavigate(max_page_id + 1, url); 155 active_rvh()->SendNavigate(max_page_id + 1, url);
156 156
157 // Simulate the SwapOut_ACK that fires if you commit a cross-site navigation 157 // Simulate the SwapOut_ACK that fires if you commit a cross-site navigation
158 // without making any network requests. 158 // without making any network requests.
159 if (old_rvh != active_rvh()) 159 if (old_rvh != active_rvh())
160 old_rvh->OnSwapOutACK(); 160 old_rvh->OnSwapOutACK();
161 } 161 }
162 162
163 bool ShouldSwapProcesses(RenderViewHostManager* manager, 163 bool ShouldSwapProcesses(RenderViewHostManager* manager,
164 const NavigationEntryImpl* cur_entry, 164 const NavigationEntryImpl* cur_entry,
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
205 std::string()); 205 std::string());
206 EXPECT_TRUE(contents2.cross_navigation_pending()); 206 EXPECT_TRUE(contents2.cross_navigation_pending());
207 TestRenderViewHost* dest_rvh2 = static_cast<TestRenderViewHost*>( 207 TestRenderViewHost* dest_rvh2 = static_cast<TestRenderViewHost*>(
208 contents2.GetRenderManagerForTesting()->pending_render_view_host()); 208 contents2.GetRenderManagerForTesting()->pending_render_view_host());
209 ASSERT_TRUE(dest_rvh2); 209 ASSERT_TRUE(dest_rvh2);
210 ntp_rvh2->SendShouldCloseACK(true); 210 ntp_rvh2->SendShouldCloseACK(true);
211 dest_rvh2->SendNavigate(101, kDestUrl); 211 dest_rvh2->SendNavigate(101, kDestUrl);
212 ntp_rvh2->OnSwapOutACK(); 212 ntp_rvh2->OnSwapOutACK();
213 213
214 // The two RVH's should be different in every way. 214 // The two RVH's should be different in every way.
215 EXPECT_NE(active_rvh()->process(), dest_rvh2->process()); 215 EXPECT_NE(active_rvh()->GetProcess(), dest_rvh2->GetProcess());
216 EXPECT_NE(active_rvh()->site_instance(), dest_rvh2->site_instance()); 216 EXPECT_NE(active_rvh()->GetSiteInstance(), dest_rvh2->GetSiteInstance());
217 EXPECT_NE(static_cast<SiteInstanceImpl*>(active_rvh()->site_instance())-> 217 EXPECT_NE(static_cast<SiteInstanceImpl*>(active_rvh()->GetSiteInstance())->
218 browsing_instance_, 218 browsing_instance_,
219 static_cast<SiteInstanceImpl*>(dest_rvh2->site_instance())-> 219 static_cast<SiteInstanceImpl*>(dest_rvh2->GetSiteInstance())->
220 browsing_instance_); 220 browsing_instance_);
221 221
222 // Navigate both to the new tab page, and verify that they share a 222 // Navigate both to the new tab page, and verify that they share a
223 // SiteInstance. 223 // SiteInstance.
224 NavigateActiveAndCommit(kNtpUrl); 224 NavigateActiveAndCommit(kNtpUrl);
225 225
226 contents2.GetController().LoadURL( 226 contents2.GetController().LoadURL(
227 kNtpUrl, content::Referrer(), content::PAGE_TRANSITION_LINK, 227 kNtpUrl, content::Referrer(), content::PAGE_TRANSITION_LINK,
228 std::string()); 228 std::string());
229 dest_rvh2->SendShouldCloseACK(true); 229 dest_rvh2->SendShouldCloseACK(true);
230 static_cast<TestRenderViewHost*>(contents2.GetRenderManagerForTesting()-> 230 static_cast<TestRenderViewHost*>(contents2.GetRenderManagerForTesting()->
231 pending_render_view_host())->SendNavigate(102, kNtpUrl); 231 pending_render_view_host())->SendNavigate(102, kNtpUrl);
232 dest_rvh2->OnSwapOutACK(); 232 dest_rvh2->OnSwapOutACK();
233 233
234 EXPECT_EQ(active_rvh()->site_instance(), 234 EXPECT_EQ(active_rvh()->GetSiteInstance(),
235 contents2.GetRenderViewHost()->site_instance()); 235 contents2.GetRenderViewHost()->GetSiteInstance());
236 } 236 }
237 237
238 // Ensure that the browser ignores most IPC messages that arrive from a 238 // Ensure that the browser ignores most IPC messages that arrive from a
239 // RenderViewHost that has been swapped out. We do not want to take 239 // RenderViewHost that has been swapped out. We do not want to take
240 // action on requests from a non-active renderer. The main exception is 240 // action on requests from a non-active renderer. The main exception is
241 // for synchronous messages, which cannot be ignored without leaving the 241 // for synchronous messages, which cannot be ignored without leaving the
242 // renderer in a stuck state. See http://crbug.com/93427. 242 // renderer in a stuck state. See http://crbug.com/93427.
243 TEST_F(RenderViewHostManagerTest, FilterMessagesWhileSwappedOut) { 243 TEST_F(RenderViewHostManagerTest, FilterMessagesWhileSwappedOut) {
244 BrowserThreadImpl ui_thread(BrowserThread::UI, MessageLoop::current()); 244 BrowserThreadImpl ui_thread(BrowserThread::UI, MessageLoop::current());
245 const GURL kNtpUrl(chrome::kTestNewTabURL); 245 const GURL kNtpUrl(chrome::kTestNewTabURL);
246 const GURL kDestUrl("http://www.google.com/"); 246 const GURL kDestUrl("http://www.google.com/");
247 247
248 // Navigate our first tab to the new tab page and then to the destination. 248 // Navigate our first tab to the new tab page and then to the destination.
249 NavigateActiveAndCommit(kNtpUrl); 249 NavigateActiveAndCommit(kNtpUrl);
250 TestRenderViewHost* ntp_rvh = static_cast<TestRenderViewHost*>( 250 TestRenderViewHost* ntp_rvh = static_cast<TestRenderViewHost*>(
251 contents()->GetRenderManagerForTesting()->current_host()); 251 contents()->GetRenderManagerForTesting()->current_host());
252 252
253 // Send an update title message and make sure it works. 253 // Send an update title message and make sure it works.
254 const string16 ntp_title = ASCIIToUTF16("NTP Title"); 254 const string16 ntp_title = ASCIIToUTF16("NTP Title");
255 WebKit::WebTextDirection direction = WebKit::WebTextDirectionLeftToRight; 255 WebKit::WebTextDirection direction = WebKit::WebTextDirectionLeftToRight;
256 EXPECT_TRUE(ntp_rvh->TestOnMessageReceived( 256 EXPECT_TRUE(ntp_rvh->TestOnMessageReceived(
257 ViewHostMsg_UpdateTitle(rvh()->routing_id(), 0, ntp_title, direction))); 257 ViewHostMsg_UpdateTitle(rvh()->GetRoutingID(), 0, ntp_title, direction)));
258 EXPECT_EQ(ntp_title, contents()->GetTitle()); 258 EXPECT_EQ(ntp_title, contents()->GetTitle());
259 259
260 // Navigate to a cross-site URL. 260 // Navigate to a cross-site URL.
261 contents()->GetController().LoadURL( 261 contents()->GetController().LoadURL(
262 kDestUrl, content::Referrer(), content::PAGE_TRANSITION_LINK, 262 kDestUrl, content::Referrer(), content::PAGE_TRANSITION_LINK,
263 std::string()); 263 std::string());
264 EXPECT_TRUE(contents()->cross_navigation_pending()); 264 EXPECT_TRUE(contents()->cross_navigation_pending());
265 TestRenderViewHost* dest_rvh = static_cast<TestRenderViewHost*>( 265 TestRenderViewHost* dest_rvh = static_cast<TestRenderViewHost*>(
266 contents()->GetRenderManagerForTesting()->pending_render_view_host()); 266 contents()->GetRenderManagerForTesting()->pending_render_view_host());
267 ASSERT_TRUE(dest_rvh); 267 ASSERT_TRUE(dest_rvh);
268 EXPECT_NE(ntp_rvh, dest_rvh); 268 EXPECT_NE(ntp_rvh, dest_rvh);
269 269
270 // BeforeUnload finishes. 270 // BeforeUnload finishes.
271 ntp_rvh->SendShouldCloseACK(true); 271 ntp_rvh->SendShouldCloseACK(true);
272 272
273 // Assume SwapOutACK times out, so the dest_rvh proceeds and commits. 273 // Assume SwapOutACK times out, so the dest_rvh proceeds and commits.
274 dest_rvh->SendNavigate(101, kDestUrl); 274 dest_rvh->SendNavigate(101, kDestUrl);
275 275
276 // The new RVH should be able to update its title. 276 // The new RVH should be able to update its title.
277 const string16 dest_title = ASCIIToUTF16("Google"); 277 const string16 dest_title = ASCIIToUTF16("Google");
278 EXPECT_TRUE(dest_rvh->TestOnMessageReceived( 278 EXPECT_TRUE(dest_rvh->TestOnMessageReceived(
279 ViewHostMsg_UpdateTitle(rvh()->routing_id(), 101, dest_title, 279 ViewHostMsg_UpdateTitle(rvh()->GetRoutingID(), 101, dest_title,
280 direction))); 280 direction)));
281 EXPECT_EQ(dest_title, contents()->GetTitle()); 281 EXPECT_EQ(dest_title, contents()->GetTitle());
282 282
283 // The old renderer, being slow, now updates the title. It should be filtered 283 // The old renderer, being slow, now updates the title. It should be filtered
284 // out and not take effect. 284 // out and not take effect.
285 EXPECT_TRUE(ntp_rvh->is_swapped_out()); 285 EXPECT_TRUE(ntp_rvh->is_swapped_out());
286 EXPECT_TRUE(ntp_rvh->TestOnMessageReceived( 286 EXPECT_TRUE(ntp_rvh->TestOnMessageReceived(
287 ViewHostMsg_UpdateTitle(rvh()->routing_id(), 0, ntp_title, direction))); 287 ViewHostMsg_UpdateTitle(rvh()->GetRoutingID(), 0, ntp_title, direction)));
288 EXPECT_EQ(dest_title, contents()->GetTitle()); 288 EXPECT_EQ(dest_title, contents()->GetTitle());
289 289
290 // We cannot filter out synchronous IPC messages, because the renderer would 290 // We cannot filter out synchronous IPC messages, because the renderer would
291 // be left waiting for a reply. We pick RunBeforeUnloadConfirm as an example 291 // be left waiting for a reply. We pick RunBeforeUnloadConfirm as an example
292 // that can run easily within a unit test, and that needs to receive a reply 292 // that can run easily within a unit test, and that needs to receive a reply
293 // without showing an actual dialog. 293 // without showing an actual dialog.
294 MockRenderProcessHost* ntp_process_host = 294 MockRenderProcessHost* ntp_process_host =
295 static_cast<MockRenderProcessHost*>(ntp_rvh->process()); 295 static_cast<MockRenderProcessHost*>(ntp_rvh->GetProcess());
296 ntp_process_host->sink().ClearMessages(); 296 ntp_process_host->sink().ClearMessages();
297 const string16 msg = ASCIIToUTF16("Message"); 297 const string16 msg = ASCIIToUTF16("Message");
298 bool result = false; 298 bool result = false;
299 string16 unused; 299 string16 unused;
300 ViewHostMsg_RunBeforeUnloadConfirm before_unload_msg( 300 ViewHostMsg_RunBeforeUnloadConfirm before_unload_msg(
301 rvh()->routing_id(), kNtpUrl, msg, false, &result, &unused); 301 rvh()->GetRoutingID(), kNtpUrl, msg, false, &result, &unused);
302 // Enable pumping for check in BrowserMessageFilter::CheckCanDispatchOnUI. 302 // Enable pumping for check in BrowserMessageFilter::CheckCanDispatchOnUI.
303 before_unload_msg.EnableMessagePumping(); 303 before_unload_msg.EnableMessagePumping();
304 EXPECT_TRUE(ntp_rvh->TestOnMessageReceived(before_unload_msg)); 304 EXPECT_TRUE(ntp_rvh->TestOnMessageReceived(before_unload_msg));
305 EXPECT_TRUE(ntp_process_host->sink().GetUniqueMessageMatching(IPC_REPLY_ID)); 305 EXPECT_TRUE(ntp_process_host->sink().GetUniqueMessageMatching(IPC_REPLY_ID));
306 306
307 // Also test RunJavaScriptMessage. 307 // Also test RunJavaScriptMessage.
308 ntp_process_host->sink().ClearMessages(); 308 ntp_process_host->sink().ClearMessages();
309 ViewHostMsg_RunJavaScriptMessage js_msg( 309 ViewHostMsg_RunJavaScriptMessage js_msg(
310 rvh()->routing_id(), msg, msg, kNtpUrl, 310 rvh()->GetRoutingID(), msg, msg, kNtpUrl,
311 ui::JAVASCRIPT_MESSAGE_TYPE_CONFIRM, &result, &unused); 311 ui::JAVASCRIPT_MESSAGE_TYPE_CONFIRM, &result, &unused);
312 js_msg.EnableMessagePumping(); 312 js_msg.EnableMessagePumping();
313 EXPECT_TRUE(ntp_rvh->TestOnMessageReceived(js_msg)); 313 EXPECT_TRUE(ntp_rvh->TestOnMessageReceived(js_msg));
314 EXPECT_TRUE(ntp_process_host->sink().GetUniqueMessageMatching(IPC_REPLY_ID)); 314 EXPECT_TRUE(ntp_process_host->sink().GetUniqueMessageMatching(IPC_REPLY_ID));
315 } 315 }
316 316
317 // When there is an error with the specified page, renderer exits view-source 317 // When there is an error with the specified page, renderer exits view-source
318 // mode. See WebFrameImpl::DidFail(). We check by this test that 318 // mode. See WebFrameImpl::DidFail(). We check by this test that
319 // EnableViewSourceMode message is sent on every navigation regardless 319 // EnableViewSourceMode message is sent on every navigation regardless
320 // RenderView is being newly created or reused. 320 // RenderView is being newly created or reused.
321 TEST_F(RenderViewHostManagerTest, AlwaysSendEnableViewSourceMode) { 321 TEST_F(RenderViewHostManagerTest, AlwaysSendEnableViewSourceMode) {
322 BrowserThreadImpl ui_thread(BrowserThread::UI, MessageLoop::current()); 322 BrowserThreadImpl ui_thread(BrowserThread::UI, MessageLoop::current());
323 const GURL kNtpUrl(chrome::kTestNewTabURL); 323 const GURL kNtpUrl(chrome::kTestNewTabURL);
324 const GURL kUrl("view-source:http://foo"); 324 const GURL kUrl("view-source:http://foo");
325 325
326 // We have to navigate to some page at first since without this, the first 326 // We have to navigate to some page at first since without this, the first
327 // navigation will reuse the SiteInstance created by Init(), and the second 327 // navigation will reuse the SiteInstance created by Init(), and the second
328 // one will create a new SiteInstance. Because current_instance and 328 // one will create a new SiteInstance. Because current_instance and
329 // new_instance will be different, a new RenderViewHost will be created for 329 // new_instance will be different, a new RenderViewHost will be created for
330 // the second navigation. We have to avoid this in order to exercise the 330 // the second navigation. We have to avoid this in order to exercise the
331 // target code patch. 331 // target code patch.
332 NavigateActiveAndCommit(kNtpUrl); 332 NavigateActiveAndCommit(kNtpUrl);
333 333
334 // Navigate. 334 // Navigate.
335 controller().LoadURL( 335 controller().LoadURL(
336 kUrl, content::Referrer(), content::PAGE_TRANSITION_TYPED, std::string()); 336 kUrl, content::Referrer(), content::PAGE_TRANSITION_TYPED, std::string());
337 // Simulate response from RenderView for FirePageBeforeUnload. 337 // Simulate response from RenderView for FirePageBeforeUnload.
338 rvh()->TestOnMessageReceived( 338 rvh()->TestOnMessageReceived(
339 ViewHostMsg_ShouldClose_ACK(rvh()->routing_id(), true)); 339 ViewHostMsg_ShouldClose_ACK(rvh()->GetRoutingID(), true));
340 ASSERT_TRUE(pending_rvh()); // New pending RenderViewHost will be created. 340 ASSERT_TRUE(pending_rvh()); // New pending RenderViewHost will be created.
341 RenderViewHost* last_rvh = pending_rvh(); 341 RenderViewHost* last_rvh = pending_rvh();
342 int32 new_id = contents()->GetMaxPageIDForSiteInstance( 342 int32 new_id = contents()->GetMaxPageIDForSiteInstance(
343 active_rvh()->site_instance()) + 1; 343 active_rvh()->GetSiteInstance()) + 1;
344 pending_rvh()->SendNavigate(new_id, kUrl); 344 pending_rvh()->SendNavigate(new_id, kUrl);
345 EXPECT_EQ(controller().GetLastCommittedEntryIndex(), 1); 345 EXPECT_EQ(controller().GetLastCommittedEntryIndex(), 1);
346 ASSERT_TRUE(controller().GetLastCommittedEntry()); 346 ASSERT_TRUE(controller().GetLastCommittedEntry());
347 EXPECT_TRUE(kUrl == controller().GetLastCommittedEntry()->GetURL()); 347 EXPECT_TRUE(kUrl == controller().GetLastCommittedEntry()->GetURL());
348 EXPECT_FALSE(controller().GetPendingEntry()); 348 EXPECT_FALSE(controller().GetPendingEntry());
349 // Because we're using TestTabContents and TestRenderViewHost in this 349 // Because we're using TestTabContents and TestRenderViewHost in this
350 // unittest, no one calls TabContents::RenderViewCreated(). So, we see no 350 // unittest, no one calls TabContents::RenderViewCreated(). So, we see no
351 // EnableViewSourceMode message, here. 351 // EnableViewSourceMode message, here.
352 352
353 // Clear queued messages before load. 353 // Clear queued messages before load.
(...skipping 19 matching lines...) Expand all
373 static_cast<SiteInstanceImpl*>(SiteInstance::Create(browser_context())); 373 static_cast<SiteInstanceImpl*>(SiteInstance::Create(browser_context()));
374 EXPECT_FALSE(instance->HasSite()); 374 EXPECT_FALSE(instance->HasSite());
375 375
376 TestTabContents tab_contents(browser_context(), instance); 376 TestTabContents tab_contents(browser_context(), instance);
377 RenderViewHostManager manager(&tab_contents, &tab_contents); 377 RenderViewHostManager manager(&tab_contents, &tab_contents);
378 378
379 manager.Init(browser_context(), instance, MSG_ROUTING_NONE); 379 manager.Init(browser_context(), instance, MSG_ROUTING_NONE);
380 380
381 RenderViewHost* host = manager.current_host(); 381 RenderViewHost* host = manager.current_host();
382 ASSERT_TRUE(host); 382 ASSERT_TRUE(host);
383 EXPECT_TRUE(instance == host->site_instance()); 383 EXPECT_TRUE(instance == host->GetSiteInstance());
384 EXPECT_TRUE(&tab_contents == host->delegate()); 384 EXPECT_TRUE(&tab_contents == host->GetDelegate());
385 EXPECT_TRUE(manager.GetRenderWidgetHostView()); 385 EXPECT_TRUE(manager.GetRenderWidgetHostView());
386 EXPECT_FALSE(manager.pending_render_view_host()); 386 EXPECT_FALSE(manager.pending_render_view_host());
387 } 387 }
388 388
389 // Tests the Navigate function. We navigate three sites consecutively and check 389 // Tests the Navigate function. We navigate three sites consecutively and check
390 // how the pending/committed RenderViewHost are modified. 390 // how the pending/committed RenderViewHost are modified.
391 TEST_F(RenderViewHostManagerTest, Navigate) { 391 TEST_F(RenderViewHostManagerTest, Navigate) {
392 TestNotificationTracker notifications; 392 TestNotificationTracker notifications;
393 393
394 SiteInstance* instance = SiteInstance::Create(browser_context()); 394 SiteInstance* instance = SiteInstance::Create(browser_context());
(...skipping 21 matching lines...) Expand all
416 416
417 // The RenderViewHost created in Init will be reused. 417 // The RenderViewHost created in Init will be reused.
418 EXPECT_TRUE(host == manager.current_host()); 418 EXPECT_TRUE(host == manager.current_host());
419 EXPECT_FALSE(manager.pending_render_view_host()); 419 EXPECT_FALSE(manager.pending_render_view_host());
420 420
421 // Commit. 421 // Commit.
422 manager.DidNavigateMainFrame(host); 422 manager.DidNavigateMainFrame(host);
423 // Commit to SiteInstance should be delayed until RenderView commit. 423 // Commit to SiteInstance should be delayed until RenderView commit.
424 EXPECT_TRUE(host == manager.current_host()); 424 EXPECT_TRUE(host == manager.current_host());
425 ASSERT_TRUE(host); 425 ASSERT_TRUE(host);
426 EXPECT_FALSE(static_cast<SiteInstanceImpl*>(host->site_instance())-> 426 EXPECT_FALSE(static_cast<SiteInstanceImpl*>(host->GetSiteInstance())->
427 HasSite()); 427 HasSite());
428 static_cast<SiteInstanceImpl*>(host->site_instance())->SetSite(kUrl1); 428 static_cast<SiteInstanceImpl*>(host->GetSiteInstance())->SetSite(kUrl1);
429 429
430 // 2) Navigate to next site. ------------------------- 430 // 2) Navigate to next site. -------------------------
431 const GURL kUrl2("http://www.google.com/foo"); 431 const GURL kUrl2("http://www.google.com/foo");
432 NavigationEntryImpl entry2( 432 NavigationEntryImpl entry2(
433 NULL /* instance */, -1 /* page_id */, kUrl2, 433 NULL /* instance */, -1 /* page_id */, kUrl2,
434 content::Referrer(kUrl1, WebKit::WebReferrerPolicyDefault), 434 content::Referrer(kUrl1, WebKit::WebReferrerPolicyDefault),
435 string16() /* title */, content::PAGE_TRANSITION_LINK, 435 string16() /* title */, content::PAGE_TRANSITION_LINK,
436 true /* is_renderer_init */); 436 true /* is_renderer_init */);
437 host = manager.Navigate(entry2); 437 host = manager.Navigate(entry2);
438 438
439 // The RenderViewHost created in Init will be reused. 439 // The RenderViewHost created in Init will be reused.
440 EXPECT_TRUE(host == manager.current_host()); 440 EXPECT_TRUE(host == manager.current_host());
441 EXPECT_FALSE(manager.pending_render_view_host()); 441 EXPECT_FALSE(manager.pending_render_view_host());
442 442
443 // Commit. 443 // Commit.
444 manager.DidNavigateMainFrame(host); 444 manager.DidNavigateMainFrame(host);
445 EXPECT_TRUE(host == manager.current_host()); 445 EXPECT_TRUE(host == manager.current_host());
446 ASSERT_TRUE(host); 446 ASSERT_TRUE(host);
447 EXPECT_TRUE(static_cast<SiteInstanceImpl*>(host->site_instance())-> 447 EXPECT_TRUE(static_cast<SiteInstanceImpl*>(host->GetSiteInstance())->
448 HasSite()); 448 HasSite());
449 449
450 // 3) Cross-site navigate to next site. -------------- 450 // 3) Cross-site navigate to next site. --------------
451 const GURL kUrl3("http://webkit.org/"); 451 const GURL kUrl3("http://webkit.org/");
452 NavigationEntryImpl entry3( 452 NavigationEntryImpl entry3(
453 NULL /* instance */, -1 /* page_id */, kUrl3, 453 NULL /* instance */, -1 /* page_id */, kUrl3,
454 content::Referrer(kUrl2, WebKit::WebReferrerPolicyDefault), 454 content::Referrer(kUrl2, WebKit::WebReferrerPolicyDefault),
455 string16() /* title */, content::PAGE_TRANSITION_LINK, 455 string16() /* title */, content::PAGE_TRANSITION_LINK,
456 false /* is_renderer_init */); 456 false /* is_renderer_init */);
457 host = manager.Navigate(entry3); 457 host = manager.Navigate(entry3);
458 458
459 // A new RenderViewHost should be created. 459 // A new RenderViewHost should be created.
460 EXPECT_TRUE(manager.pending_render_view_host()); 460 EXPECT_TRUE(manager.pending_render_view_host());
461 ASSERT_EQ(host, manager.pending_render_view_host()); 461 ASSERT_EQ(host, manager.pending_render_view_host());
462 462
463 notifications.Reset(); 463 notifications.Reset();
464 464
465 // Commit. 465 // Commit.
466 manager.DidNavigateMainFrame(manager.pending_render_view_host()); 466 manager.DidNavigateMainFrame(manager.pending_render_view_host());
467 EXPECT_TRUE(host == manager.current_host()); 467 EXPECT_TRUE(host == manager.current_host());
468 ASSERT_TRUE(host); 468 ASSERT_TRUE(host);
469 EXPECT_TRUE(static_cast<SiteInstanceImpl*>(host->site_instance())-> 469 EXPECT_TRUE(static_cast<SiteInstanceImpl*>(host->GetSiteInstance())->
470 HasSite()); 470 HasSite());
471 // Check the pending RenderViewHost has been committed. 471 // Check the pending RenderViewHost has been committed.
472 EXPECT_FALSE(manager.pending_render_view_host()); 472 EXPECT_FALSE(manager.pending_render_view_host());
473 473
474 // We should observe a notification. 474 // We should observe a notification.
475 EXPECT_TRUE(notifications.Check1AndReset( 475 EXPECT_TRUE(notifications.Check1AndReset(
476 content::NOTIFICATION_RENDER_VIEW_HOST_CHANGED)); 476 content::NOTIFICATION_RENDER_VIEW_HOST_CHANGED));
477 } 477 }
478 478
479 // Tests the Navigate function. In this unit test we verify that the Navigate 479 // Tests the Navigate function. In this unit test we verify that the Navigate
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
512 EXPECT_TRUE(notifications.Check1AndReset( 512 EXPECT_TRUE(notifications.Check1AndReset(
513 content::NOTIFICATION_RENDER_VIEW_HOST_CHANGED)); 513 content::NOTIFICATION_RENDER_VIEW_HOST_CHANGED));
514 notifications.Reset(); 514 notifications.Reset();
515 515
516 // Commit. 516 // Commit.
517 manager.DidNavigateMainFrame(host); 517 manager.DidNavigateMainFrame(host);
518 518
519 // Commit to SiteInstance should be delayed until RenderView commit. 519 // Commit to SiteInstance should be delayed until RenderView commit.
520 EXPECT_TRUE(host == manager.current_host()); 520 EXPECT_TRUE(host == manager.current_host());
521 ASSERT_TRUE(host); 521 ASSERT_TRUE(host);
522 EXPECT_FALSE(static_cast<SiteInstanceImpl*>(host->site_instance())-> 522 EXPECT_FALSE(static_cast<SiteInstanceImpl*>(host->GetSiteInstance())->
523 HasSite()); 523 HasSite());
524 static_cast<SiteInstanceImpl*>(host->site_instance())->SetSite(kUrl1); 524 static_cast<SiteInstanceImpl*>(host->GetSiteInstance())->SetSite(kUrl1);
525 525
526 // 2) Cross-site navigate to next site. ------------------------- 526 // 2) Cross-site navigate to next site. -------------------------
527 const GURL kUrl2("http://www.example.com"); 527 const GURL kUrl2("http://www.example.com");
528 NavigationEntryImpl entry2( 528 NavigationEntryImpl entry2(
529 NULL /* instance */, -1 /* page_id */, kUrl2, content::Referrer(), 529 NULL /* instance */, -1 /* page_id */, kUrl2, content::Referrer(),
530 string16() /* title */, content::PAGE_TRANSITION_TYPED, 530 string16() /* title */, content::PAGE_TRANSITION_TYPED,
531 false /* is_renderer_init */); 531 false /* is_renderer_init */);
532 RenderViewHost* host2 = manager.Navigate(entry2); 532 RenderViewHostImpl* host2 = static_cast<RenderViewHostImpl*>(
533 int host2_process_id = host2->process()->GetID(); 533 manager.Navigate(entry2));
534 int host2_process_id = host2->GetProcess()->GetID();
534 535
535 // A new RenderViewHost should be created. 536 // A new RenderViewHost should be created.
536 EXPECT_TRUE(manager.pending_render_view_host()); 537 EXPECT_TRUE(manager.pending_render_view_host());
537 ASSERT_EQ(host2, manager.pending_render_view_host()); 538 ASSERT_EQ(host2, manager.pending_render_view_host());
538 EXPECT_NE(host2, host); 539 EXPECT_NE(host2, host);
539 540
540 // Check that the navigation is still suspended because the old RVH 541 // Check that the navigation is still suspended because the old RVH
541 // is not swapped out, yet. 542 // is not swapped out, yet.
542 EXPECT_TRUE(host2->are_navigations_suspended()); 543 EXPECT_TRUE(host2->are_navigations_suspended());
543 MockRenderProcessHost* test_process_host2 = 544 MockRenderProcessHost* test_process_host2 =
544 static_cast<MockRenderProcessHost*>(host2->process()); 545 static_cast<MockRenderProcessHost*>(host2->GetProcess());
545 test_process_host2->sink().ClearMessages(); 546 test_process_host2->sink().ClearMessages();
546 host2->NavigateToURL(kUrl2); 547 host2->NavigateToURL(kUrl2);
547 EXPECT_FALSE(test_process_host2->sink().GetUniqueMessageMatching( 548 EXPECT_FALSE(test_process_host2->sink().GetUniqueMessageMatching(
548 ViewMsg_Navigate::ID)); 549 ViewMsg_Navigate::ID));
549 550
550 // Allow closing the current Render View (precondition for swapping out 551 // Allow closing the current Render View (precondition for swapping out
551 // the RVH): Simulate response from RenderView for ViewMsg_ShouldClose sent by 552 // the RVH): Simulate response from RenderView for ViewMsg_ShouldClose sent by
552 // FirePageBeforeUnload. 553 // FirePageBeforeUnload.
553 TestRenderViewHost* test_host = static_cast<TestRenderViewHost*>(host); 554 TestRenderViewHost* test_host = static_cast<TestRenderViewHost*>(host);
554 MockRenderProcessHost* test_process_host = 555 MockRenderProcessHost* test_process_host =
555 static_cast<MockRenderProcessHost*>(test_host->process()); 556 static_cast<MockRenderProcessHost*>(test_host->GetProcess());
556 EXPECT_TRUE(test_process_host->sink().GetUniqueMessageMatching( 557 EXPECT_TRUE(test_process_host->sink().GetUniqueMessageMatching(
557 ViewMsg_ShouldClose::ID)); 558 ViewMsg_ShouldClose::ID));
558 test_host->SendShouldCloseACK(true); 559 test_host->SendShouldCloseACK(true);
559 560
560 // CrossSiteResourceHandler::StartCrossSiteTransition triggers a 561 // CrossSiteResourceHandler::StartCrossSiteTransition triggers a
561 // call of RenderViewHostManager::OnCrossSiteResponse before 562 // call of RenderViewHostManager::OnCrossSiteResponse before
562 // RenderViewHostManager::DidNavigateMainFrame is called. 563 // RenderViewHostManager::DidNavigateMainFrame is called.
563 // The RVH is not swapped out until the commit. 564 // The RVH is not swapped out until the commit.
564 manager.OnCrossSiteResponse(host2->process()->GetID(), 565 manager.OnCrossSiteResponse(host2->GetProcess()->GetID(),
565 host2->GetPendingRequestId()); 566 host2->GetPendingRequestId());
566 EXPECT_TRUE(test_process_host->sink().GetUniqueMessageMatching( 567 EXPECT_TRUE(test_process_host->sink().GetUniqueMessageMatching(
567 ViewMsg_SwapOut::ID)); 568 ViewMsg_SwapOut::ID));
568 test_host->OnSwapOutACK(); 569 test_host->OnSwapOutACK();
569 570
570 EXPECT_EQ(host, manager.current_host()); 571 EXPECT_EQ(host, manager.current_host());
571 EXPECT_FALSE(manager.current_host()->is_swapped_out()); 572 EXPECT_FALSE(static_cast<RenderViewHostImpl*>(
573 manager.current_host())->is_swapped_out());
572 EXPECT_EQ(host2, manager.pending_render_view_host()); 574 EXPECT_EQ(host2, manager.pending_render_view_host());
573 // There should be still no navigation messages being sent. 575 // There should be still no navigation messages being sent.
574 EXPECT_FALSE(test_process_host2->sink().GetUniqueMessageMatching( 576 EXPECT_FALSE(test_process_host2->sink().GetUniqueMessageMatching(
575 ViewMsg_Navigate::ID)); 577 ViewMsg_Navigate::ID));
576 578
577 // 3) Cross-site navigate to next site before 2) has committed. -------------- 579 // 3) Cross-site navigate to next site before 2) has committed. --------------
578 const GURL kUrl3("http://webkit.org/"); 580 const GURL kUrl3("http://webkit.org/");
579 NavigationEntryImpl entry3(NULL /* instance */, -1 /* page_id */, kUrl3, 581 NavigationEntryImpl entry3(NULL /* instance */, -1 /* page_id */, kUrl3,
580 content::Referrer(), string16() /* title */, 582 content::Referrer(), string16() /* title */,
581 content::PAGE_TRANSITION_TYPED, 583 content::PAGE_TRANSITION_TYPED,
582 false /* is_renderer_init */); 584 false /* is_renderer_init */);
583 test_process_host->sink().ClearMessages(); 585 test_process_host->sink().ClearMessages();
584 RenderViewHost* host3 = manager.Navigate(entry3); 586 RenderViewHost* host3 = manager.Navigate(entry3);
585 587
586 // A new RenderViewHost should be created. host2 is now deleted. 588 // A new RenderViewHost should be created. host2 is now deleted.
587 EXPECT_TRUE(manager.pending_render_view_host()); 589 EXPECT_TRUE(manager.pending_render_view_host());
588 ASSERT_EQ(host3, manager.pending_render_view_host()); 590 ASSERT_EQ(host3, manager.pending_render_view_host());
589 EXPECT_NE(host3, host); 591 EXPECT_NE(host3, host);
590 EXPECT_NE(host3->process()->GetID(), host2_process_id); 592 EXPECT_NE(host3->GetProcess()->GetID(), host2_process_id);
591 593
592 // Navigations in the new RVH should be suspended, which is ok because the 594 // Navigations in the new RVH should be suspended, which is ok because the
593 // old RVH is not yet swapped out and can respond to a second beforeunload 595 // old RVH is not yet swapped out and can respond to a second beforeunload
594 // request. 596 // request.
595 EXPECT_TRUE(host3->are_navigations_suspended()); 597 EXPECT_TRUE(static_cast<RenderViewHostImpl*>(
598 host3)->are_navigations_suspended());
596 EXPECT_EQ(host, manager.current_host()); 599 EXPECT_EQ(host, manager.current_host());
597 EXPECT_FALSE(manager.current_host()->is_swapped_out()); 600 EXPECT_FALSE(static_cast<RenderViewHostImpl*>(
601 manager.current_host())->is_swapped_out());
598 602
599 // Simulate a response to the second beforeunload request. 603 // Simulate a response to the second beforeunload request.
600 EXPECT_TRUE(test_process_host->sink().GetUniqueMessageMatching( 604 EXPECT_TRUE(test_process_host->sink().GetUniqueMessageMatching(
601 ViewMsg_ShouldClose::ID)); 605 ViewMsg_ShouldClose::ID));
602 test_host->SendShouldCloseACK(true); 606 test_host->SendShouldCloseACK(true);
603 607
604 // CrossSiteResourceHandler::StartCrossSiteTransition triggers a 608 // CrossSiteResourceHandler::StartCrossSiteTransition triggers a
605 // call of RenderViewHostManager::OnCrossSiteResponse before 609 // call of RenderViewHostManager::OnCrossSiteResponse before
606 // RenderViewHostManager::DidNavigateMainFrame is called. 610 // RenderViewHostManager::DidNavigateMainFrame is called.
607 // The RVH is not swapped out until the commit. 611 // The RVH is not swapped out until the commit.
608 manager.OnCrossSiteResponse(host3->process()->GetID(), 612 manager.OnCrossSiteResponse(host3->GetProcess()->GetID(),
609 host3->GetPendingRequestId()); 613 static_cast<RenderViewHostImpl*>(
614 host3)->GetPendingRequestId());
610 EXPECT_TRUE(test_process_host->sink().GetUniqueMessageMatching( 615 EXPECT_TRUE(test_process_host->sink().GetUniqueMessageMatching(
611 ViewMsg_SwapOut::ID)); 616 ViewMsg_SwapOut::ID));
612 test_host->OnSwapOutACK(); 617 test_host->OnSwapOutACK();
613 618
614 // Commit. 619 // Commit.
615 manager.DidNavigateMainFrame(host3); 620 manager.DidNavigateMainFrame(host3);
616 EXPECT_TRUE(host3 == manager.current_host()); 621 EXPECT_TRUE(host3 == manager.current_host());
617 ASSERT_TRUE(host3); 622 ASSERT_TRUE(host3);
618 EXPECT_TRUE(static_cast<SiteInstanceImpl*>(host3->site_instance())-> 623 EXPECT_TRUE(static_cast<SiteInstanceImpl*>(host3->GetSiteInstance())->
619 HasSite()); 624 HasSite());
620 // Check the pending RenderViewHost has been committed. 625 // Check the pending RenderViewHost has been committed.
621 EXPECT_FALSE(manager.pending_render_view_host()); 626 EXPECT_FALSE(manager.pending_render_view_host());
622 627
623 // We should observe a notification. 628 // We should observe a notification.
624 EXPECT_TRUE(notifications.Check1AndReset( 629 EXPECT_TRUE(notifications.Check1AndReset(
625 content::NOTIFICATION_RENDER_VIEW_HOST_CHANGED)); 630 content::NOTIFICATION_RENDER_VIEW_HOST_CHANGED));
626 } 631 }
627 632
628 // Tests WebUI creation. 633 // Tests WebUI creation.
(...skipping 15 matching lines...) Expand all
644 RenderViewHost* host = manager.Navigate(entry); 649 RenderViewHost* host = manager.Navigate(entry);
645 650
646 EXPECT_TRUE(host); 651 EXPECT_TRUE(host);
647 EXPECT_TRUE(host == manager.current_host()); 652 EXPECT_TRUE(host == manager.current_host());
648 EXPECT_FALSE(manager.pending_render_view_host()); 653 EXPECT_FALSE(manager.pending_render_view_host());
649 654
650 // It's important that the site instance get set on the Web UI page as soon 655 // It's important that the site instance get set on the Web UI page as soon
651 // as the navigation starts, rather than lazily after it commits, so we don't 656 // as the navigation starts, rather than lazily after it commits, so we don't
652 // try to re-use the SiteInstance/process for non DOM-UI things that may 657 // try to re-use the SiteInstance/process for non DOM-UI things that may
653 // get loaded in between. 658 // get loaded in between.
654 EXPECT_TRUE(static_cast<SiteInstanceImpl*>(host->site_instance())-> 659 EXPECT_TRUE(static_cast<SiteInstanceImpl*>(host->GetSiteInstance())->
655 HasSite()); 660 HasSite());
656 EXPECT_EQ(kUrl, host->site_instance()->GetSite()); 661 EXPECT_EQ(kUrl, host->GetSiteInstance()->GetSite());
657 662
658 // The Web UI is committed immediately because the RenderViewHost has not been 663 // The Web UI is committed immediately because the RenderViewHost has not been
659 // used yet. UpdateRendererStateForNavigate() took the short cut path. 664 // used yet. UpdateRendererStateForNavigate() took the short cut path.
660 EXPECT_FALSE(manager.pending_web_ui()); 665 EXPECT_FALSE(manager.pending_web_ui());
661 EXPECT_TRUE(manager.web_ui()); 666 EXPECT_TRUE(manager.web_ui());
662 667
663 // Commit. 668 // Commit.
664 manager.DidNavigateMainFrame(host); 669 manager.DidNavigateMainFrame(host);
665 } 670 }
666 671
(...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after
769 774
770 // We should be able to navigate forward. 775 // We should be able to navigate forward.
771 contents()->GetController().GoForward(); 776 contents()->GetController().GoForward();
772 contents()->ProceedWithCrossSiteNavigation(); 777 contents()->ProceedWithCrossSiteNavigation();
773 const NavigationEntry* entry2 = contents()->GetController().GetPendingEntry(); 778 const NavigationEntry* entry2 = contents()->GetController().GetPendingEntry();
774 rvh2->SendNavigate(entry2->GetPageID(), entry2->GetURL()); 779 rvh2->SendNavigate(entry2->GetPageID(), entry2->GetURL());
775 EXPECT_EQ(rvh2, rvh()); 780 EXPECT_EQ(rvh2, rvh());
776 EXPECT_FALSE(rvh2->is_swapped_out()); 781 EXPECT_FALSE(rvh2->is_swapped_out());
777 EXPECT_TRUE(rvh1->is_swapped_out()); 782 EXPECT_TRUE(rvh1->is_swapped_out());
778 } 783 }
OLDNEW
« no previous file with comments | « content/browser/tab_contents/render_view_host_manager.cc ('k') | content/browser/tab_contents/tab_contents.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698