OLD | NEW |
1 // Copyright 2012 The Chromium Authors. All rights reserved. | 1 // Copyright 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 <string> | 7 #include <string> |
8 #include <vector> | 8 #include <vector> |
9 | 9 |
10 #include "base/command_line.h" | 10 #include "base/command_line.h" |
(...skipping 151 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
162 scoped_ptr<sync_driver::LocalDeviceInfoProviderMock> local_device_; | 162 scoped_ptr<sync_driver::LocalDeviceInfoProviderMock> local_device_; |
163 }; | 163 }; |
164 | 164 |
165 // Test disabled "Recently closed" header with no foreign tabs. | 165 // Test disabled "Recently closed" header with no foreign tabs. |
166 TEST_F(RecentTabsSubMenuModelTest, NoTabs) { | 166 TEST_F(RecentTabsSubMenuModelTest, NoTabs) { |
167 TestRecentTabsSubMenuModel model(NULL, browser(), NULL); | 167 TestRecentTabsSubMenuModel model(NULL, browser(), NULL); |
168 | 168 |
169 // Expected menu: | 169 // Expected menu: |
170 // Menu index Menu items | 170 // Menu index Menu items |
171 // --------------------------------------------- | 171 // --------------------------------------------- |
172 // 0 Recently closed header (disabled) | 172 // 0 History |
173 // 1 <separator> | 173 // 1 <separator> |
174 // 2 No tabs from other Devices | 174 // 2 Recently closed header (disabled) |
| 175 // 3 <separator> |
| 176 // 4 No tabs from other Devices |
175 | 177 |
176 int num_items = model.GetItemCount(); | 178 int num_items = model.GetItemCount(); |
177 EXPECT_EQ(3, num_items); | 179 EXPECT_EQ(5, num_items); |
178 EXPECT_FALSE(model.IsEnabledAt(0)); | |
179 EXPECT_FALSE(model.IsEnabledAt(2)); | 180 EXPECT_FALSE(model.IsEnabledAt(2)); |
| 181 EXPECT_FALSE(model.IsEnabledAt(4)); |
180 EXPECT_EQ(0, model.enable_count()); | 182 EXPECT_EQ(0, model.enable_count()); |
181 | 183 |
182 EXPECT_EQ(NULL, model.GetLabelFontListAt(0)); | 184 EXPECT_EQ(NULL, model.GetLabelFontListAt(0)); |
183 EXPECT_EQ(NULL, model.GetLabelFontListAt(1)); | 185 EXPECT_EQ(NULL, model.GetLabelFontListAt(1)); |
184 EXPECT_EQ(NULL, model.GetLabelFontListAt(2)); | 186 EXPECT_EQ(NULL, model.GetLabelFontListAt(2)); |
| 187 EXPECT_EQ(NULL, model.GetLabelFontListAt(3)); |
| 188 EXPECT_EQ(NULL, model.GetLabelFontListAt(4)); |
185 | 189 |
186 std::string url; | 190 std::string url; |
187 base::string16 title; | 191 base::string16 title; |
188 EXPECT_FALSE(model.GetURLAndTitleForItemAtIndex(0, &url, &title)); | 192 EXPECT_FALSE(model.GetURLAndTitleForItemAtIndex(0, &url, &title)); |
189 EXPECT_FALSE(model.GetURLAndTitleForItemAtIndex(1, &url, &title)); | 193 EXPECT_FALSE(model.GetURLAndTitleForItemAtIndex(1, &url, &title)); |
190 EXPECT_FALSE(model.GetURLAndTitleForItemAtIndex(2, &url, &title)); | 194 EXPECT_FALSE(model.GetURLAndTitleForItemAtIndex(2, &url, &title)); |
| 195 EXPECT_FALSE(model.GetURLAndTitleForItemAtIndex(3, &url, &title)); |
| 196 EXPECT_FALSE(model.GetURLAndTitleForItemAtIndex(4, &url, &title)); |
191 } | 197 } |
192 | 198 |
193 // Test enabled "Recently closed" header with no foreign tabs. | 199 // Test enabled "Recently closed" header with no foreign tabs. |
194 TEST_F(RecentTabsSubMenuModelTest, RecentlyClosedTabsFromCurrentSession) { | 200 TEST_F(RecentTabsSubMenuModelTest, RecentlyClosedTabsFromCurrentSession) { |
195 TabRestoreServiceFactory::GetInstance()->SetTestingFactory( | 201 TabRestoreServiceFactory::GetInstance()->SetTestingFactory( |
196 profile(), RecentTabsSubMenuModelTest::GetTabRestoreService); | 202 profile(), RecentTabsSubMenuModelTest::GetTabRestoreService); |
197 | 203 |
198 // Add 2 tabs and close them. | 204 // Add 2 tabs and close them. |
199 AddTab(browser(), GURL("http://foo/1")); | 205 AddTab(browser(), GURL("http://foo/1")); |
200 AddTab(browser(), GURL("http://foo/2")); | 206 AddTab(browser(), GURL("http://foo/2")); |
201 browser()->tab_strip_model()->CloseAllTabs(); | 207 browser()->tab_strip_model()->CloseAllTabs(); |
202 | 208 |
203 TestRecentTabsSubMenuModel model(NULL, browser(), NULL); | 209 TestRecentTabsSubMenuModel model(NULL, browser(), NULL); |
204 // Expected menu: | 210 // Expected menu: |
205 // Menu index Menu items | 211 // Menu index Menu items |
206 // -------------------------------------- | 212 // -------------------------------------- |
207 // 0 Recently closed header | 213 // 0 History |
208 // 1 <tab for http://foo/2> | 214 // 1 <separator> |
209 // 2 <tab for http://foo/1> | 215 // 2 Recently closed header |
210 // 3 <separator> | 216 // 3 <tab for http://foo/2> |
211 // 4 No tabs from other Devices | 217 // 4 <tab for http://foo/1> |
| 218 // 5 <separator> |
| 219 // 6 No tabs from other Devices |
212 int num_items = model.GetItemCount(); | 220 int num_items = model.GetItemCount(); |
213 EXPECT_EQ(5, num_items); | 221 EXPECT_EQ(7, num_items); |
214 EXPECT_FALSE(model.IsEnabledAt(0)); | 222 EXPECT_TRUE(model.IsEnabledAt(0)); |
| 223 model.ActivatedAt(0); |
215 EXPECT_TRUE(model.IsEnabledAt(1)); | 224 EXPECT_TRUE(model.IsEnabledAt(1)); |
216 EXPECT_TRUE(model.IsEnabledAt(2)); | 225 EXPECT_FALSE(model.IsEnabledAt(2)); |
217 model.ActivatedAt(1); | 226 EXPECT_TRUE(model.IsEnabledAt(3)); |
218 model.ActivatedAt(2); | 227 EXPECT_TRUE(model.IsEnabledAt(4)); |
219 EXPECT_FALSE(model.IsEnabledAt(4)); | 228 model.ActivatedAt(3); |
220 EXPECT_EQ(2, model.enable_count()); | 229 model.ActivatedAt(4); |
221 EXPECT_EQ(2, model.execute_count()); | 230 EXPECT_FALSE(model.IsEnabledAt(6)); |
| 231 EXPECT_EQ(3, model.enable_count()); |
| 232 EXPECT_EQ(3, model.execute_count()); |
222 | 233 |
223 EXPECT_TRUE(model.GetLabelFontListAt(0) != NULL); | 234 EXPECT_EQ(NULL, model.GetLabelFontListAt(0)); |
224 EXPECT_EQ(NULL, model.GetLabelFontListAt(1)); | 235 EXPECT_EQ(NULL, model.GetLabelFontListAt(1)); |
225 EXPECT_EQ(NULL, model.GetLabelFontListAt(2)); | 236 EXPECT_TRUE(model.GetLabelFontListAt(2) != nullptr); |
226 EXPECT_EQ(NULL, model.GetLabelFontListAt(3)); | 237 EXPECT_EQ(NULL, model.GetLabelFontListAt(3)); |
227 EXPECT_EQ(NULL, model.GetLabelFontListAt(4)); | 238 EXPECT_EQ(NULL, model.GetLabelFontListAt(4)); |
| 239 EXPECT_EQ(NULL, model.GetLabelFontListAt(5)); |
| 240 EXPECT_EQ(NULL, model.GetLabelFontListAt(6)); |
228 | 241 |
229 std::string url; | 242 std::string url; |
230 base::string16 title; | 243 base::string16 title; |
231 EXPECT_FALSE(model.GetURLAndTitleForItemAtIndex(0, &url, &title)); | 244 EXPECT_FALSE(model.GetURLAndTitleForItemAtIndex(0, &url, &title)); |
232 EXPECT_TRUE(model.GetURLAndTitleForItemAtIndex(1, &url, &title)); | 245 EXPECT_FALSE(model.GetURLAndTitleForItemAtIndex(1, &url, &title)); |
233 EXPECT_TRUE(model.GetURLAndTitleForItemAtIndex(2, &url, &title)); | 246 EXPECT_FALSE(model.GetURLAndTitleForItemAtIndex(2, &url, &title)); |
234 EXPECT_FALSE(model.GetURLAndTitleForItemAtIndex(3, &url, &title)); | 247 EXPECT_TRUE(model.GetURLAndTitleForItemAtIndex(3, &url, &title)); |
235 EXPECT_FALSE(model.GetURLAndTitleForItemAtIndex(4, &url, &title)); | 248 EXPECT_TRUE(model.GetURLAndTitleForItemAtIndex(4, &url, &title)); |
| 249 EXPECT_FALSE(model.GetURLAndTitleForItemAtIndex(5, &url, &title)); |
| 250 EXPECT_FALSE(model.GetURLAndTitleForItemAtIndex(6, &url, &title)); |
236 } | 251 } |
237 | 252 |
238 // TODO(sail): enable this test when dynamic model is enabled in | 253 // TODO(sail): enable this test when dynamic model is enabled in |
239 // RecentTabsSubMenuModel. | 254 // RecentTabsSubMenuModel. |
240 #if defined(OS_MACOSX) | 255 #if defined(OS_MACOSX) |
241 #define MAYBE_RecentlyClosedTabsAndWindowsFromLastSession \ | 256 #define MAYBE_RecentlyClosedTabsAndWindowsFromLastSession \ |
242 DISABLED_RecentlyClosedTabsAndWindowsFromLastSession | 257 DISABLED_RecentlyClosedTabsAndWindowsFromLastSession |
243 #else | 258 #else |
244 #define MAYBE_RecentlyClosedTabsAndWindowsFromLastSession \ | 259 #define MAYBE_RecentlyClosedTabsAndWindowsFromLastSession \ |
245 RecentlyClosedTabsAndWindowsFromLastSession | 260 RecentlyClosedTabsAndWindowsFromLastSession |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
285 // Let the shutdown of previous TabRestoreService run. | 300 // Let the shutdown of previous TabRestoreService run. |
286 content::RunAllBlockingPoolTasksUntilIdle(); | 301 content::RunAllBlockingPoolTasksUntilIdle(); |
287 | 302 |
288 TestRecentTabsSubMenuModel model(NULL, browser(), NULL); | 303 TestRecentTabsSubMenuModel model(NULL, browser(), NULL); |
289 TestRecentTabsMenuModelDelegate delegate(&model); | 304 TestRecentTabsMenuModelDelegate delegate(&model); |
290 EXPECT_FALSE(delegate.got_changes()); | 305 EXPECT_FALSE(delegate.got_changes()); |
291 | 306 |
292 // Expected menu before tabs/windows from last session are loaded: | 307 // Expected menu before tabs/windows from last session are loaded: |
293 // Menu index Menu items | 308 // Menu index Menu items |
294 // ---------------------------------------------------------------- | 309 // ---------------------------------------------------------------- |
295 // 0 Recently closed header | 310 // 0 History |
296 // 1 <separator> | 311 // 1 <separator> |
297 // 2 No tabs from other Devices | 312 // 2 Recently closed header |
| 313 // 3 <separator> |
| 314 // 4 No tabs from other Devices |
298 | 315 |
299 int num_items = model.GetItemCount(); | 316 int num_items = model.GetItemCount(); |
300 EXPECT_EQ(3, num_items); | 317 EXPECT_EQ(5, num_items); |
301 EXPECT_FALSE(model.IsEnabledAt(0)); | 318 EXPECT_TRUE(model.IsEnabledAt(0)); |
302 EXPECT_EQ(ui::MenuModel::TYPE_SEPARATOR, model.GetTypeAt(1)); | 319 EXPECT_EQ(ui::MenuModel::TYPE_SEPARATOR, model.GetTypeAt(1)); |
303 EXPECT_FALSE(model.IsEnabledAt(2)); | 320 EXPECT_FALSE(model.IsEnabledAt(2)); |
304 EXPECT_EQ(0, model.enable_count()); | 321 EXPECT_EQ(ui::MenuModel::TYPE_SEPARATOR, model.GetTypeAt(3)); |
| 322 EXPECT_FALSE(model.IsEnabledAt(4)); |
| 323 EXPECT_EQ(1, model.enable_count()); |
305 | 324 |
306 // Wait for tabs from last session to be loaded. | 325 // Wait for tabs from last session to be loaded. |
307 WaitForLoadFromLastSession(); | 326 WaitForLoadFromLastSession(); |
308 | 327 |
309 // Expected menu after tabs/windows from last session are loaded: | 328 // Expected menu after tabs/windows from last session are loaded: |
310 // Menu index Menu items | 329 // Menu index Menu items |
311 // -------------------------------------------------------------- | 330 // -------------------------------------------------------------- |
312 // 0 Recently closed header | 331 // 0 History |
313 // 1 <window for the tab http://wnd1/tab0> | 332 // 1 <separator> |
314 // 2 <tab for http://wnd0/tab1> | 333 // 2 Recently closed header |
315 // 3 <tab for http://wnd0/tab0> | 334 // 3 <window for the tab http://wnd1/tab0> |
316 // 4 <separator> | 335 // 4 <tab for http://wnd0/tab1> |
317 // 5 No tabs from other Devices | 336 // 5 <tab for http://wnd0/tab0> |
| 337 // 6 <separator> |
| 338 // 7 No tabs from other Devices |
318 | 339 |
319 EXPECT_TRUE(delegate.got_changes()); | 340 EXPECT_TRUE(delegate.got_changes()); |
320 | 341 |
321 num_items = model.GetItemCount(); | 342 num_items = model.GetItemCount(); |
322 EXPECT_EQ(6, num_items); | 343 EXPECT_EQ(8, num_items); |
323 EXPECT_FALSE(model.IsEnabledAt(0)); | 344 |
| 345 EXPECT_TRUE(model.IsEnabledAt(0)); |
| 346 model.ActivatedAt(0); |
324 EXPECT_TRUE(model.IsEnabledAt(1)); | 347 EXPECT_TRUE(model.IsEnabledAt(1)); |
325 EXPECT_TRUE(model.IsEnabledAt(2)); | 348 EXPECT_EQ(ui::MenuModel::TYPE_SEPARATOR, model.GetTypeAt(1)); |
| 349 EXPECT_FALSE(model.IsEnabledAt(2)); |
326 EXPECT_TRUE(model.IsEnabledAt(3)); | 350 EXPECT_TRUE(model.IsEnabledAt(3)); |
327 model.ActivatedAt(1); | 351 EXPECT_TRUE(model.IsEnabledAt(4)); |
328 model.ActivatedAt(2); | 352 EXPECT_TRUE(model.IsEnabledAt(5)); |
329 model.ActivatedAt(3); | 353 model.ActivatedAt(3); |
330 EXPECT_EQ(ui::MenuModel::TYPE_SEPARATOR, model.GetTypeAt(4)); | 354 model.ActivatedAt(4); |
331 EXPECT_FALSE(model.IsEnabledAt(5)); | 355 model.ActivatedAt(5); |
332 EXPECT_EQ(3, model.enable_count()); | 356 EXPECT_EQ(ui::MenuModel::TYPE_SEPARATOR, model.GetTypeAt(6)); |
333 EXPECT_EQ(3, model.execute_count()); | 357 EXPECT_FALSE(model.IsEnabledAt(7)); |
| 358 EXPECT_EQ(5, model.enable_count()); |
| 359 EXPECT_EQ(4, model.execute_count()); |
334 | 360 |
335 EXPECT_TRUE(model.GetLabelFontListAt(0) != NULL); | 361 EXPECT_EQ(NULL, model.GetLabelFontListAt(0)); |
336 EXPECT_EQ(NULL, model.GetLabelFontListAt(1)); | 362 EXPECT_EQ(NULL, model.GetLabelFontListAt(1)); |
337 EXPECT_EQ(NULL, model.GetLabelFontListAt(2)); | 363 EXPECT_TRUE(model.GetLabelFontListAt(2) != nullptr); |
338 EXPECT_EQ(NULL, model.GetLabelFontListAt(3)); | 364 EXPECT_EQ(NULL, model.GetLabelFontListAt(3)); |
339 EXPECT_EQ(NULL, model.GetLabelFontListAt(4)); | 365 EXPECT_EQ(NULL, model.GetLabelFontListAt(4)); |
340 EXPECT_EQ(NULL, model.GetLabelFontListAt(5)); | 366 EXPECT_EQ(NULL, model.GetLabelFontListAt(5)); |
| 367 EXPECT_EQ(NULL, model.GetLabelFontListAt(6)); |
| 368 EXPECT_EQ(NULL, model.GetLabelFontListAt(7)); |
341 | 369 |
342 std::string url; | 370 std::string url; |
343 base::string16 title; | 371 base::string16 title; |
344 EXPECT_FALSE(model.GetURLAndTitleForItemAtIndex(0, &url, &title)); | 372 EXPECT_FALSE(model.GetURLAndTitleForItemAtIndex(0, &url, &title)); |
345 EXPECT_FALSE(model.GetURLAndTitleForItemAtIndex(1, &url, &title)); | 373 EXPECT_FALSE(model.GetURLAndTitleForItemAtIndex(1, &url, &title)); |
346 EXPECT_TRUE(model.GetURLAndTitleForItemAtIndex(2, &url, &title)); | 374 EXPECT_FALSE(model.GetURLAndTitleForItemAtIndex(2, &url, &title)); |
347 EXPECT_TRUE(model.GetURLAndTitleForItemAtIndex(3, &url, &title)); | 375 EXPECT_FALSE(model.GetURLAndTitleForItemAtIndex(3, &url, &title)); |
348 EXPECT_FALSE(model.GetURLAndTitleForItemAtIndex(4, &url, &title)); | 376 EXPECT_TRUE(model.GetURLAndTitleForItemAtIndex(4, &url, &title)); |
349 EXPECT_FALSE(model.GetURLAndTitleForItemAtIndex(5, &url, &title)); | 377 EXPECT_TRUE(model.GetURLAndTitleForItemAtIndex(5, &url, &title)); |
| 378 EXPECT_FALSE(model.GetURLAndTitleForItemAtIndex(6, &url, &title)); |
| 379 EXPECT_FALSE(model.GetURLAndTitleForItemAtIndex(7, &url, &title)); |
350 } | 380 } |
351 | 381 |
352 // Test disabled "Recently closed" header with multiple sessions, multiple | 382 // Test disabled "Recently closed" header with multiple sessions, multiple |
353 // windows, and multiple enabled tabs from other devices. | 383 // windows, and multiple enabled tabs from other devices. |
354 TEST_F(RecentTabsSubMenuModelTest, OtherDevices) { | 384 TEST_F(RecentTabsSubMenuModelTest, OtherDevices) { |
355 // Tabs are populated in decreasing timestamp. | 385 // Tabs are populated in decreasing timestamp. |
356 base::Time timestamp = base::Time::Now(); | 386 base::Time timestamp = base::Time::Now(); |
357 const base::TimeDelta time_delta = base::TimeDelta::FromMinutes(10); | 387 const base::TimeDelta time_delta = base::TimeDelta::FromMinutes(10); |
358 | 388 |
359 RecentTabsBuilderTestHelper recent_tabs_builder; | 389 RecentTabsBuilderTestHelper recent_tabs_builder; |
(...skipping 17 matching lines...) Expand all Loading... |
377 timestamp -= time_delta; | 407 timestamp -= time_delta; |
378 recent_tabs_builder.AddTabWithInfo(1, 1, timestamp, base::string16()); | 408 recent_tabs_builder.AddTabWithInfo(1, 1, timestamp, base::string16()); |
379 | 409 |
380 RegisterRecentTabs(&recent_tabs_builder); | 410 RegisterRecentTabs(&recent_tabs_builder); |
381 | 411 |
382 // Verify that data is populated correctly in RecentTabsSubMenuModel. | 412 // Verify that data is populated correctly in RecentTabsSubMenuModel. |
383 // Expected menu: | 413 // Expected menu: |
384 // - first inserted tab is most recent and hence is top | 414 // - first inserted tab is most recent and hence is top |
385 // Menu index Menu items | 415 // Menu index Menu items |
386 // ----------------------------------------------------- | 416 // ----------------------------------------------------- |
387 // 0 Recently closed header (disabled) | 417 // 0 History |
388 // 1 <separator> | 418 // 1 <separator> |
389 // 2 <section header for 1st session> | 419 // 2 Recently closed header (disabled) |
390 // 3-5 <3 tabs of the only window of session 0> | 420 // 3 <separator> |
391 // 6 <separator> | 421 // 4 <section header for 1st session> |
392 // 7 <section header for 2nd session> | 422 // 5-7 <3 tabs of the only window of session 0> |
393 // 8 <the only tab of window 0 of session 1> | 423 // 8 <separator> |
394 // 9-10 <2 tabs of window 1 of session 2> | 424 // 9 <section header for 2nd session> |
395 // 11 <separator> | 425 // 10 <the only tab of window 0 of session 1> |
396 // 12 More... | 426 // 11-12 <2 tabs of window 1 of session 2> |
397 | 427 |
398 TestRecentTabsSubMenuModel model(NULL, browser(), GetOpenTabsDelegate()); | 428 TestRecentTabsSubMenuModel model(NULL, browser(), GetOpenTabsDelegate()); |
399 int num_items = model.GetItemCount(); | 429 int num_items = model.GetItemCount(); |
400 EXPECT_EQ(13, num_items); | 430 EXPECT_EQ(13, num_items); |
401 model.ActivatedAt(0); | 431 model.ActivatedAt(0); |
402 EXPECT_FALSE(model.IsEnabledAt(0)); | 432 EXPECT_TRUE(model.IsEnabledAt(0)); |
| 433 model.ActivatedAt(1); |
| 434 EXPECT_TRUE(model.IsEnabledAt(1)); |
| 435 model.ActivatedAt(2); |
| 436 EXPECT_FALSE(model.IsEnabledAt(2)); |
403 model.ActivatedAt(3); | 437 model.ActivatedAt(3); |
404 EXPECT_TRUE(model.IsEnabledAt(3)); | 438 EXPECT_TRUE(model.IsEnabledAt(3)); |
405 model.ActivatedAt(4); | |
406 EXPECT_TRUE(model.IsEnabledAt(4)); | |
407 model.ActivatedAt(5); | 439 model.ActivatedAt(5); |
408 EXPECT_TRUE(model.IsEnabledAt(5)); | 440 EXPECT_TRUE(model.IsEnabledAt(5)); |
409 model.ActivatedAt(8); | 441 model.ActivatedAt(6); |
410 EXPECT_TRUE(model.IsEnabledAt(8)); | 442 EXPECT_TRUE(model.IsEnabledAt(6)); |
411 model.ActivatedAt(9); | 443 model.ActivatedAt(7); |
412 EXPECT_TRUE(model.IsEnabledAt(9)); | 444 EXPECT_TRUE(model.IsEnabledAt(7)); |
413 model.ActivatedAt(10); | 445 model.ActivatedAt(10); |
414 EXPECT_TRUE(model.IsEnabledAt(10)); | 446 EXPECT_TRUE(model.IsEnabledAt(10)); |
| 447 model.ActivatedAt(11); |
| 448 EXPECT_TRUE(model.IsEnabledAt(11)); |
| 449 model.ActivatedAt(12); |
415 EXPECT_TRUE(model.IsEnabledAt(12)); | 450 EXPECT_TRUE(model.IsEnabledAt(12)); |
| 451 |
416 EXPECT_EQ(7, model.enable_count()); | 452 EXPECT_EQ(7, model.enable_count()); |
417 EXPECT_EQ(7, model.execute_count()); | 453 EXPECT_EQ(10, model.execute_count()); |
418 | 454 |
419 EXPECT_EQ(NULL, model.GetLabelFontListAt(0)); | 455 EXPECT_EQ(NULL, model.GetLabelFontListAt(0)); |
420 EXPECT_EQ(NULL, model.GetLabelFontListAt(1)); | 456 EXPECT_EQ(NULL, model.GetLabelFontListAt(1)); |
421 EXPECT_TRUE(model.GetLabelFontListAt(2) != NULL); | 457 EXPECT_EQ(NULL, model.GetLabelFontListAt(2)); |
422 EXPECT_EQ(NULL, model.GetLabelFontListAt(3)); | 458 EXPECT_EQ(NULL, model.GetLabelFontListAt(3)); |
423 EXPECT_EQ(NULL, model.GetLabelFontListAt(4)); | 459 EXPECT_TRUE(model.GetLabelFontListAt(4) != nullptr); |
424 EXPECT_EQ(NULL, model.GetLabelFontListAt(5)); | 460 EXPECT_EQ(NULL, model.GetLabelFontListAt(5)); |
425 EXPECT_EQ(NULL, model.GetLabelFontListAt(6)); | 461 EXPECT_EQ(NULL, model.GetLabelFontListAt(6)); |
426 EXPECT_TRUE(model.GetLabelFontListAt(7) != NULL); | 462 EXPECT_EQ(NULL, model.GetLabelFontListAt(7)); |
427 EXPECT_EQ(NULL, model.GetLabelFontListAt(8)); | 463 EXPECT_EQ(NULL, model.GetLabelFontListAt(8)); |
428 EXPECT_EQ(NULL, model.GetLabelFontListAt(9)); | 464 EXPECT_TRUE(model.GetLabelFontListAt(9) != nullptr); |
429 EXPECT_EQ(NULL, model.GetLabelFontListAt(10)); | 465 EXPECT_EQ(NULL, model.GetLabelFontListAt(10)); |
430 EXPECT_EQ(NULL, model.GetLabelFontListAt(11)); | 466 EXPECT_EQ(NULL, model.GetLabelFontListAt(11)); |
431 EXPECT_EQ(NULL, model.GetLabelFontListAt(12)); | 467 EXPECT_EQ(NULL, model.GetLabelFontListAt(12)); |
432 | 468 |
433 std::string url; | 469 std::string url; |
434 base::string16 title; | 470 base::string16 title; |
435 EXPECT_FALSE(model.GetURLAndTitleForItemAtIndex(0, &url, &title)); | 471 EXPECT_FALSE(model.GetURLAndTitleForItemAtIndex(0, &url, &title)); |
436 EXPECT_FALSE(model.GetURLAndTitleForItemAtIndex(1, &url, &title)); | 472 EXPECT_FALSE(model.GetURLAndTitleForItemAtIndex(1, &url, &title)); |
437 EXPECT_FALSE(model.GetURLAndTitleForItemAtIndex(2, &url, &title)); | 473 EXPECT_FALSE(model.GetURLAndTitleForItemAtIndex(2, &url, &title)); |
438 EXPECT_TRUE(model.GetURLAndTitleForItemAtIndex(3, &url, &title)); | 474 EXPECT_FALSE(model.GetURLAndTitleForItemAtIndex(3, &url, &title)); |
439 EXPECT_TRUE(model.GetURLAndTitleForItemAtIndex(4, &url, &title)); | 475 EXPECT_FALSE(model.GetURLAndTitleForItemAtIndex(4, &url, &title)); |
440 EXPECT_TRUE(model.GetURLAndTitleForItemAtIndex(5, &url, &title)); | 476 EXPECT_TRUE(model.GetURLAndTitleForItemAtIndex(5, &url, &title)); |
441 EXPECT_FALSE(model.GetURLAndTitleForItemAtIndex(6, &url, &title)); | 477 EXPECT_TRUE(model.GetURLAndTitleForItemAtIndex(6, &url, &title)); |
442 EXPECT_FALSE(model.GetURLAndTitleForItemAtIndex(7, &url, &title)); | 478 EXPECT_TRUE(model.GetURLAndTitleForItemAtIndex(7, &url, &title)); |
443 EXPECT_TRUE(model.GetURLAndTitleForItemAtIndex(8, &url, &title)); | 479 EXPECT_FALSE(model.GetURLAndTitleForItemAtIndex(8, &url, &title)); |
444 EXPECT_TRUE(model.GetURLAndTitleForItemAtIndex(9, &url, &title)); | 480 EXPECT_FALSE(model.GetURLAndTitleForItemAtIndex(9, &url, &title)); |
445 EXPECT_TRUE(model.GetURLAndTitleForItemAtIndex(10, &url, &title)); | 481 EXPECT_TRUE(model.GetURLAndTitleForItemAtIndex(10, &url, &title)); |
446 EXPECT_FALSE(model.GetURLAndTitleForItemAtIndex(11, &url, &title)); | 482 EXPECT_TRUE(model.GetURLAndTitleForItemAtIndex(11, &url, &title)); |
447 EXPECT_FALSE(model.GetURLAndTitleForItemAtIndex(12, &url, &title)); | 483 EXPECT_TRUE(model.GetURLAndTitleForItemAtIndex(12, &url, &title)); |
448 } | 484 } |
449 | 485 |
450 TEST_F(RecentTabsSubMenuModelTest, MaxSessionsAndRecency) { | 486 TEST_F(RecentTabsSubMenuModelTest, MaxSessionsAndRecency) { |
451 // Create 4 sessions : each session has 1 window with 1 tab each. | 487 // Create 4 sessions : each session has 1 window with 1 tab each. |
452 RecentTabsBuilderTestHelper recent_tabs_builder; | 488 RecentTabsBuilderTestHelper recent_tabs_builder; |
453 for (int s = 0; s < 4; ++s) { | 489 for (int s = 0; s < 4; ++s) { |
454 recent_tabs_builder.AddSession(); | 490 recent_tabs_builder.AddSession(); |
455 recent_tabs_builder.AddWindow(s); | 491 recent_tabs_builder.AddWindow(s); |
456 recent_tabs_builder.AddTab(s, 0); | 492 recent_tabs_builder.AddTab(s, 0); |
457 } | 493 } |
458 RegisterRecentTabs(&recent_tabs_builder); | 494 RegisterRecentTabs(&recent_tabs_builder); |
459 | 495 |
460 // Verify that data is populated correctly in RecentTabsSubMenuModel. | 496 // Verify that data is populated correctly in RecentTabsSubMenuModel. |
461 // Expected menu: | 497 // Expected menu: |
462 // - max sessions is 3, so only 3 most-recent sessions will show. | 498 // - max sessions is 3, so only 3 most-recent sessions will show. |
463 // Menu index Menu items | 499 // Menu index Menu items |
464 // ---------------------------------------------------------- | 500 // ---------------------------------------------------------- |
465 // 0 Recently closed header (disabled) | 501 // 0 History |
466 // 1 <separator> | 502 // 1 <separator> |
467 // 2 <section header for 1st session> | 503 // 2 Recently closed header (disabled) |
468 // 3 <the only tab of the only window of session 3> | 504 // 3 <separator> |
469 // 4 <separator> | 505 // 4 <section header for 1st session> |
470 // 5 <section header for 2nd session> | 506 // 5 <the only tab of the only window of session 3> |
471 // 6 <the only tab of the only window of session 2> | 507 // 6 <separator> |
472 // 7 <separator> | 508 // 7 <section header for 2nd session> |
473 // 8 <section header for 3rd session> | 509 // 8 <the only tab of the only window of session 2> |
474 // 9 <the only tab of the only window of session 1> | 510 // 9 <separator> |
475 // 10 <separator> | 511 // 10 <section header for 3rd session> |
476 // 11 More... | 512 // 11 <the only tab of the only window of session 1> |
477 | 513 |
478 TestRecentTabsSubMenuModel model(NULL, browser(), GetOpenTabsDelegate()); | 514 TestRecentTabsSubMenuModel model(NULL, browser(), GetOpenTabsDelegate()); |
479 int num_items = model.GetItemCount(); | 515 int num_items = model.GetItemCount(); |
480 EXPECT_EQ(12, num_items); | 516 EXPECT_EQ(12, num_items); |
481 | 517 |
482 std::vector<base::string16> tab_titles = | 518 std::vector<base::string16> tab_titles = |
483 recent_tabs_builder.GetTabTitlesSortedByRecency(); | 519 recent_tabs_builder.GetTabTitlesSortedByRecency(); |
484 EXPECT_EQ(tab_titles[0], model.GetLabelAt(3)); | 520 EXPECT_EQ(tab_titles[0], model.GetLabelAt(5)); |
485 EXPECT_EQ(tab_titles[1], model.GetLabelAt(6)); | 521 EXPECT_EQ(tab_titles[1], model.GetLabelAt(8)); |
486 EXPECT_EQ(tab_titles[2], model.GetLabelAt(9)); | 522 EXPECT_EQ(tab_titles[2], model.GetLabelAt(11)); |
487 } | 523 } |
488 | 524 |
489 TEST_F(RecentTabsSubMenuModelTest, MaxTabsPerSessionAndRecency) { | 525 TEST_F(RecentTabsSubMenuModelTest, MaxTabsPerSessionAndRecency) { |
490 // Create a session: 2 windows with 5 tabs each. | 526 // Create a session: 2 windows with 5 tabs each. |
491 RecentTabsBuilderTestHelper recent_tabs_builder; | 527 RecentTabsBuilderTestHelper recent_tabs_builder; |
492 recent_tabs_builder.AddSession(); | 528 recent_tabs_builder.AddSession(); |
493 for (int w = 0; w < 2; ++w) { | 529 for (int w = 0; w < 2; ++w) { |
494 recent_tabs_builder.AddWindow(0); | 530 recent_tabs_builder.AddWindow(0); |
495 for (int t = 0; t < 5; ++t) | 531 for (int t = 0; t < 5; ++t) |
496 recent_tabs_builder.AddTab(0, w); | 532 recent_tabs_builder.AddTab(0, w); |
497 } | 533 } |
498 RegisterRecentTabs(&recent_tabs_builder); | 534 RegisterRecentTabs(&recent_tabs_builder); |
499 | 535 |
500 // Verify that data is populated correctly in RecentTabsSubMenuModel. | 536 // Verify that data is populated correctly in RecentTabsSubMenuModel. |
501 // Expected menu: | 537 // Expected menu: |
502 // - max tabs per session is 4, so only 4 most-recent tabs will show, | 538 // - max tabs per session is 4, so only 4 most-recent tabs will show, |
503 // independent of which window they came from. | 539 // independent of which window they came from. |
504 // Menu index Menu items | 540 // Menu index Menu items |
505 // --------------------------------------------- | 541 // --------------------------------------------- |
506 // 0 Recently closed header (disabled) | 542 // 0 History |
507 // 1 <separator> | 543 // 1 <separator> |
508 // 2 <section header for session> | 544 // 2 Recently closed header (disabled) |
509 // 3-6 <4 most-recent tabs of session> | 545 // 3 <separator> |
510 // 7 <separator> | 546 // 4 <section header for session> |
511 // 8 More... | 547 // 5-8 <4 most-recent tabs of session> |
512 | 548 |
513 TestRecentTabsSubMenuModel model(NULL, browser(), GetOpenTabsDelegate()); | 549 TestRecentTabsSubMenuModel model(NULL, browser(), GetOpenTabsDelegate()); |
514 int num_items = model.GetItemCount(); | 550 int num_items = model.GetItemCount(); |
515 EXPECT_EQ(9, num_items); | 551 EXPECT_EQ(9, num_items); |
516 | 552 |
517 std::vector<base::string16> tab_titles = | 553 std::vector<base::string16> tab_titles = |
518 recent_tabs_builder.GetTabTitlesSortedByRecency(); | 554 recent_tabs_builder.GetTabTitlesSortedByRecency(); |
519 for (int i = 0; i < 4; ++i) | 555 for (int i = 0; i < 4; ++i) |
520 EXPECT_EQ(tab_titles[i], model.GetLabelAt(i + 3)); | 556 EXPECT_EQ(tab_titles[i], model.GetLabelAt(i + 5)); |
521 } | 557 } |
522 | 558 |
523 TEST_F(RecentTabsSubMenuModelTest, MaxWidth) { | 559 TEST_F(RecentTabsSubMenuModelTest, MaxWidth) { |
524 // Create 1 session with 1 window and 1 tab. | 560 // Create 1 session with 1 window and 1 tab. |
525 RecentTabsBuilderTestHelper recent_tabs_builder; | 561 RecentTabsBuilderTestHelper recent_tabs_builder; |
526 recent_tabs_builder.AddSession(); | 562 recent_tabs_builder.AddSession(); |
527 recent_tabs_builder.AddWindow(0); | 563 recent_tabs_builder.AddWindow(0); |
528 recent_tabs_builder.AddTab(0, 0); | 564 recent_tabs_builder.AddTab(0, 0); |
529 RegisterRecentTabs(&recent_tabs_builder); | 565 RegisterRecentTabs(&recent_tabs_builder); |
530 | 566 |
531 // Menu index Menu items | 567 // Menu index Menu items |
532 // ---------------------------------------------------------- | 568 // ---------------------------------------------------------- |
533 // 0 Recently closed header (disabled) | 569 // 0 History |
534 // 1 <separator> | 570 // 1 <separator> |
535 // 2 <section header for 1st session> | 571 // 2 Recently closed header (disabled) |
536 // 3 <the only tab of the only window of session 1> | 572 // 3 <separator> |
537 // 4 <separator> | 573 // 4 <section header for 1st session> |
538 // 5 More... | 574 // 5 <the only tab of the only window of session 1> |
539 | 575 |
540 TestRecentTabsSubMenuModel model(NULL, browser(), GetOpenTabsDelegate()); | 576 TestRecentTabsSubMenuModel model(NULL, browser(), GetOpenTabsDelegate()); |
541 EXPECT_EQ(6, model.GetItemCount()); | 577 EXPECT_EQ(6, model.GetItemCount()); |
542 EXPECT_EQ(-1, model.GetMaxWidthForItemAtIndex(0)); | 578 EXPECT_EQ(-1, model.GetMaxWidthForItemAtIndex(2)); |
543 EXPECT_NE(-1, model.GetMaxWidthForItemAtIndex(1)); | |
544 EXPECT_NE(-1, model.GetMaxWidthForItemAtIndex(2)); | |
545 EXPECT_NE(-1, model.GetMaxWidthForItemAtIndex(3)); | 579 EXPECT_NE(-1, model.GetMaxWidthForItemAtIndex(3)); |
| 580 EXPECT_NE(-1, model.GetMaxWidthForItemAtIndex(4)); |
| 581 EXPECT_NE(-1, model.GetMaxWidthForItemAtIndex(5)); |
546 } | 582 } |
547 | 583 |
548 TEST_F(RecentTabsSubMenuModelTest, MaxWidthNoDevices) { | 584 TEST_F(RecentTabsSubMenuModelTest, MaxWidthNoDevices) { |
549 // Expected menu: | 585 // Expected menu: |
550 // Menu index Menu items | 586 // Menu index Menu items |
551 // -------------------------------------------- | 587 // -------------------------------------------- |
552 // 0 Recently closed heaer (disabled) | 588 // 0 History |
553 // 1 <separator> | 589 // 1 <separator> |
554 // 2 No tabs from other Devices | 590 // 2 Recently closed heaer (disabled) |
| 591 // 3 <separator> |
| 592 // 4 No tabs from other Devices |
555 | 593 |
556 TestRecentTabsSubMenuModel model(NULL, browser(), NULL); | 594 TestRecentTabsSubMenuModel model(NULL, browser(), NULL); |
557 EXPECT_EQ(3, model.GetItemCount()); | 595 EXPECT_EQ(5, model.GetItemCount()); |
558 EXPECT_EQ(-1, model.GetMaxWidthForItemAtIndex(0)); | |
559 EXPECT_NE(-1, model.GetMaxWidthForItemAtIndex(1)); | |
560 EXPECT_EQ(-1, model.GetMaxWidthForItemAtIndex(2)); | 596 EXPECT_EQ(-1, model.GetMaxWidthForItemAtIndex(2)); |
| 597 EXPECT_NE(-1, model.GetMaxWidthForItemAtIndex(3)); |
| 598 EXPECT_EQ(-1, model.GetMaxWidthForItemAtIndex(4)); |
561 } | 599 } |
OLD | NEW |