| 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/views/tabs/tab_strip.h" | 5 #include "chrome/browser/ui/views/tabs/tab_strip.h" |
| 6 | 6 |
| 7 #include "base/macros.h" | 7 #include "base/macros.h" |
| 8 #include "base/message_loop/message_loop.h" | 8 #include "base/message_loop/message_loop.h" |
| 9 #include "chrome/browser/ui/views/tabs/fake_base_tab_strip_controller.h" | 9 #include "chrome/browser/ui/views/tabs/fake_base_tab_strip_controller.h" |
| 10 #include "chrome/browser/ui/views/tabs/tab.h" | 10 #include "chrome/browser/ui/views/tabs/tab.h" |
| (...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 118 init_params.bounds = gfx::Rect(0, 0, 200, 200); | 118 init_params.bounds = gfx::Rect(0, 0, 200, 200); |
| 119 widget_->Init(init_params); | 119 widget_->Init(init_params); |
| 120 widget_->SetContentsView(&parent_); | 120 widget_->SetContentsView(&parent_); |
| 121 } | 121 } |
| 122 | 122 |
| 123 void TearDown() override { | 123 void TearDown() override { |
| 124 widget_.reset(); | 124 widget_.reset(); |
| 125 views::ViewsTestBase::TearDown(); | 125 views::ViewsTestBase::TearDown(); |
| 126 } | 126 } |
| 127 | 127 |
| 128 // Forces a call to OnPaint() for each tab in |tab_strip_| in order to | |
| 129 // trigger a layout, which is needed to update the visibility of tab | |
| 130 // close buttons after a tab switch or close. Note that painting does | |
| 131 // not occur in unit tests, which is why this helper is used. | |
| 132 void TriggerPaintOfAllTabs() { | |
| 133 gfx::Canvas canvas; | |
| 134 for (int i = 0; i < tab_strip_->tab_count(); ++i) | |
| 135 tab_strip_->tab_at(i)->OnPaint(&canvas); | |
| 136 } | |
| 137 | |
| 138 protected: | 128 protected: |
| 139 // Returns the rectangular hit test region of |tab| in |tab|'s local | 129 // Returns the rectangular hit test region of |tab| in |tab|'s local |
| 140 // coordinate space. | 130 // coordinate space. |
| 141 gfx::Rect GetTabHitTestMask(Tab* tab) { | 131 gfx::Rect GetTabHitTestMask(Tab* tab) { |
| 142 views::ViewTargeter* targeter = tab->targeter(); | 132 views::ViewTargeter* targeter = tab->targeter(); |
| 143 DCHECK(targeter); | 133 DCHECK(targeter); |
| 144 views::MaskedTargeterDelegate* delegate = | 134 views::MaskedTargeterDelegate* delegate = |
| 145 static_cast<views::MaskedTargeterDelegate*>(tab); | 135 static_cast<views::MaskedTargeterDelegate*>(tab); |
| 146 | 136 |
| 147 gfx::Path mask; | 137 gfx::Path mask; |
| (...skipping 287 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 435 controller_->AddTab(1, true); | 425 controller_->AddTab(1, true); |
| 436 controller_->AddTab(2, false); | 426 controller_->AddTab(2, false); |
| 437 ASSERT_EQ(3, tab_strip_->tab_count()); | 427 ASSERT_EQ(3, tab_strip_->tab_count()); |
| 438 | 428 |
| 439 Tab* tab0 = tab_strip_->tab_at(0); | 429 Tab* tab0 = tab_strip_->tab_at(0); |
| 440 Tab* tab1 = tab_strip_->tab_at(1); | 430 Tab* tab1 = tab_strip_->tab_at(1); |
| 441 ASSERT_TRUE(tab1->IsActive()); | 431 ASSERT_TRUE(tab1->IsActive()); |
| 442 Tab* tab2 = tab_strip_->tab_at(2); | 432 Tab* tab2 = tab_strip_->tab_at(2); |
| 443 | 433 |
| 444 // Ensure that all tab close buttons are initially visible. | 434 // Ensure that all tab close buttons are initially visible. |
| 445 TriggerPaintOfAllTabs(); | |
| 446 EXPECT_TRUE(tab0->showing_close_button_); | 435 EXPECT_TRUE(tab0->showing_close_button_); |
| 447 EXPECT_TRUE(tab1->showing_close_button_); | 436 EXPECT_TRUE(tab1->showing_close_button_); |
| 448 EXPECT_TRUE(tab2->showing_close_button_); | 437 EXPECT_TRUE(tab2->showing_close_button_); |
| 449 | 438 |
| 450 // Enter stacked layout mode and verify this sets |touch_layout_|. | 439 // Enter stacked layout mode and verify this sets |touch_layout_|. |
| 451 ASSERT_FALSE(tab_strip_->touch_layout_.get()); | 440 ASSERT_FALSE(tab_strip_->touch_layout_.get()); |
| 452 tab_strip_->SetStackedLayout(true); | 441 tab_strip_->SetStackedLayout(true); |
| 453 TriggerPaintOfAllTabs(); | |
| 454 ASSERT_TRUE(tab_strip_->touch_layout_.get()); | 442 ASSERT_TRUE(tab_strip_->touch_layout_.get()); |
| 455 | 443 |
| 456 // Only the close button of the active tab should be visible in stacked | 444 // Only the close button of the active tab should be visible in stacked |
| 457 // layout mode. | 445 // layout mode. |
| 458 EXPECT_FALSE(tab0->showing_close_button_); | 446 EXPECT_FALSE(tab0->showing_close_button_); |
| 459 EXPECT_TRUE(tab1->showing_close_button_); | 447 EXPECT_TRUE(tab1->showing_close_button_); |
| 460 EXPECT_FALSE(tab2->showing_close_button_); | 448 EXPECT_FALSE(tab2->showing_close_button_); |
| 461 | 449 |
| 462 // An inactive tab added to the tabstrip should not show | 450 // An inactive tab added to the tabstrip should not show |
| 463 // its tab close button. | 451 // its tab close button. |
| 464 controller_->AddTab(3, false); | 452 controller_->AddTab(3, false); |
| 465 Tab* tab3 = tab_strip_->tab_at(3); | 453 Tab* tab3 = tab_strip_->tab_at(3); |
| 466 EXPECT_FALSE(tab0->showing_close_button_); | 454 EXPECT_FALSE(tab0->showing_close_button_); |
| 467 EXPECT_TRUE(tab1->showing_close_button_); | 455 EXPECT_TRUE(tab1->showing_close_button_); |
| 468 EXPECT_FALSE(tab2->showing_close_button_); | 456 EXPECT_FALSE(tab2->showing_close_button_); |
| 469 EXPECT_FALSE(tab3->showing_close_button_); | 457 EXPECT_FALSE(tab3->showing_close_button_); |
| 470 | 458 |
| 471 // After switching tabs, the previously-active tab should have its | 459 // After switching tabs, the previously-active tab should have its |
| 472 // tab close button hidden and the newly-active tab should show | 460 // tab close button hidden and the newly-active tab should show |
| 473 // its tab close button. | 461 // its tab close button. |
| 474 tab_strip_->SelectTab(tab2); | 462 tab_strip_->SelectTab(tab2); |
| 475 TriggerPaintOfAllTabs(); | |
| 476 ASSERT_FALSE(tab1->IsActive()); | 463 ASSERT_FALSE(tab1->IsActive()); |
| 477 ASSERT_TRUE(tab2->IsActive()); | 464 ASSERT_TRUE(tab2->IsActive()); |
| 478 EXPECT_FALSE(tab0->showing_close_button_); | 465 EXPECT_FALSE(tab0->showing_close_button_); |
| 479 EXPECT_FALSE(tab1->showing_close_button_); | 466 EXPECT_FALSE(tab1->showing_close_button_); |
| 480 EXPECT_TRUE(tab2->showing_close_button_); | 467 EXPECT_TRUE(tab2->showing_close_button_); |
| 481 EXPECT_FALSE(tab3->showing_close_button_); | 468 EXPECT_FALSE(tab3->showing_close_button_); |
| 482 | 469 |
| 483 // After closing the active tab, the tab which becomes active should | 470 // After closing the active tab, the tab which becomes active should |
| 484 // show its tab close button. | 471 // show its tab close button. |
| 485 tab_strip_->CloseTab(tab1, CLOSE_TAB_FROM_TOUCH); | 472 tab_strip_->CloseTab(tab1, CLOSE_TAB_FROM_TOUCH); |
| 486 tab1 = nullptr; | 473 tab1 = nullptr; |
| 487 ASSERT_TRUE(tab2->IsActive()); | 474 ASSERT_TRUE(tab2->IsActive()); |
| 488 TriggerPaintOfAllTabs(); | |
| 489 EXPECT_FALSE(tab0->showing_close_button_); | 475 EXPECT_FALSE(tab0->showing_close_button_); |
| 490 EXPECT_TRUE(tab2->showing_close_button_); | 476 EXPECT_TRUE(tab2->showing_close_button_); |
| 491 EXPECT_FALSE(tab3->showing_close_button_); | 477 EXPECT_FALSE(tab3->showing_close_button_); |
| 492 | 478 |
| 493 // All tab close buttons should be shown when disengaging stacked tab mode. | 479 // All tab close buttons should be shown when disengaging stacked tab mode. |
| 494 tab_strip_->SetStackedLayout(false); | 480 tab_strip_->SetStackedLayout(false); |
| 495 TriggerPaintOfAllTabs(); | |
| 496 ASSERT_FALSE(tab_strip_->touch_layout_.get()); | 481 ASSERT_FALSE(tab_strip_->touch_layout_.get()); |
| 497 EXPECT_TRUE(tab0->showing_close_button_); | 482 EXPECT_TRUE(tab0->showing_close_button_); |
| 498 EXPECT_TRUE(tab2->showing_close_button_); | 483 EXPECT_TRUE(tab2->showing_close_button_); |
| 499 EXPECT_TRUE(tab3->showing_close_button_); | 484 EXPECT_TRUE(tab3->showing_close_button_); |
| 500 } | 485 } |
| 501 | 486 |
| 502 TEST_F(TabStripTest, GetEventHandlerForOverlappingArea) { | 487 TEST_F(TabStripTest, GetEventHandlerForOverlappingArea) { |
| 503 tab_strip_->SetBounds(0, 0, 1000, 20); | 488 tab_strip_->SetBounds(0, 0, 1000, 20); |
| 504 | 489 |
| 505 controller_->AddTab(0, false); | 490 controller_->AddTab(0, false); |
| (...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 622 ASSERT_TRUE(IsPointInTab(most_right_tab, unactive_overlap)); | 607 ASSERT_TRUE(IsPointInTab(most_right_tab, unactive_overlap)); |
| 623 | 608 |
| 624 EXPECT_EQ( | 609 EXPECT_EQ( |
| 625 right_tab, | 610 right_tab, |
| 626 FindTabView(tab_strip_->GetTooltipHandlerForPoint(unactive_overlap))); | 611 FindTabView(tab_strip_->GetTooltipHandlerForPoint(unactive_overlap))); |
| 627 | 612 |
| 628 // Confirm that tab strip doe not return tooltip handler for points that | 613 // Confirm that tab strip doe not return tooltip handler for points that |
| 629 // don't hit it. | 614 // don't hit it. |
| 630 EXPECT_FALSE(tab_strip_->GetTooltipHandlerForPoint(gfx::Point(-1, 2))); | 615 EXPECT_FALSE(tab_strip_->GetTooltipHandlerForPoint(gfx::Point(-1, 2))); |
| 631 } | 616 } |
| OLD | NEW |