OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "base/logging.h" | 5 #include "base/logging.h" |
6 #include "base/utf_string_conversions.h" | 6 #include "base/utf_string_conversions.h" |
7 #include "chrome/browser/dom_operation_notification_details.h" | 7 #include "chrome/browser/dom_operation_notification_details.h" |
8 #include "chrome/browser/prefs/pref_service.h" | 8 #include "chrome/browser/prefs/pref_service.h" |
9 #include "chrome/browser/tab_contents/chrome_interstitial_page.h" | 9 #include "chrome/browser/tab_contents/chrome_interstitial_page.h" |
10 #include "chrome/common/chrome_notification_types.h" | 10 #include "chrome/common/chrome_notification_types.h" |
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
96 | 96 |
97 void TestDomOperationResponse(const std::string& json_string) { | 97 void TestDomOperationResponse(const std::string& json_string) { |
98 DomOperationNotificationDetails details(json_string, 1); | 98 DomOperationNotificationDetails details(json_string, 1); |
99 Observe(chrome::NOTIFICATION_DOM_OPERATION_RESPONSE, | 99 Observe(chrome::NOTIFICATION_DOM_OPERATION_RESPONSE, |
100 Source<RenderViewHost>(render_view_host()), | 100 Source<RenderViewHost>(render_view_host()), |
101 Details<DomOperationNotificationDetails>(&details)); | 101 Details<DomOperationNotificationDetails>(&details)); |
102 } | 102 } |
103 | 103 |
104 void TestDidNavigate(int page_id, const GURL& url) { | 104 void TestDidNavigate(int page_id, const GURL& url) { |
105 ViewHostMsg_FrameNavigate_Params params; | 105 ViewHostMsg_FrameNavigate_Params params; |
106 InitNavigateParams(¶ms, page_id, url, PageTransition::TYPED); | 106 InitNavigateParams(¶ms, page_id, url, content::PAGE_TRANSITION_TYPED); |
107 DidNavigate(render_view_host(), params); | 107 DidNavigate(render_view_host(), params); |
108 } | 108 } |
109 | 109 |
110 void TestRenderViewGone(base::TerminationStatus status, int error_code) { | 110 void TestRenderViewGone(base::TerminationStatus status, int error_code) { |
111 RenderViewGone(render_view_host(), status, error_code); | 111 RenderViewGone(render_view_host(), status, error_code); |
112 } | 112 } |
113 | 113 |
114 bool is_showing() const { | 114 bool is_showing() const { |
115 return static_cast<TestRenderWidgetHostView*>(render_view_host()->view())-> | 115 return static_cast<TestRenderWidgetHostView*>(render_view_host()->view())-> |
116 is_showing(); | 116 is_showing(); |
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
198 Value::CreateStringValue("bar")); | 198 Value::CreateStringValue("bar")); |
199 } | 199 } |
200 | 200 |
201 BrowserThread ui_thread_; | 201 BrowserThread ui_thread_; |
202 }; | 202 }; |
203 | 203 |
204 // Test to make sure that title updates get stripped of whitespace. | 204 // Test to make sure that title updates get stripped of whitespace. |
205 TEST_F(TabContentsTest, UpdateTitle) { | 205 TEST_F(TabContentsTest, UpdateTitle) { |
206 ViewHostMsg_FrameNavigate_Params params; | 206 ViewHostMsg_FrameNavigate_Params params; |
207 InitNavigateParams(¶ms, 0, GURL(chrome::kAboutBlankURL), | 207 InitNavigateParams(¶ms, 0, GURL(chrome::kAboutBlankURL), |
208 PageTransition::TYPED); | 208 content::PAGE_TRANSITION_TYPED); |
209 | 209 |
210 content::LoadCommittedDetails details; | 210 content::LoadCommittedDetails details; |
211 controller().RendererDidNavigate(params, &details); | 211 controller().RendererDidNavigate(params, &details); |
212 | 212 |
213 contents()->UpdateTitle(rvh(), 0, ASCIIToUTF16(" Lots O' Whitespace\n"), | 213 contents()->UpdateTitle(rvh(), 0, ASCIIToUTF16(" Lots O' Whitespace\n"), |
214 base::i18n::LEFT_TO_RIGHT); | 214 base::i18n::LEFT_TO_RIGHT); |
215 EXPECT_EQ(ASCIIToUTF16("Lots O' Whitespace"), contents()->GetTitle()); | 215 EXPECT_EQ(ASCIIToUTF16("Lots O' Whitespace"), contents()->GetTitle()); |
216 } | 216 } |
217 | 217 |
218 // Test view source mode for the new tabs page. | 218 // Test view source mode for the new tabs page. |
219 TEST_F(TabContentsTest, NTPViewSource) { | 219 TEST_F(TabContentsTest, NTPViewSource) { |
220 const char kUrl[] = "view-source:chrome://newtab"; | 220 const char kUrl[] = "view-source:chrome://newtab"; |
221 const GURL kGURL(kUrl); | 221 const GURL kGURL(kUrl); |
222 | 222 |
223 process()->sink().ClearMessages(); | 223 process()->sink().ClearMessages(); |
224 | 224 |
225 controller().LoadURL(kGURL, GURL(), PageTransition::TYPED, std::string()); | 225 controller().LoadURL( |
| 226 kGURL, GURL(), content::PAGE_TRANSITION_TYPED, std::string()); |
226 rvh()->delegate()->RenderViewCreated(rvh()); | 227 rvh()->delegate()->RenderViewCreated(rvh()); |
227 // Did we get the expected message? | 228 // Did we get the expected message? |
228 EXPECT_TRUE(process()->sink().GetFirstMessageMatching( | 229 EXPECT_TRUE(process()->sink().GetFirstMessageMatching( |
229 ViewMsg_EnableViewSourceMode::ID)); | 230 ViewMsg_EnableViewSourceMode::ID)); |
230 | 231 |
231 ViewHostMsg_FrameNavigate_Params params; | 232 ViewHostMsg_FrameNavigate_Params params; |
232 InitNavigateParams(¶ms, 0, kGURL, PageTransition::TYPED); | 233 InitNavigateParams(¶ms, 0, kGURL, content::PAGE_TRANSITION_TYPED); |
233 content::LoadCommittedDetails details; | 234 content::LoadCommittedDetails details; |
234 controller().RendererDidNavigate(params, &details); | 235 controller().RendererDidNavigate(params, &details); |
235 // Also check title and url. | 236 // Also check title and url. |
236 EXPECT_EQ(ASCIIToUTF16(kUrl), contents()->GetTitle()); | 237 EXPECT_EQ(ASCIIToUTF16(kUrl), contents()->GetTitle()); |
237 } | 238 } |
238 | 239 |
239 // Test simple same-SiteInstance navigation. | 240 // Test simple same-SiteInstance navigation. |
240 TEST_F(TabContentsTest, SimpleNavigation) { | 241 TEST_F(TabContentsTest, SimpleNavigation) { |
241 TestRenderViewHost* orig_rvh = rvh(); | 242 TestRenderViewHost* orig_rvh = rvh(); |
242 SiteInstance* instance1 = contents()->GetSiteInstance(); | 243 SiteInstance* instance1 = contents()->GetSiteInstance(); |
243 EXPECT_TRUE(contents()->pending_rvh() == NULL); | 244 EXPECT_TRUE(contents()->pending_rvh() == NULL); |
244 | 245 |
245 // Navigate to URL | 246 // Navigate to URL |
246 const GURL url("http://www.google.com"); | 247 const GURL url("http://www.google.com"); |
247 controller().LoadURL(url, GURL(), PageTransition::TYPED, std::string()); | 248 controller().LoadURL( |
| 249 url, GURL(), content::PAGE_TRANSITION_TYPED, std::string()); |
248 EXPECT_FALSE(contents()->cross_navigation_pending()); | 250 EXPECT_FALSE(contents()->cross_navigation_pending()); |
249 EXPECT_EQ(instance1, orig_rvh->site_instance()); | 251 EXPECT_EQ(instance1, orig_rvh->site_instance()); |
250 // Controller's pending entry will have a NULL site instance until we assign | 252 // Controller's pending entry will have a NULL site instance until we assign |
251 // it in DidNavigate. | 253 // it in DidNavigate. |
252 EXPECT_TRUE(controller().GetActiveEntry()->site_instance() == NULL); | 254 EXPECT_TRUE(controller().GetActiveEntry()->site_instance() == NULL); |
253 | 255 |
254 // DidNavigate from the page | 256 // DidNavigate from the page |
255 ViewHostMsg_FrameNavigate_Params params; | 257 ViewHostMsg_FrameNavigate_Params params; |
256 InitNavigateParams(¶ms, 1, url, PageTransition::TYPED); | 258 InitNavigateParams(¶ms, 1, url, content::PAGE_TRANSITION_TYPED); |
257 contents()->TestDidNavigate(orig_rvh, params); | 259 contents()->TestDidNavigate(orig_rvh, params); |
258 EXPECT_FALSE(contents()->cross_navigation_pending()); | 260 EXPECT_FALSE(contents()->cross_navigation_pending()); |
259 EXPECT_EQ(orig_rvh, contents()->render_view_host()); | 261 EXPECT_EQ(orig_rvh, contents()->render_view_host()); |
260 EXPECT_EQ(instance1, orig_rvh->site_instance()); | 262 EXPECT_EQ(instance1, orig_rvh->site_instance()); |
261 // Controller's entry should now have the SiteInstance, or else we won't be | 263 // Controller's entry should now have the SiteInstance, or else we won't be |
262 // able to find it later. | 264 // able to find it later. |
263 EXPECT_EQ(instance1, controller().GetActiveEntry()->site_instance()); | 265 EXPECT_EQ(instance1, controller().GetActiveEntry()->site_instance()); |
264 } | 266 } |
265 | 267 |
266 // Test that we reject NavigateToEntry if the url is over content::kMaxURLChars. | 268 // Test that we reject NavigateToEntry if the url is over content::kMaxURLChars. |
267 TEST_F(TabContentsTest, NavigateToExcessivelyLongURL) { | 269 TEST_F(TabContentsTest, NavigateToExcessivelyLongURL) { |
268 // Construct a URL that's kMaxURLChars + 1 long of all 'a's. | 270 // Construct a URL that's kMaxURLChars + 1 long of all 'a's. |
269 const GURL url(std::string("http://example.org/").append( | 271 const GURL url(std::string("http://example.org/").append( |
270 content::kMaxURLChars + 1, 'a')); | 272 content::kMaxURLChars + 1, 'a')); |
271 | 273 |
272 controller().LoadURL(url, GURL(), PageTransition::GENERATED, std::string()); | 274 controller().LoadURL( |
| 275 url, GURL(), content::PAGE_TRANSITION_GENERATED, std::string()); |
273 EXPECT_TRUE(controller().GetActiveEntry() == NULL); | 276 EXPECT_TRUE(controller().GetActiveEntry() == NULL); |
274 } | 277 } |
275 | 278 |
276 // Test that navigating across a site boundary creates a new RenderViewHost | 279 // Test that navigating across a site boundary creates a new RenderViewHost |
277 // with a new SiteInstance. Going back should do the same. | 280 // with a new SiteInstance. Going back should do the same. |
278 TEST_F(TabContentsTest, CrossSiteBoundaries) { | 281 TEST_F(TabContentsTest, CrossSiteBoundaries) { |
279 contents()->transition_cross_site = true; | 282 contents()->transition_cross_site = true; |
280 TestRenderViewHost* orig_rvh = rvh(); | 283 TestRenderViewHost* orig_rvh = rvh(); |
281 int orig_rvh_delete_count = 0; | 284 int orig_rvh_delete_count = 0; |
282 orig_rvh->set_delete_counter(&orig_rvh_delete_count); | 285 orig_rvh->set_delete_counter(&orig_rvh_delete_count); |
283 SiteInstance* instance1 = contents()->GetSiteInstance(); | 286 SiteInstance* instance1 = contents()->GetSiteInstance(); |
284 | 287 |
285 // Navigate to URL. First URL should use first RenderViewHost. | 288 // Navigate to URL. First URL should use first RenderViewHost. |
286 const GURL url("http://www.google.com"); | 289 const GURL url("http://www.google.com"); |
287 controller().LoadURL(url, GURL(), PageTransition::TYPED, std::string()); | 290 controller().LoadURL( |
| 291 url, GURL(), content::PAGE_TRANSITION_TYPED, std::string()); |
288 ViewHostMsg_FrameNavigate_Params params1; | 292 ViewHostMsg_FrameNavigate_Params params1; |
289 InitNavigateParams(¶ms1, 1, url, PageTransition::TYPED); | 293 InitNavigateParams(¶ms1, 1, url, content::PAGE_TRANSITION_TYPED); |
290 contents()->TestDidNavigate(orig_rvh, params1); | 294 contents()->TestDidNavigate(orig_rvh, params1); |
291 | 295 |
292 EXPECT_FALSE(contents()->cross_navigation_pending()); | 296 EXPECT_FALSE(contents()->cross_navigation_pending()); |
293 EXPECT_EQ(orig_rvh, contents()->render_view_host()); | 297 EXPECT_EQ(orig_rvh, contents()->render_view_host()); |
294 | 298 |
295 // Navigate to new site | 299 // Navigate to new site |
296 const GURL url2("http://www.yahoo.com"); | 300 const GURL url2("http://www.yahoo.com"); |
297 controller().LoadURL(url2, GURL(), PageTransition::TYPED, std::string()); | 301 controller().LoadURL( |
| 302 url2, GURL(), content::PAGE_TRANSITION_TYPED, std::string()); |
298 EXPECT_TRUE(contents()->cross_navigation_pending()); | 303 EXPECT_TRUE(contents()->cross_navigation_pending()); |
299 TestRenderViewHost* pending_rvh = contents()->pending_rvh(); | 304 TestRenderViewHost* pending_rvh = contents()->pending_rvh(); |
300 int pending_rvh_delete_count = 0; | 305 int pending_rvh_delete_count = 0; |
301 pending_rvh->set_delete_counter(&pending_rvh_delete_count); | 306 pending_rvh->set_delete_counter(&pending_rvh_delete_count); |
302 | 307 |
303 // Navigations should be suspended in pending_rvh until ShouldCloseACK. | 308 // Navigations should be suspended in pending_rvh until ShouldCloseACK. |
304 EXPECT_TRUE(pending_rvh->are_navigations_suspended()); | 309 EXPECT_TRUE(pending_rvh->are_navigations_suspended()); |
305 orig_rvh->SendShouldCloseACK(true); | 310 orig_rvh->SendShouldCloseACK(true); |
306 EXPECT_FALSE(pending_rvh->are_navigations_suspended()); | 311 EXPECT_FALSE(pending_rvh->are_navigations_suspended()); |
307 | 312 |
308 // DidNavigate from the pending page | 313 // DidNavigate from the pending page |
309 ViewHostMsg_FrameNavigate_Params params2; | 314 ViewHostMsg_FrameNavigate_Params params2; |
310 InitNavigateParams(¶ms2, 1, url2, PageTransition::TYPED); | 315 InitNavigateParams(¶ms2, 1, url2, content::PAGE_TRANSITION_TYPED); |
311 contents()->TestDidNavigate(pending_rvh, params2); | 316 contents()->TestDidNavigate(pending_rvh, params2); |
312 SiteInstance* instance2 = contents()->GetSiteInstance(); | 317 SiteInstance* instance2 = contents()->GetSiteInstance(); |
313 | 318 |
314 EXPECT_FALSE(contents()->cross_navigation_pending()); | 319 EXPECT_FALSE(contents()->cross_navigation_pending()); |
315 EXPECT_EQ(pending_rvh, contents()->render_view_host()); | 320 EXPECT_EQ(pending_rvh, contents()->render_view_host()); |
316 EXPECT_NE(instance1, instance2); | 321 EXPECT_NE(instance1, instance2); |
317 EXPECT_TRUE(contents()->pending_rvh() == NULL); | 322 EXPECT_TRUE(contents()->pending_rvh() == NULL); |
318 // We keep the original RVH around, swapped out. | 323 // We keep the original RVH around, swapped out. |
319 EXPECT_TRUE(contents()->render_manager_for_testing()->IsSwappedOut(orig_rvh)); | 324 EXPECT_TRUE(contents()->render_manager_for_testing()->IsSwappedOut(orig_rvh)); |
320 EXPECT_EQ(orig_rvh_delete_count, 0); | 325 EXPECT_EQ(orig_rvh_delete_count, 0); |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
352 // RVH without requiring a cross-site transition (i.e., PENDING state). | 357 // RVH without requiring a cross-site transition (i.e., PENDING state). |
353 TEST_F(TabContentsTest, CrossSiteBoundariesAfterCrash) { | 358 TEST_F(TabContentsTest, CrossSiteBoundariesAfterCrash) { |
354 contents()->transition_cross_site = true; | 359 contents()->transition_cross_site = true; |
355 TestRenderViewHost* orig_rvh = rvh(); | 360 TestRenderViewHost* orig_rvh = rvh(); |
356 int orig_rvh_delete_count = 0; | 361 int orig_rvh_delete_count = 0; |
357 orig_rvh->set_delete_counter(&orig_rvh_delete_count); | 362 orig_rvh->set_delete_counter(&orig_rvh_delete_count); |
358 SiteInstance* instance1 = contents()->GetSiteInstance(); | 363 SiteInstance* instance1 = contents()->GetSiteInstance(); |
359 | 364 |
360 // Navigate to URL. First URL should use first RenderViewHost. | 365 // Navigate to URL. First URL should use first RenderViewHost. |
361 const GURL url("http://www.google.com"); | 366 const GURL url("http://www.google.com"); |
362 controller().LoadURL(url, GURL(), PageTransition::TYPED, std::string()); | 367 controller().LoadURL( |
| 368 url, GURL(), content::PAGE_TRANSITION_TYPED, std::string()); |
363 ViewHostMsg_FrameNavigate_Params params1; | 369 ViewHostMsg_FrameNavigate_Params params1; |
364 InitNavigateParams(¶ms1, 1, url, PageTransition::TYPED); | 370 InitNavigateParams(¶ms1, 1, url, content::PAGE_TRANSITION_TYPED); |
365 contents()->TestDidNavigate(orig_rvh, params1); | 371 contents()->TestDidNavigate(orig_rvh, params1); |
366 | 372 |
367 EXPECT_FALSE(contents()->cross_navigation_pending()); | 373 EXPECT_FALSE(contents()->cross_navigation_pending()); |
368 EXPECT_EQ(orig_rvh, contents()->render_view_host()); | 374 EXPECT_EQ(orig_rvh, contents()->render_view_host()); |
369 | 375 |
370 // Crash the renderer. | 376 // Crash the renderer. |
371 orig_rvh->set_render_view_created(false); | 377 orig_rvh->set_render_view_created(false); |
372 | 378 |
373 // Navigate to new site. We should not go into PENDING. | 379 // Navigate to new site. We should not go into PENDING. |
374 const GURL url2("http://www.yahoo.com"); | 380 const GURL url2("http://www.yahoo.com"); |
375 controller().LoadURL(url2, GURL(), PageTransition::TYPED, std::string()); | 381 controller().LoadURL( |
| 382 url2, GURL(), content::PAGE_TRANSITION_TYPED, std::string()); |
376 TestRenderViewHost* new_rvh = rvh(); | 383 TestRenderViewHost* new_rvh = rvh(); |
377 EXPECT_FALSE(contents()->cross_navigation_pending()); | 384 EXPECT_FALSE(contents()->cross_navigation_pending()); |
378 EXPECT_TRUE(contents()->pending_rvh() == NULL); | 385 EXPECT_TRUE(contents()->pending_rvh() == NULL); |
379 EXPECT_NE(orig_rvh, new_rvh); | 386 EXPECT_NE(orig_rvh, new_rvh); |
380 EXPECT_EQ(orig_rvh_delete_count, 1); | 387 EXPECT_EQ(orig_rvh_delete_count, 1); |
381 | 388 |
382 // DidNavigate from the new page | 389 // DidNavigate from the new page |
383 ViewHostMsg_FrameNavigate_Params params2; | 390 ViewHostMsg_FrameNavigate_Params params2; |
384 InitNavigateParams(¶ms2, 1, url2, PageTransition::TYPED); | 391 InitNavigateParams(¶ms2, 1, url2, content::PAGE_TRANSITION_TYPED); |
385 contents()->TestDidNavigate(new_rvh, params2); | 392 contents()->TestDidNavigate(new_rvh, params2); |
386 SiteInstance* instance2 = contents()->GetSiteInstance(); | 393 SiteInstance* instance2 = contents()->GetSiteInstance(); |
387 | 394 |
388 EXPECT_FALSE(contents()->cross_navigation_pending()); | 395 EXPECT_FALSE(contents()->cross_navigation_pending()); |
389 EXPECT_EQ(new_rvh, rvh()); | 396 EXPECT_EQ(new_rvh, rvh()); |
390 EXPECT_NE(instance1, instance2); | 397 EXPECT_NE(instance1, instance2); |
391 EXPECT_TRUE(contents()->pending_rvh() == NULL); | 398 EXPECT_TRUE(contents()->pending_rvh() == NULL); |
392 | 399 |
393 // Close tab and ensure RVHs are deleted. | 400 // Close tab and ensure RVHs are deleted. |
394 DeleteContents(); | 401 DeleteContents(); |
395 EXPECT_EQ(orig_rvh_delete_count, 1); | 402 EXPECT_EQ(orig_rvh_delete_count, 1); |
396 } | 403 } |
397 | 404 |
398 // Test that opening a new tab in the same SiteInstance and then navigating | 405 // Test that opening a new tab in the same SiteInstance and then navigating |
399 // both tabs to a new site will place both tabs in a single SiteInstance. | 406 // both tabs to a new site will place both tabs in a single SiteInstance. |
400 TEST_F(TabContentsTest, NavigateTwoTabsCrossSite) { | 407 TEST_F(TabContentsTest, NavigateTwoTabsCrossSite) { |
401 contents()->transition_cross_site = true; | 408 contents()->transition_cross_site = true; |
402 TestRenderViewHost* orig_rvh = rvh(); | 409 TestRenderViewHost* orig_rvh = rvh(); |
403 SiteInstance* instance1 = contents()->GetSiteInstance(); | 410 SiteInstance* instance1 = contents()->GetSiteInstance(); |
404 | 411 |
405 // Navigate to URL. First URL should use first RenderViewHost. | 412 // Navigate to URL. First URL should use first RenderViewHost. |
406 const GURL url("http://www.google.com"); | 413 const GURL url("http://www.google.com"); |
407 controller().LoadURL(url, GURL(), PageTransition::TYPED, std::string()); | 414 controller().LoadURL( |
| 415 url, GURL(), content::PAGE_TRANSITION_TYPED, std::string()); |
408 ViewHostMsg_FrameNavigate_Params params1; | 416 ViewHostMsg_FrameNavigate_Params params1; |
409 InitNavigateParams(¶ms1, 1, url, PageTransition::TYPED); | 417 InitNavigateParams(¶ms1, 1, url, content::PAGE_TRANSITION_TYPED); |
410 contents()->TestDidNavigate(orig_rvh, params1); | 418 contents()->TestDidNavigate(orig_rvh, params1); |
411 | 419 |
412 // Open a new tab with the same SiteInstance, navigated to the same site. | 420 // Open a new tab with the same SiteInstance, navigated to the same site. |
413 TestTabContents contents2(profile(), instance1); | 421 TestTabContents contents2(profile(), instance1); |
414 params1.page_id = 2; // Need this since the site instance is the same (which | 422 params1.page_id = 2; // Need this since the site instance is the same (which |
415 // is the scope of page IDs) and we want to consider | 423 // is the scope of page IDs) and we want to consider |
416 // this a new page. | 424 // this a new page. |
417 contents2.transition_cross_site = true; | 425 contents2.transition_cross_site = true; |
418 contents2.controller().LoadURL(url, GURL(), PageTransition::TYPED, | 426 contents2.controller().LoadURL(url, GURL(), content::PAGE_TRANSITION_TYPED, |
419 std::string()); | 427 std::string()); |
420 contents2.TestDidNavigate(contents2.render_view_host(), params1); | 428 contents2.TestDidNavigate(contents2.render_view_host(), params1); |
421 | 429 |
422 // Navigate first tab to a new site | 430 // Navigate first tab to a new site |
423 const GURL url2a("http://www.yahoo.com"); | 431 const GURL url2a("http://www.yahoo.com"); |
424 controller().LoadURL(url2a, GURL(), PageTransition::TYPED, std::string()); | 432 controller().LoadURL( |
| 433 url2a, GURL(), content::PAGE_TRANSITION_TYPED, std::string()); |
425 orig_rvh->SendShouldCloseACK(true); | 434 orig_rvh->SendShouldCloseACK(true); |
426 TestRenderViewHost* pending_rvh_a = contents()->pending_rvh(); | 435 TestRenderViewHost* pending_rvh_a = contents()->pending_rvh(); |
427 ViewHostMsg_FrameNavigate_Params params2a; | 436 ViewHostMsg_FrameNavigate_Params params2a; |
428 InitNavigateParams(¶ms2a, 1, url2a, PageTransition::TYPED); | 437 InitNavigateParams(¶ms2a, 1, url2a, content::PAGE_TRANSITION_TYPED); |
429 contents()->TestDidNavigate(pending_rvh_a, params2a); | 438 contents()->TestDidNavigate(pending_rvh_a, params2a); |
430 SiteInstance* instance2a = contents()->GetSiteInstance(); | 439 SiteInstance* instance2a = contents()->GetSiteInstance(); |
431 EXPECT_NE(instance1, instance2a); | 440 EXPECT_NE(instance1, instance2a); |
432 | 441 |
433 // Navigate second tab to the same site as the first tab | 442 // Navigate second tab to the same site as the first tab |
434 const GURL url2b("http://mail.yahoo.com"); | 443 const GURL url2b("http://mail.yahoo.com"); |
435 contents2.controller().LoadURL(url2b, GURL(), PageTransition::TYPED, | 444 contents2.controller().LoadURL(url2b, GURL(), content::PAGE_TRANSITION_TYPED, |
436 std::string()); | 445 std::string()); |
437 TestRenderViewHost* rvh2 = | 446 TestRenderViewHost* rvh2 = |
438 static_cast<TestRenderViewHost*>(contents2.render_view_host()); | 447 static_cast<TestRenderViewHost*>(contents2.render_view_host()); |
439 rvh2->SendShouldCloseACK(true); | 448 rvh2->SendShouldCloseACK(true); |
440 TestRenderViewHost* pending_rvh_b = contents2.pending_rvh(); | 449 TestRenderViewHost* pending_rvh_b = contents2.pending_rvh(); |
441 EXPECT_TRUE(pending_rvh_b != NULL); | 450 EXPECT_TRUE(pending_rvh_b != NULL); |
442 EXPECT_TRUE(contents2.cross_navigation_pending()); | 451 EXPECT_TRUE(contents2.cross_navigation_pending()); |
443 | 452 |
444 // NOTE(creis): We used to be in danger of showing a sad tab page here if the | 453 // 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 | 454 // second tab hadn't navigated somewhere first (bug 1145430). That case is |
446 // now covered by the CrossSiteBoundariesAfterCrash test. | 455 // now covered by the CrossSiteBoundariesAfterCrash test. |
447 | 456 |
448 ViewHostMsg_FrameNavigate_Params params2b; | 457 ViewHostMsg_FrameNavigate_Params params2b; |
449 InitNavigateParams(¶ms2b, 2, url2b, PageTransition::TYPED); | 458 InitNavigateParams(¶ms2b, 2, url2b, content::PAGE_TRANSITION_TYPED); |
450 contents2.TestDidNavigate(pending_rvh_b, params2b); | 459 contents2.TestDidNavigate(pending_rvh_b, params2b); |
451 SiteInstance* instance2b = contents2.GetSiteInstance(); | 460 SiteInstance* instance2b = contents2.GetSiteInstance(); |
452 EXPECT_NE(instance1, instance2b); | 461 EXPECT_NE(instance1, instance2b); |
453 | 462 |
454 // Both tabs should now be in the same SiteInstance. | 463 // Both tabs should now be in the same SiteInstance. |
455 EXPECT_EQ(instance2a, instance2b); | 464 EXPECT_EQ(instance2a, instance2b); |
456 } | 465 } |
457 | 466 |
458 // Tests that TabContents uses the current URL, not the SiteInstance's site, to | 467 // Tests that TabContents uses the current URL, not the SiteInstance's site, to |
459 // determine whether a navigation is cross-site. | 468 // determine whether a navigation is cross-site. |
460 TEST_F(TabContentsTest, CrossSiteComparesAgainstCurrentPage) { | 469 TEST_F(TabContentsTest, CrossSiteComparesAgainstCurrentPage) { |
461 contents()->transition_cross_site = true; | 470 contents()->transition_cross_site = true; |
462 TestRenderViewHost* orig_rvh = rvh(); | 471 TestRenderViewHost* orig_rvh = rvh(); |
463 SiteInstance* instance1 = contents()->GetSiteInstance(); | 472 SiteInstance* instance1 = contents()->GetSiteInstance(); |
464 | 473 |
465 // Navigate to URL. | 474 // Navigate to URL. |
466 const GURL url("http://www.google.com"); | 475 const GURL url("http://www.google.com"); |
467 controller().LoadURL(url, GURL(), PageTransition::TYPED, std::string()); | 476 controller().LoadURL( |
| 477 url, GURL(), content::PAGE_TRANSITION_TYPED, std::string()); |
468 ViewHostMsg_FrameNavigate_Params params1; | 478 ViewHostMsg_FrameNavigate_Params params1; |
469 InitNavigateParams(¶ms1, 1, url, PageTransition::TYPED); | 479 InitNavigateParams(¶ms1, 1, url, content::PAGE_TRANSITION_TYPED); |
470 contents()->TestDidNavigate(orig_rvh, params1); | 480 contents()->TestDidNavigate(orig_rvh, params1); |
471 | 481 |
472 // Open a related tab to a second site. | 482 // Open a related tab to a second site. |
473 TestTabContents contents2(profile(), instance1); | 483 TestTabContents contents2(profile(), instance1); |
474 contents2.transition_cross_site = true; | 484 contents2.transition_cross_site = true; |
475 const GURL url2("http://www.yahoo.com"); | 485 const GURL url2("http://www.yahoo.com"); |
476 contents2.controller().LoadURL(url2, GURL(), PageTransition::TYPED, | 486 contents2.controller().LoadURL(url2, GURL(), content::PAGE_TRANSITION_TYPED, |
477 std::string()); | 487 std::string()); |
478 // The first RVH in contents2 isn't live yet, so we shortcut the cross site | 488 // The first RVH in contents2 isn't live yet, so we shortcut the cross site |
479 // pending. | 489 // pending. |
480 TestRenderViewHost* rvh2 = static_cast<TestRenderViewHost*>( | 490 TestRenderViewHost* rvh2 = static_cast<TestRenderViewHost*>( |
481 contents2.render_view_host()); | 491 contents2.render_view_host()); |
482 EXPECT_FALSE(contents2.cross_navigation_pending()); | 492 EXPECT_FALSE(contents2.cross_navigation_pending()); |
483 ViewHostMsg_FrameNavigate_Params params2; | 493 ViewHostMsg_FrameNavigate_Params params2; |
484 InitNavigateParams(¶ms2, 2, url2, PageTransition::TYPED); | 494 InitNavigateParams(¶ms2, 2, url2, content::PAGE_TRANSITION_TYPED); |
485 contents2.TestDidNavigate(rvh2, params2); | 495 contents2.TestDidNavigate(rvh2, params2); |
486 SiteInstance* instance2 = contents2.GetSiteInstance(); | 496 SiteInstance* instance2 = contents2.GetSiteInstance(); |
487 EXPECT_NE(instance1, instance2); | 497 EXPECT_NE(instance1, instance2); |
488 EXPECT_FALSE(contents2.cross_navigation_pending()); | 498 EXPECT_FALSE(contents2.cross_navigation_pending()); |
489 | 499 |
490 // Simulate a link click in first tab to second site. Doesn't switch | 500 // Simulate a link click in first tab to second site. Doesn't switch |
491 // SiteInstances, because we don't intercept WebKit navigations. | 501 // SiteInstances, because we don't intercept WebKit navigations. |
492 ViewHostMsg_FrameNavigate_Params params3; | 502 ViewHostMsg_FrameNavigate_Params params3; |
493 InitNavigateParams(¶ms3, 2, url2, PageTransition::TYPED); | 503 InitNavigateParams(¶ms3, 2, url2, content::PAGE_TRANSITION_TYPED); |
494 contents()->TestDidNavigate(orig_rvh, params3); | 504 contents()->TestDidNavigate(orig_rvh, params3); |
495 SiteInstance* instance3 = contents()->GetSiteInstance(); | 505 SiteInstance* instance3 = contents()->GetSiteInstance(); |
496 EXPECT_EQ(instance1, instance3); | 506 EXPECT_EQ(instance1, instance3); |
497 EXPECT_FALSE(contents()->cross_navigation_pending()); | 507 EXPECT_FALSE(contents()->cross_navigation_pending()); |
498 | 508 |
499 // Navigate to the new site. Doesn't switch SiteInstancees, because we | 509 // Navigate to the new site. Doesn't switch SiteInstancees, because we |
500 // compare against the current URL, not the SiteInstance's site. | 510 // compare against the current URL, not the SiteInstance's site. |
501 const GURL url3("http://mail.yahoo.com"); | 511 const GURL url3("http://mail.yahoo.com"); |
502 controller().LoadURL(url3, GURL(), PageTransition::TYPED, std::string()); | 512 controller().LoadURL( |
| 513 url3, GURL(), content::PAGE_TRANSITION_TYPED, std::string()); |
503 EXPECT_FALSE(contents()->cross_navigation_pending()); | 514 EXPECT_FALSE(contents()->cross_navigation_pending()); |
504 ViewHostMsg_FrameNavigate_Params params4; | 515 ViewHostMsg_FrameNavigate_Params params4; |
505 InitNavigateParams(¶ms4, 3, url3, PageTransition::TYPED); | 516 InitNavigateParams(¶ms4, 3, url3, content::PAGE_TRANSITION_TYPED); |
506 contents()->TestDidNavigate(orig_rvh, params4); | 517 contents()->TestDidNavigate(orig_rvh, params4); |
507 SiteInstance* instance4 = contents()->GetSiteInstance(); | 518 SiteInstance* instance4 = contents()->GetSiteInstance(); |
508 EXPECT_EQ(instance1, instance4); | 519 EXPECT_EQ(instance1, instance4); |
509 } | 520 } |
510 | 521 |
511 // Test that the onbeforeunload and onunload handlers run when navigating | 522 // Test that the onbeforeunload and onunload handlers run when navigating |
512 // across site boundaries. | 523 // across site boundaries. |
513 TEST_F(TabContentsTest, CrossSiteUnloadHandlers) { | 524 TEST_F(TabContentsTest, CrossSiteUnloadHandlers) { |
514 contents()->transition_cross_site = true; | 525 contents()->transition_cross_site = true; |
515 TestRenderViewHost* orig_rvh = rvh(); | 526 TestRenderViewHost* orig_rvh = rvh(); |
516 SiteInstance* instance1 = contents()->GetSiteInstance(); | 527 SiteInstance* instance1 = contents()->GetSiteInstance(); |
517 | 528 |
518 // Navigate to URL. First URL should use first RenderViewHost. | 529 // Navigate to URL. First URL should use first RenderViewHost. |
519 const GURL url("http://www.google.com"); | 530 const GURL url("http://www.google.com"); |
520 controller().LoadURL(url, GURL(), PageTransition::TYPED, std::string()); | 531 controller().LoadURL( |
| 532 url, GURL(), content::PAGE_TRANSITION_TYPED, std::string()); |
521 ViewHostMsg_FrameNavigate_Params params1; | 533 ViewHostMsg_FrameNavigate_Params params1; |
522 InitNavigateParams(¶ms1, 1, url, PageTransition::TYPED); | 534 InitNavigateParams(¶ms1, 1, url, content::PAGE_TRANSITION_TYPED); |
523 contents()->TestDidNavigate(orig_rvh, params1); | 535 contents()->TestDidNavigate(orig_rvh, params1); |
524 EXPECT_FALSE(contents()->cross_navigation_pending()); | 536 EXPECT_FALSE(contents()->cross_navigation_pending()); |
525 EXPECT_EQ(orig_rvh, contents()->render_view_host()); | 537 EXPECT_EQ(orig_rvh, contents()->render_view_host()); |
526 | 538 |
527 // Navigate to new site, but simulate an onbeforeunload denial. | 539 // Navigate to new site, but simulate an onbeforeunload denial. |
528 const GURL url2("http://www.yahoo.com"); | 540 const GURL url2("http://www.yahoo.com"); |
529 controller().LoadURL(url2, GURL(), PageTransition::TYPED, std::string()); | 541 controller().LoadURL( |
| 542 url2, GURL(), content::PAGE_TRANSITION_TYPED, std::string()); |
530 EXPECT_TRUE(orig_rvh->is_waiting_for_beforeunload_ack()); | 543 EXPECT_TRUE(orig_rvh->is_waiting_for_beforeunload_ack()); |
531 orig_rvh->TestOnMessageReceived(ViewHostMsg_ShouldClose_ACK(0, false)); | 544 orig_rvh->TestOnMessageReceived(ViewHostMsg_ShouldClose_ACK(0, false)); |
532 EXPECT_FALSE(orig_rvh->is_waiting_for_beforeunload_ack()); | 545 EXPECT_FALSE(orig_rvh->is_waiting_for_beforeunload_ack()); |
533 EXPECT_FALSE(contents()->cross_navigation_pending()); | 546 EXPECT_FALSE(contents()->cross_navigation_pending()); |
534 EXPECT_EQ(orig_rvh, contents()->render_view_host()); | 547 EXPECT_EQ(orig_rvh, contents()->render_view_host()); |
535 | 548 |
536 // Navigate again, but simulate an onbeforeunload approval. | 549 // Navigate again, but simulate an onbeforeunload approval. |
537 controller().LoadURL(url2, GURL(), PageTransition::TYPED, std::string()); | 550 controller().LoadURL( |
| 551 url2, GURL(), content::PAGE_TRANSITION_TYPED, std::string()); |
538 EXPECT_TRUE(orig_rvh->is_waiting_for_beforeunload_ack()); | 552 EXPECT_TRUE(orig_rvh->is_waiting_for_beforeunload_ack()); |
539 orig_rvh->TestOnMessageReceived(ViewHostMsg_ShouldClose_ACK(0, true)); | 553 orig_rvh->TestOnMessageReceived(ViewHostMsg_ShouldClose_ACK(0, true)); |
540 EXPECT_FALSE(orig_rvh->is_waiting_for_beforeunload_ack()); | 554 EXPECT_FALSE(orig_rvh->is_waiting_for_beforeunload_ack()); |
541 EXPECT_TRUE(contents()->cross_navigation_pending()); | 555 EXPECT_TRUE(contents()->cross_navigation_pending()); |
542 TestRenderViewHost* pending_rvh = static_cast<TestRenderViewHost*>( | 556 TestRenderViewHost* pending_rvh = static_cast<TestRenderViewHost*>( |
543 contents()->pending_rvh()); | 557 contents()->pending_rvh()); |
544 | 558 |
545 // We won't hear DidNavigate until the onunload handler has finished running. | 559 // We won't hear DidNavigate until the onunload handler has finished running. |
546 // (No way to simulate that here, but it involves a call from RDH to | 560 // (No way to simulate that here, but it involves a call from RDH to |
547 // TabContents::OnCrossSiteResponse.) | 561 // TabContents::OnCrossSiteResponse.) |
548 | 562 |
549 // DidNavigate from the pending page | 563 // DidNavigate from the pending page |
550 ViewHostMsg_FrameNavigate_Params params2; | 564 ViewHostMsg_FrameNavigate_Params params2; |
551 InitNavigateParams(¶ms2, 1, url2, PageTransition::TYPED); | 565 InitNavigateParams(¶ms2, 1, url2, content::PAGE_TRANSITION_TYPED); |
552 contents()->TestDidNavigate(pending_rvh, params2); | 566 contents()->TestDidNavigate(pending_rvh, params2); |
553 SiteInstance* instance2 = contents()->GetSiteInstance(); | 567 SiteInstance* instance2 = contents()->GetSiteInstance(); |
554 EXPECT_FALSE(contents()->cross_navigation_pending()); | 568 EXPECT_FALSE(contents()->cross_navigation_pending()); |
555 EXPECT_EQ(pending_rvh, rvh()); | 569 EXPECT_EQ(pending_rvh, rvh()); |
556 EXPECT_NE(instance1, instance2); | 570 EXPECT_NE(instance1, instance2); |
557 EXPECT_TRUE(contents()->pending_rvh() == NULL); | 571 EXPECT_TRUE(contents()->pending_rvh() == NULL); |
558 } | 572 } |
559 | 573 |
560 // Test that during a slow cross-site navigation, the original renderer can | 574 // Test that during a slow cross-site navigation, the original renderer can |
561 // navigate to a different URL and have it displayed, canceling the slow | 575 // navigate to a different URL and have it displayed, canceling the slow |
562 // navigation. | 576 // navigation. |
563 TEST_F(TabContentsTest, CrossSiteNavigationPreempted) { | 577 TEST_F(TabContentsTest, CrossSiteNavigationPreempted) { |
564 contents()->transition_cross_site = true; | 578 contents()->transition_cross_site = true; |
565 TestRenderViewHost* orig_rvh = rvh(); | 579 TestRenderViewHost* orig_rvh = rvh(); |
566 SiteInstance* instance1 = contents()->GetSiteInstance(); | 580 SiteInstance* instance1 = contents()->GetSiteInstance(); |
567 | 581 |
568 // Navigate to URL. First URL should use first RenderViewHost. | 582 // Navigate to URL. First URL should use first RenderViewHost. |
569 const GURL url("http://www.google.com"); | 583 const GURL url("http://www.google.com"); |
570 controller().LoadURL(url, GURL(), PageTransition::TYPED, std::string()); | 584 controller().LoadURL( |
| 585 url, GURL(), content::PAGE_TRANSITION_TYPED, std::string()); |
571 ViewHostMsg_FrameNavigate_Params params1; | 586 ViewHostMsg_FrameNavigate_Params params1; |
572 InitNavigateParams(¶ms1, 1, url, PageTransition::TYPED); | 587 InitNavigateParams(¶ms1, 1, url, content::PAGE_TRANSITION_TYPED); |
573 contents()->TestDidNavigate(orig_rvh, params1); | 588 contents()->TestDidNavigate(orig_rvh, params1); |
574 EXPECT_FALSE(contents()->cross_navigation_pending()); | 589 EXPECT_FALSE(contents()->cross_navigation_pending()); |
575 EXPECT_EQ(orig_rvh, contents()->render_view_host()); | 590 EXPECT_EQ(orig_rvh, contents()->render_view_host()); |
576 | 591 |
577 // Navigate to new site, simulating an onbeforeunload approval. | 592 // Navigate to new site, simulating an onbeforeunload approval. |
578 const GURL url2("http://www.yahoo.com"); | 593 const GURL url2("http://www.yahoo.com"); |
579 controller().LoadURL(url2, GURL(), PageTransition::TYPED, std::string()); | 594 controller().LoadURL( |
| 595 url2, GURL(), content::PAGE_TRANSITION_TYPED, std::string()); |
580 EXPECT_TRUE(orig_rvh->is_waiting_for_beforeunload_ack()); | 596 EXPECT_TRUE(orig_rvh->is_waiting_for_beforeunload_ack()); |
581 orig_rvh->TestOnMessageReceived(ViewHostMsg_ShouldClose_ACK(0, true)); | 597 orig_rvh->TestOnMessageReceived(ViewHostMsg_ShouldClose_ACK(0, true)); |
582 EXPECT_TRUE(contents()->cross_navigation_pending()); | 598 EXPECT_TRUE(contents()->cross_navigation_pending()); |
583 | 599 |
584 // Suppose the original renderer navigates before the new one is ready. | 600 // Suppose the original renderer navigates before the new one is ready. |
585 orig_rvh->SendNavigate(2, GURL("http://www.google.com/foo")); | 601 orig_rvh->SendNavigate(2, GURL("http://www.google.com/foo")); |
586 | 602 |
587 // Verify that the pending navigation is cancelled. | 603 // Verify that the pending navigation is cancelled. |
588 EXPECT_FALSE(orig_rvh->is_waiting_for_beforeunload_ack()); | 604 EXPECT_FALSE(orig_rvh->is_waiting_for_beforeunload_ack()); |
589 SiteInstance* instance2 = contents()->GetSiteInstance(); | 605 SiteInstance* instance2 = contents()->GetSiteInstance(); |
590 EXPECT_FALSE(contents()->cross_navigation_pending()); | 606 EXPECT_FALSE(contents()->cross_navigation_pending()); |
591 EXPECT_EQ(orig_rvh, rvh()); | 607 EXPECT_EQ(orig_rvh, rvh()); |
592 EXPECT_EQ(instance1, instance2); | 608 EXPECT_EQ(instance1, instance2); |
593 EXPECT_TRUE(contents()->pending_rvh() == NULL); | 609 EXPECT_TRUE(contents()->pending_rvh() == NULL); |
594 } | 610 } |
595 | 611 |
596 TEST_F(TabContentsTest, CrossSiteNavigationBackPreempted) { | 612 TEST_F(TabContentsTest, CrossSiteNavigationBackPreempted) { |
597 contents()->transition_cross_site = true; | 613 contents()->transition_cross_site = true; |
598 | 614 |
599 // Start with NTP, which gets a new RVH with WebUI bindings. | 615 // Start with NTP, which gets a new RVH with WebUI bindings. |
600 const GURL url1("chrome://newtab"); | 616 const GURL url1("chrome://newtab"); |
601 controller().LoadURL(url1, GURL(), PageTransition::TYPED, std::string()); | 617 controller().LoadURL( |
| 618 url1, GURL(), content::PAGE_TRANSITION_TYPED, std::string()); |
602 TestRenderViewHost* ntp_rvh = rvh(); | 619 TestRenderViewHost* ntp_rvh = rvh(); |
603 ViewHostMsg_FrameNavigate_Params params1; | 620 ViewHostMsg_FrameNavigate_Params params1; |
604 InitNavigateParams(¶ms1, 1, url1, PageTransition::TYPED); | 621 InitNavigateParams(¶ms1, 1, url1, content::PAGE_TRANSITION_TYPED); |
605 contents()->TestDidNavigate(ntp_rvh, params1); | 622 contents()->TestDidNavigate(ntp_rvh, params1); |
606 NavigationEntry* entry1 = controller().GetLastCommittedEntry(); | 623 NavigationEntry* entry1 = controller().GetLastCommittedEntry(); |
607 SiteInstance* instance1 = contents()->GetSiteInstance(); | 624 SiteInstance* instance1 = contents()->GetSiteInstance(); |
608 | 625 |
609 EXPECT_FALSE(contents()->cross_navigation_pending()); | 626 EXPECT_FALSE(contents()->cross_navigation_pending()); |
610 EXPECT_EQ(ntp_rvh, contents()->render_view_host()); | 627 EXPECT_EQ(ntp_rvh, contents()->render_view_host()); |
611 EXPECT_EQ(url1, entry1->url()); | 628 EXPECT_EQ(url1, entry1->url()); |
612 EXPECT_EQ(instance1, entry1->site_instance()); | 629 EXPECT_EQ(instance1, entry1->site_instance()); |
613 EXPECT_TRUE(ntp_rvh->enabled_bindings() & content::BINDINGS_POLICY_WEB_UI); | 630 EXPECT_TRUE(ntp_rvh->enabled_bindings() & content::BINDINGS_POLICY_WEB_UI); |
614 | 631 |
615 // Navigate to new site. | 632 // Navigate to new site. |
616 const GURL url2("http://www.google.com"); | 633 const GURL url2("http://www.google.com"); |
617 controller().LoadURL(url2, GURL(), PageTransition::TYPED, std::string()); | 634 controller().LoadURL( |
| 635 url2, GURL(), content::PAGE_TRANSITION_TYPED, std::string()); |
618 EXPECT_TRUE(contents()->cross_navigation_pending()); | 636 EXPECT_TRUE(contents()->cross_navigation_pending()); |
619 TestRenderViewHost* google_rvh = contents()->pending_rvh(); | 637 TestRenderViewHost* google_rvh = contents()->pending_rvh(); |
620 | 638 |
621 // Simulate beforeunload approval. | 639 // Simulate beforeunload approval. |
622 EXPECT_TRUE(ntp_rvh->is_waiting_for_beforeunload_ack()); | 640 EXPECT_TRUE(ntp_rvh->is_waiting_for_beforeunload_ack()); |
623 ntp_rvh->TestOnMessageReceived(ViewHostMsg_ShouldClose_ACK(0, true)); | 641 ntp_rvh->TestOnMessageReceived(ViewHostMsg_ShouldClose_ACK(0, true)); |
624 | 642 |
625 // DidNavigate from the pending page. | 643 // DidNavigate from the pending page. |
626 ViewHostMsg_FrameNavigate_Params params2; | 644 ViewHostMsg_FrameNavigate_Params params2; |
627 InitNavigateParams(¶ms2, 1, url2, PageTransition::TYPED); | 645 InitNavigateParams(¶ms2, 1, url2, content::PAGE_TRANSITION_TYPED); |
628 contents()->TestDidNavigate(google_rvh, params2); | 646 contents()->TestDidNavigate(google_rvh, params2); |
629 NavigationEntry* entry2 = controller().GetLastCommittedEntry(); | 647 NavigationEntry* entry2 = controller().GetLastCommittedEntry(); |
630 SiteInstance* instance2 = contents()->GetSiteInstance(); | 648 SiteInstance* instance2 = contents()->GetSiteInstance(); |
631 | 649 |
632 EXPECT_FALSE(contents()->cross_navigation_pending()); | 650 EXPECT_FALSE(contents()->cross_navigation_pending()); |
633 EXPECT_EQ(google_rvh, contents()->render_view_host()); | 651 EXPECT_EQ(google_rvh, contents()->render_view_host()); |
634 EXPECT_NE(instance1, instance2); | 652 EXPECT_NE(instance1, instance2); |
635 EXPECT_FALSE(contents()->pending_rvh()); | 653 EXPECT_FALSE(contents()->pending_rvh()); |
636 EXPECT_EQ(url2, entry2->url()); | 654 EXPECT_EQ(url2, entry2->url()); |
637 EXPECT_EQ(instance2, entry2->site_instance()); | 655 EXPECT_EQ(instance2, entry2->site_instance()); |
638 EXPECT_FALSE(google_rvh->enabled_bindings() & | 656 EXPECT_FALSE(google_rvh->enabled_bindings() & |
639 content::BINDINGS_POLICY_WEB_UI); | 657 content::BINDINGS_POLICY_WEB_UI); |
640 | 658 |
641 // Navigate to third page on same site. | 659 // Navigate to third page on same site. |
642 const GURL url3("http://news.google.com"); | 660 const GURL url3("http://news.google.com"); |
643 controller().LoadURL(url3, GURL(), PageTransition::TYPED, std::string()); | 661 controller().LoadURL( |
| 662 url3, GURL(), content::PAGE_TRANSITION_TYPED, std::string()); |
644 EXPECT_FALSE(contents()->cross_navigation_pending()); | 663 EXPECT_FALSE(contents()->cross_navigation_pending()); |
645 ViewHostMsg_FrameNavigate_Params params3; | 664 ViewHostMsg_FrameNavigate_Params params3; |
646 InitNavigateParams(¶ms3, 2, url3, PageTransition::TYPED); | 665 InitNavigateParams(¶ms3, 2, url3, content::PAGE_TRANSITION_TYPED); |
647 contents()->TestDidNavigate(google_rvh, params3); | 666 contents()->TestDidNavigate(google_rvh, params3); |
648 NavigationEntry* entry3 = controller().GetLastCommittedEntry(); | 667 NavigationEntry* entry3 = controller().GetLastCommittedEntry(); |
649 SiteInstance* instance3 = contents()->GetSiteInstance(); | 668 SiteInstance* instance3 = contents()->GetSiteInstance(); |
650 | 669 |
651 EXPECT_FALSE(contents()->cross_navigation_pending()); | 670 EXPECT_FALSE(contents()->cross_navigation_pending()); |
652 EXPECT_EQ(google_rvh, contents()->render_view_host()); | 671 EXPECT_EQ(google_rvh, contents()->render_view_host()); |
653 EXPECT_EQ(instance2, instance3); | 672 EXPECT_EQ(instance2, instance3); |
654 EXPECT_FALSE(contents()->pending_rvh()); | 673 EXPECT_FALSE(contents()->pending_rvh()); |
655 EXPECT_EQ(url3, entry3->url()); | 674 EXPECT_EQ(url3, entry3->url()); |
656 EXPECT_EQ(instance3, entry3->site_instance()); | 675 EXPECT_EQ(instance3, entry3->site_instance()); |
(...skipping 30 matching lines...) Expand all Loading... |
687 } | 706 } |
688 | 707 |
689 // Test that during a slow cross-site navigation, a sub-frame navigation in the | 708 // Test that during a slow cross-site navigation, a sub-frame navigation in the |
690 // original renderer will not cancel the slow navigation (bug 42029). | 709 // original renderer will not cancel the slow navigation (bug 42029). |
691 TEST_F(TabContentsTest, CrossSiteNavigationNotPreemptedByFrame) { | 710 TEST_F(TabContentsTest, CrossSiteNavigationNotPreemptedByFrame) { |
692 contents()->transition_cross_site = true; | 711 contents()->transition_cross_site = true; |
693 TestRenderViewHost* orig_rvh = rvh(); | 712 TestRenderViewHost* orig_rvh = rvh(); |
694 | 713 |
695 // Navigate to URL. First URL should use first RenderViewHost. | 714 // Navigate to URL. First URL should use first RenderViewHost. |
696 const GURL url("http://www.google.com"); | 715 const GURL url("http://www.google.com"); |
697 controller().LoadURL(url, GURL(), PageTransition::TYPED, std::string()); | 716 controller().LoadURL( |
| 717 url, GURL(), content::PAGE_TRANSITION_TYPED, std::string()); |
698 ViewHostMsg_FrameNavigate_Params params1; | 718 ViewHostMsg_FrameNavigate_Params params1; |
699 InitNavigateParams(¶ms1, 1, url, PageTransition::TYPED); | 719 InitNavigateParams(¶ms1, 1, url, content::PAGE_TRANSITION_TYPED); |
700 contents()->TestDidNavigate(orig_rvh, params1); | 720 contents()->TestDidNavigate(orig_rvh, params1); |
701 EXPECT_FALSE(contents()->cross_navigation_pending()); | 721 EXPECT_FALSE(contents()->cross_navigation_pending()); |
702 EXPECT_EQ(orig_rvh, contents()->render_view_host()); | 722 EXPECT_EQ(orig_rvh, contents()->render_view_host()); |
703 | 723 |
704 // Start navigating to new site. | 724 // Start navigating to new site. |
705 const GURL url2("http://www.yahoo.com"); | 725 const GURL url2("http://www.yahoo.com"); |
706 controller().LoadURL(url2, GURL(), PageTransition::TYPED, std::string()); | 726 controller().LoadURL( |
| 727 url2, GURL(), content::PAGE_TRANSITION_TYPED, std::string()); |
707 | 728 |
708 // Simulate a sub-frame navigation arriving and ensure the RVH is still | 729 // Simulate a sub-frame navigation arriving and ensure the RVH is still |
709 // waiting for a before unload response. | 730 // waiting for a before unload response. |
710 orig_rvh->SendNavigateWithTransition(1, GURL("http://google.com/frame"), | 731 orig_rvh->SendNavigateWithTransition(1, GURL("http://google.com/frame"), |
711 PageTransition::AUTO_SUBFRAME); | 732 content::PAGE_TRANSITION_AUTO_SUBFRAME); |
712 EXPECT_TRUE(orig_rvh->is_waiting_for_beforeunload_ack()); | 733 EXPECT_TRUE(orig_rvh->is_waiting_for_beforeunload_ack()); |
713 | 734 |
714 // Now simulate the onbeforeunload approval and verify the navigation is | 735 // Now simulate the onbeforeunload approval and verify the navigation is |
715 // not canceled. | 736 // not canceled. |
716 orig_rvh->TestOnMessageReceived(ViewHostMsg_ShouldClose_ACK(0, true)); | 737 orig_rvh->TestOnMessageReceived(ViewHostMsg_ShouldClose_ACK(0, true)); |
717 EXPECT_FALSE(orig_rvh->is_waiting_for_beforeunload_ack()); | 738 EXPECT_FALSE(orig_rvh->is_waiting_for_beforeunload_ack()); |
718 EXPECT_TRUE(contents()->cross_navigation_pending()); | 739 EXPECT_TRUE(contents()->cross_navigation_pending()); |
719 } | 740 } |
720 | 741 |
721 // Test that a cross-site navigation is not preempted if the previous | 742 // Test that a cross-site navigation is not preempted if the previous |
722 // renderer sends a FrameNavigate message just before being told to stop. | 743 // renderer sends a FrameNavigate message just before being told to stop. |
723 // We should only preempt the cross-site navigation if the previous renderer | 744 // We should only preempt the cross-site navigation if the previous renderer |
724 // has started a new navigation. See http://crbug.com/79176. | 745 // has started a new navigation. See http://crbug.com/79176. |
725 TEST_F(TabContentsTest, CrossSiteNotPreemptedDuringBeforeUnload) { | 746 TEST_F(TabContentsTest, CrossSiteNotPreemptedDuringBeforeUnload) { |
726 contents()->transition_cross_site = true; | 747 contents()->transition_cross_site = true; |
727 | 748 |
728 // Navigate to NTP URL. | 749 // Navigate to NTP URL. |
729 const GURL url("chrome://newtab"); | 750 const GURL url("chrome://newtab"); |
730 controller().LoadURL(url, GURL(), PageTransition::TYPED, std::string()); | 751 controller().LoadURL( |
| 752 url, GURL(), content::PAGE_TRANSITION_TYPED, std::string()); |
731 TestRenderViewHost* orig_rvh = rvh(); | 753 TestRenderViewHost* orig_rvh = rvh(); |
732 EXPECT_FALSE(contents()->cross_navigation_pending()); | 754 EXPECT_FALSE(contents()->cross_navigation_pending()); |
733 | 755 |
734 // Navigate to new site, with the beforeunload request in flight. | 756 // Navigate to new site, with the beforeunload request in flight. |
735 const GURL url2("http://www.yahoo.com"); | 757 const GURL url2("http://www.yahoo.com"); |
736 controller().LoadURL(url2, GURL(), PageTransition::TYPED, std::string()); | 758 controller().LoadURL( |
| 759 url2, GURL(), content::PAGE_TRANSITION_TYPED, std::string()); |
737 TestRenderViewHost* pending_rvh = contents()->pending_rvh(); | 760 TestRenderViewHost* pending_rvh = contents()->pending_rvh(); |
738 EXPECT_TRUE(contents()->cross_navigation_pending()); | 761 EXPECT_TRUE(contents()->cross_navigation_pending()); |
739 EXPECT_TRUE(orig_rvh->is_waiting_for_beforeunload_ack()); | 762 EXPECT_TRUE(orig_rvh->is_waiting_for_beforeunload_ack()); |
740 | 763 |
741 // Suppose the first navigation tries to commit now, with a | 764 // Suppose the first navigation tries to commit now, with a |
742 // ViewMsg_Stop in flight. This should not cancel the pending navigation, | 765 // ViewMsg_Stop in flight. This should not cancel the pending navigation, |
743 // but it should act as if the beforeunload ack arrived. | 766 // but it should act as if the beforeunload ack arrived. |
744 orig_rvh->SendNavigate(1, GURL("chrome://newtab")); | 767 orig_rvh->SendNavigate(1, GURL("chrome://newtab")); |
745 EXPECT_TRUE(contents()->cross_navigation_pending()); | 768 EXPECT_TRUE(contents()->cross_navigation_pending()); |
746 EXPECT_EQ(orig_rvh, contents()->render_view_host()); | 769 EXPECT_EQ(orig_rvh, contents()->render_view_host()); |
747 EXPECT_FALSE(orig_rvh->is_waiting_for_beforeunload_ack()); | 770 EXPECT_FALSE(orig_rvh->is_waiting_for_beforeunload_ack()); |
748 | 771 |
749 // The pending navigation should be able to commit successfully. | 772 // The pending navigation should be able to commit successfully. |
750 ViewHostMsg_FrameNavigate_Params params2; | 773 ViewHostMsg_FrameNavigate_Params params2; |
751 InitNavigateParams(¶ms2, 1, url2, PageTransition::TYPED); | 774 InitNavigateParams(¶ms2, 1, url2, content::PAGE_TRANSITION_TYPED); |
752 contents()->TestDidNavigate(pending_rvh, params2); | 775 contents()->TestDidNavigate(pending_rvh, params2); |
753 EXPECT_FALSE(contents()->cross_navigation_pending()); | 776 EXPECT_FALSE(contents()->cross_navigation_pending()); |
754 EXPECT_EQ(pending_rvh, contents()->render_view_host()); | 777 EXPECT_EQ(pending_rvh, contents()->render_view_host()); |
755 } | 778 } |
756 | 779 |
757 // Test that the original renderer cannot preempt a cross-site navigation once | 780 // Test that the original renderer cannot preempt a cross-site navigation once |
758 // the unload request has been made. At this point, the cross-site navigation | 781 // the unload request has been made. At this point, the cross-site navigation |
759 // is almost ready to be displayed, and the original renderer is only given a | 782 // is almost ready to be displayed, and the original renderer is only given a |
760 // short chance to run an unload handler. Prevents regression of bug 23942. | 783 // short chance to run an unload handler. Prevents regression of bug 23942. |
761 TEST_F(TabContentsTest, CrossSiteCantPreemptAfterUnload) { | 784 TEST_F(TabContentsTest, CrossSiteCantPreemptAfterUnload) { |
762 contents()->transition_cross_site = true; | 785 contents()->transition_cross_site = true; |
763 TestRenderViewHost* orig_rvh = rvh(); | 786 TestRenderViewHost* orig_rvh = rvh(); |
764 SiteInstance* instance1 = contents()->GetSiteInstance(); | 787 SiteInstance* instance1 = contents()->GetSiteInstance(); |
765 | 788 |
766 // Navigate to URL. First URL should use first RenderViewHost. | 789 // Navigate to URL. First URL should use first RenderViewHost. |
767 const GURL url("http://www.google.com"); | 790 const GURL url("http://www.google.com"); |
768 controller().LoadURL(url, GURL(), PageTransition::TYPED, std::string()); | 791 controller().LoadURL( |
| 792 url, GURL(), content::PAGE_TRANSITION_TYPED, std::string()); |
769 ViewHostMsg_FrameNavigate_Params params1; | 793 ViewHostMsg_FrameNavigate_Params params1; |
770 InitNavigateParams(¶ms1, 1, url, PageTransition::TYPED); | 794 InitNavigateParams(¶ms1, 1, url, content::PAGE_TRANSITION_TYPED); |
771 contents()->TestDidNavigate(orig_rvh, params1); | 795 contents()->TestDidNavigate(orig_rvh, params1); |
772 EXPECT_FALSE(contents()->cross_navigation_pending()); | 796 EXPECT_FALSE(contents()->cross_navigation_pending()); |
773 EXPECT_EQ(orig_rvh, contents()->render_view_host()); | 797 EXPECT_EQ(orig_rvh, contents()->render_view_host()); |
774 | 798 |
775 // Navigate to new site, simulating an onbeforeunload approval. | 799 // Navigate to new site, simulating an onbeforeunload approval. |
776 const GURL url2("http://www.yahoo.com"); | 800 const GURL url2("http://www.yahoo.com"); |
777 controller().LoadURL(url2, GURL(), PageTransition::TYPED, std::string()); | 801 controller().LoadURL( |
| 802 url2, GURL(), content::PAGE_TRANSITION_TYPED, std::string()); |
778 orig_rvh->TestOnMessageReceived(ViewHostMsg_ShouldClose_ACK(0, true)); | 803 orig_rvh->TestOnMessageReceived(ViewHostMsg_ShouldClose_ACK(0, true)); |
779 EXPECT_TRUE(contents()->cross_navigation_pending()); | 804 EXPECT_TRUE(contents()->cross_navigation_pending()); |
780 TestRenderViewHost* pending_rvh = static_cast<TestRenderViewHost*>( | 805 TestRenderViewHost* pending_rvh = static_cast<TestRenderViewHost*>( |
781 contents()->pending_rvh()); | 806 contents()->pending_rvh()); |
782 | 807 |
783 // Simulate the pending renderer's response, which leads to an unload request | 808 // Simulate the pending renderer's response, which leads to an unload request |
784 // being sent to orig_rvh. | 809 // being sent to orig_rvh. |
785 contents()->render_manager_for_testing()->OnCrossSiteResponse(0, 0); | 810 contents()->render_manager_for_testing()->OnCrossSiteResponse(0, 0); |
786 | 811 |
787 // Suppose the original renderer navigates now, while the unload request is in | 812 // Suppose the original renderer navigates now, while the unload request is in |
788 // flight. We should ignore it, wait for the unload ack, and let the pending | 813 // flight. We should ignore it, wait for the unload ack, and let the pending |
789 // request continue. Otherwise, the tab may close spontaneously or stop | 814 // request continue. Otherwise, the tab may close spontaneously or stop |
790 // responding to navigation requests. (See bug 23942.) | 815 // responding to navigation requests. (See bug 23942.) |
791 ViewHostMsg_FrameNavigate_Params params1a; | 816 ViewHostMsg_FrameNavigate_Params params1a; |
792 InitNavigateParams(¶ms1a, 2, GURL("http://www.google.com/foo"), | 817 InitNavigateParams(¶ms1a, 2, GURL("http://www.google.com/foo"), |
793 PageTransition::TYPED); | 818 content::PAGE_TRANSITION_TYPED); |
794 orig_rvh->SendNavigate(2, GURL("http://www.google.com/foo")); | 819 orig_rvh->SendNavigate(2, GURL("http://www.google.com/foo")); |
795 | 820 |
796 // Verify that the pending navigation is still in progress. | 821 // Verify that the pending navigation is still in progress. |
797 EXPECT_TRUE(contents()->cross_navigation_pending()); | 822 EXPECT_TRUE(contents()->cross_navigation_pending()); |
798 EXPECT_TRUE(contents()->pending_rvh() != NULL); | 823 EXPECT_TRUE(contents()->pending_rvh() != NULL); |
799 | 824 |
800 // DidNavigate from the pending page should commit it. | 825 // DidNavigate from the pending page should commit it. |
801 ViewHostMsg_FrameNavigate_Params params2; | 826 ViewHostMsg_FrameNavigate_Params params2; |
802 InitNavigateParams(¶ms2, 1, url2, PageTransition::TYPED); | 827 InitNavigateParams(¶ms2, 1, url2, content::PAGE_TRANSITION_TYPED); |
803 contents()->TestDidNavigate(pending_rvh, params2); | 828 contents()->TestDidNavigate(pending_rvh, params2); |
804 SiteInstance* instance2 = contents()->GetSiteInstance(); | 829 SiteInstance* instance2 = contents()->GetSiteInstance(); |
805 EXPECT_FALSE(contents()->cross_navigation_pending()); | 830 EXPECT_FALSE(contents()->cross_navigation_pending()); |
806 EXPECT_EQ(pending_rvh, rvh()); | 831 EXPECT_EQ(pending_rvh, rvh()); |
807 EXPECT_NE(instance1, instance2); | 832 EXPECT_NE(instance1, instance2); |
808 EXPECT_TRUE(contents()->pending_rvh() == NULL); | 833 EXPECT_TRUE(contents()->pending_rvh() == NULL); |
809 } | 834 } |
810 | 835 |
811 // Test that a cross-site navigation that doesn't commit after the unload | 836 // Test that a cross-site navigation that doesn't commit after the unload |
812 // handler doesn't leave the tab in a stuck state. http://crbug.com/88562. | 837 // handler doesn't leave the tab in a stuck state. http://crbug.com/88562. |
813 TEST_F(TabContentsTest, CrossSiteNavigationCanceled) { | 838 TEST_F(TabContentsTest, CrossSiteNavigationCanceled) { |
814 contents()->transition_cross_site = true; | 839 contents()->transition_cross_site = true; |
815 TestRenderViewHost* orig_rvh = rvh(); | 840 TestRenderViewHost* orig_rvh = rvh(); |
816 SiteInstance* instance1 = contents()->GetSiteInstance(); | 841 SiteInstance* instance1 = contents()->GetSiteInstance(); |
817 | 842 |
818 // Navigate to URL. First URL should use first RenderViewHost. | 843 // Navigate to URL. First URL should use first RenderViewHost. |
819 const GURL url("http://www.google.com"); | 844 const GURL url("http://www.google.com"); |
820 controller().LoadURL(url, GURL(), PageTransition::TYPED, std::string()); | 845 controller().LoadURL( |
| 846 url, GURL(), content::PAGE_TRANSITION_TYPED, std::string()); |
821 ViewHostMsg_FrameNavigate_Params params1; | 847 ViewHostMsg_FrameNavigate_Params params1; |
822 InitNavigateParams(¶ms1, 1, url, PageTransition::TYPED); | 848 InitNavigateParams(¶ms1, 1, url, content::PAGE_TRANSITION_TYPED); |
823 contents()->TestDidNavigate(orig_rvh, params1); | 849 contents()->TestDidNavigate(orig_rvh, params1); |
824 EXPECT_FALSE(contents()->cross_navigation_pending()); | 850 EXPECT_FALSE(contents()->cross_navigation_pending()); |
825 EXPECT_EQ(orig_rvh, contents()->render_view_host()); | 851 EXPECT_EQ(orig_rvh, contents()->render_view_host()); |
826 | 852 |
827 // Navigate to new site, simulating an onbeforeunload approval. | 853 // Navigate to new site, simulating an onbeforeunload approval. |
828 const GURL url2("http://www.yahoo.com"); | 854 const GURL url2("http://www.yahoo.com"); |
829 controller().LoadURL(url2, GURL(), PageTransition::TYPED, std::string()); | 855 controller().LoadURL( |
| 856 url2, GURL(), content::PAGE_TRANSITION_TYPED, std::string()); |
830 EXPECT_TRUE(orig_rvh->is_waiting_for_beforeunload_ack()); | 857 EXPECT_TRUE(orig_rvh->is_waiting_for_beforeunload_ack()); |
831 orig_rvh->TestOnMessageReceived(ViewHostMsg_ShouldClose_ACK(0, true)); | 858 orig_rvh->TestOnMessageReceived(ViewHostMsg_ShouldClose_ACK(0, true)); |
832 EXPECT_TRUE(contents()->cross_navigation_pending()); | 859 EXPECT_TRUE(contents()->cross_navigation_pending()); |
833 | 860 |
834 // Simulate swap out message when the response arrives. | 861 // Simulate swap out message when the response arrives. |
835 orig_rvh->set_is_swapped_out(true); | 862 orig_rvh->set_is_swapped_out(true); |
836 | 863 |
837 // Suppose the navigation doesn't get a chance to commit, and the user | 864 // Suppose the navigation doesn't get a chance to commit, and the user |
838 // navigates in the current RVH's SiteInstance. | 865 // navigates in the current RVH's SiteInstance. |
839 controller().LoadURL(url, GURL(), PageTransition::TYPED, std::string()); | 866 controller().LoadURL( |
| 867 url, GURL(), content::PAGE_TRANSITION_TYPED, std::string()); |
840 | 868 |
841 // Verify that the pending navigation is cancelled and the renderer is no | 869 // Verify that the pending navigation is cancelled and the renderer is no |
842 // longer swapped out. | 870 // longer swapped out. |
843 EXPECT_FALSE(orig_rvh->is_waiting_for_beforeunload_ack()); | 871 EXPECT_FALSE(orig_rvh->is_waiting_for_beforeunload_ack()); |
844 SiteInstance* instance2 = contents()->GetSiteInstance(); | 872 SiteInstance* instance2 = contents()->GetSiteInstance(); |
845 EXPECT_FALSE(contents()->cross_navigation_pending()); | 873 EXPECT_FALSE(contents()->cross_navigation_pending()); |
846 EXPECT_EQ(orig_rvh, rvh()); | 874 EXPECT_EQ(orig_rvh, rvh()); |
847 EXPECT_FALSE(orig_rvh->is_swapped_out()); | 875 EXPECT_FALSE(orig_rvh->is_swapped_out()); |
848 EXPECT_EQ(instance1, instance2); | 876 EXPECT_EQ(instance1, instance2); |
849 EXPECT_TRUE(contents()->pending_rvh() == NULL); | 877 EXPECT_TRUE(contents()->pending_rvh() == NULL); |
850 } | 878 } |
851 | 879 |
852 // Test that NavigationEntries have the correct content state after going | 880 // Test that NavigationEntries have the correct content state after going |
853 // forward and back. Prevents regression for bug 1116137. | 881 // forward and back. Prevents regression for bug 1116137. |
854 TEST_F(TabContentsTest, NavigationEntryContentState) { | 882 TEST_F(TabContentsTest, NavigationEntryContentState) { |
855 TestRenderViewHost* orig_rvh = rvh(); | 883 TestRenderViewHost* orig_rvh = rvh(); |
856 | 884 |
857 // Navigate to URL. There should be no committed entry yet. | 885 // Navigate to URL. There should be no committed entry yet. |
858 const GURL url("http://www.google.com"); | 886 const GURL url("http://www.google.com"); |
859 controller().LoadURL(url, GURL(), PageTransition::TYPED, std::string()); | 887 controller().LoadURL( |
| 888 url, GURL(), content::PAGE_TRANSITION_TYPED, std::string()); |
860 NavigationEntry* entry = controller().GetLastCommittedEntry(); | 889 NavigationEntry* entry = controller().GetLastCommittedEntry(); |
861 EXPECT_TRUE(entry == NULL); | 890 EXPECT_TRUE(entry == NULL); |
862 | 891 |
863 // Committed entry should have content state after DidNavigate. | 892 // Committed entry should have content state after DidNavigate. |
864 ViewHostMsg_FrameNavigate_Params params1; | 893 ViewHostMsg_FrameNavigate_Params params1; |
865 InitNavigateParams(¶ms1, 1, url, PageTransition::TYPED); | 894 InitNavigateParams(¶ms1, 1, url, content::PAGE_TRANSITION_TYPED); |
866 contents()->TestDidNavigate(orig_rvh, params1); | 895 contents()->TestDidNavigate(orig_rvh, params1); |
867 entry = controller().GetLastCommittedEntry(); | 896 entry = controller().GetLastCommittedEntry(); |
868 EXPECT_FALSE(entry->content_state().empty()); | 897 EXPECT_FALSE(entry->content_state().empty()); |
869 | 898 |
870 // Navigate to same site. | 899 // Navigate to same site. |
871 const GURL url2("http://images.google.com"); | 900 const GURL url2("http://images.google.com"); |
872 controller().LoadURL(url2, GURL(), PageTransition::TYPED, std::string()); | 901 controller().LoadURL( |
| 902 url2, GURL(), content::PAGE_TRANSITION_TYPED, std::string()); |
873 entry = controller().GetLastCommittedEntry(); | 903 entry = controller().GetLastCommittedEntry(); |
874 EXPECT_FALSE(entry->content_state().empty()); | 904 EXPECT_FALSE(entry->content_state().empty()); |
875 | 905 |
876 // Committed entry should have content state after DidNavigate. | 906 // Committed entry should have content state after DidNavigate. |
877 ViewHostMsg_FrameNavigate_Params params2; | 907 ViewHostMsg_FrameNavigate_Params params2; |
878 InitNavigateParams(¶ms2, 2, url2, PageTransition::TYPED); | 908 InitNavigateParams(¶ms2, 2, url2, content::PAGE_TRANSITION_TYPED); |
879 contents()->TestDidNavigate(orig_rvh, params2); | 909 contents()->TestDidNavigate(orig_rvh, params2); |
880 entry = controller().GetLastCommittedEntry(); | 910 entry = controller().GetLastCommittedEntry(); |
881 EXPECT_FALSE(entry->content_state().empty()); | 911 EXPECT_FALSE(entry->content_state().empty()); |
882 | 912 |
883 // Now go back. Committed entry should still have content state. | 913 // Now go back. Committed entry should still have content state. |
884 controller().GoBack(); | 914 controller().GoBack(); |
885 contents()->TestDidNavigate(orig_rvh, params1); | 915 contents()->TestDidNavigate(orig_rvh, params1); |
886 entry = controller().GetLastCommittedEntry(); | 916 entry = controller().GetLastCommittedEntry(); |
887 EXPECT_FALSE(entry->content_state().empty()); | 917 EXPECT_FALSE(entry->content_state().empty()); |
888 } | 918 } |
889 | 919 |
890 // Test that NavigationEntries have the correct content state after opening | 920 // Test that NavigationEntries have the correct content state after opening |
891 // a new window to about:blank. Prevents regression for bug 1116137. | 921 // a new window to about:blank. Prevents regression for bug 1116137. |
892 TEST_F(TabContentsTest, NavigationEntryContentStateNewWindow) { | 922 TEST_F(TabContentsTest, NavigationEntryContentStateNewWindow) { |
893 TestRenderViewHost* orig_rvh = rvh(); | 923 TestRenderViewHost* orig_rvh = rvh(); |
894 | 924 |
895 // When opening a new window, it is navigated to about:blank internally. | 925 // When opening a new window, it is navigated to about:blank internally. |
896 // Currently, this results in two DidNavigate events. | 926 // Currently, this results in two DidNavigate events. |
897 const GURL url(chrome::kAboutBlankURL); | 927 const GURL url(chrome::kAboutBlankURL); |
898 ViewHostMsg_FrameNavigate_Params params1; | 928 ViewHostMsg_FrameNavigate_Params params1; |
899 InitNavigateParams(¶ms1, 1, url, PageTransition::TYPED); | 929 InitNavigateParams(¶ms1, 1, url, content::PAGE_TRANSITION_TYPED); |
900 contents()->TestDidNavigate(orig_rvh, params1); | 930 contents()->TestDidNavigate(orig_rvh, params1); |
901 contents()->TestDidNavigate(orig_rvh, params1); | 931 contents()->TestDidNavigate(orig_rvh, params1); |
902 | 932 |
903 // Should have a content state here. | 933 // Should have a content state here. |
904 NavigationEntry* entry = controller().GetLastCommittedEntry(); | 934 NavigationEntry* entry = controller().GetLastCommittedEntry(); |
905 EXPECT_FALSE(entry->content_state().empty()); | 935 EXPECT_FALSE(entry->content_state().empty()); |
906 } | 936 } |
907 | 937 |
908 // Tests to see that webkit preferences are properly loaded and copied over | 938 // Tests to see that webkit preferences are properly loaded and copied over |
909 // to a WebPreferences object. | 939 // to a WebPreferences object. |
(...skipping 27 matching lines...) Expand all Loading... |
937 // creates a new navigation entry, then hiding it without proceeding. | 967 // creates a new navigation entry, then hiding it without proceeding. |
938 TEST_F(TabContentsTest, | 968 TEST_F(TabContentsTest, |
939 ShowInterstitialFromBrowserWithNewNavigationDontProceed) { | 969 ShowInterstitialFromBrowserWithNewNavigationDontProceed) { |
940 // Navigate to a page. | 970 // Navigate to a page. |
941 GURL url1("http://www.google.com"); | 971 GURL url1("http://www.google.com"); |
942 rvh()->SendNavigate(1, url1); | 972 rvh()->SendNavigate(1, url1); |
943 EXPECT_EQ(1, controller().entry_count()); | 973 EXPECT_EQ(1, controller().entry_count()); |
944 | 974 |
945 // Initiate a browser navigation that will trigger the interstitial | 975 // Initiate a browser navigation that will trigger the interstitial |
946 controller().LoadURL(GURL("http://www.evil.com"), GURL(), | 976 controller().LoadURL(GURL("http://www.evil.com"), GURL(), |
947 PageTransition::TYPED, std::string()); | 977 content::PAGE_TRANSITION_TYPED, std::string()); |
948 | 978 |
949 // Show an interstitial. | 979 // Show an interstitial. |
950 TestInterstitialPage::InterstitialState state = | 980 TestInterstitialPage::InterstitialState state = |
951 TestInterstitialPage::UNDECIDED; | 981 TestInterstitialPage::UNDECIDED; |
952 bool deleted = false; | 982 bool deleted = false; |
953 GURL url2("http://interstitial"); | 983 GURL url2("http://interstitial"); |
954 TestInterstitialPage* interstitial = | 984 TestInterstitialPage* interstitial = |
955 new TestInterstitialPage(contents(), true, url2, &state, &deleted); | 985 new TestInterstitialPage(contents(), true, url2, &state, &deleted); |
956 TestInterstitialPageStateGuard state_guard(interstitial); | 986 TestInterstitialPageStateGuard state_guard(interstitial); |
957 interstitial->Show(); | 987 interstitial->Show(); |
(...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1074 // creates a new navigation entry, then proceeding. | 1104 // creates a new navigation entry, then proceeding. |
1075 TEST_F(TabContentsTest, | 1105 TEST_F(TabContentsTest, |
1076 ShowInterstitialFromBrowserNewNavigationProceed) { | 1106 ShowInterstitialFromBrowserNewNavigationProceed) { |
1077 // Navigate to a page. | 1107 // Navigate to a page. |
1078 GURL url1("http://www.google.com"); | 1108 GURL url1("http://www.google.com"); |
1079 rvh()->SendNavigate(1, url1); | 1109 rvh()->SendNavigate(1, url1); |
1080 EXPECT_EQ(1, controller().entry_count()); | 1110 EXPECT_EQ(1, controller().entry_count()); |
1081 | 1111 |
1082 // Initiate a browser navigation that will trigger the interstitial | 1112 // Initiate a browser navigation that will trigger the interstitial |
1083 controller().LoadURL(GURL("http://www.evil.com"), GURL(), | 1113 controller().LoadURL(GURL("http://www.evil.com"), GURL(), |
1084 PageTransition::TYPED, std::string()); | 1114 content::PAGE_TRANSITION_TYPED, std::string()); |
1085 | 1115 |
1086 // Show an interstitial. | 1116 // Show an interstitial. |
1087 TestInterstitialPage::InterstitialState state = | 1117 TestInterstitialPage::InterstitialState state = |
1088 TestInterstitialPage::UNDECIDED; | 1118 TestInterstitialPage::UNDECIDED; |
1089 bool deleted = false; | 1119 bool deleted = false; |
1090 GURL url2("http://interstitial"); | 1120 GURL url2("http://interstitial"); |
1091 TestInterstitialPage* interstitial = | 1121 TestInterstitialPage* interstitial = |
1092 new TestInterstitialPage(contents(), true, url2, &state, &deleted); | 1122 new TestInterstitialPage(contents(), true, url2, &state, &deleted); |
1093 TestInterstitialPageStateGuard state_guard(interstitial); | 1123 TestInterstitialPageStateGuard state_guard(interstitial); |
1094 interstitial->Show(); | 1124 interstitial->Show(); |
(...skipping 421 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1516 GURL interstitial_url("http://interstitial"); | 1546 GURL interstitial_url("http://interstitial"); |
1517 TestInterstitialPage* interstitial = | 1547 TestInterstitialPage* interstitial = |
1518 new TestInterstitialPage(contents(), true, interstitial_url, | 1548 new TestInterstitialPage(contents(), true, interstitial_url, |
1519 &state, &deleted); | 1549 &state, &deleted); |
1520 TestInterstitialPageStateGuard state_guard(interstitial); | 1550 TestInterstitialPageStateGuard state_guard(interstitial); |
1521 interstitial->Show(); | 1551 interstitial->Show(); |
1522 | 1552 |
1523 // Let's simulate a navigation initiated from the browser before the | 1553 // Let's simulate a navigation initiated from the browser before the |
1524 // interstitial finishes loading. | 1554 // interstitial finishes loading. |
1525 const GURL url("http://www.google.com"); | 1555 const GURL url("http://www.google.com"); |
1526 controller().LoadURL(url, GURL(), PageTransition::TYPED, std::string()); | 1556 controller().LoadURL( |
| 1557 url, GURL(), content::PAGE_TRANSITION_TYPED, std::string()); |
1527 ASSERT_FALSE(deleted); | 1558 ASSERT_FALSE(deleted); |
1528 EXPECT_FALSE(interstitial->is_showing()); | 1559 EXPECT_FALSE(interstitial->is_showing()); |
1529 | 1560 |
1530 // Now let's make the interstitial navigation commit. | 1561 // Now let's make the interstitial navigation commit. |
1531 interstitial->TestDidNavigate(1, interstitial_url); | 1562 interstitial->TestDidNavigate(1, interstitial_url); |
1532 | 1563 |
1533 // After it loaded the interstitial should be gone. | 1564 // After it loaded the interstitial should be gone. |
1534 EXPECT_TRUE(deleted); | 1565 EXPECT_TRUE(deleted); |
1535 EXPECT_EQ(TestInterstitialPage::CANCELED, state); | 1566 EXPECT_EQ(TestInterstitialPage::CANCELED, state); |
1536 } | 1567 } |
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1606 } | 1637 } |
1607 | 1638 |
1608 // Tests that showing an interstitial as a result of a browser initiated | 1639 // Tests that showing an interstitial as a result of a browser initiated |
1609 // navigation while an interstitial is showing does not remove the pending | 1640 // navigation while an interstitial is showing does not remove the pending |
1610 // entry (see http://crbug.com/9791). | 1641 // entry (see http://crbug.com/9791). |
1611 TEST_F(TabContentsTest, NewInterstitialDoesNotCancelPendingEntry) { | 1642 TEST_F(TabContentsTest, NewInterstitialDoesNotCancelPendingEntry) { |
1612 const char kUrl[] = "http://www.badguys.com/"; | 1643 const char kUrl[] = "http://www.badguys.com/"; |
1613 const GURL kGURL(kUrl); | 1644 const GURL kGURL(kUrl); |
1614 | 1645 |
1615 // Start a navigation to a page | 1646 // Start a navigation to a page |
1616 contents()->controller().LoadURL(kGURL, GURL(), PageTransition::TYPED, | 1647 contents()->controller().LoadURL( |
1617 std::string()); | 1648 kGURL, GURL(), content::PAGE_TRANSITION_TYPED, std::string()); |
1618 | 1649 |
1619 // Simulate that navigation triggering an interstitial. | 1650 // Simulate that navigation triggering an interstitial. |
1620 TestInterstitialPage::InterstitialState state = | 1651 TestInterstitialPage::InterstitialState state = |
1621 TestInterstitialPage::UNDECIDED; | 1652 TestInterstitialPage::UNDECIDED; |
1622 bool deleted = false; | 1653 bool deleted = false; |
1623 TestInterstitialPage* interstitial = | 1654 TestInterstitialPage* interstitial = |
1624 new TestInterstitialPage(contents(), true, kGURL, &state, &deleted); | 1655 new TestInterstitialPage(contents(), true, kGURL, &state, &deleted); |
1625 TestInterstitialPageStateGuard state_guard(interstitial); | 1656 TestInterstitialPageStateGuard state_guard(interstitial); |
1626 interstitial->Show(); | 1657 interstitial->Show(); |
1627 interstitial->TestDidNavigate(1, kGURL); | 1658 interstitial->TestDidNavigate(1, kGURL); |
1628 | 1659 |
1629 // Initiate a new navigation from the browser that also triggers an | 1660 // Initiate a new navigation from the browser that also triggers an |
1630 // interstitial. | 1661 // interstitial. |
1631 contents()->controller().LoadURL(kGURL, GURL(), PageTransition::TYPED, | 1662 contents()->controller().LoadURL( |
1632 std::string()); | 1663 kGURL, GURL(), content::PAGE_TRANSITION_TYPED, std::string()); |
1633 TestInterstitialPage::InterstitialState state2 = | 1664 TestInterstitialPage::InterstitialState state2 = |
1634 TestInterstitialPage::UNDECIDED; | 1665 TestInterstitialPage::UNDECIDED; |
1635 bool deleted2 = false; | 1666 bool deleted2 = false; |
1636 TestInterstitialPage* interstitial2 = | 1667 TestInterstitialPage* interstitial2 = |
1637 new TestInterstitialPage(contents(), true, kGURL, &state, &deleted); | 1668 new TestInterstitialPage(contents(), true, kGURL, &state, &deleted); |
1638 TestInterstitialPageStateGuard state_guard2(interstitial2); | 1669 TestInterstitialPageStateGuard state_guard2(interstitial2); |
1639 interstitial2->Show(); | 1670 interstitial2->Show(); |
1640 interstitial2->TestDidNavigate(1, kGURL); | 1671 interstitial2->TestDidNavigate(1, kGURL); |
1641 | 1672 |
1642 // Make sure we still have an entry. | 1673 // Make sure we still have an entry. |
1643 NavigationEntry* entry = contents()->controller().pending_entry(); | 1674 NavigationEntry* entry = contents()->controller().pending_entry(); |
1644 ASSERT_TRUE(entry); | 1675 ASSERT_TRUE(entry); |
1645 EXPECT_EQ(kUrl, entry->url().spec()); | 1676 EXPECT_EQ(kUrl, entry->url().spec()); |
1646 | 1677 |
1647 // And that the first interstitial is gone, but not the second. | 1678 // And that the first interstitial is gone, but not the second. |
1648 EXPECT_TRUE(deleted); | 1679 EXPECT_TRUE(deleted); |
1649 EXPECT_EQ(TestInterstitialPage::CANCELED, state); | 1680 EXPECT_EQ(TestInterstitialPage::CANCELED, state); |
1650 EXPECT_FALSE(deleted2); | 1681 EXPECT_FALSE(deleted2); |
1651 EXPECT_EQ(TestInterstitialPage::UNDECIDED, state2); | 1682 EXPECT_EQ(TestInterstitialPage::UNDECIDED, state2); |
1652 } | 1683 } |
1653 | 1684 |
1654 // Tests that Javascript messages are not shown while an interstitial is | 1685 // Tests that Javascript messages are not shown while an interstitial is |
1655 // showing. | 1686 // showing. |
1656 TEST_F(TabContentsTest, NoJSMessageOnInterstitials) { | 1687 TEST_F(TabContentsTest, NoJSMessageOnInterstitials) { |
1657 const char kUrl[] = "http://www.badguys.com/"; | 1688 const char kUrl[] = "http://www.badguys.com/"; |
1658 const GURL kGURL(kUrl); | 1689 const GURL kGURL(kUrl); |
1659 | 1690 |
1660 // Start a navigation to a page | 1691 // Start a navigation to a page |
1661 contents()->controller().LoadURL(kGURL, GURL(), PageTransition::TYPED, | 1692 contents()->controller().LoadURL( |
1662 std::string()); | 1693 kGURL, GURL(), content::PAGE_TRANSITION_TYPED, std::string()); |
1663 // DidNavigate from the page | 1694 // DidNavigate from the page |
1664 ViewHostMsg_FrameNavigate_Params params; | 1695 ViewHostMsg_FrameNavigate_Params params; |
1665 InitNavigateParams(¶ms, 1, kGURL, PageTransition::TYPED); | 1696 InitNavigateParams(¶ms, 1, kGURL, content::PAGE_TRANSITION_TYPED); |
1666 contents()->TestDidNavigate(rvh(), params); | 1697 contents()->TestDidNavigate(rvh(), params); |
1667 | 1698 |
1668 // Simulate showing an interstitial while the page is showing. | 1699 // Simulate showing an interstitial while the page is showing. |
1669 TestInterstitialPage::InterstitialState state = | 1700 TestInterstitialPage::InterstitialState state = |
1670 TestInterstitialPage::UNDECIDED; | 1701 TestInterstitialPage::UNDECIDED; |
1671 bool deleted = false; | 1702 bool deleted = false; |
1672 TestInterstitialPage* interstitial = | 1703 TestInterstitialPage* interstitial = |
1673 new TestInterstitialPage(contents(), true, kGURL, &state, &deleted); | 1704 new TestInterstitialPage(contents(), true, kGURL, &state, &deleted); |
1674 TestInterstitialPageStateGuard state_guard(interstitial); | 1705 TestInterstitialPageStateGuard state_guard(interstitial); |
1675 interstitial->Show(); | 1706 interstitial->Show(); |
(...skipping 13 matching lines...) Expand all Loading... |
1689 // Makes sure that if the source passed to CopyStateFromAndPrune has an | 1720 // Makes sure that if the source passed to CopyStateFromAndPrune has an |
1690 // interstitial it isn't copied over to the destination. | 1721 // interstitial it isn't copied over to the destination. |
1691 TEST_F(TabContentsTest, CopyStateFromAndPruneSourceInterstitial) { | 1722 TEST_F(TabContentsTest, CopyStateFromAndPruneSourceInterstitial) { |
1692 // Navigate to a page. | 1723 // Navigate to a page. |
1693 GURL url1("http://www.google.com"); | 1724 GURL url1("http://www.google.com"); |
1694 rvh()->SendNavigate(1, url1); | 1725 rvh()->SendNavigate(1, url1); |
1695 EXPECT_EQ(1, controller().entry_count()); | 1726 EXPECT_EQ(1, controller().entry_count()); |
1696 | 1727 |
1697 // Initiate a browser navigation that will trigger the interstitial | 1728 // Initiate a browser navigation that will trigger the interstitial |
1698 controller().LoadURL(GURL("http://www.evil.com"), GURL(), | 1729 controller().LoadURL(GURL("http://www.evil.com"), GURL(), |
1699 PageTransition::TYPED, std::string()); | 1730 content::PAGE_TRANSITION_TYPED, std::string()); |
1700 | 1731 |
1701 // Show an interstitial. | 1732 // Show an interstitial. |
1702 TestInterstitialPage::InterstitialState state = | 1733 TestInterstitialPage::InterstitialState state = |
1703 TestInterstitialPage::UNDECIDED; | 1734 TestInterstitialPage::UNDECIDED; |
1704 bool deleted = false; | 1735 bool deleted = false; |
1705 GURL url2("http://interstitial"); | 1736 GURL url2("http://interstitial"); |
1706 TestInterstitialPage* interstitial = | 1737 TestInterstitialPage* interstitial = |
1707 new TestInterstitialPage(contents(), true, url2, &state, &deleted); | 1738 new TestInterstitialPage(contents(), true, url2, &state, &deleted); |
1708 TestInterstitialPageStateGuard state_guard(interstitial); | 1739 TestInterstitialPageStateGuard state_guard(interstitial); |
1709 interstitial->Show(); | 1740 interstitial->Show(); |
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1772 | 1803 |
1773 // It should have a transient entry. | 1804 // It should have a transient entry. |
1774 EXPECT_TRUE(other_controller.GetTransientEntry()); | 1805 EXPECT_TRUE(other_controller.GetTransientEntry()); |
1775 | 1806 |
1776 // And the interstitial should be showing. | 1807 // And the interstitial should be showing. |
1777 EXPECT_TRUE(other_contents->showing_interstitial_page()); | 1808 EXPECT_TRUE(other_contents->showing_interstitial_page()); |
1778 | 1809 |
1779 // And the interstitial should do a reload on don't proceed. | 1810 // And the interstitial should do a reload on don't proceed. |
1780 EXPECT_TRUE(other_contents->interstitial_page()->reload_on_dont_proceed()); | 1811 EXPECT_TRUE(other_contents->interstitial_page()->reload_on_dont_proceed()); |
1781 } | 1812 } |
OLD | NEW |