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/ui/browser_list_unittest.cc

Issue 6930034: Print Preview: Print in the background. (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: fix build after r84303 Created 9 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) 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/printing/background_printing_manager.h"
5 #include "chrome/browser/ui/browser_list.h" 6 #include "chrome/browser/ui/browser_list.h"
7 #include "chrome/browser/ui/tab_contents/tab_contents_wrapper.h"
6 #include "chrome/test/browser_with_test_window_test.h" 8 #include "chrome/test/browser_with_test_window_test.h"
7 9
8 typedef BrowserWithTestWindowTest BrowserListTest; 10 typedef BrowserWithTestWindowTest BrowserListTest;
9 11
10 namespace { 12 namespace {
11 13
12 // Helper function to iterate and count all the tabs. 14 // Helper function to iterate and count all the tabs.
13 size_t CountAllTabs() { 15 size_t CountAllTabs() {
14 size_t count = 0; 16 size_t count = 0;
15 for (TabContentsIterator iterator; !iterator.done(); ++iterator) 17 for (TabContentsIterator iterator; !iterator.done(); ++iterator)
(...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after
130 else if (count == 2) 132 else if (count == 2)
131 EXPECT_EQ(browser3.get(), iterator.browser()); 133 EXPECT_EQ(browser3.get(), iterator.browser());
132 else 134 else
133 EXPECT_TRUE(false); 135 EXPECT_TRUE(false);
134 } 136 }
135 137
136 // Close all remaining tabs to keep all the destructors happy. 138 // Close all remaining tabs to keep all the destructors happy.
137 browser2->CloseAllTabs(); 139 browser2->CloseAllTabs();
138 browser3->CloseAllTabs(); 140 browser3->CloseAllTabs();
139 } 141 }
142
143 TEST_F(BrowserListTest, TabContentsIteratorBackgroundPrinting) {
144 // Make sure we have 1 window to start with.
145 EXPECT_EQ(1U, BrowserList::size());
146
147 // Create more browsers/windows.
148 scoped_ptr<Browser> browser2(new Browser(Browser::TYPE_TABBED, profile()));
149 scoped_ptr<Browser> browser3(new Browser(Browser::TYPE_TABBED, profile()));
150
151 scoped_ptr<TestBrowserWindow> window2(new TestBrowserWindow(browser2.get()));
152 scoped_ptr<TestBrowserWindow> window3(new TestBrowserWindow(browser3.get()));
153
154 browser2->set_window(window2.get());
155 browser3->set_window(window3.get());
156
157 EXPECT_EQ(0U, CountAllTabs());
158
159 // Add some tabs.
160 for (size_t i = 0; i < 3; ++i)
161 browser2->NewTab();
162 browser3->NewTab();
163
164 EXPECT_EQ(4U, CountAllTabs());
165
166 TestingBrowserProcess* browser_process = testing_browser_process_.get();
167 printing::BackgroundPrintingManager* bg_print_manager =
168 browser_process->background_printing_manager();
169
170 // Grab a tab and hide it.
171 TabContentsIterator tab_iterator;
172 TabContentsWrapper* tab = *tab_iterator;
173 bg_print_manager->HideTabContents(tab);
174
175 EXPECT_EQ(4U, CountAllTabs());
176
177 // Close remaining tabs.
178 browser2->CloseAllTabs();
179 browser3->CloseAllTabs();
180
181 EXPECT_EQ(1U, CountAllTabs());
182
183 // Delete the last remaining tab.
184 delete tab;
185
186 EXPECT_EQ(0U, CountAllTabs());
187
188 // Add some tabs.
189 for (size_t i = 0; i < 3; ++i) {
190 browser2->NewTab();
191 browser3->NewTab();
192 }
193
194 EXPECT_EQ(6U, CountAllTabs());
195
196 // Hide all tabs. Save the tabs in |hidden_tabs| because manipulating
197 // tabs in the middle of TabContentsIterator is a bad idea.
198 std::vector<TabContentsWrapper*> hidden_tabs;
199 for (TabContentsIterator iterator; !iterator.done(); ++iterator)
200 hidden_tabs.push_back(*iterator);
201 for (std::vector<TabContentsWrapper*>::iterator it = hidden_tabs.begin();
202 it != hidden_tabs.end(); ++it) {
203 bg_print_manager->HideTabContents(*it);
204 }
205
206 EXPECT_EQ(6U, CountAllTabs());
207
208 // Delete all tabs to clean up.
209 for (std::vector<TabContentsWrapper*>::iterator it = hidden_tabs.begin();
210 it != hidden_tabs.end(); ++it) {
211 delete *it;
212 }
213
214 EXPECT_EQ(0U, CountAllTabs());
215 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698