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

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: '' 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
« no previous file with comments | « chrome/browser/ui/browser_list.cc ('k') | chrome/browser/ui/webui/print_preview_handler.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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"
8 #include "chrome/common/url_constants.h"
6 #include "chrome/test/browser_with_test_window_test.h" 9 #include "chrome/test/browser_with_test_window_test.h"
7 10
8 typedef BrowserWithTestWindowTest BrowserListTest; 11 typedef BrowserWithTestWindowTest BrowserListTest;
9 12
10 namespace { 13 namespace {
11 14
12 // Helper function to iterate and count all the tabs. 15 // Helper function to iterate and count all the tabs.
13 size_t CountAllTabs() { 16 size_t CountAllTabs() {
14 size_t count = 0; 17 size_t count = 0;
15 for (TabContentsIterator iterator; !iterator.done(); ++iterator) 18 for (TabContentsIterator iterator; !iterator.done(); ++iterator)
16 ++count; 19 ++count;
17 return count; 20 return count;
18 } 21 }
19 22
23 // Helper function to navigate to the print preview page.
24 void NavigateToPrintUrl(TabContentsWrapper* tab, int page_id) {
25 static_cast<TestRenderViewHost*>(
26 tab->render_view_host())->SendNavigate(page_id,
27 GURL(chrome::kChromeUIPrintURL));
28 }
29
20 } // namespace 30 } // namespace
21 31
22 TEST_F(BrowserListTest, TabContentsIteratorVerifyCount) { 32 TEST_F(BrowserListTest, TabContentsIteratorVerifyCount) {
23 // Make sure we have 1 window to start with. 33 // Make sure we have 1 window to start with.
24 EXPECT_EQ(1U, BrowserList::size()); 34 EXPECT_EQ(1U, BrowserList::size());
25 35
26 EXPECT_EQ(0U, CountAllTabs()); 36 EXPECT_EQ(0U, CountAllTabs());
27 37
28 // Create more browsers/windows. 38 // Create more browsers/windows.
29 scoped_ptr<Browser> browser2(new Browser(Browser::TYPE_TABBED, profile())); 39 scoped_ptr<Browser> browser2(new Browser(Browser::TYPE_TABBED, profile()));
(...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after
130 else if (count == 2) 140 else if (count == 2)
131 EXPECT_EQ(browser3.get(), iterator.browser()); 141 EXPECT_EQ(browser3.get(), iterator.browser());
132 else 142 else
133 EXPECT_TRUE(false); 143 EXPECT_TRUE(false);
134 } 144 }
135 145
136 // Close all remaining tabs to keep all the destructors happy. 146 // Close all remaining tabs to keep all the destructors happy.
137 browser2->CloseAllTabs(); 147 browser2->CloseAllTabs();
138 browser3->CloseAllTabs(); 148 browser3->CloseAllTabs();
139 } 149 }
150
151 TEST_F(BrowserListTest, TabContentsIteratorBackgroundPrinting) {
152 // Make sure we have 1 window to start with.
153 EXPECT_EQ(1U, BrowserList::size());
154
155 // Create more browsers/windows.
156 scoped_ptr<Browser> browser2(new Browser(Browser::TYPE_TABBED, profile()));
157 scoped_ptr<Browser> browser3(new Browser(Browser::TYPE_TABBED, profile()));
158
159 scoped_ptr<TestBrowserWindow> window2(new TestBrowserWindow(browser2.get()));
160 scoped_ptr<TestBrowserWindow> window3(new TestBrowserWindow(browser3.get()));
161
162 browser2->set_window(window2.get());
163 browser3->set_window(window3.get());
164
165 EXPECT_EQ(0U, CountAllTabs());
166
167 // Add some tabs.
168 for (size_t i = 0; i < 3; ++i)
169 browser2->NewTab();
170 browser3->NewTab();
171
172 EXPECT_EQ(4U, CountAllTabs());
173
174 TestingBrowserProcess* browser_process = testing_browser_process_.get();
175 printing::BackgroundPrintingManager* bg_print_manager =
176 browser_process->background_printing_manager();
177
178 // Grab a tab and give ownership to BackgroundPrintingManager.
179 TabContentsIterator tab_iterator;
180 TabContentsWrapper* tab = *tab_iterator;
181 int page_id = 1;
182 NavigateToPrintUrl(tab, page_id++);
183
184 bg_print_manager->OwnTabContents(tab);
185
186 EXPECT_EQ(4U, CountAllTabs());
187
188 // Close remaining tabs.
189 browser2->CloseAllTabs();
190 browser3->CloseAllTabs();
191
192 EXPECT_EQ(1U, CountAllTabs());
193
194 // Delete the last remaining tab.
195 delete tab;
196
197 EXPECT_EQ(0U, CountAllTabs());
198
199 // Add some tabs.
200 for (size_t i = 0; i < 3; ++i) {
201 browser2->NewTab();
202 browser3->NewTab();
203 }
204
205 EXPECT_EQ(6U, CountAllTabs());
206
207 // Tell BackgroundPrintingManager to take ownership of all tabs.
208 // Save the tabs in |owned_tabs| because manipulating tabs in the middle of
209 // TabContentsIterator is a bad idea.
210 std::vector<TabContentsWrapper*> owned_tabs;
211 for (TabContentsIterator iterator; !iterator.done(); ++iterator) {
212 NavigateToPrintUrl(*iterator, page_id++);
213 owned_tabs.push_back(*iterator);
214 }
215 for (std::vector<TabContentsWrapper*>::iterator it = owned_tabs.begin();
216 it != owned_tabs.end(); ++it) {
217 bg_print_manager->OwnTabContents(*it);
218 }
219
220 EXPECT_EQ(6U, CountAllTabs());
221
222 // Delete all tabs to clean up.
223 for (std::vector<TabContentsWrapper*>::iterator it = owned_tabs.begin();
224 it != owned_tabs.end(); ++it) {
225 delete *it;
226 }
227
228 EXPECT_EQ(0U, CountAllTabs());
229 }
OLDNEW
« no previous file with comments | « chrome/browser/ui/browser_list.cc ('k') | chrome/browser/ui/webui/print_preview_handler.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698