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 100 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
111 base::Time timestamp = base::Time::Now(); | 111 base::Time timestamp = base::Time::Now(); |
112 const base::TimeDelta time_delta = base::TimeDelta::FromMinutes(10); | 112 const base::TimeDelta time_delta = base::TimeDelta::FromMinutes(10); |
113 | 113 |
114 RecentTabsBuilderTestHelper recent_tabs_builder; | 114 RecentTabsBuilderTestHelper recent_tabs_builder; |
115 | 115 |
116 // Create 1st session : 1 window, 3 tabs | 116 // Create 1st session : 1 window, 3 tabs |
117 recent_tabs_builder.AddSession(); | 117 recent_tabs_builder.AddSession(); |
118 recent_tabs_builder.AddWindow(0); | 118 recent_tabs_builder.AddWindow(0); |
119 for (int i = 0; i < 3; ++i) { | 119 for (int i = 0; i < 3; ++i) { |
120 timestamp -= time_delta; | 120 timestamp -= time_delta; |
121 recent_tabs_builder.AddTabWithTimestamp(0, 0, timestamp); | 121 recent_tabs_builder.AddTabWithInfo(0, 0, timestamp, string16()); |
122 } | 122 } |
123 | 123 |
124 // Create 2nd session : 2 windows, 1 tab in 1st window, 2 tabs in 2nd window | 124 // Create 2nd session : 2 windows, 1 tab in 1st window, 2 tabs in 2nd window |
125 recent_tabs_builder.AddSession(); | 125 recent_tabs_builder.AddSession(); |
126 recent_tabs_builder.AddWindow(1); | 126 recent_tabs_builder.AddWindow(1); |
127 recent_tabs_builder.AddWindow(1); | 127 recent_tabs_builder.AddWindow(1); |
128 timestamp -= time_delta; | 128 timestamp -= time_delta; |
129 recent_tabs_builder.AddTabWithTimestamp(1, 0, timestamp); | 129 recent_tabs_builder.AddTabWithInfo(1, 0, timestamp, string16()); |
130 timestamp -= time_delta; | 130 timestamp -= time_delta; |
131 recent_tabs_builder.AddTabWithTimestamp(1, 1, timestamp); | 131 recent_tabs_builder.AddTabWithInfo(1, 1, timestamp, string16()); |
132 timestamp -= time_delta; | 132 timestamp -= time_delta; |
133 recent_tabs_builder.AddTabWithTimestamp(1, 1, timestamp); | 133 recent_tabs_builder.AddTabWithInfo(1, 1, timestamp, string16()); |
134 | 134 |
135 recent_tabs_builder.RegisterRecentTabs(&associator_); | 135 recent_tabs_builder.RegisterRecentTabs(&associator_); |
136 | 136 |
137 // Verify that data is populated correctly in RecentTabsSubMenuModel. | 137 // Verify that data is populated correctly in RecentTabsSubMenuModel. |
138 // Expected menu: | 138 // Expected menu: |
139 // - first inserted tab is most recent and hence is top | 139 // - first inserted tab is most recent and hence is top |
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> |
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
230 | 230 |
231 TestRecentTabsSubMenuModel model(NULL, browser(), &associator_, true); | 231 TestRecentTabsSubMenuModel model(NULL, browser(), &associator_, true); |
232 int num_items = model.GetItemCount(); | 232 int num_items = model.GetItemCount(); |
233 EXPECT_EQ(7, num_items); | 233 EXPECT_EQ(7, num_items); |
234 | 234 |
235 std::vector<string16> tab_titles = | 235 std::vector<string16> tab_titles = |
236 recent_tabs_builder.GetTabTitlesSortedByRecency(); | 236 recent_tabs_builder.GetTabTitlesSortedByRecency(); |
237 for (int i = 0; i < 4; ++i) | 237 for (int i = 0; i < 4; ++i) |
238 EXPECT_EQ(tab_titles[i], model.GetLabelAt(i + 3)); | 238 EXPECT_EQ(tab_titles[i], model.GetLabelAt(i + 3)); |
239 } | 239 } |
| 240 |
| 241 TEST_F(RecentTabsSubMenuModelTest, MaxWidth) { |
| 242 // Create 1 session with 1 window and 1 tab. |
| 243 RecentTabsBuilderTestHelper recent_tabs_builder; |
| 244 recent_tabs_builder.AddSession(); |
| 245 recent_tabs_builder.AddWindow(0); |
| 246 recent_tabs_builder.AddTab(0, 0); |
| 247 recent_tabs_builder.RegisterRecentTabs(&associator_); |
| 248 |
| 249 // Menu index Menu items |
| 250 // -------------------------------------- |
| 251 // 0 Reopen closed tab |
| 252 // 1 <separator> |
| 253 // 2 <section header for 1st session> |
| 254 // 3 <the only tab of the only window of session 1> |
| 255 |
| 256 TestRecentTabsSubMenuModel model(NULL, browser(), &associator_, true); |
| 257 EXPECT_EQ(4, model.GetItemCount()); |
| 258 EXPECT_EQ(-1, model.GetMaxWidthForItemAtIndex(0)); |
| 259 EXPECT_NE(-1, model.GetMaxWidthForItemAtIndex(1)); |
| 260 EXPECT_NE(-1, model.GetMaxWidthForItemAtIndex(2)); |
| 261 EXPECT_NE(-1, model.GetMaxWidthForItemAtIndex(3)); |
| 262 } |
| 263 |
| 264 TEST_F(RecentTabsSubMenuModelTest, MaxWidthNoDevices) { |
| 265 // Expected menu: |
| 266 // Menu index Menu items |
| 267 // -------------------------------------- |
| 268 // 0 Reopen closed tab |
| 269 // 1 <separator> |
| 270 // 2 No tabs from other Devices |
| 271 |
| 272 TestRecentTabsSubMenuModel model(NULL, browser(), NULL, false); |
| 273 EXPECT_EQ(3, model.GetItemCount()); |
| 274 EXPECT_EQ(-1, model.GetMaxWidthForItemAtIndex(0)); |
| 275 EXPECT_NE(-1, model.GetMaxWidthForItemAtIndex(1)); |
| 276 EXPECT_EQ(-1, model.GetMaxWidthForItemAtIndex(2)); |
| 277 } |
OLD | NEW |