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/toolbar/recent_tabs_sub_menu_model.h" | 5 #include "chrome/browser/ui/toolbar/recent_tabs_sub_menu_model.h" |
6 | 6 |
7 #include "chrome/app/chrome_command_ids.h" | 7 #include "chrome/app/chrome_command_ids.h" |
8 #include "chrome/browser/sessions/session_types.h" | 8 #include "chrome/browser/sessions/session_types.h" |
9 #include "chrome/browser/sessions/session_types_test_helper.h" | 9 #include "chrome/browser/sessions/session_types_test_helper.h" |
10 #include "chrome/browser/sync/glue/session_model_associator.h" | 10 #include "chrome/browser/sync/glue/session_model_associator.h" |
(...skipping 163 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
174 RecentTabsBuilderTestHelper recent_tabs_builder; | 174 RecentTabsBuilderTestHelper recent_tabs_builder; |
175 for (int s = 0; s < 4; ++s) { | 175 for (int s = 0; s < 4; ++s) { |
176 recent_tabs_builder.AddSession(); | 176 recent_tabs_builder.AddSession(); |
177 recent_tabs_builder.AddWindow(s); | 177 recent_tabs_builder.AddWindow(s); |
178 recent_tabs_builder.AddTab(s, 0); | 178 recent_tabs_builder.AddTab(s, 0); |
179 } | 179 } |
180 recent_tabs_builder.RegisterRecentTabs(&associator_); | 180 recent_tabs_builder.RegisterRecentTabs(&associator_); |
181 | 181 |
182 // Verify that data is populated correctly in RecentTabsSubMenuModel. | 182 // Verify that data is populated correctly in RecentTabsSubMenuModel. |
183 // Expected menu: | 183 // Expected menu: |
184 // - max sessions is 3, so only 3 most-recent sessions will show | 184 // - max sessions is 3, so only 3 most-recent sessions will show |
Alexei Svitkine (slow)
2013/03/19 17:09:33
Expand this comment to explain why More devices...
MAD
2013/03/19 17:46:48
Done.
| |
185 // Menu index Menu items | 185 // Menu index Menu items |
186 // -------------------------------------- | 186 // -------------------------------------- |
187 // 0 Reopen closed tab | 187 // 0 Reopen closed tab |
188 // 1 <separator> | 188 // 1 <separator> |
189 // 2 <section header for 1st session> | 189 // 2 <section header for 1st session> |
190 // 3 <the only tab of the only window of session 3> | 190 // 3 <the only tab of the only window of session 3> |
191 // 4 <separator> | 191 // 4 <separator> |
192 // 5 <section header for 2nd session> | 192 // 5 <section header for 2nd session> |
193 // 6 <the only tab of the only window of session 2> | 193 // 6 <the only tab of the only window of session 2> |
194 // 7 <separator> | 194 // 7 <separator> |
195 // 8 <section header for 3rd session> | 195 // 8 <section header for 3rd session> |
196 // 9 <the only tab of the only window of session 1> | 196 // 9 <the only tab of the only window of session 1> |
197 // 10 <separator> | |
198 // 11 <More devices...> | |
197 | 199 |
198 TestRecentTabsSubMenuModel model(NULL, browser(), &associator_, true); | 200 TestRecentTabsSubMenuModel model(NULL, browser(), &associator_, true); |
199 int num_items = model.GetItemCount(); | 201 int num_items = model.GetItemCount(); |
200 EXPECT_EQ(10, num_items); | 202 EXPECT_EQ(12, num_items); |
201 | 203 |
202 std::vector<string16> tab_titles = | 204 std::vector<string16> tab_titles = |
203 recent_tabs_builder.GetTabTitlesSortedByRecency(); | 205 recent_tabs_builder.GetTabTitlesSortedByRecency(); |
204 EXPECT_EQ(tab_titles[0], model.GetLabelAt(3)); | 206 EXPECT_EQ(tab_titles[0], model.GetLabelAt(3)); |
205 EXPECT_EQ(tab_titles[1], model.GetLabelAt(6)); | 207 EXPECT_EQ(tab_titles[1], model.GetLabelAt(6)); |
206 EXPECT_EQ(tab_titles[2], model.GetLabelAt(9)); | 208 EXPECT_EQ(tab_titles[2], model.GetLabelAt(9)); |
207 } | 209 } |
208 | 210 |
209 TEST_F(RecentTabsSubMenuModelTest, MaxTabsPerSessionAndRecency) { | 211 TEST_F(RecentTabsSubMenuModelTest, MaxTabsPerSessionAndRecency) { |
210 // Create a session: 2 windows with 5 tabs each. | 212 // Create a session: 2 windows with 5 tabs each. |
211 RecentTabsBuilderTestHelper recent_tabs_builder; | 213 RecentTabsBuilderTestHelper recent_tabs_builder; |
212 recent_tabs_builder.AddSession(); | 214 recent_tabs_builder.AddSession(); |
213 for (int w = 0; w < 2; ++w) { | 215 for (int w = 0; w < 2; ++w) { |
214 recent_tabs_builder.AddWindow(0); | 216 recent_tabs_builder.AddWindow(0); |
215 for (int t = 0; t < 5; ++t) | 217 for (int t = 0; t < 5; ++t) |
216 recent_tabs_builder.AddTab(0, w); | 218 recent_tabs_builder.AddTab(0, w); |
217 } | 219 } |
218 recent_tabs_builder.RegisterRecentTabs(&associator_); | 220 recent_tabs_builder.RegisterRecentTabs(&associator_); |
219 | 221 |
220 // Verify that data is populated correctly in RecentTabsSubMenuModel. | 222 // Verify that data is populated correctly in RecentTabsSubMenuModel. |
221 // Expected menu: | 223 // Expected menu: |
222 // - max tabs per session is 4, so only 4 most-recent tabs will show, | 224 // - max tabs per session is 4, so only 4 most-recent tabs will show, |
223 // independent of which window they came from | 225 // independent of which window they came from |
Alexei Svitkine (slow)
2013/03/19 17:09:33
Expand this comment to explain why More devices...
MAD
2013/03/19 17:46:48
Done.
| |
224 // Menu index Menu items | 226 // Menu index Menu items |
225 // -------------------------------------- | 227 // -------------------------------------- |
226 // 0 Reopen closed tab | 228 // 0 Reopen closed tab |
227 // 1 <separator> | 229 // 1 <separator> |
228 // 2 <section header for session> | 230 // 2 <section header for session> |
229 // 3-6 <4 most-recent tabs of session> | 231 // 3-6 <4 most-recent tabs of session> |
232 // 7 <separator> | |
233 // 8 <More devices...> | |
230 | 234 |
231 TestRecentTabsSubMenuModel model(NULL, browser(), &associator_, true); | 235 TestRecentTabsSubMenuModel model(NULL, browser(), &associator_, true); |
232 int num_items = model.GetItemCount(); | 236 int num_items = model.GetItemCount(); |
233 EXPECT_EQ(7, num_items); | 237 EXPECT_EQ(9, num_items); |
234 | 238 |
235 std::vector<string16> tab_titles = | 239 std::vector<string16> tab_titles = |
236 recent_tabs_builder.GetTabTitlesSortedByRecency(); | 240 recent_tabs_builder.GetTabTitlesSortedByRecency(); |
237 for (int i = 0; i < 4; ++i) | 241 for (int i = 0; i < 4; ++i) |
238 EXPECT_EQ(tab_titles[i], model.GetLabelAt(i + 3)); | 242 EXPECT_EQ(tab_titles[i], model.GetLabelAt(i + 3)); |
239 } | 243 } |
240 | 244 |
241 TEST_F(RecentTabsSubMenuModelTest, MaxWidth) { | 245 TEST_F(RecentTabsSubMenuModelTest, MaxWidth) { |
242 // Create 1 session with 1 window and 1 tab. | 246 // Create 1 session with 1 window and 1 tab. |
243 RecentTabsBuilderTestHelper recent_tabs_builder; | 247 RecentTabsBuilderTestHelper recent_tabs_builder; |
(...skipping 24 matching lines...) Expand all Loading... | |
268 // 0 Reopen closed tab | 272 // 0 Reopen closed tab |
269 // 1 <separator> | 273 // 1 <separator> |
270 // 2 No tabs from other Devices | 274 // 2 No tabs from other Devices |
271 | 275 |
272 TestRecentTabsSubMenuModel model(NULL, browser(), NULL, false); | 276 TestRecentTabsSubMenuModel model(NULL, browser(), NULL, false); |
273 EXPECT_EQ(3, model.GetItemCount()); | 277 EXPECT_EQ(3, model.GetItemCount()); |
274 EXPECT_EQ(-1, model.GetMaxWidthForItemAtIndex(0)); | 278 EXPECT_EQ(-1, model.GetMaxWidthForItemAtIndex(0)); |
275 EXPECT_NE(-1, model.GetMaxWidthForItemAtIndex(1)); | 279 EXPECT_NE(-1, model.GetMaxWidthForItemAtIndex(1)); |
276 EXPECT_EQ(-1, model.GetMaxWidthForItemAtIndex(2)); | 280 EXPECT_EQ(-1, model.GetMaxWidthForItemAtIndex(2)); |
277 } | 281 } |
OLD | NEW |