OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 "chrome/browser/browser_process.h" |
| 6 #include "chrome/browser/browser_shutdown.h" |
| 7 #include "chrome/browser/prefs/pref_service.h" |
5 #include "chrome/browser/printing/background_printing_manager.h" | 8 #include "chrome/browser/printing/background_printing_manager.h" |
| 9 #include "chrome/browser/profiles/profile_manager.h" |
6 #include "chrome/browser/ui/browser_list.h" | 10 #include "chrome/browser/ui/browser_list.h" |
7 #include "chrome/browser/ui/tab_contents/tab_contents_wrapper.h" | 11 #include "chrome/browser/ui/tab_contents/tab_contents_wrapper.h" |
| 12 #include "chrome/common/pref_names.h" |
8 #include "chrome/common/url_constants.h" | 13 #include "chrome/common/url_constants.h" |
9 #include "chrome/test/base/browser_with_test_window_test.h" | 14 #include "chrome/test/base/browser_with_test_window_test.h" |
10 #include "chrome/test/base/testing_browser_process.h" | 15 #include "chrome/test/base/testing_browser_process.h" |
| 16 #include "chrome/test/base/testing_pref_service.h" |
| 17 #include "chrome/test/base/testing_profile_manager.h" |
11 #include "content/browser/tab_contents/tab_contents.h" | 18 #include "content/browser/tab_contents/tab_contents.h" |
12 | 19 |
13 typedef BrowserWithTestWindowTest BrowserListTest; | 20 typedef BrowserWithTestWindowTest BrowserListTest; |
14 | 21 |
15 namespace { | 22 namespace { |
16 | 23 |
17 // Helper function to iterate and count all the tabs. | 24 // Helper function to iterate and count all the tabs. |
18 size_t CountAllTabs() { | 25 size_t CountAllTabs() { |
19 size_t count = 0; | 26 size_t count = 0; |
20 for (TabContentsIterator iterator; !iterator.done(); ++iterator) | 27 for (TabContentsIterator iterator; !iterator.done(); ++iterator) |
(...skipping 204 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
225 | 232 |
226 // Delete all tabs to clean up. | 233 // Delete all tabs to clean up. |
227 for (std::vector<TabContentsWrapper*>::iterator it = owned_tabs.begin(); | 234 for (std::vector<TabContentsWrapper*>::iterator it = owned_tabs.begin(); |
228 it != owned_tabs.end(); ++it) { | 235 it != owned_tabs.end(); ++it) { |
229 delete *it; | 236 delete *it; |
230 } | 237 } |
231 | 238 |
232 EXPECT_EQ(0U, CountAllTabs()); | 239 EXPECT_EQ(0U, CountAllTabs()); |
233 } | 240 } |
234 #endif | 241 #endif |
| 242 |
| 243 #if defined(OS_CHROMEOS) |
| 244 // Calling AttemptRestart on ChromeOS will exit the test. |
| 245 #define MAYBE_AttemptRestart DISABLED_AttemptRestart |
| 246 #else |
| 247 #define MAYBE_AttemptRestart AttemptRestart |
| 248 #endif |
| 249 |
| 250 TEST_F(BrowserListTest, MAYBE_AttemptRestart) { |
| 251 ASSERT_TRUE(g_browser_process); |
| 252 TestingPrefService testing_pref_service; |
| 253 testing_pref_service.RegisterBooleanPref(prefs::kWasRestarted, false); |
| 254 testing_pref_service.RegisterBooleanPref(prefs::kRestartLastSessionOnShutdown, |
| 255 false); |
| 256 |
| 257 TestingBrowserProcess* testing_browser_process = |
| 258 static_cast<TestingBrowserProcess*>(g_browser_process); |
| 259 testing_browser_process->SetLocalState(&testing_pref_service); |
| 260 ASSERT_TRUE(g_browser_process->local_state()); |
| 261 ProfileManager* profile_manager = new ProfileManager(FilePath()); |
| 262 testing_browser_process->SetProfileManager(profile_manager); |
| 263 |
| 264 BrowserList::AttemptRestart(); |
| 265 // Cancel the effects of us calling BrowserList::AttemptRestart. Otherwise |
| 266 // tests ran after this one will fail. |
| 267 browser_shutdown::SetTryingToQuit(false); |
| 268 |
| 269 EXPECT_TRUE(testing_pref_service.GetBoolean(prefs::kWasRestarted)); |
| 270 testing_browser_process->SetLocalState(NULL); |
| 271 } |
OLD | NEW |