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/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 129 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 140 // Menu index Menu items | 140 // Menu index Menu items |
| 141 // -------------------------------------- | 141 // -------------------------------------- |
| 142 // 0 Reopen closed tab | 142 // 0 Reopen closed tab |
| 143 // 1 <separator> | 143 // 1 <separator> |
| 144 // 2 <section header for 1st session> | 144 // 2 <section header for 1st session> |
| 145 // 3-5 <3 tabs of the only window of session 0> | 145 // 3-5 <3 tabs of the only window of session 0> |
| 146 // 6 <separator> | 146 // 6 <separator> |
| 147 // 7 <section header for 2nd session> | 147 // 7 <section header for 2nd session> |
| 148 // 8 <the only tab of window 0 of session 1> | 148 // 8 <the only tab of window 0 of session 1> |
| 149 // 9-10 <2 tabs of window 1 of session 2> | 149 // 9-10 <2 tabs of window 1 of session 2> |
| 150 // 11 <separator> | |
| 151 // 12 Devices and history... | |
| 150 | 152 |
| 151 TestRecentTabsSubMenuModel model(NULL, browser(), &associator_, true); | 153 TestRecentTabsSubMenuModel model(NULL, browser(), &associator_, true); |
| 152 int num_items = model.GetItemCount(); | 154 int num_items = model.GetItemCount(); |
| 153 EXPECT_EQ(11, num_items); | 155 EXPECT_EQ(13, num_items); |
| 154 model.ActivatedAt(0); | 156 model.ActivatedAt(0); |
| 155 EXPECT_TRUE(model.IsEnabledAt(0)); | 157 EXPECT_TRUE(model.IsEnabledAt(0)); |
| 156 model.ActivatedAt(3); | 158 model.ActivatedAt(3); |
| 157 EXPECT_TRUE(model.IsEnabledAt(3)); | 159 EXPECT_TRUE(model.IsEnabledAt(3)); |
| 158 model.ActivatedAt(4); | 160 model.ActivatedAt(4); |
| 159 EXPECT_TRUE(model.IsEnabledAt(4)); | 161 EXPECT_TRUE(model.IsEnabledAt(4)); |
| 160 model.ActivatedAt(5); | 162 model.ActivatedAt(5); |
| 161 EXPECT_TRUE(model.IsEnabledAt(5)); | 163 EXPECT_TRUE(model.IsEnabledAt(5)); |
| 162 model.ActivatedAt(8); | 164 model.ActivatedAt(8); |
| 163 EXPECT_TRUE(model.IsEnabledAt(8)); | 165 EXPECT_TRUE(model.IsEnabledAt(8)); |
| 164 model.ActivatedAt(9); | 166 model.ActivatedAt(9); |
| 165 EXPECT_TRUE(model.IsEnabledAt(9)); | 167 EXPECT_TRUE(model.IsEnabledAt(9)); |
| 166 model.ActivatedAt(10); | 168 model.ActivatedAt(10); |
| 167 EXPECT_TRUE(model.IsEnabledAt(10)); | 169 EXPECT_TRUE(model.IsEnabledAt(10)); |
| 168 EXPECT_EQ(7, model.enable_count_); | 170 EXPECT_TRUE(model.IsEnabledAt(12)); |
| 171 EXPECT_EQ(8, model.enable_count_); | |
| 169 EXPECT_EQ(7, model.execute_count_); | 172 EXPECT_EQ(7, model.execute_count_); |
| 170 } | 173 } |
| 171 | 174 |
| 172 TEST_F(RecentTabsSubMenuModelTest, MaxSessionsAndRecency) { | 175 TEST_F(RecentTabsSubMenuModelTest, MaxSessionsAndRecency) { |
| 173 // Create 4 sessions : each session has 1 window with 1 tab each. | 176 // Create 4 sessions : each session has 1 window with 1 tab each. |
| 174 RecentTabsBuilderTestHelper recent_tabs_builder; | 177 RecentTabsBuilderTestHelper recent_tabs_builder; |
| 175 for (int s = 0; s < 4; ++s) { | 178 for (int s = 0; s < 4; ++s) { |
| 176 recent_tabs_builder.AddSession(); | 179 recent_tabs_builder.AddSession(); |
| 177 recent_tabs_builder.AddWindow(s); | 180 recent_tabs_builder.AddWindow(s); |
| 178 recent_tabs_builder.AddTab(s, 0); | 181 recent_tabs_builder.AddTab(s, 0); |
| 179 } | 182 } |
| 180 recent_tabs_builder.RegisterRecentTabs(&associator_); | 183 recent_tabs_builder.RegisterRecentTabs(&associator_); |
| 181 | 184 |
| 182 // Verify that data is populated correctly in RecentTabsSubMenuModel. | 185 // Verify that data is populated correctly in RecentTabsSubMenuModel. |
| 183 // Expected menu: | 186 // Expected menu: |
| 184 // - max sessions is 3, so only 3 most-recent sessions will show | 187 // - max sessions is 3, so only 3 most-recent sessions will show. |
| 188 // - the "More devices" entry since not all possible tabs are shown. | |
|
Alexei Svitkine (slow)
2013/03/19 20:11:01
Now, remove this comment since you're unconditiona
MAD
2013/03/19 20:19:22
D'Ho!ne.
Meant to remove them, I guess it slipped.
| |
| 185 // Menu index Menu items | 189 // Menu index Menu items |
| 186 // -------------------------------------- | 190 // -------------------------------------- |
| 187 // 0 Reopen closed tab | 191 // 0 Reopen closed tab |
| 188 // 1 <separator> | 192 // 1 <separator> |
| 189 // 2 <section header for 1st session> | 193 // 2 <section header for 1st session> |
| 190 // 3 <the only tab of the only window of session 3> | 194 // 3 <the only tab of the only window of session 3> |
| 191 // 4 <separator> | 195 // 4 <separator> |
| 192 // 5 <section header for 2nd session> | 196 // 5 <section header for 2nd session> |
| 193 // 6 <the only tab of the only window of session 2> | 197 // 6 <the only tab of the only window of session 2> |
| 194 // 7 <separator> | 198 // 7 <separator> |
| 195 // 8 <section header for 3rd session> | 199 // 8 <section header for 3rd session> |
| 196 // 9 <the only tab of the only window of session 1> | 200 // 9 <the only tab of the only window of session 1> |
| 201 // 10 <separator> | |
| 202 // 11 Devices and history... | |
| 197 | 203 |
| 198 TestRecentTabsSubMenuModel model(NULL, browser(), &associator_, true); | 204 TestRecentTabsSubMenuModel model(NULL, browser(), &associator_, true); |
| 199 int num_items = model.GetItemCount(); | 205 int num_items = model.GetItemCount(); |
| 200 EXPECT_EQ(10, num_items); | 206 EXPECT_EQ(12, num_items); |
| 201 | 207 |
| 202 std::vector<string16> tab_titles = | 208 std::vector<string16> tab_titles = |
| 203 recent_tabs_builder.GetTabTitlesSortedByRecency(); | 209 recent_tabs_builder.GetTabTitlesSortedByRecency(); |
| 204 EXPECT_EQ(tab_titles[0], model.GetLabelAt(3)); | 210 EXPECT_EQ(tab_titles[0], model.GetLabelAt(3)); |
| 205 EXPECT_EQ(tab_titles[1], model.GetLabelAt(6)); | 211 EXPECT_EQ(tab_titles[1], model.GetLabelAt(6)); |
| 206 EXPECT_EQ(tab_titles[2], model.GetLabelAt(9)); | 212 EXPECT_EQ(tab_titles[2], model.GetLabelAt(9)); |
| 207 } | 213 } |
| 208 | 214 |
| 209 TEST_F(RecentTabsSubMenuModelTest, MaxTabsPerSessionAndRecency) { | 215 TEST_F(RecentTabsSubMenuModelTest, MaxTabsPerSessionAndRecency) { |
| 210 // Create a session: 2 windows with 5 tabs each. | 216 // Create a session: 2 windows with 5 tabs each. |
| 211 RecentTabsBuilderTestHelper recent_tabs_builder; | 217 RecentTabsBuilderTestHelper recent_tabs_builder; |
| 212 recent_tabs_builder.AddSession(); | 218 recent_tabs_builder.AddSession(); |
| 213 for (int w = 0; w < 2; ++w) { | 219 for (int w = 0; w < 2; ++w) { |
| 214 recent_tabs_builder.AddWindow(0); | 220 recent_tabs_builder.AddWindow(0); |
| 215 for (int t = 0; t < 5; ++t) | 221 for (int t = 0; t < 5; ++t) |
| 216 recent_tabs_builder.AddTab(0, w); | 222 recent_tabs_builder.AddTab(0, w); |
| 217 } | 223 } |
| 218 recent_tabs_builder.RegisterRecentTabs(&associator_); | 224 recent_tabs_builder.RegisterRecentTabs(&associator_); |
| 219 | 225 |
| 220 // Verify that data is populated correctly in RecentTabsSubMenuModel. | 226 // Verify that data is populated correctly in RecentTabsSubMenuModel. |
| 221 // Expected menu: | 227 // Expected menu: |
| 222 // - max tabs per session is 4, so only 4 most-recent tabs will show, | 228 // - max tabs per session is 4, so only 4 most-recent tabs will show, |
| 223 // independent of which window they came from | 229 // independent of which window they came from. |
| 230 // - the "More devices" entry since not all possible tabs are shown. | |
|
Alexei Svitkine (slow)
2013/03/19 20:11:01
Now, remove this comment since you're unconditiona
MAD
2013/03/19 20:19:22
Done.
| |
| 224 // Menu index Menu items | 231 // Menu index Menu items |
| 225 // -------------------------------------- | 232 // -------------------------------------- |
| 226 // 0 Reopen closed tab | 233 // 0 Reopen closed tab |
| 227 // 1 <separator> | 234 // 1 <separator> |
| 228 // 2 <section header for session> | 235 // 2 <section header for session> |
| 229 // 3-6 <4 most-recent tabs of session> | 236 // 3-6 <4 most-recent tabs of session> |
| 237 // 7 <separator> | |
| 238 // 8 Devices and history... | |
| 230 | 239 |
| 231 TestRecentTabsSubMenuModel model(NULL, browser(), &associator_, true); | 240 TestRecentTabsSubMenuModel model(NULL, browser(), &associator_, true); |
| 232 int num_items = model.GetItemCount(); | 241 int num_items = model.GetItemCount(); |
| 233 EXPECT_EQ(7, num_items); | 242 EXPECT_EQ(9, num_items); |
| 234 | 243 |
| 235 std::vector<string16> tab_titles = | 244 std::vector<string16> tab_titles = |
| 236 recent_tabs_builder.GetTabTitlesSortedByRecency(); | 245 recent_tabs_builder.GetTabTitlesSortedByRecency(); |
| 237 for (int i = 0; i < 4; ++i) | 246 for (int i = 0; i < 4; ++i) |
| 238 EXPECT_EQ(tab_titles[i], model.GetLabelAt(i + 3)); | 247 EXPECT_EQ(tab_titles[i], model.GetLabelAt(i + 3)); |
| 239 } | 248 } |
| 240 | 249 |
| 241 TEST_F(RecentTabsSubMenuModelTest, MaxWidth) { | 250 TEST_F(RecentTabsSubMenuModelTest, MaxWidth) { |
| 242 // Create 1 session with 1 window and 1 tab. | 251 // Create 1 session with 1 window and 1 tab. |
| 243 RecentTabsBuilderTestHelper recent_tabs_builder; | 252 RecentTabsBuilderTestHelper recent_tabs_builder; |
| 244 recent_tabs_builder.AddSession(); | 253 recent_tabs_builder.AddSession(); |
| 245 recent_tabs_builder.AddWindow(0); | 254 recent_tabs_builder.AddWindow(0); |
| 246 recent_tabs_builder.AddTab(0, 0); | 255 recent_tabs_builder.AddTab(0, 0); |
| 247 recent_tabs_builder.RegisterRecentTabs(&associator_); | 256 recent_tabs_builder.RegisterRecentTabs(&associator_); |
| 248 | 257 |
| 249 // Menu index Menu items | 258 // Menu index Menu items |
| 250 // -------------------------------------- | 259 // -------------------------------------- |
| 251 // 0 Reopen closed tab | 260 // 0 Reopen closed tab |
| 252 // 1 <separator> | 261 // 1 <separator> |
| 253 // 2 <section header for 1st session> | 262 // 2 <section header for 1st session> |
| 254 // 3 <the only tab of the only window of session 1> | 263 // 3 <the only tab of the only window of session 1> |
| 264 // 4 <separator> | |
| 265 // 5 Devices and history... | |
| 255 | 266 |
| 256 TestRecentTabsSubMenuModel model(NULL, browser(), &associator_, true); | 267 TestRecentTabsSubMenuModel model(NULL, browser(), &associator_, true); |
| 257 EXPECT_EQ(4, model.GetItemCount()); | 268 EXPECT_EQ(6, model.GetItemCount()); |
| 258 EXPECT_EQ(-1, model.GetMaxWidthForItemAtIndex(0)); | 269 EXPECT_EQ(-1, model.GetMaxWidthForItemAtIndex(0)); |
| 259 EXPECT_NE(-1, model.GetMaxWidthForItemAtIndex(1)); | 270 EXPECT_NE(-1, model.GetMaxWidthForItemAtIndex(1)); |
| 260 EXPECT_NE(-1, model.GetMaxWidthForItemAtIndex(2)); | 271 EXPECT_NE(-1, model.GetMaxWidthForItemAtIndex(2)); |
| 261 EXPECT_NE(-1, model.GetMaxWidthForItemAtIndex(3)); | 272 EXPECT_NE(-1, model.GetMaxWidthForItemAtIndex(3)); |
| 262 } | 273 } |
| 263 | 274 |
| 264 TEST_F(RecentTabsSubMenuModelTest, MaxWidthNoDevices) { | 275 TEST_F(RecentTabsSubMenuModelTest, MaxWidthNoDevices) { |
| 265 // Expected menu: | 276 // Expected menu: |
| 266 // Menu index Menu items | 277 // Menu index Menu items |
| 267 // -------------------------------------- | 278 // -------------------------------------- |
| 268 // 0 Reopen closed tab | 279 // 0 Reopen closed tab |
| 269 // 1 <separator> | 280 // 1 <separator> |
| 270 // 2 No tabs from other Devices | 281 // 2 No tabs from other Devices |
| 271 | 282 |
| 272 TestRecentTabsSubMenuModel model(NULL, browser(), NULL, false); | 283 TestRecentTabsSubMenuModel model(NULL, browser(), NULL, false); |
| 273 EXPECT_EQ(3, model.GetItemCount()); | 284 EXPECT_EQ(3, model.GetItemCount()); |
| 274 EXPECT_EQ(-1, model.GetMaxWidthForItemAtIndex(0)); | 285 EXPECT_EQ(-1, model.GetMaxWidthForItemAtIndex(0)); |
| 275 EXPECT_NE(-1, model.GetMaxWidthForItemAtIndex(1)); | 286 EXPECT_NE(-1, model.GetMaxWidthForItemAtIndex(1)); |
| 276 EXPECT_EQ(-1, model.GetMaxWidthForItemAtIndex(2)); | 287 EXPECT_EQ(-1, model.GetMaxWidthForItemAtIndex(2)); |
| 277 } | 288 } |
| OLD | NEW |