Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(160)

Side by Side Diff: chrome/browser/tab_contents/web_contents_unittest.cc

Issue 18432: Factor out the test web contents from the WebContents unit test so that it ca... (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 11 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « chrome/browser/tab_contents/test_web_contents.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2006-2008 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 "chrome/browser/render_view_host.h" 6 #include "chrome/browser/render_view_host.h"
7 #include "chrome/browser/renderer_host/test_render_view_host.h" 7 #include "chrome/browser/renderer_host/test_render_view_host.h"
8 #include "chrome/browser/render_widget_host_view.h" 8 #include "chrome/browser/render_widget_host_view.h"
9 #include "chrome/browser/tab_contents/interstitial_page.h" 9 #include "chrome/browser/tab_contents/interstitial_page.h"
10 #include "chrome/browser/tab_contents/navigation_controller.h" 10 #include "chrome/browser/tab_contents/navigation_controller.h"
11 #include "chrome/browser/tab_contents/navigation_entry.h" 11 #include "chrome/browser/tab_contents/navigation_entry.h"
12 #include "chrome/browser/tab_contents/web_contents.h" 12 #include "chrome/browser/tab_contents/test_web_contents.h"
13 #include "chrome/common/chrome_paths.h" 13 #include "chrome/common/chrome_paths.h"
14 #include "chrome/common/ipc_channel.h" 14 #include "chrome/common/ipc_channel.h"
15 #include "chrome/common/pref_service.h" 15 #include "chrome/common/pref_service.h"
16 #include "chrome/common/render_messages.h" 16 #include "chrome/common/render_messages.h"
17 #include "chrome/test/testing_profile.h" 17 #include "chrome/test/testing_profile.h"
18 #include "testing/gtest/include/gtest/gtest.h" 18 #include "testing/gtest/include/gtest/gtest.h"
19 19
20 static void InitNavigateParams(ViewHostMsg_FrameNavigate_Params* params, 20 static void InitNavigateParams(ViewHostMsg_FrameNavigate_Params* params,
21 int page_id, 21 int page_id,
22 const GURL& url) { 22 const GURL& url) {
(...skipping 26 matching lines...) Expand all
49 file_util::AppendToPath(&source_path, L"Preferences"); 49 file_util::AppendToPath(&source_path, L"Preferences");
50 50
51 prefs_.reset(new PrefService(source_path)); 51 prefs_.reset(new PrefService(source_path));
52 Profile::RegisterUserPrefs(prefs_.get()); 52 Profile::RegisterUserPrefs(prefs_.get());
53 browser::RegisterAllPrefs(prefs_.get(), prefs_.get()); 53 browser::RegisterAllPrefs(prefs_.get(), prefs_.get());
54 } 54 }
55 return prefs_.get(); 55 return prefs_.get();
56 } 56 }
57 }; 57 };
58 58
59 // Subclass WebContents to ensure it creates TestRenderViewHosts and does
60 // not do anything involving views.
61 //
62 // TODO(brettw) merge this with the TestRenderProcessHost to it can be used by
63 // other tests as well.
64 class TestWebContents : public WebContents {
65 public:
66 TestWebContents(Profile* profile, SiteInstance* instance)
67 : WebContents(profile,
68 instance,
69 TestRenderViewHostFactory::GetInstance(),
70 MSG_ROUTING_NONE,
71 NULL),
72 transition_cross_site(false) {}
73
74 // Accessors for interesting fields
75 TestRenderViewHost* rvh() {
76 return static_cast<TestRenderViewHost*>(
77 render_manager_.render_view_host_);
78 }
79 TestRenderViewHost* pending_rvh() {
80 return static_cast<TestRenderViewHost*>(
81 render_manager_.pending_render_view_host_);
82 }
83
84 // State accessor.
85 bool cross_navigation_pending() {
86 return render_manager_.cross_navigation_pending_;
87 }
88
89 // Overrides WebContents::ShouldTransitionCrossSite so that we can test both
90 // alternatives without using command-line switches.
91 bool ShouldTransitionCrossSite() { return transition_cross_site; }
92
93 // Promote DidNavigate to public.
94 void TestDidNavigate(TestRenderViewHost* render_view_host,
95 const ViewHostMsg_FrameNavigate_Params& params) {
96 DidNavigate(render_view_host, params);
97 }
98
99 // Promote GetWebkitPrefs to public.
100 WebPreferences TestGetWebkitPrefs() {
101 return GetWebkitPrefs();
102 }
103
104 // Prevent interaction with views.
105 bool CreateRenderViewForRenderManager(RenderViewHost* render_view_host) {
106 // This will go to a TestRenderViewHost.
107 render_view_host->CreateRenderView();
108 return true;
109 }
110 void UpdateRenderViewSizeForRenderManager() {}
111
112 // Set by individual tests.
113 bool transition_cross_site;
114 };
115
116 class TestInterstitialPage : public InterstitialPage { 59 class TestInterstitialPage : public InterstitialPage {
117 public: 60 public:
118 enum InterstitialState { 61 enum InterstitialState {
119 UNDECIDED = 0, // No decision taken yet. 62 UNDECIDED = 0, // No decision taken yet.
120 OKED, // Proceed was called. 63 OKED, // Proceed was called.
121 CANCELED // DontProceed was called. 64 CANCELED // DontProceed was called.
122 }; 65 };
123 66
124 class Delegate { 67 class Delegate {
125 public: 68 public:
(...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after
234 177
235 virtual void TestInterstitialPageDeleted(TestInterstitialPage* interstitial) { 178 virtual void TestInterstitialPageDeleted(TestInterstitialPage* interstitial) {
236 DCHECK(interstitial_page_ == interstitial); 179 DCHECK(interstitial_page_ == interstitial);
237 interstitial_page_ = NULL; 180 interstitial_page_ = NULL;
238 } 181 }
239 182
240 private: 183 private:
241 TestInterstitialPage* interstitial_page_; 184 TestInterstitialPage* interstitial_page_;
242 }; 185 };
243 186
244 class WebContentsTest : public testing::Test { 187 class WebContentsTest : public RenderViewHostTestHarness {
245 public: 188 public:
246 WebContentsTest() : contents(NULL) {} 189 WebContentsTest() : RenderViewHostTestHarness() {
247
248 // testing::Test methods:
249
250 virtual void SetUp() {
251 profile.reset(new WebContentsTestingProfile());
252
253 // This will be deleted when the WebContents goes away
254 SiteInstance* instance = SiteInstance::CreateSiteInstance(profile.get());
255
256 contents = new TestWebContents(profile.get(), instance);
257 contents->SetupController(profile.get());
258 } 190 }
259 191
260 virtual void TearDown() { 192 private:
261 // This will delete the contents. 193 // Supply our own profile so we use the correct profile data. The test harness
262 if (contents) 194 // is not supposed to overwrite an profile if it's already created.
263 contents->CloseContents(); 195 virtual void SetUp() {
264 196 profile_.reset(new WebContentsTestingProfile());
265 // Make sure that we flush any messages related to WebContents destruction 197 RenderViewHostTestHarness::SetUp();
266 // before we destroy the profile.
267 MessageLoop::current()->RunAllPending();
268 } 198 }
269
270 void Navigate(int page_id, const GURL& url) {
271 DCHECK(contents);
272 ViewHostMsg_FrameNavigate_Params params;
273 InitNavigateParams(&params, page_id, url);
274 contents->TestDidNavigate(contents->rvh(), params);
275 }
276
277 scoped_ptr<WebContentsTestingProfile> profile;
278 TestWebContents* contents;
279
280 private:
281 MessageLoopForUI message_loop_;
282 }; 199 };
283 200
284 // Test to make sure that title updates get stripped of whitespace. 201 // Test to make sure that title updates get stripped of whitespace.
285 TEST_F(WebContentsTest, UpdateTitle) { 202 TEST_F(WebContentsTest, UpdateTitle) {
286 ViewHostMsg_FrameNavigate_Params params; 203 ViewHostMsg_FrameNavigate_Params params;
287 InitNavigateParams(&params, 0, GURL("about:blank")); 204 InitNavigateParams(&params, 0, GURL("about:blank"));
288 205
289 NavigationController::LoadCommittedDetails details; 206 NavigationController::LoadCommittedDetails details;
290 contents->controller()->RendererDidNavigate(params, &details); 207 controller()->RendererDidNavigate(params, &details);
291 208
292 contents->UpdateTitle(contents->rvh(), 0, L" Lots O' Whitespace\n"); 209 contents()->UpdateTitle(rvh(), 0, L" Lots O' Whitespace\n");
293 EXPECT_EQ(std::wstring(L"Lots O' Whitespace"), contents->GetTitle()); 210 EXPECT_EQ(std::wstring(L"Lots O' Whitespace"), contents()->GetTitle());
294 } 211 }
295 212
296 // Test simple same-SiteInstance navigation. 213 // Test simple same-SiteInstance navigation.
297 TEST_F(WebContentsTest, SimpleNavigation) { 214 TEST_F(WebContentsTest, SimpleNavigation) {
298 TestRenderViewHost* orig_rvh = contents->rvh(); 215 TestRenderViewHost* orig_rvh = rvh();
299 SiteInstance* instance1 = contents->GetSiteInstance(); 216 SiteInstance* instance1 = contents()->GetSiteInstance();
300 EXPECT_TRUE(contents->pending_rvh() == NULL); 217 EXPECT_TRUE(contents()->pending_rvh() == NULL);
301 218
302 // Navigate to URL 219 // Navigate to URL
303 const GURL url("http://www.google.com"); 220 const GURL url("http://www.google.com");
304 contents->controller()->LoadURL(url, GURL(), PageTransition::TYPED); 221 controller()->LoadURL(url, GURL(), PageTransition::TYPED);
305 EXPECT_FALSE(contents->cross_navigation_pending()); 222 EXPECT_FALSE(contents()->cross_navigation_pending());
306 EXPECT_EQ(instance1, orig_rvh->site_instance()); 223 EXPECT_EQ(instance1, orig_rvh->site_instance());
307 // Controller's pending entry will have a NULL site instance until we assign 224 // Controller's pending entry will have a NULL site instance until we assign
308 // it in DidNavigate. 225 // it in DidNavigate.
309 EXPECT_TRUE( 226 EXPECT_TRUE(controller()->GetActiveEntry()->site_instance() == NULL);
310 contents->controller()->GetActiveEntry()->site_instance() == NULL);
311 227
312 // DidNavigate from the page 228 // DidNavigate from the page
313 ViewHostMsg_FrameNavigate_Params params; 229 ViewHostMsg_FrameNavigate_Params params;
314 InitNavigateParams(&params, 1, url); 230 InitNavigateParams(&params, 1, url);
315 contents->TestDidNavigate(orig_rvh, params); 231 contents()->TestDidNavigate(orig_rvh, params);
316 EXPECT_FALSE(contents->cross_navigation_pending()); 232 EXPECT_FALSE(contents()->cross_navigation_pending());
317 EXPECT_EQ(orig_rvh, contents->render_view_host()); 233 EXPECT_EQ(orig_rvh, contents()->render_view_host());
318 EXPECT_EQ(instance1, orig_rvh->site_instance()); 234 EXPECT_EQ(instance1, orig_rvh->site_instance());
319 // Controller's entry should now have the SiteInstance, or else we won't be 235 // Controller's entry should now have the SiteInstance, or else we won't be
320 // able to find it later. 236 // able to find it later.
321 EXPECT_EQ(instance1, 237 EXPECT_EQ(instance1, controller()->GetActiveEntry()->site_instance());
322 contents->controller()->GetActiveEntry()->site_instance());
323 } 238 }
324 239
325 // Test that navigating across a site boundary creates a new RenderViewHost 240 // Test that navigating across a site boundary creates a new RenderViewHost
326 // with a new SiteInstance. Going back should do the same. 241 // with a new SiteInstance. Going back should do the same.
327 TEST_F(WebContentsTest, CrossSiteBoundaries) { 242 TEST_F(WebContentsTest, CrossSiteBoundaries) {
328 contents->transition_cross_site = true; 243 contents()->transition_cross_site = true;
329 TestRenderViewHost* orig_rvh = contents->rvh(); 244 TestRenderViewHost* orig_rvh = rvh();
330 int orig_rvh_delete_count = 0; 245 int orig_rvh_delete_count = 0;
331 orig_rvh->set_delete_counter(&orig_rvh_delete_count); 246 orig_rvh->set_delete_counter(&orig_rvh_delete_count);
332 SiteInstance* instance1 = contents->GetSiteInstance(); 247 SiteInstance* instance1 = contents()->GetSiteInstance();
333 248
334 // Navigate to URL. First URL should use first RenderViewHost. 249 // Navigate to URL. First URL should use first RenderViewHost.
335 const GURL url("http://www.google.com"); 250 const GURL url("http://www.google.com");
336 contents->controller()->LoadURL(url, GURL(), PageTransition::TYPED); 251 controller()->LoadURL(url, GURL(), PageTransition::TYPED);
337 ViewHostMsg_FrameNavigate_Params params1; 252 ViewHostMsg_FrameNavigate_Params params1;
338 InitNavigateParams(&params1, 1, url); 253 InitNavigateParams(&params1, 1, url);
339 contents->TestDidNavigate(orig_rvh, params1); 254 contents()->TestDidNavigate(orig_rvh, params1);
340 255
341 EXPECT_FALSE(contents->cross_navigation_pending()); 256 EXPECT_FALSE(contents()->cross_navigation_pending());
342 EXPECT_EQ(orig_rvh, contents->render_view_host()); 257 EXPECT_EQ(orig_rvh, contents()->render_view_host());
343 258
344 // Navigate to new site 259 // Navigate to new site
345 const GURL url2("http://www.yahoo.com"); 260 const GURL url2("http://www.yahoo.com");
346 contents->controller()->LoadURL(url2, GURL(), PageTransition::TYPED); 261 controller()->LoadURL(url2, GURL(), PageTransition::TYPED);
347 EXPECT_TRUE(contents->cross_navigation_pending()); 262 EXPECT_TRUE(contents()->cross_navigation_pending());
348 TestRenderViewHost* pending_rvh = contents->pending_rvh(); 263 TestRenderViewHost* pending_rvh = contents()->pending_rvh();
349 int pending_rvh_delete_count = 0; 264 int pending_rvh_delete_count = 0;
350 pending_rvh->set_delete_counter(&pending_rvh_delete_count); 265 pending_rvh->set_delete_counter(&pending_rvh_delete_count);
351 266
352 // DidNavigate from the pending page 267 // DidNavigate from the pending page
353 ViewHostMsg_FrameNavigate_Params params2; 268 ViewHostMsg_FrameNavigate_Params params2;
354 InitNavigateParams(&params2, 1, url2); 269 InitNavigateParams(&params2, 1, url2);
355 contents->TestDidNavigate(pending_rvh, params2); 270 contents()->TestDidNavigate(pending_rvh, params2);
356 SiteInstance* instance2 = contents->GetSiteInstance(); 271 SiteInstance* instance2 = contents()->GetSiteInstance();
357 272
358 EXPECT_FALSE(contents->cross_navigation_pending()); 273 EXPECT_FALSE(contents()->cross_navigation_pending());
359 EXPECT_EQ(pending_rvh, contents->render_view_host()); 274 EXPECT_EQ(pending_rvh, contents()->render_view_host());
360 EXPECT_NE(instance1, instance2); 275 EXPECT_NE(instance1, instance2);
361 EXPECT_TRUE(contents->pending_rvh() == NULL); 276 EXPECT_TRUE(contents()->pending_rvh() == NULL);
362 EXPECT_EQ(orig_rvh_delete_count, 1); 277 EXPECT_EQ(orig_rvh_delete_count, 1);
363 278
364 // Going back should switch SiteInstances again. The first SiteInstance is 279 // Going back should switch SiteInstances again. The first SiteInstance is
365 // stored in the NavigationEntry, so it should be the same as at the start. 280 // stored in the NavigationEntry, so it should be the same as at the start.
366 contents->controller()->GoBack(); 281 controller()->GoBack();
367 TestRenderViewHost* goback_rvh = contents->pending_rvh(); 282 TestRenderViewHost* goback_rvh = contents()->pending_rvh();
368 EXPECT_TRUE(contents->cross_navigation_pending()); 283 EXPECT_TRUE(contents()->cross_navigation_pending());
369 284
370 // DidNavigate from the back action 285 // DidNavigate from the back action
371 contents->TestDidNavigate(goback_rvh, params1); 286 contents()->TestDidNavigate(goback_rvh, params1);
372 EXPECT_FALSE(contents->cross_navigation_pending()); 287 EXPECT_FALSE(contents()->cross_navigation_pending());
373 EXPECT_EQ(goback_rvh, contents->render_view_host()); 288 EXPECT_EQ(goback_rvh, contents()->render_view_host());
374 EXPECT_EQ(pending_rvh_delete_count, 1); 289 EXPECT_EQ(pending_rvh_delete_count, 1);
375 EXPECT_EQ(instance1, contents->GetSiteInstance()); 290 EXPECT_EQ(instance1, contents()->GetSiteInstance());
376 } 291 }
377 292
378 // Test that navigating across a site boundary after a crash creates a new 293 // Test that navigating across a site boundary after a crash creates a new
379 // RVH without requiring a cross-site transition (i.e., PENDING state). 294 // RVH without requiring a cross-site transition (i.e., PENDING state).
380 TEST_F(WebContentsTest, CrossSiteBoundariesAfterCrash) { 295 TEST_F(WebContentsTest, CrossSiteBoundariesAfterCrash) {
381 contents->transition_cross_site = true; 296 contents()->transition_cross_site = true;
382 TestRenderViewHost* orig_rvh = contents->rvh(); 297 TestRenderViewHost* orig_rvh = rvh();
383 int orig_rvh_delete_count = 0; 298 int orig_rvh_delete_count = 0;
384 orig_rvh->set_delete_counter(&orig_rvh_delete_count); 299 orig_rvh->set_delete_counter(&orig_rvh_delete_count);
385 SiteInstance* instance1 = contents->GetSiteInstance(); 300 SiteInstance* instance1 = contents()->GetSiteInstance();
386 301
387 // Navigate to URL. First URL should use first RenderViewHost. 302 // Navigate to URL. First URL should use first RenderViewHost.
388 const GURL url("http://www.google.com"); 303 const GURL url("http://www.google.com");
389 contents->controller()->LoadURL(url, GURL(), PageTransition::TYPED); 304 controller()->LoadURL(url, GURL(), PageTransition::TYPED);
390 ViewHostMsg_FrameNavigate_Params params1; 305 ViewHostMsg_FrameNavigate_Params params1;
391 InitNavigateParams(&params1, 1, url); 306 InitNavigateParams(&params1, 1, url);
392 contents->TestDidNavigate(orig_rvh, params1); 307 contents()->TestDidNavigate(orig_rvh, params1);
393 308
394 EXPECT_FALSE(contents->cross_navigation_pending()); 309 EXPECT_FALSE(contents()->cross_navigation_pending());
395 EXPECT_EQ(orig_rvh, contents->render_view_host()); 310 EXPECT_EQ(orig_rvh, contents()->render_view_host());
396 311
397 // Crash the renderer. 312 // Crash the renderer.
398 orig_rvh->set_render_view_created(false); 313 orig_rvh->set_render_view_created(false);
399 314
400 // Navigate to new site. We should not go into PENDING. 315 // Navigate to new site. We should not go into PENDING.
401 const GURL url2("http://www.yahoo.com"); 316 const GURL url2("http://www.yahoo.com");
402 contents->controller()->LoadURL(url2, GURL(), PageTransition::TYPED); 317 controller()->LoadURL(url2, GURL(), PageTransition::TYPED);
403 TestRenderViewHost* new_rvh = contents->rvh(); 318 TestRenderViewHost* new_rvh = rvh();
404 EXPECT_FALSE(contents->cross_navigation_pending()); 319 EXPECT_FALSE(contents()->cross_navigation_pending());
405 EXPECT_TRUE(contents->pending_rvh() == NULL); 320 EXPECT_TRUE(contents()->pending_rvh() == NULL);
406 EXPECT_NE(orig_rvh, new_rvh); 321 EXPECT_NE(orig_rvh, new_rvh);
407 EXPECT_EQ(orig_rvh_delete_count, 1); 322 EXPECT_EQ(orig_rvh_delete_count, 1);
408 323
409 // DidNavigate from the new page 324 // DidNavigate from the new page
410 ViewHostMsg_FrameNavigate_Params params2; 325 ViewHostMsg_FrameNavigate_Params params2;
411 InitNavigateParams(&params2, 1, url2); 326 InitNavigateParams(&params2, 1, url2);
412 contents->TestDidNavigate(new_rvh, params2); 327 contents()->TestDidNavigate(new_rvh, params2);
413 SiteInstance* instance2 = contents->GetSiteInstance(); 328 SiteInstance* instance2 = contents()->GetSiteInstance();
414 329
415 EXPECT_FALSE(contents->cross_navigation_pending()); 330 EXPECT_FALSE(contents()->cross_navigation_pending());
416 EXPECT_EQ(new_rvh, contents->render_view_host()); 331 EXPECT_EQ(new_rvh, rvh());
417 EXPECT_NE(instance1, instance2); 332 EXPECT_NE(instance1, instance2);
418 EXPECT_TRUE(contents->pending_rvh() == NULL); 333 EXPECT_TRUE(contents()->pending_rvh() == NULL);
419 } 334 }
420 335
421 // Test that opening a new tab in the same SiteInstance and then navigating 336 // Test that opening a new tab in the same SiteInstance and then navigating
422 // both tabs to a new site will place both tabs in a single SiteInstance. 337 // both tabs to a new site will place both tabs in a single SiteInstance.
423 TEST_F(WebContentsTest, NavigateTwoTabsCrossSite) { 338 TEST_F(WebContentsTest, NavigateTwoTabsCrossSite) {
424 contents->transition_cross_site = true; 339 contents()->transition_cross_site = true;
425 TestRenderViewHost* orig_rvh = contents->rvh(); 340 TestRenderViewHost* orig_rvh = rvh();
426 SiteInstance* instance1 = contents->GetSiteInstance(); 341 SiteInstance* instance1 = contents()->GetSiteInstance();
427 342
428 // Navigate to URL. First URL should use first RenderViewHost. 343 // Navigate to URL. First URL should use first RenderViewHost.
429 const GURL url("http://www.google.com"); 344 const GURL url("http://www.google.com");
430 contents->controller()->LoadURL(url, GURL(), PageTransition::TYPED); 345 controller()->LoadURL(url, GURL(), PageTransition::TYPED);
431 ViewHostMsg_FrameNavigate_Params params1; 346 ViewHostMsg_FrameNavigate_Params params1;
432 InitNavigateParams(&params1, 1, url); 347 InitNavigateParams(&params1, 1, url);
433 contents->TestDidNavigate(orig_rvh, params1); 348 contents()->TestDidNavigate(orig_rvh, params1);
434 349
435 // Open a new tab with the same SiteInstance, navigated to the same site. 350 // Open a new tab with the same SiteInstance, navigated to the same site.
436 TestWebContents* contents2 = new TestWebContents(profile.get(), instance1); 351 TestWebContents* contents2 = new TestWebContents(profile(), instance1,
352 &rvh_factory_);
437 params1.page_id = 2; // Need this since the site instance is the same (which 353 params1.page_id = 2; // Need this since the site instance is the same (which
438 // is the scope of page IDs) and we want to consider 354 // is the scope of page IDs) and we want to consider
439 // this a new page. 355 // this a new page.
440 contents2->transition_cross_site = true; 356 contents2->transition_cross_site = true;
441 contents2->SetupController(profile.get()); 357 contents2->SetupController(profile());
442 contents2->controller()->LoadURL(url, GURL(), PageTransition::TYPED); 358 contents2->controller()->LoadURL(url, GURL(), PageTransition::TYPED);
443 contents2->TestDidNavigate(contents2->rvh(), params1); 359 contents2->TestDidNavigate(contents2->render_view_host(), params1);
444 360
445 // Navigate first tab to a new site 361 // Navigate first tab to a new site
446 const GURL url2a("http://www.yahoo.com"); 362 const GURL url2a("http://www.yahoo.com");
447 contents->controller()->LoadURL(url2a, GURL(), PageTransition::TYPED); 363 controller()->LoadURL(url2a, GURL(), PageTransition::TYPED);
448 TestRenderViewHost* pending_rvh_a = contents->pending_rvh(); 364 TestRenderViewHost* pending_rvh_a = contents()->pending_rvh();
449 ViewHostMsg_FrameNavigate_Params params2a; 365 ViewHostMsg_FrameNavigate_Params params2a;
450 InitNavigateParams(&params2a, 1, url2a); 366 InitNavigateParams(&params2a, 1, url2a);
451 contents->TestDidNavigate(pending_rvh_a, params2a); 367 contents()->TestDidNavigate(pending_rvh_a, params2a);
452 SiteInstance* instance2a = contents->GetSiteInstance(); 368 SiteInstance* instance2a = contents()->GetSiteInstance();
453 EXPECT_NE(instance1, instance2a); 369 EXPECT_NE(instance1, instance2a);
454 370
455 // Navigate second tab to the same site as the first tab 371 // Navigate second tab to the same site as the first tab
456 const GURL url2b("http://mail.yahoo.com"); 372 const GURL url2b("http://mail.yahoo.com");
457 contents2->controller()->LoadURL(url2b, GURL(), PageTransition::TYPED); 373 contents2->controller()->LoadURL(url2b, GURL(), PageTransition::TYPED);
458 TestRenderViewHost* pending_rvh_b = contents2->pending_rvh(); 374 TestRenderViewHost* pending_rvh_b = contents2->pending_rvh();
459 EXPECT_TRUE(pending_rvh_b != NULL); 375 EXPECT_TRUE(pending_rvh_b != NULL);
460 EXPECT_TRUE(contents2->cross_navigation_pending()); 376 EXPECT_TRUE(contents2->cross_navigation_pending());
461 377
462 // NOTE(creis): We used to be in danger of showing a sad tab page here if the 378 // NOTE(creis): We used to be in danger of showing a sad tab page here if the
463 // second tab hadn't navigated somewhere first (bug 1145430). That case is 379 // second tab hadn't navigated somewhere first (bug 1145430). That case is
464 // now covered by the CrossSiteBoundariesAfterCrash test. 380 // now covered by the CrossSiteBoundariesAfterCrash test.
465 381
466 ViewHostMsg_FrameNavigate_Params params2b; 382 ViewHostMsg_FrameNavigate_Params params2b;
467 InitNavigateParams(&params2b, 2, url2b); 383 InitNavigateParams(&params2b, 2, url2b);
468 contents2->TestDidNavigate(pending_rvh_b, params2b); 384 contents2->TestDidNavigate(pending_rvh_b, params2b);
469 SiteInstance* instance2b = contents2->GetSiteInstance(); 385 SiteInstance* instance2b = contents2->GetSiteInstance();
470 EXPECT_NE(instance1, instance2b); 386 EXPECT_NE(instance1, instance2b);
471 387
472 // Both tabs should now be in the same SiteInstance. 388 // Both tabs should now be in the same SiteInstance.
473 EXPECT_EQ(instance2a, instance2b); 389 EXPECT_EQ(instance2a, instance2b);
474 390
475 contents2->CloseContents(); 391 contents2->CloseContents();
476 } 392 }
477 393
478 // Tests that WebContents uses the current URL, not the SiteInstance's site, to 394 // Tests that WebContents uses the current URL, not the SiteInstance's site, to
479 // determine whether a navigation is cross-site. 395 // determine whether a navigation is cross-site.
480 TEST_F(WebContentsTest, CrossSiteComparesAgainstCurrentPage) { 396 TEST_F(WebContentsTest, CrossSiteComparesAgainstCurrentPage) {
481 contents->transition_cross_site = true; 397 contents()->transition_cross_site = true;
482 TestRenderViewHost* orig_rvh = contents->rvh(); 398 TestRenderViewHost* orig_rvh = rvh();
483 SiteInstance* instance1 = contents->GetSiteInstance(); 399 SiteInstance* instance1 = contents()->GetSiteInstance();
484 400
485 // Navigate to URL. 401 // Navigate to URL.
486 const GURL url("http://www.google.com"); 402 const GURL url("http://www.google.com");
487 contents->controller()->LoadURL(url, GURL(), PageTransition::TYPED); 403 controller()->LoadURL(url, GURL(), PageTransition::TYPED);
488 ViewHostMsg_FrameNavigate_Params params1; 404 ViewHostMsg_FrameNavigate_Params params1;
489 InitNavigateParams(&params1, 1, url); 405 InitNavigateParams(&params1, 1, url);
490 contents->TestDidNavigate(orig_rvh, params1); 406 contents()->TestDidNavigate(orig_rvh, params1);
491 407
492 // Open a related tab to a second site. 408 // Open a related tab to a second site.
493 TestWebContents* contents2 = new TestWebContents(profile.get(), instance1); 409 TestWebContents* contents2 = new TestWebContents(profile(), instance1,
410 &rvh_factory_);
494 contents2->transition_cross_site = true; 411 contents2->transition_cross_site = true;
495 contents2->SetupController(profile.get()); 412 contents2->SetupController(profile());
496 const GURL url2("http://www.yahoo.com"); 413 const GURL url2("http://www.yahoo.com");
497 contents2->controller()->LoadURL(url2, GURL(), PageTransition::TYPED); 414 contents2->controller()->LoadURL(url2, GURL(), PageTransition::TYPED);
498 // The first RVH in contents2 isn't live yet, so we shortcut the cross site 415 // The first RVH in contents2 isn't live yet, so we shortcut the cross site
499 // pending. 416 // pending.
500 TestRenderViewHost* rvh2 = contents2->rvh(); 417 TestRenderViewHost* rvh2 = static_cast<TestRenderViewHost*>(
418 contents2->render_view_host());
501 EXPECT_FALSE(contents2->cross_navigation_pending()); 419 EXPECT_FALSE(contents2->cross_navigation_pending());
502 ViewHostMsg_FrameNavigate_Params params2; 420 ViewHostMsg_FrameNavigate_Params params2;
503 InitNavigateParams(&params2, 2, url2); 421 InitNavigateParams(&params2, 2, url2);
504 contents2->TestDidNavigate(rvh2, params2); 422 contents2->TestDidNavigate(rvh2, params2);
505 SiteInstance* instance2 = contents2->GetSiteInstance(); 423 SiteInstance* instance2 = contents2->GetSiteInstance();
506 EXPECT_NE(instance1, instance2); 424 EXPECT_NE(instance1, instance2);
507 EXPECT_FALSE(contents2->cross_navigation_pending()); 425 EXPECT_FALSE(contents2->cross_navigation_pending());
508 426
509 // Simulate a link click in first tab to second site. Doesn't switch 427 // Simulate a link click in first tab to second site. Doesn't switch
510 // SiteInstances, because we don't intercept WebKit navigations. 428 // SiteInstances, because we don't intercept WebKit navigations.
511 ViewHostMsg_FrameNavigate_Params params3; 429 ViewHostMsg_FrameNavigate_Params params3;
512 InitNavigateParams(&params3, 2, url2); 430 InitNavigateParams(&params3, 2, url2);
513 contents->TestDidNavigate(orig_rvh, params3); 431 contents()->TestDidNavigate(orig_rvh, params3);
514 SiteInstance* instance3 = contents->GetSiteInstance(); 432 SiteInstance* instance3 = contents()->GetSiteInstance();
515 EXPECT_EQ(instance1, instance3); 433 EXPECT_EQ(instance1, instance3);
516 EXPECT_FALSE(contents->cross_navigation_pending()); 434 EXPECT_FALSE(contents()->cross_navigation_pending());
517 435
518 // Navigate to the new site. Doesn't switch SiteInstancees, because we 436 // Navigate to the new site. Doesn't switch SiteInstancees, because we
519 // compare against the current URL, not the SiteInstance's site. 437 // compare against the current URL, not the SiteInstance's site.
520 const GURL url3("http://mail.yahoo.com"); 438 const GURL url3("http://mail.yahoo.com");
521 contents->controller()->LoadURL(url3, GURL(), PageTransition::TYPED); 439 controller()->LoadURL(url3, GURL(), PageTransition::TYPED);
522 EXPECT_FALSE(contents->cross_navigation_pending()); 440 EXPECT_FALSE(contents()->cross_navigation_pending());
523 ViewHostMsg_FrameNavigate_Params params4; 441 ViewHostMsg_FrameNavigate_Params params4;
524 InitNavigateParams(&params4, 3, url3); 442 InitNavigateParams(&params4, 3, url3);
525 contents->TestDidNavigate(orig_rvh, params4); 443 contents()->TestDidNavigate(orig_rvh, params4);
526 SiteInstance* instance4 = contents->GetSiteInstance(); 444 SiteInstance* instance4 = contents()->GetSiteInstance();
527 EXPECT_EQ(instance1, instance4); 445 EXPECT_EQ(instance1, instance4);
528 446
529 contents2->CloseContents(); 447 contents2->CloseContents();
530 } 448 }
531 449
532 // Test that the onbeforeunload and onunload handlers run when navigating 450 // Test that the onbeforeunload and onunload handlers run when navigating
533 // across site boundaries. 451 // across site boundaries.
534 TEST_F(WebContentsTest, CrossSiteUnloadHandlers) { 452 TEST_F(WebContentsTest, CrossSiteUnloadHandlers) {
535 contents->transition_cross_site = true; 453 contents()->transition_cross_site = true;
536 TestRenderViewHost* orig_rvh = contents->rvh(); 454 TestRenderViewHost* orig_rvh = rvh();
537 SiteInstance* instance1 = contents->GetSiteInstance(); 455 SiteInstance* instance1 = contents()->GetSiteInstance();
538 456
539 // Navigate to URL. First URL should use first RenderViewHost. 457 // Navigate to URL. First URL should use first RenderViewHost.
540 const GURL url("http://www.google.com"); 458 const GURL url("http://www.google.com");
541 contents->controller()->LoadURL(url, GURL(), PageTransition::TYPED); 459 controller()->LoadURL(url, GURL(), PageTransition::TYPED);
542 ViewHostMsg_FrameNavigate_Params params1; 460 ViewHostMsg_FrameNavigate_Params params1;
543 InitNavigateParams(&params1, 1, url); 461 InitNavigateParams(&params1, 1, url);
544 contents->TestDidNavigate(orig_rvh, params1); 462 contents()->TestDidNavigate(orig_rvh, params1);
545 EXPECT_FALSE(contents->cross_navigation_pending()); 463 EXPECT_FALSE(contents()->cross_navigation_pending());
546 EXPECT_EQ(orig_rvh, contents->render_view_host()); 464 EXPECT_EQ(orig_rvh, contents()->render_view_host());
547 465
548 // Navigate to new site, but simulate an onbeforeunload denial. 466 // Navigate to new site, but simulate an onbeforeunload denial.
549 const GURL url2("http://www.yahoo.com"); 467 const GURL url2("http://www.yahoo.com");
550 contents->controller()->LoadURL(url2, GURL(), PageTransition::TYPED); 468 controller()->LoadURL(url2, GURL(), PageTransition::TYPED);
551 orig_rvh->TestOnMessageReceived(ViewHostMsg_ShouldClose_ACK(0, false)); 469 orig_rvh->TestOnMessageReceived(ViewHostMsg_ShouldClose_ACK(0, false));
552 EXPECT_FALSE(contents->cross_navigation_pending()); 470 EXPECT_FALSE(contents()->cross_navigation_pending());
553 EXPECT_EQ(orig_rvh, contents->render_view_host()); 471 EXPECT_EQ(orig_rvh, contents()->render_view_host());
554 472
555 // Navigate again, but simulate an onbeforeunload approval. 473 // Navigate again, but simulate an onbeforeunload approval.
556 contents->controller()->LoadURL(url2, GURL(), PageTransition::TYPED); 474 controller()->LoadURL(url2, GURL(), PageTransition::TYPED);
557 orig_rvh->TestOnMessageReceived(ViewHostMsg_ShouldClose_ACK(0, true)); 475 orig_rvh->TestOnMessageReceived(ViewHostMsg_ShouldClose_ACK(0, true));
558 EXPECT_TRUE(contents->cross_navigation_pending()); 476 EXPECT_TRUE(contents()->cross_navigation_pending());
559 TestRenderViewHost* pending_rvh = contents->pending_rvh(); 477 TestRenderViewHost* pending_rvh = static_cast<TestRenderViewHost*>(
478 contents()->pending_rvh());
560 479
561 // We won't hear DidNavigate until the onunload handler has finished running. 480 // We won't hear DidNavigate until the onunload handler has finished running.
562 // (No way to simulate that here, but it involves a call from RDH to 481 // (No way to simulate that here, but it involves a call from RDH to
563 // WebContents::OnCrossSiteResponse.) 482 // WebContents::OnCrossSiteResponse.)
564 483
565 // DidNavigate from the pending page 484 // DidNavigate from the pending page
566 ViewHostMsg_FrameNavigate_Params params2; 485 ViewHostMsg_FrameNavigate_Params params2;
567 InitNavigateParams(&params2, 1, url2); 486 InitNavigateParams(&params2, 1, url2);
568 contents->TestDidNavigate(pending_rvh, params2); 487 contents()->TestDidNavigate(pending_rvh, params2);
569 SiteInstance* instance2 = contents->GetSiteInstance(); 488 SiteInstance* instance2 = contents()->GetSiteInstance();
570 EXPECT_FALSE(contents->cross_navigation_pending()); 489 EXPECT_FALSE(contents()->cross_navigation_pending());
571 EXPECT_EQ(pending_rvh, contents->render_view_host()); 490 EXPECT_EQ(pending_rvh, rvh());
572 EXPECT_NE(instance1, instance2); 491 EXPECT_NE(instance1, instance2);
573 EXPECT_TRUE(contents->pending_rvh() == NULL); 492 EXPECT_TRUE(contents()->pending_rvh() == NULL);
574 } 493 }
575 494
576 // Test that NavigationEntries have the correct content state after going 495 // Test that NavigationEntries have the correct content state after going
577 // forward and back. Prevents regression for bug 1116137. 496 // forward and back. Prevents regression for bug 1116137.
578 TEST_F(WebContentsTest, NavigationEntryContentState) { 497 TEST_F(WebContentsTest, NavigationEntryContentState) {
579 TestRenderViewHost* orig_rvh = contents->rvh(); 498 TestRenderViewHost* orig_rvh = rvh();
580 499
581 // Navigate to URL. There should be no committed entry yet. 500 // Navigate to URL. There should be no committed entry yet.
582 const GURL url("http://www.google.com"); 501 const GURL url("http://www.google.com");
583 contents->controller()->LoadURL(url, GURL(), PageTransition::TYPED); 502 controller()->LoadURL(url, GURL(), PageTransition::TYPED);
584 NavigationEntry* entry = contents->controller()->GetLastCommittedEntry(); 503 NavigationEntry* entry = controller()->GetLastCommittedEntry();
585 EXPECT_TRUE(entry == NULL); 504 EXPECT_TRUE(entry == NULL);
586 505
587 // Committed entry should have content state after DidNavigate. 506 // Committed entry should have content state after DidNavigate.
588 ViewHostMsg_FrameNavigate_Params params1; 507 ViewHostMsg_FrameNavigate_Params params1;
589 InitNavigateParams(&params1, 1, url); 508 InitNavigateParams(&params1, 1, url);
590 contents->TestDidNavigate(orig_rvh, params1); 509 contents()->TestDidNavigate(orig_rvh, params1);
591 entry = contents->controller()->GetLastCommittedEntry(); 510 entry = controller()->GetLastCommittedEntry();
592 EXPECT_FALSE(entry->content_state().empty()); 511 EXPECT_FALSE(entry->content_state().empty());
593 512
594 // Navigate to same site. 513 // Navigate to same site.
595 const GURL url2("http://images.google.com"); 514 const GURL url2("http://images.google.com");
596 contents->controller()->LoadURL(url2, GURL(), PageTransition::TYPED); 515 controller()->LoadURL(url2, GURL(), PageTransition::TYPED);
597 entry = contents->controller()->GetLastCommittedEntry(); 516 entry = controller()->GetLastCommittedEntry();
598 EXPECT_FALSE(entry->content_state().empty()); 517 EXPECT_FALSE(entry->content_state().empty());
599 518
600 // Committed entry should have content state after DidNavigate. 519 // Committed entry should have content state after DidNavigate.
601 ViewHostMsg_FrameNavigate_Params params2; 520 ViewHostMsg_FrameNavigate_Params params2;
602 InitNavigateParams(&params2, 2, url2); 521 InitNavigateParams(&params2, 2, url2);
603 contents->TestDidNavigate(orig_rvh, params2); 522 contents()->TestDidNavigate(orig_rvh, params2);
604 entry = contents->controller()->GetLastCommittedEntry(); 523 entry = controller()->GetLastCommittedEntry();
605 EXPECT_FALSE(entry->content_state().empty()); 524 EXPECT_FALSE(entry->content_state().empty());
606 525
607 // Now go back. Committed entry should still have content state. 526 // Now go back. Committed entry should still have content state.
608 contents->controller()->GoBack(); 527 controller()->GoBack();
609 contents->TestDidNavigate(orig_rvh, params1); 528 contents()->TestDidNavigate(orig_rvh, params1);
610 entry = contents->controller()->GetLastCommittedEntry(); 529 entry = controller()->GetLastCommittedEntry();
611 EXPECT_FALSE(entry->content_state().empty()); 530 EXPECT_FALSE(entry->content_state().empty());
612 } 531 }
613 532
614 // Test that NavigationEntries have the correct content state after opening 533 // Test that NavigationEntries have the correct content state after opening
615 // a new window to about:blank. Prevents regression for bug 1116137. 534 // a new window to about:blank. Prevents regression for bug 1116137.
616 TEST_F(WebContentsTest, NavigationEntryContentStateNewWindow) { 535 TEST_F(WebContentsTest, NavigationEntryContentStateNewWindow) {
617 TestRenderViewHost* orig_rvh = contents->rvh(); 536 TestRenderViewHost* orig_rvh = rvh();
618 537
619 // When opening a new window, it is navigated to about:blank internally. 538 // When opening a new window, it is navigated to about:blank internally.
620 // Currently, this results in two DidNavigate events. 539 // Currently, this results in two DidNavigate events.
621 const GURL url("about:blank"); 540 const GURL url("about:blank");
622 ViewHostMsg_FrameNavigate_Params params1; 541 ViewHostMsg_FrameNavigate_Params params1;
623 InitNavigateParams(&params1, 1, url); 542 InitNavigateParams(&params1, 1, url);
624 contents->TestDidNavigate(orig_rvh, params1); 543 contents()->TestDidNavigate(orig_rvh, params1);
625 contents->TestDidNavigate(orig_rvh, params1); 544 contents()->TestDidNavigate(orig_rvh, params1);
626 545
627 // Should have a content state here. 546 // Should have a content state here.
628 NavigationEntry* entry = contents->controller()->GetLastCommittedEntry(); 547 NavigationEntry* entry = controller()->GetLastCommittedEntry();
629 EXPECT_FALSE(entry->content_state().empty()); 548 EXPECT_FALSE(entry->content_state().empty());
630 } 549 }
631 550
632 // Tests to see that webkit preferences are properly loaded and copied over 551 // Tests to see that webkit preferences are properly loaded and copied over
633 // to a WebPreferences object. 552 // to a WebPreferences object.
634 TEST_F(WebContentsTest, WebKitPrefs) { 553 TEST_F(WebContentsTest, WebKitPrefs) {
635 WebPreferences webkit_prefs = contents->TestGetWebkitPrefs(); 554 WebPreferences webkit_prefs = contents()->TestGetWebkitPrefs();
636 555
637 // These values have been overridden by the profile preferences. 556 // These values have been overridden by the profile preferences.
638 EXPECT_EQ(L"UTF-8", webkit_prefs.default_encoding); 557 EXPECT_EQ(L"UTF-8", webkit_prefs.default_encoding);
639 EXPECT_EQ(20, webkit_prefs.default_font_size); 558 EXPECT_EQ(20, webkit_prefs.default_font_size);
640 EXPECT_EQ(false, webkit_prefs.text_areas_are_resizable); 559 EXPECT_EQ(false, webkit_prefs.text_areas_are_resizable);
641 EXPECT_EQ(true, webkit_prefs.uses_universal_detector); 560 EXPECT_EQ(true, webkit_prefs.uses_universal_detector);
642 561
643 // These should still be the default values. 562 // These should still be the default values.
644 EXPECT_EQ(L"Times New Roman", webkit_prefs.standard_font_family); 563 EXPECT_EQ(L"Times New Roman", webkit_prefs.standard_font_family);
645 EXPECT_EQ(true, webkit_prefs.javascript_enabled); 564 EXPECT_EQ(true, webkit_prefs.javascript_enabled);
646 } 565 }
647 566
648 //////////////////////////////////////////////////////////////////////////////// 567 ////////////////////////////////////////////////////////////////////////////////
649 // Interstitial Tests 568 // Interstitial Tests
650 //////////////////////////////////////////////////////////////////////////////// 569 ////////////////////////////////////////////////////////////////////////////////
651 570
652 // Test navigating to a page (with the navigation initiated from the browser, 571 // Test navigating to a page (with the navigation initiated from the browser,
653 // as when a URL is typed in the location bar) that shows an interstitial and 572 // as when a URL is typed in the location bar) that shows an interstitial and
654 // creates a new navigation entry, then hiding it without proceeding. 573 // creates a new navigation entry, then hiding it without proceeding.
655 TEST_F(WebContentsTest, 574 TEST_F(WebContentsTest,
656 ShowInterstitialFromBrowserWithNewNavigationDontProceed) { 575 ShowInterstitialFromBrowserWithNewNavigationDontProceed) {
657 // Navigate to a page. 576 // Navigate to a page.
658 GURL url1("http://www.google.com"); 577 GURL url1("http://www.google.com");
659 Navigate(1, url1); 578 rvh()->SendNavigate(1, url1);
660 EXPECT_EQ(1, contents->controller()->GetEntryCount()); 579 EXPECT_EQ(1, controller()->GetEntryCount());
661 580
662 // Initiate a browser navigation that will trigger the interstitial 581 // Initiate a browser navigation that will trigger the interstitial
663 contents->controller()->LoadURL(GURL("http://www.evil.com"), GURL(), 582 controller()->LoadURL(GURL("http://www.evil.com"), GURL(),
664 PageTransition::TYPED); 583 PageTransition::TYPED);
665 584
666 // Show an interstitial. 585 // Show an interstitial.
667 TestInterstitialPage::InterstitialState state = 586 TestInterstitialPage::InterstitialState state =
668 TestInterstitialPage::UNDECIDED; 587 TestInterstitialPage::UNDECIDED;
669 bool deleted = false; 588 bool deleted = false;
670 GURL url2("http://interstitial"); 589 GURL url2("http://interstitial");
671 TestInterstitialPage* interstitial = 590 TestInterstitialPage* interstitial =
672 new TestInterstitialPage(contents, true, url2, &state, &deleted); 591 new TestInterstitialPage(contents(), true, url2, &state, &deleted);
673 TestInterstitialPageStateGuard state_guard(interstitial); 592 TestInterstitialPageStateGuard state_guard(interstitial);
674 interstitial->Show(); 593 interstitial->Show();
675 // The interstitial should not show until its navigation has committed. 594 // The interstitial should not show until its navigation has committed.
676 EXPECT_FALSE(interstitial->is_showing()); 595 EXPECT_FALSE(interstitial->is_showing());
677 EXPECT_FALSE(contents->showing_interstitial_page()); 596 EXPECT_FALSE(contents()->showing_interstitial_page());
678 EXPECT_TRUE(contents->interstitial_page() == NULL); 597 EXPECT_TRUE(contents()->interstitial_page() == NULL);
679 // Let's commit the interstitial navigation. 598 // Let's commit the interstitial navigation.
680 interstitial->TestDidNavigate(1, url2); 599 interstitial->TestDidNavigate(1, url2);
681 EXPECT_TRUE(interstitial->is_showing()); 600 EXPECT_TRUE(interstitial->is_showing());
682 EXPECT_TRUE(contents->showing_interstitial_page()); 601 EXPECT_TRUE(contents()->showing_interstitial_page());
683 EXPECT_TRUE(contents->interstitial_page() == interstitial); 602 EXPECT_TRUE(contents()->interstitial_page() == interstitial);
684 NavigationEntry* entry = contents->controller()->GetActiveEntry(); 603 NavigationEntry* entry = controller()->GetActiveEntry();
685 ASSERT_TRUE(entry != NULL); 604 ASSERT_TRUE(entry != NULL);
686 EXPECT_TRUE(entry->url() == url2); 605 EXPECT_TRUE(entry->url() == url2);
687 606
688 // Now don't proceed. 607 // Now don't proceed.
689 interstitial->DontProceed(); 608 interstitial->DontProceed();
690 EXPECT_TRUE(deleted); 609 EXPECT_TRUE(deleted);
691 EXPECT_EQ(TestInterstitialPage::CANCELED, state); 610 EXPECT_EQ(TestInterstitialPage::CANCELED, state);
692 EXPECT_FALSE(contents->showing_interstitial_page()); 611 EXPECT_FALSE(contents()->showing_interstitial_page());
693 EXPECT_TRUE(contents->interstitial_page() == NULL); 612 EXPECT_TRUE(contents()->interstitial_page() == NULL);
694 entry = contents->controller()->GetActiveEntry(); 613 entry = controller()->GetActiveEntry();
695 ASSERT_TRUE(entry != NULL); 614 ASSERT_TRUE(entry != NULL);
696 EXPECT_TRUE(entry->url() == url1); 615 EXPECT_TRUE(entry->url() == url1);
697 EXPECT_EQ(1, contents->controller()->GetEntryCount()); 616 EXPECT_EQ(1, controller()->GetEntryCount());
698 } 617 }
699 618
700 // Test navigating to a page (with the navigation initiated from the renderer, 619 // Test navigating to a page (with the navigation initiated from the renderer,
701 // as when clicking on a link in the page) that shows an interstitial and 620 // as when clicking on a link in the page) that shows an interstitial and
702 // creates a new navigation entry, then hiding it without proceeding. 621 // creates a new navigation entry, then hiding it without proceeding.
703 TEST_F(WebContentsTest, 622 TEST_F(WebContentsTest,
704 ShowInterstitiaFromRendererlWithNewNavigationDontProceed) { 623 ShowInterstitiaFromRendererlWithNewNavigationDontProceed) {
705 // Navigate to a page. 624 // Navigate to a page.
706 GURL url1("http://www.google.com"); 625 GURL url1("http://www.google.com");
707 Navigate(1, url1); 626 rvh()->SendNavigate(1, url1);
708 EXPECT_EQ(1, contents->controller()->GetEntryCount()); 627 EXPECT_EQ(1, controller()->GetEntryCount());
709 628
710 // Show an interstitial (no pending entry, the interstitial would have been 629 // Show an interstitial (no pending entry, the interstitial would have been
711 // triggered by clicking on a link). 630 // triggered by clicking on a link).
712 TestInterstitialPage::InterstitialState state = 631 TestInterstitialPage::InterstitialState state =
713 TestInterstitialPage::UNDECIDED; 632 TestInterstitialPage::UNDECIDED;
714 bool deleted = false; 633 bool deleted = false;
715 GURL url2("http://interstitial"); 634 GURL url2("http://interstitial");
716 TestInterstitialPage* interstitial = 635 TestInterstitialPage* interstitial =
717 new TestInterstitialPage(contents, true, url2, &state, &deleted); 636 new TestInterstitialPage(contents(), true, url2, &state, &deleted);
718 TestInterstitialPageStateGuard state_guard(interstitial); 637 TestInterstitialPageStateGuard state_guard(interstitial);
719 interstitial->Show(); 638 interstitial->Show();
720 // The interstitial should not show until its navigation has committed. 639 // The interstitial should not show until its navigation has committed.
721 EXPECT_FALSE(interstitial->is_showing()); 640 EXPECT_FALSE(interstitial->is_showing());
722 EXPECT_FALSE(contents->showing_interstitial_page()); 641 EXPECT_FALSE(contents()->showing_interstitial_page());
723 EXPECT_TRUE(contents->interstitial_page() == NULL); 642 EXPECT_TRUE(contents()->interstitial_page() == NULL);
724 // Let's commit the interstitial navigation. 643 // Let's commit the interstitial navigation.
725 interstitial->TestDidNavigate(1, url2); 644 interstitial->TestDidNavigate(1, url2);
726 EXPECT_TRUE(interstitial->is_showing()); 645 EXPECT_TRUE(interstitial->is_showing());
727 EXPECT_TRUE(contents->showing_interstitial_page()); 646 EXPECT_TRUE(contents()->showing_interstitial_page());
728 EXPECT_TRUE(contents->interstitial_page() == interstitial); 647 EXPECT_TRUE(contents()->interstitial_page() == interstitial);
729 NavigationEntry* entry = contents->controller()->GetActiveEntry(); 648 NavigationEntry* entry = controller()->GetActiveEntry();
730 ASSERT_TRUE(entry != NULL); 649 ASSERT_TRUE(entry != NULL);
731 EXPECT_TRUE(entry->url() == url2); 650 EXPECT_TRUE(entry->url() == url2);
732 651
733 // Now don't proceed. 652 // Now don't proceed.
734 interstitial->DontProceed(); 653 interstitial->DontProceed();
735 EXPECT_TRUE(deleted); 654 EXPECT_TRUE(deleted);
736 EXPECT_EQ(TestInterstitialPage::CANCELED, state); 655 EXPECT_EQ(TestInterstitialPage::CANCELED, state);
737 EXPECT_FALSE(contents->showing_interstitial_page()); 656 EXPECT_FALSE(contents()->showing_interstitial_page());
738 EXPECT_TRUE(contents->interstitial_page() == NULL); 657 EXPECT_TRUE(contents()->interstitial_page() == NULL);
739 entry = contents->controller()->GetActiveEntry(); 658 entry = controller()->GetActiveEntry();
740 ASSERT_TRUE(entry != NULL); 659 ASSERT_TRUE(entry != NULL);
741 EXPECT_TRUE(entry->url() == url1); 660 EXPECT_TRUE(entry->url() == url1);
742 EXPECT_EQ(1, contents->controller()->GetEntryCount()); 661 EXPECT_EQ(1, controller()->GetEntryCount());
743 } 662 }
744 663
745 // Test navigating to a page that shows an interstitial without creating a new 664 // Test navigating to a page that shows an interstitial without creating a new
746 // navigation entry (this happens when the interstitial is triggered by a 665 // navigation entry (this happens when the interstitial is triggered by a
747 // sub-resource in the page), then hiding it without proceeding. 666 // sub-resource in the page), then hiding it without proceeding.
748 TEST_F(WebContentsTest, ShowInterstitialNoNewNavigationDontProceed) { 667 TEST_F(WebContentsTest, ShowInterstitialNoNewNavigationDontProceed) {
749 // Navigate to a page. 668 // Navigate to a page.
750 GURL url1("http://www.google.com"); 669 GURL url1("http://www.google.com");
751 Navigate(1, url1); 670 rvh()->SendNavigate(1, url1);
752 EXPECT_EQ(1, contents->controller()->GetEntryCount()); 671 EXPECT_EQ(1, controller()->GetEntryCount());
753 672
754 // Show an interstitial. 673 // Show an interstitial.
755 TestInterstitialPage::InterstitialState state = 674 TestInterstitialPage::InterstitialState state =
756 TestInterstitialPage::UNDECIDED; 675 TestInterstitialPage::UNDECIDED;
757 bool deleted = false; 676 bool deleted = false;
758 GURL url2("http://interstitial"); 677 GURL url2("http://interstitial");
759 TestInterstitialPage* interstitial = 678 TestInterstitialPage* interstitial =
760 new TestInterstitialPage(contents, false, url2, &state, &deleted); 679 new TestInterstitialPage(contents(), false, url2, &state, &deleted);
761 TestInterstitialPageStateGuard state_guard(interstitial); 680 TestInterstitialPageStateGuard state_guard(interstitial);
762 interstitial->Show(); 681 interstitial->Show();
763 // The interstitial should not show until its navigation has committed. 682 // The interstitial should not show until its navigation has committed.
764 EXPECT_FALSE(interstitial->is_showing()); 683 EXPECT_FALSE(interstitial->is_showing());
765 EXPECT_FALSE(contents->showing_interstitial_page()); 684 EXPECT_FALSE(contents()->showing_interstitial_page());
766 EXPECT_TRUE(contents->interstitial_page() == NULL); 685 EXPECT_TRUE(contents()->interstitial_page() == NULL);
767 // Let's commit the interstitial navigation. 686 // Let's commit the interstitial navigation.
768 interstitial->TestDidNavigate(1, url2); 687 interstitial->TestDidNavigate(1, url2);
769 EXPECT_TRUE(interstitial->is_showing()); 688 EXPECT_TRUE(interstitial->is_showing());
770 EXPECT_TRUE(contents->showing_interstitial_page()); 689 EXPECT_TRUE(contents()->showing_interstitial_page());
771 EXPECT_TRUE(contents->interstitial_page() == interstitial); 690 EXPECT_TRUE(contents()->interstitial_page() == interstitial);
772 NavigationEntry* entry = contents->controller()->GetActiveEntry(); 691 NavigationEntry* entry = controller()->GetActiveEntry();
773 ASSERT_TRUE(entry != NULL); 692 ASSERT_TRUE(entry != NULL);
774 // The URL specified to the interstitial should have been ignored. 693 // The URL specified to the interstitial should have been ignored.
775 EXPECT_TRUE(entry->url() == url1); 694 EXPECT_TRUE(entry->url() == url1);
776 695
777 // Now don't proceed. 696 // Now don't proceed.
778 interstitial->DontProceed(); 697 interstitial->DontProceed();
779 EXPECT_TRUE(deleted); 698 EXPECT_TRUE(deleted);
780 EXPECT_EQ(TestInterstitialPage::CANCELED, state); 699 EXPECT_EQ(TestInterstitialPage::CANCELED, state);
781 EXPECT_FALSE(contents->showing_interstitial_page()); 700 EXPECT_FALSE(contents()->showing_interstitial_page());
782 EXPECT_TRUE(contents->interstitial_page() == NULL); 701 EXPECT_TRUE(contents()->interstitial_page() == NULL);
783 entry = contents->controller()->GetActiveEntry(); 702 entry = controller()->GetActiveEntry();
784 ASSERT_TRUE(entry != NULL); 703 ASSERT_TRUE(entry != NULL);
785 EXPECT_TRUE(entry->url() == url1); 704 EXPECT_TRUE(entry->url() == url1);
786 EXPECT_EQ(1, contents->controller()->GetEntryCount()); 705 EXPECT_EQ(1, controller()->GetEntryCount());
787 } 706 }
788 707
789 // Test navigating to a page (with the navigation initiated from the browser, 708 // Test navigating to a page (with the navigation initiated from the browser,
790 // as when a URL is typed in the location bar) that shows an interstitial and 709 // as when a URL is typed in the location bar) that shows an interstitial and
791 // creates a new navigation entry, then proceeding. 710 // creates a new navigation entry, then proceeding.
792 TEST_F(WebContentsTest, 711 TEST_F(WebContentsTest,
793 ShowInterstitialFromBrowserNewNavigationProceed) { 712 ShowInterstitialFromBrowserNewNavigationProceed) {
794 // Navigate to a page. 713 // Navigate to a page.
795 GURL url1("http://www.google.com"); 714 GURL url1("http://www.google.com");
796 Navigate(1, url1); 715 rvh()->SendNavigate(1, url1);
797 EXPECT_EQ(1, contents->controller()->GetEntryCount()); 716 EXPECT_EQ(1, controller()->GetEntryCount());
798 717
799 // Initiate a browser navigation that will trigger the interstitial 718 // Initiate a browser navigation that will trigger the interstitial
800 contents->controller()->LoadURL(GURL("http://www.evil.com"), GURL(), 719 controller()->LoadURL(GURL("http://www.evil.com"), GURL(),
801 PageTransition::TYPED); 720 PageTransition::TYPED);
802 721
803 // Show an interstitial. 722 // Show an interstitial.
804 TestInterstitialPage::InterstitialState state = 723 TestInterstitialPage::InterstitialState state =
805 TestInterstitialPage::UNDECIDED; 724 TestInterstitialPage::UNDECIDED;
806 bool deleted = false; 725 bool deleted = false;
807 GURL url2("http://interstitial"); 726 GURL url2("http://interstitial");
808 TestInterstitialPage* interstitial = 727 TestInterstitialPage* interstitial =
809 new TestInterstitialPage(contents, true, url2, &state, &deleted); 728 new TestInterstitialPage(contents(), true, url2, &state, &deleted);
810 TestInterstitialPageStateGuard state_guard(interstitial); 729 TestInterstitialPageStateGuard state_guard(interstitial);
811 interstitial->Show(); 730 interstitial->Show();
812 // The interstitial should not show until its navigation has committed. 731 // The interstitial should not show until its navigation has committed.
813 EXPECT_FALSE(interstitial->is_showing()); 732 EXPECT_FALSE(interstitial->is_showing());
814 EXPECT_FALSE(contents->showing_interstitial_page()); 733 EXPECT_FALSE(contents()->showing_interstitial_page());
815 EXPECT_TRUE(contents->interstitial_page() == NULL); 734 EXPECT_TRUE(contents()->interstitial_page() == NULL);
816 // Let's commit the interstitial navigation. 735 // Let's commit the interstitial navigation.
817 interstitial->TestDidNavigate(1, url2); 736 interstitial->TestDidNavigate(1, url2);
818 EXPECT_TRUE(interstitial->is_showing()); 737 EXPECT_TRUE(interstitial->is_showing());
819 EXPECT_TRUE(contents->showing_interstitial_page()); 738 EXPECT_TRUE(contents()->showing_interstitial_page());
820 EXPECT_TRUE(contents->interstitial_page() == interstitial); 739 EXPECT_TRUE(contents()->interstitial_page() == interstitial);
821 NavigationEntry* entry = contents->controller()->GetActiveEntry(); 740 NavigationEntry* entry = controller()->GetActiveEntry();
822 ASSERT_TRUE(entry != NULL); 741 ASSERT_TRUE(entry != NULL);
823 EXPECT_TRUE(entry->url() == url2); 742 EXPECT_TRUE(entry->url() == url2);
824 743
825 // Then proceed. 744 // Then proceed.
826 interstitial->Proceed(); 745 interstitial->Proceed();
827 // The interstitial should show until the new navigation commits. 746 // The interstitial should show until the new navigation commits.
828 ASSERT_FALSE(deleted); 747 ASSERT_FALSE(deleted);
829 EXPECT_EQ(TestInterstitialPage::OKED, state); 748 EXPECT_EQ(TestInterstitialPage::OKED, state);
830 EXPECT_TRUE(contents->showing_interstitial_page()); 749 EXPECT_TRUE(contents()->showing_interstitial_page());
831 EXPECT_TRUE(contents->interstitial_page() == interstitial); 750 EXPECT_TRUE(contents()->interstitial_page() == interstitial);
832 751
833 // Simulate the navigation to the page, that's when the interstitial gets 752 // Simulate the navigation to the page, that's when the interstitial gets
834 // hidden. 753 // hidden.
835 GURL url3("http://www.thepage.com"); 754 GURL url3("http://www.thepage.com");
836 Navigate(2, url3); 755 rvh()->SendNavigate(2, url3);
837 756
838 EXPECT_TRUE(deleted); 757 EXPECT_TRUE(deleted);
839 EXPECT_FALSE(contents->showing_interstitial_page()); 758 EXPECT_FALSE(contents()->showing_interstitial_page());
840 EXPECT_TRUE(contents->interstitial_page() == NULL); 759 EXPECT_TRUE(contents()->interstitial_page() == NULL);
841 entry = contents->controller()->GetActiveEntry(); 760 entry = controller()->GetActiveEntry();
842 ASSERT_TRUE(entry != NULL); 761 ASSERT_TRUE(entry != NULL);
843 EXPECT_TRUE(entry->url() == url3); 762 EXPECT_TRUE(entry->url() == url3);
844 763
845 EXPECT_EQ(2, contents->controller()->GetEntryCount()); 764 EXPECT_EQ(2, controller()->GetEntryCount());
846 } 765 }
847 766
848 // Test navigating to a page (with the navigation initiated from the renderer, 767 // Test navigating to a page (with the navigation initiated from the renderer,
849 // as when clicking on a link in the page) that shows an interstitial and 768 // as when clicking on a link in the page) that shows an interstitial and
850 // creates a new navigation entry, then proceeding. 769 // creates a new navigation entry, then proceeding.
851 TEST_F(WebContentsTest, 770 TEST_F(WebContentsTest,
852 ShowInterstitialFromRendererNewNavigationProceed) { 771 ShowInterstitialFromRendererNewNavigationProceed) {
853 // Navigate to a page. 772 // Navigate to a page.
854 GURL url1("http://www.google.com"); 773 GURL url1("http://www.google.com");
855 Navigate(1, url1); 774 rvh()->SendNavigate(1, url1);
856 EXPECT_EQ(1, contents->controller()->GetEntryCount()); 775 EXPECT_EQ(1, controller()->GetEntryCount());
857 776
858 // Show an interstitial. 777 // Show an interstitial.
859 TestInterstitialPage::InterstitialState state = 778 TestInterstitialPage::InterstitialState state =
860 TestInterstitialPage::UNDECIDED; 779 TestInterstitialPage::UNDECIDED;
861 bool deleted = false; 780 bool deleted = false;
862 GURL url2("http://interstitial"); 781 GURL url2("http://interstitial");
863 TestInterstitialPage* interstitial = 782 TestInterstitialPage* interstitial =
864 new TestInterstitialPage(contents, true, url2, &state, &deleted); 783 new TestInterstitialPage(contents(), true, url2, &state, &deleted);
865 TestInterstitialPageStateGuard state_guard(interstitial); 784 TestInterstitialPageStateGuard state_guard(interstitial);
866 interstitial->Show(); 785 interstitial->Show();
867 // The interstitial should not show until its navigation has committed. 786 // The interstitial should not show until its navigation has committed.
868 EXPECT_FALSE(interstitial->is_showing()); 787 EXPECT_FALSE(interstitial->is_showing());
869 EXPECT_FALSE(contents->showing_interstitial_page()); 788 EXPECT_FALSE(contents()->showing_interstitial_page());
870 EXPECT_TRUE(contents->interstitial_page() == NULL); 789 EXPECT_TRUE(contents()->interstitial_page() == NULL);
871 // Let's commit the interstitial navigation. 790 // Let's commit the interstitial navigation.
872 interstitial->TestDidNavigate(1, url2); 791 interstitial->TestDidNavigate(1, url2);
873 EXPECT_TRUE(interstitial->is_showing()); 792 EXPECT_TRUE(interstitial->is_showing());
874 EXPECT_TRUE(contents->showing_interstitial_page()); 793 EXPECT_TRUE(contents()->showing_interstitial_page());
875 EXPECT_TRUE(contents->interstitial_page() == interstitial); 794 EXPECT_TRUE(contents()->interstitial_page() == interstitial);
876 NavigationEntry* entry = contents->controller()->GetActiveEntry(); 795 NavigationEntry* entry = controller()->GetActiveEntry();
877 ASSERT_TRUE(entry != NULL); 796 ASSERT_TRUE(entry != NULL);
878 EXPECT_TRUE(entry->url() == url2); 797 EXPECT_TRUE(entry->url() == url2);
879 798
880 // Then proceed. 799 // Then proceed.
881 interstitial->Proceed(); 800 interstitial->Proceed();
882 // The interstitial should show until the new navigation commits. 801 // The interstitial should show until the new navigation commits.
883 ASSERT_FALSE(deleted); 802 ASSERT_FALSE(deleted);
884 EXPECT_EQ(TestInterstitialPage::OKED, state); 803 EXPECT_EQ(TestInterstitialPage::OKED, state);
885 EXPECT_TRUE(contents->showing_interstitial_page()); 804 EXPECT_TRUE(contents()->showing_interstitial_page());
886 EXPECT_TRUE(contents->interstitial_page() == interstitial); 805 EXPECT_TRUE(contents()->interstitial_page() == interstitial);
887 806
888 // Simulate the navigation to the page, that's when the interstitial gets 807 // Simulate the navigation to the page, that's when the interstitial gets
889 // hidden. 808 // hidden.
890 GURL url3("http://www.thepage.com"); 809 GURL url3("http://www.thepage.com");
891 Navigate(2, url3); 810 rvh()->SendNavigate(2, url3);
892 811
893 EXPECT_TRUE(deleted); 812 EXPECT_TRUE(deleted);
894 EXPECT_FALSE(contents->showing_interstitial_page()); 813 EXPECT_FALSE(contents()->showing_interstitial_page());
895 EXPECT_TRUE(contents->interstitial_page() == NULL); 814 EXPECT_TRUE(contents()->interstitial_page() == NULL);
896 entry = contents->controller()->GetActiveEntry(); 815 entry = controller()->GetActiveEntry();
897 ASSERT_TRUE(entry != NULL); 816 ASSERT_TRUE(entry != NULL);
898 EXPECT_TRUE(entry->url() == url3); 817 EXPECT_TRUE(entry->url() == url3);
899 818
900 EXPECT_EQ(2, contents->controller()->GetEntryCount()); 819 EXPECT_EQ(2, controller()->GetEntryCount());
901 } 820 }
902 821
903 // Test navigating to a page that shows an interstitial without creating a new 822 // Test navigating to a page that shows an interstitial without creating a new
904 // navigation entry (this happens when the interstitial is triggered by a 823 // navigation entry (this happens when the interstitial is triggered by a
905 // sub-resource in the page), then proceeding. 824 // sub-resource in the page), then proceeding.
906 TEST_F(WebContentsTest, ShowInterstitialNoNewNavigationProceed) { 825 TEST_F(WebContentsTest, ShowInterstitialNoNewNavigationProceed) {
907 // Navigate to a page so we have a navigation entry in the controller. 826 // Navigate to a page so we have a navigation entry in the controller.
908 GURL url1("http://www.google.com"); 827 GURL url1("http://www.google.com");
909 Navigate(1, url1); 828 rvh()->SendNavigate(1, url1);
910 EXPECT_EQ(1, contents->controller()->GetEntryCount()); 829 EXPECT_EQ(1, controller()->GetEntryCount());
911 830
912 // Show an interstitial. 831 // Show an interstitial.
913 TestInterstitialPage::InterstitialState state = 832 TestInterstitialPage::InterstitialState state =
914 TestInterstitialPage::UNDECIDED; 833 TestInterstitialPage::UNDECIDED;
915 bool deleted = false; 834 bool deleted = false;
916 GURL url2("http://interstitial"); 835 GURL url2("http://interstitial");
917 TestInterstitialPage* interstitial = 836 TestInterstitialPage* interstitial =
918 new TestInterstitialPage(contents, false, url2, &state, &deleted); 837 new TestInterstitialPage(contents(), false, url2, &state, &deleted);
919 TestInterstitialPageStateGuard state_guard(interstitial); 838 TestInterstitialPageStateGuard state_guard(interstitial);
920 interstitial->Show(); 839 interstitial->Show();
921 // The interstitial should not show until its navigation has committed. 840 // The interstitial should not show until its navigation has committed.
922 EXPECT_FALSE(interstitial->is_showing()); 841 EXPECT_FALSE(interstitial->is_showing());
923 EXPECT_FALSE(contents->showing_interstitial_page()); 842 EXPECT_FALSE(contents()->showing_interstitial_page());
924 EXPECT_TRUE(contents->interstitial_page() == NULL); 843 EXPECT_TRUE(contents()->interstitial_page() == NULL);
925 // Let's commit the interstitial navigation. 844 // Let's commit the interstitial navigation.
926 interstitial->TestDidNavigate(1, url2); 845 interstitial->TestDidNavigate(1, url2);
927 EXPECT_TRUE(interstitial->is_showing()); 846 EXPECT_TRUE(interstitial->is_showing());
928 EXPECT_TRUE(contents->showing_interstitial_page()); 847 EXPECT_TRUE(contents()->showing_interstitial_page());
929 EXPECT_TRUE(contents->interstitial_page() == interstitial); 848 EXPECT_TRUE(contents()->interstitial_page() == interstitial);
930 NavigationEntry* entry = contents->controller()->GetActiveEntry(); 849 NavigationEntry* entry = controller()->GetActiveEntry();
931 ASSERT_TRUE(entry != NULL); 850 ASSERT_TRUE(entry != NULL);
932 // The URL specified to the interstitial should have been ignored. 851 // The URL specified to the interstitial should have been ignored.
933 EXPECT_TRUE(entry->url() == url1); 852 EXPECT_TRUE(entry->url() == url1);
934 853
935 // Then proceed. 854 // Then proceed.
936 interstitial->Proceed(); 855 interstitial->Proceed();
937 // Since this is not a new navigation, the previous page is dismissed right 856 // Since this is not a new navigation, the previous page is dismissed right
938 // away and shows the original page. 857 // away and shows the original page.
939 EXPECT_TRUE(deleted); 858 EXPECT_TRUE(deleted);
940 EXPECT_EQ(TestInterstitialPage::OKED, state); 859 EXPECT_EQ(TestInterstitialPage::OKED, state);
941 EXPECT_FALSE(contents->showing_interstitial_page()); 860 EXPECT_FALSE(contents()->showing_interstitial_page());
942 EXPECT_TRUE(contents->interstitial_page() == NULL); 861 EXPECT_TRUE(contents()->interstitial_page() == NULL);
943 entry = contents->controller()->GetActiveEntry(); 862 entry = controller()->GetActiveEntry();
944 ASSERT_TRUE(entry != NULL); 863 ASSERT_TRUE(entry != NULL);
945 EXPECT_TRUE(entry->url() == url1); 864 EXPECT_TRUE(entry->url() == url1);
946 865
947 EXPECT_EQ(1, contents->controller()->GetEntryCount()); 866 EXPECT_EQ(1, controller()->GetEntryCount());
948 } 867 }
949 868
950 // Test navigating to a page that shows an interstitial, then navigating away. 869 // Test navigating to a page that shows an interstitial, then navigating away.
951 TEST_F(WebContentsTest, ShowInterstitialThenNavigate) { 870 TEST_F(WebContentsTest, ShowInterstitialThenNavigate) {
952 // Show interstitial. 871 // Show interstitial.
953 TestInterstitialPage::InterstitialState state = 872 TestInterstitialPage::InterstitialState state =
954 TestInterstitialPage::UNDECIDED; 873 TestInterstitialPage::UNDECIDED;
955 bool deleted = false; 874 bool deleted = false;
956 GURL url("http://interstitial"); 875 GURL url("http://interstitial");
957 TestInterstitialPage* interstitial = 876 TestInterstitialPage* interstitial =
958 new TestInterstitialPage(contents, true, url, &state, &deleted); 877 new TestInterstitialPage(contents(), true, url, &state, &deleted);
959 TestInterstitialPageStateGuard state_guard(interstitial); 878 TestInterstitialPageStateGuard state_guard(interstitial);
960 interstitial->Show(); 879 interstitial->Show();
961 interstitial->TestDidNavigate(1, url); 880 interstitial->TestDidNavigate(1, url);
962 881
963 // While interstitial showing, navigate to a new URL. 882 // While interstitial showing, navigate to a new URL.
964 const GURL url2("http://www.yahoo.com"); 883 const GURL url2("http://www.yahoo.com");
965 Navigate(1, url2); 884 rvh()->SendNavigate(1, url2);
966 885
967 EXPECT_TRUE(deleted); 886 EXPECT_TRUE(deleted);
968 EXPECT_EQ(TestInterstitialPage::CANCELED, state); 887 EXPECT_EQ(TestInterstitialPage::CANCELED, state);
969 } 888 }
970 889 /* FIXME(brettw)
971 // Test navigating to a page that shows an interstitial, then close the tab. 890 // Test navigating to a page that shows an interstitial, then close the tab.
972 TEST_F(WebContentsTest, ShowInterstitialThenCloseTab) { 891 TEST_F(WebContentsTest, ShowInterstitialThenCloseTab) {
973 // Show interstitial. 892 // Show interstitial.
974 TestInterstitialPage::InterstitialState state = 893 TestInterstitialPage::InterstitialState state =
975 TestInterstitialPage::UNDECIDED; 894 TestInterstitialPage::UNDECIDED;
976 bool deleted = false; 895 bool deleted = false;
977 GURL url("http://interstitial"); 896 GURL url("http://interstitial");
978 TestInterstitialPage* interstitial = 897 TestInterstitialPage* interstitial =
979 new TestInterstitialPage(contents, true, url, &state, &deleted); 898 new TestInterstitialPage(contents(), true, url, &state, &deleted);
980 TestInterstitialPageStateGuard state_guard(interstitial); 899 TestInterstitialPageStateGuard state_guard(interstitial);
981 interstitial->Show(); 900 interstitial->Show();
982 interstitial->TestDidNavigate(1, url); 901 interstitial->TestDidNavigate(1, url);
983 902
984 // Now close the tab. 903 // Now close the tab.
985 contents->CloseContents(); 904 contents()->CloseContents();
986 contents = NULL; // So we don't detroy it again on TearDown. 905 contents = NULL; // So we don't detroy it again on TearDown.
987 EXPECT_TRUE(deleted); 906 EXPECT_TRUE(deleted);
988 EXPECT_EQ(TestInterstitialPage::CANCELED, state); 907 EXPECT_EQ(TestInterstitialPage::CANCELED, state);
989 } 908 }
990 909 */
991 // Test that after Proceed is called and an interstitial is still shown, no more 910 // Test that after Proceed is called and an interstitial is still shown, no more
992 // commands get executed. 911 // commands get executed.
993 TEST_F(WebContentsTest, ShowInterstitialProceedMultipleCommands) { 912 TEST_F(WebContentsTest, ShowInterstitialProceedMultipleCommands) {
994 // Navigate to a page so we have a navigation entry in the controller. 913 // Navigate to a page so we have a navigation entry in the controller.
995 GURL url1("http://www.google.com"); 914 GURL url1("http://www.google.com");
996 Navigate(1, url1); 915 rvh()->SendNavigate(1, url1);
997 EXPECT_EQ(1, contents->controller()->GetEntryCount()); 916 EXPECT_EQ(1, controller()->GetEntryCount());
998 917
999 // Show an interstitial. 918 // Show an interstitial.
1000 TestInterstitialPage::InterstitialState state = 919 TestInterstitialPage::InterstitialState state =
1001 TestInterstitialPage::UNDECIDED; 920 TestInterstitialPage::UNDECIDED;
1002 bool deleted = false; 921 bool deleted = false;
1003 GURL url2("http://interstitial"); 922 GURL url2("http://interstitial");
1004 TestInterstitialPage* interstitial = 923 TestInterstitialPage* interstitial =
1005 new TestInterstitialPage(contents, true, url2, &state, &deleted); 924 new TestInterstitialPage(contents(), true, url2, &state, &deleted);
1006 TestInterstitialPageStateGuard state_guard(interstitial); 925 TestInterstitialPageStateGuard state_guard(interstitial);
1007 interstitial->Show(); 926 interstitial->Show();
1008 interstitial->TestDidNavigate(1, url2); 927 interstitial->TestDidNavigate(1, url2);
1009 928
1010 // Run a command. 929 // Run a command.
1011 EXPECT_EQ(0, interstitial->command_received_count()); 930 EXPECT_EQ(0, interstitial->command_received_count());
1012 interstitial->TestDomOperationResponse("toto"); 931 interstitial->TestDomOperationResponse("toto");
1013 EXPECT_EQ(1, interstitial->command_received_count()); 932 EXPECT_EQ(1, interstitial->command_received_count());
1014 933
1015 // Then proceed. 934 // Then proceed.
1016 interstitial->Proceed(); 935 interstitial->Proceed();
1017 ASSERT_FALSE(deleted); 936 ASSERT_FALSE(deleted);
1018 937
1019 // While the navigation to the new page is pending, send other commands, they 938 // While the navigation to the new page is pending, send other commands, they
1020 // should be ignored. 939 // should be ignored.
1021 interstitial->TestDomOperationResponse("hello"); 940 interstitial->TestDomOperationResponse("hello");
1022 interstitial->TestDomOperationResponse("hi"); 941 interstitial->TestDomOperationResponse("hi");
1023 EXPECT_EQ(1, interstitial->command_received_count()); 942 EXPECT_EQ(1, interstitial->command_received_count());
1024 } 943 }
1025 944
1026 // Test showing an interstitial while another interstitial is already showing. 945 // Test showing an interstitial while another interstitial is already showing.
1027 TEST_F(WebContentsTest, ShowInterstitialOnInterstitial) { 946 TEST_F(WebContentsTest, ShowInterstitialOnInterstitial) {
1028 // Navigate to a page so we have a navigation entry in the controller. 947 // Navigate to a page so we have a navigation entry in the controller.
1029 GURL start_url("http://www.google.com"); 948 GURL start_url("http://www.google.com");
1030 Navigate(1, start_url); 949 rvh()->SendNavigate(1, start_url);
1031 EXPECT_EQ(1, contents->controller()->GetEntryCount()); 950 EXPECT_EQ(1, controller()->GetEntryCount());
1032 951
1033 // Show an interstitial. 952 // Show an interstitial.
1034 TestInterstitialPage::InterstitialState state1 = 953 TestInterstitialPage::InterstitialState state1 =
1035 TestInterstitialPage::UNDECIDED; 954 TestInterstitialPage::UNDECIDED;
1036 bool deleted1 = false; 955 bool deleted1 = false;
1037 GURL url1("http://interstitial1"); 956 GURL url1("http://interstitial1");
1038 TestInterstitialPage* interstitial1 = 957 TestInterstitialPage* interstitial1 =
1039 new TestInterstitialPage(contents, true, url1, &state1, &deleted1); 958 new TestInterstitialPage(contents(), true, url1, &state1, &deleted1);
1040 TestInterstitialPageStateGuard state_guard1(interstitial1); 959 TestInterstitialPageStateGuard state_guard1(interstitial1);
1041 interstitial1->Show(); 960 interstitial1->Show();
1042 interstitial1->TestDidNavigate(1, url1); 961 interstitial1->TestDidNavigate(1, url1);
1043 962
1044 // Now show another interstitial. 963 // Now show another interstitial.
1045 TestInterstitialPage::InterstitialState state2 = 964 TestInterstitialPage::InterstitialState state2 =
1046 TestInterstitialPage::UNDECIDED; 965 TestInterstitialPage::UNDECIDED;
1047 bool deleted2 = false; 966 bool deleted2 = false;
1048 GURL url2("http://interstitial2"); 967 GURL url2("http://interstitial2");
1049 TestInterstitialPage* interstitial2 = 968 TestInterstitialPage* interstitial2 =
1050 new TestInterstitialPage(contents, true, url2, &state2, &deleted2); 969 new TestInterstitialPage(contents(), true, url2, &state2, &deleted2);
1051 TestInterstitialPageStateGuard state_guard2(interstitial2); 970 TestInterstitialPageStateGuard state_guard2(interstitial2);
1052 interstitial2->Show(); 971 interstitial2->Show();
1053 interstitial2->TestDidNavigate(1, url2); 972 interstitial2->TestDidNavigate(1, url2);
1054 973
1055 // Showing interstitial2 should have caused interstitial1 to go away. 974 // Showing interstitial2 should have caused interstitial1 to go away.
1056 EXPECT_TRUE(deleted1); 975 EXPECT_TRUE(deleted1);
1057 EXPECT_EQ(TestInterstitialPage::CANCELED, state1); 976 EXPECT_EQ(TestInterstitialPage::CANCELED, state1);
1058 977
1059 // Let's make sure interstitial2 is working as intended. 978 // Let's make sure interstitial2 is working as intended.
1060 ASSERT_FALSE(deleted2); 979 ASSERT_FALSE(deleted2);
1061 EXPECT_EQ(TestInterstitialPage::UNDECIDED, state2); 980 EXPECT_EQ(TestInterstitialPage::UNDECIDED, state2);
1062 interstitial2->Proceed(); 981 interstitial2->Proceed();
1063 GURL landing_url("http://www.thepage.com"); 982 GURL landing_url("http://www.thepage.com");
1064 Navigate(2, landing_url); 983 rvh()->SendNavigate(2, landing_url);
1065 984
1066 EXPECT_TRUE(deleted2); 985 EXPECT_TRUE(deleted2);
1067 EXPECT_FALSE(contents->showing_interstitial_page()); 986 EXPECT_FALSE(contents()->showing_interstitial_page());
1068 EXPECT_TRUE(contents->interstitial_page() == NULL); 987 EXPECT_TRUE(contents()->interstitial_page() == NULL);
1069 NavigationEntry* entry = contents->controller()->GetActiveEntry(); 988 NavigationEntry* entry = controller()->GetActiveEntry();
1070 ASSERT_TRUE(entry != NULL); 989 ASSERT_TRUE(entry != NULL);
1071 EXPECT_TRUE(entry->url() == landing_url); 990 EXPECT_TRUE(entry->url() == landing_url);
1072 EXPECT_EQ(2, contents->controller()->GetEntryCount()); 991 EXPECT_EQ(2, controller()->GetEntryCount());
1073 } 992 }
1074 993
1075 // Test that navigating away from an interstitial while it's loading cause it 994 // Test that navigating away from an interstitial while it's loading cause it
1076 // not to show. 995 // not to show.
1077 TEST_F(WebContentsTest, NavigateBeforeInterstitialShows) { 996 TEST_F(WebContentsTest, NavigateBeforeInterstitialShows) {
1078 // Show an interstitial. 997 // Show an interstitial.
1079 TestInterstitialPage::InterstitialState state = 998 TestInterstitialPage::InterstitialState state =
1080 TestInterstitialPage::UNDECIDED; 999 TestInterstitialPage::UNDECIDED;
1081 bool deleted = false; 1000 bool deleted = false;
1082 GURL interstitial_url("http://interstitial"); 1001 GURL interstitial_url("http://interstitial");
1083 TestInterstitialPage* interstitial = 1002 TestInterstitialPage* interstitial =
1084 new TestInterstitialPage(contents, true, interstitial_url, 1003 new TestInterstitialPage(contents(), true, interstitial_url,
1085 &state, &deleted); 1004 &state, &deleted);
1086 TestInterstitialPageStateGuard state_guard(interstitial); 1005 TestInterstitialPageStateGuard state_guard(interstitial);
1087 interstitial->Show(); 1006 interstitial->Show();
1088 1007
1089 // Let's simulate a navigation initiated from the browser before the 1008 // Let's simulate a navigation initiated from the browser before the
1090 // interstitial finishes loading. 1009 // interstitial finishes loading.
1091 const GURL url("http://www.google.com"); 1010 const GURL url("http://www.google.com");
1092 contents->controller()->LoadURL(url, GURL(), PageTransition::TYPED); 1011 controller()->LoadURL(url, GURL(), PageTransition::TYPED);
1093 ASSERT_FALSE(deleted); 1012 ASSERT_FALSE(deleted);
1094 EXPECT_FALSE(interstitial->is_showing()); 1013 EXPECT_FALSE(interstitial->is_showing());
1095 1014
1096 // Now let's make the interstitial navigation commit. 1015 // Now let's make the interstitial navigation commit.
1097 interstitial->TestDidNavigate(1, interstitial_url); 1016 interstitial->TestDidNavigate(1, interstitial_url);
1098 1017
1099 // After it loaded the interstitial should be gone. 1018 // After it loaded the interstitial should be gone.
1100 EXPECT_TRUE(deleted); 1019 EXPECT_TRUE(deleted);
1101 EXPECT_EQ(TestInterstitialPage::CANCELED, state); 1020 EXPECT_EQ(TestInterstitialPage::CANCELED, state);
1102 } 1021 }
1103 1022
1104 // Test showing an interstitial and have its renderer crash. 1023 // Test showing an interstitial and have its renderer crash.
1105 TEST_F(WebContentsTest, InterstitialCrasher) { 1024 TEST_F(WebContentsTest, InterstitialCrasher) {
1106 // Show an interstitial. 1025 // Show an interstitial.
1107 TestInterstitialPage::InterstitialState state = 1026 TestInterstitialPage::InterstitialState state =
1108 TestInterstitialPage::UNDECIDED; 1027 TestInterstitialPage::UNDECIDED;
1109 bool deleted = false; 1028 bool deleted = false;
1110 GURL url("http://interstitial"); 1029 GURL url("http://interstitial");
1111 TestInterstitialPage* interstitial = 1030 TestInterstitialPage* interstitial =
1112 new TestInterstitialPage(contents, true, url, &state, &deleted); 1031 new TestInterstitialPage(contents(), true, url, &state, &deleted);
1113 TestInterstitialPageStateGuard state_guard(interstitial); 1032 TestInterstitialPageStateGuard state_guard(interstitial);
1114 interstitial->Show(); 1033 interstitial->Show();
1115 // Simulate a renderer crash before the interstitial is shown. 1034 // Simulate a renderer crash before the interstitial is shown.
1116 interstitial->TestRendererGone(); 1035 interstitial->TestRendererGone();
1117 // The interstitial should have been dismissed. 1036 // The interstitial should have been dismissed.
1118 EXPECT_TRUE(deleted); 1037 EXPECT_TRUE(deleted);
1119 EXPECT_EQ(TestInterstitialPage::CANCELED, state); 1038 EXPECT_EQ(TestInterstitialPage::CANCELED, state);
1120 1039
1121 // Now try again but this time crash the intersitial after it was shown. 1040 // Now try again but this time crash the intersitial after it was shown.
1122 interstitial = 1041 interstitial =
1123 new TestInterstitialPage(contents, true, url, &state, &deleted); 1042 new TestInterstitialPage(contents(), true, url, &state, &deleted);
1124 interstitial->Show(); 1043 interstitial->Show();
1125 interstitial->TestDidNavigate(1, url); 1044 interstitial->TestDidNavigate(1, url);
1126 // Simulate a renderer crash. 1045 // Simulate a renderer crash.
1127 interstitial->TestRendererGone(); 1046 interstitial->TestRendererGone();
1128 // The interstitial should have been dismissed. 1047 // The interstitial should have been dismissed.
1129 EXPECT_TRUE(deleted); 1048 EXPECT_TRUE(deleted);
1130 EXPECT_EQ(TestInterstitialPage::CANCELED, state); 1049 EXPECT_EQ(TestInterstitialPage::CANCELED, state);
1131 } 1050 }
OLDNEW
« no previous file with comments | « chrome/browser/tab_contents/test_web_contents.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698