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