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" | |
8 #include "chrome/browser/prefs/pref_service.h" | 7 #include "chrome/browser/prefs/pref_service.h" |
9 #include "chrome/browser/tab_contents/chrome_interstitial_page.h" | |
10 #include "chrome/common/chrome_notification_types.h" | |
11 #include "chrome/common/pref_names.h" | 8 #include "chrome/common/pref_names.h" |
12 #include "chrome/common/render_messages.h" | |
13 #include "chrome/common/url_constants.h" | |
14 #include "chrome/test/base/chrome_render_view_host_test_harness.h" | 9 #include "chrome/test/base/chrome_render_view_host_test_harness.h" |
15 #include "chrome/test/base/testing_pref_service.h" | 10 #include "chrome/test/base/testing_pref_service.h" |
16 #include "chrome/test/base/testing_profile.h" | 11 #include "chrome/test/base/testing_profile.h" |
17 #include "content/browser/renderer_host/render_view_host.h" | 12 #include "content/browser/renderer_host/render_view_host.h" |
18 #include "content/browser/renderer_host/render_widget_host_view.h" | 13 #include "content/browser/renderer_host/render_widget_host_view.h" |
19 #include "content/browser/site_instance.h" | 14 #include "content/browser/site_instance.h" |
| 15 #include "content/browser/tab_contents/interstitial_page.h" |
20 #include "content/browser/tab_contents/navigation_details.h" | 16 #include "content/browser/tab_contents/navigation_details.h" |
21 #include "content/browser/tab_contents/navigation_entry.h" | 17 #include "content/browser/tab_contents/navigation_entry.h" |
22 #include "content/browser/tab_contents/test_tab_contents.h" | 18 #include "content/browser/tab_contents/test_tab_contents.h" |
23 #include "content/common/view_messages.h" | 19 #include "content/common/view_messages.h" |
24 #include "content/public/browser/notification_details.h" | 20 #include "content/public/browser/notification_details.h" |
25 #include "content/public/browser/notification_source.h" | 21 #include "content/public/browser/notification_source.h" |
26 #include "content/public/browser/notification_source.h" | 22 #include "content/public/browser/notification_source.h" |
27 #include "content/public/common/bindings_policy.h" | 23 #include "content/public/common/bindings_policy.h" |
28 #include "content/public/common/content_constants.h" | 24 #include "content/public/common/content_constants.h" |
| 25 #include "content/public/common/url_constants.h" |
29 #include "content/test/test_browser_thread.h" | 26 #include "content/test/test_browser_thread.h" |
30 #include "testing/gtest/include/gtest/gtest.h" | 27 #include "testing/gtest/include/gtest/gtest.h" |
31 #include "ui/base/message_box_flags.h" | 28 #include "ui/base/message_box_flags.h" |
32 #include "webkit/glue/webkit_glue.h" | 29 #include "webkit/glue/webkit_glue.h" |
33 | 30 |
34 using content::BrowserThread; | 31 using content::BrowserThread; |
35 using webkit_glue::PasswordForm; | 32 using webkit_glue::PasswordForm; |
36 | 33 |
37 class TestInterstitialPage : public ChromeInterstitialPage { | 34 class TestInterstitialPage : public InterstitialPage { |
38 public: | 35 public: |
39 enum InterstitialState { | 36 enum InterstitialState { |
40 UNDECIDED = 0, // No decision taken yet. | 37 UNDECIDED = 0, // No decision taken yet. |
41 OKED, // Proceed was called. | 38 OKED, // Proceed was called. |
42 CANCELED // DontProceed was called. | 39 CANCELED // DontProceed was called. |
43 }; | 40 }; |
44 | 41 |
45 class Delegate { | 42 class Delegate { |
46 public: | 43 public: |
47 virtual void TestInterstitialPageDeleted( | 44 virtual void TestInterstitialPageDeleted( |
(...skipping 10 matching lines...) Expand all Loading... |
58 // are cleared when the test finishes. | 55 // are cleared when the test finishes. |
59 // Not doing so will cause stack trashing if your test does not hide the | 56 // Not doing so will cause stack trashing if your test does not hide the |
60 // interstitial, as in such a case it will be destroyed in the test TearDown | 57 // interstitial, as in such a case it will be destroyed in the test TearDown |
61 // method and will dereference the |deleted| local variable which by then is | 58 // method and will dereference the |deleted| local variable which by then is |
62 // out of scope. | 59 // out of scope. |
63 TestInterstitialPage(TabContents* tab, | 60 TestInterstitialPage(TabContents* tab, |
64 bool new_navigation, | 61 bool new_navigation, |
65 const GURL& url, | 62 const GURL& url, |
66 InterstitialState* state, | 63 InterstitialState* state, |
67 bool* deleted) | 64 bool* deleted) |
68 : ChromeInterstitialPage(tab, new_navigation, url), | 65 : InterstitialPage(tab, new_navigation, url), |
69 state_(state), | 66 state_(state), |
70 deleted_(deleted), | 67 deleted_(deleted), |
71 command_received_count_(0), | 68 command_received_count_(0), |
72 delegate_(NULL) { | 69 delegate_(NULL) { |
73 *state_ = UNDECIDED; | 70 *state_ = UNDECIDED; |
74 *deleted_ = false; | 71 *deleted_ = false; |
75 } | 72 } |
76 | 73 |
77 virtual ~TestInterstitialPage() { | 74 virtual ~TestInterstitialPage() { |
78 if (deleted_) | 75 if (deleted_) |
(...skipping 11 matching lines...) Expand all Loading... |
90 if (state_) | 87 if (state_) |
91 *state_ = OKED; | 88 *state_ = OKED; |
92 InterstitialPage::Proceed(); | 89 InterstitialPage::Proceed(); |
93 } | 90 } |
94 | 91 |
95 int command_received_count() const { | 92 int command_received_count() const { |
96 return command_received_count_; | 93 return command_received_count_; |
97 } | 94 } |
98 | 95 |
99 void TestDomOperationResponse(const std::string& json_string) { | 96 void TestDomOperationResponse(const std::string& json_string) { |
100 DomOperationNotificationDetails details(json_string, 1); | 97 if (enabled()) |
101 Observe(chrome::NOTIFICATION_DOM_OPERATION_RESPONSE, | 98 CommandReceived(json_string); |
102 content::Source<RenderViewHost>(render_view_host()), | |
103 content::Details<DomOperationNotificationDetails>(&details)); | |
104 } | 99 } |
105 | 100 |
106 void TestDidNavigate(int page_id, const GURL& url) { | 101 void TestDidNavigate(int page_id, const GURL& url) { |
107 ViewHostMsg_FrameNavigate_Params params; | 102 ViewHostMsg_FrameNavigate_Params params; |
108 InitNavigateParams(¶ms, page_id, url, content::PAGE_TRANSITION_TYPED); | 103 InitNavigateParams(¶ms, page_id, url, content::PAGE_TRANSITION_TYPED); |
109 DidNavigate(render_view_host(), params); | 104 DidNavigate(render_view_host(), params); |
110 } | 105 } |
111 | 106 |
112 void TestRenderViewGone(base::TerminationStatus status, int error_code) { | 107 void TestRenderViewGone(base::TerminationStatus status, int error_code) { |
113 RenderViewGone(render_view_host(), status, error_code); | 108 RenderViewGone(render_view_host(), status, error_code); |
(...skipping 136 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
250 const GURL url("http://www.google.com"); | 245 const GURL url("http://www.google.com"); |
251 controller().LoadURL( | 246 controller().LoadURL( |
252 url, content::Referrer(), content::PAGE_TRANSITION_TYPED, std::string()); | 247 url, content::Referrer(), content::PAGE_TRANSITION_TYPED, std::string()); |
253 EXPECT_FALSE(contents()->cross_navigation_pending()); | 248 EXPECT_FALSE(contents()->cross_navigation_pending()); |
254 EXPECT_EQ(instance1, orig_rvh->site_instance()); | 249 EXPECT_EQ(instance1, orig_rvh->site_instance()); |
255 // Controller's pending entry will have a NULL site instance until we assign | 250 // Controller's pending entry will have a NULL site instance until we assign |
256 // it in DidNavigate. | 251 // it in DidNavigate. |
257 EXPECT_TRUE(controller().GetActiveEntry()->site_instance() == NULL); | 252 EXPECT_TRUE(controller().GetActiveEntry()->site_instance() == NULL); |
258 | 253 |
259 // DidNavigate from the page | 254 // DidNavigate from the page |
260 ViewHostMsg_FrameNavigate_Params params; | 255 contents()->TestDidNavigate(orig_rvh, 1, url, content::PAGE_TRANSITION_TYPED); |
261 InitNavigateParams(¶ms, 1, url, content::PAGE_TRANSITION_TYPED); | |
262 contents()->TestDidNavigate(orig_rvh, params); | |
263 EXPECT_FALSE(contents()->cross_navigation_pending()); | 256 EXPECT_FALSE(contents()->cross_navigation_pending()); |
264 EXPECT_EQ(orig_rvh, contents()->render_view_host()); | 257 EXPECT_EQ(orig_rvh, contents()->render_view_host()); |
265 EXPECT_EQ(instance1, orig_rvh->site_instance()); | 258 EXPECT_EQ(instance1, orig_rvh->site_instance()); |
266 // Controller's entry should now have the SiteInstance, or else we won't be | 259 // Controller's entry should now have the SiteInstance, or else we won't be |
267 // able to find it later. | 260 // able to find it later. |
268 EXPECT_EQ(instance1, controller().GetActiveEntry()->site_instance()); | 261 EXPECT_EQ(instance1, controller().GetActiveEntry()->site_instance()); |
269 } | 262 } |
270 | 263 |
271 // Test that we reject NavigateToEntry if the url is over content::kMaxURLChars. | 264 // Test that we reject NavigateToEntry if the url is over content::kMaxURLChars. |
272 TEST_F(TabContentsTest, NavigateToExcessivelyLongURL) { | 265 TEST_F(TabContentsTest, NavigateToExcessivelyLongURL) { |
(...skipping 13 matching lines...) Expand all Loading... |
286 contents()->transition_cross_site = true; | 279 contents()->transition_cross_site = true; |
287 TestRenderViewHost* orig_rvh = rvh(); | 280 TestRenderViewHost* orig_rvh = rvh(); |
288 int orig_rvh_delete_count = 0; | 281 int orig_rvh_delete_count = 0; |
289 orig_rvh->set_delete_counter(&orig_rvh_delete_count); | 282 orig_rvh->set_delete_counter(&orig_rvh_delete_count); |
290 SiteInstance* instance1 = contents()->GetSiteInstance(); | 283 SiteInstance* instance1 = contents()->GetSiteInstance(); |
291 | 284 |
292 // Navigate to URL. First URL should use first RenderViewHost. | 285 // Navigate to URL. First URL should use first RenderViewHost. |
293 const GURL url("http://www.google.com"); | 286 const GURL url("http://www.google.com"); |
294 controller().LoadURL( | 287 controller().LoadURL( |
295 url, content::Referrer(), content::PAGE_TRANSITION_TYPED, std::string()); | 288 url, content::Referrer(), content::PAGE_TRANSITION_TYPED, std::string()); |
296 ViewHostMsg_FrameNavigate_Params params1; | 289 contents()->TestDidNavigate(orig_rvh, 1, url, content::PAGE_TRANSITION_TYPED); |
297 InitNavigateParams(¶ms1, 1, url, content::PAGE_TRANSITION_TYPED); | |
298 contents()->TestDidNavigate(orig_rvh, params1); | |
299 | 290 |
300 EXPECT_FALSE(contents()->cross_navigation_pending()); | 291 EXPECT_FALSE(contents()->cross_navigation_pending()); |
301 EXPECT_EQ(orig_rvh, contents()->render_view_host()); | 292 EXPECT_EQ(orig_rvh, contents()->render_view_host()); |
302 | 293 |
303 // Navigate to new site | 294 // Navigate to new site |
304 const GURL url2("http://www.yahoo.com"); | 295 const GURL url2("http://www.yahoo.com"); |
305 controller().LoadURL( | 296 controller().LoadURL( |
306 url2, content::Referrer(), content::PAGE_TRANSITION_TYPED, std::string()); | 297 url2, content::Referrer(), content::PAGE_TRANSITION_TYPED, std::string()); |
307 EXPECT_TRUE(contents()->cross_navigation_pending()); | 298 EXPECT_TRUE(contents()->cross_navigation_pending()); |
308 TestRenderViewHost* pending_rvh = contents()->pending_rvh(); | 299 TestRenderViewHost* pending_rvh = contents()->pending_rvh(); |
309 int pending_rvh_delete_count = 0; | 300 int pending_rvh_delete_count = 0; |
310 pending_rvh->set_delete_counter(&pending_rvh_delete_count); | 301 pending_rvh->set_delete_counter(&pending_rvh_delete_count); |
311 | 302 |
312 // Navigations should be suspended in pending_rvh until ShouldCloseACK. | 303 // Navigations should be suspended in pending_rvh until ShouldCloseACK. |
313 EXPECT_TRUE(pending_rvh->are_navigations_suspended()); | 304 EXPECT_TRUE(pending_rvh->are_navigations_suspended()); |
314 orig_rvh->SendShouldCloseACK(true); | 305 orig_rvh->SendShouldCloseACK(true); |
315 EXPECT_FALSE(pending_rvh->are_navigations_suspended()); | 306 EXPECT_FALSE(pending_rvh->are_navigations_suspended()); |
316 | 307 |
317 // DidNavigate from the pending page | 308 // DidNavigate from the pending page |
318 ViewHostMsg_FrameNavigate_Params params2; | 309 contents()->TestDidNavigate( |
319 InitNavigateParams(¶ms2, 1, url2, content::PAGE_TRANSITION_TYPED); | 310 pending_rvh, 1, url2, content::PAGE_TRANSITION_TYPED); |
320 contents()->TestDidNavigate(pending_rvh, params2); | |
321 SiteInstance* instance2 = contents()->GetSiteInstance(); | 311 SiteInstance* instance2 = contents()->GetSiteInstance(); |
322 | 312 |
323 EXPECT_FALSE(contents()->cross_navigation_pending()); | 313 EXPECT_FALSE(contents()->cross_navigation_pending()); |
324 EXPECT_EQ(pending_rvh, contents()->render_view_host()); | 314 EXPECT_EQ(pending_rvh, contents()->render_view_host()); |
325 EXPECT_NE(instance1, instance2); | 315 EXPECT_NE(instance1, instance2); |
326 EXPECT_TRUE(contents()->pending_rvh() == NULL); | 316 EXPECT_TRUE(contents()->pending_rvh() == NULL); |
327 // We keep the original RVH around, swapped out. | 317 // We keep the original RVH around, swapped out. |
328 EXPECT_TRUE(contents()->render_manager_for_testing()->IsSwappedOut(orig_rvh)); | 318 EXPECT_TRUE(contents()->render_manager_for_testing()->IsSwappedOut(orig_rvh)); |
329 EXPECT_EQ(orig_rvh_delete_count, 0); | 319 EXPECT_EQ(orig_rvh_delete_count, 0); |
330 | 320 |
331 // Going back should switch SiteInstances again. The first SiteInstance is | 321 // Going back should switch SiteInstances again. The first SiteInstance is |
332 // stored in the NavigationEntry, so it should be the same as at the start. | 322 // stored in the NavigationEntry, so it should be the same as at the start. |
333 // We should use the same RVH as before, swapping it back in. | 323 // We should use the same RVH as before, swapping it back in. |
334 controller().GoBack(); | 324 controller().GoBack(); |
335 TestRenderViewHost* goback_rvh = contents()->pending_rvh(); | 325 TestRenderViewHost* goback_rvh = contents()->pending_rvh(); |
336 EXPECT_EQ(orig_rvh, goback_rvh); | 326 EXPECT_EQ(orig_rvh, goback_rvh); |
337 EXPECT_TRUE(contents()->cross_navigation_pending()); | 327 EXPECT_TRUE(contents()->cross_navigation_pending()); |
338 | 328 |
339 // Navigations should be suspended in goback_rvh until ShouldCloseACK. | 329 // Navigations should be suspended in goback_rvh until ShouldCloseACK. |
340 EXPECT_TRUE(goback_rvh->are_navigations_suspended()); | 330 EXPECT_TRUE(goback_rvh->are_navigations_suspended()); |
341 pending_rvh->SendShouldCloseACK(true); | 331 pending_rvh->SendShouldCloseACK(true); |
342 EXPECT_FALSE(goback_rvh->are_navigations_suspended()); | 332 EXPECT_FALSE(goback_rvh->are_navigations_suspended()); |
343 | 333 |
344 // DidNavigate from the back action | 334 // DidNavigate from the back action |
345 contents()->TestDidNavigate(goback_rvh, params1); | 335 contents()->TestDidNavigate( |
| 336 goback_rvh, 1, url2, content::PAGE_TRANSITION_TYPED); |
346 EXPECT_FALSE(contents()->cross_navigation_pending()); | 337 EXPECT_FALSE(contents()->cross_navigation_pending()); |
347 EXPECT_EQ(goback_rvh, contents()->render_view_host()); | 338 EXPECT_EQ(goback_rvh, contents()->render_view_host()); |
348 EXPECT_EQ(instance1, contents()->GetSiteInstance()); | 339 EXPECT_EQ(instance1, contents()->GetSiteInstance()); |
349 // The pending RVH should now be swapped out, not deleted. | 340 // The pending RVH should now be swapped out, not deleted. |
350 EXPECT_TRUE(contents()->render_manager_for_testing()-> | 341 EXPECT_TRUE(contents()->render_manager_for_testing()-> |
351 IsSwappedOut(pending_rvh)); | 342 IsSwappedOut(pending_rvh)); |
352 EXPECT_EQ(pending_rvh_delete_count, 0); | 343 EXPECT_EQ(pending_rvh_delete_count, 0); |
353 | 344 |
354 // Close tab and ensure RVHs are deleted. | 345 // Close tab and ensure RVHs are deleted. |
355 DeleteContents(); | 346 DeleteContents(); |
356 EXPECT_EQ(orig_rvh_delete_count, 1); | 347 EXPECT_EQ(orig_rvh_delete_count, 1); |
357 EXPECT_EQ(pending_rvh_delete_count, 1); | 348 EXPECT_EQ(pending_rvh_delete_count, 1); |
358 } | 349 } |
359 | 350 |
360 // Test that navigating across a site boundary after a crash creates a new | 351 // Test that navigating across a site boundary after a crash creates a new |
361 // RVH without requiring a cross-site transition (i.e., PENDING state). | 352 // RVH without requiring a cross-site transition (i.e., PENDING state). |
362 TEST_F(TabContentsTest, CrossSiteBoundariesAfterCrash) { | 353 TEST_F(TabContentsTest, CrossSiteBoundariesAfterCrash) { |
363 contents()->transition_cross_site = true; | 354 contents()->transition_cross_site = true; |
364 TestRenderViewHost* orig_rvh = rvh(); | 355 TestRenderViewHost* orig_rvh = rvh(); |
365 int orig_rvh_delete_count = 0; | 356 int orig_rvh_delete_count = 0; |
366 orig_rvh->set_delete_counter(&orig_rvh_delete_count); | 357 orig_rvh->set_delete_counter(&orig_rvh_delete_count); |
367 SiteInstance* instance1 = contents()->GetSiteInstance(); | 358 SiteInstance* instance1 = contents()->GetSiteInstance(); |
368 | 359 |
369 // Navigate to URL. First URL should use first RenderViewHost. | 360 // Navigate to URL. First URL should use first RenderViewHost. |
370 const GURL url("http://www.google.com"); | 361 const GURL url("http://www.google.com"); |
371 controller().LoadURL( | 362 controller().LoadURL( |
372 url, content::Referrer(), content::PAGE_TRANSITION_TYPED, std::string()); | 363 url, content::Referrer(), content::PAGE_TRANSITION_TYPED, std::string()); |
373 ViewHostMsg_FrameNavigate_Params params1; | 364 contents()->TestDidNavigate(orig_rvh, 1, url, content::PAGE_TRANSITION_TYPED); |
374 InitNavigateParams(¶ms1, 1, url, content::PAGE_TRANSITION_TYPED); | |
375 contents()->TestDidNavigate(orig_rvh, params1); | |
376 | 365 |
377 EXPECT_FALSE(contents()->cross_navigation_pending()); | 366 EXPECT_FALSE(contents()->cross_navigation_pending()); |
378 EXPECT_EQ(orig_rvh, contents()->render_view_host()); | 367 EXPECT_EQ(orig_rvh, contents()->render_view_host()); |
379 | 368 |
380 // Crash the renderer. | 369 // Crash the renderer. |
381 orig_rvh->set_render_view_created(false); | 370 orig_rvh->set_render_view_created(false); |
382 | 371 |
383 // Navigate to new site. We should not go into PENDING. | 372 // Navigate to new site. We should not go into PENDING. |
384 const GURL url2("http://www.yahoo.com"); | 373 const GURL url2("http://www.yahoo.com"); |
385 controller().LoadURL( | 374 controller().LoadURL( |
386 url2, content::Referrer(), content::PAGE_TRANSITION_TYPED, std::string()); | 375 url2, content::Referrer(), content::PAGE_TRANSITION_TYPED, std::string()); |
387 TestRenderViewHost* new_rvh = rvh(); | 376 TestRenderViewHost* new_rvh = rvh(); |
388 EXPECT_FALSE(contents()->cross_navigation_pending()); | 377 EXPECT_FALSE(contents()->cross_navigation_pending()); |
389 EXPECT_TRUE(contents()->pending_rvh() == NULL); | 378 EXPECT_TRUE(contents()->pending_rvh() == NULL); |
390 EXPECT_NE(orig_rvh, new_rvh); | 379 EXPECT_NE(orig_rvh, new_rvh); |
391 EXPECT_EQ(orig_rvh_delete_count, 1); | 380 EXPECT_EQ(orig_rvh_delete_count, 1); |
392 | 381 |
393 // DidNavigate from the new page | 382 // DidNavigate from the new page |
394 ViewHostMsg_FrameNavigate_Params params2; | 383 contents()->TestDidNavigate(new_rvh, 1, url2, content::PAGE_TRANSITION_TYPED); |
395 InitNavigateParams(¶ms2, 1, url2, content::PAGE_TRANSITION_TYPED); | |
396 contents()->TestDidNavigate(new_rvh, params2); | |
397 SiteInstance* instance2 = contents()->GetSiteInstance(); | 384 SiteInstance* instance2 = contents()->GetSiteInstance(); |
398 | 385 |
399 EXPECT_FALSE(contents()->cross_navigation_pending()); | 386 EXPECT_FALSE(contents()->cross_navigation_pending()); |
400 EXPECT_EQ(new_rvh, rvh()); | 387 EXPECT_EQ(new_rvh, rvh()); |
401 EXPECT_NE(instance1, instance2); | 388 EXPECT_NE(instance1, instance2); |
402 EXPECT_TRUE(contents()->pending_rvh() == NULL); | 389 EXPECT_TRUE(contents()->pending_rvh() == NULL); |
403 | 390 |
404 // Close tab and ensure RVHs are deleted. | 391 // Close tab and ensure RVHs are deleted. |
405 DeleteContents(); | 392 DeleteContents(); |
406 EXPECT_EQ(orig_rvh_delete_count, 1); | 393 EXPECT_EQ(orig_rvh_delete_count, 1); |
407 } | 394 } |
408 | 395 |
409 // Test that opening a new tab in the same SiteInstance and then navigating | 396 // Test that opening a new tab in the same SiteInstance and then navigating |
410 // both tabs to a new site will place both tabs in a single SiteInstance. | 397 // both tabs to a new site will place both tabs in a single SiteInstance. |
411 TEST_F(TabContentsTest, NavigateTwoTabsCrossSite) { | 398 TEST_F(TabContentsTest, NavigateTwoTabsCrossSite) { |
412 contents()->transition_cross_site = true; | 399 contents()->transition_cross_site = true; |
413 TestRenderViewHost* orig_rvh = rvh(); | 400 TestRenderViewHost* orig_rvh = rvh(); |
414 SiteInstance* instance1 = contents()->GetSiteInstance(); | 401 SiteInstance* instance1 = contents()->GetSiteInstance(); |
415 | 402 |
416 // Navigate to URL. First URL should use first RenderViewHost. | 403 // Navigate to URL. First URL should use first RenderViewHost. |
417 const GURL url("http://www.google.com"); | 404 const GURL url("http://www.google.com"); |
418 controller().LoadURL( | 405 controller().LoadURL( |
419 url, content::Referrer(), content::PAGE_TRANSITION_TYPED, std::string()); | 406 url, content::Referrer(), content::PAGE_TRANSITION_TYPED, std::string()); |
420 ViewHostMsg_FrameNavigate_Params params1; | 407 contents()->TestDidNavigate(orig_rvh, 1, url, content::PAGE_TRANSITION_TYPED); |
421 InitNavigateParams(¶ms1, 1, url, content::PAGE_TRANSITION_TYPED); | |
422 contents()->TestDidNavigate(orig_rvh, params1); | |
423 | 408 |
424 // Open a new tab with the same SiteInstance, navigated to the same site. | 409 // Open a new tab with the same SiteInstance, navigated to the same site. |
425 TestTabContents contents2(profile(), instance1); | 410 TestTabContents contents2(profile(), instance1); |
426 params1.page_id = 2; // Need this since the site instance is the same (which | |
427 // is the scope of page IDs) and we want to consider | |
428 // this a new page. | |
429 contents2.transition_cross_site = true; | 411 contents2.transition_cross_site = true; |
430 contents2.controller().LoadURL(url, content::Referrer(), | 412 contents2.controller().LoadURL(url, content::Referrer(), |
431 content::PAGE_TRANSITION_TYPED, | 413 content::PAGE_TRANSITION_TYPED, |
432 std::string()); | 414 std::string()); |
433 contents2.TestDidNavigate(contents2.render_view_host(), params1); | 415 // Need this page id to be 2 since the site instance is the same (which is the |
| 416 // scope of page IDs) and we want to consider this a new page. |
| 417 contents2.TestDidNavigate( |
| 418 contents2.render_view_host(), 2, url, content::PAGE_TRANSITION_TYPED); |
434 | 419 |
435 // Navigate first tab to a new site | 420 // Navigate first tab to a new site |
436 const GURL url2a("http://www.yahoo.com"); | 421 const GURL url2a("http://www.yahoo.com"); |
437 controller().LoadURL( | 422 controller().LoadURL( |
438 url2a, content::Referrer(), content::PAGE_TRANSITION_TYPED, | 423 url2a, content::Referrer(), content::PAGE_TRANSITION_TYPED, |
439 std::string()); | 424 std::string()); |
440 orig_rvh->SendShouldCloseACK(true); | 425 orig_rvh->SendShouldCloseACK(true); |
441 TestRenderViewHost* pending_rvh_a = contents()->pending_rvh(); | 426 TestRenderViewHost* pending_rvh_a = contents()->pending_rvh(); |
442 ViewHostMsg_FrameNavigate_Params params2a; | 427 contents()->TestDidNavigate( |
443 InitNavigateParams(¶ms2a, 1, url2a, content::PAGE_TRANSITION_TYPED); | 428 pending_rvh_a, 1, url2a, content::PAGE_TRANSITION_TYPED); |
444 contents()->TestDidNavigate(pending_rvh_a, params2a); | |
445 SiteInstance* instance2a = contents()->GetSiteInstance(); | 429 SiteInstance* instance2a = contents()->GetSiteInstance(); |
446 EXPECT_NE(instance1, instance2a); | 430 EXPECT_NE(instance1, instance2a); |
447 | 431 |
448 // Navigate second tab to the same site as the first tab | 432 // Navigate second tab to the same site as the first tab |
449 const GURL url2b("http://mail.yahoo.com"); | 433 const GURL url2b("http://mail.yahoo.com"); |
450 contents2.controller().LoadURL(url2b, content::Referrer(), | 434 contents2.controller().LoadURL(url2b, content::Referrer(), |
451 content::PAGE_TRANSITION_TYPED, | 435 content::PAGE_TRANSITION_TYPED, |
452 std::string()); | 436 std::string()); |
453 TestRenderViewHost* rvh2 = | 437 TestRenderViewHost* rvh2 = |
454 static_cast<TestRenderViewHost*>(contents2.render_view_host()); | 438 static_cast<TestRenderViewHost*>(contents2.render_view_host()); |
455 rvh2->SendShouldCloseACK(true); | 439 rvh2->SendShouldCloseACK(true); |
456 TestRenderViewHost* pending_rvh_b = contents2.pending_rvh(); | 440 TestRenderViewHost* pending_rvh_b = contents2.pending_rvh(); |
457 EXPECT_TRUE(pending_rvh_b != NULL); | 441 EXPECT_TRUE(pending_rvh_b != NULL); |
458 EXPECT_TRUE(contents2.cross_navigation_pending()); | 442 EXPECT_TRUE(contents2.cross_navigation_pending()); |
459 | 443 |
460 // NOTE(creis): We used to be in danger of showing a sad tab page here if the | 444 // NOTE(creis): We used to be in danger of showing a sad tab page here if the |
461 // second tab hadn't navigated somewhere first (bug 1145430). That case is | 445 // second tab hadn't navigated somewhere first (bug 1145430). That case is |
462 // now covered by the CrossSiteBoundariesAfterCrash test. | 446 // now covered by the CrossSiteBoundariesAfterCrash test. |
463 | 447 contents2.TestDidNavigate( |
464 ViewHostMsg_FrameNavigate_Params params2b; | 448 pending_rvh_b, 2, url2b, content::PAGE_TRANSITION_TYPED); |
465 InitNavigateParams(¶ms2b, 2, url2b, content::PAGE_TRANSITION_TYPED); | |
466 contents2.TestDidNavigate(pending_rvh_b, params2b); | |
467 SiteInstance* instance2b = contents2.GetSiteInstance(); | 449 SiteInstance* instance2b = contents2.GetSiteInstance(); |
468 EXPECT_NE(instance1, instance2b); | 450 EXPECT_NE(instance1, instance2b); |
469 | 451 |
470 // Both tabs should now be in the same SiteInstance. | 452 // Both tabs should now be in the same SiteInstance. |
471 EXPECT_EQ(instance2a, instance2b); | 453 EXPECT_EQ(instance2a, instance2b); |
472 } | 454 } |
473 | 455 |
474 // Tests that TabContents uses the current URL, not the SiteInstance's site, to | 456 // Tests that TabContents uses the current URL, not the SiteInstance's site, to |
475 // determine whether a navigation is cross-site. | 457 // determine whether a navigation is cross-site. |
476 TEST_F(TabContentsTest, CrossSiteComparesAgainstCurrentPage) { | 458 TEST_F(TabContentsTest, CrossSiteComparesAgainstCurrentPage) { |
477 contents()->transition_cross_site = true; | 459 contents()->transition_cross_site = true; |
478 TestRenderViewHost* orig_rvh = rvh(); | 460 TestRenderViewHost* orig_rvh = rvh(); |
479 SiteInstance* instance1 = contents()->GetSiteInstance(); | 461 SiteInstance* instance1 = contents()->GetSiteInstance(); |
480 | 462 |
481 // Navigate to URL. | 463 // Navigate to URL. |
482 const GURL url("http://www.google.com"); | 464 const GURL url("http://www.google.com"); |
483 controller().LoadURL( | 465 controller().LoadURL( |
484 url, content::Referrer(), content::PAGE_TRANSITION_TYPED, std::string()); | 466 url, content::Referrer(), content::PAGE_TRANSITION_TYPED, std::string()); |
485 ViewHostMsg_FrameNavigate_Params params1; | 467 contents()->TestDidNavigate( |
486 InitNavigateParams(¶ms1, 1, url, content::PAGE_TRANSITION_TYPED); | 468 orig_rvh, 1, url, content::PAGE_TRANSITION_TYPED); |
487 contents()->TestDidNavigate(orig_rvh, params1); | |
488 | 469 |
489 // Open a related tab to a second site. | 470 // Open a related tab to a second site. |
490 TestTabContents contents2(profile(), instance1); | 471 TestTabContents contents2(profile(), instance1); |
491 contents2.transition_cross_site = true; | 472 contents2.transition_cross_site = true; |
492 const GURL url2("http://www.yahoo.com"); | 473 const GURL url2("http://www.yahoo.com"); |
493 contents2.controller().LoadURL(url2, content::Referrer(), | 474 contents2.controller().LoadURL(url2, content::Referrer(), |
494 content::PAGE_TRANSITION_TYPED, | 475 content::PAGE_TRANSITION_TYPED, |
495 std::string()); | 476 std::string()); |
496 // The first RVH in contents2 isn't live yet, so we shortcut the cross site | 477 // The first RVH in contents2 isn't live yet, so we shortcut the cross site |
497 // pending. | 478 // pending. |
498 TestRenderViewHost* rvh2 = static_cast<TestRenderViewHost*>( | 479 TestRenderViewHost* rvh2 = static_cast<TestRenderViewHost*>( |
499 contents2.render_view_host()); | 480 contents2.render_view_host()); |
500 EXPECT_FALSE(contents2.cross_navigation_pending()); | 481 EXPECT_FALSE(contents2.cross_navigation_pending()); |
501 ViewHostMsg_FrameNavigate_Params params2; | 482 contents2.TestDidNavigate(rvh2, 2, url2, content::PAGE_TRANSITION_TYPED); |
502 InitNavigateParams(¶ms2, 2, url2, content::PAGE_TRANSITION_TYPED); | |
503 contents2.TestDidNavigate(rvh2, params2); | |
504 SiteInstance* instance2 = contents2.GetSiteInstance(); | 483 SiteInstance* instance2 = contents2.GetSiteInstance(); |
505 EXPECT_NE(instance1, instance2); | 484 EXPECT_NE(instance1, instance2); |
506 EXPECT_FALSE(contents2.cross_navigation_pending()); | 485 EXPECT_FALSE(contents2.cross_navigation_pending()); |
507 | 486 |
508 // Simulate a link click in first tab to second site. Doesn't switch | 487 // Simulate a link click in first tab to second site. Doesn't switch |
509 // SiteInstances, because we don't intercept WebKit navigations. | 488 // SiteInstances, because we don't intercept WebKit navigations. |
510 ViewHostMsg_FrameNavigate_Params params3; | 489 contents()->TestDidNavigate( |
511 InitNavigateParams(¶ms3, 2, url2, content::PAGE_TRANSITION_TYPED); | 490 orig_rvh, 2, url2, content::PAGE_TRANSITION_TYPED); |
512 contents()->TestDidNavigate(orig_rvh, params3); | |
513 SiteInstance* instance3 = contents()->GetSiteInstance(); | 491 SiteInstance* instance3 = contents()->GetSiteInstance(); |
514 EXPECT_EQ(instance1, instance3); | 492 EXPECT_EQ(instance1, instance3); |
515 EXPECT_FALSE(contents()->cross_navigation_pending()); | 493 EXPECT_FALSE(contents()->cross_navigation_pending()); |
516 | 494 |
517 // Navigate to the new site. Doesn't switch SiteInstancees, because we | 495 // Navigate to the new site. Doesn't switch SiteInstancees, because we |
518 // compare against the current URL, not the SiteInstance's site. | 496 // compare against the current URL, not the SiteInstance's site. |
519 const GURL url3("http://mail.yahoo.com"); | 497 const GURL url3("http://mail.yahoo.com"); |
520 controller().LoadURL( | 498 controller().LoadURL( |
521 url3, content::Referrer(), content::PAGE_TRANSITION_TYPED, std::string()); | 499 url3, content::Referrer(), content::PAGE_TRANSITION_TYPED, std::string()); |
522 EXPECT_FALSE(contents()->cross_navigation_pending()); | 500 EXPECT_FALSE(contents()->cross_navigation_pending()); |
523 ViewHostMsg_FrameNavigate_Params params4; | 501 contents()->TestDidNavigate( |
524 InitNavigateParams(¶ms4, 3, url3, content::PAGE_TRANSITION_TYPED); | 502 orig_rvh, 3, url3, content::PAGE_TRANSITION_TYPED); |
525 contents()->TestDidNavigate(orig_rvh, params4); | |
526 SiteInstance* instance4 = contents()->GetSiteInstance(); | 503 SiteInstance* instance4 = contents()->GetSiteInstance(); |
527 EXPECT_EQ(instance1, instance4); | 504 EXPECT_EQ(instance1, instance4); |
528 } | 505 } |
529 | 506 |
530 // Test that the onbeforeunload and onunload handlers run when navigating | 507 // Test that the onbeforeunload and onunload handlers run when navigating |
531 // across site boundaries. | 508 // across site boundaries. |
532 TEST_F(TabContentsTest, CrossSiteUnloadHandlers) { | 509 TEST_F(TabContentsTest, CrossSiteUnloadHandlers) { |
533 contents()->transition_cross_site = true; | 510 contents()->transition_cross_site = true; |
534 TestRenderViewHost* orig_rvh = rvh(); | 511 TestRenderViewHost* orig_rvh = rvh(); |
535 SiteInstance* instance1 = contents()->GetSiteInstance(); | 512 SiteInstance* instance1 = contents()->GetSiteInstance(); |
536 | 513 |
537 // Navigate to URL. First URL should use first RenderViewHost. | 514 // Navigate to URL. First URL should use first RenderViewHost. |
538 const GURL url("http://www.google.com"); | 515 const GURL url("http://www.google.com"); |
539 controller().LoadURL( | 516 controller().LoadURL( |
540 url, content::Referrer(), content::PAGE_TRANSITION_TYPED, std::string()); | 517 url, content::Referrer(), content::PAGE_TRANSITION_TYPED, std::string()); |
541 ViewHostMsg_FrameNavigate_Params params1; | 518 contents()->TestDidNavigate(orig_rvh, 1, url, content::PAGE_TRANSITION_TYPED); |
542 InitNavigateParams(¶ms1, 1, url, content::PAGE_TRANSITION_TYPED); | |
543 contents()->TestDidNavigate(orig_rvh, params1); | |
544 EXPECT_FALSE(contents()->cross_navigation_pending()); | 519 EXPECT_FALSE(contents()->cross_navigation_pending()); |
545 EXPECT_EQ(orig_rvh, contents()->render_view_host()); | 520 EXPECT_EQ(orig_rvh, contents()->render_view_host()); |
546 | 521 |
547 // Navigate to new site, but simulate an onbeforeunload denial. | 522 // Navigate to new site, but simulate an onbeforeunload denial. |
548 const GURL url2("http://www.yahoo.com"); | 523 const GURL url2("http://www.yahoo.com"); |
549 controller().LoadURL( | 524 controller().LoadURL( |
550 url2, content::Referrer(), content::PAGE_TRANSITION_TYPED, std::string()); | 525 url2, content::Referrer(), content::PAGE_TRANSITION_TYPED, std::string()); |
551 EXPECT_TRUE(orig_rvh->is_waiting_for_beforeunload_ack()); | 526 EXPECT_TRUE(orig_rvh->is_waiting_for_beforeunload_ack()); |
552 orig_rvh->TestOnMessageReceived(ViewHostMsg_ShouldClose_ACK(0, false)); | 527 orig_rvh->TestOnMessageReceived(ViewHostMsg_ShouldClose_ACK(0, false)); |
553 EXPECT_FALSE(orig_rvh->is_waiting_for_beforeunload_ack()); | 528 EXPECT_FALSE(orig_rvh->is_waiting_for_beforeunload_ack()); |
554 EXPECT_FALSE(contents()->cross_navigation_pending()); | 529 EXPECT_FALSE(contents()->cross_navigation_pending()); |
555 EXPECT_EQ(orig_rvh, contents()->render_view_host()); | 530 EXPECT_EQ(orig_rvh, contents()->render_view_host()); |
556 | 531 |
557 // Navigate again, but simulate an onbeforeunload approval. | 532 // Navigate again, but simulate an onbeforeunload approval. |
558 controller().LoadURL( | 533 controller().LoadURL( |
559 url2, content::Referrer(), content::PAGE_TRANSITION_TYPED, std::string()); | 534 url2, content::Referrer(), content::PAGE_TRANSITION_TYPED, std::string()); |
560 EXPECT_TRUE(orig_rvh->is_waiting_for_beforeunload_ack()); | 535 EXPECT_TRUE(orig_rvh->is_waiting_for_beforeunload_ack()); |
561 orig_rvh->TestOnMessageReceived(ViewHostMsg_ShouldClose_ACK(0, true)); | 536 orig_rvh->TestOnMessageReceived(ViewHostMsg_ShouldClose_ACK(0, true)); |
562 EXPECT_FALSE(orig_rvh->is_waiting_for_beforeunload_ack()); | 537 EXPECT_FALSE(orig_rvh->is_waiting_for_beforeunload_ack()); |
563 EXPECT_TRUE(contents()->cross_navigation_pending()); | 538 EXPECT_TRUE(contents()->cross_navigation_pending()); |
564 TestRenderViewHost* pending_rvh = static_cast<TestRenderViewHost*>( | 539 TestRenderViewHost* pending_rvh = static_cast<TestRenderViewHost*>( |
565 contents()->pending_rvh()); | 540 contents()->pending_rvh()); |
566 | 541 |
567 // We won't hear DidNavigate until the onunload handler has finished running. | 542 // We won't hear DidNavigate until the onunload handler has finished running. |
568 // (No way to simulate that here, but it involves a call from RDH to | 543 // (No way to simulate that here, but it involves a call from RDH to |
569 // TabContents::OnCrossSiteResponse.) | 544 // TabContents::OnCrossSiteResponse.) |
570 | 545 |
571 // DidNavigate from the pending page | 546 // DidNavigate from the pending page |
572 ViewHostMsg_FrameNavigate_Params params2; | 547 contents()->TestDidNavigate( |
573 InitNavigateParams(¶ms2, 1, url2, content::PAGE_TRANSITION_TYPED); | 548 pending_rvh, 1, url2, content::PAGE_TRANSITION_TYPED); |
574 contents()->TestDidNavigate(pending_rvh, params2); | |
575 SiteInstance* instance2 = contents()->GetSiteInstance(); | 549 SiteInstance* instance2 = contents()->GetSiteInstance(); |
576 EXPECT_FALSE(contents()->cross_navigation_pending()); | 550 EXPECT_FALSE(contents()->cross_navigation_pending()); |
577 EXPECT_EQ(pending_rvh, rvh()); | 551 EXPECT_EQ(pending_rvh, rvh()); |
578 EXPECT_NE(instance1, instance2); | 552 EXPECT_NE(instance1, instance2); |
579 EXPECT_TRUE(contents()->pending_rvh() == NULL); | 553 EXPECT_TRUE(contents()->pending_rvh() == NULL); |
580 } | 554 } |
581 | 555 |
582 // Test that during a slow cross-site navigation, the original renderer can | 556 // Test that during a slow cross-site navigation, the original renderer can |
583 // navigate to a different URL and have it displayed, canceling the slow | 557 // navigate to a different URL and have it displayed, canceling the slow |
584 // navigation. | 558 // navigation. |
585 TEST_F(TabContentsTest, CrossSiteNavigationPreempted) { | 559 TEST_F(TabContentsTest, CrossSiteNavigationPreempted) { |
586 contents()->transition_cross_site = true; | 560 contents()->transition_cross_site = true; |
587 TestRenderViewHost* orig_rvh = rvh(); | 561 TestRenderViewHost* orig_rvh = rvh(); |
588 SiteInstance* instance1 = contents()->GetSiteInstance(); | 562 SiteInstance* instance1 = contents()->GetSiteInstance(); |
589 | 563 |
590 // Navigate to URL. First URL should use first RenderViewHost. | 564 // Navigate to URL. First URL should use first RenderViewHost. |
591 const GURL url("http://www.google.com"); | 565 const GURL url("http://www.google.com"); |
592 controller().LoadURL( | 566 controller().LoadURL( |
593 url, content::Referrer(), content::PAGE_TRANSITION_TYPED, std::string()); | 567 url, content::Referrer(), content::PAGE_TRANSITION_TYPED, std::string()); |
594 ViewHostMsg_FrameNavigate_Params params1; | 568 contents()->TestDidNavigate(orig_rvh, 1, url, content::PAGE_TRANSITION_TYPED); |
595 InitNavigateParams(¶ms1, 1, url, content::PAGE_TRANSITION_TYPED); | |
596 contents()->TestDidNavigate(orig_rvh, params1); | |
597 EXPECT_FALSE(contents()->cross_navigation_pending()); | 569 EXPECT_FALSE(contents()->cross_navigation_pending()); |
598 EXPECT_EQ(orig_rvh, contents()->render_view_host()); | 570 EXPECT_EQ(orig_rvh, contents()->render_view_host()); |
599 | 571 |
600 // Navigate to new site, simulating an onbeforeunload approval. | 572 // Navigate to new site, simulating an onbeforeunload approval. |
601 const GURL url2("http://www.yahoo.com"); | 573 const GURL url2("http://www.yahoo.com"); |
602 controller().LoadURL( | 574 controller().LoadURL( |
603 url2, content::Referrer(), content::PAGE_TRANSITION_TYPED, std::string()); | 575 url2, content::Referrer(), content::PAGE_TRANSITION_TYPED, std::string()); |
604 EXPECT_TRUE(orig_rvh->is_waiting_for_beforeunload_ack()); | 576 EXPECT_TRUE(orig_rvh->is_waiting_for_beforeunload_ack()); |
605 orig_rvh->TestOnMessageReceived(ViewHostMsg_ShouldClose_ACK(0, true)); | 577 orig_rvh->TestOnMessageReceived(ViewHostMsg_ShouldClose_ACK(0, true)); |
606 EXPECT_TRUE(contents()->cross_navigation_pending()); | 578 EXPECT_TRUE(contents()->cross_navigation_pending()); |
(...skipping 11 matching lines...) Expand all Loading... |
618 } | 590 } |
619 | 591 |
620 TEST_F(TabContentsTest, CrossSiteNavigationBackPreempted) { | 592 TEST_F(TabContentsTest, CrossSiteNavigationBackPreempted) { |
621 contents()->transition_cross_site = true; | 593 contents()->transition_cross_site = true; |
622 | 594 |
623 // Start with NTP, which gets a new RVH with WebUI bindings. | 595 // Start with NTP, which gets a new RVH with WebUI bindings. |
624 const GURL url1("chrome://newtab"); | 596 const GURL url1("chrome://newtab"); |
625 controller().LoadURL( | 597 controller().LoadURL( |
626 url1, content::Referrer(), content::PAGE_TRANSITION_TYPED, std::string()); | 598 url1, content::Referrer(), content::PAGE_TRANSITION_TYPED, std::string()); |
627 TestRenderViewHost* ntp_rvh = rvh(); | 599 TestRenderViewHost* ntp_rvh = rvh(); |
628 ViewHostMsg_FrameNavigate_Params params1; | 600 contents()->TestDidNavigate(ntp_rvh, 1, url1, content::PAGE_TRANSITION_TYPED); |
629 InitNavigateParams(¶ms1, 1, url1, content::PAGE_TRANSITION_TYPED); | |
630 contents()->TestDidNavigate(ntp_rvh, params1); | |
631 NavigationEntry* entry1 = controller().GetLastCommittedEntry(); | 601 NavigationEntry* entry1 = controller().GetLastCommittedEntry(); |
632 SiteInstance* instance1 = contents()->GetSiteInstance(); | 602 SiteInstance* instance1 = contents()->GetSiteInstance(); |
633 | 603 |
634 EXPECT_FALSE(contents()->cross_navigation_pending()); | 604 EXPECT_FALSE(contents()->cross_navigation_pending()); |
635 EXPECT_EQ(ntp_rvh, contents()->render_view_host()); | 605 EXPECT_EQ(ntp_rvh, contents()->render_view_host()); |
636 EXPECT_EQ(url1, entry1->url()); | 606 EXPECT_EQ(url1, entry1->url()); |
637 EXPECT_EQ(instance1, entry1->site_instance()); | 607 EXPECT_EQ(instance1, entry1->site_instance()); |
638 EXPECT_TRUE(ntp_rvh->enabled_bindings() & content::BINDINGS_POLICY_WEB_UI); | 608 EXPECT_TRUE(ntp_rvh->enabled_bindings() & content::BINDINGS_POLICY_WEB_UI); |
639 | 609 |
640 // Navigate to new site. | 610 // Navigate to new site. |
641 const GURL url2("http://www.google.com"); | 611 const GURL url2("http://www.google.com"); |
642 controller().LoadURL( | 612 controller().LoadURL( |
643 url2, content::Referrer(), content::PAGE_TRANSITION_TYPED, std::string()); | 613 url2, content::Referrer(), content::PAGE_TRANSITION_TYPED, std::string()); |
644 EXPECT_TRUE(contents()->cross_navigation_pending()); | 614 EXPECT_TRUE(contents()->cross_navigation_pending()); |
645 TestRenderViewHost* google_rvh = contents()->pending_rvh(); | 615 TestRenderViewHost* google_rvh = contents()->pending_rvh(); |
646 | 616 |
647 // Simulate beforeunload approval. | 617 // Simulate beforeunload approval. |
648 EXPECT_TRUE(ntp_rvh->is_waiting_for_beforeunload_ack()); | 618 EXPECT_TRUE(ntp_rvh->is_waiting_for_beforeunload_ack()); |
649 ntp_rvh->TestOnMessageReceived(ViewHostMsg_ShouldClose_ACK(0, true)); | 619 ntp_rvh->TestOnMessageReceived(ViewHostMsg_ShouldClose_ACK(0, true)); |
650 | 620 |
651 // DidNavigate from the pending page. | 621 // DidNavigate from the pending page. |
652 ViewHostMsg_FrameNavigate_Params params2; | 622 contents()->TestDidNavigate( |
653 InitNavigateParams(¶ms2, 1, url2, content::PAGE_TRANSITION_TYPED); | 623 google_rvh, 1, url2, content::PAGE_TRANSITION_TYPED); |
654 contents()->TestDidNavigate(google_rvh, params2); | |
655 NavigationEntry* entry2 = controller().GetLastCommittedEntry(); | 624 NavigationEntry* entry2 = controller().GetLastCommittedEntry(); |
656 SiteInstance* instance2 = contents()->GetSiteInstance(); | 625 SiteInstance* instance2 = contents()->GetSiteInstance(); |
657 | 626 |
658 EXPECT_FALSE(contents()->cross_navigation_pending()); | 627 EXPECT_FALSE(contents()->cross_navigation_pending()); |
659 EXPECT_EQ(google_rvh, contents()->render_view_host()); | 628 EXPECT_EQ(google_rvh, contents()->render_view_host()); |
660 EXPECT_NE(instance1, instance2); | 629 EXPECT_NE(instance1, instance2); |
661 EXPECT_FALSE(contents()->pending_rvh()); | 630 EXPECT_FALSE(contents()->pending_rvh()); |
662 EXPECT_EQ(url2, entry2->url()); | 631 EXPECT_EQ(url2, entry2->url()); |
663 EXPECT_EQ(instance2, entry2->site_instance()); | 632 EXPECT_EQ(instance2, entry2->site_instance()); |
664 EXPECT_FALSE(google_rvh->enabled_bindings() & | 633 EXPECT_FALSE(google_rvh->enabled_bindings() & |
665 content::BINDINGS_POLICY_WEB_UI); | 634 content::BINDINGS_POLICY_WEB_UI); |
666 | 635 |
667 // Navigate to third page on same site. | 636 // Navigate to third page on same site. |
668 const GURL url3("http://news.google.com"); | 637 const GURL url3("http://news.google.com"); |
669 controller().LoadURL( | 638 controller().LoadURL( |
670 url3, content::Referrer(), content::PAGE_TRANSITION_TYPED, std::string()); | 639 url3, content::Referrer(), content::PAGE_TRANSITION_TYPED, std::string()); |
671 EXPECT_FALSE(contents()->cross_navigation_pending()); | 640 EXPECT_FALSE(contents()->cross_navigation_pending()); |
672 ViewHostMsg_FrameNavigate_Params params3; | 641 contents()->TestDidNavigate( |
673 InitNavigateParams(¶ms3, 2, url3, content::PAGE_TRANSITION_TYPED); | 642 google_rvh, 2, url3, content::PAGE_TRANSITION_TYPED); |
674 contents()->TestDidNavigate(google_rvh, params3); | |
675 NavigationEntry* entry3 = controller().GetLastCommittedEntry(); | 643 NavigationEntry* entry3 = controller().GetLastCommittedEntry(); |
676 SiteInstance* instance3 = contents()->GetSiteInstance(); | 644 SiteInstance* instance3 = contents()->GetSiteInstance(); |
677 | 645 |
678 EXPECT_FALSE(contents()->cross_navigation_pending()); | 646 EXPECT_FALSE(contents()->cross_navigation_pending()); |
679 EXPECT_EQ(google_rvh, contents()->render_view_host()); | 647 EXPECT_EQ(google_rvh, contents()->render_view_host()); |
680 EXPECT_EQ(instance2, instance3); | 648 EXPECT_EQ(instance2, instance3); |
681 EXPECT_FALSE(contents()->pending_rvh()); | 649 EXPECT_FALSE(contents()->pending_rvh()); |
682 EXPECT_EQ(url3, entry3->url()); | 650 EXPECT_EQ(url3, entry3->url()); |
683 EXPECT_EQ(instance3, entry3->site_instance()); | 651 EXPECT_EQ(instance3, entry3->site_instance()); |
684 | 652 |
685 // Go back within the site. | 653 // Go back within the site. |
686 controller().GoBack(); | 654 controller().GoBack(); |
687 EXPECT_FALSE(contents()->cross_navigation_pending()); | 655 EXPECT_FALSE(contents()->cross_navigation_pending()); |
688 EXPECT_EQ(entry2, controller().pending_entry()); | 656 EXPECT_EQ(entry2, controller().pending_entry()); |
689 | 657 |
690 // Before that commits, go back again. | 658 // Before that commits, go back again. |
691 controller().GoBack(); | 659 controller().GoBack(); |
692 EXPECT_TRUE(contents()->cross_navigation_pending()); | 660 EXPECT_TRUE(contents()->cross_navigation_pending()); |
693 EXPECT_TRUE(contents()->pending_rvh()); | 661 EXPECT_TRUE(contents()->pending_rvh()); |
694 EXPECT_EQ(entry1, controller().pending_entry()); | 662 EXPECT_EQ(entry1, controller().pending_entry()); |
695 | 663 |
696 // Simulate beforeunload approval. | 664 // Simulate beforeunload approval. |
697 EXPECT_TRUE(google_rvh->is_waiting_for_beforeunload_ack()); | 665 EXPECT_TRUE(google_rvh->is_waiting_for_beforeunload_ack()); |
698 google_rvh->TestOnMessageReceived(ViewHostMsg_ShouldClose_ACK(0, true)); | 666 google_rvh->TestOnMessageReceived(ViewHostMsg_ShouldClose_ACK(0, true)); |
699 | 667 |
700 // DidNavigate from the first back. This aborts the second back's pending RVH. | 668 // DidNavigate from the first back. This aborts the second back's pending RVH. |
701 contents()->TestDidNavigate(google_rvh, params2); | 669 contents()->TestDidNavigate( |
| 670 google_rvh, 1, url2, content::PAGE_TRANSITION_TYPED); |
702 | 671 |
703 // We should commit this page and forget about the second back. | 672 // We should commit this page and forget about the second back. |
704 EXPECT_FALSE(contents()->cross_navigation_pending()); | 673 EXPECT_FALSE(contents()->cross_navigation_pending()); |
705 EXPECT_FALSE(controller().pending_entry()); | 674 EXPECT_FALSE(controller().pending_entry()); |
706 EXPECT_EQ(google_rvh, contents()->render_view_host()); | 675 EXPECT_EQ(google_rvh, contents()->render_view_host()); |
707 EXPECT_EQ(url2, controller().GetLastCommittedEntry()->url()); | 676 EXPECT_EQ(url2, controller().GetLastCommittedEntry()->url()); |
708 | 677 |
709 // We should not have corrupted the NTP entry. | 678 // We should not have corrupted the NTP entry. |
710 EXPECT_EQ(instance3, entry3->site_instance()); | 679 EXPECT_EQ(instance3, entry3->site_instance()); |
711 EXPECT_EQ(instance2, entry2->site_instance()); | 680 EXPECT_EQ(instance2, entry2->site_instance()); |
712 EXPECT_EQ(instance1, entry1->site_instance()); | 681 EXPECT_EQ(instance1, entry1->site_instance()); |
713 EXPECT_EQ(url1, entry1->url()); | 682 EXPECT_EQ(url1, entry1->url()); |
714 } | 683 } |
715 | 684 |
716 // Test that during a slow cross-site navigation, a sub-frame navigation in the | 685 // Test that during a slow cross-site navigation, a sub-frame navigation in the |
717 // original renderer will not cancel the slow navigation (bug 42029). | 686 // original renderer will not cancel the slow navigation (bug 42029). |
718 TEST_F(TabContentsTest, CrossSiteNavigationNotPreemptedByFrame) { | 687 TEST_F(TabContentsTest, CrossSiteNavigationNotPreemptedByFrame) { |
719 contents()->transition_cross_site = true; | 688 contents()->transition_cross_site = true; |
720 TestRenderViewHost* orig_rvh = rvh(); | 689 TestRenderViewHost* orig_rvh = rvh(); |
721 | 690 |
722 // Navigate to URL. First URL should use first RenderViewHost. | 691 // Navigate to URL. First URL should use first RenderViewHost. |
723 const GURL url("http://www.google.com"); | 692 const GURL url("http://www.google.com"); |
724 controller().LoadURL( | 693 controller().LoadURL( |
725 url, content::Referrer(), content::PAGE_TRANSITION_TYPED, std::string()); | 694 url, content::Referrer(), content::PAGE_TRANSITION_TYPED, std::string()); |
726 ViewHostMsg_FrameNavigate_Params params1; | 695 contents()->TestDidNavigate(orig_rvh, 1, url, content::PAGE_TRANSITION_TYPED); |
727 InitNavigateParams(¶ms1, 1, url, content::PAGE_TRANSITION_TYPED); | |
728 contents()->TestDidNavigate(orig_rvh, params1); | |
729 EXPECT_FALSE(contents()->cross_navigation_pending()); | 696 EXPECT_FALSE(contents()->cross_navigation_pending()); |
730 EXPECT_EQ(orig_rvh, contents()->render_view_host()); | 697 EXPECT_EQ(orig_rvh, contents()->render_view_host()); |
731 | 698 |
732 // Start navigating to new site. | 699 // Start navigating to new site. |
733 const GURL url2("http://www.yahoo.com"); | 700 const GURL url2("http://www.yahoo.com"); |
734 controller().LoadURL( | 701 controller().LoadURL( |
735 url2, content::Referrer(), content::PAGE_TRANSITION_TYPED, std::string()); | 702 url2, content::Referrer(), content::PAGE_TRANSITION_TYPED, std::string()); |
736 | 703 |
737 // Simulate a sub-frame navigation arriving and ensure the RVH is still | 704 // Simulate a sub-frame navigation arriving and ensure the RVH is still |
738 // waiting for a before unload response. | 705 // waiting for a before unload response. |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
771 | 738 |
772 // Suppose the first navigation tries to commit now, with a | 739 // Suppose the first navigation tries to commit now, with a |
773 // ViewMsg_Stop in flight. This should not cancel the pending navigation, | 740 // ViewMsg_Stop in flight. This should not cancel the pending navigation, |
774 // but it should act as if the beforeunload ack arrived. | 741 // but it should act as if the beforeunload ack arrived. |
775 orig_rvh->SendNavigate(1, GURL("chrome://newtab")); | 742 orig_rvh->SendNavigate(1, GURL("chrome://newtab")); |
776 EXPECT_TRUE(contents()->cross_navigation_pending()); | 743 EXPECT_TRUE(contents()->cross_navigation_pending()); |
777 EXPECT_EQ(orig_rvh, contents()->render_view_host()); | 744 EXPECT_EQ(orig_rvh, contents()->render_view_host()); |
778 EXPECT_FALSE(orig_rvh->is_waiting_for_beforeunload_ack()); | 745 EXPECT_FALSE(orig_rvh->is_waiting_for_beforeunload_ack()); |
779 | 746 |
780 // The pending navigation should be able to commit successfully. | 747 // The pending navigation should be able to commit successfully. |
781 ViewHostMsg_FrameNavigate_Params params2; | 748 contents()->TestDidNavigate( |
782 InitNavigateParams(¶ms2, 1, url2, content::PAGE_TRANSITION_TYPED); | 749 pending_rvh, 1, url2, content::PAGE_TRANSITION_TYPED); |
783 contents()->TestDidNavigate(pending_rvh, params2); | |
784 EXPECT_FALSE(contents()->cross_navigation_pending()); | 750 EXPECT_FALSE(contents()->cross_navigation_pending()); |
785 EXPECT_EQ(pending_rvh, contents()->render_view_host()); | 751 EXPECT_EQ(pending_rvh, contents()->render_view_host()); |
786 } | 752 } |
787 | 753 |
788 // Test that the original renderer cannot preempt a cross-site navigation once | 754 // Test that the original renderer cannot preempt a cross-site navigation once |
789 // the unload request has been made. At this point, the cross-site navigation | 755 // the unload request has been made. At this point, the cross-site navigation |
790 // is almost ready to be displayed, and the original renderer is only given a | 756 // is almost ready to be displayed, and the original renderer is only given a |
791 // short chance to run an unload handler. Prevents regression of bug 23942. | 757 // short chance to run an unload handler. Prevents regression of bug 23942. |
792 TEST_F(TabContentsTest, CrossSiteCantPreemptAfterUnload) { | 758 TEST_F(TabContentsTest, CrossSiteCantPreemptAfterUnload) { |
793 contents()->transition_cross_site = true; | 759 contents()->transition_cross_site = true; |
794 TestRenderViewHost* orig_rvh = rvh(); | 760 TestRenderViewHost* orig_rvh = rvh(); |
795 SiteInstance* instance1 = contents()->GetSiteInstance(); | 761 SiteInstance* instance1 = contents()->GetSiteInstance(); |
796 | 762 |
797 // Navigate to URL. First URL should use first RenderViewHost. | 763 // Navigate to URL. First URL should use first RenderViewHost. |
798 const GURL url("http://www.google.com"); | 764 const GURL url("http://www.google.com"); |
799 controller().LoadURL( | 765 controller().LoadURL( |
800 url, content::Referrer(), content::PAGE_TRANSITION_TYPED, std::string()); | 766 url, content::Referrer(), content::PAGE_TRANSITION_TYPED, std::string()); |
801 ViewHostMsg_FrameNavigate_Params params1; | 767 contents()->TestDidNavigate(orig_rvh, 1, url, content::PAGE_TRANSITION_TYPED); |
802 InitNavigateParams(¶ms1, 1, url, content::PAGE_TRANSITION_TYPED); | |
803 contents()->TestDidNavigate(orig_rvh, params1); | |
804 EXPECT_FALSE(contents()->cross_navigation_pending()); | 768 EXPECT_FALSE(contents()->cross_navigation_pending()); |
805 EXPECT_EQ(orig_rvh, contents()->render_view_host()); | 769 EXPECT_EQ(orig_rvh, contents()->render_view_host()); |
806 | 770 |
807 // Navigate to new site, simulating an onbeforeunload approval. | 771 // Navigate to new site, simulating an onbeforeunload approval. |
808 const GURL url2("http://www.yahoo.com"); | 772 const GURL url2("http://www.yahoo.com"); |
809 controller().LoadURL( | 773 controller().LoadURL( |
810 url2, content::Referrer(), content::PAGE_TRANSITION_TYPED, std::string()); | 774 url2, content::Referrer(), content::PAGE_TRANSITION_TYPED, std::string()); |
811 orig_rvh->TestOnMessageReceived(ViewHostMsg_ShouldClose_ACK(0, true)); | 775 orig_rvh->TestOnMessageReceived(ViewHostMsg_ShouldClose_ACK(0, true)); |
812 EXPECT_TRUE(contents()->cross_navigation_pending()); | 776 EXPECT_TRUE(contents()->cross_navigation_pending()); |
813 TestRenderViewHost* pending_rvh = static_cast<TestRenderViewHost*>( | 777 TestRenderViewHost* pending_rvh = static_cast<TestRenderViewHost*>( |
(...skipping 10 matching lines...) Expand all Loading... |
824 ViewHostMsg_FrameNavigate_Params params1a; | 788 ViewHostMsg_FrameNavigate_Params params1a; |
825 InitNavigateParams(¶ms1a, 2, GURL("http://www.google.com/foo"), | 789 InitNavigateParams(¶ms1a, 2, GURL("http://www.google.com/foo"), |
826 content::PAGE_TRANSITION_TYPED); | 790 content::PAGE_TRANSITION_TYPED); |
827 orig_rvh->SendNavigate(2, GURL("http://www.google.com/foo")); | 791 orig_rvh->SendNavigate(2, GURL("http://www.google.com/foo")); |
828 | 792 |
829 // Verify that the pending navigation is still in progress. | 793 // Verify that the pending navigation is still in progress. |
830 EXPECT_TRUE(contents()->cross_navigation_pending()); | 794 EXPECT_TRUE(contents()->cross_navigation_pending()); |
831 EXPECT_TRUE(contents()->pending_rvh() != NULL); | 795 EXPECT_TRUE(contents()->pending_rvh() != NULL); |
832 | 796 |
833 // DidNavigate from the pending page should commit it. | 797 // DidNavigate from the pending page should commit it. |
834 ViewHostMsg_FrameNavigate_Params params2; | 798 contents()->TestDidNavigate( |
835 InitNavigateParams(¶ms2, 1, url2, content::PAGE_TRANSITION_TYPED); | 799 pending_rvh, 1, url2, content::PAGE_TRANSITION_TYPED); |
836 contents()->TestDidNavigate(pending_rvh, params2); | |
837 SiteInstance* instance2 = contents()->GetSiteInstance(); | 800 SiteInstance* instance2 = contents()->GetSiteInstance(); |
838 EXPECT_FALSE(contents()->cross_navigation_pending()); | 801 EXPECT_FALSE(contents()->cross_navigation_pending()); |
839 EXPECT_EQ(pending_rvh, rvh()); | 802 EXPECT_EQ(pending_rvh, rvh()); |
840 EXPECT_NE(instance1, instance2); | 803 EXPECT_NE(instance1, instance2); |
841 EXPECT_TRUE(contents()->pending_rvh() == NULL); | 804 EXPECT_TRUE(contents()->pending_rvh() == NULL); |
842 } | 805 } |
843 | 806 |
844 // Test that a cross-site navigation that doesn't commit after the unload | 807 // Test that a cross-site navigation that doesn't commit after the unload |
845 // handler doesn't leave the tab in a stuck state. http://crbug.com/88562. | 808 // handler doesn't leave the tab in a stuck state. http://crbug.com/88562. |
846 TEST_F(TabContentsTest, CrossSiteNavigationCanceled) { | 809 TEST_F(TabContentsTest, CrossSiteNavigationCanceled) { |
847 contents()->transition_cross_site = true; | 810 contents()->transition_cross_site = true; |
848 TestRenderViewHost* orig_rvh = rvh(); | 811 TestRenderViewHost* orig_rvh = rvh(); |
849 SiteInstance* instance1 = contents()->GetSiteInstance(); | 812 SiteInstance* instance1 = contents()->GetSiteInstance(); |
850 | 813 |
851 // Navigate to URL. First URL should use first RenderViewHost. | 814 // Navigate to URL. First URL should use first RenderViewHost. |
852 const GURL url("http://www.google.com"); | 815 const GURL url("http://www.google.com"); |
853 controller().LoadURL( | 816 controller().LoadURL( |
854 url, content::Referrer(), content::PAGE_TRANSITION_TYPED, std::string()); | 817 url, content::Referrer(), content::PAGE_TRANSITION_TYPED, std::string()); |
855 ViewHostMsg_FrameNavigate_Params params1; | 818 contents()->TestDidNavigate(orig_rvh, 1, url, content::PAGE_TRANSITION_TYPED); |
856 InitNavigateParams(¶ms1, 1, url, content::PAGE_TRANSITION_TYPED); | |
857 contents()->TestDidNavigate(orig_rvh, params1); | |
858 EXPECT_FALSE(contents()->cross_navigation_pending()); | 819 EXPECT_FALSE(contents()->cross_navigation_pending()); |
859 EXPECT_EQ(orig_rvh, contents()->render_view_host()); | 820 EXPECT_EQ(orig_rvh, contents()->render_view_host()); |
860 | 821 |
861 // Navigate to new site, simulating an onbeforeunload approval. | 822 // Navigate to new site, simulating an onbeforeunload approval. |
862 const GURL url2("http://www.yahoo.com"); | 823 const GURL url2("http://www.yahoo.com"); |
863 controller().LoadURL( | 824 controller().LoadURL( |
864 url2, content::Referrer(), content::PAGE_TRANSITION_TYPED, std::string()); | 825 url2, content::Referrer(), content::PAGE_TRANSITION_TYPED, std::string()); |
865 EXPECT_TRUE(orig_rvh->is_waiting_for_beforeunload_ack()); | 826 EXPECT_TRUE(orig_rvh->is_waiting_for_beforeunload_ack()); |
866 orig_rvh->TestOnMessageReceived(ViewHostMsg_ShouldClose_ACK(0, true)); | 827 orig_rvh->TestOnMessageReceived(ViewHostMsg_ShouldClose_ACK(0, true)); |
867 EXPECT_TRUE(contents()->cross_navigation_pending()); | 828 EXPECT_TRUE(contents()->cross_navigation_pending()); |
(...skipping 23 matching lines...) Expand all Loading... |
891 TestRenderViewHost* orig_rvh = rvh(); | 852 TestRenderViewHost* orig_rvh = rvh(); |
892 | 853 |
893 // Navigate to URL. There should be no committed entry yet. | 854 // Navigate to URL. There should be no committed entry yet. |
894 const GURL url("http://www.google.com"); | 855 const GURL url("http://www.google.com"); |
895 controller().LoadURL( | 856 controller().LoadURL( |
896 url, content::Referrer(), content::PAGE_TRANSITION_TYPED, std::string()); | 857 url, content::Referrer(), content::PAGE_TRANSITION_TYPED, std::string()); |
897 NavigationEntry* entry = controller().GetLastCommittedEntry(); | 858 NavigationEntry* entry = controller().GetLastCommittedEntry(); |
898 EXPECT_TRUE(entry == NULL); | 859 EXPECT_TRUE(entry == NULL); |
899 | 860 |
900 // Committed entry should have content state after DidNavigate. | 861 // Committed entry should have content state after DidNavigate. |
901 ViewHostMsg_FrameNavigate_Params params1; | 862 contents()->TestDidNavigate(orig_rvh, 1, url, content::PAGE_TRANSITION_TYPED); |
902 InitNavigateParams(¶ms1, 1, url, content::PAGE_TRANSITION_TYPED); | |
903 contents()->TestDidNavigate(orig_rvh, params1); | |
904 entry = controller().GetLastCommittedEntry(); | 863 entry = controller().GetLastCommittedEntry(); |
905 EXPECT_FALSE(entry->content_state().empty()); | 864 EXPECT_FALSE(entry->content_state().empty()); |
906 | 865 |
907 // Navigate to same site. | 866 // Navigate to same site. |
908 const GURL url2("http://images.google.com"); | 867 const GURL url2("http://images.google.com"); |
909 controller().LoadURL( | 868 controller().LoadURL( |
910 url2, content::Referrer(), content::PAGE_TRANSITION_TYPED, std::string()); | 869 url2, content::Referrer(), content::PAGE_TRANSITION_TYPED, std::string()); |
911 entry = controller().GetLastCommittedEntry(); | 870 entry = controller().GetLastCommittedEntry(); |
912 EXPECT_FALSE(entry->content_state().empty()); | 871 EXPECT_FALSE(entry->content_state().empty()); |
913 | 872 |
914 // Committed entry should have content state after DidNavigate. | 873 // Committed entry should have content state after DidNavigate. |
915 ViewHostMsg_FrameNavigate_Params params2; | 874 contents()->TestDidNavigate( |
916 InitNavigateParams(¶ms2, 2, url2, content::PAGE_TRANSITION_TYPED); | 875 orig_rvh, 2, url2, content::PAGE_TRANSITION_TYPED); |
917 contents()->TestDidNavigate(orig_rvh, params2); | |
918 entry = controller().GetLastCommittedEntry(); | 876 entry = controller().GetLastCommittedEntry(); |
919 EXPECT_FALSE(entry->content_state().empty()); | 877 EXPECT_FALSE(entry->content_state().empty()); |
920 | 878 |
921 // Now go back. Committed entry should still have content state. | 879 // Now go back. Committed entry should still have content state. |
922 controller().GoBack(); | 880 controller().GoBack(); |
923 contents()->TestDidNavigate(orig_rvh, params1); | 881 contents()->TestDidNavigate(orig_rvh, 1, url, content::PAGE_TRANSITION_TYPED); |
924 entry = controller().GetLastCommittedEntry(); | 882 entry = controller().GetLastCommittedEntry(); |
925 EXPECT_FALSE(entry->content_state().empty()); | 883 EXPECT_FALSE(entry->content_state().empty()); |
926 } | 884 } |
927 | 885 |
928 // Test that NavigationEntries have the correct content state after opening | 886 // Test that NavigationEntries have the correct content state after opening |
929 // a new window to about:blank. Prevents regression for bug 1116137. | 887 // a new window to about:blank. Prevents regression for bug 1116137. |
930 TEST_F(TabContentsTest, NavigationEntryContentStateNewWindow) { | 888 TEST_F(TabContentsTest, NavigationEntryContentStateNewWindow) { |
931 TestRenderViewHost* orig_rvh = rvh(); | 889 TestRenderViewHost* orig_rvh = rvh(); |
932 | 890 |
933 // When opening a new window, it is navigated to about:blank internally. | 891 // When opening a new window, it is navigated to about:blank internally. |
934 // Currently, this results in two DidNavigate events. | 892 // Currently, this results in two DidNavigate events. |
935 const GURL url(chrome::kAboutBlankURL); | 893 const GURL url(chrome::kAboutBlankURL); |
936 ViewHostMsg_FrameNavigate_Params params1; | 894 contents()->TestDidNavigate(orig_rvh, 1, url, content::PAGE_TRANSITION_TYPED); |
937 InitNavigateParams(¶ms1, 1, url, content::PAGE_TRANSITION_TYPED); | 895 contents()->TestDidNavigate(orig_rvh, 1, url, content::PAGE_TRANSITION_TYPED); |
938 contents()->TestDidNavigate(orig_rvh, params1); | |
939 contents()->TestDidNavigate(orig_rvh, params1); | |
940 | 896 |
941 // Should have a content state here. | 897 // Should have a content state here. |
942 NavigationEntry* entry = controller().GetLastCommittedEntry(); | 898 NavigationEntry* entry = controller().GetLastCommittedEntry(); |
943 EXPECT_FALSE(entry->content_state().empty()); | 899 EXPECT_FALSE(entry->content_state().empty()); |
944 } | 900 } |
945 | 901 |
946 // Tests to see that webkit preferences are properly loaded and copied over | 902 // Tests to see that webkit preferences are properly loaded and copied over |
947 // to a WebPreferences object. | 903 // to a WebPreferences object. |
948 TEST_F(TabContentsTest, WebKitPrefs) { | 904 TEST_F(TabContentsTest, WebKitPrefs) { |
949 WebPreferences webkit_prefs = contents()->TestGetWebkitPrefs(); | 905 WebPreferences webkit_prefs = contents()->TestGetWebkitPrefs(); |
(...skipping 746 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1696 // showing. | 1652 // showing. |
1697 TEST_F(TabContentsTest, NoJSMessageOnInterstitials) { | 1653 TEST_F(TabContentsTest, NoJSMessageOnInterstitials) { |
1698 const char kUrl[] = "http://www.badguys.com/"; | 1654 const char kUrl[] = "http://www.badguys.com/"; |
1699 const GURL kGURL(kUrl); | 1655 const GURL kGURL(kUrl); |
1700 | 1656 |
1701 // Start a navigation to a page | 1657 // Start a navigation to a page |
1702 contents()->controller().LoadURL( | 1658 contents()->controller().LoadURL( |
1703 kGURL, content::Referrer(), content::PAGE_TRANSITION_TYPED, | 1659 kGURL, content::Referrer(), content::PAGE_TRANSITION_TYPED, |
1704 std::string()); | 1660 std::string()); |
1705 // DidNavigate from the page | 1661 // DidNavigate from the page |
1706 ViewHostMsg_FrameNavigate_Params params; | 1662 contents()->TestDidNavigate(rvh(), 1, kGURL, content::PAGE_TRANSITION_TYPED); |
1707 InitNavigateParams(¶ms, 1, kGURL, content::PAGE_TRANSITION_TYPED); | |
1708 contents()->TestDidNavigate(rvh(), params); | |
1709 | 1663 |
1710 // Simulate showing an interstitial while the page is showing. | 1664 // Simulate showing an interstitial while the page is showing. |
1711 TestInterstitialPage::InterstitialState state = | 1665 TestInterstitialPage::InterstitialState state = |
1712 TestInterstitialPage::UNDECIDED; | 1666 TestInterstitialPage::UNDECIDED; |
1713 bool deleted = false; | 1667 bool deleted = false; |
1714 TestInterstitialPage* interstitial = | 1668 TestInterstitialPage* interstitial = |
1715 new TestInterstitialPage(contents(), true, kGURL, &state, &deleted); | 1669 new TestInterstitialPage(contents(), true, kGURL, &state, &deleted); |
1716 TestInterstitialPageStateGuard state_guard(interstitial); | 1670 TestInterstitialPageStateGuard state_guard(interstitial); |
1717 interstitial->Show(); | 1671 interstitial->Show(); |
1718 interstitial->TestDidNavigate(1, kGURL); | 1672 interstitial->TestDidNavigate(1, kGURL); |
(...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1814 | 1768 |
1815 // It should have a transient entry. | 1769 // It should have a transient entry. |
1816 EXPECT_TRUE(other_controller.GetTransientEntry()); | 1770 EXPECT_TRUE(other_controller.GetTransientEntry()); |
1817 | 1771 |
1818 // And the interstitial should be showing. | 1772 // And the interstitial should be showing. |
1819 EXPECT_TRUE(other_contents->showing_interstitial_page()); | 1773 EXPECT_TRUE(other_contents->showing_interstitial_page()); |
1820 | 1774 |
1821 // And the interstitial should do a reload on don't proceed. | 1775 // And the interstitial should do a reload on don't proceed. |
1822 EXPECT_TRUE(other_contents->interstitial_page()->reload_on_dont_proceed()); | 1776 EXPECT_TRUE(other_contents->interstitial_page()->reload_on_dont_proceed()); |
1823 } | 1777 } |
OLD | NEW |