Chromium Code Reviews| OLD | NEW |
|---|---|
| 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 "chrome/browser/ui/tab_contents/tab_contents_iterator.h" | 5 #include "chrome/browser/ui/tab_contents/tab_contents_iterator.h" |
| 6 | 6 |
| 7 #include "chrome/browser/browser_process.h" | 7 #include "chrome/browser/browser_process.h" |
| 8 #include "chrome/browser/browser_shutdown.h" | 8 #include "chrome/browser/browser_shutdown.h" |
| 9 #include "chrome/browser/lifetime/application_lifetime.h" | 9 #include "chrome/browser/lifetime/application_lifetime.h" |
| 10 #include "chrome/browser/prefs/pref_service.h" | 10 #include "chrome/browser/prefs/pref_service.h" |
| (...skipping 17 matching lines...) Expand all Loading... | |
| 28 namespace { | 28 namespace { |
| 29 | 29 |
| 30 // Helper function to iterate and count all the tabs. | 30 // Helper function to iterate and count all the tabs. |
| 31 size_t CountAllTabs() { | 31 size_t CountAllTabs() { |
| 32 size_t count = 0; | 32 size_t count = 0; |
| 33 for (TabContentsIterator iterator; !iterator.done(); ++iterator) | 33 for (TabContentsIterator iterator; !iterator.done(); ++iterator) |
| 34 ++count; | 34 ++count; |
| 35 return count; | 35 return count; |
| 36 } | 36 } |
| 37 | 37 |
| 38 // Helper function to navigate to the print preview page. | |
| 39 void NavigateToPrintUrl(TabContents* tab, int page_id) { | |
| 40 content::RenderViewHostTester::For( | |
| 41 tab->web_contents()->GetRenderViewHost())->SendNavigate( | |
| 42 page_id, GURL(chrome::kChromeUIPrintURL)); | |
| 43 } | |
| 44 | |
| 45 } // namespace | 38 } // namespace |
| 46 | 39 |
| 47 TEST_F(BrowserListTest, TabContentsIteratorVerifyCount) { | 40 TEST_F(BrowserListTest, TabContentsIteratorVerifyCount) { |
| 48 // Make sure we have 1 window to start with. | 41 // Make sure we have 1 window to start with. |
| 49 EXPECT_EQ(1U, BrowserList::size()); | 42 EXPECT_EQ(1U, BrowserList::size()); |
| 50 | 43 |
| 51 EXPECT_EQ(0U, CountAllTabs()); | 44 EXPECT_EQ(0U, CountAllTabs()); |
| 52 | 45 |
| 53 // Create more browsers/windows. | 46 // Create more browsers/windows. |
| 54 scoped_ptr<Browser> browser2( | 47 scoped_ptr<Browser> browser2( |
| (...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 146 EXPECT_EQ(browser3.get(), iterator.browser()); | 139 EXPECT_EQ(browser3.get(), iterator.browser()); |
| 147 else | 140 else |
| 148 EXPECT_TRUE(false); | 141 EXPECT_TRUE(false); |
| 149 } | 142 } |
| 150 | 143 |
| 151 // Close all remaining tabs to keep all the destructors happy. | 144 // Close all remaining tabs to keep all the destructors happy. |
| 152 chrome::CloseAllTabs(browser2.get()); | 145 chrome::CloseAllTabs(browser2.get()); |
| 153 chrome::CloseAllTabs(browser3.get()); | 146 chrome::CloseAllTabs(browser3.get()); |
| 154 } | 147 } |
| 155 | 148 |
| 156 #if 0 | |
|
Lei Zhang
2012/09/28 18:41:24
Do you mind leaving this one alone? I'll take a lo
Nico
2012/09/29 11:08:40
Can't you just get it from source control once you
Lei Zhang
2012/10/01 17:31:43
Sure. I decided to delete it anyway.
| |
| 157 // TODO(thestig) Fix or remove this test. http://crbug.com/100309 | |
| 158 TEST_F(BrowserListTest, TabContentsIteratorBackgroundPrinting) { | |
| 159 // Make sure we have 1 window to start with. | |
| 160 EXPECT_EQ(1U, BrowserList::size()); | |
| 161 | |
| 162 // Create more browsers/windows. | |
| 163 scoped_ptr<Browser> browser2( | |
| 164 chrome::CreateBrowserWithTestWindowForProfile(profile())); | |
| 165 scoped_ptr<Browser> browser3( | |
| 166 chrome::CreateBrowserWithTestWindowForProfile(profile())); | |
| 167 | |
| 168 EXPECT_EQ(0U, CountAllTabs()); | |
| 169 | |
| 170 // Add some tabs. | |
| 171 for (size_t i = 0; i < 3; ++i) | |
| 172 chrome::NewTab(browser2); | |
| 173 chrome::NewTab(browser3); | |
| 174 | |
| 175 EXPECT_EQ(4U, CountAllTabs()); | |
| 176 | |
| 177 TestingBrowserProcess* browser_process = | |
| 178 static_cast<TestingBrowserProcess*>(g_browser_process); | |
| 179 printing::BackgroundPrintingManager* bg_print_manager = | |
| 180 browser_process->background_printing_manager(); | |
| 181 | |
| 182 // Grab a tab and give ownership to BackgroundPrintingManager. | |
| 183 TabContentsIterator tab_iterator; | |
| 184 TabContents* tab = *tab_iterator; | |
| 185 int page_id = 1; | |
| 186 NavigateToPrintUrl(tab, page_id++); | |
| 187 | |
| 188 bg_print_manager->OwnPrintPreviewTab(tab); | |
| 189 | |
| 190 EXPECT_EQ(4U, CountAllTabs()); | |
| 191 | |
| 192 // Close remaining tabs. | |
| 193 chrome::CloseAllTabs(browser2.get()); | |
| 194 chrome::CloseAllTabs(browser3.get()); | |
| 195 | |
| 196 EXPECT_EQ(1U, CountAllTabs()); | |
| 197 | |
| 198 // Delete the last remaining tab. | |
| 199 delete tab; | |
| 200 | |
| 201 EXPECT_EQ(0U, CountAllTabs()); | |
| 202 | |
| 203 // Add some tabs. | |
| 204 for (size_t i = 0; i < 3; ++i) { | |
| 205 chrome::NewTab(browser2.get()); | |
| 206 chrome::NewTab(browser3.get()); | |
| 207 } | |
| 208 | |
| 209 EXPECT_EQ(6U, CountAllTabs()); | |
| 210 | |
| 211 // Tell BackgroundPrintingManager to take ownership of all tabs. | |
| 212 // Save the tabs in |owned_tabs| because manipulating tabs in the middle of | |
| 213 // TabContentsIterator is a bad idea. | |
| 214 std::vector<TabContents*> owned_tabs; | |
| 215 for (TabContentsIterator iterator; !iterator.done(); ++iterator) { | |
| 216 NavigateToPrintUrl(*iterator, page_id++); | |
| 217 owned_tabs.push_back(*iterator); | |
| 218 } | |
| 219 for (std::vector<TabContents*>::iterator it = owned_tabs.begin(); | |
| 220 it != owned_tabs.end(); ++it) { | |
| 221 bg_print_manager->OwnPrintPreviewTab(*it); | |
| 222 } | |
| 223 | |
| 224 EXPECT_EQ(6U, CountAllTabs()); | |
| 225 | |
| 226 // Delete all tabs to clean up. | |
| 227 for (std::vector<TabContents*>::iterator it = owned_tabs.begin(); | |
| 228 it != owned_tabs.end(); ++it) { | |
| 229 delete *it; | |
| 230 } | |
| 231 | |
| 232 EXPECT_EQ(0U, CountAllTabs()); | |
| 233 } | |
| 234 #endif | |
| 235 | |
| 236 #if defined(OS_CHROMEOS) | 149 #if defined(OS_CHROMEOS) |
| 237 // Calling AttemptRestart on ChromeOS will exit the test. | 150 // Calling AttemptRestart on ChromeOS will exit the test. |
| 238 #define MAYBE_AttemptRestart DISABLED_AttemptRestart | 151 #define MAYBE_AttemptRestart DISABLED_AttemptRestart |
| 239 #else | 152 #else |
| 240 #define MAYBE_AttemptRestart AttemptRestart | 153 #define MAYBE_AttemptRestart AttemptRestart |
| 241 #endif | 154 #endif |
| 242 | 155 |
| 243 TEST_F(BrowserListTest, MAYBE_AttemptRestart) { | 156 TEST_F(BrowserListTest, MAYBE_AttemptRestart) { |
| 244 ASSERT_TRUE(g_browser_process); | 157 ASSERT_TRUE(g_browser_process); |
| 245 TestingPrefService testing_pref_service; | 158 TestingPrefService testing_pref_service; |
| 246 testing_pref_service.RegisterBooleanPref(prefs::kWasRestarted, false); | 159 testing_pref_service.RegisterBooleanPref(prefs::kWasRestarted, false); |
| 247 testing_pref_service.RegisterBooleanPref(prefs::kRestartLastSessionOnShutdown, | 160 testing_pref_service.RegisterBooleanPref(prefs::kRestartLastSessionOnShutdown, |
| 248 false); | 161 false); |
| 249 | 162 |
| 250 TestingBrowserProcess* testing_browser_process = | 163 TestingBrowserProcess* testing_browser_process = |
| 251 static_cast<TestingBrowserProcess*>(g_browser_process); | 164 static_cast<TestingBrowserProcess*>(g_browser_process); |
| 252 testing_browser_process->SetLocalState(&testing_pref_service); | 165 testing_browser_process->SetLocalState(&testing_pref_service); |
| 253 ASSERT_TRUE(g_browser_process->local_state()); | 166 ASSERT_TRUE(g_browser_process->local_state()); |
| 254 ProfileManager* profile_manager = new ProfileManager(FilePath()); | 167 ProfileManager* profile_manager = new ProfileManager(FilePath()); |
| 255 testing_browser_process->SetProfileManager(profile_manager); | 168 testing_browser_process->SetProfileManager(profile_manager); |
| 256 | 169 |
| 257 browser::AttemptRestart(); | 170 browser::AttemptRestart(); |
| 258 // Cancel the effects of us calling browser::AttemptRestart. Otherwise tests | 171 // Cancel the effects of us calling browser::AttemptRestart. Otherwise tests |
| 259 // ran after this one will fail. | 172 // ran after this one will fail. |
| 260 browser_shutdown::SetTryingToQuit(false); | 173 browser_shutdown::SetTryingToQuit(false); |
| 261 | 174 |
| 262 EXPECT_TRUE(testing_pref_service.GetBoolean(prefs::kWasRestarted)); | 175 EXPECT_TRUE(testing_pref_service.GetBoolean(prefs::kWasRestarted)); |
| 263 testing_browser_process->SetLocalState(NULL); | 176 testing_browser_process->SetLocalState(NULL); |
| 264 } | 177 } |
| OLD | NEW |