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

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

Issue 14497003: Moves TabNavigation into components/sessions and renames (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Really remove webkit_support Created 7 years, 7 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 "base/command_line.h" 5 #include "base/command_line.h"
6 #include "base/files/file_path.h" 6 #include "base/files/file_path.h"
7 #include "base/time.h" 7 #include "base/time.h"
8 #include "base/utf_string_conversions.h" 8 #include "base/utf_string_conversions.h"
9 #include "chrome/browser/browser_process.h" 9 #include "chrome/browser/browser_process.h"
10 #include "chrome/browser/defaults.h" 10 #include "chrome/browser/defaults.h"
11 #include "chrome/browser/first_run/first_run.h" 11 #include "chrome/browser/first_run/first_run.h"
12 #include "chrome/browser/profiles/profile.h" 12 #include "chrome/browser/profiles/profile.h"
13 #include "chrome/browser/profiles/profile_manager.h" 13 #include "chrome/browser/profiles/profile_manager.h"
14 #include "chrome/browser/sessions/session_restore.h" 14 #include "chrome/browser/sessions/session_restore.h"
15 #include "chrome/browser/sessions/session_service.h" 15 #include "chrome/browser/sessions/session_service.h"
16 #include "chrome/browser/sessions/session_service_factory.h" 16 #include "chrome/browser/sessions/session_service_factory.h"
17 #include "chrome/browser/sessions/session_service_test_helper.h" 17 #include "chrome/browser/sessions/session_service_test_helper.h"
18 #include "chrome/browser/sessions/session_types.h" 18 #include "chrome/browser/sessions/session_types.h"
19 #include "chrome/browser/sessions/session_types_test_helper.h"
20 #include "chrome/browser/sessions/tab_restore_service.h" 19 #include "chrome/browser/sessions/tab_restore_service.h"
21 #include "chrome/browser/sessions/tab_restore_service_factory.h" 20 #include "chrome/browser/sessions/tab_restore_service_factory.h"
22 #include "chrome/browser/ui/browser.h" 21 #include "chrome/browser/ui/browser.h"
23 #include "chrome/browser/ui/browser_commands.h" 22 #include "chrome/browser/ui/browser_commands.h"
24 #include "chrome/browser/ui/browser_list.h" 23 #include "chrome/browser/ui/browser_list.h"
25 #include "chrome/browser/ui/browser_tabstrip.h" 24 #include "chrome/browser/ui/browser_tabstrip.h"
26 #include "chrome/browser/ui/browser_window.h" 25 #include "chrome/browser/ui/browser_window.h"
27 #include "chrome/browser/ui/host_desktop.h" 26 #include "chrome/browser/ui/host_desktop.h"
28 #include "chrome/browser/ui/tabs/tab_strip_model.h" 27 #include "chrome/browser/ui/tabs/tab_strip_model.h"
29 #include "chrome/common/chrome_notification_types.h" 28 #include "chrome/common/chrome_notification_types.h"
30 #include "chrome/common/chrome_switches.h" 29 #include "chrome/common/chrome_switches.h"
31 #include "chrome/common/url_constants.h" 30 #include "chrome/common/url_constants.h"
32 #include "chrome/test/base/in_process_browser_test.h" 31 #include "chrome/test/base/in_process_browser_test.h"
33 #include "chrome/test/base/ui_test_utils.h" 32 #include "chrome/test/base/ui_test_utils.h"
33 #include "components/sessions/serialized_navigation_entry_test_helper.h"
34 #include "content/public/browser/navigation_controller.h" 34 #include "content/public/browser/navigation_controller.h"
35 #include "content/public/browser/navigation_entry.h" 35 #include "content/public/browser/navigation_entry.h"
36 #include "content/public/browser/notification_service.h" 36 #include "content/public/browser/notification_service.h"
37 #include "content/public/browser/notification_types.h" 37 #include "content/public/browser/notification_types.h"
38 #include "content/public/browser/render_process_host.h" 38 #include "content/public/browser/render_process_host.h"
39 #include "content/public/browser/render_view_host.h" 39 #include "content/public/browser/render_view_host.h"
40 #include "content/public/browser/web_contents.h" 40 #include "content/public/browser/web_contents.h"
41 #include "content/public/common/bindings_policy.h" 41 #include "content/public/common/bindings_policy.h"
42 #include "content/public/common/page_transition_types.h" 42 #include "content/public/common/page_transition_types.h"
43 #include "content/public/test/test_navigation_observer.h" 43 #include "content/public/test/test_navigation_observer.h"
44 #include "sync/protocol/session_specifics.pb.h" 44 #include "sync/protocol/session_specifics.pb.h"
45 45
46 using sessions::SerializedNavigationEntry;
47 using sessions::SerializedNavigationEntryTestHelper;
48
46 #if defined(OS_MACOSX) 49 #if defined(OS_MACOSX)
47 #include "base/mac/scoped_nsautorelease_pool.h" 50 #include "base/mac/scoped_nsautorelease_pool.h"
48 #endif 51 #endif
49 52
50 class SessionRestoreTest : public InProcessBrowserTest { 53 class SessionRestoreTest : public InProcessBrowserTest {
51 public: 54 public:
52 SessionRestoreTest() 55 SessionRestoreTest()
53 : native_browser_list(BrowserList::GetInstance( 56 : native_browser_list(BrowserList::GetInstance(
54 chrome::HOST_DESKTOP_TYPE_NATIVE)) { 57 chrome::HOST_DESKTOP_TYPE_NATIVE)) {
55 } 58 }
(...skipping 281 matching lines...) Expand 10 before | Expand all | Expand 10 after
337 EXPECT_EQ(3U, window->tabs.size()); 340 EXPECT_EQ(3U, window->tabs.size());
338 341
339 // Find the SessionID for entry2. Since the session service was destroyed, 342 // Find the SessionID for entry2. Since the session service was destroyed,
340 // there is no guarantee that the SessionID for the tab has remained the same. 343 // there is no guarantee that the SessionID for the tab has remained the same.
341 base::Time timestamp; 344 base::Time timestamp;
342 for (std::vector<TabRestoreService::Tab>::const_iterator it = 345 for (std::vector<TabRestoreService::Tab>::const_iterator it =
343 window->tabs.begin(); it != window->tabs.end(); ++it) { 346 window->tabs.begin(); it != window->tabs.end(); ++it) {
344 const TabRestoreService::Tab& tab = *it; 347 const TabRestoreService::Tab& tab = *it;
345 // If this tab held url2, then restore this single tab. 348 // If this tab held url2, then restore this single tab.
346 if (tab.navigations[0].virtual_url() == url2) { 349 if (tab.navigations[0].virtual_url() == url2) {
347 timestamp = SessionTypesTestHelper::GetTimestamp(tab.navigations[0]); 350 timestamp = tab.navigations[0].timestamp();
348 service->RestoreEntryById(NULL, tab.id, host_desktop_type, UNKNOWN); 351 service->RestoreEntryById(NULL, tab.id, host_desktop_type, UNKNOWN);
349 break; 352 break;
350 } 353 }
351 } 354 }
352 EXPECT_FALSE(timestamp.is_null()); 355 EXPECT_FALSE(timestamp.is_null());
353 356
354 // Make sure that the restored tab is removed from the service. 357 // Make sure that the restored tab is removed from the service.
355 ASSERT_EQ(1U, service->entries().size()); 358 ASSERT_EQ(1U, service->entries().size());
356 ASSERT_EQ(TabRestoreService::WINDOW, service->entries().front()->type); 359 ASSERT_EQ(TabRestoreService::WINDOW, service->entries().front()->type);
357 window = static_cast<TabRestoreService::Window*>(service->entries().front()); 360 window = static_cast<TabRestoreService::Window*>(service->entries().front());
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after
447 EXPECT_EQ(url2, controller.GetEntryAtIndex(1)->GetURL()); 450 EXPECT_EQ(url2, controller.GetEntryAtIndex(1)->GetURL());
448 EXPECT_TRUE(controller.GetEntryAtIndex(0)->GetTimestamp().is_null()); 451 EXPECT_TRUE(controller.GetEntryAtIndex(0)->GetTimestamp().is_null());
449 EXPECT_FALSE(controller.GetEntryAtIndex(1)->GetTimestamp().is_null()); 452 EXPECT_FALSE(controller.GetEntryAtIndex(1)->GetTimestamp().is_null());
450 } 453 }
451 454
452 } // namespace 455 } // namespace
453 456
454 IN_PROC_BROWSER_TEST_F(SessionRestoreTest, RestoreForeignTab) { 457 IN_PROC_BROWSER_TEST_F(SessionRestoreTest, RestoreForeignTab) {
455 GURL url1("http://google.com"); 458 GURL url1("http://google.com");
456 GURL url2("http://google2.com"); 459 GURL url2("http://google2.com");
457 TabNavigation nav1 = 460 SerializedNavigationEntry nav1 =
458 SessionTypesTestHelper::CreateNavigation(url1.spec(), "one"); 461 SerializedNavigationEntryTestHelper::CreateNavigation(url1.spec(), "one");
459 TabNavigation nav2 = 462 SerializedNavigationEntry nav2 =
460 SessionTypesTestHelper::CreateNavigation(url2.spec(), "two"); 463 SerializedNavigationEntryTestHelper::CreateNavigation(url2.spec(), "two");
461 464
462 // Set up the restore data. 465 // Set up the restore data.
463 sync_pb::SessionTab sync_data; 466 sync_pb::SessionTab sync_data;
464 sync_data.set_tab_visual_index(0); 467 sync_data.set_tab_visual_index(0);
465 sync_data.set_current_navigation_index(1); 468 sync_data.set_current_navigation_index(1);
466 sync_data.set_pinned(false); 469 sync_data.set_pinned(false);
467 sync_data.add_navigation()->CopyFrom(nav1.ToSyncData()); 470 sync_data.add_navigation()->CopyFrom(nav1.ToSyncData());
468 sync_data.add_navigation()->CopyFrom(nav2.ToSyncData()); 471 sync_data.add_navigation()->CopyFrom(nav2.ToSyncData());
469 472
470 SessionTab tab; 473 SessionTab tab;
471 tab.SetFromSyncData(sync_data, base::Time::Now()); 474 tab.SetFromSyncData(sync_data, base::Time::Now());
472 EXPECT_EQ(2U, tab.navigations.size()); 475 EXPECT_EQ(2U, tab.navigations.size());
473 for (size_t i = 0; i < tab.navigations.size(); ++i) { 476 for (size_t i = 0; i < tab.navigations.size(); ++i)
474 EXPECT_TRUE( 477 EXPECT_TRUE(tab.navigations[i].timestamp().is_null());
475 SessionTypesTestHelper::GetTimestamp(tab.navigations[i]).is_null());
476 }
477 478
478 ASSERT_EQ(1, browser()->tab_strip_model()->count()); 479 ASSERT_EQ(1, browser()->tab_strip_model()->count());
479 480
480 // Restore in the current tab. 481 // Restore in the current tab.
481 { 482 {
482 content::WindowedNotificationObserver observer( 483 content::WindowedNotificationObserver observer(
483 content::NOTIFICATION_LOAD_STOP, 484 content::NOTIFICATION_LOAD_STOP,
484 content::NotificationService::AllSources()); 485 content::NotificationService::AllSources());
485 SessionRestore::RestoreForeignSessionTab( 486 SessionRestore::RestoreForeignSessionTab(
486 browser()->tab_strip_model()->GetActiveWebContents(), tab, CURRENT_TAB); 487 browser()->tab_strip_model()->GetActiveWebContents(), tab, CURRENT_TAB);
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
525 web_contents = new_browser->tab_strip_model()->GetWebContentsAt(0); 526 web_contents = new_browser->tab_strip_model()->GetWebContentsAt(0);
526 VerifyNavigationEntries(web_contents->GetController(), url1, url2); 527 VerifyNavigationEntries(web_contents->GetController(), url1, url2);
527 ASSERT_TRUE(web_contents->GetUserAgentOverride().empty()); 528 ASSERT_TRUE(web_contents->GetUserAgentOverride().empty());
528 } 529 }
529 530
530 IN_PROC_BROWSER_TEST_F(SessionRestoreTest, RestoreForeignSession) { 531 IN_PROC_BROWSER_TEST_F(SessionRestoreTest, RestoreForeignSession) {
531 Profile* profile = browser()->profile(); 532 Profile* profile = browser()->profile();
532 533
533 GURL url1("http://google.com"); 534 GURL url1("http://google.com");
534 GURL url2("http://google2.com"); 535 GURL url2("http://google2.com");
535 TabNavigation nav1 = 536 SerializedNavigationEntry nav1 =
536 SessionTypesTestHelper::CreateNavigation(url1.spec(), "one"); 537 SerializedNavigationEntryTestHelper::CreateNavigation(url1.spec(), "one");
537 TabNavigation nav2 = 538 SerializedNavigationEntry nav2 =
538 SessionTypesTestHelper::CreateNavigation(url2.spec(), "two"); 539 SerializedNavigationEntryTestHelper::CreateNavigation(url2.spec(), "two");
539 SessionTypesTestHelper::SetIsOverridingUserAgent(&nav2, true); 540 SerializedNavigationEntryTestHelper::SetIsOverridingUserAgent(true, &nav2);
540 541
541 // Set up the restore data -- one window with two tabs. 542 // Set up the restore data -- one window with two tabs.
542 std::vector<const SessionWindow*> session; 543 std::vector<const SessionWindow*> session;
543 SessionWindow window; 544 SessionWindow window;
544 SessionTab tab1; 545 SessionTab tab1;
545 { 546 {
546 sync_pb::SessionTab sync_data; 547 sync_pb::SessionTab sync_data;
547 sync_data.set_tab_visual_index(0); 548 sync_data.set_tab_visual_index(0);
548 sync_data.set_current_navigation_index(0); 549 sync_data.set_current_navigation_index(0);
549 sync_data.set_pinned(true); 550 sync_data.set_pinned(true);
(...skipping 495 matching lines...) Expand 10 before | Expand all | Expand 10 after
1045 content::NavigationController* controller = 1046 content::NavigationController* controller =
1046 &browser()->tab_strip_model()->GetActiveWebContents()->GetController(); 1047 &browser()->tab_strip_model()->GetActiveWebContents()->GetController();
1047 EXPECT_TRUE( 1048 EXPECT_TRUE(
1048 controller->GetDefaultSessionStorageNamespace()->should_persist()); 1049 controller->GetDefaultSessionStorageNamespace()->should_persist());
1049 1050
1050 // Quit and restore. Check that no extra tabs were created. 1051 // Quit and restore. Check that no extra tabs were created.
1051 Browser* new_browser = QuitBrowserAndRestore(browser(), 1); 1052 Browser* new_browser = QuitBrowserAndRestore(browser(), 1);
1052 ASSERT_EQ(1u, native_browser_list->size()); 1053 ASSERT_EQ(1u, native_browser_list->size());
1053 EXPECT_EQ(1, new_browser->tab_strip_model()->count()); 1054 EXPECT_EQ(1, new_browser->tab_strip_model()->count());
1054 } 1055 }
OLDNEW
« no previous file with comments | « chrome/browser/sessions/session_restore_android.cc ('k') | chrome/browser/sessions/session_service.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698