| 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 "base/logging.h" | 5 #include "base/logging.h" |
| 6 #include "base/utf_string_conversions.h" | 6 #include "base/utf_string_conversions.h" |
| 7 #include "chrome/browser/dom_operation_notification_details.h" | 7 #include "chrome/browser/dom_operation_notification_details.h" |
| 8 #include "chrome/browser/prefs/pref_service.h" | 8 #include "chrome/browser/prefs/pref_service.h" |
| 9 #include "chrome/browser/tab_contents/chrome_interstitial_page.h" | 9 #include "chrome/browser/tab_contents/chrome_interstitial_page.h" |
| 10 #include "chrome/common/chrome_notification_types.h" | 10 #include "chrome/common/chrome_notification_types.h" |
| (...skipping 207 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 218 } | 218 } |
| 219 | 219 |
| 220 // Test view source mode for the new tabs page. | 220 // Test view source mode for the new tabs page. |
| 221 TEST_F(TabContentsTest, NTPViewSource) { | 221 TEST_F(TabContentsTest, NTPViewSource) { |
| 222 const char kUrl[] = "view-source:chrome://newtab"; | 222 const char kUrl[] = "view-source:chrome://newtab"; |
| 223 const GURL kGURL(kUrl); | 223 const GURL kGURL(kUrl); |
| 224 | 224 |
| 225 process()->sink().ClearMessages(); | 225 process()->sink().ClearMessages(); |
| 226 | 226 |
| 227 controller().LoadURL( | 227 controller().LoadURL( |
| 228 kGURL, GURL(), content::PAGE_TRANSITION_TYPED, std::string()); | 228 kGURL, content::Referrer(), content::PAGE_TRANSITION_TYPED, |
| 229 std::string()); |
| 229 rvh()->delegate()->RenderViewCreated(rvh()); | 230 rvh()->delegate()->RenderViewCreated(rvh()); |
| 230 // Did we get the expected message? | 231 // Did we get the expected message? |
| 231 EXPECT_TRUE(process()->sink().GetFirstMessageMatching( | 232 EXPECT_TRUE(process()->sink().GetFirstMessageMatching( |
| 232 ViewMsg_EnableViewSourceMode::ID)); | 233 ViewMsg_EnableViewSourceMode::ID)); |
| 233 | 234 |
| 234 ViewHostMsg_FrameNavigate_Params params; | 235 ViewHostMsg_FrameNavigate_Params params; |
| 235 InitNavigateParams(¶ms, 0, kGURL, content::PAGE_TRANSITION_TYPED); | 236 InitNavigateParams(¶ms, 0, kGURL, content::PAGE_TRANSITION_TYPED); |
| 236 content::LoadCommittedDetails details; | 237 content::LoadCommittedDetails details; |
| 237 controller().RendererDidNavigate(params, &details); | 238 controller().RendererDidNavigate(params, &details); |
| 238 // Also check title and url. | 239 // Also check title and url. |
| 239 EXPECT_EQ(ASCIIToUTF16(kUrl), contents()->GetTitle()); | 240 EXPECT_EQ(ASCIIToUTF16(kUrl), contents()->GetTitle()); |
| 240 } | 241 } |
| 241 | 242 |
| 242 // Test simple same-SiteInstance navigation. | 243 // Test simple same-SiteInstance navigation. |
| 243 TEST_F(TabContentsTest, SimpleNavigation) { | 244 TEST_F(TabContentsTest, SimpleNavigation) { |
| 244 TestRenderViewHost* orig_rvh = rvh(); | 245 TestRenderViewHost* orig_rvh = rvh(); |
| 245 SiteInstance* instance1 = contents()->GetSiteInstance(); | 246 SiteInstance* instance1 = contents()->GetSiteInstance(); |
| 246 EXPECT_TRUE(contents()->pending_rvh() == NULL); | 247 EXPECT_TRUE(contents()->pending_rvh() == NULL); |
| 247 | 248 |
| 248 // Navigate to URL | 249 // Navigate to URL |
| 249 const GURL url("http://www.google.com"); | 250 const GURL url("http://www.google.com"); |
| 250 controller().LoadURL( | 251 controller().LoadURL( |
| 251 url, GURL(), content::PAGE_TRANSITION_TYPED, std::string()); | 252 url, content::Referrer(), content::PAGE_TRANSITION_TYPED, std::string()); |
| 252 EXPECT_FALSE(contents()->cross_navigation_pending()); | 253 EXPECT_FALSE(contents()->cross_navigation_pending()); |
| 253 EXPECT_EQ(instance1, orig_rvh->site_instance()); | 254 EXPECT_EQ(instance1, orig_rvh->site_instance()); |
| 254 // Controller's pending entry will have a NULL site instance until we assign | 255 // Controller's pending entry will have a NULL site instance until we assign |
| 255 // it in DidNavigate. | 256 // it in DidNavigate. |
| 256 EXPECT_TRUE(controller().GetActiveEntry()->site_instance() == NULL); | 257 EXPECT_TRUE(controller().GetActiveEntry()->site_instance() == NULL); |
| 257 | 258 |
| 258 // DidNavigate from the page | 259 // DidNavigate from the page |
| 259 ViewHostMsg_FrameNavigate_Params params; | 260 ViewHostMsg_FrameNavigate_Params params; |
| 260 InitNavigateParams(¶ms, 1, url, content::PAGE_TRANSITION_TYPED); | 261 InitNavigateParams(¶ms, 1, url, content::PAGE_TRANSITION_TYPED); |
| 261 contents()->TestDidNavigate(orig_rvh, params); | 262 contents()->TestDidNavigate(orig_rvh, params); |
| 262 EXPECT_FALSE(contents()->cross_navigation_pending()); | 263 EXPECT_FALSE(contents()->cross_navigation_pending()); |
| 263 EXPECT_EQ(orig_rvh, contents()->render_view_host()); | 264 EXPECT_EQ(orig_rvh, contents()->render_view_host()); |
| 264 EXPECT_EQ(instance1, orig_rvh->site_instance()); | 265 EXPECT_EQ(instance1, orig_rvh->site_instance()); |
| 265 // Controller's entry should now have the SiteInstance, or else we won't be | 266 // Controller's entry should now have the SiteInstance, or else we won't be |
| 266 // able to find it later. | 267 // able to find it later. |
| 267 EXPECT_EQ(instance1, controller().GetActiveEntry()->site_instance()); | 268 EXPECT_EQ(instance1, controller().GetActiveEntry()->site_instance()); |
| 268 } | 269 } |
| 269 | 270 |
| 270 // Test that we reject NavigateToEntry if the url is over content::kMaxURLChars. | 271 // Test that we reject NavigateToEntry if the url is over content::kMaxURLChars. |
| 271 TEST_F(TabContentsTest, NavigateToExcessivelyLongURL) { | 272 TEST_F(TabContentsTest, NavigateToExcessivelyLongURL) { |
| 272 // Construct a URL that's kMaxURLChars + 1 long of all 'a's. | 273 // Construct a URL that's kMaxURLChars + 1 long of all 'a's. |
| 273 const GURL url(std::string("http://example.org/").append( | 274 const GURL url(std::string("http://example.org/").append( |
| 274 content::kMaxURLChars + 1, 'a')); | 275 content::kMaxURLChars + 1, 'a')); |
| 275 | 276 |
| 276 controller().LoadURL( | 277 controller().LoadURL( |
| 277 url, GURL(), content::PAGE_TRANSITION_GENERATED, std::string()); | 278 url, content::Referrer(), content::PAGE_TRANSITION_GENERATED, |
| 279 std::string()); |
| 278 EXPECT_TRUE(controller().GetActiveEntry() == NULL); | 280 EXPECT_TRUE(controller().GetActiveEntry() == NULL); |
| 279 } | 281 } |
| 280 | 282 |
| 281 // Test that navigating across a site boundary creates a new RenderViewHost | 283 // Test that navigating across a site boundary creates a new RenderViewHost |
| 282 // with a new SiteInstance. Going back should do the same. | 284 // with a new SiteInstance. Going back should do the same. |
| 283 TEST_F(TabContentsTest, CrossSiteBoundaries) { | 285 TEST_F(TabContentsTest, CrossSiteBoundaries) { |
| 284 contents()->transition_cross_site = true; | 286 contents()->transition_cross_site = true; |
| 285 TestRenderViewHost* orig_rvh = rvh(); | 287 TestRenderViewHost* orig_rvh = rvh(); |
| 286 int orig_rvh_delete_count = 0; | 288 int orig_rvh_delete_count = 0; |
| 287 orig_rvh->set_delete_counter(&orig_rvh_delete_count); | 289 orig_rvh->set_delete_counter(&orig_rvh_delete_count); |
| 288 SiteInstance* instance1 = contents()->GetSiteInstance(); | 290 SiteInstance* instance1 = contents()->GetSiteInstance(); |
| 289 | 291 |
| 290 // Navigate to URL. First URL should use first RenderViewHost. | 292 // Navigate to URL. First URL should use first RenderViewHost. |
| 291 const GURL url("http://www.google.com"); | 293 const GURL url("http://www.google.com"); |
| 292 controller().LoadURL( | 294 controller().LoadURL( |
| 293 url, GURL(), content::PAGE_TRANSITION_TYPED, std::string()); | 295 url, content::Referrer(), content::PAGE_TRANSITION_TYPED, std::string()); |
| 294 ViewHostMsg_FrameNavigate_Params params1; | 296 ViewHostMsg_FrameNavigate_Params params1; |
| 295 InitNavigateParams(¶ms1, 1, url, content::PAGE_TRANSITION_TYPED); | 297 InitNavigateParams(¶ms1, 1, url, content::PAGE_TRANSITION_TYPED); |
| 296 contents()->TestDidNavigate(orig_rvh, params1); | 298 contents()->TestDidNavigate(orig_rvh, params1); |
| 297 | 299 |
| 298 EXPECT_FALSE(contents()->cross_navigation_pending()); | 300 EXPECT_FALSE(contents()->cross_navigation_pending()); |
| 299 EXPECT_EQ(orig_rvh, contents()->render_view_host()); | 301 EXPECT_EQ(orig_rvh, contents()->render_view_host()); |
| 300 | 302 |
| 301 // Navigate to new site | 303 // Navigate to new site |
| 302 const GURL url2("http://www.yahoo.com"); | 304 const GURL url2("http://www.yahoo.com"); |
| 303 controller().LoadURL( | 305 controller().LoadURL( |
| 304 url2, GURL(), content::PAGE_TRANSITION_TYPED, std::string()); | 306 url2, content::Referrer(), content::PAGE_TRANSITION_TYPED, std::string()); |
| 305 EXPECT_TRUE(contents()->cross_navigation_pending()); | 307 EXPECT_TRUE(contents()->cross_navigation_pending()); |
| 306 TestRenderViewHost* pending_rvh = contents()->pending_rvh(); | 308 TestRenderViewHost* pending_rvh = contents()->pending_rvh(); |
| 307 int pending_rvh_delete_count = 0; | 309 int pending_rvh_delete_count = 0; |
| 308 pending_rvh->set_delete_counter(&pending_rvh_delete_count); | 310 pending_rvh->set_delete_counter(&pending_rvh_delete_count); |
| 309 | 311 |
| 310 // Navigations should be suspended in pending_rvh until ShouldCloseACK. | 312 // Navigations should be suspended in pending_rvh until ShouldCloseACK. |
| 311 EXPECT_TRUE(pending_rvh->are_navigations_suspended()); | 313 EXPECT_TRUE(pending_rvh->are_navigations_suspended()); |
| 312 orig_rvh->SendShouldCloseACK(true); | 314 orig_rvh->SendShouldCloseACK(true); |
| 313 EXPECT_FALSE(pending_rvh->are_navigations_suspended()); | 315 EXPECT_FALSE(pending_rvh->are_navigations_suspended()); |
| 314 | 316 |
| (...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 360 TEST_F(TabContentsTest, CrossSiteBoundariesAfterCrash) { | 362 TEST_F(TabContentsTest, CrossSiteBoundariesAfterCrash) { |
| 361 contents()->transition_cross_site = true; | 363 contents()->transition_cross_site = true; |
| 362 TestRenderViewHost* orig_rvh = rvh(); | 364 TestRenderViewHost* orig_rvh = rvh(); |
| 363 int orig_rvh_delete_count = 0; | 365 int orig_rvh_delete_count = 0; |
| 364 orig_rvh->set_delete_counter(&orig_rvh_delete_count); | 366 orig_rvh->set_delete_counter(&orig_rvh_delete_count); |
| 365 SiteInstance* instance1 = contents()->GetSiteInstance(); | 367 SiteInstance* instance1 = contents()->GetSiteInstance(); |
| 366 | 368 |
| 367 // Navigate to URL. First URL should use first RenderViewHost. | 369 // Navigate to URL. First URL should use first RenderViewHost. |
| 368 const GURL url("http://www.google.com"); | 370 const GURL url("http://www.google.com"); |
| 369 controller().LoadURL( | 371 controller().LoadURL( |
| 370 url, GURL(), content::PAGE_TRANSITION_TYPED, std::string()); | 372 url, content::Referrer(), content::PAGE_TRANSITION_TYPED, std::string()); |
| 371 ViewHostMsg_FrameNavigate_Params params1; | 373 ViewHostMsg_FrameNavigate_Params params1; |
| 372 InitNavigateParams(¶ms1, 1, url, content::PAGE_TRANSITION_TYPED); | 374 InitNavigateParams(¶ms1, 1, url, content::PAGE_TRANSITION_TYPED); |
| 373 contents()->TestDidNavigate(orig_rvh, params1); | 375 contents()->TestDidNavigate(orig_rvh, params1); |
| 374 | 376 |
| 375 EXPECT_FALSE(contents()->cross_navigation_pending()); | 377 EXPECT_FALSE(contents()->cross_navigation_pending()); |
| 376 EXPECT_EQ(orig_rvh, contents()->render_view_host()); | 378 EXPECT_EQ(orig_rvh, contents()->render_view_host()); |
| 377 | 379 |
| 378 // Crash the renderer. | 380 // Crash the renderer. |
| 379 orig_rvh->set_render_view_created(false); | 381 orig_rvh->set_render_view_created(false); |
| 380 | 382 |
| 381 // Navigate to new site. We should not go into PENDING. | 383 // Navigate to new site. We should not go into PENDING. |
| 382 const GURL url2("http://www.yahoo.com"); | 384 const GURL url2("http://www.yahoo.com"); |
| 383 controller().LoadURL( | 385 controller().LoadURL( |
| 384 url2, GURL(), content::PAGE_TRANSITION_TYPED, std::string()); | 386 url2, content::Referrer(), content::PAGE_TRANSITION_TYPED, std::string()); |
| 385 TestRenderViewHost* new_rvh = rvh(); | 387 TestRenderViewHost* new_rvh = rvh(); |
| 386 EXPECT_FALSE(contents()->cross_navigation_pending()); | 388 EXPECT_FALSE(contents()->cross_navigation_pending()); |
| 387 EXPECT_TRUE(contents()->pending_rvh() == NULL); | 389 EXPECT_TRUE(contents()->pending_rvh() == NULL); |
| 388 EXPECT_NE(orig_rvh, new_rvh); | 390 EXPECT_NE(orig_rvh, new_rvh); |
| 389 EXPECT_EQ(orig_rvh_delete_count, 1); | 391 EXPECT_EQ(orig_rvh_delete_count, 1); |
| 390 | 392 |
| 391 // DidNavigate from the new page | 393 // DidNavigate from the new page |
| 392 ViewHostMsg_FrameNavigate_Params params2; | 394 ViewHostMsg_FrameNavigate_Params params2; |
| 393 InitNavigateParams(¶ms2, 1, url2, content::PAGE_TRANSITION_TYPED); | 395 InitNavigateParams(¶ms2, 1, url2, content::PAGE_TRANSITION_TYPED); |
| 394 contents()->TestDidNavigate(new_rvh, params2); | 396 contents()->TestDidNavigate(new_rvh, params2); |
| (...skipping 12 matching lines...) Expand all Loading... |
| 407 // Test that opening a new tab in the same SiteInstance and then navigating | 409 // Test that opening a new tab in the same SiteInstance and then navigating |
| 408 // both tabs to a new site will place both tabs in a single SiteInstance. | 410 // both tabs to a new site will place both tabs in a single SiteInstance. |
| 409 TEST_F(TabContentsTest, NavigateTwoTabsCrossSite) { | 411 TEST_F(TabContentsTest, NavigateTwoTabsCrossSite) { |
| 410 contents()->transition_cross_site = true; | 412 contents()->transition_cross_site = true; |
| 411 TestRenderViewHost* orig_rvh = rvh(); | 413 TestRenderViewHost* orig_rvh = rvh(); |
| 412 SiteInstance* instance1 = contents()->GetSiteInstance(); | 414 SiteInstance* instance1 = contents()->GetSiteInstance(); |
| 413 | 415 |
| 414 // Navigate to URL. First URL should use first RenderViewHost. | 416 // Navigate to URL. First URL should use first RenderViewHost. |
| 415 const GURL url("http://www.google.com"); | 417 const GURL url("http://www.google.com"); |
| 416 controller().LoadURL( | 418 controller().LoadURL( |
| 417 url, GURL(), content::PAGE_TRANSITION_TYPED, std::string()); | 419 url, content::Referrer(), content::PAGE_TRANSITION_TYPED, std::string()); |
| 418 ViewHostMsg_FrameNavigate_Params params1; | 420 ViewHostMsg_FrameNavigate_Params params1; |
| 419 InitNavigateParams(¶ms1, 1, url, content::PAGE_TRANSITION_TYPED); | 421 InitNavigateParams(¶ms1, 1, url, content::PAGE_TRANSITION_TYPED); |
| 420 contents()->TestDidNavigate(orig_rvh, params1); | 422 contents()->TestDidNavigate(orig_rvh, params1); |
| 421 | 423 |
| 422 // Open a new tab with the same SiteInstance, navigated to the same site. | 424 // Open a new tab with the same SiteInstance, navigated to the same site. |
| 423 TestTabContents contents2(profile(), instance1); | 425 TestTabContents contents2(profile(), instance1); |
| 424 params1.page_id = 2; // Need this since the site instance is the same (which | 426 params1.page_id = 2; // Need this since the site instance is the same (which |
| 425 // is the scope of page IDs) and we want to consider | 427 // is the scope of page IDs) and we want to consider |
| 426 // this a new page. | 428 // this a new page. |
| 427 contents2.transition_cross_site = true; | 429 contents2.transition_cross_site = true; |
| 428 contents2.controller().LoadURL(url, GURL(), content::PAGE_TRANSITION_TYPED, | 430 contents2.controller().LoadURL(url, content::Referrer(), |
| 431 content::PAGE_TRANSITION_TYPED, |
| 429 std::string()); | 432 std::string()); |
| 430 contents2.TestDidNavigate(contents2.render_view_host(), params1); | 433 contents2.TestDidNavigate(contents2.render_view_host(), params1); |
| 431 | 434 |
| 432 // Navigate first tab to a new site | 435 // Navigate first tab to a new site |
| 433 const GURL url2a("http://www.yahoo.com"); | 436 const GURL url2a("http://www.yahoo.com"); |
| 434 controller().LoadURL( | 437 controller().LoadURL( |
| 435 url2a, GURL(), content::PAGE_TRANSITION_TYPED, std::string()); | 438 url2a, content::Referrer(), content::PAGE_TRANSITION_TYPED, |
| 439 std::string()); |
| 436 orig_rvh->SendShouldCloseACK(true); | 440 orig_rvh->SendShouldCloseACK(true); |
| 437 TestRenderViewHost* pending_rvh_a = contents()->pending_rvh(); | 441 TestRenderViewHost* pending_rvh_a = contents()->pending_rvh(); |
| 438 ViewHostMsg_FrameNavigate_Params params2a; | 442 ViewHostMsg_FrameNavigate_Params params2a; |
| 439 InitNavigateParams(¶ms2a, 1, url2a, content::PAGE_TRANSITION_TYPED); | 443 InitNavigateParams(¶ms2a, 1, url2a, content::PAGE_TRANSITION_TYPED); |
| 440 contents()->TestDidNavigate(pending_rvh_a, params2a); | 444 contents()->TestDidNavigate(pending_rvh_a, params2a); |
| 441 SiteInstance* instance2a = contents()->GetSiteInstance(); | 445 SiteInstance* instance2a = contents()->GetSiteInstance(); |
| 442 EXPECT_NE(instance1, instance2a); | 446 EXPECT_NE(instance1, instance2a); |
| 443 | 447 |
| 444 // Navigate second tab to the same site as the first tab | 448 // Navigate second tab to the same site as the first tab |
| 445 const GURL url2b("http://mail.yahoo.com"); | 449 const GURL url2b("http://mail.yahoo.com"); |
| 446 contents2.controller().LoadURL(url2b, GURL(), content::PAGE_TRANSITION_TYPED, | 450 contents2.controller().LoadURL(url2b, content::Referrer(), |
| 451 content::PAGE_TRANSITION_TYPED, |
| 447 std::string()); | 452 std::string()); |
| 448 TestRenderViewHost* rvh2 = | 453 TestRenderViewHost* rvh2 = |
| 449 static_cast<TestRenderViewHost*>(contents2.render_view_host()); | 454 static_cast<TestRenderViewHost*>(contents2.render_view_host()); |
| 450 rvh2->SendShouldCloseACK(true); | 455 rvh2->SendShouldCloseACK(true); |
| 451 TestRenderViewHost* pending_rvh_b = contents2.pending_rvh(); | 456 TestRenderViewHost* pending_rvh_b = contents2.pending_rvh(); |
| 452 EXPECT_TRUE(pending_rvh_b != NULL); | 457 EXPECT_TRUE(pending_rvh_b != NULL); |
| 453 EXPECT_TRUE(contents2.cross_navigation_pending()); | 458 EXPECT_TRUE(contents2.cross_navigation_pending()); |
| 454 | 459 |
| 455 // NOTE(creis): We used to be in danger of showing a sad tab page here if the | 460 // NOTE(creis): We used to be in danger of showing a sad tab page here if the |
| 456 // second tab hadn't navigated somewhere first (bug 1145430). That case is | 461 // second tab hadn't navigated somewhere first (bug 1145430). That case is |
| (...skipping 12 matching lines...) Expand all Loading... |
| 469 // Tests that TabContents uses the current URL, not the SiteInstance's site, to | 474 // Tests that TabContents uses the current URL, not the SiteInstance's site, to |
| 470 // determine whether a navigation is cross-site. | 475 // determine whether a navigation is cross-site. |
| 471 TEST_F(TabContentsTest, CrossSiteComparesAgainstCurrentPage) { | 476 TEST_F(TabContentsTest, CrossSiteComparesAgainstCurrentPage) { |
| 472 contents()->transition_cross_site = true; | 477 contents()->transition_cross_site = true; |
| 473 TestRenderViewHost* orig_rvh = rvh(); | 478 TestRenderViewHost* orig_rvh = rvh(); |
| 474 SiteInstance* instance1 = contents()->GetSiteInstance(); | 479 SiteInstance* instance1 = contents()->GetSiteInstance(); |
| 475 | 480 |
| 476 // Navigate to URL. | 481 // Navigate to URL. |
| 477 const GURL url("http://www.google.com"); | 482 const GURL url("http://www.google.com"); |
| 478 controller().LoadURL( | 483 controller().LoadURL( |
| 479 url, GURL(), content::PAGE_TRANSITION_TYPED, std::string()); | 484 url, content::Referrer(), content::PAGE_TRANSITION_TYPED, std::string()); |
| 480 ViewHostMsg_FrameNavigate_Params params1; | 485 ViewHostMsg_FrameNavigate_Params params1; |
| 481 InitNavigateParams(¶ms1, 1, url, content::PAGE_TRANSITION_TYPED); | 486 InitNavigateParams(¶ms1, 1, url, content::PAGE_TRANSITION_TYPED); |
| 482 contents()->TestDidNavigate(orig_rvh, params1); | 487 contents()->TestDidNavigate(orig_rvh, params1); |
| 483 | 488 |
| 484 // Open a related tab to a second site. | 489 // Open a related tab to a second site. |
| 485 TestTabContents contents2(profile(), instance1); | 490 TestTabContents contents2(profile(), instance1); |
| 486 contents2.transition_cross_site = true; | 491 contents2.transition_cross_site = true; |
| 487 const GURL url2("http://www.yahoo.com"); | 492 const GURL url2("http://www.yahoo.com"); |
| 488 contents2.controller().LoadURL(url2, GURL(), content::PAGE_TRANSITION_TYPED, | 493 contents2.controller().LoadURL(url2, content::Referrer(), |
| 494 content::PAGE_TRANSITION_TYPED, |
| 489 std::string()); | 495 std::string()); |
| 490 // The first RVH in contents2 isn't live yet, so we shortcut the cross site | 496 // The first RVH in contents2 isn't live yet, so we shortcut the cross site |
| 491 // pending. | 497 // pending. |
| 492 TestRenderViewHost* rvh2 = static_cast<TestRenderViewHost*>( | 498 TestRenderViewHost* rvh2 = static_cast<TestRenderViewHost*>( |
| 493 contents2.render_view_host()); | 499 contents2.render_view_host()); |
| 494 EXPECT_FALSE(contents2.cross_navigation_pending()); | 500 EXPECT_FALSE(contents2.cross_navigation_pending()); |
| 495 ViewHostMsg_FrameNavigate_Params params2; | 501 ViewHostMsg_FrameNavigate_Params params2; |
| 496 InitNavigateParams(¶ms2, 2, url2, content::PAGE_TRANSITION_TYPED); | 502 InitNavigateParams(¶ms2, 2, url2, content::PAGE_TRANSITION_TYPED); |
| 497 contents2.TestDidNavigate(rvh2, params2); | 503 contents2.TestDidNavigate(rvh2, params2); |
| 498 SiteInstance* instance2 = contents2.GetSiteInstance(); | 504 SiteInstance* instance2 = contents2.GetSiteInstance(); |
| 499 EXPECT_NE(instance1, instance2); | 505 EXPECT_NE(instance1, instance2); |
| 500 EXPECT_FALSE(contents2.cross_navigation_pending()); | 506 EXPECT_FALSE(contents2.cross_navigation_pending()); |
| 501 | 507 |
| 502 // Simulate a link click in first tab to second site. Doesn't switch | 508 // Simulate a link click in first tab to second site. Doesn't switch |
| 503 // SiteInstances, because we don't intercept WebKit navigations. | 509 // SiteInstances, because we don't intercept WebKit navigations. |
| 504 ViewHostMsg_FrameNavigate_Params params3; | 510 ViewHostMsg_FrameNavigate_Params params3; |
| 505 InitNavigateParams(¶ms3, 2, url2, content::PAGE_TRANSITION_TYPED); | 511 InitNavigateParams(¶ms3, 2, url2, content::PAGE_TRANSITION_TYPED); |
| 506 contents()->TestDidNavigate(orig_rvh, params3); | 512 contents()->TestDidNavigate(orig_rvh, params3); |
| 507 SiteInstance* instance3 = contents()->GetSiteInstance(); | 513 SiteInstance* instance3 = contents()->GetSiteInstance(); |
| 508 EXPECT_EQ(instance1, instance3); | 514 EXPECT_EQ(instance1, instance3); |
| 509 EXPECT_FALSE(contents()->cross_navigation_pending()); | 515 EXPECT_FALSE(contents()->cross_navigation_pending()); |
| 510 | 516 |
| 511 // Navigate to the new site. Doesn't switch SiteInstancees, because we | 517 // Navigate to the new site. Doesn't switch SiteInstancees, because we |
| 512 // compare against the current URL, not the SiteInstance's site. | 518 // compare against the current URL, not the SiteInstance's site. |
| 513 const GURL url3("http://mail.yahoo.com"); | 519 const GURL url3("http://mail.yahoo.com"); |
| 514 controller().LoadURL( | 520 controller().LoadURL( |
| 515 url3, GURL(), content::PAGE_TRANSITION_TYPED, std::string()); | 521 url3, content::Referrer(), content::PAGE_TRANSITION_TYPED, std::string()); |
| 516 EXPECT_FALSE(contents()->cross_navigation_pending()); | 522 EXPECT_FALSE(contents()->cross_navigation_pending()); |
| 517 ViewHostMsg_FrameNavigate_Params params4; | 523 ViewHostMsg_FrameNavigate_Params params4; |
| 518 InitNavigateParams(¶ms4, 3, url3, content::PAGE_TRANSITION_TYPED); | 524 InitNavigateParams(¶ms4, 3, url3, content::PAGE_TRANSITION_TYPED); |
| 519 contents()->TestDidNavigate(orig_rvh, params4); | 525 contents()->TestDidNavigate(orig_rvh, params4); |
| 520 SiteInstance* instance4 = contents()->GetSiteInstance(); | 526 SiteInstance* instance4 = contents()->GetSiteInstance(); |
| 521 EXPECT_EQ(instance1, instance4); | 527 EXPECT_EQ(instance1, instance4); |
| 522 } | 528 } |
| 523 | 529 |
| 524 // Test that the onbeforeunload and onunload handlers run when navigating | 530 // Test that the onbeforeunload and onunload handlers run when navigating |
| 525 // across site boundaries. | 531 // across site boundaries. |
| 526 TEST_F(TabContentsTest, CrossSiteUnloadHandlers) { | 532 TEST_F(TabContentsTest, CrossSiteUnloadHandlers) { |
| 527 contents()->transition_cross_site = true; | 533 contents()->transition_cross_site = true; |
| 528 TestRenderViewHost* orig_rvh = rvh(); | 534 TestRenderViewHost* orig_rvh = rvh(); |
| 529 SiteInstance* instance1 = contents()->GetSiteInstance(); | 535 SiteInstance* instance1 = contents()->GetSiteInstance(); |
| 530 | 536 |
| 531 // Navigate to URL. First URL should use first RenderViewHost. | 537 // Navigate to URL. First URL should use first RenderViewHost. |
| 532 const GURL url("http://www.google.com"); | 538 const GURL url("http://www.google.com"); |
| 533 controller().LoadURL( | 539 controller().LoadURL( |
| 534 url, GURL(), content::PAGE_TRANSITION_TYPED, std::string()); | 540 url, content::Referrer(), content::PAGE_TRANSITION_TYPED, std::string()); |
| 535 ViewHostMsg_FrameNavigate_Params params1; | 541 ViewHostMsg_FrameNavigate_Params params1; |
| 536 InitNavigateParams(¶ms1, 1, url, content::PAGE_TRANSITION_TYPED); | 542 InitNavigateParams(¶ms1, 1, url, content::PAGE_TRANSITION_TYPED); |
| 537 contents()->TestDidNavigate(orig_rvh, params1); | 543 contents()->TestDidNavigate(orig_rvh, params1); |
| 538 EXPECT_FALSE(contents()->cross_navigation_pending()); | 544 EXPECT_FALSE(contents()->cross_navigation_pending()); |
| 539 EXPECT_EQ(orig_rvh, contents()->render_view_host()); | 545 EXPECT_EQ(orig_rvh, contents()->render_view_host()); |
| 540 | 546 |
| 541 // Navigate to new site, but simulate an onbeforeunload denial. | 547 // Navigate to new site, but simulate an onbeforeunload denial. |
| 542 const GURL url2("http://www.yahoo.com"); | 548 const GURL url2("http://www.yahoo.com"); |
| 543 controller().LoadURL( | 549 controller().LoadURL( |
| 544 url2, GURL(), content::PAGE_TRANSITION_TYPED, std::string()); | 550 url2, content::Referrer(), content::PAGE_TRANSITION_TYPED, std::string()); |
| 545 EXPECT_TRUE(orig_rvh->is_waiting_for_beforeunload_ack()); | 551 EXPECT_TRUE(orig_rvh->is_waiting_for_beforeunload_ack()); |
| 546 orig_rvh->TestOnMessageReceived(ViewHostMsg_ShouldClose_ACK(0, false)); | 552 orig_rvh->TestOnMessageReceived(ViewHostMsg_ShouldClose_ACK(0, false)); |
| 547 EXPECT_FALSE(orig_rvh->is_waiting_for_beforeunload_ack()); | 553 EXPECT_FALSE(orig_rvh->is_waiting_for_beforeunload_ack()); |
| 548 EXPECT_FALSE(contents()->cross_navigation_pending()); | 554 EXPECT_FALSE(contents()->cross_navigation_pending()); |
| 549 EXPECT_EQ(orig_rvh, contents()->render_view_host()); | 555 EXPECT_EQ(orig_rvh, contents()->render_view_host()); |
| 550 | 556 |
| 551 // Navigate again, but simulate an onbeforeunload approval. | 557 // Navigate again, but simulate an onbeforeunload approval. |
| 552 controller().LoadURL( | 558 controller().LoadURL( |
| 553 url2, GURL(), content::PAGE_TRANSITION_TYPED, std::string()); | 559 url2, content::Referrer(), content::PAGE_TRANSITION_TYPED, std::string()); |
| 554 EXPECT_TRUE(orig_rvh->is_waiting_for_beforeunload_ack()); | 560 EXPECT_TRUE(orig_rvh->is_waiting_for_beforeunload_ack()); |
| 555 orig_rvh->TestOnMessageReceived(ViewHostMsg_ShouldClose_ACK(0, true)); | 561 orig_rvh->TestOnMessageReceived(ViewHostMsg_ShouldClose_ACK(0, true)); |
| 556 EXPECT_FALSE(orig_rvh->is_waiting_for_beforeunload_ack()); | 562 EXPECT_FALSE(orig_rvh->is_waiting_for_beforeunload_ack()); |
| 557 EXPECT_TRUE(contents()->cross_navigation_pending()); | 563 EXPECT_TRUE(contents()->cross_navigation_pending()); |
| 558 TestRenderViewHost* pending_rvh = static_cast<TestRenderViewHost*>( | 564 TestRenderViewHost* pending_rvh = static_cast<TestRenderViewHost*>( |
| 559 contents()->pending_rvh()); | 565 contents()->pending_rvh()); |
| 560 | 566 |
| 561 // We won't hear DidNavigate until the onunload handler has finished running. | 567 // We won't hear DidNavigate until the onunload handler has finished running. |
| 562 // (No way to simulate that here, but it involves a call from RDH to | 568 // (No way to simulate that here, but it involves a call from RDH to |
| 563 // TabContents::OnCrossSiteResponse.) | 569 // TabContents::OnCrossSiteResponse.) |
| (...skipping 13 matching lines...) Expand all Loading... |
| 577 // navigate to a different URL and have it displayed, canceling the slow | 583 // navigate to a different URL and have it displayed, canceling the slow |
| 578 // navigation. | 584 // navigation. |
| 579 TEST_F(TabContentsTest, CrossSiteNavigationPreempted) { | 585 TEST_F(TabContentsTest, CrossSiteNavigationPreempted) { |
| 580 contents()->transition_cross_site = true; | 586 contents()->transition_cross_site = true; |
| 581 TestRenderViewHost* orig_rvh = rvh(); | 587 TestRenderViewHost* orig_rvh = rvh(); |
| 582 SiteInstance* instance1 = contents()->GetSiteInstance(); | 588 SiteInstance* instance1 = contents()->GetSiteInstance(); |
| 583 | 589 |
| 584 // Navigate to URL. First URL should use first RenderViewHost. | 590 // Navigate to URL. First URL should use first RenderViewHost. |
| 585 const GURL url("http://www.google.com"); | 591 const GURL url("http://www.google.com"); |
| 586 controller().LoadURL( | 592 controller().LoadURL( |
| 587 url, GURL(), content::PAGE_TRANSITION_TYPED, std::string()); | 593 url, content::Referrer(), content::PAGE_TRANSITION_TYPED, std::string()); |
| 588 ViewHostMsg_FrameNavigate_Params params1; | 594 ViewHostMsg_FrameNavigate_Params params1; |
| 589 InitNavigateParams(¶ms1, 1, url, content::PAGE_TRANSITION_TYPED); | 595 InitNavigateParams(¶ms1, 1, url, content::PAGE_TRANSITION_TYPED); |
| 590 contents()->TestDidNavigate(orig_rvh, params1); | 596 contents()->TestDidNavigate(orig_rvh, params1); |
| 591 EXPECT_FALSE(contents()->cross_navigation_pending()); | 597 EXPECT_FALSE(contents()->cross_navigation_pending()); |
| 592 EXPECT_EQ(orig_rvh, contents()->render_view_host()); | 598 EXPECT_EQ(orig_rvh, contents()->render_view_host()); |
| 593 | 599 |
| 594 // Navigate to new site, simulating an onbeforeunload approval. | 600 // Navigate to new site, simulating an onbeforeunload approval. |
| 595 const GURL url2("http://www.yahoo.com"); | 601 const GURL url2("http://www.yahoo.com"); |
| 596 controller().LoadURL( | 602 controller().LoadURL( |
| 597 url2, GURL(), content::PAGE_TRANSITION_TYPED, std::string()); | 603 url2, content::Referrer(), content::PAGE_TRANSITION_TYPED, std::string()); |
| 598 EXPECT_TRUE(orig_rvh->is_waiting_for_beforeunload_ack()); | 604 EXPECT_TRUE(orig_rvh->is_waiting_for_beforeunload_ack()); |
| 599 orig_rvh->TestOnMessageReceived(ViewHostMsg_ShouldClose_ACK(0, true)); | 605 orig_rvh->TestOnMessageReceived(ViewHostMsg_ShouldClose_ACK(0, true)); |
| 600 EXPECT_TRUE(contents()->cross_navigation_pending()); | 606 EXPECT_TRUE(contents()->cross_navigation_pending()); |
| 601 | 607 |
| 602 // Suppose the original renderer navigates before the new one is ready. | 608 // Suppose the original renderer navigates before the new one is ready. |
| 603 orig_rvh->SendNavigate(2, GURL("http://www.google.com/foo")); | 609 orig_rvh->SendNavigate(2, GURL("http://www.google.com/foo")); |
| 604 | 610 |
| 605 // Verify that the pending navigation is cancelled. | 611 // Verify that the pending navigation is cancelled. |
| 606 EXPECT_FALSE(orig_rvh->is_waiting_for_beforeunload_ack()); | 612 EXPECT_FALSE(orig_rvh->is_waiting_for_beforeunload_ack()); |
| 607 SiteInstance* instance2 = contents()->GetSiteInstance(); | 613 SiteInstance* instance2 = contents()->GetSiteInstance(); |
| 608 EXPECT_FALSE(contents()->cross_navigation_pending()); | 614 EXPECT_FALSE(contents()->cross_navigation_pending()); |
| 609 EXPECT_EQ(orig_rvh, rvh()); | 615 EXPECT_EQ(orig_rvh, rvh()); |
| 610 EXPECT_EQ(instance1, instance2); | 616 EXPECT_EQ(instance1, instance2); |
| 611 EXPECT_TRUE(contents()->pending_rvh() == NULL); | 617 EXPECT_TRUE(contents()->pending_rvh() == NULL); |
| 612 } | 618 } |
| 613 | 619 |
| 614 TEST_F(TabContentsTest, CrossSiteNavigationBackPreempted) { | 620 TEST_F(TabContentsTest, CrossSiteNavigationBackPreempted) { |
| 615 contents()->transition_cross_site = true; | 621 contents()->transition_cross_site = true; |
| 616 | 622 |
| 617 // Start with NTP, which gets a new RVH with WebUI bindings. | 623 // Start with NTP, which gets a new RVH with WebUI bindings. |
| 618 const GURL url1("chrome://newtab"); | 624 const GURL url1("chrome://newtab"); |
| 619 controller().LoadURL( | 625 controller().LoadURL( |
| 620 url1, GURL(), content::PAGE_TRANSITION_TYPED, std::string()); | 626 url1, content::Referrer(), content::PAGE_TRANSITION_TYPED, std::string()); |
| 621 TestRenderViewHost* ntp_rvh = rvh(); | 627 TestRenderViewHost* ntp_rvh = rvh(); |
| 622 ViewHostMsg_FrameNavigate_Params params1; | 628 ViewHostMsg_FrameNavigate_Params params1; |
| 623 InitNavigateParams(¶ms1, 1, url1, content::PAGE_TRANSITION_TYPED); | 629 InitNavigateParams(¶ms1, 1, url1, content::PAGE_TRANSITION_TYPED); |
| 624 contents()->TestDidNavigate(ntp_rvh, params1); | 630 contents()->TestDidNavigate(ntp_rvh, params1); |
| 625 NavigationEntry* entry1 = controller().GetLastCommittedEntry(); | 631 NavigationEntry* entry1 = controller().GetLastCommittedEntry(); |
| 626 SiteInstance* instance1 = contents()->GetSiteInstance(); | 632 SiteInstance* instance1 = contents()->GetSiteInstance(); |
| 627 | 633 |
| 628 EXPECT_FALSE(contents()->cross_navigation_pending()); | 634 EXPECT_FALSE(contents()->cross_navigation_pending()); |
| 629 EXPECT_EQ(ntp_rvh, contents()->render_view_host()); | 635 EXPECT_EQ(ntp_rvh, contents()->render_view_host()); |
| 630 EXPECT_EQ(url1, entry1->url()); | 636 EXPECT_EQ(url1, entry1->url()); |
| 631 EXPECT_EQ(instance1, entry1->site_instance()); | 637 EXPECT_EQ(instance1, entry1->site_instance()); |
| 632 EXPECT_TRUE(ntp_rvh->enabled_bindings() & content::BINDINGS_POLICY_WEB_UI); | 638 EXPECT_TRUE(ntp_rvh->enabled_bindings() & content::BINDINGS_POLICY_WEB_UI); |
| 633 | 639 |
| 634 // Navigate to new site. | 640 // Navigate to new site. |
| 635 const GURL url2("http://www.google.com"); | 641 const GURL url2("http://www.google.com"); |
| 636 controller().LoadURL( | 642 controller().LoadURL( |
| 637 url2, GURL(), content::PAGE_TRANSITION_TYPED, std::string()); | 643 url2, content::Referrer(), content::PAGE_TRANSITION_TYPED, std::string()); |
| 638 EXPECT_TRUE(contents()->cross_navigation_pending()); | 644 EXPECT_TRUE(contents()->cross_navigation_pending()); |
| 639 TestRenderViewHost* google_rvh = contents()->pending_rvh(); | 645 TestRenderViewHost* google_rvh = contents()->pending_rvh(); |
| 640 | 646 |
| 641 // Simulate beforeunload approval. | 647 // Simulate beforeunload approval. |
| 642 EXPECT_TRUE(ntp_rvh->is_waiting_for_beforeunload_ack()); | 648 EXPECT_TRUE(ntp_rvh->is_waiting_for_beforeunload_ack()); |
| 643 ntp_rvh->TestOnMessageReceived(ViewHostMsg_ShouldClose_ACK(0, true)); | 649 ntp_rvh->TestOnMessageReceived(ViewHostMsg_ShouldClose_ACK(0, true)); |
| 644 | 650 |
| 645 // DidNavigate from the pending page. | 651 // DidNavigate from the pending page. |
| 646 ViewHostMsg_FrameNavigate_Params params2; | 652 ViewHostMsg_FrameNavigate_Params params2; |
| 647 InitNavigateParams(¶ms2, 1, url2, content::PAGE_TRANSITION_TYPED); | 653 InitNavigateParams(¶ms2, 1, url2, content::PAGE_TRANSITION_TYPED); |
| 648 contents()->TestDidNavigate(google_rvh, params2); | 654 contents()->TestDidNavigate(google_rvh, params2); |
| 649 NavigationEntry* entry2 = controller().GetLastCommittedEntry(); | 655 NavigationEntry* entry2 = controller().GetLastCommittedEntry(); |
| 650 SiteInstance* instance2 = contents()->GetSiteInstance(); | 656 SiteInstance* instance2 = contents()->GetSiteInstance(); |
| 651 | 657 |
| 652 EXPECT_FALSE(contents()->cross_navigation_pending()); | 658 EXPECT_FALSE(contents()->cross_navigation_pending()); |
| 653 EXPECT_EQ(google_rvh, contents()->render_view_host()); | 659 EXPECT_EQ(google_rvh, contents()->render_view_host()); |
| 654 EXPECT_NE(instance1, instance2); | 660 EXPECT_NE(instance1, instance2); |
| 655 EXPECT_FALSE(contents()->pending_rvh()); | 661 EXPECT_FALSE(contents()->pending_rvh()); |
| 656 EXPECT_EQ(url2, entry2->url()); | 662 EXPECT_EQ(url2, entry2->url()); |
| 657 EXPECT_EQ(instance2, entry2->site_instance()); | 663 EXPECT_EQ(instance2, entry2->site_instance()); |
| 658 EXPECT_FALSE(google_rvh->enabled_bindings() & | 664 EXPECT_FALSE(google_rvh->enabled_bindings() & |
| 659 content::BINDINGS_POLICY_WEB_UI); | 665 content::BINDINGS_POLICY_WEB_UI); |
| 660 | 666 |
| 661 // Navigate to third page on same site. | 667 // Navigate to third page on same site. |
| 662 const GURL url3("http://news.google.com"); | 668 const GURL url3("http://news.google.com"); |
| 663 controller().LoadURL( | 669 controller().LoadURL( |
| 664 url3, GURL(), content::PAGE_TRANSITION_TYPED, std::string()); | 670 url3, content::Referrer(), content::PAGE_TRANSITION_TYPED, std::string()); |
| 665 EXPECT_FALSE(contents()->cross_navigation_pending()); | 671 EXPECT_FALSE(contents()->cross_navigation_pending()); |
| 666 ViewHostMsg_FrameNavigate_Params params3; | 672 ViewHostMsg_FrameNavigate_Params params3; |
| 667 InitNavigateParams(¶ms3, 2, url3, content::PAGE_TRANSITION_TYPED); | 673 InitNavigateParams(¶ms3, 2, url3, content::PAGE_TRANSITION_TYPED); |
| 668 contents()->TestDidNavigate(google_rvh, params3); | 674 contents()->TestDidNavigate(google_rvh, params3); |
| 669 NavigationEntry* entry3 = controller().GetLastCommittedEntry(); | 675 NavigationEntry* entry3 = controller().GetLastCommittedEntry(); |
| 670 SiteInstance* instance3 = contents()->GetSiteInstance(); | 676 SiteInstance* instance3 = contents()->GetSiteInstance(); |
| 671 | 677 |
| 672 EXPECT_FALSE(contents()->cross_navigation_pending()); | 678 EXPECT_FALSE(contents()->cross_navigation_pending()); |
| 673 EXPECT_EQ(google_rvh, contents()->render_view_host()); | 679 EXPECT_EQ(google_rvh, contents()->render_view_host()); |
| 674 EXPECT_EQ(instance2, instance3); | 680 EXPECT_EQ(instance2, instance3); |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 709 | 715 |
| 710 // Test that during a slow cross-site navigation, a sub-frame navigation in the | 716 // Test that during a slow cross-site navigation, a sub-frame navigation in the |
| 711 // original renderer will not cancel the slow navigation (bug 42029). | 717 // original renderer will not cancel the slow navigation (bug 42029). |
| 712 TEST_F(TabContentsTest, CrossSiteNavigationNotPreemptedByFrame) { | 718 TEST_F(TabContentsTest, CrossSiteNavigationNotPreemptedByFrame) { |
| 713 contents()->transition_cross_site = true; | 719 contents()->transition_cross_site = true; |
| 714 TestRenderViewHost* orig_rvh = rvh(); | 720 TestRenderViewHost* orig_rvh = rvh(); |
| 715 | 721 |
| 716 // Navigate to URL. First URL should use first RenderViewHost. | 722 // Navigate to URL. First URL should use first RenderViewHost. |
| 717 const GURL url("http://www.google.com"); | 723 const GURL url("http://www.google.com"); |
| 718 controller().LoadURL( | 724 controller().LoadURL( |
| 719 url, GURL(), content::PAGE_TRANSITION_TYPED, std::string()); | 725 url, content::Referrer(), content::PAGE_TRANSITION_TYPED, std::string()); |
| 720 ViewHostMsg_FrameNavigate_Params params1; | 726 ViewHostMsg_FrameNavigate_Params params1; |
| 721 InitNavigateParams(¶ms1, 1, url, content::PAGE_TRANSITION_TYPED); | 727 InitNavigateParams(¶ms1, 1, url, content::PAGE_TRANSITION_TYPED); |
| 722 contents()->TestDidNavigate(orig_rvh, params1); | 728 contents()->TestDidNavigate(orig_rvh, params1); |
| 723 EXPECT_FALSE(contents()->cross_navigation_pending()); | 729 EXPECT_FALSE(contents()->cross_navigation_pending()); |
| 724 EXPECT_EQ(orig_rvh, contents()->render_view_host()); | 730 EXPECT_EQ(orig_rvh, contents()->render_view_host()); |
| 725 | 731 |
| 726 // Start navigating to new site. | 732 // Start navigating to new site. |
| 727 const GURL url2("http://www.yahoo.com"); | 733 const GURL url2("http://www.yahoo.com"); |
| 728 controller().LoadURL( | 734 controller().LoadURL( |
| 729 url2, GURL(), content::PAGE_TRANSITION_TYPED, std::string()); | 735 url2, content::Referrer(), content::PAGE_TRANSITION_TYPED, std::string()); |
| 730 | 736 |
| 731 // Simulate a sub-frame navigation arriving and ensure the RVH is still | 737 // Simulate a sub-frame navigation arriving and ensure the RVH is still |
| 732 // waiting for a before unload response. | 738 // waiting for a before unload response. |
| 733 orig_rvh->SendNavigateWithTransition(1, GURL("http://google.com/frame"), | 739 orig_rvh->SendNavigateWithTransition(1, GURL("http://google.com/frame"), |
| 734 content::PAGE_TRANSITION_AUTO_SUBFRAME); | 740 content::PAGE_TRANSITION_AUTO_SUBFRAME); |
| 735 EXPECT_TRUE(orig_rvh->is_waiting_for_beforeunload_ack()); | 741 EXPECT_TRUE(orig_rvh->is_waiting_for_beforeunload_ack()); |
| 736 | 742 |
| 737 // Now simulate the onbeforeunload approval and verify the navigation is | 743 // Now simulate the onbeforeunload approval and verify the navigation is |
| 738 // not canceled. | 744 // not canceled. |
| 739 orig_rvh->TestOnMessageReceived(ViewHostMsg_ShouldClose_ACK(0, true)); | 745 orig_rvh->TestOnMessageReceived(ViewHostMsg_ShouldClose_ACK(0, true)); |
| 740 EXPECT_FALSE(orig_rvh->is_waiting_for_beforeunload_ack()); | 746 EXPECT_FALSE(orig_rvh->is_waiting_for_beforeunload_ack()); |
| 741 EXPECT_TRUE(contents()->cross_navigation_pending()); | 747 EXPECT_TRUE(contents()->cross_navigation_pending()); |
| 742 } | 748 } |
| 743 | 749 |
| 744 // Test that a cross-site navigation is not preempted if the previous | 750 // Test that a cross-site navigation is not preempted if the previous |
| 745 // renderer sends a FrameNavigate message just before being told to stop. | 751 // renderer sends a FrameNavigate message just before being told to stop. |
| 746 // We should only preempt the cross-site navigation if the previous renderer | 752 // We should only preempt the cross-site navigation if the previous renderer |
| 747 // has started a new navigation. See http://crbug.com/79176. | 753 // has started a new navigation. See http://crbug.com/79176. |
| 748 TEST_F(TabContentsTest, CrossSiteNotPreemptedDuringBeforeUnload) { | 754 TEST_F(TabContentsTest, CrossSiteNotPreemptedDuringBeforeUnload) { |
| 749 contents()->transition_cross_site = true; | 755 contents()->transition_cross_site = true; |
| 750 | 756 |
| 751 // Navigate to NTP URL. | 757 // Navigate to NTP URL. |
| 752 const GURL url("chrome://newtab"); | 758 const GURL url("chrome://newtab"); |
| 753 controller().LoadURL( | 759 controller().LoadURL( |
| 754 url, GURL(), content::PAGE_TRANSITION_TYPED, std::string()); | 760 url, content::Referrer(), content::PAGE_TRANSITION_TYPED, std::string()); |
| 755 TestRenderViewHost* orig_rvh = rvh(); | 761 TestRenderViewHost* orig_rvh = rvh(); |
| 756 EXPECT_FALSE(contents()->cross_navigation_pending()); | 762 EXPECT_FALSE(contents()->cross_navigation_pending()); |
| 757 | 763 |
| 758 // Navigate to new site, with the beforeunload request in flight. | 764 // Navigate to new site, with the beforeunload request in flight. |
| 759 const GURL url2("http://www.yahoo.com"); | 765 const GURL url2("http://www.yahoo.com"); |
| 760 controller().LoadURL( | 766 controller().LoadURL( |
| 761 url2, GURL(), content::PAGE_TRANSITION_TYPED, std::string()); | 767 url2, content::Referrer(), content::PAGE_TRANSITION_TYPED, std::string()); |
| 762 TestRenderViewHost* pending_rvh = contents()->pending_rvh(); | 768 TestRenderViewHost* pending_rvh = contents()->pending_rvh(); |
| 763 EXPECT_TRUE(contents()->cross_navigation_pending()); | 769 EXPECT_TRUE(contents()->cross_navigation_pending()); |
| 764 EXPECT_TRUE(orig_rvh->is_waiting_for_beforeunload_ack()); | 770 EXPECT_TRUE(orig_rvh->is_waiting_for_beforeunload_ack()); |
| 765 | 771 |
| 766 // Suppose the first navigation tries to commit now, with a | 772 // Suppose the first navigation tries to commit now, with a |
| 767 // ViewMsg_Stop in flight. This should not cancel the pending navigation, | 773 // ViewMsg_Stop in flight. This should not cancel the pending navigation, |
| 768 // but it should act as if the beforeunload ack arrived. | 774 // but it should act as if the beforeunload ack arrived. |
| 769 orig_rvh->SendNavigate(1, GURL("chrome://newtab")); | 775 orig_rvh->SendNavigate(1, GURL("chrome://newtab")); |
| 770 EXPECT_TRUE(contents()->cross_navigation_pending()); | 776 EXPECT_TRUE(contents()->cross_navigation_pending()); |
| 771 EXPECT_EQ(orig_rvh, contents()->render_view_host()); | 777 EXPECT_EQ(orig_rvh, contents()->render_view_host()); |
| (...skipping 12 matching lines...) Expand all Loading... |
| 784 // is almost ready to be displayed, and the original renderer is only given a | 790 // is almost ready to be displayed, and the original renderer is only given a |
| 785 // short chance to run an unload handler. Prevents regression of bug 23942. | 791 // short chance to run an unload handler. Prevents regression of bug 23942. |
| 786 TEST_F(TabContentsTest, CrossSiteCantPreemptAfterUnload) { | 792 TEST_F(TabContentsTest, CrossSiteCantPreemptAfterUnload) { |
| 787 contents()->transition_cross_site = true; | 793 contents()->transition_cross_site = true; |
| 788 TestRenderViewHost* orig_rvh = rvh(); | 794 TestRenderViewHost* orig_rvh = rvh(); |
| 789 SiteInstance* instance1 = contents()->GetSiteInstance(); | 795 SiteInstance* instance1 = contents()->GetSiteInstance(); |
| 790 | 796 |
| 791 // Navigate to URL. First URL should use first RenderViewHost. | 797 // Navigate to URL. First URL should use first RenderViewHost. |
| 792 const GURL url("http://www.google.com"); | 798 const GURL url("http://www.google.com"); |
| 793 controller().LoadURL( | 799 controller().LoadURL( |
| 794 url, GURL(), content::PAGE_TRANSITION_TYPED, std::string()); | 800 url, content::Referrer(), content::PAGE_TRANSITION_TYPED, std::string()); |
| 795 ViewHostMsg_FrameNavigate_Params params1; | 801 ViewHostMsg_FrameNavigate_Params params1; |
| 796 InitNavigateParams(¶ms1, 1, url, content::PAGE_TRANSITION_TYPED); | 802 InitNavigateParams(¶ms1, 1, url, content::PAGE_TRANSITION_TYPED); |
| 797 contents()->TestDidNavigate(orig_rvh, params1); | 803 contents()->TestDidNavigate(orig_rvh, params1); |
| 798 EXPECT_FALSE(contents()->cross_navigation_pending()); | 804 EXPECT_FALSE(contents()->cross_navigation_pending()); |
| 799 EXPECT_EQ(orig_rvh, contents()->render_view_host()); | 805 EXPECT_EQ(orig_rvh, contents()->render_view_host()); |
| 800 | 806 |
| 801 // Navigate to new site, simulating an onbeforeunload approval. | 807 // Navigate to new site, simulating an onbeforeunload approval. |
| 802 const GURL url2("http://www.yahoo.com"); | 808 const GURL url2("http://www.yahoo.com"); |
| 803 controller().LoadURL( | 809 controller().LoadURL( |
| 804 url2, GURL(), content::PAGE_TRANSITION_TYPED, std::string()); | 810 url2, content::Referrer(), content::PAGE_TRANSITION_TYPED, std::string()); |
| 805 orig_rvh->TestOnMessageReceived(ViewHostMsg_ShouldClose_ACK(0, true)); | 811 orig_rvh->TestOnMessageReceived(ViewHostMsg_ShouldClose_ACK(0, true)); |
| 806 EXPECT_TRUE(contents()->cross_navigation_pending()); | 812 EXPECT_TRUE(contents()->cross_navigation_pending()); |
| 807 TestRenderViewHost* pending_rvh = static_cast<TestRenderViewHost*>( | 813 TestRenderViewHost* pending_rvh = static_cast<TestRenderViewHost*>( |
| 808 contents()->pending_rvh()); | 814 contents()->pending_rvh()); |
| 809 | 815 |
| 810 // Simulate the pending renderer's response, which leads to an unload request | 816 // Simulate the pending renderer's response, which leads to an unload request |
| 811 // being sent to orig_rvh. | 817 // being sent to orig_rvh. |
| 812 contents()->render_manager_for_testing()->OnCrossSiteResponse(0, 0); | 818 contents()->render_manager_for_testing()->OnCrossSiteResponse(0, 0); |
| 813 | 819 |
| 814 // Suppose the original renderer navigates now, while the unload request is in | 820 // Suppose the original renderer navigates now, while the unload request is in |
| (...skipping 23 matching lines...) Expand all Loading... |
| 838 // Test that a cross-site navigation that doesn't commit after the unload | 844 // Test that a cross-site navigation that doesn't commit after the unload |
| 839 // handler doesn't leave the tab in a stuck state. http://crbug.com/88562. | 845 // handler doesn't leave the tab in a stuck state. http://crbug.com/88562. |
| 840 TEST_F(TabContentsTest, CrossSiteNavigationCanceled) { | 846 TEST_F(TabContentsTest, CrossSiteNavigationCanceled) { |
| 841 contents()->transition_cross_site = true; | 847 contents()->transition_cross_site = true; |
| 842 TestRenderViewHost* orig_rvh = rvh(); | 848 TestRenderViewHost* orig_rvh = rvh(); |
| 843 SiteInstance* instance1 = contents()->GetSiteInstance(); | 849 SiteInstance* instance1 = contents()->GetSiteInstance(); |
| 844 | 850 |
| 845 // Navigate to URL. First URL should use first RenderViewHost. | 851 // Navigate to URL. First URL should use first RenderViewHost. |
| 846 const GURL url("http://www.google.com"); | 852 const GURL url("http://www.google.com"); |
| 847 controller().LoadURL( | 853 controller().LoadURL( |
| 848 url, GURL(), content::PAGE_TRANSITION_TYPED, std::string()); | 854 url, content::Referrer(), content::PAGE_TRANSITION_TYPED, std::string()); |
| 849 ViewHostMsg_FrameNavigate_Params params1; | 855 ViewHostMsg_FrameNavigate_Params params1; |
| 850 InitNavigateParams(¶ms1, 1, url, content::PAGE_TRANSITION_TYPED); | 856 InitNavigateParams(¶ms1, 1, url, content::PAGE_TRANSITION_TYPED); |
| 851 contents()->TestDidNavigate(orig_rvh, params1); | 857 contents()->TestDidNavigate(orig_rvh, params1); |
| 852 EXPECT_FALSE(contents()->cross_navigation_pending()); | 858 EXPECT_FALSE(contents()->cross_navigation_pending()); |
| 853 EXPECT_EQ(orig_rvh, contents()->render_view_host()); | 859 EXPECT_EQ(orig_rvh, contents()->render_view_host()); |
| 854 | 860 |
| 855 // Navigate to new site, simulating an onbeforeunload approval. | 861 // Navigate to new site, simulating an onbeforeunload approval. |
| 856 const GURL url2("http://www.yahoo.com"); | 862 const GURL url2("http://www.yahoo.com"); |
| 857 controller().LoadURL( | 863 controller().LoadURL( |
| 858 url2, GURL(), content::PAGE_TRANSITION_TYPED, std::string()); | 864 url2, content::Referrer(), content::PAGE_TRANSITION_TYPED, std::string()); |
| 859 EXPECT_TRUE(orig_rvh->is_waiting_for_beforeunload_ack()); | 865 EXPECT_TRUE(orig_rvh->is_waiting_for_beforeunload_ack()); |
| 860 orig_rvh->TestOnMessageReceived(ViewHostMsg_ShouldClose_ACK(0, true)); | 866 orig_rvh->TestOnMessageReceived(ViewHostMsg_ShouldClose_ACK(0, true)); |
| 861 EXPECT_TRUE(contents()->cross_navigation_pending()); | 867 EXPECT_TRUE(contents()->cross_navigation_pending()); |
| 862 | 868 |
| 863 // Simulate swap out message when the response arrives. | 869 // Simulate swap out message when the response arrives. |
| 864 orig_rvh->set_is_swapped_out(true); | 870 orig_rvh->set_is_swapped_out(true); |
| 865 | 871 |
| 866 // Suppose the navigation doesn't get a chance to commit, and the user | 872 // Suppose the navigation doesn't get a chance to commit, and the user |
| 867 // navigates in the current RVH's SiteInstance. | 873 // navigates in the current RVH's SiteInstance. |
| 868 controller().LoadURL( | 874 controller().LoadURL( |
| 869 url, GURL(), content::PAGE_TRANSITION_TYPED, std::string()); | 875 url, content::Referrer(), content::PAGE_TRANSITION_TYPED, std::string()); |
| 870 | 876 |
| 871 // Verify that the pending navigation is cancelled and the renderer is no | 877 // Verify that the pending navigation is cancelled and the renderer is no |
| 872 // longer swapped out. | 878 // longer swapped out. |
| 873 EXPECT_FALSE(orig_rvh->is_waiting_for_beforeunload_ack()); | 879 EXPECT_FALSE(orig_rvh->is_waiting_for_beforeunload_ack()); |
| 874 SiteInstance* instance2 = contents()->GetSiteInstance(); | 880 SiteInstance* instance2 = contents()->GetSiteInstance(); |
| 875 EXPECT_FALSE(contents()->cross_navigation_pending()); | 881 EXPECT_FALSE(contents()->cross_navigation_pending()); |
| 876 EXPECT_EQ(orig_rvh, rvh()); | 882 EXPECT_EQ(orig_rvh, rvh()); |
| 877 EXPECT_FALSE(orig_rvh->is_swapped_out()); | 883 EXPECT_FALSE(orig_rvh->is_swapped_out()); |
| 878 EXPECT_EQ(instance1, instance2); | 884 EXPECT_EQ(instance1, instance2); |
| 879 EXPECT_TRUE(contents()->pending_rvh() == NULL); | 885 EXPECT_TRUE(contents()->pending_rvh() == NULL); |
| 880 } | 886 } |
| 881 | 887 |
| 882 // Test that NavigationEntries have the correct content state after going | 888 // Test that NavigationEntries have the correct content state after going |
| 883 // forward and back. Prevents regression for bug 1116137. | 889 // forward and back. Prevents regression for bug 1116137. |
| 884 TEST_F(TabContentsTest, NavigationEntryContentState) { | 890 TEST_F(TabContentsTest, NavigationEntryContentState) { |
| 885 TestRenderViewHost* orig_rvh = rvh(); | 891 TestRenderViewHost* orig_rvh = rvh(); |
| 886 | 892 |
| 887 // Navigate to URL. There should be no committed entry yet. | 893 // Navigate to URL. There should be no committed entry yet. |
| 888 const GURL url("http://www.google.com"); | 894 const GURL url("http://www.google.com"); |
| 889 controller().LoadURL( | 895 controller().LoadURL( |
| 890 url, GURL(), content::PAGE_TRANSITION_TYPED, std::string()); | 896 url, content::Referrer(), content::PAGE_TRANSITION_TYPED, std::string()); |
| 891 NavigationEntry* entry = controller().GetLastCommittedEntry(); | 897 NavigationEntry* entry = controller().GetLastCommittedEntry(); |
| 892 EXPECT_TRUE(entry == NULL); | 898 EXPECT_TRUE(entry == NULL); |
| 893 | 899 |
| 894 // Committed entry should have content state after DidNavigate. | 900 // Committed entry should have content state after DidNavigate. |
| 895 ViewHostMsg_FrameNavigate_Params params1; | 901 ViewHostMsg_FrameNavigate_Params params1; |
| 896 InitNavigateParams(¶ms1, 1, url, content::PAGE_TRANSITION_TYPED); | 902 InitNavigateParams(¶ms1, 1, url, content::PAGE_TRANSITION_TYPED); |
| 897 contents()->TestDidNavigate(orig_rvh, params1); | 903 contents()->TestDidNavigate(orig_rvh, params1); |
| 898 entry = controller().GetLastCommittedEntry(); | 904 entry = controller().GetLastCommittedEntry(); |
| 899 EXPECT_FALSE(entry->content_state().empty()); | 905 EXPECT_FALSE(entry->content_state().empty()); |
| 900 | 906 |
| 901 // Navigate to same site. | 907 // Navigate to same site. |
| 902 const GURL url2("http://images.google.com"); | 908 const GURL url2("http://images.google.com"); |
| 903 controller().LoadURL( | 909 controller().LoadURL( |
| 904 url2, GURL(), content::PAGE_TRANSITION_TYPED, std::string()); | 910 url2, content::Referrer(), content::PAGE_TRANSITION_TYPED, std::string()); |
| 905 entry = controller().GetLastCommittedEntry(); | 911 entry = controller().GetLastCommittedEntry(); |
| 906 EXPECT_FALSE(entry->content_state().empty()); | 912 EXPECT_FALSE(entry->content_state().empty()); |
| 907 | 913 |
| 908 // Committed entry should have content state after DidNavigate. | 914 // Committed entry should have content state after DidNavigate. |
| 909 ViewHostMsg_FrameNavigate_Params params2; | 915 ViewHostMsg_FrameNavigate_Params params2; |
| 910 InitNavigateParams(¶ms2, 2, url2, content::PAGE_TRANSITION_TYPED); | 916 InitNavigateParams(¶ms2, 2, url2, content::PAGE_TRANSITION_TYPED); |
| 911 contents()->TestDidNavigate(orig_rvh, params2); | 917 contents()->TestDidNavigate(orig_rvh, params2); |
| 912 entry = controller().GetLastCommittedEntry(); | 918 entry = controller().GetLastCommittedEntry(); |
| 913 EXPECT_FALSE(entry->content_state().empty()); | 919 EXPECT_FALSE(entry->content_state().empty()); |
| 914 | 920 |
| (...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 968 // as when a URL is typed in the location bar) that shows an interstitial and | 974 // as when a URL is typed in the location bar) that shows an interstitial and |
| 969 // creates a new navigation entry, then hiding it without proceeding. | 975 // creates a new navigation entry, then hiding it without proceeding. |
| 970 TEST_F(TabContentsTest, | 976 TEST_F(TabContentsTest, |
| 971 ShowInterstitialFromBrowserWithNewNavigationDontProceed) { | 977 ShowInterstitialFromBrowserWithNewNavigationDontProceed) { |
| 972 // Navigate to a page. | 978 // Navigate to a page. |
| 973 GURL url1("http://www.google.com"); | 979 GURL url1("http://www.google.com"); |
| 974 rvh()->SendNavigate(1, url1); | 980 rvh()->SendNavigate(1, url1); |
| 975 EXPECT_EQ(1, controller().entry_count()); | 981 EXPECT_EQ(1, controller().entry_count()); |
| 976 | 982 |
| 977 // Initiate a browser navigation that will trigger the interstitial | 983 // Initiate a browser navigation that will trigger the interstitial |
| 978 controller().LoadURL(GURL("http://www.evil.com"), GURL(), | 984 controller().LoadURL(GURL("http://www.evil.com"), content::Referrer(), |
| 979 content::PAGE_TRANSITION_TYPED, std::string()); | 985 content::PAGE_TRANSITION_TYPED, std::string()); |
| 980 | 986 |
| 981 // Show an interstitial. | 987 // Show an interstitial. |
| 982 TestInterstitialPage::InterstitialState state = | 988 TestInterstitialPage::InterstitialState state = |
| 983 TestInterstitialPage::UNDECIDED; | 989 TestInterstitialPage::UNDECIDED; |
| 984 bool deleted = false; | 990 bool deleted = false; |
| 985 GURL url2("http://interstitial"); | 991 GURL url2("http://interstitial"); |
| 986 TestInterstitialPage* interstitial = | 992 TestInterstitialPage* interstitial = |
| 987 new TestInterstitialPage(contents(), true, url2, &state, &deleted); | 993 new TestInterstitialPage(contents(), true, url2, &state, &deleted); |
| 988 TestInterstitialPageStateGuard state_guard(interstitial); | 994 TestInterstitialPageStateGuard state_guard(interstitial); |
| (...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1105 // as when a URL is typed in the location bar) that shows an interstitial and | 1111 // as when a URL is typed in the location bar) that shows an interstitial and |
| 1106 // creates a new navigation entry, then proceeding. | 1112 // creates a new navigation entry, then proceeding. |
| 1107 TEST_F(TabContentsTest, | 1113 TEST_F(TabContentsTest, |
| 1108 ShowInterstitialFromBrowserNewNavigationProceed) { | 1114 ShowInterstitialFromBrowserNewNavigationProceed) { |
| 1109 // Navigate to a page. | 1115 // Navigate to a page. |
| 1110 GURL url1("http://www.google.com"); | 1116 GURL url1("http://www.google.com"); |
| 1111 rvh()->SendNavigate(1, url1); | 1117 rvh()->SendNavigate(1, url1); |
| 1112 EXPECT_EQ(1, controller().entry_count()); | 1118 EXPECT_EQ(1, controller().entry_count()); |
| 1113 | 1119 |
| 1114 // Initiate a browser navigation that will trigger the interstitial | 1120 // Initiate a browser navigation that will trigger the interstitial |
| 1115 controller().LoadURL(GURL("http://www.evil.com"), GURL(), | 1121 controller().LoadURL(GURL("http://www.evil.com"), content::Referrer(), |
| 1116 content::PAGE_TRANSITION_TYPED, std::string()); | 1122 content::PAGE_TRANSITION_TYPED, std::string()); |
| 1117 | 1123 |
| 1118 // Show an interstitial. | 1124 // Show an interstitial. |
| 1119 TestInterstitialPage::InterstitialState state = | 1125 TestInterstitialPage::InterstitialState state = |
| 1120 TestInterstitialPage::UNDECIDED; | 1126 TestInterstitialPage::UNDECIDED; |
| 1121 bool deleted = false; | 1127 bool deleted = false; |
| 1122 GURL url2("http://interstitial"); | 1128 GURL url2("http://interstitial"); |
| 1123 TestInterstitialPage* interstitial = | 1129 TestInterstitialPage* interstitial = |
| 1124 new TestInterstitialPage(contents(), true, url2, &state, &deleted); | 1130 new TestInterstitialPage(contents(), true, url2, &state, &deleted); |
| 1125 TestInterstitialPageStateGuard state_guard(interstitial); | 1131 TestInterstitialPageStateGuard state_guard(interstitial); |
| (...skipping 423 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1549 TestInterstitialPage* interstitial = | 1555 TestInterstitialPage* interstitial = |
| 1550 new TestInterstitialPage(contents(), true, interstitial_url, | 1556 new TestInterstitialPage(contents(), true, interstitial_url, |
| 1551 &state, &deleted); | 1557 &state, &deleted); |
| 1552 TestInterstitialPageStateGuard state_guard(interstitial); | 1558 TestInterstitialPageStateGuard state_guard(interstitial); |
| 1553 interstitial->Show(); | 1559 interstitial->Show(); |
| 1554 | 1560 |
| 1555 // Let's simulate a navigation initiated from the browser before the | 1561 // Let's simulate a navigation initiated from the browser before the |
| 1556 // interstitial finishes loading. | 1562 // interstitial finishes loading. |
| 1557 const GURL url("http://www.google.com"); | 1563 const GURL url("http://www.google.com"); |
| 1558 controller().LoadURL( | 1564 controller().LoadURL( |
| 1559 url, GURL(), content::PAGE_TRANSITION_TYPED, std::string()); | 1565 url, content::Referrer(), content::PAGE_TRANSITION_TYPED, std::string()); |
| 1560 ASSERT_FALSE(deleted); | 1566 ASSERT_FALSE(deleted); |
| 1561 EXPECT_FALSE(interstitial->is_showing()); | 1567 EXPECT_FALSE(interstitial->is_showing()); |
| 1562 | 1568 |
| 1563 // Now let's make the interstitial navigation commit. | 1569 // Now let's make the interstitial navigation commit. |
| 1564 interstitial->TestDidNavigate(1, interstitial_url); | 1570 interstitial->TestDidNavigate(1, interstitial_url); |
| 1565 | 1571 |
| 1566 // After it loaded the interstitial should be gone. | 1572 // After it loaded the interstitial should be gone. |
| 1567 EXPECT_TRUE(deleted); | 1573 EXPECT_TRUE(deleted); |
| 1568 EXPECT_EQ(TestInterstitialPage::CANCELED, state); | 1574 EXPECT_EQ(TestInterstitialPage::CANCELED, state); |
| 1569 } | 1575 } |
| (...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1640 | 1646 |
| 1641 // Tests that showing an interstitial as a result of a browser initiated | 1647 // Tests that showing an interstitial as a result of a browser initiated |
| 1642 // navigation while an interstitial is showing does not remove the pending | 1648 // navigation while an interstitial is showing does not remove the pending |
| 1643 // entry (see http://crbug.com/9791). | 1649 // entry (see http://crbug.com/9791). |
| 1644 TEST_F(TabContentsTest, NewInterstitialDoesNotCancelPendingEntry) { | 1650 TEST_F(TabContentsTest, NewInterstitialDoesNotCancelPendingEntry) { |
| 1645 const char kUrl[] = "http://www.badguys.com/"; | 1651 const char kUrl[] = "http://www.badguys.com/"; |
| 1646 const GURL kGURL(kUrl); | 1652 const GURL kGURL(kUrl); |
| 1647 | 1653 |
| 1648 // Start a navigation to a page | 1654 // Start a navigation to a page |
| 1649 contents()->controller().LoadURL( | 1655 contents()->controller().LoadURL( |
| 1650 kGURL, GURL(), content::PAGE_TRANSITION_TYPED, std::string()); | 1656 kGURL, content::Referrer(), content::PAGE_TRANSITION_TYPED, |
| 1657 std::string()); |
| 1651 | 1658 |
| 1652 // Simulate that navigation triggering an interstitial. | 1659 // Simulate that navigation triggering an interstitial. |
| 1653 TestInterstitialPage::InterstitialState state = | 1660 TestInterstitialPage::InterstitialState state = |
| 1654 TestInterstitialPage::UNDECIDED; | 1661 TestInterstitialPage::UNDECIDED; |
| 1655 bool deleted = false; | 1662 bool deleted = false; |
| 1656 TestInterstitialPage* interstitial = | 1663 TestInterstitialPage* interstitial = |
| 1657 new TestInterstitialPage(contents(), true, kGURL, &state, &deleted); | 1664 new TestInterstitialPage(contents(), true, kGURL, &state, &deleted); |
| 1658 TestInterstitialPageStateGuard state_guard(interstitial); | 1665 TestInterstitialPageStateGuard state_guard(interstitial); |
| 1659 interstitial->Show(); | 1666 interstitial->Show(); |
| 1660 interstitial->TestDidNavigate(1, kGURL); | 1667 interstitial->TestDidNavigate(1, kGURL); |
| 1661 | 1668 |
| 1662 // Initiate a new navigation from the browser that also triggers an | 1669 // Initiate a new navigation from the browser that also triggers an |
| 1663 // interstitial. | 1670 // interstitial. |
| 1664 contents()->controller().LoadURL( | 1671 contents()->controller().LoadURL( |
| 1665 kGURL, GURL(), content::PAGE_TRANSITION_TYPED, std::string()); | 1672 kGURL, content::Referrer(), content::PAGE_TRANSITION_TYPED, |
| 1673 std::string()); |
| 1666 TestInterstitialPage::InterstitialState state2 = | 1674 TestInterstitialPage::InterstitialState state2 = |
| 1667 TestInterstitialPage::UNDECIDED; | 1675 TestInterstitialPage::UNDECIDED; |
| 1668 bool deleted2 = false; | 1676 bool deleted2 = false; |
| 1669 TestInterstitialPage* interstitial2 = | 1677 TestInterstitialPage* interstitial2 = |
| 1670 new TestInterstitialPage(contents(), true, kGURL, &state, &deleted); | 1678 new TestInterstitialPage(contents(), true, kGURL, &state, &deleted); |
| 1671 TestInterstitialPageStateGuard state_guard2(interstitial2); | 1679 TestInterstitialPageStateGuard state_guard2(interstitial2); |
| 1672 interstitial2->Show(); | 1680 interstitial2->Show(); |
| 1673 interstitial2->TestDidNavigate(1, kGURL); | 1681 interstitial2->TestDidNavigate(1, kGURL); |
| 1674 | 1682 |
| 1675 // Make sure we still have an entry. | 1683 // Make sure we still have an entry. |
| 1676 NavigationEntry* entry = contents()->controller().pending_entry(); | 1684 NavigationEntry* entry = contents()->controller().pending_entry(); |
| 1677 ASSERT_TRUE(entry); | 1685 ASSERT_TRUE(entry); |
| 1678 EXPECT_EQ(kUrl, entry->url().spec()); | 1686 EXPECT_EQ(kUrl, entry->url().spec()); |
| 1679 | 1687 |
| 1680 // And that the first interstitial is gone, but not the second. | 1688 // And that the first interstitial is gone, but not the second. |
| 1681 EXPECT_TRUE(deleted); | 1689 EXPECT_TRUE(deleted); |
| 1682 EXPECT_EQ(TestInterstitialPage::CANCELED, state); | 1690 EXPECT_EQ(TestInterstitialPage::CANCELED, state); |
| 1683 EXPECT_FALSE(deleted2); | 1691 EXPECT_FALSE(deleted2); |
| 1684 EXPECT_EQ(TestInterstitialPage::UNDECIDED, state2); | 1692 EXPECT_EQ(TestInterstitialPage::UNDECIDED, state2); |
| 1685 } | 1693 } |
| 1686 | 1694 |
| 1687 // Tests that Javascript messages are not shown while an interstitial is | 1695 // Tests that Javascript messages are not shown while an interstitial is |
| 1688 // showing. | 1696 // showing. |
| 1689 TEST_F(TabContentsTest, NoJSMessageOnInterstitials) { | 1697 TEST_F(TabContentsTest, NoJSMessageOnInterstitials) { |
| 1690 const char kUrl[] = "http://www.badguys.com/"; | 1698 const char kUrl[] = "http://www.badguys.com/"; |
| 1691 const GURL kGURL(kUrl); | 1699 const GURL kGURL(kUrl); |
| 1692 | 1700 |
| 1693 // Start a navigation to a page | 1701 // Start a navigation to a page |
| 1694 contents()->controller().LoadURL( | 1702 contents()->controller().LoadURL( |
| 1695 kGURL, GURL(), content::PAGE_TRANSITION_TYPED, std::string()); | 1703 kGURL, content::Referrer(), content::PAGE_TRANSITION_TYPED, |
| 1704 std::string()); |
| 1696 // DidNavigate from the page | 1705 // DidNavigate from the page |
| 1697 ViewHostMsg_FrameNavigate_Params params; | 1706 ViewHostMsg_FrameNavigate_Params params; |
| 1698 InitNavigateParams(¶ms, 1, kGURL, content::PAGE_TRANSITION_TYPED); | 1707 InitNavigateParams(¶ms, 1, kGURL, content::PAGE_TRANSITION_TYPED); |
| 1699 contents()->TestDidNavigate(rvh(), params); | 1708 contents()->TestDidNavigate(rvh(), params); |
| 1700 | 1709 |
| 1701 // Simulate showing an interstitial while the page is showing. | 1710 // Simulate showing an interstitial while the page is showing. |
| 1702 TestInterstitialPage::InterstitialState state = | 1711 TestInterstitialPage::InterstitialState state = |
| 1703 TestInterstitialPage::UNDECIDED; | 1712 TestInterstitialPage::UNDECIDED; |
| 1704 bool deleted = false; | 1713 bool deleted = false; |
| 1705 TestInterstitialPage* interstitial = | 1714 TestInterstitialPage* interstitial = |
| (...skipping 15 matching lines...) Expand all Loading... |
| 1721 | 1730 |
| 1722 // Makes sure that if the source passed to CopyStateFromAndPrune has an | 1731 // Makes sure that if the source passed to CopyStateFromAndPrune has an |
| 1723 // interstitial it isn't copied over to the destination. | 1732 // interstitial it isn't copied over to the destination. |
| 1724 TEST_F(TabContentsTest, CopyStateFromAndPruneSourceInterstitial) { | 1733 TEST_F(TabContentsTest, CopyStateFromAndPruneSourceInterstitial) { |
| 1725 // Navigate to a page. | 1734 // Navigate to a page. |
| 1726 GURL url1("http://www.google.com"); | 1735 GURL url1("http://www.google.com"); |
| 1727 rvh()->SendNavigate(1, url1); | 1736 rvh()->SendNavigate(1, url1); |
| 1728 EXPECT_EQ(1, controller().entry_count()); | 1737 EXPECT_EQ(1, controller().entry_count()); |
| 1729 | 1738 |
| 1730 // Initiate a browser navigation that will trigger the interstitial | 1739 // Initiate a browser navigation that will trigger the interstitial |
| 1731 controller().LoadURL(GURL("http://www.evil.com"), GURL(), | 1740 controller().LoadURL(GURL("http://www.evil.com"), content::Referrer(), |
| 1732 content::PAGE_TRANSITION_TYPED, std::string()); | 1741 content::PAGE_TRANSITION_TYPED, std::string()); |
| 1733 | 1742 |
| 1734 // Show an interstitial. | 1743 // Show an interstitial. |
| 1735 TestInterstitialPage::InterstitialState state = | 1744 TestInterstitialPage::InterstitialState state = |
| 1736 TestInterstitialPage::UNDECIDED; | 1745 TestInterstitialPage::UNDECIDED; |
| 1737 bool deleted = false; | 1746 bool deleted = false; |
| 1738 GURL url2("http://interstitial"); | 1747 GURL url2("http://interstitial"); |
| 1739 TestInterstitialPage* interstitial = | 1748 TestInterstitialPage* interstitial = |
| 1740 new TestInterstitialPage(contents(), true, url2, &state, &deleted); | 1749 new TestInterstitialPage(contents(), true, url2, &state, &deleted); |
| 1741 TestInterstitialPageStateGuard state_guard(interstitial); | 1750 TestInterstitialPageStateGuard state_guard(interstitial); |
| (...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1805 | 1814 |
| 1806 // It should have a transient entry. | 1815 // It should have a transient entry. |
| 1807 EXPECT_TRUE(other_controller.GetTransientEntry()); | 1816 EXPECT_TRUE(other_controller.GetTransientEntry()); |
| 1808 | 1817 |
| 1809 // And the interstitial should be showing. | 1818 // And the interstitial should be showing. |
| 1810 EXPECT_TRUE(other_contents->showing_interstitial_page()); | 1819 EXPECT_TRUE(other_contents->showing_interstitial_page()); |
| 1811 | 1820 |
| 1812 // And the interstitial should do a reload on don't proceed. | 1821 // And the interstitial should do a reload on don't proceed. |
| 1813 EXPECT_TRUE(other_contents->interstitial_page()->reload_on_dont_proceed()); | 1822 EXPECT_TRUE(other_contents->interstitial_page()->reload_on_dont_proceed()); |
| 1814 } | 1823 } |
| OLD | NEW |