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

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

Issue 8186: Plumb the referrer throughout the OpenURL APIs.... (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 12 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « chrome/browser/navigation_controller.cc ('k') | chrome/browser/navigation_entry.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "base/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"
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after
66 66
67 void ClearContents() { 67 void ClearContents() {
68 contents->set_delegate(NULL); 68 contents->set_delegate(NULL);
69 contents->CloseContents(); 69 contents->CloseContents();
70 contents = NULL; 70 contents = NULL;
71 } 71 }
72 72
73 // TabContentsDelegate methods (only care about ReplaceContents): 73 // TabContentsDelegate methods (only care about ReplaceContents):
74 virtual void OpenURLFromTab(TabContents*, 74 virtual void OpenURLFromTab(TabContents*,
75 const GURL&, 75 const GURL&,
76 const GURL&,
76 WindowOpenDisposition, 77 WindowOpenDisposition,
77 PageTransition::Type) {} 78 PageTransition::Type) {}
78 virtual void NavigationStateChanged(const TabContents*, 79 virtual void NavigationStateChanged(const TabContents*,
79 unsigned flags) {} 80 unsigned flags) {}
80 virtual void ReplaceContents(TabContents* source, 81 virtual void ReplaceContents(TabContents* source,
81 TabContents* new_contents) { 82 TabContents* new_contents) {
82 contents->set_delegate(NULL); 83 contents->set_delegate(NULL);
83 contents = static_cast<TestTabContents*>(new_contents); 84 contents = static_cast<TestTabContents*>(new_contents);
84 contents->set_delegate(this); 85 contents->set_delegate(this);
85 } 86 }
(...skipping 162 matching lines...) Expand 10 before | Expand all | Expand 10 after
248 EXPECT_FALSE(contents->controller()->CanGoForward()); 249 EXPECT_FALSE(contents->controller()->CanGoForward());
249 } 250 }
250 251
251 TEST_F(NavigationControllerTest, LoadURL) { 252 TEST_F(NavigationControllerTest, LoadURL) {
252 TestNotificationTracker notifications; 253 TestNotificationTracker notifications;
253 RegisterForAllNavNotifications(&notifications, contents->controller()); 254 RegisterForAllNavNotifications(&notifications, contents->controller());
254 255
255 const GURL url1(scheme1() + ":foo1"); 256 const GURL url1(scheme1() + ":foo1");
256 const GURL url2(scheme1() + ":foo2"); 257 const GURL url2(scheme1() + ":foo2");
257 258
258 contents->controller()->LoadURL(url1, PageTransition::TYPED); 259 contents->controller()->LoadURL(url1, GURL(), PageTransition::TYPED);
259 // Creating a pending notification should not have issued any of the 260 // Creating a pending notification should not have issued any of the
260 // notifications we're listening for. 261 // notifications we're listening for.
261 EXPECT_EQ(0, notifications.size()); 262 EXPECT_EQ(0, notifications.size());
262 263
263 // The load should now be pending. 264 // The load should now be pending.
264 EXPECT_EQ(contents->controller()->GetEntryCount(), 0); 265 EXPECT_EQ(contents->controller()->GetEntryCount(), 0);
265 EXPECT_EQ(contents->controller()->GetLastCommittedEntryIndex(), -1); 266 EXPECT_EQ(contents->controller()->GetLastCommittedEntryIndex(), -1);
266 EXPECT_EQ(contents->controller()->GetPendingEntryIndex(), -1); 267 EXPECT_EQ(contents->controller()->GetPendingEntryIndex(), -1);
267 EXPECT_FALSE(contents->controller()->GetLastCommittedEntry()); 268 EXPECT_FALSE(contents->controller()->GetLastCommittedEntry());
268 EXPECT_TRUE(contents->controller()->GetPendingEntry()); 269 EXPECT_TRUE(contents->controller()->GetPendingEntry());
(...skipping 11 matching lines...) Expand all
280 EXPECT_EQ(contents->controller()->GetEntryCount(), 1); 281 EXPECT_EQ(contents->controller()->GetEntryCount(), 1);
281 EXPECT_EQ(contents->controller()->GetLastCommittedEntryIndex(), 0); 282 EXPECT_EQ(contents->controller()->GetLastCommittedEntryIndex(), 0);
282 EXPECT_EQ(contents->controller()->GetPendingEntryIndex(), -1); 283 EXPECT_EQ(contents->controller()->GetPendingEntryIndex(), -1);
283 EXPECT_TRUE(contents->controller()->GetLastCommittedEntry()); 284 EXPECT_TRUE(contents->controller()->GetLastCommittedEntry());
284 EXPECT_FALSE(contents->controller()->GetPendingEntry()); 285 EXPECT_FALSE(contents->controller()->GetPendingEntry());
285 EXPECT_FALSE(contents->controller()->CanGoBack()); 286 EXPECT_FALSE(contents->controller()->CanGoBack());
286 EXPECT_FALSE(contents->controller()->CanGoForward()); 287 EXPECT_FALSE(contents->controller()->CanGoForward());
287 EXPECT_EQ(contents->GetMaxPageID(), 0); 288 EXPECT_EQ(contents->GetMaxPageID(), 0);
288 289
289 // Load another... 290 // Load another...
290 contents->controller()->LoadURL(url2, PageTransition::TYPED); 291 contents->controller()->LoadURL(url2, GURL(), PageTransition::TYPED);
291 292
292 // The load should now be pending. 293 // The load should now be pending.
293 EXPECT_EQ(contents->controller()->GetEntryCount(), 1); 294 EXPECT_EQ(contents->controller()->GetEntryCount(), 1);
294 EXPECT_EQ(contents->controller()->GetLastCommittedEntryIndex(), 0); 295 EXPECT_EQ(contents->controller()->GetLastCommittedEntryIndex(), 0);
295 EXPECT_EQ(contents->controller()->GetPendingEntryIndex(), -1); 296 EXPECT_EQ(contents->controller()->GetPendingEntryIndex(), -1);
296 EXPECT_TRUE(contents->controller()->GetLastCommittedEntry()); 297 EXPECT_TRUE(contents->controller()->GetLastCommittedEntry());
297 EXPECT_TRUE(contents->controller()->GetPendingEntry()); 298 EXPECT_TRUE(contents->controller()->GetPendingEntry());
298 // TODO(darin): maybe this should really be true? 299 // TODO(darin): maybe this should really be true?
299 EXPECT_FALSE(contents->controller()->CanGoBack()); 300 EXPECT_FALSE(contents->controller()->CanGoBack());
300 EXPECT_FALSE(contents->controller()->CanGoForward()); 301 EXPECT_FALSE(contents->controller()->CanGoForward());
(...skipping 16 matching lines...) Expand all
317 // Tests what happens when the same page is loaded again. Should not create a 318 // Tests what happens when the same page is loaded again. Should not create a
318 // new session history entry. This is what happens when you press enter in the 319 // new session history entry. This is what happens when you press enter in the
319 // URL bar to reload: a pending entry is created and then it is discarded when 320 // URL bar to reload: a pending entry is created and then it is discarded when
320 // the load commits (because WebCore didn't actually make a new entry). 321 // the load commits (because WebCore didn't actually make a new entry).
321 TEST_F(NavigationControllerTest, LoadURL_SamePage) { 322 TEST_F(NavigationControllerTest, LoadURL_SamePage) {
322 TestNotificationTracker notifications; 323 TestNotificationTracker notifications;
323 RegisterForAllNavNotifications(&notifications, contents->controller()); 324 RegisterForAllNavNotifications(&notifications, contents->controller());
324 325
325 const GURL url1(scheme1() + ":foo1"); 326 const GURL url1(scheme1() + ":foo1");
326 327
327 contents->controller()->LoadURL(url1, PageTransition::TYPED); 328 contents->controller()->LoadURL(url1, GURL(), PageTransition::TYPED);
328 EXPECT_EQ(0, notifications.size()); 329 EXPECT_EQ(0, notifications.size());
329 contents->CompleteNavigationAsRenderer(0, url1); 330 contents->CompleteNavigationAsRenderer(0, url1);
330 EXPECT_TRUE(notifications.Check1AndReset(NOTIFY_NAV_ENTRY_COMMITTED)); 331 EXPECT_TRUE(notifications.Check1AndReset(NOTIFY_NAV_ENTRY_COMMITTED));
331 332
332 contents->controller()->LoadURL(url1, PageTransition::TYPED); 333 contents->controller()->LoadURL(url1, GURL(), PageTransition::TYPED);
333 EXPECT_EQ(0, notifications.size()); 334 EXPECT_EQ(0, notifications.size());
334 contents->CompleteNavigationAsRenderer(0, url1); 335 contents->CompleteNavigationAsRenderer(0, url1);
335 EXPECT_TRUE(notifications.Check1AndReset(NOTIFY_NAV_ENTRY_COMMITTED)); 336 EXPECT_TRUE(notifications.Check1AndReset(NOTIFY_NAV_ENTRY_COMMITTED));
336 337
337 // We should not have produced a new session history entry. 338 // We should not have produced a new session history entry.
338 EXPECT_EQ(contents->controller()->GetEntryCount(), 1); 339 EXPECT_EQ(contents->controller()->GetEntryCount(), 1);
339 EXPECT_EQ(contents->controller()->GetLastCommittedEntryIndex(), 0); 340 EXPECT_EQ(contents->controller()->GetLastCommittedEntryIndex(), 0);
340 EXPECT_EQ(contents->controller()->GetPendingEntryIndex(), -1); 341 EXPECT_EQ(contents->controller()->GetPendingEntryIndex(), -1);
341 EXPECT_TRUE(contents->controller()->GetLastCommittedEntry()); 342 EXPECT_TRUE(contents->controller()->GetLastCommittedEntry());
342 EXPECT_FALSE(contents->controller()->GetPendingEntry()); 343 EXPECT_FALSE(contents->controller()->GetPendingEntry());
343 EXPECT_FALSE(contents->controller()->CanGoBack()); 344 EXPECT_FALSE(contents->controller()->CanGoBack());
344 EXPECT_FALSE(contents->controller()->CanGoForward()); 345 EXPECT_FALSE(contents->controller()->CanGoForward());
345 } 346 }
346 347
347 // Tests loading a URL but discarding it before the load commits. 348 // Tests loading a URL but discarding it before the load commits.
348 TEST_F(NavigationControllerTest, LoadURL_Discarded) { 349 TEST_F(NavigationControllerTest, LoadURL_Discarded) {
349 TestNotificationTracker notifications; 350 TestNotificationTracker notifications;
350 RegisterForAllNavNotifications(&notifications, contents->controller()); 351 RegisterForAllNavNotifications(&notifications, contents->controller());
351 352
352 const GURL url1(scheme1() + ":foo1"); 353 const GURL url1(scheme1() + ":foo1");
353 const GURL url2(scheme1() + ":foo2"); 354 const GURL url2(scheme1() + ":foo2");
354 355
355 contents->controller()->LoadURL(url1, PageTransition::TYPED); 356 contents->controller()->LoadURL(url1, GURL(), PageTransition::TYPED);
356 EXPECT_EQ(0, notifications.size()); 357 EXPECT_EQ(0, notifications.size());
357 contents->CompleteNavigationAsRenderer(0, url1); 358 contents->CompleteNavigationAsRenderer(0, url1);
358 EXPECT_TRUE(notifications.Check1AndReset(NOTIFY_NAV_ENTRY_COMMITTED)); 359 EXPECT_TRUE(notifications.Check1AndReset(NOTIFY_NAV_ENTRY_COMMITTED));
359 360
360 contents->controller()->LoadURL(url2, PageTransition::TYPED); 361 contents->controller()->LoadURL(url2, GURL(), PageTransition::TYPED);
361 contents->controller()->DiscardNonCommittedEntries(); 362 contents->controller()->DiscardNonCommittedEntries();
362 EXPECT_EQ(0, notifications.size()); 363 EXPECT_EQ(0, notifications.size());
363 364
364 // Should not have produced a new session history entry. 365 // Should not have produced a new session history entry.
365 EXPECT_EQ(contents->controller()->GetEntryCount(), 1); 366 EXPECT_EQ(contents->controller()->GetEntryCount(), 1);
366 EXPECT_EQ(contents->controller()->GetLastCommittedEntryIndex(), 0); 367 EXPECT_EQ(contents->controller()->GetLastCommittedEntryIndex(), 0);
367 EXPECT_EQ(contents->controller()->GetPendingEntryIndex(), -1); 368 EXPECT_EQ(contents->controller()->GetPendingEntryIndex(), -1);
368 EXPECT_TRUE(contents->controller()->GetLastCommittedEntry()); 369 EXPECT_TRUE(contents->controller()->GetLastCommittedEntry());
369 EXPECT_FALSE(contents->controller()->GetPendingEntry()); 370 EXPECT_FALSE(contents->controller()->GetPendingEntry());
370 EXPECT_FALSE(contents->controller()->CanGoBack()); 371 EXPECT_FALSE(contents->controller()->CanGoBack());
371 EXPECT_FALSE(contents->controller()->CanGoForward()); 372 EXPECT_FALSE(contents->controller()->CanGoForward());
372 } 373 }
373 374
374 // Tests navigations that come in unrequested. This happens when the user 375 // Tests navigations that come in unrequested. This happens when the user
375 // navigates from the web page, and here we test that there is no pending entry. 376 // navigates from the web page, and here we test that there is no pending entry.
376 TEST_F(NavigationControllerTest, LoadURL_NoPending) { 377 TEST_F(NavigationControllerTest, LoadURL_NoPending) {
377 TestNotificationTracker notifications; 378 TestNotificationTracker notifications;
378 RegisterForAllNavNotifications(&notifications, contents->controller()); 379 RegisterForAllNavNotifications(&notifications, contents->controller());
379 380
380 // First make an existing committed entry. 381 // First make an existing committed entry.
381 const GURL kExistingURL1(scheme1() + ":eh"); 382 const GURL kExistingURL1(scheme1() + ":eh");
382 contents->controller()->LoadURL(kExistingURL1, PageTransition::TYPED); 383 contents->controller()->LoadURL(kExistingURL1, GURL(),
384 PageTransition::TYPED);
383 contents->CompleteNavigationAsRenderer(0, kExistingURL1); 385 contents->CompleteNavigationAsRenderer(0, kExistingURL1);
384 EXPECT_TRUE(notifications.Check1AndReset(NOTIFY_NAV_ENTRY_COMMITTED)); 386 EXPECT_TRUE(notifications.Check1AndReset(NOTIFY_NAV_ENTRY_COMMITTED));
385 387
386 // Do a new navigation without making a pending one. 388 // Do a new navigation without making a pending one.
387 const GURL kNewURL(scheme1() + ":see"); 389 const GURL kNewURL(scheme1() + ":see");
388 contents->CompleteNavigationAsRenderer(99, kNewURL); 390 contents->CompleteNavigationAsRenderer(99, kNewURL);
389 391
390 // There should no longer be any pending entry, and the third navigation we 392 // There should no longer be any pending entry, and the third navigation we
391 // just made should be committed. 393 // just made should be committed.
392 EXPECT_TRUE(notifications.Check1AndReset(NOTIFY_NAV_ENTRY_COMMITTED)); 394 EXPECT_TRUE(notifications.Check1AndReset(NOTIFY_NAV_ENTRY_COMMITTED));
393 EXPECT_EQ(-1, contents->controller()->GetPendingEntryIndex()); 395 EXPECT_EQ(-1, contents->controller()->GetPendingEntryIndex());
394 EXPECT_EQ(1, contents->controller()->GetLastCommittedEntryIndex()); 396 EXPECT_EQ(1, contents->controller()->GetLastCommittedEntryIndex());
395 EXPECT_EQ(kNewURL, contents->controller()->GetActiveEntry()->url()); 397 EXPECT_EQ(kNewURL, contents->controller()->GetActiveEntry()->url());
396 } 398 }
397 399
398 // Tests navigating to a new URL when there is a new pending navigation that is 400 // Tests navigating to a new URL when there is a new pending navigation that is
399 // not the one that just loaded. This will happen if the user types in a URL to 401 // not the one that just loaded. This will happen if the user types in a URL to
400 // somewhere slow, and then navigates the current page before the typed URL 402 // somewhere slow, and then navigates the current page before the typed URL
401 // commits. 403 // commits.
402 TEST_F(NavigationControllerTest, LoadURL_NewPending) { 404 TEST_F(NavigationControllerTest, LoadURL_NewPending) {
403 TestNotificationTracker notifications; 405 TestNotificationTracker notifications;
404 RegisterForAllNavNotifications(&notifications, contents->controller()); 406 RegisterForAllNavNotifications(&notifications, contents->controller());
405 407
406 // First make an existing committed entry. 408 // First make an existing committed entry.
407 const GURL kExistingURL1(scheme1() + ":eh"); 409 const GURL kExistingURL1(scheme1() + ":eh");
408 contents->controller()->LoadURL(kExistingURL1, PageTransition::TYPED); 410 contents->controller()->LoadURL(kExistingURL1, GURL(),
411 PageTransition::TYPED);
409 contents->CompleteNavigationAsRenderer(0, kExistingURL1); 412 contents->CompleteNavigationAsRenderer(0, kExistingURL1);
410 EXPECT_TRUE(notifications.Check1AndReset(NOTIFY_NAV_ENTRY_COMMITTED)); 413 EXPECT_TRUE(notifications.Check1AndReset(NOTIFY_NAV_ENTRY_COMMITTED));
411 414
412 // Make a pending entry to somewhere new. 415 // Make a pending entry to somewhere new.
413 const GURL kExistingURL2(scheme1() + ":bee"); 416 const GURL kExistingURL2(scheme1() + ":bee");
414 contents->controller()->LoadURL(kExistingURL2, PageTransition::TYPED); 417 contents->controller()->LoadURL(kExistingURL2, GURL(),
418 PageTransition::TYPED);
415 EXPECT_EQ(0, notifications.size()); 419 EXPECT_EQ(0, notifications.size());
416 420
417 // Before that commits, do a new navigation. 421 // Before that commits, do a new navigation.
418 const GURL kNewURL(scheme1() + ":see"); 422 const GURL kNewURL(scheme1() + ":see");
419 contents->CompleteNavigationAsRenderer(3, kNewURL); 423 contents->CompleteNavigationAsRenderer(3, kNewURL);
420 424
421 // There should no longer be any pending entry, and the third navigation we 425 // There should no longer be any pending entry, and the third navigation we
422 // just made should be committed. 426 // just made should be committed.
423 EXPECT_TRUE(notifications.Check1AndReset(NOTIFY_NAV_ENTRY_COMMITTED)); 427 EXPECT_TRUE(notifications.Check1AndReset(NOTIFY_NAV_ENTRY_COMMITTED));
424 EXPECT_EQ(-1, contents->controller()->GetPendingEntryIndex()); 428 EXPECT_EQ(-1, contents->controller()->GetPendingEntryIndex());
425 EXPECT_EQ(1, contents->controller()->GetLastCommittedEntryIndex()); 429 EXPECT_EQ(1, contents->controller()->GetLastCommittedEntryIndex());
426 EXPECT_EQ(kNewURL, contents->controller()->GetActiveEntry()->url()); 430 EXPECT_EQ(kNewURL, contents->controller()->GetActiveEntry()->url());
427 } 431 }
428 432
429 // Tests navigating to a new URL when there is a pending back/forward 433 // Tests navigating to a new URL when there is a pending back/forward
430 // navigation. This will happen if the user hits back, but before that commits, 434 // navigation. This will happen if the user hits back, but before that commits,
431 // they navigate somewhere new. 435 // they navigate somewhere new.
432 TEST_F(NavigationControllerTest, LoadURL_ExistingPending) { 436 TEST_F(NavigationControllerTest, LoadURL_ExistingPending) {
433 TestNotificationTracker notifications; 437 TestNotificationTracker notifications;
434 RegisterForAllNavNotifications(&notifications, contents->controller()); 438 RegisterForAllNavNotifications(&notifications, contents->controller());
435 439
436 // First make some history. 440 // First make some history.
437 const GURL kExistingURL1(scheme1() + ":eh"); 441 const GURL kExistingURL1(scheme1() + ":eh");
438 contents->controller()->LoadURL(kExistingURL1, PageTransition::TYPED); 442 contents->controller()->LoadURL(kExistingURL1, GURL(),
443 PageTransition::TYPED);
439 contents->CompleteNavigationAsRenderer(0, kExistingURL1); 444 contents->CompleteNavigationAsRenderer(0, kExistingURL1);
440 EXPECT_TRUE(notifications.Check1AndReset(NOTIFY_NAV_ENTRY_COMMITTED)); 445 EXPECT_TRUE(notifications.Check1AndReset(NOTIFY_NAV_ENTRY_COMMITTED));
441 446
442 const GURL kExistingURL2(scheme1() + ":bee"); 447 const GURL kExistingURL2(scheme1() + ":bee");
443 contents->controller()->LoadURL(kExistingURL2, PageTransition::TYPED); 448 contents->controller()->LoadURL(kExistingURL2, GURL(),
449 PageTransition::TYPED);
444 contents->CompleteNavigationAsRenderer(1, kExistingURL2); 450 contents->CompleteNavigationAsRenderer(1, kExistingURL2);
445 EXPECT_TRUE(notifications.Check1AndReset(NOTIFY_NAV_ENTRY_COMMITTED)); 451 EXPECT_TRUE(notifications.Check1AndReset(NOTIFY_NAV_ENTRY_COMMITTED));
446 452
447 // Now make a pending back/forward navigation. The zeroth entry should be 453 // Now make a pending back/forward navigation. The zeroth entry should be
448 // pending. 454 // pending.
449 contents->controller()->GoBack(); 455 contents->controller()->GoBack();
450 EXPECT_EQ(0, notifications.size()); 456 EXPECT_EQ(0, notifications.size());
451 EXPECT_EQ(0, contents->controller()->GetPendingEntryIndex()); 457 EXPECT_EQ(0, contents->controller()->GetPendingEntryIndex());
452 EXPECT_EQ(1, contents->controller()->GetLastCommittedEntryIndex()); 458 EXPECT_EQ(1, contents->controller()->GetLastCommittedEntryIndex());
453 459
454 // Before that commits, do a new navigation. 460 // Before that commits, do a new navigation.
455 const GURL kNewURL(scheme1() + ":see"); 461 const GURL kNewURL(scheme1() + ":see");
456 NavigationController::LoadCommittedDetails details; 462 NavigationController::LoadCommittedDetails details;
457 contents->CompleteNavigationAsRenderer(3, kNewURL); 463 contents->CompleteNavigationAsRenderer(3, kNewURL);
458 464
459 // There should no longer be any pending entry, and the third navigation we 465 // There should no longer be any pending entry, and the third navigation we
460 // just made should be committed. 466 // just made should be committed.
461 EXPECT_TRUE(notifications.Check1AndReset(NOTIFY_NAV_ENTRY_COMMITTED)); 467 EXPECT_TRUE(notifications.Check1AndReset(NOTIFY_NAV_ENTRY_COMMITTED));
462 EXPECT_EQ(-1, contents->controller()->GetPendingEntryIndex()); 468 EXPECT_EQ(-1, contents->controller()->GetPendingEntryIndex());
463 EXPECT_EQ(2, contents->controller()->GetLastCommittedEntryIndex()); 469 EXPECT_EQ(2, contents->controller()->GetLastCommittedEntryIndex());
464 EXPECT_EQ(kNewURL, contents->controller()->GetActiveEntry()->url()); 470 EXPECT_EQ(kNewURL, contents->controller()->GetActiveEntry()->url());
465 } 471 }
466 472
467 TEST_F(NavigationControllerTest, Reload) { 473 TEST_F(NavigationControllerTest, Reload) {
468 TestNotificationTracker notifications; 474 TestNotificationTracker notifications;
469 RegisterForAllNavNotifications(&notifications, contents->controller()); 475 RegisterForAllNavNotifications(&notifications, contents->controller());
470 476
471 const GURL url1(scheme1() + ":foo1"); 477 const GURL url1(scheme1() + ":foo1");
472 478
473 contents->controller()->LoadURL(url1, PageTransition::TYPED); 479 contents->controller()->LoadURL(url1, GURL(), PageTransition::TYPED);
474 EXPECT_EQ(0, notifications.size()); 480 EXPECT_EQ(0, notifications.size());
475 contents->CompleteNavigationAsRenderer(0, url1); 481 contents->CompleteNavigationAsRenderer(0, url1);
476 EXPECT_TRUE(notifications.Check1AndReset(NOTIFY_NAV_ENTRY_COMMITTED)); 482 EXPECT_TRUE(notifications.Check1AndReset(NOTIFY_NAV_ENTRY_COMMITTED));
477 483
478 contents->controller()->Reload(); 484 contents->controller()->Reload();
479 EXPECT_EQ(0, notifications.size()); 485 EXPECT_EQ(0, notifications.size());
480 486
481 // The reload is pending. 487 // The reload is pending.
482 EXPECT_EQ(contents->controller()->GetEntryCount(), 1); 488 EXPECT_EQ(contents->controller()->GetEntryCount(), 1);
483 EXPECT_EQ(contents->controller()->GetLastCommittedEntryIndex(), 0); 489 EXPECT_EQ(contents->controller()->GetLastCommittedEntryIndex(), 0);
(...skipping 17 matching lines...) Expand all
501 } 507 }
502 508
503 // Tests what happens when a reload navigation produces a new page. 509 // Tests what happens when a reload navigation produces a new page.
504 TEST_F(NavigationControllerTest, Reload_GeneratesNewPage) { 510 TEST_F(NavigationControllerTest, Reload_GeneratesNewPage) {
505 TestNotificationTracker notifications; 511 TestNotificationTracker notifications;
506 RegisterForAllNavNotifications(&notifications, contents->controller()); 512 RegisterForAllNavNotifications(&notifications, contents->controller());
507 513
508 const GURL url1(scheme1() + ":foo1"); 514 const GURL url1(scheme1() + ":foo1");
509 const GURL url2(scheme1() + ":foo2"); 515 const GURL url2(scheme1() + ":foo2");
510 516
511 contents->controller()->LoadURL(url1, PageTransition::TYPED); 517 contents->controller()->LoadURL(url1, GURL(), PageTransition::TYPED);
512 contents->CompleteNavigationAsRenderer(0, url1); 518 contents->CompleteNavigationAsRenderer(0, url1);
513 EXPECT_TRUE(notifications.Check1AndReset(NOTIFY_NAV_ENTRY_COMMITTED)); 519 EXPECT_TRUE(notifications.Check1AndReset(NOTIFY_NAV_ENTRY_COMMITTED));
514 520
515 contents->controller()->Reload(); 521 contents->controller()->Reload();
516 EXPECT_EQ(0, notifications.size()); 522 EXPECT_EQ(0, notifications.size());
517 523
518 contents->CompleteNavigationAsRenderer(1, url2); 524 contents->CompleteNavigationAsRenderer(1, url2);
519 EXPECT_TRUE(notifications.Check1AndReset(NOTIFY_NAV_ENTRY_COMMITTED)); 525 EXPECT_TRUE(notifications.Check1AndReset(NOTIFY_NAV_ENTRY_COMMITTED));
520 526
521 // Now the reload is committed. 527 // Now the reload is committed.
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
568 574
569 // Tests what happens when a back navigation produces a new page. 575 // Tests what happens when a back navigation produces a new page.
570 TEST_F(NavigationControllerTest, Back_GeneratesNewPage) { 576 TEST_F(NavigationControllerTest, Back_GeneratesNewPage) {
571 TestNotificationTracker notifications; 577 TestNotificationTracker notifications;
572 RegisterForAllNavNotifications(&notifications, contents->controller()); 578 RegisterForAllNavNotifications(&notifications, contents->controller());
573 579
574 const GURL url1(scheme1() + ":foo1"); 580 const GURL url1(scheme1() + ":foo1");
575 const GURL url2(scheme1() + ":foo2"); 581 const GURL url2(scheme1() + ":foo2");
576 const GURL url3(scheme1() + ":foo3"); 582 const GURL url3(scheme1() + ":foo3");
577 583
578 contents->controller()->LoadURL(url1, PageTransition::TYPED); 584 contents->controller()->LoadURL(url1, GURL(), PageTransition::TYPED);
579 contents->CompleteNavigationAsRenderer(0, url1); 585 contents->CompleteNavigationAsRenderer(0, url1);
580 EXPECT_TRUE(notifications.Check1AndReset(NOTIFY_NAV_ENTRY_COMMITTED)); 586 EXPECT_TRUE(notifications.Check1AndReset(NOTIFY_NAV_ENTRY_COMMITTED));
581 587
582 contents->controller()->LoadURL(url2, PageTransition::TYPED); 588 contents->controller()->LoadURL(url2, GURL(), PageTransition::TYPED);
583 contents->CompleteNavigationAsRenderer(1, url2); 589 contents->CompleteNavigationAsRenderer(1, url2);
584 EXPECT_TRUE(notifications.Check1AndReset(NOTIFY_NAV_ENTRY_COMMITTED)); 590 EXPECT_TRUE(notifications.Check1AndReset(NOTIFY_NAV_ENTRY_COMMITTED));
585 591
586 contents->controller()->GoBack(); 592 contents->controller()->GoBack();
587 EXPECT_EQ(0, notifications.size()); 593 EXPECT_EQ(0, notifications.size());
588 594
589 // We should now have a pending navigation to go back. 595 // We should now have a pending navigation to go back.
590 EXPECT_EQ(contents->controller()->GetEntryCount(), 2); 596 EXPECT_EQ(contents->controller()->GetEntryCount(), 2);
591 EXPECT_EQ(contents->controller()->GetLastCommittedEntryIndex(), 1); 597 EXPECT_EQ(contents->controller()->GetLastCommittedEntryIndex(), 1);
592 EXPECT_EQ(contents->controller()->GetPendingEntryIndex(), 0); 598 EXPECT_EQ(contents->controller()->GetPendingEntryIndex(), 0);
(...skipping 27 matching lines...) Expand all
620 626
621 // First navigate two places so we have some back history. 627 // First navigate two places so we have some back history.
622 contents->CompleteNavigationAsRenderer(0, kUrl1); 628 contents->CompleteNavigationAsRenderer(0, kUrl1);
623 EXPECT_TRUE(notifications.Check1AndReset(NOTIFY_NAV_ENTRY_COMMITTED)); 629 EXPECT_TRUE(notifications.Check1AndReset(NOTIFY_NAV_ENTRY_COMMITTED));
624 630
625 //contents->controller()->LoadURL(kUrl2, PageTransition::TYPED); 631 //contents->controller()->LoadURL(kUrl2, PageTransition::TYPED);
626 contents->CompleteNavigationAsRenderer(1, kUrl2); 632 contents->CompleteNavigationAsRenderer(1, kUrl2);
627 EXPECT_TRUE(notifications.Check1AndReset(NOTIFY_NAV_ENTRY_COMMITTED)); 633 EXPECT_TRUE(notifications.Check1AndReset(NOTIFY_NAV_ENTRY_COMMITTED));
628 634
629 // Now start a new pending navigation and go back before it commits. 635 // Now start a new pending navigation and go back before it commits.
630 contents->controller()->LoadURL(kUrl3, PageTransition::TYPED); 636 contents->controller()->LoadURL(kUrl3, GURL(), PageTransition::TYPED);
631 EXPECT_EQ(-1, contents->controller()->GetPendingEntryIndex()); 637 EXPECT_EQ(-1, contents->controller()->GetPendingEntryIndex());
632 EXPECT_EQ(kUrl3, contents->controller()->GetPendingEntry()->url()); 638 EXPECT_EQ(kUrl3, contents->controller()->GetPendingEntry()->url());
633 contents->controller()->GoBack(); 639 contents->controller()->GoBack();
634 640
635 // The pending navigation should now be the "back" item and the new one 641 // The pending navigation should now be the "back" item and the new one
636 // should be gone. 642 // should be gone.
637 EXPECT_EQ(0, contents->controller()->GetPendingEntryIndex()); 643 EXPECT_EQ(0, contents->controller()->GetPendingEntryIndex());
638 EXPECT_EQ(kUrl1, contents->controller()->GetPendingEntry()->url()); 644 EXPECT_EQ(kUrl1, contents->controller()->GetPendingEntry()->url());
639 } 645 }
640 646
(...skipping 365 matching lines...) Expand 10 before | Expand all | Expand 10 after
1006 TestNotificationTracker notifications; 1012 TestNotificationTracker notifications;
1007 RegisterForAllNavNotifications(&notifications, contents->controller()); 1013 RegisterForAllNavNotifications(&notifications, contents->controller());
1008 1014
1009 const GURL url1(scheme1() + ":foo"); 1015 const GURL url1(scheme1() + ":foo");
1010 const GURL url2(scheme2() + ":foo"); 1016 const GURL url2(scheme2() + ":foo");
1011 1017
1012 contents->CompleteNavigationAsRenderer(0, url1); 1018 contents->CompleteNavigationAsRenderer(0, url1);
1013 EXPECT_TRUE(notifications.Check1AndReset(NOTIFY_NAV_ENTRY_COMMITTED)); 1019 EXPECT_TRUE(notifications.Check1AndReset(NOTIFY_NAV_ENTRY_COMMITTED));
1014 1020
1015 TestTabContents* initial_contents = contents; 1021 TestTabContents* initial_contents = contents;
1016 contents->controller()->LoadURL(url2, PageTransition::TYPED); 1022 contents->controller()->LoadURL(url2, GURL(), PageTransition::TYPED);
1017 1023
1018 // The tab contents should have been replaced 1024 // The tab contents should have been replaced
1019 ASSERT_TRUE(initial_contents != contents); 1025 ASSERT_TRUE(initial_contents != contents);
1020 1026
1021 contents->CompleteNavigationAsRenderer(1, url2); 1027 contents->CompleteNavigationAsRenderer(1, url2);
1022 EXPECT_TRUE(notifications.Check1AndReset(NOTIFY_NAV_ENTRY_COMMITTED)); 1028 EXPECT_TRUE(notifications.Check1AndReset(NOTIFY_NAV_ENTRY_COMMITTED));
1023 1029
1024 // A second navigation entry should have been committed even though the 1030 // A second navigation entry should have been committed even though the
1025 // PageIDs are the same. PageIDs are scoped to the tab contents type. 1031 // PageIDs are the same. PageIDs are scoped to the tab contents type.
1026 EXPECT_EQ(contents->controller()->GetEntryCount(), 2); 1032 EXPECT_EQ(contents->controller()->GetEntryCount(), 2);
(...skipping 29 matching lines...) Expand all
1056 RegisterForAllNavNotifications(&notifications, contents->controller()); 1062 RegisterForAllNavNotifications(&notifications, contents->controller());
1057 1063
1058 const GURL url1(scheme1() + ":foo"); 1064 const GURL url1(scheme1() + ":foo");
1059 const GURL url2(scheme2() + ":foo"); 1065 const GURL url2(scheme2() + ":foo");
1060 1066
1061 contents->CompleteNavigationAsRenderer(0, url1); 1067 contents->CompleteNavigationAsRenderer(0, url1);
1062 EXPECT_TRUE(notifications.Check1AndReset(NOTIFY_NAV_ENTRY_COMMITTED)); 1068 EXPECT_TRUE(notifications.Check1AndReset(NOTIFY_NAV_ENTRY_COMMITTED));
1063 1069
1064 TestTabContents* initial_contents = contents; 1070 TestTabContents* initial_contents = contents;
1065 1071
1066 contents->controller()->LoadURL(url2, PageTransition::TYPED); 1072 contents->controller()->LoadURL(url2, GURL(), PageTransition::TYPED);
1067 EXPECT_EQ(0, notifications.size()); 1073 EXPECT_EQ(0, notifications.size());
1068 1074
1069 // The tab contents should have been replaced 1075 // The tab contents should have been replaced
1070 ASSERT_TRUE(initial_contents != contents); 1076 ASSERT_TRUE(initial_contents != contents);
1071 1077
1072 contents->controller()->DiscardNonCommittedEntries(); 1078 contents->controller()->DiscardNonCommittedEntries();
1073 EXPECT_EQ(0, notifications.size()); 1079 EXPECT_EQ(0, notifications.size());
1074 1080
1075 // The tab contents should have been replaced back 1081 // The tab contents should have been replaced back
1076 ASSERT_TRUE(initial_contents == contents); 1082 ASSERT_TRUE(initial_contents == contents);
(...skipping 13 matching lines...) Expand all
1090 // Tests that TabContentsTypes that are not in use are deleted (via a 1096 // Tests that TabContentsTypes that are not in use are deleted (via a
1091 // TabContentsCollector task). Prevents regression of bug 1296773. 1097 // TabContentsCollector task). Prevents regression of bug 1296773.
1092 TEST_F(NavigationControllerTest, SwitchTypesCleanup) { 1098 TEST_F(NavigationControllerTest, SwitchTypesCleanup) {
1093 const GURL url1(scheme1() + ":foo"); 1099 const GURL url1(scheme1() + ":foo");
1094 const GURL url2(scheme2() + ":foo"); 1100 const GURL url2(scheme2() + ":foo");
1095 const GURL url3(scheme2() + ":bar"); 1101 const GURL url3(scheme2() + ":bar");
1096 1102
1097 // Note that we need the LoadURL calls so that pending entries and the 1103 // Note that we need the LoadURL calls so that pending entries and the
1098 // different tab contents types are created. "Renderer" navigations won't 1104 // different tab contents types are created. "Renderer" navigations won't
1099 // actually cross tab contents boundaries without these. 1105 // actually cross tab contents boundaries without these.
1100 contents->controller()->LoadURL(url1, PageTransition::TYPED); 1106 contents->controller()->LoadURL(url1, GURL(), PageTransition::TYPED);
1101 contents->CompleteNavigationAsRenderer(0, url1); 1107 contents->CompleteNavigationAsRenderer(0, url1);
1102 contents->controller()->LoadURL(url2, PageTransition::TYPED); 1108 contents->controller()->LoadURL(url2, GURL(), PageTransition::TYPED);
1103 contents->CompleteNavigationAsRenderer(1, url2); 1109 contents->CompleteNavigationAsRenderer(1, url2);
1104 contents->controller()->LoadURL(url3, PageTransition::TYPED); 1110 contents->controller()->LoadURL(url3, GURL(), PageTransition::TYPED);
1105 contents->CompleteNavigationAsRenderer(2, url3); 1111 contents->CompleteNavigationAsRenderer(2, url3);
1106 1112
1107 // Navigate back to the start. 1113 // Navigate back to the start.
1108 contents->controller()->GoToIndex(0); 1114 contents->controller()->GoToIndex(0);
1109 contents->CompleteNavigationAsRenderer(0, url1); 1115 contents->CompleteNavigationAsRenderer(0, url1);
1110 1116
1111 // Now jump to the end. 1117 // Now jump to the end.
1112 contents->controller()->GoToIndex(2); 1118 contents->controller()->GoToIndex(2);
1113 contents->CompleteNavigationAsRenderer(2, url3); 1119 contents->CompleteNavigationAsRenderer(2, url3);
1114 1120
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
1163 const size_t kMaxEntryCount = 5; 1169 const size_t kMaxEntryCount = 5;
1164 1170
1165 NavigationController::set_max_entry_count(kMaxEntryCount); 1171 NavigationController::set_max_entry_count(kMaxEntryCount);
1166 1172
1167 int url_index; 1173 int url_index;
1168 char buffer[128]; 1174 char buffer[128];
1169 // Load up to the max count, all entries should be there. 1175 // Load up to the max count, all entries should be there.
1170 for (url_index = 0; url_index < kMaxEntryCount; url_index++) { 1176 for (url_index = 0; url_index < kMaxEntryCount; url_index++) {
1171 SNPrintF(buffer, 128, (scheme1() + "://www.a.com/%d").c_str(), url_index); 1177 SNPrintF(buffer, 128, (scheme1() + "://www.a.com/%d").c_str(), url_index);
1172 GURL url(buffer); 1178 GURL url(buffer);
1173 contents->controller()->LoadURL(url, PageTransition::TYPED); 1179 contents->controller()->LoadURL(url, GURL(), PageTransition::TYPED);
1174 contents->CompleteNavigationAsRenderer(url_index, url); 1180 contents->CompleteNavigationAsRenderer(url_index, url);
1175 } 1181 }
1176 1182
1177 EXPECT_EQ(contents->controller()->GetEntryCount(), kMaxEntryCount); 1183 EXPECT_EQ(contents->controller()->GetEntryCount(), kMaxEntryCount);
1178 1184
1179 // Created a PrunedListener to observe prune notifications. 1185 // Created a PrunedListener to observe prune notifications.
1180 PrunedListener listener(contents->controller()); 1186 PrunedListener listener(contents->controller());
1181 1187
1182 // Navigate some more. 1188 // Navigate some more.
1183 SNPrintF(buffer, 128, (scheme1() + "://www.a.com/%d").c_str(), url_index); 1189 SNPrintF(buffer, 128, (scheme1() + "://www.a.com/%d").c_str(), url_index);
1184 GURL url(buffer); 1190 GURL url(buffer);
1185 contents->controller()->LoadURL(url, PageTransition::TYPED); 1191 contents->controller()->LoadURL(url, GURL(), PageTransition::TYPED);
1186 contents->CompleteNavigationAsRenderer(url_index, url); 1192 contents->CompleteNavigationAsRenderer(url_index, url);
1187 url_index++; 1193 url_index++;
1188 1194
1189 // We should have got a pruned navigation. 1195 // We should have got a pruned navigation.
1190 EXPECT_EQ(1, listener.notification_count_); 1196 EXPECT_EQ(1, listener.notification_count_);
1191 EXPECT_TRUE(listener.details_.from_front); 1197 EXPECT_TRUE(listener.details_.from_front);
1192 EXPECT_EQ(1, listener.details_.count); 1198 EXPECT_EQ(1, listener.details_.count);
1193 1199
1194 // We expect http://www.a.com/0 to be gone. 1200 // We expect http://www.a.com/0 to be gone.
1195 EXPECT_EQ(contents->controller()->GetEntryCount(), kMaxEntryCount); 1201 EXPECT_EQ(contents->controller()->GetEntryCount(), kMaxEntryCount);
1196 EXPECT_EQ(contents->controller()->GetEntryAtIndex(0)->url(), 1202 EXPECT_EQ(contents->controller()->GetEntryAtIndex(0)->url(),
1197 GURL(scheme1() + "://www.a.com/1")); 1203 GURL(scheme1() + "://www.a.com/1"));
1198 1204
1199 // More navigations. 1205 // More navigations.
1200 for (int i = 0; i < 3; i++) { 1206 for (int i = 0; i < 3; i++) {
1201 SNPrintF(buffer, 128, (scheme1() + "://www.a.com/%d").c_str(), url_index); 1207 SNPrintF(buffer, 128, (scheme1() + "://www.a.com/%d").c_str(), url_index);
1202 url = GURL(buffer); 1208 url = GURL(buffer);
1203 contents->controller()->LoadURL(url, PageTransition::TYPED); 1209 contents->controller()->LoadURL(url, GURL(), PageTransition::TYPED);
1204 contents->CompleteNavigationAsRenderer(url_index, url); 1210 contents->CompleteNavigationAsRenderer(url_index, url);
1205 url_index++; 1211 url_index++;
1206 } 1212 }
1207 EXPECT_EQ(contents->controller()->GetEntryCount(), kMaxEntryCount); 1213 EXPECT_EQ(contents->controller()->GetEntryCount(), kMaxEntryCount);
1208 EXPECT_EQ(contents->controller()->GetEntryAtIndex(0)->url(), 1214 EXPECT_EQ(contents->controller()->GetEntryAtIndex(0)->url(),
1209 GURL(scheme1() + "://www.a.com/4")); 1215 GURL(scheme1() + "://www.a.com/4"));
1210 1216
1211 NavigationController::set_max_entry_count(original_count); 1217 NavigationController::set_max_entry_count(original_count);
1212 } 1218 }
1213 1219
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
1257 ClearContents(); 1263 ClearContents();
1258 controller->Destroy(); 1264 controller->Destroy();
1259 TestTabContents::set_site_instance(NULL); 1265 TestTabContents::set_site_instance(NULL);
1260 site_instance->Release(); 1266 site_instance->Release();
1261 } 1267 }
1262 1268
1263 // Make sure that the page type and stuff is correct after an interstitial. 1269 // Make sure that the page type and stuff is correct after an interstitial.
1264 TEST_F(NavigationControllerTest, Interstitial) { 1270 TEST_F(NavigationControllerTest, Interstitial) {
1265 // First navigate somewhere normal. 1271 // First navigate somewhere normal.
1266 const GURL url1(scheme1() + ":foo"); 1272 const GURL url1(scheme1() + ":foo");
1267 contents->controller()->LoadURL(url1, PageTransition::TYPED); 1273 contents->controller()->LoadURL(url1, GURL(), PageTransition::TYPED);
1268 contents->CompleteNavigationAsRenderer(0, url1); 1274 contents->CompleteNavigationAsRenderer(0, url1);
1269 1275
1270 // Now navigate somewhere with an interstitial. 1276 // Now navigate somewhere with an interstitial.
1271 const GURL url2(scheme1() + ":bar"); 1277 const GURL url2(scheme1() + ":bar");
1272 contents->controller()->LoadURL(url1, PageTransition::TYPED); 1278 contents->controller()->LoadURL(url1, GURL(), PageTransition::TYPED);
1273 contents->controller()->GetPendingEntry()->set_page_type( 1279 contents->controller()->GetPendingEntry()->set_page_type(
1274 NavigationEntry::INTERSTITIAL_PAGE); 1280 NavigationEntry::INTERSTITIAL_PAGE);
1275 1281
1276 // At this point the interstitial will be displayed and the load will still 1282 // At this point the interstitial will be displayed and the load will still
1277 // be pending. If the user continues, the load will commit. 1283 // be pending. If the user continues, the load will commit.
1278 contents->CompleteNavigationAsRenderer(1, url2); 1284 contents->CompleteNavigationAsRenderer(1, url2);
1279 1285
1280 // The page should be a normal page again. 1286 // The page should be a normal page again.
1281 EXPECT_EQ(url2, contents->controller()->GetLastCommittedEntry()->url()); 1287 EXPECT_EQ(url2, contents->controller()->GetLastCommittedEntry()->url());
1282 EXPECT_EQ(NavigationEntry::NORMAL_PAGE, 1288 EXPECT_EQ(NavigationEntry::NORMAL_PAGE,
1283 contents->controller()->GetLastCommittedEntry()->page_type()); 1289 contents->controller()->GetLastCommittedEntry()->page_type());
1284 } 1290 }
1285 1291
1286 TEST_F(NavigationControllerTest, RemoveEntry) { 1292 TEST_F(NavigationControllerTest, RemoveEntry) {
1287 const GURL url1(scheme1() + ":foo1"); 1293 const GURL url1(scheme1() + ":foo1");
1288 const GURL url2(scheme1() + ":foo2"); 1294 const GURL url2(scheme1() + ":foo2");
1289 const GURL url3(scheme1() + ":foo3"); 1295 const GURL url3(scheme1() + ":foo3");
1290 const GURL url4(scheme1() + ":foo4"); 1296 const GURL url4(scheme1() + ":foo4");
1291 const GURL url5(scheme1() + ":foo5"); 1297 const GURL url5(scheme1() + ":foo5");
1292 const GURL pending_url(scheme1() + ":pending"); 1298 const GURL pending_url(scheme1() + ":pending");
1293 const GURL default_url(scheme1() + ":default"); 1299 const GURL default_url(scheme1() + ":default");
1294 1300
1295 contents->controller()->LoadURL(url1, PageTransition::TYPED); 1301 contents->controller()->LoadURL(url1, GURL(), PageTransition::TYPED);
1296 contents->CompleteNavigationAsRenderer(0, url1); 1302 contents->CompleteNavigationAsRenderer(0, url1);
1297 contents->controller()->LoadURL(url2, PageTransition::TYPED); 1303 contents->controller()->LoadURL(url2, GURL(), PageTransition::TYPED);
1298 contents->CompleteNavigationAsRenderer(1, url2); 1304 contents->CompleteNavigationAsRenderer(1, url2);
1299 contents->controller()->LoadURL(url3, PageTransition::TYPED); 1305 contents->controller()->LoadURL(url3, GURL(), PageTransition::TYPED);
1300 contents->CompleteNavigationAsRenderer(2, url3); 1306 contents->CompleteNavigationAsRenderer(2, url3);
1301 contents->controller()->LoadURL(url4, PageTransition::TYPED); 1307 contents->controller()->LoadURL(url4, GURL(), PageTransition::TYPED);
1302 contents->CompleteNavigationAsRenderer(3, url4); 1308 contents->CompleteNavigationAsRenderer(3, url4);
1303 contents->controller()->LoadURL(url5, PageTransition::TYPED); 1309 contents->controller()->LoadURL(url5, GURL(), PageTransition::TYPED);
1304 contents->CompleteNavigationAsRenderer(4, url5); 1310 contents->CompleteNavigationAsRenderer(4, url5);
1305 1311
1306 // Remove the last entry. 1312 // Remove the last entry.
1307 contents->controller()->RemoveEntryAtIndex( 1313 contents->controller()->RemoveEntryAtIndex(
1308 contents->controller()->GetEntryCount() - 1, default_url); 1314 contents->controller()->GetEntryCount() - 1, default_url);
1309 EXPECT_EQ(4, contents->controller()->GetEntryCount()); 1315 EXPECT_EQ(4, contents->controller()->GetEntryCount());
1310 EXPECT_EQ(3, contents->controller()->GetLastCommittedEntryIndex()); 1316 EXPECT_EQ(3, contents->controller()->GetLastCommittedEntryIndex());
1311 NavigationEntry* pending_entry = contents->controller()->GetPendingEntry(); 1317 NavigationEntry* pending_entry = contents->controller()->GetPendingEntry();
1312 EXPECT_TRUE(pending_entry && pending_entry->url() == url4); 1318 EXPECT_TRUE(pending_entry && pending_entry->url() == url4);
1313 1319
1314 // Add a pending entry. 1320 // Add a pending entry.
1315 contents->controller()->LoadURL(pending_url, PageTransition::TYPED); 1321 contents->controller()->LoadURL(pending_url, GURL(), PageTransition::TYPED);
1316 // Now remove the last entry. 1322 // Now remove the last entry.
1317 contents->controller()->RemoveEntryAtIndex( 1323 contents->controller()->RemoveEntryAtIndex(
1318 contents->controller()->GetEntryCount() - 1, default_url); 1324 contents->controller()->GetEntryCount() - 1, default_url);
1319 // The pending entry should have been discarded and the last committed entry 1325 // The pending entry should have been discarded and the last committed entry
1320 // removed. 1326 // removed.
1321 EXPECT_EQ(3, contents->controller()->GetEntryCount()); 1327 EXPECT_EQ(3, contents->controller()->GetEntryCount());
1322 EXPECT_EQ(2, contents->controller()->GetLastCommittedEntryIndex()); 1328 EXPECT_EQ(2, contents->controller()->GetLastCommittedEntryIndex());
1323 pending_entry = contents->controller()->GetPendingEntry(); 1329 pending_entry = contents->controller()->GetPendingEntry();
1324 EXPECT_TRUE(pending_entry && pending_entry->url() == url3); 1330 EXPECT_TRUE(pending_entry && pending_entry->url() == url3);
1325 1331
(...skipping 21 matching lines...) Expand all
1347 TestNotificationTracker notifications; 1353 TestNotificationTracker notifications;
1348 RegisterForAllNavNotifications(&notifications, contents->controller()); 1354 RegisterForAllNavNotifications(&notifications, contents->controller());
1349 1355
1350 const GURL url0(scheme1() + ":foo0"); 1356 const GURL url0(scheme1() + ":foo0");
1351 const GURL url1(scheme1() + ":foo1"); 1357 const GURL url1(scheme1() + ":foo1");
1352 const GURL url2(scheme1() + ":foo2"); 1358 const GURL url2(scheme1() + ":foo2");
1353 const GURL url3(scheme1() + ":foo3"); 1359 const GURL url3(scheme1() + ":foo3");
1354 const GURL url4(scheme1() + ":foo4"); 1360 const GURL url4(scheme1() + ":foo4");
1355 const GURL transient_url(scheme1() + ":transient"); 1361 const GURL transient_url(scheme1() + ":transient");
1356 1362
1357 contents->controller()->LoadURL(url0, PageTransition::TYPED); 1363 contents->controller()->LoadURL(url0, GURL(), PageTransition::TYPED);
1358 contents->CompleteNavigationAsRenderer(0, url0); 1364 contents->CompleteNavigationAsRenderer(0, url0);
1359 contents->controller()->LoadURL(url1, PageTransition::TYPED); 1365 contents->controller()->LoadURL(url1, GURL(), PageTransition::TYPED);
1360 contents->CompleteNavigationAsRenderer(1, url1); 1366 contents->CompleteNavigationAsRenderer(1, url1);
1361 1367
1362 notifications.Reset(); 1368 notifications.Reset();
1363 1369
1364 // Adding a transient with no pending entry. 1370 // Adding a transient with no pending entry.
1365 NavigationEntry* transient_entry = new NavigationEntry(TAB_CONTENTS_WEB); 1371 NavigationEntry* transient_entry = new NavigationEntry(TAB_CONTENTS_WEB);
1366 transient_entry->set_url(transient_url); 1372 transient_entry->set_url(transient_url);
1367 contents->controller()->AddTransientEntry(transient_entry); 1373 contents->controller()->AddTransientEntry(transient_entry);
1368 1374
1369 // We should not have received any notifications. 1375 // We should not have received any notifications.
1370 EXPECT_EQ(0, notifications.size()); 1376 EXPECT_EQ(0, notifications.size());
1371 1377
1372 // Check our state. 1378 // Check our state.
1373 EXPECT_EQ(transient_url, contents->controller()->GetActiveEntry()->url()); 1379 EXPECT_EQ(transient_url, contents->controller()->GetActiveEntry()->url());
1374 EXPECT_EQ(contents->controller()->GetEntryCount(), 3); 1380 EXPECT_EQ(contents->controller()->GetEntryCount(), 3);
1375 EXPECT_EQ(contents->controller()->GetLastCommittedEntryIndex(), 1); 1381 EXPECT_EQ(contents->controller()->GetLastCommittedEntryIndex(), 1);
1376 EXPECT_EQ(contents->controller()->GetPendingEntryIndex(), -1); 1382 EXPECT_EQ(contents->controller()->GetPendingEntryIndex(), -1);
1377 EXPECT_TRUE(contents->controller()->GetLastCommittedEntry()); 1383 EXPECT_TRUE(contents->controller()->GetLastCommittedEntry());
1378 EXPECT_FALSE(contents->controller()->GetPendingEntry()); 1384 EXPECT_FALSE(contents->controller()->GetPendingEntry());
1379 EXPECT_TRUE(contents->controller()->CanGoBack()); 1385 EXPECT_TRUE(contents->controller()->CanGoBack());
1380 EXPECT_FALSE(contents->controller()->CanGoForward()); 1386 EXPECT_FALSE(contents->controller()->CanGoForward());
1381 EXPECT_EQ(contents->GetMaxPageID(), 1); 1387 EXPECT_EQ(contents->GetMaxPageID(), 1);
1382 1388
1383 // Navigate. 1389 // Navigate.
1384 contents->controller()->LoadURL(url2, PageTransition::TYPED); 1390 contents->controller()->LoadURL(url2, GURL(), PageTransition::TYPED);
1385 contents->CompleteNavigationAsRenderer(2, url2); 1391 contents->CompleteNavigationAsRenderer(2, url2);
1386 1392
1387 // We should have navigated, transient entry should be gone. 1393 // We should have navigated, transient entry should be gone.
1388 EXPECT_EQ(url2, contents->controller()->GetActiveEntry()->url()); 1394 EXPECT_EQ(url2, contents->controller()->GetActiveEntry()->url());
1389 EXPECT_EQ(contents->controller()->GetEntryCount(), 3); 1395 EXPECT_EQ(contents->controller()->GetEntryCount(), 3);
1390 1396
1391 // Add a transient again, then navigate with no pending entry this time. 1397 // Add a transient again, then navigate with no pending entry this time.
1392 transient_entry = new NavigationEntry(TAB_CONTENTS_WEB); 1398 transient_entry = new NavigationEntry(TAB_CONTENTS_WEB);
1393 transient_entry->set_url(transient_url); 1399 transient_entry->set_url(transient_url);
1394 contents->controller()->AddTransientEntry(transient_entry); 1400 contents->controller()->AddTransientEntry(transient_entry);
1395 EXPECT_EQ(transient_url, contents->controller()->GetActiveEntry()->url()); 1401 EXPECT_EQ(transient_url, contents->controller()->GetActiveEntry()->url());
1396 contents->CompleteNavigationAsRenderer(3, url3); 1402 contents->CompleteNavigationAsRenderer(3, url3);
1397 // Transient entry should be gone. 1403 // Transient entry should be gone.
1398 EXPECT_EQ(url3, contents->controller()->GetActiveEntry()->url()); 1404 EXPECT_EQ(url3, contents->controller()->GetActiveEntry()->url());
1399 EXPECT_EQ(contents->controller()->GetEntryCount(), 4); 1405 EXPECT_EQ(contents->controller()->GetEntryCount(), 4);
1400 1406
1401 // Initiate a navigation, add a transient then commit navigation. 1407 // Initiate a navigation, add a transient then commit navigation.
1402 contents->controller()->LoadURL(url4, PageTransition::TYPED); 1408 contents->controller()->LoadURL(url4, GURL(), PageTransition::TYPED);
1403 transient_entry = new NavigationEntry(TAB_CONTENTS_WEB); 1409 transient_entry = new NavigationEntry(TAB_CONTENTS_WEB);
1404 transient_entry->set_url(transient_url); 1410 transient_entry->set_url(transient_url);
1405 contents->controller()->AddTransientEntry(transient_entry); 1411 contents->controller()->AddTransientEntry(transient_entry);
1406 EXPECT_EQ(transient_url, contents->controller()->GetActiveEntry()->url()); 1412 EXPECT_EQ(transient_url, contents->controller()->GetActiveEntry()->url());
1407 contents->CompleteNavigationAsRenderer(4, url4); 1413 contents->CompleteNavigationAsRenderer(4, url4);
1408 EXPECT_EQ(url4, contents->controller()->GetActiveEntry()->url()); 1414 EXPECT_EQ(url4, contents->controller()->GetActiveEntry()->url());
1409 EXPECT_EQ(contents->controller()->GetEntryCount(), 5); 1415 EXPECT_EQ(contents->controller()->GetEntryCount(), 5);
1410 1416
1411 // Add a transient and go back. This should simply remove the transient. 1417 // Add a transient and go back. This should simply remove the transient.
1412 transient_entry = new NavigationEntry(TAB_CONTENTS_WEB); 1418 transient_entry = new NavigationEntry(TAB_CONTENTS_WEB);
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after
1485 EXPECT_FALSE(contents->controller()->IsURLInPageNavigation(url)); 1491 EXPECT_FALSE(contents->controller()->IsURLInPageNavigation(url));
1486 EXPECT_FALSE(contents->controller()->IsURLInPageNavigation(other_url)); 1492 EXPECT_FALSE(contents->controller()->IsURLInPageNavigation(other_url));
1487 const GURL other_url_with_ref("http://www.google.com/home.html#my_other_ref"); 1493 const GURL other_url_with_ref("http://www.google.com/home.html#my_other_ref");
1488 EXPECT_TRUE(contents->controller()->IsURLInPageNavigation( 1494 EXPECT_TRUE(contents->controller()->IsURLInPageNavigation(
1489 other_url_with_ref)); 1495 other_url_with_ref));
1490 } 1496 }
1491 1497
1492 // A basic test case. Navigates to a single url, and make sure the history 1498 // A basic test case. Navigates to a single url, and make sure the history
1493 // db matches. 1499 // db matches.
1494 TEST_F(NavigationControllerHistoryTest, Basic) { 1500 TEST_F(NavigationControllerHistoryTest, Basic) {
1495 contents->controller()->LoadURL(url0, PageTransition::LINK); 1501 contents->controller()->LoadURL(url0, GURL(), PageTransition::LINK);
1496 contents->CompleteNavigationAsRenderer(0, url0); 1502 contents->CompleteNavigationAsRenderer(0, url0);
1497 1503
1498 GetLastSession(); 1504 GetLastSession();
1499 1505
1500 helper_.AssertSingleWindowWithSingleTab(windows_, 1); 1506 helper_.AssertSingleWindowWithSingleTab(windows_, 1);
1501 helper_.AssertTabEquals(0, 0, 1, *(windows_[0]->tabs[0])); 1507 helper_.AssertTabEquals(0, 0, 1, *(windows_[0]->tabs[0]));
1502 TabNavigation nav1(0, url0, std::wstring(), std::string(), 1508 TabNavigation nav1(0, url0, std::wstring(), std::string(),
1503 PageTransition::LINK); 1509 PageTransition::LINK);
1504 helper_.AssertNavigationEquals(nav1, windows_[0]->tabs[0]->navigations[0]); 1510 helper_.AssertNavigationEquals(nav1, windows_[0]->tabs[0]->navigations[0]);
1505 } 1511 }
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
1548 1554
1549 helper_.AssertSingleWindowWithSingleTab(windows_, 2); 1555 helper_.AssertSingleWindowWithSingleTab(windows_, 2);
1550 helper_.AssertTabEquals(0, 1, 2, *(windows_[0]->tabs[0])); 1556 helper_.AssertTabEquals(0, 1, 2, *(windows_[0]->tabs[0]));
1551 1557
1552 TabNavigation nav(0, url0, std::wstring(), std::string(), 1558 TabNavigation nav(0, url0, std::wstring(), std::string(),
1553 PageTransition::LINK); 1559 PageTransition::LINK);
1554 helper_.AssertNavigationEquals(nav, windows_[0]->tabs[0]->navigations[0]); 1560 helper_.AssertNavigationEquals(nav, windows_[0]->tabs[0]->navigations[0]);
1555 nav.url = url2; 1561 nav.url = url2;
1556 helper_.AssertNavigationEquals(nav, windows_[0]->tabs[0]->navigations[1]); 1562 helper_.AssertNavigationEquals(nav, windows_[0]->tabs[0]->navigations[1]);
1557 } 1563 }
OLDNEW
« no previous file with comments | « chrome/browser/navigation_controller.cc ('k') | chrome/browser/navigation_entry.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698