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

Side by Side Diff: chrome/browser/sessions/session_restore_browsertest.cc

Issue 21656002: Return webcontents and add in test. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 7 years, 4 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) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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 <vector>
6
5 #include "base/command_line.h" 7 #include "base/command_line.h"
6 #include "base/files/file_path.h" 8 #include "base/files/file_path.h"
7 #include "base/process/launch.h" 9 #include "base/process/launch.h"
8 #include "base/strings/utf_string_conversions.h" 10 #include "base/strings/utf_string_conversions.h"
9 #include "base/time/time.h" 11 #include "base/time/time.h"
10 #include "chrome/browser/browser_process.h" 12 #include "chrome/browser/browser_process.h"
11 #include "chrome/browser/chrome_notification_types.h" 13 #include "chrome/browser/chrome_notification_types.h"
12 #include "chrome/browser/defaults.h" 14 #include "chrome/browser/defaults.h"
13 #include "chrome/browser/first_run/first_run.h" 15 #include "chrome/browser/first_run/first_run.h"
14 #include "chrome/browser/profiles/profile.h" 16 #include "chrome/browser/profiles/profile.h"
(...skipping 334 matching lines...) Expand 10 before | Expand all | Expand 10 after
349 351
350 // Find the SessionID for entry2. Since the session service was destroyed, 352 // Find the SessionID for entry2. Since the session service was destroyed,
351 // there is no guarantee that the SessionID for the tab has remained the same. 353 // there is no guarantee that the SessionID for the tab has remained the same.
352 base::Time timestamp; 354 base::Time timestamp;
353 for (std::vector<TabRestoreService::Tab>::const_iterator it = 355 for (std::vector<TabRestoreService::Tab>::const_iterator it =
354 window->tabs.begin(); it != window->tabs.end(); ++it) { 356 window->tabs.begin(); it != window->tabs.end(); ++it) {
355 const TabRestoreService::Tab& tab = *it; 357 const TabRestoreService::Tab& tab = *it;
356 // If this tab held url2, then restore this single tab. 358 // If this tab held url2, then restore this single tab.
357 if (tab.navigations[0].virtual_url() == url2) { 359 if (tab.navigations[0].virtual_url() == url2) {
358 timestamp = tab.navigations[0].timestamp(); 360 timestamp = tab.navigations[0].timestamp();
359 service->RestoreEntryById(NULL, tab.id, host_desktop_type, UNKNOWN); 361 std::vector<content::WebContents*> content =
362 service->RestoreEntryById(NULL, tab.id, host_desktop_type, UNKNOWN);
363 ASSERT_EQ(1U, content.size());
364 ASSERT_TRUE(content[0]);
365 EXPECT_EQ(url2, content[0]->GetURL());
360 break; 366 break;
361 } 367 }
362 } 368 }
363 EXPECT_FALSE(timestamp.is_null()); 369 EXPECT_FALSE(timestamp.is_null());
364 370
365 // Make sure that the restored tab is removed from the service. 371 // Make sure that the restored tab is removed from the service.
366 ASSERT_EQ(1U, service->entries().size()); 372 ASSERT_EQ(1U, service->entries().size());
367 ASSERT_EQ(TabRestoreService::WINDOW, service->entries().front()->type); 373 ASSERT_EQ(TabRestoreService::WINDOW, service->entries().front()->type);
368 window = static_cast<TabRestoreService::Window*>(service->entries().front()); 374 window = static_cast<TabRestoreService::Window*>(service->entries().front());
369 EXPECT_EQ(2U, window->tabs.size()); 375 EXPECT_EQ(2U, window->tabs.size());
(...skipping 27 matching lines...) Expand all
397 // Close the window. 403 // Close the window.
398 browser()->window()->Close(); 404 browser()->window()->Close();
399 405
400 // Expect the window to be converted to a tab by the TRS. 406 // Expect the window to be converted to a tab by the TRS.
401 EXPECT_EQ(1U, service->entries().size()); 407 EXPECT_EQ(1U, service->entries().size());
402 ASSERT_EQ(TabRestoreService::TAB, service->entries().front()->type); 408 ASSERT_EQ(TabRestoreService::TAB, service->entries().front()->type);
403 const TabRestoreService::Tab* tab = 409 const TabRestoreService::Tab* tab =
404 static_cast<TabRestoreService::Tab*>(service->entries().front()); 410 static_cast<TabRestoreService::Tab*>(service->entries().front());
405 411
406 // Restore the tab. 412 // Restore the tab.
407 service->RestoreEntryById(NULL, tab->id, host_desktop_type, UNKNOWN); 413 std::vector<content::WebContents*> content =
414 service->RestoreEntryById(NULL, tab->id, host_desktop_type, UNKNOWN);
415 ASSERT_EQ(1U, content.size());
416 ASSERT_TRUE(content[0]);
417 EXPECT_EQ(url, content[0]->GetURL());
408 418
409 // Make sure the restore was successful. 419 // Make sure the restore was successful.
410 EXPECT_EQ(0U, service->entries().size()); 420 EXPECT_EQ(0U, service->entries().size());
411 } 421 }
412 422
413 #if !defined(OS_CHROMEOS) 423 #if !defined(OS_CHROMEOS)
414 // This test does not apply to ChromeOS as ChromeOS does not do session 424 // This test does not apply to ChromeOS as ChromeOS does not do session
415 // restore when a new window is open. 425 // restore when a new window is open.
416 426
417 // Verifies we remember the last browser window when closing the last 427 // Verifies we remember the last browser window when closing the last
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after
480 490
481 SessionTab tab; 491 SessionTab tab;
482 tab.SetFromSyncData(sync_data, base::Time::Now()); 492 tab.SetFromSyncData(sync_data, base::Time::Now());
483 EXPECT_EQ(2U, tab.navigations.size()); 493 EXPECT_EQ(2U, tab.navigations.size());
484 for (size_t i = 0; i < tab.navigations.size(); ++i) 494 for (size_t i = 0; i < tab.navigations.size(); ++i)
485 EXPECT_TRUE(tab.navigations[i].timestamp().is_null()); 495 EXPECT_TRUE(tab.navigations[i].timestamp().is_null());
486 496
487 ASSERT_EQ(1, browser()->tab_strip_model()->count()); 497 ASSERT_EQ(1, browser()->tab_strip_model()->count());
488 498
489 // Restore in the current tab. 499 // Restore in the current tab.
500 content::WebContents* tab_content = NULL;
490 { 501 {
491 content::WindowedNotificationObserver observer( 502 content::WindowedNotificationObserver observer(
492 content::NOTIFICATION_LOAD_STOP, 503 content::NOTIFICATION_LOAD_STOP,
493 content::NotificationService::AllSources()); 504 content::NotificationService::AllSources());
494 SessionRestore::RestoreForeignSessionTab( 505 tab_content = SessionRestore::RestoreForeignSessionTab(
495 browser()->tab_strip_model()->GetActiveWebContents(), tab, CURRENT_TAB); 506 browser()->tab_strip_model()->GetActiveWebContents(), tab, CURRENT_TAB);
496 observer.Wait(); 507 observer.Wait();
497 } 508 }
498 ASSERT_EQ(1, browser()->tab_strip_model()->count()); 509 ASSERT_EQ(1, browser()->tab_strip_model()->count());
499 content::WebContents* web_contents = 510 content::WebContents* web_contents =
500 browser()->tab_strip_model()->GetWebContentsAt(0); 511 browser()->tab_strip_model()->GetWebContentsAt(0);
501 VerifyNavigationEntries(web_contents->GetController(), url1, url2); 512 VerifyNavigationEntries(web_contents->GetController(), url1, url2);
502 ASSERT_TRUE(web_contents->GetUserAgentOverride().empty()); 513 ASSERT_TRUE(web_contents->GetUserAgentOverride().empty());
514 ASSERT_TRUE(tab_content);
515 ASSERT_EQ(url2, tab_content->GetURL());
503 516
504 // Restore in a new tab. 517 // Restore in a new tab.
518 tab_content = NULL;
505 { 519 {
506 content::WindowedNotificationObserver observer( 520 content::WindowedNotificationObserver observer(
507 content::NOTIFICATION_LOAD_STOP, 521 content::NOTIFICATION_LOAD_STOP,
508 content::NotificationService::AllSources()); 522 content::NotificationService::AllSources());
509 SessionRestore::RestoreForeignSessionTab( 523 tab_content = SessionRestore::RestoreForeignSessionTab(
510 browser()->tab_strip_model()->GetActiveWebContents(), 524 browser()->tab_strip_model()->GetActiveWebContents(),
511 tab, NEW_BACKGROUND_TAB); 525 tab, NEW_BACKGROUND_TAB);
512 observer.Wait(); 526 observer.Wait();
513 } 527 }
514 ASSERT_EQ(2, browser()->tab_strip_model()->count()); 528 ASSERT_EQ(2, browser()->tab_strip_model()->count());
515 ASSERT_EQ(0, browser()->tab_strip_model()->active_index()); 529 ASSERT_EQ(0, browser()->tab_strip_model()->active_index());
516 web_contents = browser()->tab_strip_model()->GetWebContentsAt(1); 530 web_contents = browser()->tab_strip_model()->GetWebContentsAt(1);
517 VerifyNavigationEntries(web_contents->GetController(), url1, url2); 531 VerifyNavigationEntries(web_contents->GetController(), url1, url2);
518 ASSERT_TRUE(web_contents->GetUserAgentOverride().empty()); 532 ASSERT_TRUE(web_contents->GetUserAgentOverride().empty());
533 ASSERT_TRUE(tab_content);
534 ASSERT_EQ(url2, tab_content->GetURL());
519 535
520 // Restore in a new window. 536 // Restore in a new window.
521 Browser* new_browser = NULL; 537 Browser* new_browser = NULL;
538 tab_content = NULL;
522 { 539 {
523 ui_test_utils::BrowserAddedObserver browser_observer; 540 ui_test_utils::BrowserAddedObserver browser_observer;
524 content::WindowedNotificationObserver observer( 541 content::WindowedNotificationObserver observer(
525 content::NOTIFICATION_LOAD_STOP, 542 content::NOTIFICATION_LOAD_STOP,
526 content::NotificationService::AllSources()); 543 content::NotificationService::AllSources());
527 SessionRestore::RestoreForeignSessionTab( 544 tab_content = SessionRestore::RestoreForeignSessionTab(
528 browser()->tab_strip_model()->GetActiveWebContents(), tab, NEW_WINDOW); 545 browser()->tab_strip_model()->GetActiveWebContents(), tab, NEW_WINDOW);
529 new_browser = browser_observer.WaitForSingleNewBrowser(); 546 new_browser = browser_observer.WaitForSingleNewBrowser();
530 observer.Wait(); 547 observer.Wait();
531 } 548 }
532 549
533 ASSERT_EQ(1, new_browser->tab_strip_model()->count()); 550 ASSERT_EQ(1, new_browser->tab_strip_model()->count());
534 web_contents = new_browser->tab_strip_model()->GetWebContentsAt(0); 551 web_contents = new_browser->tab_strip_model()->GetWebContentsAt(0);
535 VerifyNavigationEntries(web_contents->GetController(), url1, url2); 552 VerifyNavigationEntries(web_contents->GetController(), url1, url2);
536 ASSERT_TRUE(web_contents->GetUserAgentOverride().empty()); 553 ASSERT_TRUE(web_contents->GetUserAgentOverride().empty());
554 ASSERT_TRUE(tab_content);
555 ASSERT_EQ(url2, tab_content->GetURL());
537 } 556 }
538 557
539 IN_PROC_BROWSER_TEST_F(SessionRestoreTest, RestoreForeignSession) { 558 IN_PROC_BROWSER_TEST_F(SessionRestoreTest, RestoreForeignSession) {
540 Profile* profile = browser()->profile(); 559 Profile* profile = browser()->profile();
541 560
542 GURL url1("http://google.com"); 561 GURL url1("http://google.com");
543 GURL url2("http://google2.com"); 562 GURL url2("http://google2.com");
544 SerializedNavigationEntry nav1 = 563 SerializedNavigationEntry nav1 =
545 SerializedNavigationEntryTestHelper::CreateNavigation(url1.spec(), "one"); 564 SerializedNavigationEntryTestHelper::CreateNavigation(url1.spec(), "one");
546 SerializedNavigationEntry nav2 = 565 SerializedNavigationEntry nav2 =
(...skipping 20 matching lines...) Expand all
567 sync_data.set_tab_visual_index(1); 586 sync_data.set_tab_visual_index(1);
568 sync_data.set_current_navigation_index(0); 587 sync_data.set_current_navigation_index(0);
569 sync_data.set_pinned(false); 588 sync_data.set_pinned(false);
570 sync_data.add_navigation()->CopyFrom(nav2.ToSyncData()); 589 sync_data.add_navigation()->CopyFrom(nav2.ToSyncData());
571 tab2.SetFromSyncData(sync_data, base::Time::Now()); 590 tab2.SetFromSyncData(sync_data, base::Time::Now());
572 } 591 }
573 window.tabs.push_back(&tab2); 592 window.tabs.push_back(&tab2);
574 593
575 session.push_back(static_cast<const SessionWindow*>(&window)); 594 session.push_back(static_cast<const SessionWindow*>(&window));
576 ui_test_utils::BrowserAddedObserver window_observer; 595 ui_test_utils::BrowserAddedObserver window_observer;
577 SessionRestore::RestoreForeignSessionWindows( 596 std::vector<Browser*> browsers =
578 profile, browser()->host_desktop_type(), session.begin(), session.end()); 597 SessionRestore::RestoreForeignSessionWindows(
598 profile, browser()->host_desktop_type(), session.begin(),
599 session.end());
579 Browser* new_browser = window_observer.WaitForSingleNewBrowser(); 600 Browser* new_browser = window_observer.WaitForSingleNewBrowser();
580 ASSERT_TRUE(new_browser); 601 ASSERT_TRUE(new_browser);
581 ASSERT_EQ(2u, active_browser_list_->size()); 602 ASSERT_EQ(2u, active_browser_list_->size());
582 ASSERT_EQ(2, new_browser->tab_strip_model()->count()); 603 ASSERT_EQ(2, new_browser->tab_strip_model()->count());
583 604
605 ASSERT_EQ(1u, browsers.size());
606 ASSERT_TRUE(browsers[0]);
607 ASSERT_EQ(2, browsers[0]->tab_strip_model()->count());
608
584 content::WebContents* web_contents_1 = 609 content::WebContents* web_contents_1 =
585 new_browser->tab_strip_model()->GetWebContentsAt(0); 610 new_browser->tab_strip_model()->GetWebContentsAt(0);
586 content::WebContents* web_contents_2 = 611 content::WebContents* web_contents_2 =
587 new_browser->tab_strip_model()->GetWebContentsAt(1); 612 new_browser->tab_strip_model()->GetWebContentsAt(1);
588 ASSERT_EQ(url1, web_contents_1->GetURL()); 613 ASSERT_EQ(url1, web_contents_1->GetURL());
589 ASSERT_EQ(url2, web_contents_2->GetURL()); 614 ASSERT_EQ(url2, web_contents_2->GetURL());
590 615
591 // Check user agent override state. 616 // Check user agent override state.
592 ASSERT_TRUE(web_contents_1->GetUserAgentOverride().empty()); 617 ASSERT_TRUE(web_contents_1->GetUserAgentOverride().empty());
593 ASSERT_TRUE(web_contents_2->GetUserAgentOverride().empty()); 618 ASSERT_TRUE(web_contents_2->GetUserAgentOverride().empty());
(...skipping 526 matching lines...) Expand 10 before | Expand all | Expand 10 after
1120 content::NavigationController* controller = 1145 content::NavigationController* controller =
1121 &browser()->tab_strip_model()->GetActiveWebContents()->GetController(); 1146 &browser()->tab_strip_model()->GetActiveWebContents()->GetController();
1122 EXPECT_TRUE( 1147 EXPECT_TRUE(
1123 controller->GetDefaultSessionStorageNamespace()->should_persist()); 1148 controller->GetDefaultSessionStorageNamespace()->should_persist());
1124 1149
1125 // Quit and restore. Check that no extra tabs were created. 1150 // Quit and restore. Check that no extra tabs were created.
1126 Browser* new_browser = QuitBrowserAndRestore(browser(), 1); 1151 Browser* new_browser = QuitBrowserAndRestore(browser(), 1);
1127 ASSERT_EQ(1u, active_browser_list_->size()); 1152 ASSERT_EQ(1u, active_browser_list_->size());
1128 EXPECT_EQ(1, new_browser->tab_strip_model()->count()); 1153 EXPECT_EQ(1, new_browser->tab_strip_model()->count());
1129 } 1154 }
OLDNEW
« no previous file with comments | « chrome/browser/sessions/session_restore_android.cc ('k') | chrome/browser/sessions/tab_restore_service.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698