| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 "chrome/test/base/chrome_render_view_host_test_harness.h" | 5 #include "chrome/test/base/chrome_render_view_host_test_harness.h" |
| 6 #include "chrome/test/base/testing_profile.h" | 6 #include "chrome/test/base/testing_profile.h" |
| 7 #include "content/browser/browser_thread.h" | 7 #include "content/browser/browser_thread.h" |
| 8 #include "content/browser/browser_url_handler.h" | 8 #include "content/browser/browser_url_handler.h" |
| 9 #include "content/browser/site_instance.h" | 9 #include "content/browser/site_instance.h" |
| 10 #include "content/browser/tab_contents/navigation_controller.h" | 10 #include "content/browser/tab_contents/navigation_controller.h" |
| (...skipping 188 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 199 RenderViewHostManager manager(&tab_contents, &tab_contents); | 199 RenderViewHostManager manager(&tab_contents, &tab_contents); |
| 200 | 200 |
| 201 manager.Init(profile(), instance, MSG_ROUTING_NONE); | 201 manager.Init(profile(), instance, MSG_ROUTING_NONE); |
| 202 | 202 |
| 203 RenderViewHost* host; | 203 RenderViewHost* host; |
| 204 | 204 |
| 205 // 1) The first navigation. -------------------------- | 205 // 1) The first navigation. -------------------------- |
| 206 const GURL kUrl1("http://www.google.com/"); | 206 const GURL kUrl1("http://www.google.com/"); |
| 207 NavigationEntry entry1(NULL /* instance */, -1 /* page_id */, kUrl1, | 207 NavigationEntry entry1(NULL /* instance */, -1 /* page_id */, kUrl1, |
| 208 GURL() /* referrer */, string16() /* title */, | 208 GURL() /* referrer */, string16() /* title */, |
| 209 content::PAGE_TRANSITION_TYPED); | 209 content::PAGE_TRANSITION_TYPED, |
| 210 false /* is_renderer_init */); |
| 210 host = manager.Navigate(entry1); | 211 host = manager.Navigate(entry1); |
| 211 | 212 |
| 212 // The RenderViewHost created in Init will be reused. | 213 // The RenderViewHost created in Init will be reused. |
| 213 EXPECT_TRUE(host == manager.current_host()); | 214 EXPECT_TRUE(host == manager.current_host()); |
| 214 EXPECT_FALSE(manager.pending_render_view_host()); | 215 EXPECT_FALSE(manager.pending_render_view_host()); |
| 215 | 216 |
| 216 // Commit. | 217 // Commit. |
| 217 manager.DidNavigateMainFrame(host); | 218 manager.DidNavigateMainFrame(host); |
| 218 // Commit to SiteInstance should be delayed until RenderView commit. | 219 // Commit to SiteInstance should be delayed until RenderView commit. |
| 219 EXPECT_TRUE(host == manager.current_host()); | 220 EXPECT_TRUE(host == manager.current_host()); |
| 220 ASSERT_TRUE(host); | 221 ASSERT_TRUE(host); |
| 221 EXPECT_FALSE(host->site_instance()->has_site()); | 222 EXPECT_FALSE(host->site_instance()->has_site()); |
| 222 host->site_instance()->SetSite(kUrl1); | 223 host->site_instance()->SetSite(kUrl1); |
| 223 | 224 |
| 224 // 2) Navigate to next site. ------------------------- | 225 // 2) Navigate to next site. ------------------------- |
| 225 const GURL kUrl2("http://www.google.com/foo"); | 226 const GURL kUrl2("http://www.google.com/foo"); |
| 226 NavigationEntry entry2(NULL /* instance */, -1 /* page_id */, kUrl2, | 227 NavigationEntry entry2(NULL /* instance */, -1 /* page_id */, kUrl2, |
| 227 kUrl1 /* referrer */, string16() /* title */, | 228 kUrl1 /* referrer */, string16() /* title */, |
| 228 content::PAGE_TRANSITION_LINK); | 229 content::PAGE_TRANSITION_LINK, |
| 230 true /* is_renderer_init */); |
| 229 host = manager.Navigate(entry2); | 231 host = manager.Navigate(entry2); |
| 230 | 232 |
| 231 // The RenderViewHost created in Init will be reused. | 233 // The RenderViewHost created in Init will be reused. |
| 232 EXPECT_TRUE(host == manager.current_host()); | 234 EXPECT_TRUE(host == manager.current_host()); |
| 233 EXPECT_FALSE(manager.pending_render_view_host()); | 235 EXPECT_FALSE(manager.pending_render_view_host()); |
| 234 | 236 |
| 235 // Commit. | 237 // Commit. |
| 236 manager.DidNavigateMainFrame(host); | 238 manager.DidNavigateMainFrame(host); |
| 237 EXPECT_TRUE(host == manager.current_host()); | 239 EXPECT_TRUE(host == manager.current_host()); |
| 238 ASSERT_TRUE(host); | 240 ASSERT_TRUE(host); |
| 239 EXPECT_TRUE(host->site_instance()->has_site()); | 241 EXPECT_TRUE(host->site_instance()->has_site()); |
| 240 | 242 |
| 241 // 3) Cross-site navigate to next site. -------------- | 243 // 3) Cross-site navigate to next site. -------------- |
| 242 const GURL kUrl3("http://webkit.org/"); | 244 const GURL kUrl3("http://webkit.org/"); |
| 243 NavigationEntry entry3(NULL /* instance */, -1 /* page_id */, kUrl3, | 245 NavigationEntry entry3(NULL /* instance */, -1 /* page_id */, kUrl3, |
| 244 kUrl2 /* referrer */, string16() /* title */, | 246 kUrl2 /* referrer */, string16() /* title */, |
| 245 content::PAGE_TRANSITION_LINK); | 247 content::PAGE_TRANSITION_LINK, |
| 248 false /* is_renderer_init */); |
| 246 host = manager.Navigate(entry3); | 249 host = manager.Navigate(entry3); |
| 247 | 250 |
| 248 // A new RenderViewHost should be created. | 251 // A new RenderViewHost should be created. |
| 249 EXPECT_TRUE(manager.pending_render_view_host()); | 252 EXPECT_TRUE(manager.pending_render_view_host()); |
| 250 ASSERT_EQ(host, manager.pending_render_view_host()); | 253 ASSERT_EQ(host, manager.pending_render_view_host()); |
| 251 | 254 |
| 252 notifications.Reset(); | 255 notifications.Reset(); |
| 253 | 256 |
| 254 // Commit. | 257 // Commit. |
| 255 manager.DidNavigateMainFrame(manager.pending_render_view_host()); | 258 manager.DidNavigateMainFrame(manager.pending_render_view_host()); |
| (...skipping 14 matching lines...) Expand all Loading... |
| 270 SiteInstance* instance = SiteInstance::CreateSiteInstance(profile()); | 273 SiteInstance* instance = SiteInstance::CreateSiteInstance(profile()); |
| 271 | 274 |
| 272 TestTabContents tab_contents(profile(), instance); | 275 TestTabContents tab_contents(profile(), instance); |
| 273 RenderViewHostManager manager(&tab_contents, &tab_contents); | 276 RenderViewHostManager manager(&tab_contents, &tab_contents); |
| 274 | 277 |
| 275 manager.Init(profile(), instance, MSG_ROUTING_NONE); | 278 manager.Init(profile(), instance, MSG_ROUTING_NONE); |
| 276 | 279 |
| 277 const GURL kUrl(chrome::kTestNewTabURL); | 280 const GURL kUrl(chrome::kTestNewTabURL); |
| 278 NavigationEntry entry(NULL /* instance */, -1 /* page_id */, kUrl, | 281 NavigationEntry entry(NULL /* instance */, -1 /* page_id */, kUrl, |
| 279 GURL() /* referrer */, string16() /* title */, | 282 GURL() /* referrer */, string16() /* title */, |
| 280 content::PAGE_TRANSITION_TYPED); | 283 content::PAGE_TRANSITION_TYPED, |
| 284 false /* is_renderer_init */); |
| 281 RenderViewHost* host = manager.Navigate(entry); | 285 RenderViewHost* host = manager.Navigate(entry); |
| 282 | 286 |
| 283 EXPECT_TRUE(host); | 287 EXPECT_TRUE(host); |
| 284 EXPECT_TRUE(host == manager.current_host()); | 288 EXPECT_TRUE(host == manager.current_host()); |
| 285 EXPECT_FALSE(manager.pending_render_view_host()); | 289 EXPECT_FALSE(manager.pending_render_view_host()); |
| 286 | 290 |
| 287 // It's important that the site instance get set on the Web UI page as soon | 291 // It's important that the site instance get set on the Web UI page as soon |
| 288 // as the navigation starts, rather than lazily after it commits, so we don't | 292 // as the navigation starts, rather than lazily after it commits, so we don't |
| 289 // try to re-use the SiteInstance/process for non DOM-UI things that may | 293 // try to re-use the SiteInstance/process for non DOM-UI things that may |
| 290 // get loaded in between. | 294 // get loaded in between. |
| (...skipping 17 matching lines...) Expand all Loading... |
| 308 BrowserThread thread(BrowserThread::UI, &message_loop_); | 312 BrowserThread thread(BrowserThread::UI, &message_loop_); |
| 309 SiteInstance* instance = SiteInstance::CreateSiteInstance(profile()); | 313 SiteInstance* instance = SiteInstance::CreateSiteInstance(profile()); |
| 310 TestTabContents tab_contents(profile(), instance); | 314 TestTabContents tab_contents(profile(), instance); |
| 311 RenderViewHostManager manager(&tab_contents, &tab_contents); | 315 RenderViewHostManager manager(&tab_contents, &tab_contents); |
| 312 manager.Init(profile(), instance, MSG_ROUTING_NONE); | 316 manager.Init(profile(), instance, MSG_ROUTING_NONE); |
| 313 | 317 |
| 314 // NTP is a Web UI page. | 318 // NTP is a Web UI page. |
| 315 const GURL kNtpUrl(chrome::kTestNewTabURL); | 319 const GURL kNtpUrl(chrome::kTestNewTabURL); |
| 316 NavigationEntry ntp_entry(NULL /* instance */, -1 /* page_id */, kNtpUrl, | 320 NavigationEntry ntp_entry(NULL /* instance */, -1 /* page_id */, kNtpUrl, |
| 317 GURL() /* referrer */, string16() /* title */, | 321 GURL() /* referrer */, string16() /* title */, |
| 318 content::PAGE_TRANSITION_TYPED); | 322 content::PAGE_TRANSITION_TYPED, |
| 323 false /* is_renderer_init */); |
| 319 | 324 |
| 320 // about: URLs are not Web UI pages. | 325 // about: URLs are not Web UI pages. |
| 321 GURL about_url(chrome::kTestMemoryURL); | 326 GURL about_url(chrome::kTestMemoryURL); |
| 322 // Rewrite so it looks like chrome://about/memory | 327 // Rewrite so it looks like chrome://about/memory |
| 323 bool reverse_on_redirect = false; | 328 bool reverse_on_redirect = false; |
| 324 BrowserURLHandler::GetInstance()->RewriteURLIfNecessary( | 329 BrowserURLHandler::GetInstance()->RewriteURLIfNecessary( |
| 325 &about_url, profile(), &reverse_on_redirect); | 330 &about_url, profile(), &reverse_on_redirect); |
| 326 NavigationEntry about_entry(NULL /* instance */, -1 /* page_id */, about_url, | 331 NavigationEntry about_entry(NULL /* instance */, -1 /* page_id */, about_url, |
| 327 GURL() /* referrer */, string16() /* title */, | 332 GURL() /* referrer */, string16() /* title */, |
| 328 content::PAGE_TRANSITION_TYPED); | 333 content::PAGE_TRANSITION_TYPED, |
| 334 false /* is_renderer_init */); |
| 329 | 335 |
| 330 EXPECT_TRUE(ShouldSwapProcesses(&manager, &ntp_entry, &about_entry)); | 336 EXPECT_TRUE(ShouldSwapProcesses(&manager, &ntp_entry, &about_entry)); |
| 331 } | 337 } |
| 332 | 338 |
| 333 // Tests that we don't end up in an inconsistent state if a page does a back and | 339 // Tests that we don't end up in an inconsistent state if a page does a back and |
| 334 // then reload. http://crbug.com/51680 | 340 // then reload. http://crbug.com/51680 |
| 335 TEST_F(RenderViewHostManagerTest, PageDoesBackAndReload) { | 341 TEST_F(RenderViewHostManagerTest, PageDoesBackAndReload) { |
| 336 const GURL kUrl1("http://www.google.com/"); | 342 const GURL kUrl1("http://www.google.com/"); |
| 337 const GURL kUrl2("http://www.evil-site.com/"); | 343 const GURL kUrl2("http://www.evil-site.com/"); |
| 338 | 344 |
| (...skipping 29 matching lines...) Expand all Loading... |
| 368 // current one. | 374 // current one. |
| 369 EXPECT_TRUE(contents()->render_manager_for_testing()-> | 375 EXPECT_TRUE(contents()->render_manager_for_testing()-> |
| 370 pending_render_view_host() == NULL); | 376 pending_render_view_host() == NULL); |
| 371 EXPECT_EQ(evil_rvh, contents()->render_manager_for_testing()->current_host()); | 377 EXPECT_EQ(evil_rvh, contents()->render_manager_for_testing()->current_host()); |
| 372 | 378 |
| 373 // Also we should not have a pending navigation entry. | 379 // Also we should not have a pending navigation entry. |
| 374 NavigationEntry* entry = contents()->controller().GetActiveEntry(); | 380 NavigationEntry* entry = contents()->controller().GetActiveEntry(); |
| 375 ASSERT_TRUE(entry != NULL); | 381 ASSERT_TRUE(entry != NULL); |
| 376 EXPECT_EQ(kUrl2, entry->url()); | 382 EXPECT_EQ(kUrl2, entry->url()); |
| 377 } | 383 } |
| OLD | NEW |