| OLD | NEW |
| 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 "content/browser/browser_thread_impl.h" | 5 #include "content/browser/browser_thread_impl.h" |
| 6 #include "content/browser/browser_url_handler.h" | 6 #include "content/browser/browser_url_handler.h" |
| 7 #include "content/browser/mock_content_browser_client.h" | 7 #include "content/browser/mock_content_browser_client.h" |
| 8 #include "content/browser/renderer_host/test_render_view_host.h" | 8 #include "content/browser/renderer_host/test_render_view_host.h" |
| 9 #include "content/browser/site_instance.h" | 9 #include "content/browser/site_instance_impl.h" |
| 10 #include "content/browser/tab_contents/navigation_controller_impl.h" | 10 #include "content/browser/tab_contents/navigation_controller_impl.h" |
| 11 #include "content/browser/tab_contents/navigation_entry_impl.h" | 11 #include "content/browser/tab_contents/navigation_entry_impl.h" |
| 12 #include "content/browser/tab_contents/render_view_host_manager.h" | 12 #include "content/browser/tab_contents/render_view_host_manager.h" |
| 13 #include "content/browser/tab_contents/test_tab_contents.h" | 13 #include "content/browser/tab_contents/test_tab_contents.h" |
| 14 #include "content/browser/webui/empty_web_ui_factory.h" | 14 #include "content/browser/webui/empty_web_ui_factory.h" |
| 15 #include "content/common/test_url_constants.h" | 15 #include "content/common/test_url_constants.h" |
| 16 #include "content/common/view_messages.h" | 16 #include "content/common/view_messages.h" |
| 17 #include "content/public/browser/notification_details.h" | 17 #include "content/public/browser/notification_details.h" |
| 18 #include "content/public/browser/notification_source.h" | 18 #include "content/public/browser/notification_source.h" |
| 19 #include "content/public/browser/notification_types.h" | 19 #include "content/public/browser/notification_types.h" |
| 20 #include "content/public/browser/web_ui_controller.h" | 20 #include "content/public/browser/web_ui_controller.h" |
| 21 #include "content/public/common/page_transition_types.h" | 21 #include "content/public/common/page_transition_types.h" |
| 22 #include "content/public/common/url_constants.h" | 22 #include "content/public/common/url_constants.h" |
| 23 #include "content/test/test_browser_context.h" | 23 #include "content/test/test_browser_context.h" |
| 24 #include "content/test/test_notification_tracker.h" | 24 #include "content/test/test_notification_tracker.h" |
| 25 #include "testing/gtest/include/gtest/gtest.h" | 25 #include "testing/gtest/include/gtest/gtest.h" |
| 26 #include "googleurl/src/url_util.h" | 26 #include "googleurl/src/url_util.h" |
| 27 #include "webkit/glue/webkit_glue.h" | 27 #include "webkit/glue/webkit_glue.h" |
| 28 | 28 |
| 29 using content::BrowserThread; | 29 using content::BrowserThread; |
| 30 using content::BrowserThreadImpl; | 30 using content::BrowserThreadImpl; |
| 31 using content::NavigationController; | 31 using content::NavigationController; |
| 32 using content::NavigationEntry; | 32 using content::NavigationEntry; |
| 33 using content::NavigationEntryImpl; | 33 using content::NavigationEntryImpl; |
| 34 using content::SiteInstance; |
| 34 using content::WebContents; | 35 using content::WebContents; |
| 35 using content::WebUIController; | 36 using content::WebUIController; |
| 36 | 37 |
| 37 namespace { | 38 namespace { |
| 38 | 39 |
| 39 const char kChromeUISchemeButNotWebUIURL[] = "chrome://not-webui"; | 40 const char kChromeUISchemeButNotWebUIURL[] = "chrome://not-webui"; |
| 40 | 41 |
| 41 class RenderViewHostManagerTestWebUIFactory | 42 class RenderViewHostManagerTestWebUIFactory |
| 42 : public content::EmptyWebUIFactory { | 43 : public content::EmptyWebUIFactory { |
| 43 public: | 44 public: |
| (...skipping 147 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 191 TestRenderViewHost* dest_rvh2 = static_cast<TestRenderViewHost*>( | 192 TestRenderViewHost* dest_rvh2 = static_cast<TestRenderViewHost*>( |
| 192 contents2.GetRenderManagerForTesting()->pending_render_view_host()); | 193 contents2.GetRenderManagerForTesting()->pending_render_view_host()); |
| 193 ASSERT_TRUE(dest_rvh2); | 194 ASSERT_TRUE(dest_rvh2); |
| 194 ntp_rvh2->SendShouldCloseACK(true); | 195 ntp_rvh2->SendShouldCloseACK(true); |
| 195 dest_rvh2->SendNavigate(101, kDestUrl); | 196 dest_rvh2->SendNavigate(101, kDestUrl); |
| 196 ntp_rvh2->OnSwapOutACK(); | 197 ntp_rvh2->OnSwapOutACK(); |
| 197 | 198 |
| 198 // The two RVH's should be different in every way. | 199 // The two RVH's should be different in every way. |
| 199 EXPECT_NE(active_rvh()->process(), dest_rvh2->process()); | 200 EXPECT_NE(active_rvh()->process(), dest_rvh2->process()); |
| 200 EXPECT_NE(active_rvh()->site_instance(), dest_rvh2->site_instance()); | 201 EXPECT_NE(active_rvh()->site_instance(), dest_rvh2->site_instance()); |
| 201 EXPECT_NE(active_rvh()->site_instance()->browsing_instance_, | 202 EXPECT_NE(static_cast<SiteInstanceImpl*>(active_rvh()->site_instance())-> |
| 202 dest_rvh2->site_instance()->browsing_instance_); | 203 GetBrowsingInstance(), |
| 204 static_cast<SiteInstanceImpl*>(dest_rvh2->site_instance())-> |
| 205 GetBrowsingInstance()); |
| 203 | 206 |
| 204 // Navigate both to the new tab page, and verify that they share a | 207 // Navigate both to the new tab page, and verify that they share a |
| 205 // SiteInstance. | 208 // SiteInstance. |
| 206 NavigateActiveAndCommit(kNtpUrl); | 209 NavigateActiveAndCommit(kNtpUrl); |
| 207 | 210 |
| 208 contents2.GetController().LoadURL( | 211 contents2.GetController().LoadURL( |
| 209 kNtpUrl, content::Referrer(), content::PAGE_TRANSITION_LINK, | 212 kNtpUrl, content::Referrer(), content::PAGE_TRANSITION_LINK, |
| 210 std::string()); | 213 std::string()); |
| 211 dest_rvh2->SendShouldCloseACK(true); | 214 dest_rvh2->SendShouldCloseACK(true); |
| 212 static_cast<TestRenderViewHost*>(contents2.GetRenderManagerForTesting()-> | 215 static_cast<TestRenderViewHost*>(contents2.GetRenderManagerForTesting()-> |
| (...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 265 EXPECT_EQ(controller().GetLastCommittedEntryIndex(), 1); | 268 EXPECT_EQ(controller().GetLastCommittedEntryIndex(), 1); |
| 266 EXPECT_FALSE(controller().GetPendingEntry()); | 269 EXPECT_FALSE(controller().GetPendingEntry()); |
| 267 // New message should be sent out to make sure to enter view-source mode. | 270 // New message should be sent out to make sure to enter view-source mode. |
| 268 EXPECT_TRUE(process()->sink().GetUniqueMessageMatching( | 271 EXPECT_TRUE(process()->sink().GetUniqueMessageMatching( |
| 269 ViewMsg_EnableViewSourceMode::ID)); | 272 ViewMsg_EnableViewSourceMode::ID)); |
| 270 } | 273 } |
| 271 | 274 |
| 272 // Tests the Init function by checking the initial RenderViewHost. | 275 // Tests the Init function by checking the initial RenderViewHost. |
| 273 TEST_F(RenderViewHostManagerTest, Init) { | 276 TEST_F(RenderViewHostManagerTest, Init) { |
| 274 // Using TestBrowserContext. | 277 // Using TestBrowserContext. |
| 275 SiteInstance* instance = SiteInstance::CreateSiteInstance(browser_context()); | 278 SiteInstanceImpl* instance = |
| 276 EXPECT_FALSE(instance->has_site()); | 279 static_cast<SiteInstanceImpl*>(SiteInstance::Create(browser_context())); |
| 280 EXPECT_FALSE(instance->HasSite()); |
| 277 | 281 |
| 278 TestTabContents tab_contents(browser_context(), instance); | 282 TestTabContents tab_contents(browser_context(), instance); |
| 279 RenderViewHostManager manager(&tab_contents, &tab_contents); | 283 RenderViewHostManager manager(&tab_contents, &tab_contents); |
| 280 | 284 |
| 281 manager.Init(browser_context(), instance, MSG_ROUTING_NONE); | 285 manager.Init(browser_context(), instance, MSG_ROUTING_NONE); |
| 282 | 286 |
| 283 RenderViewHost* host = manager.current_host(); | 287 RenderViewHost* host = manager.current_host(); |
| 284 ASSERT_TRUE(host); | 288 ASSERT_TRUE(host); |
| 285 EXPECT_TRUE(instance == host->site_instance()); | 289 EXPECT_TRUE(instance == host->site_instance()); |
| 286 EXPECT_TRUE(&tab_contents == host->delegate()); | 290 EXPECT_TRUE(&tab_contents == host->delegate()); |
| 287 EXPECT_TRUE(manager.GetRenderWidgetHostView()); | 291 EXPECT_TRUE(manager.GetRenderWidgetHostView()); |
| 288 EXPECT_FALSE(manager.pending_render_view_host()); | 292 EXPECT_FALSE(manager.pending_render_view_host()); |
| 289 } | 293 } |
| 290 | 294 |
| 291 // Tests the Navigate function. We navigate three sites consecutively and check | 295 // Tests the Navigate function. We navigate three sites consecutively and check |
| 292 // how the pending/committed RenderViewHost are modified. | 296 // how the pending/committed RenderViewHost are modified. |
| 293 TEST_F(RenderViewHostManagerTest, Navigate) { | 297 TEST_F(RenderViewHostManagerTest, Navigate) { |
| 294 TestNotificationTracker notifications; | 298 TestNotificationTracker notifications; |
| 295 | 299 |
| 296 SiteInstance* instance = SiteInstance::CreateSiteInstance(browser_context()); | 300 SiteInstance* instance = SiteInstance::Create(browser_context()); |
| 297 | 301 |
| 298 TestTabContents tab_contents(browser_context(), instance); | 302 TestTabContents tab_contents(browser_context(), instance); |
| 299 notifications.ListenFor( | 303 notifications.ListenFor( |
| 300 content::NOTIFICATION_RENDER_VIEW_HOST_CHANGED, | 304 content::NOTIFICATION_RENDER_VIEW_HOST_CHANGED, |
| 301 content::Source<NavigationController>( | 305 content::Source<NavigationController>( |
| 302 &tab_contents.GetController())); | 306 &tab_contents.GetController())); |
| 303 | 307 |
| 304 // Create. | 308 // Create. |
| 305 RenderViewHostManager manager(&tab_contents, &tab_contents); | 309 RenderViewHostManager manager(&tab_contents, &tab_contents); |
| 306 | 310 |
| (...skipping 11 matching lines...) Expand all Loading... |
| 318 | 322 |
| 319 // The RenderViewHost created in Init will be reused. | 323 // The RenderViewHost created in Init will be reused. |
| 320 EXPECT_TRUE(host == manager.current_host()); | 324 EXPECT_TRUE(host == manager.current_host()); |
| 321 EXPECT_FALSE(manager.pending_render_view_host()); | 325 EXPECT_FALSE(manager.pending_render_view_host()); |
| 322 | 326 |
| 323 // Commit. | 327 // Commit. |
| 324 manager.DidNavigateMainFrame(host); | 328 manager.DidNavigateMainFrame(host); |
| 325 // Commit to SiteInstance should be delayed until RenderView commit. | 329 // Commit to SiteInstance should be delayed until RenderView commit. |
| 326 EXPECT_TRUE(host == manager.current_host()); | 330 EXPECT_TRUE(host == manager.current_host()); |
| 327 ASSERT_TRUE(host); | 331 ASSERT_TRUE(host); |
| 328 EXPECT_FALSE(host->site_instance()->has_site()); | 332 EXPECT_FALSE(static_cast<SiteInstanceImpl*>(host->site_instance())-> |
| 329 host->site_instance()->SetSite(kUrl1); | 333 HasSite()); |
| 334 static_cast<SiteInstanceImpl*>(host->site_instance())->SetSite(kUrl1); |
| 330 | 335 |
| 331 // 2) Navigate to next site. ------------------------- | 336 // 2) Navigate to next site. ------------------------- |
| 332 const GURL kUrl2("http://www.google.com/foo"); | 337 const GURL kUrl2("http://www.google.com/foo"); |
| 333 NavigationEntryImpl entry2( | 338 NavigationEntryImpl entry2( |
| 334 NULL /* instance */, -1 /* page_id */, kUrl2, | 339 NULL /* instance */, -1 /* page_id */, kUrl2, |
| 335 content::Referrer(kUrl1, WebKit::WebReferrerPolicyDefault), | 340 content::Referrer(kUrl1, WebKit::WebReferrerPolicyDefault), |
| 336 string16() /* title */, content::PAGE_TRANSITION_LINK, | 341 string16() /* title */, content::PAGE_TRANSITION_LINK, |
| 337 true /* is_renderer_init */); | 342 true /* is_renderer_init */); |
| 338 host = manager.Navigate(entry2); | 343 host = manager.Navigate(entry2); |
| 339 | 344 |
| 340 // The RenderViewHost created in Init will be reused. | 345 // The RenderViewHost created in Init will be reused. |
| 341 EXPECT_TRUE(host == manager.current_host()); | 346 EXPECT_TRUE(host == manager.current_host()); |
| 342 EXPECT_FALSE(manager.pending_render_view_host()); | 347 EXPECT_FALSE(manager.pending_render_view_host()); |
| 343 | 348 |
| 344 // Commit. | 349 // Commit. |
| 345 manager.DidNavigateMainFrame(host); | 350 manager.DidNavigateMainFrame(host); |
| 346 EXPECT_TRUE(host == manager.current_host()); | 351 EXPECT_TRUE(host == manager.current_host()); |
| 347 ASSERT_TRUE(host); | 352 ASSERT_TRUE(host); |
| 348 EXPECT_TRUE(host->site_instance()->has_site()); | 353 EXPECT_TRUE(static_cast<SiteInstanceImpl*>(host->site_instance())-> |
| 354 HasSite()); |
| 349 | 355 |
| 350 // 3) Cross-site navigate to next site. -------------- | 356 // 3) Cross-site navigate to next site. -------------- |
| 351 const GURL kUrl3("http://webkit.org/"); | 357 const GURL kUrl3("http://webkit.org/"); |
| 352 NavigationEntryImpl entry3( | 358 NavigationEntryImpl entry3( |
| 353 NULL /* instance */, -1 /* page_id */, kUrl3, | 359 NULL /* instance */, -1 /* page_id */, kUrl3, |
| 354 content::Referrer(kUrl2, WebKit::WebReferrerPolicyDefault), | 360 content::Referrer(kUrl2, WebKit::WebReferrerPolicyDefault), |
| 355 string16() /* title */, content::PAGE_TRANSITION_LINK, | 361 string16() /* title */, content::PAGE_TRANSITION_LINK, |
| 356 false /* is_renderer_init */); | 362 false /* is_renderer_init */); |
| 357 host = manager.Navigate(entry3); | 363 host = manager.Navigate(entry3); |
| 358 | 364 |
| 359 // A new RenderViewHost should be created. | 365 // A new RenderViewHost should be created. |
| 360 EXPECT_TRUE(manager.pending_render_view_host()); | 366 EXPECT_TRUE(manager.pending_render_view_host()); |
| 361 ASSERT_EQ(host, manager.pending_render_view_host()); | 367 ASSERT_EQ(host, manager.pending_render_view_host()); |
| 362 | 368 |
| 363 notifications.Reset(); | 369 notifications.Reset(); |
| 364 | 370 |
| 365 // Commit. | 371 // Commit. |
| 366 manager.DidNavigateMainFrame(manager.pending_render_view_host()); | 372 manager.DidNavigateMainFrame(manager.pending_render_view_host()); |
| 367 EXPECT_TRUE(host == manager.current_host()); | 373 EXPECT_TRUE(host == manager.current_host()); |
| 368 ASSERT_TRUE(host); | 374 ASSERT_TRUE(host); |
| 369 EXPECT_TRUE(host->site_instance()->has_site()); | 375 EXPECT_TRUE(static_cast<SiteInstanceImpl*>(host->site_instance())-> |
| 376 HasSite()); |
| 370 // Check the pending RenderViewHost has been committed. | 377 // Check the pending RenderViewHost has been committed. |
| 371 EXPECT_FALSE(manager.pending_render_view_host()); | 378 EXPECT_FALSE(manager.pending_render_view_host()); |
| 372 | 379 |
| 373 // We should observe a notification. | 380 // We should observe a notification. |
| 374 EXPECT_TRUE(notifications.Check1AndReset( | 381 EXPECT_TRUE(notifications.Check1AndReset( |
| 375 content::NOTIFICATION_RENDER_VIEW_HOST_CHANGED)); | 382 content::NOTIFICATION_RENDER_VIEW_HOST_CHANGED)); |
| 376 } | 383 } |
| 377 | 384 |
| 378 // Tests the Navigate function. In this unit test we verify that the Navigate | 385 // Tests the Navigate function. In this unit test we verify that the Navigate |
| 379 // function can handle a new navigation event before the previous navigation | 386 // function can handle a new navigation event before the previous navigation |
| 380 // has been committed. This is also a regression test for | 387 // has been committed. This is also a regression test for |
| 381 // http://crbug.com/104600. | 388 // http://crbug.com/104600. |
| 382 TEST_F(RenderViewHostManagerTest, NavigateWithEarlyReNavigation) { | 389 TEST_F(RenderViewHostManagerTest, NavigateWithEarlyReNavigation) { |
| 383 TestNotificationTracker notifications; | 390 TestNotificationTracker notifications; |
| 384 | 391 |
| 385 SiteInstance* instance = SiteInstance::CreateSiteInstance(browser_context()); | 392 SiteInstance* instance = SiteInstance::Create(browser_context()); |
| 386 | 393 |
| 387 TestTabContents tab_contents(browser_context(), instance); | 394 TestTabContents tab_contents(browser_context(), instance); |
| 388 notifications.ListenFor( | 395 notifications.ListenFor( |
| 389 content::NOTIFICATION_RENDER_VIEW_HOST_CHANGED, | 396 content::NOTIFICATION_RENDER_VIEW_HOST_CHANGED, |
| 390 content::Source<NavigationController>( | 397 content::Source<NavigationController>( |
| 391 &tab_contents.GetController())); | 398 &tab_contents.GetController())); |
| 392 | 399 |
| 393 // Create. | 400 // Create. |
| 394 RenderViewHostManager manager(&tab_contents, &tab_contents); | 401 RenderViewHostManager manager(&tab_contents, &tab_contents); |
| 395 | 402 |
| (...skipping 15 matching lines...) Expand all Loading... |
| 411 EXPECT_TRUE(notifications.Check1AndReset( | 418 EXPECT_TRUE(notifications.Check1AndReset( |
| 412 content::NOTIFICATION_RENDER_VIEW_HOST_CHANGED)); | 419 content::NOTIFICATION_RENDER_VIEW_HOST_CHANGED)); |
| 413 notifications.Reset(); | 420 notifications.Reset(); |
| 414 | 421 |
| 415 // Commit. | 422 // Commit. |
| 416 manager.DidNavigateMainFrame(host); | 423 manager.DidNavigateMainFrame(host); |
| 417 | 424 |
| 418 // Commit to SiteInstance should be delayed until RenderView commit. | 425 // Commit to SiteInstance should be delayed until RenderView commit. |
| 419 EXPECT_TRUE(host == manager.current_host()); | 426 EXPECT_TRUE(host == manager.current_host()); |
| 420 ASSERT_TRUE(host); | 427 ASSERT_TRUE(host); |
| 421 EXPECT_FALSE(host->site_instance()->has_site()); | 428 EXPECT_FALSE(static_cast<SiteInstanceImpl*>(host->site_instance())-> |
| 422 host->site_instance()->SetSite(kUrl1); | 429 HasSite()); |
| 430 static_cast<SiteInstanceImpl*>(host->site_instance())->SetSite(kUrl1); |
| 423 | 431 |
| 424 // 2) Cross-site navigate to next site. ------------------------- | 432 // 2) Cross-site navigate to next site. ------------------------- |
| 425 const GURL kUrl2("http://www.example.com"); | 433 const GURL kUrl2("http://www.example.com"); |
| 426 NavigationEntryImpl entry2( | 434 NavigationEntryImpl entry2( |
| 427 NULL /* instance */, -1 /* page_id */, kUrl2, content::Referrer(), | 435 NULL /* instance */, -1 /* page_id */, kUrl2, content::Referrer(), |
| 428 string16() /* title */, content::PAGE_TRANSITION_TYPED, | 436 string16() /* title */, content::PAGE_TRANSITION_TYPED, |
| 429 false /* is_renderer_init */); | 437 false /* is_renderer_init */); |
| 430 RenderViewHost* host2 = manager.Navigate(entry2); | 438 RenderViewHost* host2 = manager.Navigate(entry2); |
| 431 | 439 |
| 432 // A new RenderViewHost should be created. | 440 // A new RenderViewHost should be created. |
| (...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 495 // RenderViewHostManager::Navigate followed by RenderViewHost::Navigate. | 503 // RenderViewHostManager::Navigate followed by RenderViewHost::Navigate. |
| 496 // Here we need to call the latter ourselves. | 504 // Here we need to call the latter ourselves. |
| 497 host3->NavigateToURL(kUrl3); | 505 host3->NavigateToURL(kUrl3); |
| 498 EXPECT_TRUE(test_process_host3->sink().GetUniqueMessageMatching( | 506 EXPECT_TRUE(test_process_host3->sink().GetUniqueMessageMatching( |
| 499 ViewMsg_Navigate::ID)); | 507 ViewMsg_Navigate::ID)); |
| 500 | 508 |
| 501 // Commit. | 509 // Commit. |
| 502 manager.DidNavigateMainFrame(host3); | 510 manager.DidNavigateMainFrame(host3); |
| 503 EXPECT_TRUE(host3 == manager.current_host()); | 511 EXPECT_TRUE(host3 == manager.current_host()); |
| 504 ASSERT_TRUE(host3); | 512 ASSERT_TRUE(host3); |
| 505 EXPECT_TRUE(host3->site_instance()->has_site()); | 513 EXPECT_TRUE(static_cast<SiteInstanceImpl*>(host3->site_instance())-> |
| 514 HasSite()); |
| 506 // Check the pending RenderViewHost has been committed. | 515 // Check the pending RenderViewHost has been committed. |
| 507 EXPECT_FALSE(manager.pending_render_view_host()); | 516 EXPECT_FALSE(manager.pending_render_view_host()); |
| 508 | 517 |
| 509 // We should observe a notification. | 518 // We should observe a notification. |
| 510 EXPECT_TRUE(notifications.Check1AndReset( | 519 EXPECT_TRUE(notifications.Check1AndReset( |
| 511 content::NOTIFICATION_RENDER_VIEW_HOST_CHANGED)); | 520 content::NOTIFICATION_RENDER_VIEW_HOST_CHANGED)); |
| 512 } | 521 } |
| 513 | 522 |
| 514 // Tests WebUI creation. | 523 // Tests WebUI creation. |
| 515 TEST_F(RenderViewHostManagerTest, WebUI) { | 524 TEST_F(RenderViewHostManagerTest, WebUI) { |
| 516 set_should_create_webui(true); | 525 set_should_create_webui(true); |
| 517 BrowserThreadImpl ui_thread(BrowserThread::UI, MessageLoop::current()); | 526 BrowserThreadImpl ui_thread(BrowserThread::UI, MessageLoop::current()); |
| 518 SiteInstance* instance = SiteInstance::CreateSiteInstance(browser_context()); | 527 SiteInstance* instance = SiteInstance::Create(browser_context()); |
| 519 | 528 |
| 520 TestTabContents tab_contents(browser_context(), instance); | 529 TestTabContents tab_contents(browser_context(), instance); |
| 521 RenderViewHostManager manager(&tab_contents, &tab_contents); | 530 RenderViewHostManager manager(&tab_contents, &tab_contents); |
| 522 | 531 |
| 523 manager.Init(browser_context(), instance, MSG_ROUTING_NONE); | 532 manager.Init(browser_context(), instance, MSG_ROUTING_NONE); |
| 524 | 533 |
| 525 const GURL kUrl(chrome::kTestNewTabURL); | 534 const GURL kUrl(chrome::kTestNewTabURL); |
| 526 NavigationEntryImpl entry(NULL /* instance */, -1 /* page_id */, kUrl, | 535 NavigationEntryImpl entry(NULL /* instance */, -1 /* page_id */, kUrl, |
| 527 content::Referrer(), string16() /* title */, | 536 content::Referrer(), string16() /* title */, |
| 528 content::PAGE_TRANSITION_TYPED, | 537 content::PAGE_TRANSITION_TYPED, |
| 529 false /* is_renderer_init */); | 538 false /* is_renderer_init */); |
| 530 RenderViewHost* host = manager.Navigate(entry); | 539 RenderViewHost* host = manager.Navigate(entry); |
| 531 | 540 |
| 532 EXPECT_TRUE(host); | 541 EXPECT_TRUE(host); |
| 533 EXPECT_TRUE(host == manager.current_host()); | 542 EXPECT_TRUE(host == manager.current_host()); |
| 534 EXPECT_FALSE(manager.pending_render_view_host()); | 543 EXPECT_FALSE(manager.pending_render_view_host()); |
| 535 | 544 |
| 536 // It's important that the site instance get set on the Web UI page as soon | 545 // It's important that the site instance get set on the Web UI page as soon |
| 537 // as the navigation starts, rather than lazily after it commits, so we don't | 546 // as the navigation starts, rather than lazily after it commits, so we don't |
| 538 // try to re-use the SiteInstance/process for non DOM-UI things that may | 547 // try to re-use the SiteInstance/process for non DOM-UI things that may |
| 539 // get loaded in between. | 548 // get loaded in between. |
| 540 EXPECT_TRUE(host->site_instance()->has_site()); | 549 EXPECT_TRUE(static_cast<SiteInstanceImpl*>(host->site_instance())-> |
| 541 EXPECT_EQ(kUrl, host->site_instance()->site()); | 550 HasSite()); |
| 551 EXPECT_EQ(kUrl, host->site_instance()->GetSite()); |
| 542 | 552 |
| 543 // The Web UI is committed immediately because the RenderViewHost has not been | 553 // The Web UI is committed immediately because the RenderViewHost has not been |
| 544 // used yet. UpdateRendererStateForNavigate() took the short cut path. | 554 // used yet. UpdateRendererStateForNavigate() took the short cut path. |
| 545 EXPECT_FALSE(manager.pending_web_ui()); | 555 EXPECT_FALSE(manager.pending_web_ui()); |
| 546 EXPECT_TRUE(manager.web_ui()); | 556 EXPECT_TRUE(manager.web_ui()); |
| 547 | 557 |
| 548 // Commit. | 558 // Commit. |
| 549 manager.DidNavigateMainFrame(host); | 559 manager.DidNavigateMainFrame(host); |
| 550 } | 560 } |
| 551 | 561 |
| 552 // Tests that chrome: URLs that are not Web UI pages do not get grouped into | 562 // Tests that chrome: URLs that are not Web UI pages do not get grouped into |
| 553 // Web UI renderers, even if --process-per-tab is enabled. In that mode, we | 563 // Web UI renderers, even if --process-per-tab is enabled. In that mode, we |
| 554 // still swap processes if ShouldSwapProcessesForNavigation is true. | 564 // still swap processes if ShouldSwapProcessesForNavigation is true. |
| 555 // Regression test for bug 46290. | 565 // Regression test for bug 46290. |
| 556 TEST_F(RenderViewHostManagerTest, NonWebUIChromeURLs) { | 566 TEST_F(RenderViewHostManagerTest, NonWebUIChromeURLs) { |
| 557 BrowserThreadImpl thread(BrowserThread::UI, &message_loop_); | 567 BrowserThreadImpl thread(BrowserThread::UI, &message_loop_); |
| 558 SiteInstance* instance = SiteInstance::CreateSiteInstance(browser_context()); | 568 SiteInstance* instance = SiteInstance::Create(browser_context()); |
| 559 TestTabContents tab_contents(browser_context(), instance); | 569 TestTabContents tab_contents(browser_context(), instance); |
| 560 RenderViewHostManager manager(&tab_contents, &tab_contents); | 570 RenderViewHostManager manager(&tab_contents, &tab_contents); |
| 561 manager.Init(browser_context(), instance, MSG_ROUTING_NONE); | 571 manager.Init(browser_context(), instance, MSG_ROUTING_NONE); |
| 562 | 572 |
| 563 // NTP is a Web UI page. | 573 // NTP is a Web UI page. |
| 564 const GURL kNtpUrl(chrome::kTestNewTabURL); | 574 const GURL kNtpUrl(chrome::kTestNewTabURL); |
| 565 NavigationEntryImpl ntp_entry(NULL /* instance */, -1 /* page_id */, kNtpUrl, | 575 NavigationEntryImpl ntp_entry(NULL /* instance */, -1 /* page_id */, kNtpUrl, |
| 566 content::Referrer(), string16() /* title */, | 576 content::Referrer(), string16() /* title */, |
| 567 content::PAGE_TRANSITION_TYPED, | 577 content::PAGE_TRANSITION_TYPED, |
| 568 false /* is_renderer_init */); | 578 false /* is_renderer_init */); |
| (...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 615 // current one. | 625 // current one. |
| 616 EXPECT_TRUE(contents()->GetRenderManagerForTesting()-> | 626 EXPECT_TRUE(contents()->GetRenderManagerForTesting()-> |
| 617 pending_render_view_host() == NULL); | 627 pending_render_view_host() == NULL); |
| 618 EXPECT_EQ(evil_rvh, contents()->GetRenderManagerForTesting()->current_host()); | 628 EXPECT_EQ(evil_rvh, contents()->GetRenderManagerForTesting()->current_host()); |
| 619 | 629 |
| 620 // Also we should not have a pending navigation entry. | 630 // Also we should not have a pending navigation entry. |
| 621 NavigationEntry* entry = contents()->GetController().GetActiveEntry(); | 631 NavigationEntry* entry = contents()->GetController().GetActiveEntry(); |
| 622 ASSERT_TRUE(entry != NULL); | 632 ASSERT_TRUE(entry != NULL); |
| 623 EXPECT_EQ(kUrl2, entry->GetURL()); | 633 EXPECT_EQ(kUrl2, entry->GetURL()); |
| 624 } | 634 } |
| OLD | NEW |