Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(58)

Side by Side Diff: chrome/browser/tabs/tab_strip_model_unittest.cc

Issue 7033048: Multi-tab: Adding new Notification when tab selection changes. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fixing existing unit tests, adding new unit test for multiple selection. Created 9 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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 <map> 5 #include <map>
6 #include <string> 6 #include <string>
7 7
8 #include "base/file_path.h" 8 #include "base/file_path.h"
9 #include "base/file_util.h" 9 #include "base/file_util.h"
10 #include "base/memory/scoped_ptr.h" 10 #include "base/memory/scoped_ptr.h"
(...skipping 252 matching lines...) Expand 10 before | Expand all | Expand 10 after
263 std::map<TabContents*, int> foo_; 263 std::map<TabContents*, int> foo_;
264 264
265 // ProfileManager requires a base::SystemMonitor. 265 // ProfileManager requires a base::SystemMonitor.
266 base::SystemMonitor system_monitor; 266 base::SystemMonitor system_monitor;
267 267
268 ProfileManager pm_; 268 ProfileManager pm_;
269 }; 269 };
270 270
271 class MockTabStripModelObserver : public TabStripModelObserver { 271 class MockTabStripModelObserver : public TabStripModelObserver {
272 public: 272 public:
273 MockTabStripModelObserver() : empty_(true) {} 273 MockTabStripModelObserver() : empty_(true),
274 log_tab_selection_changed_(false),
275 model_(NULL) {}
276 explicit MockTabStripModelObserver(TabStripModel* model) :
277 empty_(true),
278 log_tab_selection_changed_(false),
279 model_(model) {}
274 ~MockTabStripModelObserver() { 280 ~MockTabStripModelObserver() {
275 STLDeleteContainerPointers(states_.begin(), states_.end()); 281 STLDeleteContainerPointers(states_.begin(), states_.end());
276 } 282 }
277 283
278 enum TabStripModelObserverAction { 284 enum TabStripModelObserverAction {
279 INSERT, 285 INSERT,
280 CLOSE, 286 CLOSE,
281 DETACH, 287 DETACH,
288 ACTIVATE,
282 SELECT, 289 SELECT,
283 MOVE, 290 MOVE,
284 CHANGE, 291 CHANGE,
285 PINNED, 292 PINNED,
286 REPLACED 293 REPLACED
287 }; 294 };
288 295
289 struct State { 296 struct State {
290 State(TabContentsWrapper* a_dst_contents, 297 State(TabContentsWrapper* a_dst_contents,
291 int a_dst_index, 298 int a_dst_index,
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
341 bool foreground) { 348 bool foreground) {
342 empty_ = false; 349 empty_ = false;
343 State* s = new State(contents, index, INSERT); 350 State* s = new State(contents, index, INSERT);
344 s->foreground = foreground; 351 s->foreground = foreground;
345 states_.push_back(s); 352 states_.push_back(s);
346 } 353 }
347 virtual void ActiveTabChanged(TabContentsWrapper* old_contents, 354 virtual void ActiveTabChanged(TabContentsWrapper* old_contents,
348 TabContentsWrapper* new_contents, 355 TabContentsWrapper* new_contents,
349 int index, 356 int index,
350 bool user_gesture) { 357 bool user_gesture) {
351 State* s = new State(new_contents, index, SELECT); 358 State* s = new State(new_contents, index, ACTIVATE);
352 s->src_contents = old_contents; 359 s->src_contents = old_contents;
353 s->user_gesture = user_gesture; 360 s->user_gesture = user_gesture;
354 states_.push_back(s); 361 states_.push_back(s);
355 } 362 }
363 virtual void TabSelectionChanged(const TabStripSelectionModel& old_model) {
364 if (!log_tab_selection_changed())
365 return;
366
367 State* s = new State(model()->GetActiveTabContents(),
368 model()->active_index(),
369 SELECT);
370 s->src_contents = model()->GetTabContentsAt(old_model.active());
371 s->src_index = old_model.active();
372 states_.push_back(s);
373 }
356 virtual void TabMoved( 374 virtual void TabMoved(
357 TabContentsWrapper* contents, int from_index, int to_index) { 375 TabContentsWrapper* contents, int from_index, int to_index) {
358 State* s = new State(contents, to_index, MOVE); 376 State* s = new State(contents, to_index, MOVE);
359 s->src_index = from_index; 377 s->src_index = from_index;
360 states_.push_back(s); 378 states_.push_back(s);
361 } 379 }
362 380
363 virtual void TabClosingAt(TabStripModel* tab_strip_model, 381 virtual void TabClosingAt(TabStripModel* tab_strip_model,
364 TabContentsWrapper* contents, 382 TabContentsWrapper* contents,
365 int index) { 383 int index) {
(...skipping 19 matching lines...) Expand all
385 } 403 }
386 virtual void TabStripEmpty() { 404 virtual void TabStripEmpty() {
387 empty_ = true; 405 empty_ = true;
388 } 406 }
389 407
390 void ClearStates() { 408 void ClearStates() {
391 STLDeleteContainerPointers(states_.begin(), states_.end()); 409 STLDeleteContainerPointers(states_.begin(), states_.end());
392 states_.clear(); 410 states_.clear();
393 } 411 }
394 412
413 void set_log_tab_selection_changed(bool flag) {
414 log_tab_selection_changed_ = flag;
415 }
416
395 bool empty() const { return empty_; } 417 bool empty() const { return empty_; }
418 bool log_tab_selection_changed() const { return log_tab_selection_changed_; }
419 TabStripModel* model() { return model_; }
396 420
397 private: 421 private:
398 std::vector<State*> states_; 422 std::vector<State*> states_;
399 423
400 bool empty_; 424 bool empty_;
425 // TODO(dpapad): Remove this variable and update TestBasicAPI so that it takes
426 // into account TabSelectionChanged notifications.
427 bool log_tab_selection_changed_;
428 TabStripModel* model_;
401 429
402 DISALLOW_COPY_AND_ASSIGN(MockTabStripModelObserver); 430 DISALLOW_COPY_AND_ASSIGN(MockTabStripModelObserver);
403 }; 431 };
404 432
405 TEST_F(TabStripModelTest, TestBasicAPI) { 433 TEST_F(TabStripModelTest, TestBasicAPI) {
406 TabStripDummyDelegate delegate(NULL); 434 TabStripDummyDelegate delegate(NULL);
407 TabStripModel tabstrip(&delegate, profile()); 435 TabStripModel tabstrip(&delegate, profile());
408 MockTabStripModelObserver observer; 436 MockTabStripModelObserver observer(&tabstrip);
409 tabstrip.AddObserver(&observer); 437 tabstrip.AddObserver(&observer);
410 438
411 EXPECT_TRUE(tabstrip.empty()); 439 EXPECT_TRUE(tabstrip.empty());
412 440
413 typedef MockTabStripModelObserver::State State; 441 typedef MockTabStripModelObserver::State State;
414 442
415 TabContentsWrapper* contents1 = CreateTabContents(); 443 TabContentsWrapper* contents1 = CreateTabContents();
416 444
417 // Note! The ordering of these tests is important, each subsequent test 445 // Note! The ordering of these tests is important, each subsequent test
418 // builds on the state established in the previous. This is important if you 446 // builds on the state established in the previous. This is important if you
419 // ever insert tests rather than append. 447 // ever insert tests rather than append.
420 448
421 // Test AppendTabContents, ContainsIndex 449 // Test AppendTabContents, ContainsIndex
422 { 450 {
423 EXPECT_FALSE(tabstrip.ContainsIndex(0)); 451 EXPECT_FALSE(tabstrip.ContainsIndex(0));
424 tabstrip.AppendTabContents(contents1, true); 452 tabstrip.AppendTabContents(contents1, true);
425 EXPECT_TRUE(tabstrip.ContainsIndex(0)); 453 EXPECT_TRUE(tabstrip.ContainsIndex(0));
426 EXPECT_EQ(1, tabstrip.count()); 454 EXPECT_EQ(1, tabstrip.count());
427 EXPECT_EQ(2, observer.GetStateCount()); 455 EXPECT_EQ(2, observer.GetStateCount());
428 State s1(contents1, 0, MockTabStripModelObserver::INSERT); 456 State s1(contents1, 0, MockTabStripModelObserver::INSERT);
429 s1.foreground = true; 457 s1.foreground = true;
430 EXPECT_TRUE(observer.StateEquals(0, s1)); 458 EXPECT_TRUE(observer.StateEquals(0, s1));
431 State s2(contents1, 0, MockTabStripModelObserver::SELECT); 459 State s2(contents1, 0, MockTabStripModelObserver::ACTIVATE);
432 s2.src_contents = NULL; 460 s2.src_contents = NULL;
433 EXPECT_TRUE(observer.StateEquals(1, s2)); 461 EXPECT_TRUE(observer.StateEquals(1, s2));
434 observer.ClearStates(); 462 observer.ClearStates();
435 } 463 }
436 464
437 // Test InsertTabContentsAt, foreground tab. 465 // Test InsertTabContentsAt, foreground tab.
438 TabContentsWrapper* contents2 = CreateTabContents(); 466 TabContentsWrapper* contents2 = CreateTabContents();
439 { 467 {
440 tabstrip.InsertTabContentsAt(1, contents2, TabStripModel::ADD_ACTIVE); 468 tabstrip.InsertTabContentsAt(1, contents2, TabStripModel::ADD_ACTIVE);
441 469
442 EXPECT_EQ(2, tabstrip.count()); 470 EXPECT_EQ(2, tabstrip.count());
443 EXPECT_EQ(2, observer.GetStateCount()); 471 EXPECT_EQ(2, observer.GetStateCount());
444 State s1(contents2, 1, MockTabStripModelObserver::INSERT); 472 State s1(contents2, 1, MockTabStripModelObserver::INSERT);
445 s1.foreground = true; 473 s1.foreground = true;
446 EXPECT_TRUE(observer.StateEquals(0, s1)); 474 EXPECT_TRUE(observer.StateEquals(0, s1));
447 State s2(contents2, 1, MockTabStripModelObserver::SELECT); 475 State s2(contents2, 1, MockTabStripModelObserver::ACTIVATE);
448 s2.src_contents = contents1; 476 s2.src_contents = contents1;
449 EXPECT_TRUE(observer.StateEquals(1, s2)); 477 EXPECT_TRUE(observer.StateEquals(1, s2));
450 observer.ClearStates(); 478 observer.ClearStates();
451 } 479 }
452 480
453 // Test InsertTabContentsAt, background tab. 481 // Test InsertTabContentsAt, background tab.
454 TabContentsWrapper* contents3 = CreateTabContents(); 482 TabContentsWrapper* contents3 = CreateTabContents();
455 { 483 {
456 tabstrip.InsertTabContentsAt(2, contents3, TabStripModel::ADD_NONE); 484 tabstrip.InsertTabContentsAt(2, contents3, TabStripModel::ADD_NONE);
457 485
458 EXPECT_EQ(3, tabstrip.count()); 486 EXPECT_EQ(3, tabstrip.count());
459 EXPECT_EQ(1, observer.GetStateCount()); 487 EXPECT_EQ(1, observer.GetStateCount());
460 State s1(contents3, 2, MockTabStripModelObserver::INSERT); 488 State s1(contents3, 2, MockTabStripModelObserver::INSERT);
461 s1.foreground = false; 489 s1.foreground = false;
462 EXPECT_TRUE(observer.StateEquals(0, s1)); 490 EXPECT_TRUE(observer.StateEquals(0, s1));
463 observer.ClearStates(); 491 observer.ClearStates();
464 } 492 }
465 493
466 // Test ActivateTabAt 494 // Test ActivateTabAt
467 { 495 {
468 tabstrip.ActivateTabAt(2, true); 496 tabstrip.ActivateTabAt(2, true);
469 EXPECT_EQ(1, observer.GetStateCount()); 497 EXPECT_EQ(1, observer.GetStateCount());
470 State s1(contents3, 2, MockTabStripModelObserver::SELECT); 498 State s1(contents3, 2, MockTabStripModelObserver::ACTIVATE);
471 s1.src_contents = contents2; 499 s1.src_contents = contents2;
472 s1.user_gesture = true; 500 s1.user_gesture = true;
473 EXPECT_TRUE(observer.StateEquals(0, s1)); 501 EXPECT_TRUE(observer.StateEquals(0, s1));
474 observer.ClearStates(); 502 observer.ClearStates();
475 } 503 }
476 504
477 // Test DetachTabContentsAt 505 // Test DetachTabContentsAt
478 { 506 {
479 // Detach 507 // Detach
480 TabContentsWrapper* detached = tabstrip.DetachTabContentsAt(2); 508 TabContentsWrapper* detached = tabstrip.DetachTabContentsAt(2);
481 // ... and append again because we want this for later. 509 // ... and append again because we want this for later.
482 tabstrip.AppendTabContents(detached, true); 510 tabstrip.AppendTabContents(detached, true);
483 EXPECT_EQ(4, observer.GetStateCount()); 511 EXPECT_EQ(4, observer.GetStateCount());
484 State s1(detached, 2, MockTabStripModelObserver::DETACH); 512 State s1(detached, 2, MockTabStripModelObserver::DETACH);
485 EXPECT_TRUE(observer.StateEquals(0, s1)); 513 EXPECT_TRUE(observer.StateEquals(0, s1));
486 State s2(contents2, 1, MockTabStripModelObserver::SELECT); 514 State s2(contents2, 1, MockTabStripModelObserver::ACTIVATE);
487 s2.src_contents = contents3; 515 s2.src_contents = contents3;
488 s2.user_gesture = false; 516 s2.user_gesture = false;
489 EXPECT_TRUE(observer.StateEquals(1, s2)); 517 EXPECT_TRUE(observer.StateEquals(1, s2));
490 State s3(detached, 2, MockTabStripModelObserver::INSERT); 518 State s3(detached, 2, MockTabStripModelObserver::INSERT);
491 s3.foreground = true; 519 s3.foreground = true;
492 EXPECT_TRUE(observer.StateEquals(2, s3)); 520 EXPECT_TRUE(observer.StateEquals(2, s3));
493 State s4(detached, 2, MockTabStripModelObserver::SELECT); 521 State s4(detached, 2, MockTabStripModelObserver::ACTIVATE);
494 s4.src_contents = contents2; 522 s4.src_contents = contents2;
495 s4.user_gesture = false; 523 s4.user_gesture = false;
496 EXPECT_TRUE(observer.StateEquals(3, s4)); 524 EXPECT_TRUE(observer.StateEquals(3, s4));
497 observer.ClearStates(); 525 observer.ClearStates();
498 } 526 }
499 527
500 // Test CloseTabContentsAt 528 // Test CloseTabContentsAt
501 { 529 {
502 // Let's test nothing happens when the delegate veto the close. 530 // Let's test nothing happens when the delegate veto the close.
503 delegate.set_can_close(false); 531 delegate.set_can_close(false);
504 EXPECT_FALSE(tabstrip.CloseTabContentsAt(2, TabStripModel::CLOSE_NONE)); 532 EXPECT_FALSE(tabstrip.CloseTabContentsAt(2, TabStripModel::CLOSE_NONE));
505 EXPECT_EQ(3, tabstrip.count()); 533 EXPECT_EQ(3, tabstrip.count());
506 EXPECT_EQ(0, observer.GetStateCount()); 534 EXPECT_EQ(0, observer.GetStateCount());
507 535
508 // Now let's close for real. 536 // Now let's close for real.
509 delegate.set_can_close(true); 537 delegate.set_can_close(true);
510 EXPECT_TRUE(tabstrip.CloseTabContentsAt(2, TabStripModel::CLOSE_NONE)); 538 EXPECT_TRUE(tabstrip.CloseTabContentsAt(2, TabStripModel::CLOSE_NONE));
511 EXPECT_EQ(2, tabstrip.count()); 539 EXPECT_EQ(2, tabstrip.count());
512 540
513 EXPECT_EQ(3, observer.GetStateCount()); 541 EXPECT_EQ(3, observer.GetStateCount());
514 State s1(contents3, 2, MockTabStripModelObserver::CLOSE); 542 State s1(contents3, 2, MockTabStripModelObserver::CLOSE);
515 EXPECT_TRUE(observer.StateEquals(0, s1)); 543 EXPECT_TRUE(observer.StateEquals(0, s1));
516 State s2(contents3, 2, MockTabStripModelObserver::DETACH); 544 State s2(contents3, 2, MockTabStripModelObserver::DETACH);
517 EXPECT_TRUE(observer.StateEquals(1, s2)); 545 EXPECT_TRUE(observer.StateEquals(1, s2));
518 State s3(contents2, 1, MockTabStripModelObserver::SELECT); 546 State s3(contents2, 1, MockTabStripModelObserver::ACTIVATE);
519 s3.src_contents = contents3; 547 s3.src_contents = contents3;
520 s3.user_gesture = false; 548 s3.user_gesture = false;
521 EXPECT_TRUE(observer.StateEquals(2, s3)); 549 EXPECT_TRUE(observer.StateEquals(2, s3));
522 observer.ClearStates(); 550 observer.ClearStates();
523 } 551 }
524 552
525 // Test MoveTabContentsAt, select_after_move == true 553 // Test MoveTabContentsAt, select_after_move == true
526 { 554 {
527 tabstrip.MoveTabContentsAt(1, 0, true); 555 tabstrip.MoveTabContentsAt(1, 0, true);
528 556
(...skipping 1153 matching lines...) Expand 10 before | Expand all | Expand 10 after
1682 strip.CloseTabContentsAt(strip.count() - 1, TabStripModel::CLOSE_NONE); 1710 strip.CloseTabContentsAt(strip.count() - 1, TabStripModel::CLOSE_NONE);
1683 EXPECT_EQ(page_d_contents, strip.GetTabContentsAt(strip.active_index())); 1711 EXPECT_EQ(page_d_contents, strip.GetTabContentsAt(strip.active_index()));
1684 1712
1685 strip.CloseAllTabs(); 1713 strip.CloseAllTabs();
1686 } 1714 }
1687 1715
1688 // Tests that fast shutdown is attempted appropriately. 1716 // Tests that fast shutdown is attempted appropriately.
1689 TEST_F(TabStripModelTest, FastShutdown) { 1717 TEST_F(TabStripModelTest, FastShutdown) {
1690 TabStripDummyDelegate delegate(NULL); 1718 TabStripDummyDelegate delegate(NULL);
1691 TabStripModel tabstrip(&delegate, profile()); 1719 TabStripModel tabstrip(&delegate, profile());
1692 MockTabStripModelObserver observer; 1720 MockTabStripModelObserver observer(&tabstrip);
1693 tabstrip.AddObserver(&observer); 1721 tabstrip.AddObserver(&observer);
1694 1722
1695 EXPECT_TRUE(tabstrip.empty()); 1723 EXPECT_TRUE(tabstrip.empty());
1696 1724
1697 // Make sure fast shutdown is attempted when tabs that share a RPH are shut 1725 // Make sure fast shutdown is attempted when tabs that share a RPH are shut
1698 // down. 1726 // down.
1699 { 1727 {
1700 TabContentsWrapper* contents1 = CreateTabContents(); 1728 TabContentsWrapper* contents1 = CreateTabContents();
1701 TabContentsWrapper* contents2 = 1729 TabContentsWrapper* contents2 =
1702 CreateTabContentsWithSharedRPH(contents1->tab_contents()); 1730 CreateTabContentsWithSharedRPH(contents1->tab_contents());
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
1743 1771
1744 tabstrip.CloseAllTabs(); 1772 tabstrip.CloseAllTabs();
1745 EXPECT_TRUE(tabstrip.empty()); 1773 EXPECT_TRUE(tabstrip.empty());
1746 } 1774 }
1747 } 1775 }
1748 1776
1749 // Tests various permutations of apps. 1777 // Tests various permutations of apps.
1750 TEST_F(TabStripModelTest, Apps) { 1778 TEST_F(TabStripModelTest, Apps) {
1751 TabStripDummyDelegate delegate(NULL); 1779 TabStripDummyDelegate delegate(NULL);
1752 TabStripModel tabstrip(&delegate, profile()); 1780 TabStripModel tabstrip(&delegate, profile());
1753 MockTabStripModelObserver observer; 1781 MockTabStripModelObserver observer(&tabstrip);
1754 tabstrip.AddObserver(&observer); 1782 tabstrip.AddObserver(&observer);
1755 1783
1756 EXPECT_TRUE(tabstrip.empty()); 1784 EXPECT_TRUE(tabstrip.empty());
1757 1785
1758 typedef MockTabStripModelObserver::State State; 1786 typedef MockTabStripModelObserver::State State;
1759 1787
1760 #if defined(OS_WIN) 1788 #if defined(OS_WIN)
1761 FilePath path(FILE_PATH_LITERAL("c:\\foo")); 1789 FilePath path(FILE_PATH_LITERAL("c:\\foo"));
1762 #elif defined(OS_POSIX) 1790 #elif defined(OS_POSIX)
1763 FilePath path(FILE_PATH_LITERAL("/foo")); 1791 FilePath path(FILE_PATH_LITERAL("/foo"));
(...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after
1869 observer.ClearStates(); 1897 observer.ClearStates();
1870 } 1898 }
1871 1899
1872 tabstrip.CloseAllTabs(); 1900 tabstrip.CloseAllTabs();
1873 } 1901 }
1874 1902
1875 // Tests various permutations of pinning tabs. 1903 // Tests various permutations of pinning tabs.
1876 TEST_F(TabStripModelTest, Pinning) { 1904 TEST_F(TabStripModelTest, Pinning) {
1877 TabStripDummyDelegate delegate(NULL); 1905 TabStripDummyDelegate delegate(NULL);
1878 TabStripModel tabstrip(&delegate, profile()); 1906 TabStripModel tabstrip(&delegate, profile());
1879 MockTabStripModelObserver observer; 1907 MockTabStripModelObserver observer(&tabstrip);
1880 tabstrip.AddObserver(&observer); 1908 tabstrip.AddObserver(&observer);
1881 1909
1882 EXPECT_TRUE(tabstrip.empty()); 1910 EXPECT_TRUE(tabstrip.empty());
1883 1911
1884 typedef MockTabStripModelObserver::State State; 1912 typedef MockTabStripModelObserver::State State;
1885 1913
1886 TabContentsWrapper* contents1 = CreateTabContents(); 1914 TabContentsWrapper* contents1 = CreateTabContents();
1887 TabContentsWrapper* contents2 = CreateTabContents(); 1915 TabContentsWrapper* contents2 = CreateTabContents();
1888 TabContentsWrapper* contents3 = CreateTabContents(); 1916 TabContentsWrapper* contents3 = CreateTabContents();
1889 1917
(...skipping 165 matching lines...) Expand 10 before | Expand all | Expand 10 after
2055 delete strip.ReplaceTabContentsAt(0, new_contents); 2083 delete strip.ReplaceTabContentsAt(0, new_contents);
2056 2084
2057 ASSERT_EQ(2, tabstrip_observer.GetStateCount()); 2085 ASSERT_EQ(2, tabstrip_observer.GetStateCount());
2058 2086
2059 // First event should be for replaced. 2087 // First event should be for replaced.
2060 State state(new_contents, 0, MockTabStripModelObserver::REPLACED); 2088 State state(new_contents, 0, MockTabStripModelObserver::REPLACED);
2061 state.src_contents = first_contents; 2089 state.src_contents = first_contents;
2062 EXPECT_TRUE(tabstrip_observer.StateEquals(0, state)); 2090 EXPECT_TRUE(tabstrip_observer.StateEquals(0, state));
2063 2091
2064 // And the second for selected. 2092 // And the second for selected.
2065 state = State(new_contents, 0, MockTabStripModelObserver::SELECT); 2093 state = State(new_contents, 0, MockTabStripModelObserver::ACTIVATE);
2066 state.src_contents = first_contents; 2094 state.src_contents = first_contents;
2067 EXPECT_TRUE(tabstrip_observer.StateEquals(1, state)); 2095 EXPECT_TRUE(tabstrip_observer.StateEquals(1, state));
2068 2096
2069 // Now add another tab and replace it, making sure we don't get a selected 2097 // Now add another tab and replace it, making sure we don't get a selected
2070 // event this time. 2098 // event this time.
2071 TabContentsWrapper* third_contents = CreateTabContents(); 2099 TabContentsWrapper* third_contents = CreateTabContents();
2072 strip.AddTabContents(third_contents, 1, PageTransition::TYPED, 2100 strip.AddTabContents(third_contents, 1, PageTransition::TYPED,
2073 TabStripModel::ADD_NONE); 2101 TabStripModel::ADD_NONE);
2074 2102
2075 tabstrip_observer.ClearStates(); 2103 tabstrip_observer.ClearStates();
(...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after
2174 strip.AppendTabContents(contents1, true); 2202 strip.AppendTabContents(contents1, true);
2175 strip.AppendTabContents(contents2, true); 2203 strip.AppendTabContents(contents2, true);
2176 strip.AppendTabContents(contents3, true); 2204 strip.AppendTabContents(contents3, true);
2177 strip.ToggleSelectionAt(1); 2205 strip.ToggleSelectionAt(1);
2178 strip.CloseSelectedTabs(); 2206 strip.CloseSelectedTabs();
2179 EXPECT_EQ(1, strip.count()); 2207 EXPECT_EQ(1, strip.count());
2180 EXPECT_EQ(0, strip.active_index()); 2208 EXPECT_EQ(0, strip.active_index());
2181 strip.CloseAllTabs(); 2209 strip.CloseAllTabs();
2182 } 2210 }
2183 2211
2212 TEST_F(TabStripModelTest, MultipleSelection) {
2213 TabStripDummyDelegate delegate(NULL);
2214 TabStripModel strip(&delegate, profile());
2215 MockTabStripModelObserver observer(&strip);
2216 TabContentsWrapper* contents0 = CreateTabContents();
2217 TabContentsWrapper* contents1 = CreateTabContents();
2218 TabContentsWrapper* contents2 = CreateTabContents();
2219 TabContentsWrapper* contents3 = CreateTabContents();
2220 strip.AppendTabContents(contents0, false);
2221 strip.AppendTabContents(contents1, false);
2222 strip.AppendTabContents(contents2, false);
2223 strip.AppendTabContents(contents3, false);
2224 observer.set_log_tab_selection_changed(true);
2225 strip.AddObserver(&observer);
2226
2227 // Selection and active tab change.
2228 strip.ActivateTabAt(3, true);
2229 ASSERT_EQ(2, observer.GetStateCount());
2230 ASSERT_EQ(observer.GetStateAt(0)->action,
2231 MockTabStripModelObserver::ACTIVATE);
2232 MockTabStripModelObserver::State s1(contents3, 3,
2233 MockTabStripModelObserver::SELECT);
2234 EXPECT_TRUE(observer.StateEquals(1, s1));
2235
2236 // Adding all tabs to selection, active tab is now at 0.
2237 strip.ExtendSelectionTo(0);
2238 ASSERT_EQ(4, observer.GetStateCount());
2239 ASSERT_EQ(observer.GetStateAt(2)->action,
2240 MockTabStripModelObserver::ACTIVATE);
2241 MockTabStripModelObserver::State s2(contents0, 0,
2242 MockTabStripModelObserver::SELECT);
2243 s2.src_contents = contents3;
2244 s2.src_index = 3;
2245 EXPECT_TRUE(observer.StateEquals(3, s2));
2246
2247 // Closing one of the selected tabs, not the active one.
2248 strip.CloseTabContentsAt(1, TabStripModel::CLOSE_NONE);
2249 EXPECT_EQ(3, strip.count());
2250 ASSERT_EQ(6, observer.GetStateCount());
2251 ASSERT_EQ(observer.GetStateAt(4)->action,
dpapad 2011/06/10 17:23:55 It seems that closing a selected tab does not resu
sky 2011/06/10 17:56:04 Yes, I think its a good idea to force the notifica
dpapad 2011/06/10 18:21:37 No, sending a TabSelectionChanged notification doe
sky 2011/06/10 19:25:24 Maybe I'm confused. Lets say you have {0} active a
dpapad 2011/06/13 21:36:18 You are right that the selection seems to not have
2252 MockTabStripModelObserver::CLOSE);
2253 ASSERT_EQ(observer.GetStateAt(5)->action,
2254 MockTabStripModelObserver::DETACH);
2255
2256 // Active tab is at 0, deselecting all but the active tab.
2257 strip.ToggleSelectionAt(1);
2258 strip.ToggleSelectionAt(2);
2259 ASSERT_EQ(8, observer.GetStateCount());
2260 ASSERT_EQ(observer.GetStateAt(6)->action,
2261 MockTabStripModelObserver::SELECT);
2262 ASSERT_EQ(observer.GetStateAt(7)->action,
2263 MockTabStripModelObserver::SELECT);
2264
2265 // Attempting to deselect the only selected tab, it is ignored (no
2266 // notifications being sent) and tab at 0 remains selected and active.
2267 strip.ToggleSelectionAt(0);
2268 ASSERT_EQ(8, observer.GetStateCount());
2269
2270 strip.RemoveObserver(&observer);
2271 strip.CloseAllTabs();
2272 }
2273
2184 // Verifies that if we change the selection from a multi selection to a single 2274 // Verifies that if we change the selection from a multi selection to a single
2185 // selection, but not in a way that changes the selected_index that 2275 // selection, but not in a way that changes the selected_index that
2186 // ActiveTabChanged is still invoked. 2276 // TabSelectionChanged is invoked.
2187 TEST_F(TabStripModelTest, MultipleToSingle) { 2277 TEST_F(TabStripModelTest, MultipleToSingle) {
2188 TabStripDummyDelegate delegate(NULL); 2278 TabStripDummyDelegate delegate(NULL);
2189 TabStripModel strip(&delegate, profile()); 2279 TabStripModel strip(&delegate, profile());
2190 TabContentsWrapper* contents1 = CreateTabContents(); 2280 TabContentsWrapper* contents1 = CreateTabContents();
2191 TabContentsWrapper* contents2 = CreateTabContents(); 2281 TabContentsWrapper* contents2 = CreateTabContents();
2192 strip.AppendTabContents(contents1, false); 2282 strip.AppendTabContents(contents1, false);
2193 strip.AppendTabContents(contents2, false); 2283 strip.AppendTabContents(contents2, false);
2194 strip.ToggleSelectionAt(0); 2284 strip.ToggleSelectionAt(0);
2195 strip.ToggleSelectionAt(1); 2285 strip.ToggleSelectionAt(1);
2196 2286
2197 MockTabStripModelObserver observer; 2287 MockTabStripModelObserver observer(&strip);
2288 observer.set_log_tab_selection_changed(true);
2198 strip.AddObserver(&observer); 2289 strip.AddObserver(&observer);
2199 // This changes the selection (0 is no longer selected) but the selected_index 2290 // This changes the selection (0 is no longer selected) but the selected_index
2200 // still remains at 1. 2291 // still remains at 1.
2201 strip.ActivateTabAt(1, true); 2292 strip.ActivateTabAt(1, true);
2202 ASSERT_EQ(1, observer.GetStateCount()); 2293 ASSERT_EQ(1, observer.GetStateCount());
2203 MockTabStripModelObserver::State s( 2294 MockTabStripModelObserver::State s(
2204 contents2, 1, MockTabStripModelObserver::SELECT); 2295 contents2, 1, MockTabStripModelObserver::SELECT);
2205 s.src_contents = contents2; 2296 s.src_contents = contents2;
2206 s.user_gesture = true; 2297 s.src_index = 1;
2298 s.user_gesture = false;
2207 EXPECT_TRUE(observer.StateEquals(0, s)); 2299 EXPECT_TRUE(observer.StateEquals(0, s));
2208 strip.RemoveObserver(&observer); 2300 strip.RemoveObserver(&observer);
2209 strip.CloseAllTabs(); 2301 strip.CloseAllTabs();
2210 } 2302 }
OLDNEW
« no previous file with comments | « chrome/browser/tabs/tab_strip_model_order_controller.cc ('k') | chrome/browser/tabs/tab_strip_selection_model.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698