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

Side by Side Diff: chrome/browser/navigation_controller_unittest.cc

Issue 479: DidNavigate refactor of doom (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 12 years, 3 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
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/file_util.h" 5 #include "base/file_util.h"
6 #include "base/path_service.h" 6 #include "base/path_service.h"
7 #include "base/string_util.h" 7 #include "base/string_util.h"
8 #include "chrome/browser/browser_type.h" 8 #include "chrome/browser/browser_type.h"
9 #include "chrome/browser/navigation_controller.h" 9 #include "chrome/browser/navigation_controller.h"
10 #include "chrome/browser/navigation_entry.h" 10 #include "chrome/browser/navigation_entry.h"
11 #include "chrome/browser/profile_manager.h" 11 #include "chrome/browser/profile_manager.h"
12 #include "chrome/browser/history/history.h" 12 #include "chrome/browser/history/history.h"
13 #include "chrome/browser/session_service.h"
13 #include "chrome/browser/session_service_test_helper.h" 14 #include "chrome/browser/session_service_test_helper.h"
14 #include "chrome/browser/tab_contents.h" 15 #include "chrome/browser/tab_contents.h"
15 #include "chrome/browser/tab_contents_delegate.h" 16 #include "chrome/browser/tab_contents_delegate.h"
16 #include "chrome/browser/tab_contents_factory.h" 17 #include "chrome/browser/tab_contents_factory.h"
17 #include "chrome/common/notification_types.h" 18 #include "chrome/common/notification_types.h"
18 #include "chrome/common/stl_util-inl.h" 19 #include "chrome/common/stl_util-inl.h"
19 #include "chrome/test/test_notification_tracker.h" 20 #include "chrome/test/test_notification_tracker.h"
20 #include "chrome/test/testing_profile.h" 21 #include "chrome/test/testing_profile.h"
21 #include "net/base/net_util.h" 22 #include "net/base/net_util.h"
22 #include "testing/gtest/include/gtest/gtest.h" 23 #include "testing/gtest/include/gtest/gtest.h"
23 24
24 namespace { 25 namespace {
25 26
26 // TODO(darin): come up with a better way to define these integers 27 // TODO(darin): come up with a better way to define these integers
27 // TODO(acw): we should have a real dynamic factory for content types. 28 // TODO(acw): we should have a real dynamic factory for content types.
28 // That way we could have several implementation of 29 // That way we could have several implementation of
29 // TabContents::CreateWithType(). Once this is done we'll be able to 30 // TabContents::CreateWithType(). Once this is done we'll be able to
30 // have a unit test for NavigationController::Clone() 31 // have a unit test for NavigationController::Clone()
31 const TabContentsType kTestContentsType1 = 32 const TabContentsType kTestContentsType1 =
32 static_cast<TabContentsType>(TAB_CONTENTS_NUM_TYPES + 1); 33 static_cast<TabContentsType>(TAB_CONTENTS_NUM_TYPES + 1);
33 const TabContentsType kTestContentsType2 = 34 const TabContentsType kTestContentsType2 =
34 static_cast<TabContentsType>(TAB_CONTENTS_NUM_TYPES + 2); 35 static_cast<TabContentsType>(TAB_CONTENTS_NUM_TYPES + 2);
35 36
37 // Tests can set this to set the site instance for all the test contents. This
38 // refcounted pointer will be automatically derefed on cleanup.
39 static SiteInstance* site_instance;
40
36 // TestContents ---------------------------------------------------------------- 41 // TestContents ----------------------------------------------------------------
37 42
38 class TestContents : public TabContents { 43 class TestContents : public TabContents {
39 public: 44 public:
40 BEGIN_MSG_MAP(TestContents) 45 BEGIN_MSG_MAP(TestContents)
41 END_MSG_MAP() 46 END_MSG_MAP()
42 47
43 TestContents(TabContentsType type) : TabContents(type) { 48 TestContents(TabContentsType type) : TabContents(type) {
44 } 49 }
45 50
46 // Just record the navigation so it can be checked by the test case 51 // Overridden from TabContents so we can provide a non-NULL site instance in
47 bool Navigate(const NavigationEntry& entry, bool reload) { 52 // some cases. To use, the test will have to set the site_instance_ member
48 pending_entry_.reset(new NavigationEntry(entry)); 53 // variable to some site instance it creates.
54 virtual SiteInstance* GetSiteInstance() const {
55 return site_instance;
56 }
57
58 // Just record the navigation so it can be checked by the test case. We don't
59 // want the normal behavior of TabContents just saying it committed since we
60 // want to behave more like the renderer and call RendererDidNavigate.
61 virtual bool NavigateToPendingEntry(bool reload) {
62 pending_entry_.reset(new NavigationEntry(*controller()->GetPendingEntry()));
49 return true; 63 return true;
50 } 64 }
51 65
52 void CompleteNavigation(int page_id) { 66 // Sets up a call to RendererDidNavigate pretending to be a main frame
53 DCHECK(pending_entry_.get()); 67 // navigation to the given URL.
54 pending_entry_->set_page_id(page_id); 68 void CompleteNavigationAsRenderer(int page_id, const GURL& url) {
69 ViewHostMsg_FrameNavigate_Params params;
70 params.page_id = page_id;
71 params.url = url;
72 params.transition = PageTransition::LINK;
73 params.should_update_history = false;
74 params.gesture = NavigationGestureUser;
75 params.is_post = false;
76
55 NavigationController::LoadCommittedDetails details; 77 NavigationController::LoadCommittedDetails details;
56 DidNavigateToEntry(pending_entry_.get(), &details); 78 controller()->RendererDidNavigate(params, false, &details);
57 controller()->NotifyEntryChangedByPageID(type(), NULL, page_id);
58 pending_entry_.release();
59 } 79 }
60 80
61 NavigationEntry* pending_entry() const { return pending_entry_.get(); } 81 NavigationEntry* pending_entry() const { return pending_entry_.get(); }
62 void set_pending_entry(NavigationEntry* e) { pending_entry_.reset(e); } 82 void set_pending_entry(NavigationEntry* e) { pending_entry_.reset(e); }
63 83
84 protected:
85
64 private: 86 private:
65 scoped_ptr<NavigationEntry> pending_entry_; 87 scoped_ptr<NavigationEntry> pending_entry_;
66 }; 88 };
67 89
68 class TestContentsFactory : public TabContentsFactory { 90 class TestContentsFactory : public TabContentsFactory {
69 public: 91 public:
70 TestContentsFactory(TabContentsType type, const char* scheme) 92 TestContentsFactory(TabContentsType type, const char* scheme)
71 : type_(type), 93 : type_(type),
72 scheme_(scheme) { 94 scheme_(scheme) {
73 } 95 }
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
109 if (!profile) 131 if (!profile)
110 profile = new TestingProfile(); 132 profile = new TestingProfile();
111 133
112 contents = new TestContents(kTestContentsType1); 134 contents = new TestContents(kTestContentsType1);
113 contents->set_delegate(this); 135 contents->set_delegate(this);
114 contents->CreateView(::GetDesktopWindow(), gfx::Rect()); 136 contents->CreateView(::GetDesktopWindow(), gfx::Rect());
115 contents->SetupController(profile); 137 contents->SetupController(profile);
116 } 138 }
117 139
118 virtual void TearDown() { 140 virtual void TearDown() {
141 if (site_instance) {
142 site_instance->Release();
143 site_instance = NULL;
144 }
145
119 // Make sure contents is valid. NavigationControllerHistoryTest ends up 146 // Make sure contents is valid. NavigationControllerHistoryTest ends up
120 // resetting this before TearDown is invoked. 147 // resetting this before TearDown is invoked.
121 if (contents) 148 if (contents)
122 ClearContents(); 149 ClearContents();
123 } 150 }
124 151
125 152
126 void ClearContents() { 153 void ClearContents() {
127 contents->set_delegate(NULL); 154 contents->set_delegate(NULL);
128 contents->CloseContents(); 155 contents->CloseContents();
(...skipping 165 matching lines...) Expand 10 before | Expand all | Expand 10 after
294 TEST_F(NavigationControllerTest, Defaults) { 321 TEST_F(NavigationControllerTest, Defaults) {
295 EXPECT_TRUE(contents->is_active()); 322 EXPECT_TRUE(contents->is_active());
296 EXPECT_TRUE(contents->controller()); 323 EXPECT_TRUE(contents->controller());
297 EXPECT_FALSE(contents->controller()->GetPendingEntry()); 324 EXPECT_FALSE(contents->controller()->GetPendingEntry());
298 EXPECT_FALSE(contents->controller()->GetLastCommittedEntry()); 325 EXPECT_FALSE(contents->controller()->GetLastCommittedEntry());
299 EXPECT_EQ(contents->controller()->GetPendingEntryIndex(), -1); 326 EXPECT_EQ(contents->controller()->GetPendingEntryIndex(), -1);
300 EXPECT_EQ(contents->controller()->GetLastCommittedEntryIndex(), -1); 327 EXPECT_EQ(contents->controller()->GetLastCommittedEntryIndex(), -1);
301 EXPECT_EQ(contents->controller()->GetEntryCount(), 0); 328 EXPECT_EQ(contents->controller()->GetEntryCount(), 0);
302 EXPECT_FALSE(contents->controller()->CanGoBack()); 329 EXPECT_FALSE(contents->controller()->CanGoBack());
303 EXPECT_FALSE(contents->controller()->CanGoForward()); 330 EXPECT_FALSE(contents->controller()->CanGoForward());
304 EXPECT_FALSE(contents->controller()->CanStop());
305 } 331 }
306 332
307 TEST_F(NavigationControllerTest, LoadURL) { 333 TEST_F(NavigationControllerTest, LoadURL) {
308 TestNotificationTracker notifications; 334 TestNotificationTracker notifications;
309 RegisterForAllNavNotifications(&notifications, contents->controller()); 335 RegisterForAllNavNotifications(&notifications, contents->controller());
310 336
311 const GURL url1("test1:foo1"); 337 const GURL url1("test1:foo1");
312 const GURL url2("test1:foo2"); 338 const GURL url2("test1:foo2");
313 339
314 contents->controller()->LoadURL(url1, PageTransition::TYPED); 340 contents->controller()->LoadURL(url1, PageTransition::TYPED);
315 // Creating a pending notification should not have issued any of the 341 // Creating a pending notification should not have issued any of the
316 // notifications we're listening for. 342 // notifications we're listening for.
317 EXPECT_EQ(0, notifications.size()); 343 EXPECT_EQ(0, notifications.size());
318 344
319 // The load should now be pending. 345 // The load should now be pending.
320 EXPECT_TRUE(contents->pending_entry()); 346 EXPECT_TRUE(contents->pending_entry());
321 EXPECT_EQ(contents->controller()->GetEntryCount(), 0); 347 EXPECT_EQ(contents->controller()->GetEntryCount(), 0);
322 EXPECT_EQ(contents->controller()->GetLastCommittedEntryIndex(), -1); 348 EXPECT_EQ(contents->controller()->GetLastCommittedEntryIndex(), -1);
323 EXPECT_EQ(contents->controller()->GetPendingEntryIndex(), -1); 349 EXPECT_EQ(contents->controller()->GetPendingEntryIndex(), -1);
324 EXPECT_FALSE(contents->controller()->GetLastCommittedEntry()); 350 EXPECT_FALSE(contents->controller()->GetLastCommittedEntry());
325 EXPECT_TRUE(contents->controller()->GetPendingEntry()); 351 EXPECT_TRUE(contents->controller()->GetPendingEntry());
326 EXPECT_FALSE(contents->controller()->CanGoBack()); 352 EXPECT_FALSE(contents->controller()->CanGoBack());
327 EXPECT_FALSE(contents->controller()->CanGoForward()); 353 EXPECT_FALSE(contents->controller()->CanGoForward());
328 EXPECT_EQ(contents->GetMaxPageID(), -1); 354 EXPECT_EQ(contents->GetMaxPageID(), -1);
329 355
330 // We should have gotten no notifications from the preceeding checks. 356 // We should have gotten no notifications from the preceeding checks.
331 EXPECT_EQ(0, notifications.size()); 357 EXPECT_EQ(0, notifications.size());
332 358
333 contents->CompleteNavigation(0); 359 contents->CompleteNavigationAsRenderer(0, url1);
334 EXPECT_TRUE(notifications.Check2AndReset(NOTIFY_NAV_ENTRY_COMMITTED, 360 EXPECT_TRUE(notifications.Check1AndReset(NOTIFY_NAV_ENTRY_COMMITTED));
335 NOTIFY_NAV_ENTRY_CHANGED));
336 361
337 // The load should now be committed. 362 // The load should now be committed.
338 EXPECT_EQ(contents->controller()->GetEntryCount(), 1); 363 EXPECT_EQ(contents->controller()->GetEntryCount(), 1);
339 EXPECT_EQ(contents->controller()->GetLastCommittedEntryIndex(), 0); 364 EXPECT_EQ(contents->controller()->GetLastCommittedEntryIndex(), 0);
340 EXPECT_EQ(contents->controller()->GetPendingEntryIndex(), -1); 365 EXPECT_EQ(contents->controller()->GetPendingEntryIndex(), -1);
341 EXPECT_TRUE(contents->controller()->GetLastCommittedEntry()); 366 EXPECT_TRUE(contents->controller()->GetLastCommittedEntry());
342 EXPECT_FALSE(contents->controller()->GetPendingEntry()); 367 EXPECT_FALSE(contents->controller()->GetPendingEntry());
343 EXPECT_FALSE(contents->controller()->CanGoBack()); 368 EXPECT_FALSE(contents->controller()->CanGoBack());
344 EXPECT_FALSE(contents->controller()->CanGoForward()); 369 EXPECT_FALSE(contents->controller()->CanGoForward());
345 EXPECT_EQ(contents->GetMaxPageID(), 0); 370 EXPECT_EQ(contents->GetMaxPageID(), 0);
346 371
347 // Load another... 372 // Load another...
348 contents->controller()->LoadURL(url2, PageTransition::TYPED); 373 contents->controller()->LoadURL(url2, PageTransition::TYPED);
349 374
350 // The load should now be pending. 375 // The load should now be pending.
351 EXPECT_TRUE(contents->pending_entry()); 376 EXPECT_TRUE(contents->pending_entry());
352 EXPECT_EQ(contents->controller()->GetEntryCount(), 1); 377 EXPECT_EQ(contents->controller()->GetEntryCount(), 1);
353 EXPECT_EQ(contents->controller()->GetLastCommittedEntryIndex(), 0); 378 EXPECT_EQ(contents->controller()->GetLastCommittedEntryIndex(), 0);
354 EXPECT_EQ(contents->controller()->GetPendingEntryIndex(), -1); 379 EXPECT_EQ(contents->controller()->GetPendingEntryIndex(), -1);
355 EXPECT_TRUE(contents->controller()->GetLastCommittedEntry()); 380 EXPECT_TRUE(contents->controller()->GetLastCommittedEntry());
356 EXPECT_TRUE(contents->controller()->GetPendingEntry()); 381 EXPECT_TRUE(contents->controller()->GetPendingEntry());
357 // TODO(darin): maybe this should really be true? 382 // TODO(darin): maybe this should really be true?
358 EXPECT_FALSE(contents->controller()->CanGoBack()); 383 EXPECT_FALSE(contents->controller()->CanGoBack());
359 EXPECT_FALSE(contents->controller()->CanGoForward()); 384 EXPECT_FALSE(contents->controller()->CanGoForward());
360 EXPECT_EQ(contents->GetMaxPageID(), 0); 385 EXPECT_EQ(contents->GetMaxPageID(), 0);
361 386
362 contents->CompleteNavigation(1); 387 contents->CompleteNavigationAsRenderer(1, url2);
363 EXPECT_TRUE(notifications.Check2AndReset(NOTIFY_NAV_ENTRY_COMMITTED, 388 EXPECT_TRUE(notifications.Check1AndReset(NOTIFY_NAV_ENTRY_COMMITTED));
364 NOTIFY_NAV_ENTRY_CHANGED));
365 389
366 // The load should now be committed. 390 // The load should now be committed.
367 EXPECT_EQ(contents->controller()->GetEntryCount(), 2); 391 EXPECT_EQ(contents->controller()->GetEntryCount(), 2);
368 EXPECT_EQ(contents->controller()->GetLastCommittedEntryIndex(), 1); 392 EXPECT_EQ(contents->controller()->GetLastCommittedEntryIndex(), 1);
369 EXPECT_EQ(contents->controller()->GetPendingEntryIndex(), -1); 393 EXPECT_EQ(contents->controller()->GetPendingEntryIndex(), -1);
370 EXPECT_TRUE(contents->controller()->GetLastCommittedEntry()); 394 EXPECT_TRUE(contents->controller()->GetLastCommittedEntry());
371 EXPECT_FALSE(contents->controller()->GetPendingEntry()); 395 EXPECT_FALSE(contents->controller()->GetPendingEntry());
372 EXPECT_TRUE(contents->controller()->CanGoBack()); 396 EXPECT_TRUE(contents->controller()->CanGoBack());
373 EXPECT_FALSE(contents->controller()->CanGoForward()); 397 EXPECT_FALSE(contents->controller()->CanGoForward());
374 EXPECT_EQ(contents->GetMaxPageID(), 1); 398 EXPECT_EQ(contents->GetMaxPageID(), 1);
375 } 399 }
376 400
377 // Tests what happens when the same page is loaded again. Should not create a 401 // Tests what happens when the same page is loaded again. Should not create a
378 // new session history entry. This is what happens when you press enter in the 402 // new session history entry. This is what happens when you press enter in the
379 // URL bar to reload: a pending entry is created and then it is discarded when 403 // URL bar to reload: a pending entry is created and then it is discarded when
380 // the load commits (because WebCore didn't actually make a new entry). 404 // the load commits (because WebCore didn't actually make a new entry).
381 TEST_F(NavigationControllerTest, LoadURL_SamePage) { 405 TEST_F(NavigationControllerTest, LoadURL_SamePage) {
382 TestNotificationTracker notifications; 406 TestNotificationTracker notifications;
383 RegisterForAllNavNotifications(&notifications, contents->controller()); 407 RegisterForAllNavNotifications(&notifications, contents->controller());
384 408
385 const GURL url1("test1:foo1"); 409 const GURL url1("test1:foo1");
386 410
387 contents->controller()->LoadURL(url1, PageTransition::TYPED); 411 contents->controller()->LoadURL(url1, PageTransition::TYPED);
388 EXPECT_EQ(0, notifications.size()); 412 EXPECT_EQ(0, notifications.size());
389 contents->CompleteNavigation(0); 413 contents->CompleteNavigationAsRenderer(0, url1);
390 EXPECT_TRUE(notifications.Check2AndReset(NOTIFY_NAV_ENTRY_COMMITTED, 414 EXPECT_TRUE(notifications.Check1AndReset(NOTIFY_NAV_ENTRY_COMMITTED));
391 NOTIFY_NAV_ENTRY_CHANGED));
392
393 415
394 contents->controller()->LoadURL(url1, PageTransition::TYPED); 416 contents->controller()->LoadURL(url1, PageTransition::TYPED);
395 EXPECT_EQ(0, notifications.size()); 417 EXPECT_EQ(0, notifications.size());
396 contents->CompleteNavigation(0); 418 contents->CompleteNavigationAsRenderer(0, url1);
397 EXPECT_TRUE(notifications.Check2AndReset(NOTIFY_NAV_ENTRY_COMMITTED, 419 EXPECT_TRUE(notifications.Check1AndReset(NOTIFY_NAV_ENTRY_COMMITTED));
398 NOTIFY_NAV_ENTRY_CHANGED));
399 420
400 // should not have produced a new session history entry 421 // We should not have produced a new session history entry.
401 EXPECT_EQ(contents->controller()->GetEntryCount(), 1); 422 EXPECT_EQ(contents->controller()->GetEntryCount(), 1);
402 EXPECT_EQ(contents->controller()->GetLastCommittedEntryIndex(), 0); 423 EXPECT_EQ(contents->controller()->GetLastCommittedEntryIndex(), 0);
403 EXPECT_EQ(contents->controller()->GetPendingEntryIndex(), -1); 424 EXPECT_EQ(contents->controller()->GetPendingEntryIndex(), -1);
404 EXPECT_TRUE(contents->controller()->GetLastCommittedEntry()); 425 EXPECT_TRUE(contents->controller()->GetLastCommittedEntry());
405 EXPECT_FALSE(contents->controller()->GetPendingEntry()); 426 EXPECT_FALSE(contents->controller()->GetPendingEntry());
406 EXPECT_FALSE(contents->controller()->CanGoBack()); 427 EXPECT_FALSE(contents->controller()->CanGoBack());
407 EXPECT_FALSE(contents->controller()->CanGoForward()); 428 EXPECT_FALSE(contents->controller()->CanGoForward());
408 } 429 }
409 430
410 // Tests loading a URL but discarding it before the load commits. 431 // Tests loading a URL but discarding it before the load commits.
411 TEST_F(NavigationControllerTest, LoadURL_Discarded) { 432 TEST_F(NavigationControllerTest, LoadURL_Discarded) {
412 TestNotificationTracker notifications; 433 TestNotificationTracker notifications;
413 RegisterForAllNavNotifications(&notifications, contents->controller()); 434 RegisterForAllNavNotifications(&notifications, contents->controller());
414 435
415 const GURL url1("test1:foo1"); 436 const GURL url1("test1:foo1");
416 const GURL url2("test1:foo2"); 437 const GURL url2("test1:foo2");
417 438
418 contents->controller()->LoadURL(url1, PageTransition::TYPED); 439 contents->controller()->LoadURL(url1, PageTransition::TYPED);
419 EXPECT_EQ(0, notifications.size()); 440 EXPECT_EQ(0, notifications.size());
420 contents->CompleteNavigation(0); 441 contents->CompleteNavigationAsRenderer(0, url1);
421 EXPECT_TRUE(notifications.Check2AndReset(NOTIFY_NAV_ENTRY_COMMITTED, 442 EXPECT_TRUE(notifications.Check1AndReset(NOTIFY_NAV_ENTRY_COMMITTED));
422 NOTIFY_NAV_ENTRY_CHANGED));
423 443
424 contents->controller()->LoadURL(url2, PageTransition::TYPED); 444 contents->controller()->LoadURL(url2, PageTransition::TYPED);
425 contents->controller()->DiscardPendingEntry(); 445 contents->controller()->DiscardPendingEntry();
426 EXPECT_EQ(0, notifications.size()); 446 EXPECT_EQ(0, notifications.size());
427 447
428 // Should not have produced a new session history entry. 448 // Should not have produced a new session history entry.
429 EXPECT_EQ(contents->controller()->GetEntryCount(), 1); 449 EXPECT_EQ(contents->controller()->GetEntryCount(), 1);
430 EXPECT_EQ(contents->controller()->GetLastCommittedEntryIndex(), 0); 450 EXPECT_EQ(contents->controller()->GetLastCommittedEntryIndex(), 0);
431 EXPECT_EQ(contents->controller()->GetPendingEntryIndex(), -1); 451 EXPECT_EQ(contents->controller()->GetPendingEntryIndex(), -1);
432 EXPECT_TRUE(contents->controller()->GetLastCommittedEntry()); 452 EXPECT_TRUE(contents->controller()->GetLastCommittedEntry());
433 EXPECT_FALSE(contents->controller()->GetPendingEntry()); 453 EXPECT_FALSE(contents->controller()->GetPendingEntry());
434 EXPECT_FALSE(contents->controller()->CanGoBack()); 454 EXPECT_FALSE(contents->controller()->CanGoBack());
435 EXPECT_FALSE(contents->controller()->CanGoForward()); 455 EXPECT_FALSE(contents->controller()->CanGoForward());
436 } 456 }
437 457
438 // Tests navigations that come in unrequested. This happens when the user 458 // Tests navigations that come in unrequested. This happens when the user»
jcampan 2008/09/10 22:38:12 Remove extra white spaces
439 // navigates from the web page, and here we test that there is no pending entry. 459 // navigates from the web page, and here we test that there is no pending entry. »
jcampan 2008/09/10 22:38:12 Same here
440 TEST_F(NavigationControllerTest, LoadURL_NoPending) { 460 TEST_F(NavigationControllerTest, LoadURL_NoPending) {
441 TestNotificationTracker notifications; 461 TestNotificationTracker notifications;
442 RegisterForAllNavNotifications(&notifications, contents->controller()); 462 RegisterForAllNavNotifications(&notifications, contents->controller());
443 463
444 // First make an existing committed entry. 464 // First make an existing committed entry.
445 const GURL kExistingURL1("test1:eh"); 465 const GURL kExistingURL1("test1:eh");
446 contents->controller()->LoadURL(kExistingURL1, PageTransition::TYPED); 466 contents->controller()->LoadURL(kExistingURL1, PageTransition::TYPED);
447 contents->CompleteNavigation(0); 467 contents->CompleteNavigationAsRenderer(0, kExistingURL1);
448 EXPECT_TRUE(notifications.Check2AndReset(NOTIFY_NAV_ENTRY_COMMITTED, 468 EXPECT_TRUE(notifications.Check1AndReset(NOTIFY_NAV_ENTRY_COMMITTED));
449 NOTIFY_NAV_ENTRY_CHANGED)); 469 »
450
451 // Do a new navigation without making a pending one. 470 // Do a new navigation without making a pending one.
452 const GURL kNewURL("test1:see"); 471 const GURL kNewURL("test1:see");
453 NavigationEntry* entry = new NavigationEntry(kTestContentsType1); 472 contents->CompleteNavigationAsRenderer(99, kNewURL);
454 entry->set_page_id(2);
455 entry->set_url(kNewURL);
456 entry->set_title(L"Hello, world");
457 NavigationController::LoadCommittedDetails details;
458 contents->controller()->DidNavigateToEntry(entry, &details);
459 473
460 // There should no longer be any pending entry, and the third navigation we 474 // There should no longer be any pending entry, and the third navigation we
461 // just made should be committed. 475 // just made should be committed.
462 EXPECT_TRUE(notifications.Check1AndReset(NOTIFY_NAV_ENTRY_COMMITTED)); 476 EXPECT_TRUE(notifications.Check1AndReset(NOTIFY_NAV_ENTRY_COMMITTED));
463 EXPECT_EQ(-1, contents->controller()->GetPendingEntryIndex()); 477 EXPECT_EQ(-1, contents->controller()->GetPendingEntryIndex());
464 EXPECT_EQ(1, contents->controller()->GetLastCommittedEntryIndex()); 478 EXPECT_EQ(1, contents->controller()->GetLastCommittedEntryIndex());
465 EXPECT_EQ(kNewURL, contents->controller()->GetActiveEntry()->url()); 479 EXPECT_EQ(kNewURL, contents->controller()->GetActiveEntry()->url());
466 } 480 }
467 481
jcampan 2008/09/10 22:38:12 Remove extra white spaces.
468 // Tests navigating to a new URL when there is a new pending navigation that is 482 // Tests navigating to a new URL when there is a new pending navigation that is
469 // not the one that just loaded. This will happen if the user types in a URL to 483 // not the one that just loaded. This will happen if the user types in a URL to
470 // somewhere slow, and then navigates the current page before the typed URL 484 // somewhere slow, and then navigates the current page before the typed URL
471 // commits. 485 // commits.
472 TEST_F(NavigationControllerTest, LoadURL_NewPending) { 486 TEST_F(NavigationControllerTest, LoadURL_NewPending) {
473 TestNotificationTracker notifications; 487 TestNotificationTracker notifications;
474 RegisterForAllNavNotifications(&notifications, contents->controller()); 488 RegisterForAllNavNotifications(&notifications, contents->controller());
475 489
476 // First make an existing committed entry. 490 // First make an existing committed entry.
477 const GURL kExistingURL1("test1:eh"); 491 const GURL kExistingURL1("test1:eh");
478 contents->controller()->LoadURL(kExistingURL1, PageTransition::TYPED); 492 contents->controller()->LoadURL(kExistingURL1, PageTransition::TYPED);
479 contents->CompleteNavigation(0); 493 contents->CompleteNavigationAsRenderer(0, kExistingURL1);
480 EXPECT_TRUE(notifications.Check2AndReset(NOTIFY_NAV_ENTRY_COMMITTED, 494 EXPECT_TRUE(notifications.Check1AndReset(NOTIFY_NAV_ENTRY_COMMITTED));
481 NOTIFY_NAV_ENTRY_CHANGED));
482 495
483 // Make a pending entry to somewhere new. 496 // Make a pending entry to somewhere new.
484 const GURL kExistingURL2("test1:bee"); 497 const GURL kExistingURL2("test1:bee");
485 contents->controller()->LoadURL(kExistingURL2, PageTransition::TYPED); 498 contents->controller()->LoadURL(kExistingURL2, PageTransition::TYPED);
486 EXPECT_EQ(0, notifications.size()); 499 EXPECT_EQ(0, notifications.size());
487 500
488 // Before that commits, do a new navigation. 501 // Before that commits, do a new navigation.
489 const GURL kNewURL("test1:see"); 502 const GURL kNewURL("test1:see");
490 NavigationEntry* entry = new NavigationEntry(kTestContentsType1); 503 contents->CompleteNavigationAsRenderer(3, kNewURL);
491 entry->set_page_id(3);
492 entry->set_url(kNewURL);
493 entry->set_title(L"Hello, world");
494 NavigationController::LoadCommittedDetails details;
495 contents->controller()->DidNavigateToEntry(entry, &details);
496 504
497 // There should no longer be any pending entry, and the third navigation we 505 // There should no longer be any pending entry, and the third navigation we
498 // just made should be committed. 506 // just made should be committed.
499 // Note that we don't expect a CHANGED notification. It turns out that this
500 // is sent by the TestContents and not any code we're interested in testing,
501 // and this function doesn't get called when we manually call the controller.
502 EXPECT_TRUE(notifications.Check1AndReset(NOTIFY_NAV_ENTRY_COMMITTED)); 507 EXPECT_TRUE(notifications.Check1AndReset(NOTIFY_NAV_ENTRY_COMMITTED));
503 EXPECT_EQ(-1, contents->controller()->GetPendingEntryIndex()); 508 EXPECT_EQ(-1, contents->controller()->GetPendingEntryIndex());
504 EXPECT_EQ(1, contents->controller()->GetLastCommittedEntryIndex()); 509 EXPECT_EQ(1, contents->controller()->GetLastCommittedEntryIndex());
505 EXPECT_EQ(kNewURL, contents->controller()->GetActiveEntry()->url()); 510 EXPECT_EQ(kNewURL, contents->controller()->GetActiveEntry()->url());
506 } 511 }
507 512
508 // Tests navigating to a new URL when there is a pending back/forward 513 // Tests navigating to a new URL when there is a pending back/forward
509 // navigation. This will happen if the user hits back, but before that commits, 514 // navigation. This will happen if the user hits back, but before that commits,
510 // they navigate somewhere new. 515 // they navigate somewhere new.
511 TEST_F(NavigationControllerTest, LoadURL_ExistingPending) { 516 TEST_F(NavigationControllerTest, LoadURL_ExistingPending) {
512 TestNotificationTracker notifications; 517 TestNotificationTracker notifications;
513 RegisterForAllNavNotifications(&notifications, contents->controller()); 518 RegisterForAllNavNotifications(&notifications, contents->controller());
514 519
515 // First make some history. 520 // First make some history.
516 const GURL kExistingURL1("test1:eh"); 521 const GURL kExistingURL1("test1:eh");
517 contents->controller()->LoadURL(kExistingURL1, PageTransition::TYPED); 522 contents->controller()->LoadURL(kExistingURL1, PageTransition::TYPED);
518 contents->CompleteNavigation(0); 523 contents->CompleteNavigationAsRenderer(0, kExistingURL1);
519 EXPECT_TRUE(notifications.Check2AndReset(NOTIFY_NAV_ENTRY_COMMITTED, 524 EXPECT_TRUE(notifications.Check1AndReset(NOTIFY_NAV_ENTRY_COMMITTED));
520 NOTIFY_NAV_ENTRY_CHANGED));
521 525
522 const GURL kExistingURL2("test1:bee"); 526 const GURL kExistingURL2("test1:bee");
523 contents->controller()->LoadURL(kExistingURL2, PageTransition::TYPED); 527 contents->controller()->LoadURL(kExistingURL2, PageTransition::TYPED);
524 contents->CompleteNavigation(1); 528 contents->CompleteNavigationAsRenderer(1, kExistingURL2);
525 EXPECT_TRUE(notifications.Check2AndReset(NOTIFY_NAV_ENTRY_COMMITTED, 529 EXPECT_TRUE(notifications.Check1AndReset(NOTIFY_NAV_ENTRY_COMMITTED));
526 NOTIFY_NAV_ENTRY_CHANGED));
527 530
528 // Now make a pending back/forward navigation. The zeroth entry should be 531 // Now make a pending back/forward navigation. The zeroth entry should be
529 // pending. 532 // pending.
530 contents->controller()->GoBack(); 533 contents->controller()->GoBack();
531 EXPECT_EQ(0, notifications.size()); 534 EXPECT_EQ(0, notifications.size());
532 EXPECT_EQ(0, contents->controller()->GetPendingEntryIndex()); 535 EXPECT_EQ(0, contents->controller()->GetPendingEntryIndex());
533 EXPECT_EQ(1, contents->controller()->GetLastCommittedEntryIndex()); 536 EXPECT_EQ(1, contents->controller()->GetLastCommittedEntryIndex());
534 537
535 // Before that commits, do a new navigation. 538 // Before that commits, do a new navigation.
536 const GURL kNewURL("test1:see"); 539 const GURL kNewURL("test1:see");
537 NavigationEntry* entry = new NavigationEntry(kTestContentsType1);
538 entry->set_page_id(3);
539 entry->set_url(kNewURL);
540 entry->set_title(L"Hello, world");
541 NavigationController::LoadCommittedDetails details; 540 NavigationController::LoadCommittedDetails details;
542 contents->controller()->DidNavigateToEntry(entry, &details); 541 contents->CompleteNavigationAsRenderer(3, kNewURL);
543 542
544 // There should no longer be any pending entry, and the third navigation we 543 // There should no longer be any pending entry, and the third navigation we
545 // just made should be committed. 544 // just made should be committed.
546 EXPECT_TRUE(notifications.Check1AndReset(NOTIFY_NAV_ENTRY_COMMITTED)); 545 EXPECT_TRUE(notifications.Check1AndReset(NOTIFY_NAV_ENTRY_COMMITTED));
547 EXPECT_EQ(-1, contents->controller()->GetPendingEntryIndex()); 546 EXPECT_EQ(-1, contents->controller()->GetPendingEntryIndex());
548 EXPECT_EQ(2, contents->controller()->GetLastCommittedEntryIndex()); 547 EXPECT_EQ(2, contents->controller()->GetLastCommittedEntryIndex());
549 EXPECT_EQ(kNewURL, contents->controller()->GetActiveEntry()->url()); 548 EXPECT_EQ(kNewURL, contents->controller()->GetActiveEntry()->url());
550 } 549 }
551 550
552 TEST_F(NavigationControllerTest, Reload) { 551 TEST_F(NavigationControllerTest, Reload) {
553 TestNotificationTracker notifications; 552 TestNotificationTracker notifications;
554 RegisterForAllNavNotifications(&notifications, contents->controller()); 553 RegisterForAllNavNotifications(&notifications, contents->controller());
555 554
556 const GURL url1("test1:foo1"); 555 const GURL url1("test1:foo1");
557 556
558 contents->controller()->LoadURL(url1, PageTransition::TYPED); 557 contents->controller()->LoadURL(url1, PageTransition::TYPED);
559 EXPECT_EQ(0, notifications.size()); 558 EXPECT_EQ(0, notifications.size());
560 contents->CompleteNavigation(0); 559 contents->CompleteNavigationAsRenderer(0, url1);
561 EXPECT_TRUE(notifications.Check2AndReset(NOTIFY_NAV_ENTRY_COMMITTED, 560 EXPECT_TRUE(notifications.Check1AndReset(NOTIFY_NAV_ENTRY_COMMITTED));
562 NOTIFY_NAV_ENTRY_CHANGED));
563 561
564 contents->controller()->Reload(); 562 contents->controller()->Reload();
565 EXPECT_EQ(0, notifications.size()); 563 EXPECT_EQ(0, notifications.size());
566 564
567 // The reload is pending. 565 // The reload is pending.
568 EXPECT_EQ(contents->controller()->GetEntryCount(), 1); 566 EXPECT_EQ(contents->controller()->GetEntryCount(), 1);
569 EXPECT_EQ(contents->controller()->GetLastCommittedEntryIndex(), 0); 567 EXPECT_EQ(contents->controller()->GetLastCommittedEntryIndex(), 0);
570 EXPECT_EQ(contents->controller()->GetPendingEntryIndex(), 0); 568 EXPECT_EQ(contents->controller()->GetPendingEntryIndex(), 0);
571 EXPECT_TRUE(contents->controller()->GetLastCommittedEntry()); 569 EXPECT_TRUE(contents->controller()->GetLastCommittedEntry());
572 EXPECT_TRUE(contents->controller()->GetPendingEntry()); 570 EXPECT_TRUE(contents->controller()->GetPendingEntry());
573 EXPECT_FALSE(contents->controller()->CanGoBack()); 571 EXPECT_FALSE(contents->controller()->CanGoBack());
574 EXPECT_FALSE(contents->controller()->CanGoForward()); 572 EXPECT_FALSE(contents->controller()->CanGoForward());
575 573
576 contents->CompleteNavigation(0); 574 contents->CompleteNavigationAsRenderer(0, url1);
577 EXPECT_TRUE(notifications.Check2AndReset(NOTIFY_NAV_ENTRY_COMMITTED, 575 EXPECT_TRUE(notifications.Check1AndReset(NOTIFY_NAV_ENTRY_COMMITTED));
578 NOTIFY_NAV_ENTRY_CHANGED));
579 576
580 // Now the reload is committed. 577 // Now the reload is committed.
581 EXPECT_EQ(contents->controller()->GetEntryCount(), 1); 578 EXPECT_EQ(contents->controller()->GetEntryCount(), 1);
582 EXPECT_EQ(contents->controller()->GetLastCommittedEntryIndex(), 0); 579 EXPECT_EQ(contents->controller()->GetLastCommittedEntryIndex(), 0);
583 EXPECT_EQ(contents->controller()->GetPendingEntryIndex(), -1); 580 EXPECT_EQ(contents->controller()->GetPendingEntryIndex(), -1);
584 EXPECT_TRUE(contents->controller()->GetLastCommittedEntry()); 581 EXPECT_TRUE(contents->controller()->GetLastCommittedEntry());
585 EXPECT_FALSE(contents->controller()->GetPendingEntry()); 582 EXPECT_FALSE(contents->controller()->GetPendingEntry());
586 EXPECT_FALSE(contents->controller()->CanGoBack()); 583 EXPECT_FALSE(contents->controller()->CanGoBack());
587 EXPECT_FALSE(contents->controller()->CanGoForward()); 584 EXPECT_FALSE(contents->controller()->CanGoForward());
588 } 585 }
589 586
590 // Tests what happens when a reload navigation produces a new page. 587 // Tests what happens when a reload navigation produces a new page.
591 TEST_F(NavigationControllerTest, Reload_GeneratesNewPage) { 588 TEST_F(NavigationControllerTest, Reload_GeneratesNewPage) {
592 TestNotificationTracker notifications; 589 TestNotificationTracker notifications;
593 RegisterForAllNavNotifications(&notifications, contents->controller()); 590 RegisterForAllNavNotifications(&notifications, contents->controller());
594 591
595 const GURL url1("test1:foo1"); 592 const GURL url1("test1:foo1");
596 const GURL url2("test1:foo2"); 593 const GURL url2("test1:foo2");
597 594
598 contents->controller()->LoadURL(url1, PageTransition::TYPED); 595 contents->controller()->LoadURL(url1, PageTransition::TYPED);
599 contents->CompleteNavigation(0); 596 contents->CompleteNavigationAsRenderer(0, url1);
600 EXPECT_TRUE(notifications.Check2AndReset(NOTIFY_NAV_ENTRY_COMMITTED, 597 EXPECT_TRUE(notifications.Check1AndReset(NOTIFY_NAV_ENTRY_COMMITTED));
601 NOTIFY_NAV_ENTRY_CHANGED));
602 598
603 contents->controller()->Reload(); 599 contents->controller()->Reload();
604 EXPECT_EQ(0, notifications.size()); 600 EXPECT_EQ(0, notifications.size());
605 601
606 contents->pending_entry()->set_url(url2); 602 contents->pending_entry()->set_url(url2);
607 contents->pending_entry()->set_transition_type(PageTransition::LINK); 603 contents->pending_entry()->set_transition_type(PageTransition::LINK);
608 contents->CompleteNavigation(1); 604 contents->CompleteNavigationAsRenderer(1, url2);
609 EXPECT_TRUE(notifications.Check2AndReset(NOTIFY_NAV_ENTRY_COMMITTED, 605 EXPECT_TRUE(notifications.Check1AndReset(NOTIFY_NAV_ENTRY_COMMITTED));
610 NOTIFY_NAV_ENTRY_CHANGED));
611 606
612 // Now the reload is committed. 607 // Now the reload is committed.
613 EXPECT_EQ(contents->controller()->GetEntryCount(), 2); 608 EXPECT_EQ(contents->controller()->GetEntryCount(), 2);
614 EXPECT_EQ(contents->controller()->GetLastCommittedEntryIndex(), 1); 609 EXPECT_EQ(contents->controller()->GetLastCommittedEntryIndex(), 1);
615 EXPECT_EQ(contents->controller()->GetPendingEntryIndex(), -1); 610 EXPECT_EQ(contents->controller()->GetPendingEntryIndex(), -1);
616 EXPECT_TRUE(contents->controller()->GetLastCommittedEntry()); 611 EXPECT_TRUE(contents->controller()->GetLastCommittedEntry());
617 EXPECT_FALSE(contents->controller()->GetPendingEntry()); 612 EXPECT_FALSE(contents->controller()->GetPendingEntry());
618 EXPECT_TRUE(contents->controller()->CanGoBack()); 613 EXPECT_TRUE(contents->controller()->CanGoBack());
619 EXPECT_FALSE(contents->controller()->CanGoForward()); 614 EXPECT_FALSE(contents->controller()->CanGoForward());
620 } 615 }
621 616
622 // Tests what happens when we navigate back successfully 617 // Tests what happens when we navigate back successfully
623 TEST_F(NavigationControllerTest, Back) { 618 TEST_F(NavigationControllerTest, Back) {
624 TestNotificationTracker notifications; 619 TestNotificationTracker notifications;
625 RegisterForAllNavNotifications(&notifications, contents->controller()); 620 RegisterForAllNavNotifications(&notifications, contents->controller());
626 621
627 const GURL url1("test1:foo1"); 622 const GURL url1("test1:foo1");
623 contents->CompleteNavigationAsRenderer(0, url1);
624 EXPECT_TRUE(notifications.Check1AndReset(NOTIFY_NAV_ENTRY_COMMITTED));
625
628 const GURL url2("test1:foo2"); 626 const GURL url2("test1:foo2");
629 627 contents->CompleteNavigationAsRenderer(1, url2);
630 contents->controller()->LoadURL(url1, PageTransition::TYPED); 628 EXPECT_TRUE(notifications.Check1AndReset(NOTIFY_NAV_ENTRY_COMMITTED));
631 contents->CompleteNavigation(0);
632 EXPECT_TRUE(notifications.Check2AndReset(NOTIFY_NAV_ENTRY_COMMITTED,
633 NOTIFY_NAV_ENTRY_CHANGED));
634
635 contents->controller()->LoadURL(url2, PageTransition::TYPED);
636 contents->CompleteNavigation(1);
637 EXPECT_TRUE(notifications.Check2AndReset(NOTIFY_NAV_ENTRY_COMMITTED,
638 NOTIFY_NAV_ENTRY_CHANGED));
639 629
640 contents->controller()->GoBack(); 630 contents->controller()->GoBack();
641 EXPECT_EQ(0, notifications.size()); 631 EXPECT_EQ(0, notifications.size());
642 632
643 // We should now have a pending navigation to go back. 633 // We should now have a pending navigation to go back.
644 EXPECT_EQ(contents->controller()->GetEntryCount(), 2); 634 EXPECT_EQ(contents->controller()->GetEntryCount(), 2);
645 EXPECT_EQ(contents->controller()->GetLastCommittedEntryIndex(), 1); 635 EXPECT_EQ(contents->controller()->GetLastCommittedEntryIndex(), 1);
646 EXPECT_EQ(contents->controller()->GetPendingEntryIndex(), 0); 636 EXPECT_EQ(contents->controller()->GetPendingEntryIndex(), 0);
647 EXPECT_TRUE(contents->controller()->GetLastCommittedEntry()); 637 EXPECT_TRUE(contents->controller()->GetLastCommittedEntry());
648 EXPECT_TRUE(contents->controller()->GetPendingEntry()); 638 EXPECT_TRUE(contents->controller()->GetPendingEntry());
649 EXPECT_FALSE(contents->controller()->CanGoBack()); 639 EXPECT_FALSE(contents->controller()->CanGoBack());
650 EXPECT_TRUE(contents->controller()->CanGoForward()); 640 EXPECT_TRUE(contents->controller()->CanGoForward());
651 641
652 contents->CompleteNavigation(0); 642 contents->CompleteNavigationAsRenderer(0, url2);
653 EXPECT_TRUE(notifications.Check2AndReset(NOTIFY_NAV_ENTRY_COMMITTED, 643 EXPECT_TRUE(notifications.Check1AndReset(NOTIFY_NAV_ENTRY_COMMITTED));
654 NOTIFY_NAV_ENTRY_CHANGED));
655 644
656 // The back navigation completed successfully. 645 // The back navigation completed successfully.
657 EXPECT_EQ(contents->controller()->GetEntryCount(), 2); 646 EXPECT_EQ(contents->controller()->GetEntryCount(), 2);
658 EXPECT_EQ(contents->controller()->GetLastCommittedEntryIndex(), 0); 647 EXPECT_EQ(contents->controller()->GetLastCommittedEntryIndex(), 0);
659 EXPECT_EQ(contents->controller()->GetPendingEntryIndex(), -1); 648 EXPECT_EQ(contents->controller()->GetPendingEntryIndex(), -1);
660 EXPECT_TRUE(contents->controller()->GetLastCommittedEntry()); 649 EXPECT_TRUE(contents->controller()->GetLastCommittedEntry());
661 EXPECT_FALSE(contents->controller()->GetPendingEntry()); 650 EXPECT_FALSE(contents->controller()->GetPendingEntry());
662 EXPECT_FALSE(contents->controller()->CanGoBack()); 651 EXPECT_FALSE(contents->controller()->CanGoBack());
663 EXPECT_TRUE(contents->controller()->CanGoForward()); 652 EXPECT_TRUE(contents->controller()->CanGoForward());
664 } 653 }
665 654
666 // Tests what happens when a back navigation produces a new page. 655 // Tests what happens when a back navigation produces a new page.
667 TEST_F(NavigationControllerTest, Back_GeneratesNewPage) { 656 TEST_F(NavigationControllerTest, Back_GeneratesNewPage) {
668 TestNotificationTracker notifications; 657 TestNotificationTracker notifications;
669 RegisterForAllNavNotifications(&notifications, contents->controller()); 658 RegisterForAllNavNotifications(&notifications, contents->controller());
670 659
671 const GURL url1("test1:foo1"); 660 const GURL url1("test1:foo1");
672 const GURL url2("test1:foo2"); 661 const GURL url2("test1:foo2");
673 const GURL url3("test1:foo3"); 662 const GURL url3("test1:foo3");
674 663
675 contents->controller()->LoadURL(url1, PageTransition::TYPED); 664 contents->controller()->LoadURL(url1, PageTransition::TYPED);
676 contents->CompleteNavigation(0); 665 contents->CompleteNavigationAsRenderer(0, url1);
677 EXPECT_TRUE(notifications.Check2AndReset(NOTIFY_NAV_ENTRY_COMMITTED, 666 EXPECT_TRUE(notifications.Check1AndReset(NOTIFY_NAV_ENTRY_COMMITTED));
678 NOTIFY_NAV_ENTRY_CHANGED));
679 667
680 contents->controller()->LoadURL(url2, PageTransition::TYPED); 668 contents->controller()->LoadURL(url2, PageTransition::TYPED);
681 contents->CompleteNavigation(1); 669 contents->CompleteNavigationAsRenderer(1, url2);
682 EXPECT_TRUE(notifications.Check2AndReset(NOTIFY_NAV_ENTRY_COMMITTED, 670 EXPECT_TRUE(notifications.Check1AndReset(NOTIFY_NAV_ENTRY_COMMITTED));
683 NOTIFY_NAV_ENTRY_CHANGED));
684 671
685 contents->controller()->GoBack(); 672 contents->controller()->GoBack();
686 EXPECT_EQ(0, notifications.size()); 673 EXPECT_EQ(0, notifications.size());
687 674
688 // We should now have a pending navigation to go back. 675 // We should now have a pending navigation to go back.
689 EXPECT_EQ(contents->controller()->GetEntryCount(), 2); 676 EXPECT_EQ(contents->controller()->GetEntryCount(), 2);
690 EXPECT_EQ(contents->controller()->GetLastCommittedEntryIndex(), 1); 677 EXPECT_EQ(contents->controller()->GetLastCommittedEntryIndex(), 1);
691 EXPECT_EQ(contents->controller()->GetPendingEntryIndex(), 0); 678 EXPECT_EQ(contents->controller()->GetPendingEntryIndex(), 0);
692 EXPECT_TRUE(contents->controller()->GetLastCommittedEntry()); 679 EXPECT_TRUE(contents->controller()->GetLastCommittedEntry());
693 EXPECT_TRUE(contents->controller()->GetPendingEntry()); 680 EXPECT_TRUE(contents->controller()->GetPendingEntry());
694 EXPECT_FALSE(contents->controller()->CanGoBack()); 681 EXPECT_FALSE(contents->controller()->CanGoBack());
695 EXPECT_TRUE(contents->controller()->CanGoForward()); 682 EXPECT_TRUE(contents->controller()->CanGoForward());
696 683
697 contents->pending_entry()->set_url(url3); 684 contents->CompleteNavigationAsRenderer(2, url3);
698 contents->pending_entry()->set_transition_type(PageTransition::LINK); 685 EXPECT_TRUE(notifications.Check1AndReset(NOTIFY_NAV_ENTRY_COMMITTED));
699 contents->CompleteNavigation(2);
700 EXPECT_TRUE(notifications.Check2AndReset(NOTIFY_NAV_ENTRY_COMMITTED,
701 NOTIFY_NAV_ENTRY_CHANGED));
702 686
703 // The back navigation resulted in a completely new navigation. 687 // The back navigation resulted in a completely new navigation.
704 // TODO(darin): perhaps this behavior will be confusing to users? 688 // TODO(darin): perhaps this behavior will be confusing to users?
705 EXPECT_EQ(contents->controller()->GetEntryCount(), 3); 689 EXPECT_EQ(contents->controller()->GetEntryCount(), 3);
706 EXPECT_EQ(contents->controller()->GetLastCommittedEntryIndex(), 2); 690 EXPECT_EQ(contents->controller()->GetLastCommittedEntryIndex(), 2);
707 EXPECT_EQ(contents->controller()->GetPendingEntryIndex(), -1); 691 EXPECT_EQ(contents->controller()->GetPendingEntryIndex(), -1);
708 EXPECT_TRUE(contents->controller()->GetLastCommittedEntry()); 692 EXPECT_TRUE(contents->controller()->GetLastCommittedEntry());
709 EXPECT_FALSE(contents->controller()->GetPendingEntry()); 693 EXPECT_FALSE(contents->controller()->GetPendingEntry());
710 EXPECT_TRUE(contents->controller()->CanGoBack()); 694 EXPECT_TRUE(contents->controller()->CanGoBack());
711 EXPECT_FALSE(contents->controller()->CanGoForward()); 695 EXPECT_FALSE(contents->controller()->CanGoForward());
712 } 696 }
713 697
714 // Receives a back message when there is a new pending navigation entry. 698 // Receives a back message when there is a new pending navigation entry.
715 TEST_F(NavigationControllerTest, Back_NewPending) { 699 TEST_F(NavigationControllerTest, Back_NewPending) {
716 TestNotificationTracker notifications; 700 TestNotificationTracker notifications;
717 RegisterForAllNavNotifications(&notifications, contents->controller()); 701 RegisterForAllNavNotifications(&notifications, contents->controller());
718 702
719 const GURL kUrl1("test1:foo1"); 703 const GURL kUrl1("test1:foo1");
720 const GURL kUrl2("test1:foo2"); 704 const GURL kUrl2("test1:foo2");
721 const GURL kUrl3("test1:foo3"); 705 const GURL kUrl3("test1:foo3");
722 706
723 // First navigate two places so we have some back history. 707 // First navigate two places so we have some back history.
724 contents->controller()->LoadURL(kUrl1, PageTransition::TYPED); 708 //contents->controller()->LoadURL(kUrl1, PageTransition::TYPED);
jcampan 2008/09/10 22:38:12 Why is this commented out?
725 contents->CompleteNavigation(0); 709 contents->CompleteNavigationAsRenderer(0, kUrl1);
726 EXPECT_TRUE(notifications.Check2AndReset(NOTIFY_NAV_ENTRY_COMMITTED, 710 EXPECT_TRUE(notifications.Check1AndReset(NOTIFY_NAV_ENTRY_COMMITTED));
727 NOTIFY_NAV_ENTRY_CHANGED));
728 711
729 contents->controller()->LoadURL(kUrl2, PageTransition::TYPED); 712 //contents->controller()->LoadURL(kUrl2, PageTransition::TYPED);
730 contents->CompleteNavigation(1); 713 contents->CompleteNavigationAsRenderer(1, kUrl2);
731 EXPECT_TRUE(notifications.Check2AndReset(NOTIFY_NAV_ENTRY_COMMITTED, 714 EXPECT_TRUE(notifications.Check1AndReset(NOTIFY_NAV_ENTRY_COMMITTED));
732 NOTIFY_NAV_ENTRY_CHANGED));
733 715
734 // Now start a new pending navigation and go back before it commits. 716 // Now start a new pending navigation and go back before it commits.
735 contents->controller()->LoadURL(kUrl3, PageTransition::TYPED); 717 contents->controller()->LoadURL(kUrl3, PageTransition::TYPED);
736 EXPECT_EQ(-1, contents->controller()->GetPendingEntryIndex()); 718 EXPECT_EQ(-1, contents->controller()->GetPendingEntryIndex());
737 EXPECT_EQ(kUrl3, contents->controller()->GetPendingEntry()->url()); 719 EXPECT_EQ(kUrl3, contents->controller()->GetPendingEntry()->url());
738 contents->controller()->GoBack(); 720 contents->controller()->GoBack();
739 721
740 // The pending navigation should now be the "back" item and the new one 722 // The pending navigation should now be the "back" item and the new one
741 // should be gone. 723 // should be gone.
742 EXPECT_EQ(0, contents->controller()->GetPendingEntryIndex()); 724 EXPECT_EQ(0, contents->controller()->GetPendingEntryIndex());
743 EXPECT_EQ(kUrl1, contents->controller()->GetPendingEntry()->url()); 725 EXPECT_EQ(kUrl1, contents->controller()->GetPendingEntry()->url());
744 } 726 }
745 727
746 // Receives a back message when there is a different renavigation already 728 // Receives a back message when there is a different renavigation already
747 // pending. 729 // pending.
748 TEST_F(NavigationControllerTest, Back_OtherBackPending) { 730 TEST_F(NavigationControllerTest, Back_OtherBackPending) {
749 const GURL kUrl1("test1:foo1"); 731 const GURL kUrl1("test1:foo1");
750 const GURL kUrl2("test1:foo2"); 732 const GURL kUrl2("test1:foo2");
751 const GURL kUrl3("test1:foo3"); 733 const GURL kUrl3("test1:foo3");
752 734
753 // First navigate three places so we have some back history. 735 // First navigate three places so we have some back history.
754 contents->controller()->LoadURL(kUrl1, PageTransition::TYPED); 736 contents->CompleteNavigationAsRenderer(0, kUrl1);
755 contents->CompleteNavigation(0); 737 contents->CompleteNavigationAsRenderer(1, kUrl2);
756 contents->controller()->LoadURL(kUrl2, PageTransition::TYPED); 738 contents->CompleteNavigationAsRenderer(2, kUrl3);
757 contents->CompleteNavigation(1);
758 contents->controller()->LoadURL(kUrl3, PageTransition::TYPED);
759 contents->CompleteNavigation(2);
760 739
761 // With nothing pending, say we get a navigation to the second entry. 740 // With nothing pending, say we get a navigation to the second entry.
762 const std::wstring kNewTitle1(L"Hello, world"); 741 contents->CompleteNavigationAsRenderer(1, kUrl2);
763 NavigationEntry* entry = new NavigationEntry(kTestContentsType1);
764 entry->set_page_id(1);
765 entry->set_url(kUrl2);
766 entry->set_title(kNewTitle1);
767 NavigationController::LoadCommittedDetails details;
768 contents->controller()->DidNavigateToEntry(entry, &details);
769 742
770 // That second URL should be the last committed and it should have gotten the 743 // That second URL should be the last committed and it should have gotten the
771 // new title. 744 // new title.
772 EXPECT_EQ(kNewTitle1, contents->controller()->GetEntryWithPageID( 745 EXPECT_EQ(kUrl2, contents->controller()->GetEntryWithPageID(
773 kTestContentsType1, NULL, 1)->title()); 746 kTestContentsType1, NULL, 1)->url());
774 EXPECT_EQ(1, contents->controller()->GetLastCommittedEntryIndex()); 747 EXPECT_EQ(1, contents->controller()->GetLastCommittedEntryIndex());
775 EXPECT_EQ(-1, contents->controller()->GetPendingEntryIndex()); 748 EXPECT_EQ(-1, contents->controller()->GetPendingEntryIndex());
776 749
777 // Now go forward to the last item again and say it was committed. 750 // Now go forward to the last item again and say it was committed.
778 contents->controller()->GoForward(); 751 contents->controller()->GoForward();
779 contents->CompleteNavigation(2); 752 contents->CompleteNavigationAsRenderer(2, kUrl3);
780 753
781 // Now start going back one to the second page. It will be pending. 754 // Now start going back one to the second page. It will be pending.
782 contents->controller()->GoBack(); 755 contents->controller()->GoBack();
783 EXPECT_EQ(1, contents->controller()->GetPendingEntryIndex()); 756 EXPECT_EQ(1, contents->controller()->GetPendingEntryIndex());
784 EXPECT_EQ(2, contents->controller()->GetLastCommittedEntryIndex()); 757 EXPECT_EQ(2, contents->controller()->GetLastCommittedEntryIndex());
785 758
786 // Not synthesize a totally new back event to the first page. This will not 759 // Not synthesize a totally new back event to the first page. This will not
787 // match the pending one. 760 // match the pending one.
788 const std::wstring kNewTitle2(L"Hello, world"); 761 contents->CompleteNavigationAsRenderer(0, kUrl1);
789 entry = new NavigationEntry(kTestContentsType1);
790 entry->set_page_id(0);
791 entry->set_url(kUrl1);
792 entry->set_title(kNewTitle2);
793 contents->controller()->DidNavigateToEntry(entry, &details);
794 762
795 // The navigation should not have affected the pending entry. 763 // The navigation should not have affected the pending entry.
796 EXPECT_EQ(1, contents->controller()->GetPendingEntryIndex()); 764 EXPECT_EQ(1, contents->controller()->GetPendingEntryIndex());
797 765
798 // But the navigated entry should be updated to the new title, and should be 766 // But the navigated entry should be the last committed.
799 // the last committed.
800 EXPECT_EQ(kNewTitle2, contents->controller()->GetEntryWithPageID(
801 kTestContentsType1, NULL, 0)->title());
802 EXPECT_EQ(0, contents->controller()->GetLastCommittedEntryIndex()); 767 EXPECT_EQ(0, contents->controller()->GetLastCommittedEntryIndex());
768 EXPECT_EQ(kUrl1, contents->controller()->GetLastCommittedEntry()->url());
803 } 769 }
804 770
805 // Tests what happens when we navigate forward successfully. 771 // Tests what happens when we navigate forward successfully.
806 TEST_F(NavigationControllerTest, Forward) { 772 TEST_F(NavigationControllerTest, Forward) {
807 TestNotificationTracker notifications; 773 TestNotificationTracker notifications;
808 RegisterForAllNavNotifications(&notifications, contents->controller()); 774 RegisterForAllNavNotifications(&notifications, contents->controller());
809 775
810 const GURL url1("test1:foo1"); 776 const GURL url1("test1:foo1");
811 const GURL url2("test1:foo2"); 777 const GURL url2("test1:foo2");
812 778
813 contents->controller()->LoadURL(url1, PageTransition::TYPED); 779 contents->CompleteNavigationAsRenderer(0, url1);
814 contents->CompleteNavigation(0); 780 EXPECT_TRUE(notifications.Check1AndReset(NOTIFY_NAV_ENTRY_COMMITTED));
815 EXPECT_TRUE(notifications.Check2AndReset(NOTIFY_NAV_ENTRY_COMMITTED,
816 NOTIFY_NAV_ENTRY_CHANGED));
817 781
818 contents->controller()->LoadURL(url2, PageTransition::TYPED); 782 contents->CompleteNavigationAsRenderer(1, url2);
819 contents->CompleteNavigation(1); 783 EXPECT_TRUE(notifications.Check1AndReset(NOTIFY_NAV_ENTRY_COMMITTED));
820 EXPECT_TRUE(notifications.Check2AndReset(NOTIFY_NAV_ENTRY_COMMITTED,
821 NOTIFY_NAV_ENTRY_CHANGED));
822 784
823 contents->controller()->GoBack(); 785 contents->controller()->GoBack();
824 contents->CompleteNavigation(0); 786 contents->CompleteNavigationAsRenderer(0, url1);
825 EXPECT_TRUE(notifications.Check2AndReset(NOTIFY_NAV_ENTRY_COMMITTED, 787 EXPECT_TRUE(notifications.Check1AndReset(NOTIFY_NAV_ENTRY_COMMITTED));
826 NOTIFY_NAV_ENTRY_CHANGED));
827 788
828 contents->controller()->GoForward(); 789 contents->controller()->GoForward();
829 790
830 // We should now have a pending navigation to go forward. 791 // We should now have a pending navigation to go forward.
831 EXPECT_EQ(contents->controller()->GetEntryCount(), 2); 792 EXPECT_EQ(contents->controller()->GetEntryCount(), 2);
832 EXPECT_EQ(contents->controller()->GetLastCommittedEntryIndex(), 0); 793 EXPECT_EQ(contents->controller()->GetLastCommittedEntryIndex(), 0);
833 EXPECT_EQ(contents->controller()->GetPendingEntryIndex(), 1); 794 EXPECT_EQ(contents->controller()->GetPendingEntryIndex(), 1);
834 EXPECT_TRUE(contents->controller()->GetLastCommittedEntry()); 795 EXPECT_TRUE(contents->controller()->GetLastCommittedEntry());
835 EXPECT_TRUE(contents->controller()->GetPendingEntry()); 796 EXPECT_TRUE(contents->controller()->GetPendingEntry());
836 EXPECT_TRUE(contents->controller()->CanGoBack()); 797 EXPECT_TRUE(contents->controller()->CanGoBack());
837 EXPECT_FALSE(contents->controller()->CanGoForward()); 798 EXPECT_FALSE(contents->controller()->CanGoForward());
838 799
839 contents->CompleteNavigation(1); 800 contents->CompleteNavigationAsRenderer(1, url2);
840 EXPECT_TRUE(notifications.Check2AndReset(NOTIFY_NAV_ENTRY_COMMITTED, 801 EXPECT_TRUE(notifications.Check1AndReset(NOTIFY_NAV_ENTRY_COMMITTED));
841 NOTIFY_NAV_ENTRY_CHANGED));
842 802
843 // The forward navigation completed successfully. 803 // The forward navigation completed successfully.
844 EXPECT_EQ(contents->controller()->GetEntryCount(), 2); 804 EXPECT_EQ(contents->controller()->GetEntryCount(), 2);
845 EXPECT_EQ(contents->controller()->GetLastCommittedEntryIndex(), 1); 805 EXPECT_EQ(contents->controller()->GetLastCommittedEntryIndex(), 1);
846 EXPECT_EQ(contents->controller()->GetPendingEntryIndex(), -1); 806 EXPECT_EQ(contents->controller()->GetPendingEntryIndex(), -1);
847 EXPECT_TRUE(contents->controller()->GetLastCommittedEntry()); 807 EXPECT_TRUE(contents->controller()->GetLastCommittedEntry());
848 EXPECT_FALSE(contents->controller()->GetPendingEntry()); 808 EXPECT_FALSE(contents->controller()->GetPendingEntry());
849 EXPECT_TRUE(contents->controller()->CanGoBack()); 809 EXPECT_TRUE(contents->controller()->CanGoBack());
850 EXPECT_FALSE(contents->controller()->CanGoForward()); 810 EXPECT_FALSE(contents->controller()->CanGoForward());
851 } 811 }
852 812
853 // Tests what happens when a forward navigation produces a new page. 813 // Tests what happens when a forward navigation produces a new page.
854 TEST_F(NavigationControllerTest, Forward_GeneratesNewPage) { 814 TEST_F(NavigationControllerTest, Forward_GeneratesNewPage) {
855 TestNotificationTracker notifications; 815 TestNotificationTracker notifications;
856 RegisterForAllNavNotifications(&notifications, contents->controller()); 816 RegisterForAllNavNotifications(&notifications, contents->controller());
857 817
858 const GURL url1("test1:foo1"); 818 const GURL url1("test1:foo1");
859 const GURL url2("test1:foo2"); 819 const GURL url2("test1:foo2");
860 const GURL url3("test1:foo3"); 820 const GURL url3("test1:foo3");
861 821
862 contents->controller()->LoadURL(url1, PageTransition::TYPED); 822 contents->CompleteNavigationAsRenderer(0, url1);
863 contents->CompleteNavigation(0); 823 EXPECT_TRUE(notifications.Check1AndReset(NOTIFY_NAV_ENTRY_COMMITTED));
864 EXPECT_TRUE(notifications.Check2AndReset(NOTIFY_NAV_ENTRY_COMMITTED, 824 contents->CompleteNavigationAsRenderer(1, url2);
865 NOTIFY_NAV_ENTRY_CHANGED)); 825 EXPECT_TRUE(notifications.Check1AndReset(NOTIFY_NAV_ENTRY_COMMITTED));
866
867 contents->controller()->LoadURL(url2, PageTransition::TYPED);
868 contents->CompleteNavigation(1);
869 EXPECT_TRUE(notifications.Check2AndReset(NOTIFY_NAV_ENTRY_COMMITTED,
870 NOTIFY_NAV_ENTRY_CHANGED));
871 826
872 contents->controller()->GoBack(); 827 contents->controller()->GoBack();
873 contents->CompleteNavigation(0); 828 contents->CompleteNavigationAsRenderer(0, url1);
874 EXPECT_TRUE(notifications.Check2AndReset(NOTIFY_NAV_ENTRY_COMMITTED, 829 EXPECT_TRUE(notifications.Check1AndReset(NOTIFY_NAV_ENTRY_COMMITTED));
875 NOTIFY_NAV_ENTRY_CHANGED));
876 830
877 contents->controller()->GoForward(); 831 contents->controller()->GoForward();
878 EXPECT_EQ(0, notifications.size()); 832 EXPECT_EQ(0, notifications.size());
879 833
880 // Should now have a pending navigation to go forward. 834 // Should now have a pending navigation to go forward.
881 EXPECT_EQ(contents->controller()->GetEntryCount(), 2); 835 EXPECT_EQ(contents->controller()->GetEntryCount(), 2);
882 EXPECT_EQ(contents->controller()->GetLastCommittedEntryIndex(), 0); 836 EXPECT_EQ(contents->controller()->GetLastCommittedEntryIndex(), 0);
883 EXPECT_EQ(contents->controller()->GetPendingEntryIndex(), 1); 837 EXPECT_EQ(contents->controller()->GetPendingEntryIndex(), 1);
884 EXPECT_TRUE(contents->controller()->GetLastCommittedEntry()); 838 EXPECT_TRUE(contents->controller()->GetLastCommittedEntry());
885 EXPECT_TRUE(contents->controller()->GetPendingEntry()); 839 EXPECT_TRUE(contents->controller()->GetPendingEntry());
886 EXPECT_TRUE(contents->controller()->CanGoBack()); 840 EXPECT_TRUE(contents->controller()->CanGoBack());
887 EXPECT_FALSE(contents->controller()->CanGoForward()); 841 EXPECT_FALSE(contents->controller()->CanGoForward());
888 842
889 contents->pending_entry()->set_url(url3); 843 contents->CompleteNavigationAsRenderer(2, url3);
890 contents->pending_entry()->set_transition_type(PageTransition::LINK); 844 EXPECT_TRUE(notifications.Check2AndReset(NOTIFY_NAV_LIST_PRUNED,
891 contents->CompleteNavigation(2); 845 NOTIFY_NAV_ENTRY_COMMITTED));
892 EXPECT_TRUE(notifications.Check3AndReset(NOTIFY_NAV_LIST_PRUNED,
893 NOTIFY_NAV_ENTRY_COMMITTED,
894 NOTIFY_NAV_ENTRY_CHANGED));
895 846
896 EXPECT_EQ(contents->controller()->GetEntryCount(), 2); 847 EXPECT_EQ(contents->controller()->GetEntryCount(), 2);
897 EXPECT_EQ(contents->controller()->GetLastCommittedEntryIndex(), 1); 848 EXPECT_EQ(contents->controller()->GetLastCommittedEntryIndex(), 1);
898 EXPECT_EQ(contents->controller()->GetPendingEntryIndex(), -1); 849 EXPECT_EQ(contents->controller()->GetPendingEntryIndex(), -1);
899 EXPECT_TRUE(contents->controller()->GetLastCommittedEntry()); 850 EXPECT_TRUE(contents->controller()->GetLastCommittedEntry());
900 EXPECT_FALSE(contents->controller()->GetPendingEntry()); 851 EXPECT_FALSE(contents->controller()->GetPendingEntry());
901 EXPECT_TRUE(contents->controller()->CanGoBack()); 852 EXPECT_TRUE(contents->controller()->CanGoBack());
902 EXPECT_FALSE(contents->controller()->CanGoForward()); 853 EXPECT_FALSE(contents->controller()->CanGoForward());
903 } 854 }
904 855
856 // Tests navigation via link click within a subframe. A new navigation entry
857 // should be created.
858 TEST_F(NavigationControllerTest, NewSubframe) {
859 TestNotificationTracker notifications;
860 RegisterForAllNavNotifications(&notifications, contents->controller());
861
862 const GURL url1("test1:foo1");
863 contents->CompleteNavigationAsRenderer(0, url1);
864 EXPECT_TRUE(notifications.Check1AndReset(NOTIFY_NAV_ENTRY_COMMITTED));
865
866 const GURL url2("test1:foo2");
867 ViewHostMsg_FrameNavigate_Params params;
868 params.page_id = 1;
869 params.url = url2;
870 params.transition = PageTransition::MANUAL_SUBFRAME;
871 params.should_update_history = false;
872 params.gesture = NavigationGestureUser;
873 params.is_post = false;
874
875 NavigationController::LoadCommittedDetails details;
876 EXPECT_TRUE(contents->controller()->RendererDidNavigate(params, false,
877 &details));
878 EXPECT_TRUE(notifications.Check1AndReset(NOTIFY_NAV_ENTRY_COMMITTED));
879 EXPECT_EQ(url1, details.previous_url);
880 EXPECT_FALSE(details.is_auto);
881 EXPECT_FALSE(details.is_in_page);
882 EXPECT_FALSE(details.is_main_frame);
883
884 // The new entry should be appended.
885 EXPECT_EQ(2, contents->controller()->GetEntryCount());
886
887 // New entry should refer to the new page, but the old URL (entries only
888 // reflect the toplevel URL).
889 EXPECT_EQ(url1, details.entry->url());
890 EXPECT_EQ(params.page_id, details.entry->page_id());
891 }
892
893 // Auto subframes are ones the page loads automatically like ads. They should
894 // not create new navigation entries.
895 TEST_F(NavigationControllerTest, AutoSubframe) {
896 TestNotificationTracker notifications;
897 RegisterForAllNavNotifications(&notifications, contents->controller());
898
899 const GURL url1("test1:foo1");
900 contents->CompleteNavigationAsRenderer(0, url1);
901 EXPECT_TRUE(notifications.Check1AndReset(NOTIFY_NAV_ENTRY_COMMITTED));
902
903 const GURL url2("test1:foo2");
904 ViewHostMsg_FrameNavigate_Params params;
905 params.page_id = 0;
906 params.url = url2;
907 params.transition = PageTransition::AUTO_SUBFRAME;
908 params.should_update_history = false;
909 params.gesture = NavigationGestureUser;
910 params.is_post = false;
911
912 // Navigating should do nothing.
913 NavigationController::LoadCommittedDetails details;
914 EXPECT_FALSE(contents->controller()->RendererDidNavigate(params, false,
915 &details));
916 EXPECT_EQ(0, notifications.size());
917
918 // There should still be only one entry.
919 EXPECT_EQ(1, contents->controller()->GetEntryCount());
920 }
921
922 // Tests navigation and then going back to a subframe navigation.
923 TEST_F(NavigationControllerTest, BackSubframe) {
924 TestNotificationTracker notifications;
925 RegisterForAllNavNotifications(&notifications, contents->controller());
926
927 // Main page.
928 const GURL url1("test1:foo1");
929 contents->CompleteNavigationAsRenderer(0, url1);
930 EXPECT_TRUE(notifications.Check1AndReset(NOTIFY_NAV_ENTRY_COMMITTED));
931
932 // First manual subframe navigation.
933 const GURL url2("test1:foo2");
934 ViewHostMsg_FrameNavigate_Params params;
935 params.page_id = 1;
936 params.url = url2;
937 params.transition = PageTransition::MANUAL_SUBFRAME;
938 params.should_update_history = false;
939 params.gesture = NavigationGestureUser;
940 params.is_post = false;
941
942 // This should generate a new entry.
943 NavigationController::LoadCommittedDetails details;
944 EXPECT_TRUE(contents->controller()->RendererDidNavigate(params, false,
945 &details));
946 EXPECT_TRUE(notifications.Check1AndReset(NOTIFY_NAV_ENTRY_COMMITTED));
947 EXPECT_EQ(2, contents->controller()->GetEntryCount());
948
949 // Second manual subframe navigation should also make a new entry.
950 const GURL url3("test1:foo3");
951 params.page_id = 2;
952 params.url = url3;
953 EXPECT_TRUE(contents->controller()->RendererDidNavigate(params, false,
954 &details));
955 EXPECT_TRUE(notifications.Check1AndReset(NOTIFY_NAV_ENTRY_COMMITTED));
956 EXPECT_EQ(3, contents->controller()->GetEntryCount());
957 EXPECT_EQ(2, contents->controller()->GetCurrentEntryIndex());
958
959 // Go back one.
960 contents->controller()->GoBack();
961 params.url = url2;
962 params.page_id = 1;
963 EXPECT_TRUE(contents->controller()->RendererDidNavigate(params, false,
964 &details));
965 EXPECT_TRUE(notifications.Check1AndReset(NOTIFY_NAV_ENTRY_COMMITTED));
966 EXPECT_EQ(3, contents->controller()->GetEntryCount());
967 EXPECT_EQ(1, contents->controller()->GetCurrentEntryIndex());
968
969 // Go back one more.
970 contents->controller()->GoBack();
971 params.url = url1;
972 params.page_id = 0;
973 EXPECT_TRUE(contents->controller()->RendererDidNavigate(params, false,
974 &details));
975 EXPECT_TRUE(notifications.Check1AndReset(NOTIFY_NAV_ENTRY_COMMITTED));
976 EXPECT_EQ(3, contents->controller()->GetEntryCount());
977 EXPECT_EQ(0, contents->controller()->GetCurrentEntryIndex());
978 }
979
905 TEST_F(NavigationControllerTest, LinkClick) { 980 TEST_F(NavigationControllerTest, LinkClick) {
906 TestNotificationTracker notifications; 981 TestNotificationTracker notifications;
907 RegisterForAllNavNotifications(&notifications, contents->controller()); 982 RegisterForAllNavNotifications(&notifications, contents->controller());
908 983
909 const GURL url1("test1:foo1"); 984 const GURL url1("test1:foo1");
910 const GURL url2("test1:foo2"); 985 const GURL url2("test1:foo2");
911 986
912 contents->controller()->LoadURL(url1, PageTransition::TYPED); 987 contents->CompleteNavigationAsRenderer(0, url1);
913 contents->CompleteNavigation(0); 988 EXPECT_TRUE(notifications.Check1AndReset(NOTIFY_NAV_ENTRY_COMMITTED));
914 EXPECT_TRUE(notifications.Check2AndReset(NOTIFY_NAV_ENTRY_COMMITTED,
915 NOTIFY_NAV_ENTRY_CHANGED));
916 989
917 contents->set_pending_entry(new NavigationEntry(kTestContentsType1, NULL, 0, 990 contents->set_pending_entry(new NavigationEntry(kTestContentsType1, NULL, 0,
918 url2, 991 url2,
919 std::wstring(), 992 std::wstring(),
920 PageTransition::LINK)); 993 PageTransition::LINK));
921 contents->CompleteNavigation(1); 994 contents->CompleteNavigationAsRenderer(1, url2);
922 EXPECT_TRUE(notifications.Check2AndReset(NOTIFY_NAV_ENTRY_COMMITTED, 995 EXPECT_TRUE(notifications.Check1AndReset(NOTIFY_NAV_ENTRY_COMMITTED));
923 NOTIFY_NAV_ENTRY_CHANGED));
924 996
925 // Should not have produced a new session history entry. 997 // Should not have produced a new session history entry.
926 EXPECT_EQ(contents->controller()->GetEntryCount(), 2); 998 EXPECT_EQ(contents->controller()->GetEntryCount(), 2);
927 EXPECT_EQ(contents->controller()->GetLastCommittedEntryIndex(), 1); 999 EXPECT_EQ(contents->controller()->GetLastCommittedEntryIndex(), 1);
928 EXPECT_EQ(contents->controller()->GetPendingEntryIndex(), -1); 1000 EXPECT_EQ(contents->controller()->GetPendingEntryIndex(), -1);
929 EXPECT_TRUE(contents->controller()->GetLastCommittedEntry()); 1001 EXPECT_TRUE(contents->controller()->GetLastCommittedEntry());
930 EXPECT_FALSE(contents->controller()->GetPendingEntry()); 1002 EXPECT_FALSE(contents->controller()->GetPendingEntry());
931 EXPECT_TRUE(contents->controller()->CanGoBack()); 1003 EXPECT_TRUE(contents->controller()->CanGoBack());
932 EXPECT_FALSE(contents->controller()->CanGoForward()); 1004 EXPECT_FALSE(contents->controller()->CanGoForward());
933 } 1005 }
934 1006
1007 TEST_F(NavigationControllerTest, InPage) {
1008 TestNotificationTracker notifications;
1009 RegisterForAllNavNotifications(&notifications, contents->controller());
1010
1011 // Main page. Note that we need "://" so this URL is treated as "standard"
1012 // which are the only ones that can have a ref.
1013 const GURL url1("test1://foo");
1014 contents->CompleteNavigationAsRenderer(0, url1);
1015 EXPECT_TRUE(notifications.Check1AndReset(NOTIFY_NAV_ENTRY_COMMITTED));
1016
1017 // First navigation.
1018 const GURL url2("test1://foo#a");
1019 ViewHostMsg_FrameNavigate_Params params;
1020 params.page_id = 1;
1021 params.url = url2;
1022 params.transition = PageTransition::LINK;
1023 params.should_update_history = false;
1024 params.gesture = NavigationGestureUser;
1025 params.is_post = false;
1026
1027 // This should generate a new entry.
1028 NavigationController::LoadCommittedDetails details;
1029 EXPECT_TRUE(contents->controller()->RendererDidNavigate(params, false,
1030 &details));
1031 EXPECT_TRUE(notifications.Check1AndReset(NOTIFY_NAV_ENTRY_COMMITTED));
1032 EXPECT_EQ(2, contents->controller()->GetEntryCount());
1033
1034 // Go back one.
1035 ViewHostMsg_FrameNavigate_Params back_params(params);
1036 contents->controller()->GoBack();
1037 back_params.url = url1;
1038 back_params.page_id = 0;
1039 EXPECT_TRUE(contents->controller()->RendererDidNavigate(back_params, false,
1040 &details));
1041 EXPECT_TRUE(notifications.Check1AndReset(NOTIFY_NAV_ENTRY_COMMITTED));
1042 EXPECT_EQ(2, contents->controller()->GetEntryCount());
1043 EXPECT_EQ(0, contents->controller()->GetCurrentEntryIndex());
1044 EXPECT_EQ(back_params.url, contents->controller()->GetActiveEntry()->url());
1045
1046 // Go forward
1047 ViewHostMsg_FrameNavigate_Params forward_params(params);
1048 contents->controller()->GoForward();
1049 forward_params.url = url2;
1050 forward_params.page_id = 1;
1051 EXPECT_TRUE(contents->controller()->RendererDidNavigate(forward_params, false,
1052 &details));
1053 EXPECT_TRUE(notifications.Check1AndReset(NOTIFY_NAV_ENTRY_COMMITTED));
1054 EXPECT_EQ(2, contents->controller()->GetEntryCount());
1055 EXPECT_EQ(1, contents->controller()->GetCurrentEntryIndex());
1056 EXPECT_EQ(forward_params.url,
1057 contents->controller()->GetActiveEntry()->url());
1058
1059 // Now go back and forward again. This is to work around a bug where we would
1060 // compare the incoming URL with the last committed entry rather than the
1061 // one identified by an existing page ID. This would result in the second URL
1062 // losing the reference fragment when you navigate away from it and then back.
1063 contents->controller()->GoBack();
1064 EXPECT_TRUE(contents->controller()->RendererDidNavigate(back_params, false,
1065 &details));
1066 contents->controller()->GoForward();
1067 EXPECT_TRUE(contents->controller()->RendererDidNavigate(forward_params, false,
1068 &details));
1069 EXPECT_EQ(forward_params.url,
1070 contents->controller()->GetActiveEntry()->url());
1071 }
1072
935 TEST_F(NavigationControllerTest, SwitchTypes) { 1073 TEST_F(NavigationControllerTest, SwitchTypes) {
936 TestNotificationTracker notifications; 1074 TestNotificationTracker notifications;
937 RegisterForAllNavNotifications(&notifications, contents->controller()); 1075 RegisterForAllNavNotifications(&notifications, contents->controller());
938 1076
939 const GURL url1("test1:foo"); 1077 const GURL url1("test1:foo");
940 const GURL url2("test2:foo"); 1078 const GURL url2("test2:foo");
941 1079
942 contents->controller()->LoadURL(url1, PageTransition::TYPED); 1080 contents->CompleteNavigationAsRenderer(0, url1);
943 contents->CompleteNavigation(0); 1081 EXPECT_TRUE(notifications.Check1AndReset(NOTIFY_NAV_ENTRY_COMMITTED));
944 EXPECT_TRUE(notifications.Check2AndReset(NOTIFY_NAV_ENTRY_COMMITTED,
945 NOTIFY_NAV_ENTRY_CHANGED));
946 1082
947 TestContents* initial_contents = contents; 1083 TestContents* initial_contents = contents;
948
949 contents->controller()->LoadURL(url2, PageTransition::TYPED); 1084 contents->controller()->LoadURL(url2, PageTransition::TYPED);
950 1085
951 // The tab contents should have been replaced 1086 // The tab contents should have been replaced
952 ASSERT_TRUE(initial_contents != contents); 1087 ASSERT_TRUE(initial_contents != contents);
953 1088
954 contents->CompleteNavigation(0); 1089 contents->CompleteNavigationAsRenderer(1, url2);
955 EXPECT_TRUE(notifications.Check2AndReset(NOTIFY_NAV_ENTRY_COMMITTED, 1090 EXPECT_TRUE(notifications.Check1AndReset(NOTIFY_NAV_ENTRY_COMMITTED));
956 NOTIFY_NAV_ENTRY_CHANGED));
957 1091
958 // A second navigation entry should have been committed even though the 1092 // A second navigation entry should have been committed even though the
959 // PageIDs are the same. PageIDs are scoped to the tab contents type. 1093 // PageIDs are the same. PageIDs are scoped to the tab contents type.
960 EXPECT_EQ(contents->controller()->GetEntryCount(), 2); 1094 EXPECT_EQ(contents->controller()->GetEntryCount(), 2);
961 EXPECT_EQ(contents->controller()->GetLastCommittedEntryIndex(), 1); 1095 EXPECT_EQ(contents->controller()->GetLastCommittedEntryIndex(), 1);
962 EXPECT_EQ(contents->controller()->GetPendingEntryIndex(), -1); 1096 EXPECT_EQ(contents->controller()->GetPendingEntryIndex(), -1);
963 EXPECT_TRUE(contents->controller()->GetLastCommittedEntry()); 1097 EXPECT_TRUE(contents->controller()->GetLastCommittedEntry());
964 EXPECT_FALSE(contents->controller()->GetPendingEntry()); 1098 EXPECT_FALSE(contents->controller()->GetPendingEntry());
965 EXPECT_TRUE(contents->controller()->CanGoBack()); 1099 EXPECT_TRUE(contents->controller()->CanGoBack());
966 EXPECT_FALSE(contents->controller()->CanGoForward()); 1100 EXPECT_FALSE(contents->controller()->CanGoForward());
967 1101
968 // Navigate back... 1102 // Navigate back...
969 contents->controller()->GoBack(); 1103 contents->controller()->GoBack();
970 ASSERT_TRUE(initial_contents == contents); // switched again! 1104 ASSERT_TRUE(initial_contents == contents); // switched again!
971 contents->CompleteNavigation(0); 1105 contents->CompleteNavigationAsRenderer(0, url1);
972 EXPECT_TRUE(notifications.Check2AndReset(NOTIFY_NAV_ENTRY_COMMITTED, 1106 EXPECT_TRUE(notifications.Check1AndReset(NOTIFY_NAV_ENTRY_COMMITTED));
973 NOTIFY_NAV_ENTRY_CHANGED));
974 1107
975 EXPECT_EQ(contents->controller()->GetEntryCount(), 2); 1108 EXPECT_EQ(contents->controller()->GetEntryCount(), 2);
976 EXPECT_EQ(contents->controller()->GetLastCommittedEntryIndex(), 0); 1109 EXPECT_EQ(contents->controller()->GetLastCommittedEntryIndex(), 0);
977 EXPECT_EQ(contents->controller()->GetPendingEntryIndex(), -1); 1110 EXPECT_EQ(contents->controller()->GetPendingEntryIndex(), -1);
978 EXPECT_TRUE(contents->controller()->GetLastCommittedEntry()); 1111 EXPECT_TRUE(contents->controller()->GetLastCommittedEntry());
979 EXPECT_FALSE(contents->controller()->GetPendingEntry()); 1112 EXPECT_FALSE(contents->controller()->GetPendingEntry());
980 EXPECT_FALSE(contents->controller()->CanGoBack()); 1113 EXPECT_FALSE(contents->controller()->CanGoBack());
981 EXPECT_TRUE(contents->controller()->CanGoForward()); 1114 EXPECT_TRUE(contents->controller()->CanGoForward());
982 1115
983 // There may be TabContentsCollector tasks pending, so flush them from queue. 1116 // There may be TabContentsCollector tasks pending, so flush them from queue.
984 MessageLoop::current()->RunAllPending(); 1117 MessageLoop::current()->RunAllPending();
985 } 1118 }
986 1119
987 // Tests what happens when we begin to navigate to a new contents type, but 1120 // Tests what happens when we begin to navigate to a new contents type, but
988 // then that navigation gets discarded instead. 1121 // then that navigation gets discarded instead.
989 TEST_F(NavigationControllerTest, SwitchTypes_Discard) { 1122 TEST_F(NavigationControllerTest, SwitchTypes_Discard) {
990 TestNotificationTracker notifications; 1123 TestNotificationTracker notifications;
991 RegisterForAllNavNotifications(&notifications, contents->controller()); 1124 RegisterForAllNavNotifications(&notifications, contents->controller());
992 1125
993 const GURL url1("test1:foo"); 1126 const GURL url1("test1:foo");
994 const GURL url2("test2:foo"); 1127 const GURL url2("test2:foo");
995 1128
996 contents->controller()->LoadURL(url1, PageTransition::TYPED); 1129 contents->CompleteNavigationAsRenderer(0, url1);
997 contents->CompleteNavigation(0); 1130 EXPECT_TRUE(notifications.Check1AndReset(NOTIFY_NAV_ENTRY_COMMITTED));
998 EXPECT_TRUE(notifications.Check2AndReset(NOTIFY_NAV_ENTRY_COMMITTED,
999 NOTIFY_NAV_ENTRY_CHANGED));
1000 1131
1001 TestContents* initial_contents = contents; 1132 TestContents* initial_contents = contents;
1002 1133
1003 contents->controller()->LoadURL(url2, PageTransition::TYPED); 1134 contents->controller()->LoadURL(url2, PageTransition::TYPED);
1004 EXPECT_EQ(0, notifications.size()); 1135 EXPECT_EQ(0, notifications.size());
1005 1136
1006 // The tab contents should have been replaced 1137 // The tab contents should have been replaced
1007 ASSERT_TRUE(initial_contents != contents); 1138 ASSERT_TRUE(initial_contents != contents);
1008 1139
1009 contents->controller()->DiscardPendingEntry(); 1140 contents->controller()->DiscardPendingEntry();
(...skipping 14 matching lines...) Expand all
1024 MessageLoop::current()->RunAllPending(); 1155 MessageLoop::current()->RunAllPending();
1025 } 1156 }
1026 1157
1027 // Tests that TabContentsTypes that are not in use are deleted (via a 1158 // Tests that TabContentsTypes that are not in use are deleted (via a
1028 // TabContentsCollector task). Prevents regression of bug 1296773. 1159 // TabContentsCollector task). Prevents regression of bug 1296773.
1029 TEST_F(NavigationControllerTest, SwitchTypesCleanup) { 1160 TEST_F(NavigationControllerTest, SwitchTypesCleanup) {
1030 const GURL url1("test1:foo"); 1161 const GURL url1("test1:foo");
1031 const GURL url2("test2:foo"); 1162 const GURL url2("test2:foo");
1032 const GURL url3("test2:bar"); 1163 const GURL url3("test2:bar");
1033 1164
1165 // Note that we need the LoadURL calls so that pending entries and the
1166 // different tab contents types are created. "Renderer" navigations won't
1167 // actually cross tab contents boundaries without these.
1034 contents->controller()->LoadURL(url1, PageTransition::TYPED); 1168 contents->controller()->LoadURL(url1, PageTransition::TYPED);
1035 contents->CompleteNavigation(0); 1169 contents->CompleteNavigationAsRenderer(0, url1);
1170 contents->controller()->LoadURL(url2, PageTransition::TYPED);
1171 contents->CompleteNavigationAsRenderer(1, url2);
1172 contents->controller()->LoadURL(url3, PageTransition::TYPED);
1173 contents->CompleteNavigationAsRenderer(2, url3);
1036 1174
1037 contents->controller()->LoadURL(url2, PageTransition::TYPED); 1175 // Navigate back to the start.
1038 contents->CompleteNavigation(0); 1176 contents->controller()->GoToIndex(0);
1177 contents->CompleteNavigationAsRenderer(0, url1);
1039 1178
1040 contents->controller()->LoadURL(url3, PageTransition::TYPED); 1179 // Now jump to the end.
1041 contents->CompleteNavigation(1);
1042
1043 // Navigate back to the start
1044 contents->controller()->GoToIndex(0);
1045 contents->CompleteNavigation(0);
1046
1047 // Now jump to the end
1048 contents->controller()->GoToIndex(2); 1180 contents->controller()->GoToIndex(2);
1049 contents->CompleteNavigation(1); 1181 contents->CompleteNavigationAsRenderer(2, url3);
1050 1182
1051 // There may be TabContentsCollector tasks pending, so flush them from queue. 1183 // There may be TabContentsCollector tasks pending, so flush them from queue.
1052 MessageLoop::current()->RunAllPending(); 1184 MessageLoop::current()->RunAllPending();
1053 1185
1054 // Now that the tasks have been flushed, the first tab type should be gone. 1186 // Now that the tasks have been flushed, the first tab type should be gone.
1055 ASSERT_TRUE( 1187 ASSERT_TRUE(
1056 contents->controller()->GetTabContents(kTestContentsType1) == NULL); 1188 contents->controller()->GetTabContents(kTestContentsType1) == NULL);
1057 ASSERT_EQ(contents, 1189 ASSERT_EQ(contents,
1058 contents->controller()->GetTabContents(kTestContentsType2)); 1190 contents->controller()->GetTabContents(kTestContentsType2));
1059 } 1191 }
1060 1192
1061 // Tests that we limit the number of navigation entries created correctly. 1193 // Tests that we limit the number of navigation entries created correctly.
1062 TEST_F(NavigationControllerTest, EnforceMaxNavigationCount) { 1194 TEST_F(NavigationControllerTest, EnforceMaxNavigationCount) {
1063 const size_t kMaxEntryCount = 5; 1195 const size_t kMaxEntryCount = 5;
1064 1196
1065 contents->controller()->max_entry_count_ = kMaxEntryCount; 1197 contents->controller()->max_entry_count_ = kMaxEntryCount;
1066 1198
1067 int url_index; 1199 int url_index;
1068 char buffer[128]; 1200 char buffer[128];
1069 // Load up to the max count, all entries should be there. 1201 // Load up to the max count, all entries should be there.
1070 for (url_index = 0; url_index < kMaxEntryCount; url_index++) { 1202 for (url_index = 0; url_index < kMaxEntryCount; url_index++) {
1071 SNPrintF(buffer, 128, "test1://www.a.com/%d", url_index); 1203 SNPrintF(buffer, 128, "test1://www.a.com/%d", url_index);
1072 contents->controller()->LoadURL(GURL(buffer), PageTransition::TYPED); 1204 GURL url(buffer);
1073 contents->CompleteNavigation(url_index); 1205 contents->controller()->LoadURL(url, PageTransition::TYPED);
1206 contents->CompleteNavigationAsRenderer(url_index, url);
1074 } 1207 }
1075 1208
1076 EXPECT_EQ(contents->controller()->GetEntryCount(), kMaxEntryCount); 1209 EXPECT_EQ(contents->controller()->GetEntryCount(), kMaxEntryCount);
1077 1210
1078 // Navigate some more. 1211 // Navigate some more.
1079 SNPrintF(buffer, 128, "test1://www.a.com/%d", url_index); 1212 SNPrintF(buffer, 128, "test1://www.a.com/%d", url_index);
1080 contents->controller()->LoadURL(GURL(buffer), PageTransition::TYPED); 1213 GURL url(buffer);
1081 contents->CompleteNavigation(url_index); 1214 contents->controller()->LoadURL(url, PageTransition::TYPED);
1215 contents->CompleteNavigationAsRenderer(url_index, url);
1082 url_index++; 1216 url_index++;
1083 1217
1084 // We expect http://www.a.com/0 to be gone. 1218 // We expect http://www.a.com/0 to be gone.
1085 EXPECT_EQ(contents->controller()->GetEntryCount(), kMaxEntryCount); 1219 EXPECT_EQ(contents->controller()->GetEntryCount(), kMaxEntryCount);
1086 EXPECT_EQ(contents->controller()->GetEntryAtIndex(0)->url(), 1220 EXPECT_EQ(contents->controller()->GetEntryAtIndex(0)->url(),
1087 GURL("test1://www.a.com/1")); 1221 GURL("test1://www.a.com/1"));
1088 1222
1089 // More navigations. 1223 // More navigations.
1090 for (int i = 0; i < 3; i++) { 1224 for (int i = 0; i < 3; i++) {
1091 SNPrintF(buffer, 128, "test1://www.a.com/%d", url_index); 1225 SNPrintF(buffer, 128, "test1://www.a.com/%d", url_index);
1092 contents->controller()->LoadURL(GURL(buffer), PageTransition::TYPED); 1226 url = GURL(buffer);
1093 contents->CompleteNavigation(url_index); 1227 contents->controller()->LoadURL(url, PageTransition::TYPED);
1228 contents->CompleteNavigationAsRenderer(url_index, url);
1094 url_index++; 1229 url_index++;
1095 } 1230 }
1096 EXPECT_EQ(contents->controller()->GetEntryCount(), kMaxEntryCount); 1231 EXPECT_EQ(contents->controller()->GetEntryCount(), kMaxEntryCount);
1097 EXPECT_EQ(contents->controller()->GetEntryAtIndex(0)->url(), 1232 EXPECT_EQ(contents->controller()->GetEntryAtIndex(0)->url(),
1098 GURL("test1://www.a.com/4")); 1233 GURL("test1://www.a.com/4"));
1099 } 1234 }
1100 1235
1236 // Tests that we can do a restore and navigate to the restored entries and
1237 // everything is updated properly. This can be tricky since there is no
1238 // SiteInstance for the entries created initially.
1239 TEST_F(NavigationControllerTest, RestoreNavigate) {
1240 site_instance = SiteInstance::CreateSiteInstance(profile);
1241
1242 // Create a NavigationController with a restored set of tabs.
1243 GURL url("test1:foo");
1244 std::vector<TabNavigation> navigations;
1245 navigations.push_back(TabNavigation(0, url, L"Title", "state",
1246 PageTransition::LINK));
1247 NavigationController* controller =
1248 new NavigationController(profile, navigations, 0, NULL);
1249 controller->GoToIndex(0);
1250
1251 // We should now have one entry, and it should be "pending".
1252 EXPECT_EQ(1, controller->GetEntryCount());
1253 EXPECT_EQ(controller->GetEntryAtIndex(0), controller->GetPendingEntry());
1254 EXPECT_EQ(0, controller->GetEntryAtIndex(0)->page_id());
1255
1256 // Say we navigated to that entry.
1257 ViewHostMsg_FrameNavigate_Params params;
1258 params.page_id = 0;
1259 params.url = url;
1260 params.transition = PageTransition::LINK;
1261 params.should_update_history = false;
1262 params.gesture = NavigationGestureUser;
1263 params.is_post = false;
1264 NavigationController::LoadCommittedDetails details;
1265 controller->RendererDidNavigate(params, false, &details);
1266
1267 // There should be no longer any pending entry and one committed one. This
1268 // means that we were able to locate the entry, assign its site instance, and
1269 // commit it properly.
1270 EXPECT_EQ(1, controller->GetEntryCount());
1271 EXPECT_EQ(0, controller->GetLastCommittedEntryIndex());
1272 EXPECT_FALSE(controller->GetPendingEntry());
1273 EXPECT_EQ(site_instance,
1274 controller->GetLastCommittedEntry()->site_instance());
1275 }
1276
1277 // Make sure that the page type and stuff is correct after an interstitial.
1278 TEST_F(NavigationControllerTest, Interstitial) {
1279 // First navigate somewhere normal.
1280 const GURL url1("test1:foo");
1281 contents->controller()->LoadURL(url1, PageTransition::TYPED);
1282 contents->CompleteNavigationAsRenderer(0, url1);
1283
1284 // Now navigate somewhere with an interstitial.
1285 const GURL url2("test1:bar");
1286 contents->controller()->LoadURL(url1, PageTransition::TYPED);
1287 contents->controller()->GetPendingEntry()->set_page_type(
1288 NavigationEntry::INTERSTITIAL_PAGE);
1289
1290 // At this point the interstitial will be displayed and the load will still
1291 // be pending. If the user continues, the load will commit.
1292 contents->CompleteNavigationAsRenderer(1, url2);
1293
1294 // The page should be a normal page again.
1295 EXPECT_EQ(url2, contents->controller()->GetLastCommittedEntry()->url());
1296 EXPECT_EQ(NavigationEntry::NORMAL_PAGE,
1297 contents->controller()->GetLastCommittedEntry()->page_type());
1298 }
1299
1300 // Tests that IsInPageNavigation returns appropriate results. Prevents
1301 // regression for bug 1126349.
1302 TEST_F(NavigationControllerTest, IsInPageNavigation) {
1303 // Navigate to URL with no refs.
1304 const GURL url("http://www.google.com/home.html");
1305 contents->CompleteNavigationAsRenderer(0, url);
1306
1307 // Reloading the page is not an in-page navigation.
1308 EXPECT_FALSE(contents->controller()->IsURLInPageNavigation(url));
1309 const GURL other_url("http://www.google.com/add.html");
1310 EXPECT_FALSE(contents->controller()->IsURLInPageNavigation(other_url));
1311 const GURL url_with_ref("http://www.google.com/home.html#my_ref");
1312 EXPECT_TRUE(contents->controller()->IsURLInPageNavigation(url_with_ref));
1313
1314 // Navigate to URL with refs.
1315 contents->CompleteNavigationAsRenderer(1, url_with_ref);
1316
1317 // Reloading the page is not an in-page navigation.
1318 EXPECT_FALSE(contents->controller()->IsURLInPageNavigation(url_with_ref));
1319 EXPECT_FALSE(contents->controller()->IsURLInPageNavigation(url));
1320 EXPECT_FALSE(contents->controller()->IsURLInPageNavigation(other_url));
1321 const GURL other_url_with_ref("http://www.google.com/home.html#my_other_ref");
1322 EXPECT_TRUE(contents->controller()->IsURLInPageNavigation(
1323 other_url_with_ref));
1324 }
1325
1101 // A basic test case. Navigates to a single url, and make sure the history 1326 // A basic test case. Navigates to a single url, and make sure the history
1102 // db matches. 1327 // db matches.
1103 TEST_F(NavigationControllerHistoryTest, Basic) { 1328 TEST_F(NavigationControllerHistoryTest, Basic) {
1104 contents->controller()->LoadURL(url0, PageTransition::TYPED); 1329 contents->controller()->LoadURL(url0, PageTransition::LINK);
1105 contents->CompleteNavigation(0); 1330 contents->CompleteNavigationAsRenderer(0, url0);
1106 1331
1107 GetLastSession(); 1332 GetLastSession();
1108 1333
1109 helper_.AssertSingleWindowWithSingleTab(windows_, 1); 1334 helper_.AssertSingleWindowWithSingleTab(windows_, 1);
1110 helper_.AssertTabEquals(0, 0, 1, *(windows_[0]->tabs[0])); 1335 helper_.AssertTabEquals(0, 0, 1, *(windows_[0]->tabs[0]));
1111 TabNavigation nav1(0, url0, std::wstring(), std::string(), 1336 TabNavigation nav1(0, url0, std::wstring(), std::string(),
1112 PageTransition::TYPED); 1337 PageTransition::LINK);
1113 helper_.AssertNavigationEquals(nav1, windows_[0]->tabs[0]->navigations[0]); 1338 helper_.AssertNavigationEquals(nav1, windows_[0]->tabs[0]->navigations[0]);
1114 } 1339 }
1115 1340
1116 // Navigates to three urls, then goes back and make sure the history database 1341 // Navigates to three urls, then goes back and make sure the history database
1117 // is in sync. 1342 // is in sync.
1118 TEST_F(NavigationControllerHistoryTest, NavigationThenBack) { 1343 TEST_F(NavigationControllerHistoryTest, NavigationThenBack) {
1119 contents->controller()->LoadURL(url0, PageTransition::TYPED); 1344 contents->CompleteNavigationAsRenderer(0, url0);
1120 contents->CompleteNavigation(0); 1345 contents->CompleteNavigationAsRenderer(1, url1);
1121 1346 contents->CompleteNavigationAsRenderer(2, url2);
1122 contents->controller()->LoadURL(url1, PageTransition::TYPED);
1123 contents->CompleteNavigation(1);
1124
1125 contents->controller()->LoadURL(url2, PageTransition::TYPED);
1126 contents->CompleteNavigation(2);
1127 1347
1128 contents->controller()->GoBack(); 1348 contents->controller()->GoBack();
1129 contents->CompleteNavigation(1); 1349 contents->CompleteNavigationAsRenderer(1, url1);
1130 1350
1131 GetLastSession(); 1351 GetLastSession();
1132 1352
1133 helper_.AssertSingleWindowWithSingleTab(windows_, 3); 1353 helper_.AssertSingleWindowWithSingleTab(windows_, 3);
1134 helper_.AssertTabEquals(0, 1, 3, *(windows_[0]->tabs[0])); 1354 helper_.AssertTabEquals(0, 1, 3, *(windows_[0]->tabs[0]));
1135 1355
1136 TabNavigation nav(0, url0, std::wstring(), std::string(), 1356 TabNavigation nav(0, url0, std::wstring(), std::string(),
1137 PageTransition::TYPED); 1357 PageTransition::LINK);
1138 helper_.AssertNavigationEquals(nav, windows_[0]->tabs[0]->navigations[0]); 1358 helper_.AssertNavigationEquals(nav, windows_[0]->tabs[0]->navigations[0]);
1139 nav.index = 1; 1359 nav.index = 1;
1140 nav.url = url1; 1360 nav.url = url1;
1141 helper_.AssertNavigationEquals(nav, windows_[0]->tabs[0]->navigations[1]); 1361 helper_.AssertNavigationEquals(nav, windows_[0]->tabs[0]->navigations[1]);
1142 nav.index = 2; 1362 nav.index = 2;
1143 nav.url = url2; 1363 nav.url = url2;
1144 helper_.AssertNavigationEquals(nav, windows_[0]->tabs[0]->navigations[2]); 1364 helper_.AssertNavigationEquals(nav, windows_[0]->tabs[0]->navigations[2]);
1145 } 1365 }
1146 1366
1147 // Navigates to three urls, then goes back twice, then loads a new url. 1367 // Navigates to three urls, then goes back twice, then loads a new url.
1148 TEST_F(NavigationControllerHistoryTest, NavigationPruning) { 1368 TEST_F(NavigationControllerHistoryTest, NavigationPruning) {
1149 contents->controller()->LoadURL(url0, PageTransition::TYPED); 1369 contents->CompleteNavigationAsRenderer(0, url0);
1150 contents->CompleteNavigation(0); 1370 contents->CompleteNavigationAsRenderer(1, url1);
1151 1371 contents->CompleteNavigationAsRenderer(2, url2);
1152 contents->controller()->LoadURL(url1, PageTransition::TYPED);
1153 contents->CompleteNavigation(1);
1154
1155 contents->controller()->LoadURL(url2, PageTransition::TYPED);
1156 contents->CompleteNavigation(2);
1157 1372
1158 contents->controller()->GoBack(); 1373 contents->controller()->GoBack();
1159 contents->CompleteNavigation(1); 1374 contents->CompleteNavigationAsRenderer(1, url1);
1160 1375
1161 contents->controller()->GoBack(); 1376 contents->controller()->GoBack();
1162 contents->CompleteNavigation(0); 1377 contents->CompleteNavigationAsRenderer(0, url0);
1163 1378
1164 contents->controller()->LoadURL(url2, PageTransition::TYPED); 1379 contents->CompleteNavigationAsRenderer(3, url2);
1165 contents->CompleteNavigation(3);
1166 1380
1167 // Now have url0, and url2. 1381 // Now have url0, and url2.
1168 1382
1169 GetLastSession(); 1383 GetLastSession();
1170 1384
1171 helper_.AssertSingleWindowWithSingleTab(windows_, 2); 1385 helper_.AssertSingleWindowWithSingleTab(windows_, 2);
1172 helper_.AssertTabEquals(0, 1, 2, *(windows_[0]->tabs[0])); 1386 helper_.AssertTabEquals(0, 1, 2, *(windows_[0]->tabs[0]));
1173 1387
1174 TabNavigation nav(0, url0, std::wstring(), std::string(), 1388 TabNavigation nav(0, url0, std::wstring(), std::string(),
1175 PageTransition::TYPED); 1389 PageTransition::LINK);
1176 helper_.AssertNavigationEquals(nav, windows_[0]->tabs[0]->navigations[0]); 1390 helper_.AssertNavigationEquals(nav, windows_[0]->tabs[0]->navigations[0]);
1177 nav.index = 1; 1391 nav.index = 1;
1178 nav.url = url2; 1392 nav.url = url2;
1179 helper_.AssertNavigationEquals(nav, windows_[0]->tabs[0]->navigations[1]); 1393 helper_.AssertNavigationEquals(nav, windows_[0]->tabs[0]->navigations[1]);
1180 } 1394 }
1181
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698