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" |
11 #include "chrome/browser/printing/background_printing_manager.h" | 11 #include "chrome/browser/printing/background_printing_manager.h" |
12 #include "chrome/browser/profiles/profile_manager.h" | 12 #include "chrome/browser/profiles/profile_manager.h" |
13 #include "chrome/browser/ui/browser_commands.h" | 13 #include "chrome/browser/ui/browser_commands.h" |
| 14 #include "chrome/browser/ui/browser_tabstrip.h" |
14 #include "chrome/browser/ui/tab_contents/tab_contents.h" | 15 #include "chrome/browser/ui/tab_contents/tab_contents.h" |
15 #include "chrome/common/pref_names.h" | 16 #include "chrome/common/pref_names.h" |
16 #include "chrome/common/url_constants.h" | 17 #include "chrome/common/url_constants.h" |
17 #include "chrome/test/base/browser_with_test_window_test.h" | 18 #include "chrome/test/base/browser_with_test_window_test.h" |
18 #include "chrome/test/base/testing_browser_process.h" | 19 #include "chrome/test/base/testing_browser_process.h" |
19 #include "chrome/test/base/testing_pref_service.h" | 20 #include "chrome/test/base/testing_pref_service.h" |
20 #include "chrome/test/base/testing_profile_manager.h" | 21 #include "chrome/test/base/testing_profile_manager.h" |
21 #include "content/public/browser/web_contents.h" | 22 #include "content/public/browser/web_contents.h" |
22 #include "content/public/test/test_renderer_host.h" | 23 #include "content/public/test/test_renderer_host.h" |
23 | 24 |
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
71 EXPECT_EQ(0U, CountAllTabs()); | 72 EXPECT_EQ(0U, CountAllTabs()); |
72 | 73 |
73 // Add some tabs. | 74 // Add some tabs. |
74 for (size_t i = 0; i < 3; ++i) | 75 for (size_t i = 0; i < 3; ++i) |
75 chrome::NewTab(browser2.get()); | 76 chrome::NewTab(browser2.get()); |
76 chrome::NewTab(browser3.get()); | 77 chrome::NewTab(browser3.get()); |
77 | 78 |
78 EXPECT_EQ(4U, CountAllTabs()); | 79 EXPECT_EQ(4U, CountAllTabs()); |
79 | 80 |
80 // Close some tabs. | 81 // Close some tabs. |
81 browser2->CloseAllTabs(); | 82 chrome::CloseAllTabs(browser2.get()); |
82 | 83 |
83 EXPECT_EQ(1U, CountAllTabs()); | 84 EXPECT_EQ(1U, CountAllTabs()); |
84 | 85 |
85 // Add lots of tabs. | 86 // Add lots of tabs. |
86 for (size_t i = 0; i < 41; ++i) | 87 for (size_t i = 0; i < 41; ++i) |
87 chrome::NewTab(browser()); | 88 chrome::NewTab(browser()); |
88 | 89 |
89 EXPECT_EQ(42U, CountAllTabs()); | 90 EXPECT_EQ(42U, CountAllTabs()); |
90 // Close all remaining tabs to keep all the destructors happy. | 91 // Close all remaining tabs to keep all the destructors happy. |
91 browser3->CloseAllTabs(); | 92 chrome::CloseAllTabs(browser3.get()); |
92 } | 93 } |
93 | 94 |
94 TEST_F(BrowserListTest, TabContentsIteratorVerifyBrowser) { | 95 TEST_F(BrowserListTest, TabContentsIteratorVerifyBrowser) { |
95 // Make sure we have 1 window to start with. | 96 // Make sure we have 1 window to start with. |
96 EXPECT_EQ(1U, BrowserList::size()); | 97 EXPECT_EQ(1U, BrowserList::size()); |
97 | 98 |
98 // Create more browsers/windows. | 99 // Create more browsers/windows. |
99 scoped_ptr<Browser> browser2(new Browser(Browser::TYPE_TABBED, profile())); | 100 scoped_ptr<Browser> browser2(new Browser(Browser::TYPE_TABBED, profile())); |
100 scoped_ptr<Browser> browser3(new Browser(Browser::TYPE_TABBED, profile())); | 101 scoped_ptr<Browser> browser3(new Browser(Browser::TYPE_TABBED, profile())); |
101 | 102 |
(...skipping 20 matching lines...) Expand all Loading... |
122 for (TabContentsIterator iterator; !iterator.done(); ++iterator, ++count) { | 123 for (TabContentsIterator iterator; !iterator.done(); ++iterator, ++count) { |
123 if (count < 3) | 124 if (count < 3) |
124 EXPECT_EQ(browser2.get(), iterator.browser()); | 125 EXPECT_EQ(browser2.get(), iterator.browser()); |
125 else if (count == 3) | 126 else if (count == 3) |
126 EXPECT_EQ(browser3.get(), iterator.browser()); | 127 EXPECT_EQ(browser3.get(), iterator.browser()); |
127 else | 128 else |
128 EXPECT_TRUE(false); | 129 EXPECT_TRUE(false); |
129 } | 130 } |
130 | 131 |
131 // Close some tabs. | 132 // Close some tabs. |
132 browser2->CloseAllTabs(); | 133 chrome::CloseAllTabs(browser2.get()); |
133 | 134 |
134 count = 0; | 135 count = 0; |
135 for (TabContentsIterator iterator; !iterator.done(); ++iterator, ++count) { | 136 for (TabContentsIterator iterator; !iterator.done(); ++iterator, ++count) { |
136 if (count == 0) | 137 if (count == 0) |
137 EXPECT_EQ(browser3.get(), iterator.browser()); | 138 EXPECT_EQ(browser3.get(), iterator.browser()); |
138 else | 139 else |
139 EXPECT_TRUE(false); | 140 EXPECT_TRUE(false); |
140 } | 141 } |
141 | 142 |
142 // Now make it one tab per browser. | 143 // Now make it one tab per browser. |
143 chrome::NewTab(browser()); | 144 chrome::NewTab(browser()); |
144 chrome::NewTab(browser2.get()); | 145 chrome::NewTab(browser2.get()); |
145 | 146 |
146 count = 0; | 147 count = 0; |
147 for (TabContentsIterator iterator; !iterator.done(); ++iterator, ++count) { | 148 for (TabContentsIterator iterator; !iterator.done(); ++iterator, ++count) { |
148 if (count == 0) | 149 if (count == 0) |
149 EXPECT_EQ(browser(), iterator.browser()); | 150 EXPECT_EQ(browser(), iterator.browser()); |
150 else if (count == 1) | 151 else if (count == 1) |
151 EXPECT_EQ(browser2.get(), iterator.browser()); | 152 EXPECT_EQ(browser2.get(), iterator.browser()); |
152 else if (count == 2) | 153 else if (count == 2) |
153 EXPECT_EQ(browser3.get(), iterator.browser()); | 154 EXPECT_EQ(browser3.get(), iterator.browser()); |
154 else | 155 else |
155 EXPECT_TRUE(false); | 156 EXPECT_TRUE(false); |
156 } | 157 } |
157 | 158 |
158 // Close all remaining tabs to keep all the destructors happy. | 159 // Close all remaining tabs to keep all the destructors happy. |
159 browser2->CloseAllTabs(); | 160 chrome::CloseAllTabs(browser2.get()); |
160 browser3->CloseAllTabs(); | 161 chrome::CloseAllTabs(browser3.get()); |
161 } | 162 } |
162 | 163 |
163 #if 0 | 164 #if 0 |
164 // TODO(thestig) Fix or remove this test. http://crbug.com/100309 | 165 // TODO(thestig) Fix or remove this test. http://crbug.com/100309 |
165 TEST_F(BrowserListTest, TabContentsIteratorBackgroundPrinting) { | 166 TEST_F(BrowserListTest, TabContentsIteratorBackgroundPrinting) { |
166 // Make sure we have 1 window to start with. | 167 // Make sure we have 1 window to start with. |
167 EXPECT_EQ(1U, BrowserList::size()); | 168 EXPECT_EQ(1U, BrowserList::size()); |
168 | 169 |
169 // Create more browsers/windows. | 170 // Create more browsers/windows. |
170 scoped_ptr<Browser> browser2(new Browser(Browser::TYPE_TABBED, profile())); | 171 scoped_ptr<Browser> browser2(new Browser(Browser::TYPE_TABBED, profile())); |
(...skipping 23 matching lines...) Expand all Loading... |
194 TabContentsIterator tab_iterator; | 195 TabContentsIterator tab_iterator; |
195 TabContents* tab = *tab_iterator; | 196 TabContents* tab = *tab_iterator; |
196 int page_id = 1; | 197 int page_id = 1; |
197 NavigateToPrintUrl(tab, page_id++); | 198 NavigateToPrintUrl(tab, page_id++); |
198 | 199 |
199 bg_print_manager->OwnPrintPreviewTab(tab); | 200 bg_print_manager->OwnPrintPreviewTab(tab); |
200 | 201 |
201 EXPECT_EQ(4U, CountAllTabs()); | 202 EXPECT_EQ(4U, CountAllTabs()); |
202 | 203 |
203 // Close remaining tabs. | 204 // Close remaining tabs. |
204 browser2->CloseAllTabs(); | 205 chrome::CloseAllTabs(browser2.get()); |
205 browser3->CloseAllTabs(); | 206 chrome::CloseAllTabs(browser3.get()); |
206 | 207 |
207 EXPECT_EQ(1U, CountAllTabs()); | 208 EXPECT_EQ(1U, CountAllTabs()); |
208 | 209 |
209 // Delete the last remaining tab. | 210 // Delete the last remaining tab. |
210 delete tab; | 211 delete tab; |
211 | 212 |
212 EXPECT_EQ(0U, CountAllTabs()); | 213 EXPECT_EQ(0U, CountAllTabs()); |
213 | 214 |
214 // Add some tabs. | 215 // Add some tabs. |
215 for (size_t i = 0; i < 3; ++i) { | 216 for (size_t i = 0; i < 3; ++i) { |
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
266 testing_browser_process->SetProfileManager(profile_manager); | 267 testing_browser_process->SetProfileManager(profile_manager); |
267 | 268 |
268 browser::AttemptRestart(); | 269 browser::AttemptRestart(); |
269 // Cancel the effects of us calling browser::AttemptRestart. Otherwise tests | 270 // Cancel the effects of us calling browser::AttemptRestart. Otherwise tests |
270 // ran after this one will fail. | 271 // ran after this one will fail. |
271 browser_shutdown::SetTryingToQuit(false); | 272 browser_shutdown::SetTryingToQuit(false); |
272 | 273 |
273 EXPECT_TRUE(testing_pref_service.GetBoolean(prefs::kWasRestarted)); | 274 EXPECT_TRUE(testing_pref_service.GetBoolean(prefs::kWasRestarted)); |
274 testing_browser_process->SetLocalState(NULL); | 275 testing_browser_process->SetLocalState(NULL); |
275 } | 276 } |
OLD | NEW |