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

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

Issue 10807047: Create content\public\test\test_utils.h to hold common test classes that are used by unit and brows… (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: Created 8 years, 5 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/file_path.h" 6 #include "base/file_path.h"
7 #include "base/utf_string_conversions.h" 7 #include "base/utf_string_conversions.h"
8 #include "chrome/browser/browser_process.h" 8 #include "chrome/browser/browser_process.h"
9 #include "chrome/browser/defaults.h" 9 #include "chrome/browser/defaults.h"
10 #include "chrome/browser/first_run/first_run.h" 10 #include "chrome/browser/first_run/first_run.h"
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after
81 // correspond to the given URLs. 81 // correspond to the given URLs.
82 void VerifyNavigationEntries( 82 void VerifyNavigationEntries(
83 content::NavigationController& controller, GURL url1, GURL url2) { 83 content::NavigationController& controller, GURL url1, GURL url2) {
84 ASSERT_EQ(2, controller.GetEntryCount()); 84 ASSERT_EQ(2, controller.GetEntryCount());
85 EXPECT_EQ(1, controller.GetCurrentEntryIndex()); 85 EXPECT_EQ(1, controller.GetCurrentEntryIndex());
86 EXPECT_EQ(url1, controller.GetEntryAtIndex(0)->GetURL()); 86 EXPECT_EQ(url1, controller.GetEntryAtIndex(0)->GetURL());
87 EXPECT_EQ(url2, controller.GetEntryAtIndex(1)->GetURL()); 87 EXPECT_EQ(url2, controller.GetEntryAtIndex(1)->GetURL());
88 } 88 }
89 89
90 void CloseBrowserSynchronously(Browser* browser) { 90 void CloseBrowserSynchronously(Browser* browser) {
91 ui_test_utils::WindowedNotificationObserver observer( 91 content::WindowedNotificationObserver observer(
92 chrome::NOTIFICATION_BROWSER_CLOSED, 92 chrome::NOTIFICATION_BROWSER_CLOSED,
93 content::NotificationService::AllSources()); 93 content::NotificationService::AllSources());
94 browser->window()->Close(); 94 browser->window()->Close();
95 #if defined(OS_MACOSX) 95 #if defined(OS_MACOSX)
96 // BrowserWindowController depends on the auto release pool being recycled 96 // BrowserWindowController depends on the auto release pool being recycled
97 // in the message loop to delete itself, which frees the Browser object 97 // in the message loop to delete itself, which frees the Browser object
98 // which fires this event. 98 // which fires this event.
99 AutoreleasePool()->Recycle(); 99 AutoreleasePool()->Recycle();
100 #endif 100 #endif
101 observer.Wait(); 101 observer.Wait();
(...skipping 12 matching lines...) Expand all
114 content::NotificationService::AllSources(), NULL, expected_tab_count); 114 content::NotificationService::AllSources(), NULL, expected_tab_count);
115 chrome::NewEmptyWindow(profile); 115 chrome::NewEmptyWindow(profile);
116 Browser* new_browser = window_observer.WaitForSingleNewBrowser(); 116 Browser* new_browser = window_observer.WaitForSingleNewBrowser();
117 navigation_observer.Wait(); 117 navigation_observer.Wait();
118 g_browser_process->ReleaseModule(); 118 g_browser_process->ReleaseModule();
119 119
120 return new_browser; 120 return new_browser;
121 } 121 }
122 122
123 void GoBack(Browser* browser) { 123 void GoBack(Browser* browser) {
124 ui_test_utils::WindowedNotificationObserver observer( 124 content::WindowedNotificationObserver observer(
125 content::NOTIFICATION_LOAD_STOP, 125 content::NOTIFICATION_LOAD_STOP,
126 content::NotificationService::AllSources()); 126 content::NotificationService::AllSources());
127 chrome::GoBack(browser, CURRENT_TAB); 127 chrome::GoBack(browser, CURRENT_TAB);
128 observer.Wait(); 128 observer.Wait();
129 } 129 }
130 130
131 void GoForward(Browser* browser) { 131 void GoForward(Browser* browser) {
132 ui_test_utils::WindowedNotificationObserver observer( 132 content::WindowedNotificationObserver observer(
133 content::NOTIFICATION_LOAD_STOP, 133 content::NOTIFICATION_LOAD_STOP,
134 content::NotificationService::AllSources()); 134 content::NotificationService::AllSources());
135 chrome::GoForward(browser, CURRENT_TAB); 135 chrome::GoForward(browser, CURRENT_TAB);
136 observer.Wait(); 136 observer.Wait();
137 } 137 }
138 138
139 void AssertOneWindowWithOneTab(Browser* browser) { 139 void AssertOneWindowWithOneTab(Browser* browser) {
140 ASSERT_EQ(1u, BrowserList::size()); 140 ASSERT_EQ(1u, BrowserList::size());
141 ASSERT_EQ(1, browser->tab_count()); 141 ASSERT_EQ(1, browser->tab_count());
142 } 142 }
(...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after
256 GURL url2(ui_test_utils::GetTestUrl( 256 GURL url2(ui_test_utils::GetTestUrl(
257 FilePath(FilePath::kCurrentDirectory), 257 FilePath(FilePath::kCurrentDirectory),
258 FilePath(FILE_PATH_LITERAL("title2.html")))); 258 FilePath(FILE_PATH_LITERAL("title2.html"))));
259 GURL url3(ui_test_utils::GetTestUrl( 259 GURL url3(ui_test_utils::GetTestUrl(
260 FilePath(FilePath::kCurrentDirectory), 260 FilePath(FilePath::kCurrentDirectory),
261 FilePath(FILE_PATH_LITERAL("title3.html")))); 261 FilePath(FILE_PATH_LITERAL("title3.html"))));
262 262
263 // Add and navigate three tabs. 263 // Add and navigate three tabs.
264 ui_test_utils::NavigateToURL(browser(), url1); 264 ui_test_utils::NavigateToURL(browser(), url1);
265 { 265 {
266 ui_test_utils::WindowedNotificationObserver observer( 266 content::WindowedNotificationObserver observer(
267 content::NOTIFICATION_LOAD_STOP, 267 content::NOTIFICATION_LOAD_STOP,
268 content::NotificationService::AllSources()); 268 content::NotificationService::AllSources());
269 chrome::AddSelectedTabWithURL(browser(), url2, 269 chrome::AddSelectedTabWithURL(browser(), url2,
270 content::PAGE_TRANSITION_LINK); 270 content::PAGE_TRANSITION_LINK);
271 observer.Wait(); 271 observer.Wait();
272 } 272 }
273 { 273 {
274 ui_test_utils::WindowedNotificationObserver observer( 274 content::WindowedNotificationObserver observer(
275 content::NOTIFICATION_LOAD_STOP, 275 content::NOTIFICATION_LOAD_STOP,
276 content::NotificationService::AllSources()); 276 content::NotificationService::AllSources());
277 chrome::AddSelectedTabWithURL(browser(), url3, 277 chrome::AddSelectedTabWithURL(browser(), url3,
278 content::PAGE_TRANSITION_LINK); 278 content::PAGE_TRANSITION_LINK);
279 observer.Wait(); 279 observer.Wait();
280 } 280 }
281 281
282 TabRestoreService* service = 282 TabRestoreService* service =
283 TabRestoreServiceFactory::GetForProfile(browser()->profile()); 283 TabRestoreServiceFactory::GetForProfile(browser()->profile());
284 service->ClearEntries(); 284 service->ClearEntries();
(...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after
387 tab.tab_visual_index = 0; 387 tab.tab_visual_index = 0;
388 tab.current_navigation_index = 1; 388 tab.current_navigation_index = 1;
389 tab.pinned = false; 389 tab.pinned = false;
390 tab.navigations.push_back(nav1); 390 tab.navigations.push_back(nav1);
391 tab.navigations.push_back(nav2); 391 tab.navigations.push_back(nav2);
392 392
393 ASSERT_EQ(1, browser()->tab_count()); 393 ASSERT_EQ(1, browser()->tab_count());
394 394
395 // Restore in the current tab. 395 // Restore in the current tab.
396 { 396 {
397 ui_test_utils::WindowedNotificationObserver observer( 397 content::WindowedNotificationObserver observer(
398 content::NOTIFICATION_LOAD_STOP, 398 content::NOTIFICATION_LOAD_STOP,
399 content::NotificationService::AllSources()); 399 content::NotificationService::AllSources());
400 SessionRestore::RestoreForeignSessionTab( 400 SessionRestore::RestoreForeignSessionTab(
401 chrome::GetActiveWebContents(browser()), tab, CURRENT_TAB); 401 chrome::GetActiveWebContents(browser()), tab, CURRENT_TAB);
402 observer.Wait(); 402 observer.Wait();
403 } 403 }
404 ASSERT_EQ(1, browser()->tab_count()); 404 ASSERT_EQ(1, browser()->tab_count());
405 VerifyNavigationEntries( 405 VerifyNavigationEntries(
406 chrome::GetWebContentsAt(browser(), 0)->GetController(), url1, url2); 406 chrome::GetWebContentsAt(browser(), 0)->GetController(), url1, url2);
407 407
408 // Restore in a new tab. 408 // Restore in a new tab.
409 { 409 {
410 ui_test_utils::WindowedNotificationObserver observer( 410 content::WindowedNotificationObserver observer(
411 content::NOTIFICATION_LOAD_STOP, 411 content::NOTIFICATION_LOAD_STOP,
412 content::NotificationService::AllSources()); 412 content::NotificationService::AllSources());
413 SessionRestore::RestoreForeignSessionTab( 413 SessionRestore::RestoreForeignSessionTab(
414 chrome::GetActiveWebContents(browser()), tab, NEW_BACKGROUND_TAB); 414 chrome::GetActiveWebContents(browser()), tab, NEW_BACKGROUND_TAB);
415 observer.Wait(); 415 observer.Wait();
416 } 416 }
417 ASSERT_EQ(2, browser()->tab_count()); 417 ASSERT_EQ(2, browser()->tab_count());
418 ASSERT_EQ(0, browser()->active_index()); 418 ASSERT_EQ(0, browser()->active_index());
419 VerifyNavigationEntries( 419 VerifyNavigationEntries(
420 chrome::GetWebContentsAt(browser(), 1)->GetController(), url1, url2); 420 chrome::GetWebContentsAt(browser(), 1)->GetController(), url1, url2);
(...skipping 359 matching lines...) Expand 10 before | Expand all | Expand 10 after
780 ASSERT_EQ(1u, BrowserList::size()); 780 ASSERT_EQ(1u, BrowserList::size());
781 ASSERT_EQ(url1_, chrome::GetActiveWebContents(new_browser)->GetURL()); 781 ASSERT_EQ(url1_, chrome::GetActiveWebContents(new_browser)->GetURL());
782 const content::NavigationController& new_controller = 782 const content::NavigationController& new_controller =
783 chrome::GetActiveWebContents(new_browser)->GetController(); 783 chrome::GetActiveWebContents(new_browser)->GetController();
784 ASSERT_TRUE(new_controller.GetSessionStorageNamespace()); 784 ASSERT_TRUE(new_controller.GetSessionStorageNamespace());
785 std::string restored_session_storage_persistent_id = 785 std::string restored_session_storage_persistent_id =
786 new_controller.GetSessionStorageNamespace()->persistent_id(); 786 new_controller.GetSessionStorageNamespace()->persistent_id();
787 EXPECT_EQ(session_storage_persistent_id, 787 EXPECT_EQ(session_storage_persistent_id,
788 restored_session_storage_persistent_id); 788 restored_session_storage_persistent_id);
789 } 789 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698