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