| 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. |
| 185 // Menu index Menu items | 188 // Menu index Menu items |
| 186 // -------------------------------------- | 189 // -------------------------------------- |
| 187 // 0 Reopen closed tab | 190 // 0 Reopen closed tab |
| 188 // 1 <separator> | 191 // 1 <separator> |
| 189 // 2 <section header for 1st session> | 192 // 2 <section header for 1st session> |
| 190 // 3 <the only tab of the only window of session 3> | 193 // 3 <the only tab of the only window of session 3> |
| 191 // 4 <separator> | 194 // 4 <separator> |
| 192 // 5 <section header for 2nd session> | 195 // 5 <section header for 2nd session> |
| 193 // 6 <the only tab of the only window of session 2> | 196 // 6 <the only tab of the only window of session 2> |
| 194 // 7 <separator> | 197 // 7 <separator> |
| 195 // 8 <section header for 3rd session> | 198 // 8 <section header for 3rd session> |
| 196 // 9 <the only tab of the only window of session 1> | 199 // 9 <the only tab of the only window of session 1> |
| 200 // 10 <separator> |
| 201 // 11 Devices and history... |
| 197 | 202 |
| 198 TestRecentTabsSubMenuModel model(NULL, browser(), &associator_, true); | 203 TestRecentTabsSubMenuModel model(NULL, browser(), &associator_, true); |
| 199 int num_items = model.GetItemCount(); | 204 int num_items = model.GetItemCount(); |
| 200 EXPECT_EQ(10, num_items); | 205 EXPECT_EQ(12, num_items); |
| 201 | 206 |
| 202 std::vector<string16> tab_titles = | 207 std::vector<string16> tab_titles = |
| 203 recent_tabs_builder.GetTabTitlesSortedByRecency(); | 208 recent_tabs_builder.GetTabTitlesSortedByRecency(); |
| 204 EXPECT_EQ(tab_titles[0], model.GetLabelAt(3)); | 209 EXPECT_EQ(tab_titles[0], model.GetLabelAt(3)); |
| 205 EXPECT_EQ(tab_titles[1], model.GetLabelAt(6)); | 210 EXPECT_EQ(tab_titles[1], model.GetLabelAt(6)); |
| 206 EXPECT_EQ(tab_titles[2], model.GetLabelAt(9)); | 211 EXPECT_EQ(tab_titles[2], model.GetLabelAt(9)); |
| 207 } | 212 } |
| 208 | 213 |
| 209 TEST_F(RecentTabsSubMenuModelTest, MaxTabsPerSessionAndRecency) { | 214 TEST_F(RecentTabsSubMenuModelTest, MaxTabsPerSessionAndRecency) { |
| 210 // Create a session: 2 windows with 5 tabs each. | 215 // Create a session: 2 windows with 5 tabs each. |
| 211 RecentTabsBuilderTestHelper recent_tabs_builder; | 216 RecentTabsBuilderTestHelper recent_tabs_builder; |
| 212 recent_tabs_builder.AddSession(); | 217 recent_tabs_builder.AddSession(); |
| 213 for (int w = 0; w < 2; ++w) { | 218 for (int w = 0; w < 2; ++w) { |
| 214 recent_tabs_builder.AddWindow(0); | 219 recent_tabs_builder.AddWindow(0); |
| 215 for (int t = 0; t < 5; ++t) | 220 for (int t = 0; t < 5; ++t) |
| 216 recent_tabs_builder.AddTab(0, w); | 221 recent_tabs_builder.AddTab(0, w); |
| 217 } | 222 } |
| 218 recent_tabs_builder.RegisterRecentTabs(&associator_); | 223 recent_tabs_builder.RegisterRecentTabs(&associator_); |
| 219 | 224 |
| 220 // Verify that data is populated correctly in RecentTabsSubMenuModel. | 225 // Verify that data is populated correctly in RecentTabsSubMenuModel. |
| 221 // Expected menu: | 226 // Expected menu: |
| 222 // - max tabs per session is 4, so only 4 most-recent tabs will show, | 227 // - max tabs per session is 4, so only 4 most-recent tabs will show, |
| 223 // independent of which window they came from | 228 // independent of which window they came from. |
| 224 // Menu index Menu items | 229 // Menu index Menu items |
| 225 // -------------------------------------- | 230 // -------------------------------------- |
| 226 // 0 Reopen closed tab | 231 // 0 Reopen closed tab |
| 227 // 1 <separator> | 232 // 1 <separator> |
| 228 // 2 <section header for session> | 233 // 2 <section header for session> |
| 229 // 3-6 <4 most-recent tabs of session> | 234 // 3-6 <4 most-recent tabs of session> |
| 235 // 7 <separator> |
| 236 // 8 Devices and history... |
| 230 | 237 |
| 231 TestRecentTabsSubMenuModel model(NULL, browser(), &associator_, true); | 238 TestRecentTabsSubMenuModel model(NULL, browser(), &associator_, true); |
| 232 int num_items = model.GetItemCount(); | 239 int num_items = model.GetItemCount(); |
| 233 EXPECT_EQ(7, num_items); | 240 EXPECT_EQ(9, num_items); |
| 234 | 241 |
| 235 std::vector<string16> tab_titles = | 242 std::vector<string16> tab_titles = |
| 236 recent_tabs_builder.GetTabTitlesSortedByRecency(); | 243 recent_tabs_builder.GetTabTitlesSortedByRecency(); |
| 237 for (int i = 0; i < 4; ++i) | 244 for (int i = 0; i < 4; ++i) |
| 238 EXPECT_EQ(tab_titles[i], model.GetLabelAt(i + 3)); | 245 EXPECT_EQ(tab_titles[i], model.GetLabelAt(i + 3)); |
| 239 } | 246 } |
| 240 | 247 |
| 241 TEST_F(RecentTabsSubMenuModelTest, MaxWidth) { | 248 TEST_F(RecentTabsSubMenuModelTest, MaxWidth) { |
| 242 // Create 1 session with 1 window and 1 tab. | 249 // Create 1 session with 1 window and 1 tab. |
| 243 RecentTabsBuilderTestHelper recent_tabs_builder; | 250 RecentTabsBuilderTestHelper recent_tabs_builder; |
| 244 recent_tabs_builder.AddSession(); | 251 recent_tabs_builder.AddSession(); |
| 245 recent_tabs_builder.AddWindow(0); | 252 recent_tabs_builder.AddWindow(0); |
| 246 recent_tabs_builder.AddTab(0, 0); | 253 recent_tabs_builder.AddTab(0, 0); |
| 247 recent_tabs_builder.RegisterRecentTabs(&associator_); | 254 recent_tabs_builder.RegisterRecentTabs(&associator_); |
| 248 | 255 |
| 249 // Menu index Menu items | 256 // Menu index Menu items |
| 250 // -------------------------------------- | 257 // -------------------------------------- |
| 251 // 0 Reopen closed tab | 258 // 0 Reopen closed tab |
| 252 // 1 <separator> | 259 // 1 <separator> |
| 253 // 2 <section header for 1st session> | 260 // 2 <section header for 1st session> |
| 254 // 3 <the only tab of the only window of session 1> | 261 // 3 <the only tab of the only window of session 1> |
| 262 // 4 <separator> |
| 263 // 5 Devices and history... |
| 255 | 264 |
| 256 TestRecentTabsSubMenuModel model(NULL, browser(), &associator_, true); | 265 TestRecentTabsSubMenuModel model(NULL, browser(), &associator_, true); |
| 257 EXPECT_EQ(4, model.GetItemCount()); | 266 EXPECT_EQ(6, model.GetItemCount()); |
| 258 EXPECT_EQ(-1, model.GetMaxWidthForItemAtIndex(0)); | 267 EXPECT_EQ(-1, model.GetMaxWidthForItemAtIndex(0)); |
| 259 EXPECT_NE(-1, model.GetMaxWidthForItemAtIndex(1)); | 268 EXPECT_NE(-1, model.GetMaxWidthForItemAtIndex(1)); |
| 260 EXPECT_NE(-1, model.GetMaxWidthForItemAtIndex(2)); | 269 EXPECT_NE(-1, model.GetMaxWidthForItemAtIndex(2)); |
| 261 EXPECT_NE(-1, model.GetMaxWidthForItemAtIndex(3)); | 270 EXPECT_NE(-1, model.GetMaxWidthForItemAtIndex(3)); |
| 262 } | 271 } |
| 263 | 272 |
| 264 TEST_F(RecentTabsSubMenuModelTest, MaxWidthNoDevices) { | 273 TEST_F(RecentTabsSubMenuModelTest, MaxWidthNoDevices) { |
| 265 // Expected menu: | 274 // Expected menu: |
| 266 // Menu index Menu items | 275 // Menu index Menu items |
| 267 // -------------------------------------- | 276 // -------------------------------------- |
| 268 // 0 Reopen closed tab | 277 // 0 Reopen closed tab |
| 269 // 1 <separator> | 278 // 1 <separator> |
| 270 // 2 No tabs from other Devices | 279 // 2 No tabs from other Devices |
| 271 | 280 |
| 272 TestRecentTabsSubMenuModel model(NULL, browser(), NULL, false); | 281 TestRecentTabsSubMenuModel model(NULL, browser(), NULL, false); |
| 273 EXPECT_EQ(3, model.GetItemCount()); | 282 EXPECT_EQ(3, model.GetItemCount()); |
| 274 EXPECT_EQ(-1, model.GetMaxWidthForItemAtIndex(0)); | 283 EXPECT_EQ(-1, model.GetMaxWidthForItemAtIndex(0)); |
| 275 EXPECT_NE(-1, model.GetMaxWidthForItemAtIndex(1)); | 284 EXPECT_NE(-1, model.GetMaxWidthForItemAtIndex(1)); |
| 276 EXPECT_EQ(-1, model.GetMaxWidthForItemAtIndex(2)); | 285 EXPECT_EQ(-1, model.GetMaxWidthForItemAtIndex(2)); |
| 277 } | 286 } |
| OLD | NEW |