| 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.h" | 5 #include "chrome/browser/ui/views/tabs/tab.h" |
| 6 | 6 |
| 7 #include "base/i18n/rtl.h" | 7 #include "base/i18n/rtl.h" |
| 8 #include "base/strings/utf_string_conversions.h" | 8 #include "base/strings/utf_string_conversions.h" |
| 9 #include "chrome/browser/ui/tabs/tab_utils.h" | 9 #include "chrome/browser/ui/tabs/tab_utils.h" |
| 10 #include "chrome/browser/ui/views/tabs/media_indicator_button.h" | 10 #include "chrome/browser/ui/views/tabs/media_indicator_button.h" |
| 11 #include "chrome/browser/ui/views/tabs/tab_controller.h" | 11 #include "chrome/browser/ui/views/tabs/tab_controller.h" |
| 12 #include "testing/gtest/include/gtest/gtest.h" | 12 #include "testing/gtest/include/gtest/gtest.h" |
| 13 #include "ui/base/models/list_selection_model.h" | 13 #include "ui/base/models/list_selection_model.h" |
| 14 #include "ui/views/controls/button/image_button.h" | 14 #include "ui/views/controls/button/image_button.h" |
| 15 #include "ui/views/controls/label.h" | 15 #include "ui/views/controls/label.h" |
| 16 #include "ui/views/test/views_test_base.h" | 16 #include "ui/views/test/views_test_base.h" |
| 17 #include "ui/views/widget/widget.h" | 17 #include "ui/views/widget/widget.h" |
| 18 | 18 |
| 19 using views::Widget; | 19 using views::Widget; |
| 20 | 20 |
| 21 class FakeTabController : public TabController { | 21 class FakeTabController : public TabController { |
| 22 public: | 22 public: |
| 23 FakeTabController() : immersive_style_(false), active_tab_(false) { | 23 FakeTabController() : immersive_style_(false), active_tab_(false) { |
| 24 } | 24 } |
| 25 virtual ~FakeTabController() {} | 25 ~FakeTabController() override {} |
| 26 | 26 |
| 27 void set_immersive_style(bool value) { immersive_style_ = value; } | 27 void set_immersive_style(bool value) { immersive_style_ = value; } |
| 28 void set_active_tab(bool value) { active_tab_ = value; } | 28 void set_active_tab(bool value) { active_tab_ = value; } |
| 29 | 29 |
| 30 virtual const ui::ListSelectionModel& GetSelectionModel() override { | 30 const ui::ListSelectionModel& GetSelectionModel() override { |
| 31 return selection_model_; | 31 return selection_model_; |
| 32 } | 32 } |
| 33 virtual bool SupportsMultipleSelection() override { return false; } | 33 bool SupportsMultipleSelection() override { return false; } |
| 34 virtual void SelectTab(Tab* tab) override {} | 34 void SelectTab(Tab* tab) override {} |
| 35 virtual void ExtendSelectionTo(Tab* tab) override {} | 35 void ExtendSelectionTo(Tab* tab) override {} |
| 36 virtual void ToggleSelected(Tab* tab) override {} | 36 void ToggleSelected(Tab* tab) override {} |
| 37 virtual void AddSelectionFromAnchorTo(Tab* tab) override {} | 37 void AddSelectionFromAnchorTo(Tab* tab) override {} |
| 38 virtual void CloseTab(Tab* tab, CloseTabSource source) override {} | 38 void CloseTab(Tab* tab, CloseTabSource source) override {} |
| 39 virtual void ToggleTabAudioMute(Tab* tab) override {} | 39 void ToggleTabAudioMute(Tab* tab) override {} |
| 40 virtual void ShowContextMenuForTab(Tab* tab, | 40 void ShowContextMenuForTab(Tab* tab, |
| 41 const gfx::Point& p, | 41 const gfx::Point& p, |
| 42 ui::MenuSourceType source_type) override {} | 42 ui::MenuSourceType source_type) override {} |
| 43 virtual bool IsActiveTab(const Tab* tab) const override { | 43 bool IsActiveTab(const Tab* tab) const override { return active_tab_; } |
| 44 return active_tab_; | 44 bool IsTabSelected(const Tab* tab) const override { return false; } |
| 45 } | 45 bool IsTabPinned(const Tab* tab) const override { return false; } |
| 46 virtual bool IsTabSelected(const Tab* tab) const override { | 46 void MaybeStartDrag( |
| 47 return false; | |
| 48 } | |
| 49 virtual bool IsTabPinned(const Tab* tab) const override { return false; } | |
| 50 virtual void MaybeStartDrag( | |
| 51 Tab* tab, | 47 Tab* tab, |
| 52 const ui::LocatedEvent& event, | 48 const ui::LocatedEvent& event, |
| 53 const ui::ListSelectionModel& original_selection) override {} | 49 const ui::ListSelectionModel& original_selection) override {} |
| 54 virtual void ContinueDrag(views::View* view, | 50 void ContinueDrag(views::View* view, const ui::LocatedEvent& event) override { |
| 55 const ui::LocatedEvent& event) override {} | 51 } |
| 56 virtual bool EndDrag(EndDragReason reason) override { return false; } | 52 bool EndDrag(EndDragReason reason) override { return false; } |
| 57 virtual Tab* GetTabAt(Tab* tab, | 53 Tab* GetTabAt(Tab* tab, const gfx::Point& tab_in_tab_coordinates) override { |
| 58 const gfx::Point& tab_in_tab_coordinates) override { | |
| 59 return NULL; | 54 return NULL; |
| 60 } | 55 } |
| 61 virtual void OnMouseEventInTab(views::View* source, | 56 void OnMouseEventInTab(views::View* source, |
| 62 const ui::MouseEvent& event) override {} | 57 const ui::MouseEvent& event) override {} |
| 63 virtual bool ShouldPaintTab(const Tab* tab, gfx::Rect* clip) override { | 58 bool ShouldPaintTab(const Tab* tab, gfx::Rect* clip) override { return true; } |
| 64 return true; | 59 bool IsImmersiveStyle() const override { return immersive_style_; } |
| 65 } | 60 void UpdateTabAccessibilityState(const Tab* tab, |
| 66 virtual bool IsImmersiveStyle() const override { return immersive_style_; } | 61 ui::AXViewState* state) override{}; |
| 67 virtual void UpdateTabAccessibilityState(const Tab* tab, | |
| 68 ui::AXViewState* state) override{}; | |
| 69 | 62 |
| 70 private: | 63 private: |
| 71 ui::ListSelectionModel selection_model_; | 64 ui::ListSelectionModel selection_model_; |
| 72 bool immersive_style_; | 65 bool immersive_style_; |
| 73 bool active_tab_; | 66 bool active_tab_; |
| 74 | 67 |
| 75 DISALLOW_COPY_AND_ASSIGN(FakeTabController); | 68 DISALLOW_COPY_AND_ASSIGN(FakeTabController); |
| 76 }; | 69 }; |
| 77 | 70 |
| 78 class TabTest : public views::ViewsTestBase, | 71 class TabTest : public views::ViewsTestBase, |
| 79 public ::testing::WithParamInterface<bool> { | 72 public ::testing::WithParamInterface<bool> { |
| 80 public: | 73 public: |
| 81 TabTest() {} | 74 TabTest() {} |
| 82 virtual ~TabTest() {} | 75 virtual ~TabTest() {} |
| 83 | 76 |
| 84 bool testing_for_rtl_locale() const { return GetParam(); } | 77 bool testing_for_rtl_locale() const { return GetParam(); } |
| 85 | 78 |
| 86 virtual void SetUp() override { | 79 void SetUp() override { |
| 87 if (testing_for_rtl_locale()) { | 80 if (testing_for_rtl_locale()) { |
| 88 original_locale_ = base::i18n::GetConfiguredLocale(); | 81 original_locale_ = base::i18n::GetConfiguredLocale(); |
| 89 base::i18n::SetICUDefaultLocale("he"); | 82 base::i18n::SetICUDefaultLocale("he"); |
| 90 } | 83 } |
| 91 views::ViewsTestBase::SetUp(); | 84 views::ViewsTestBase::SetUp(); |
| 92 } | 85 } |
| 93 | 86 |
| 94 virtual void TearDown() override { | 87 void TearDown() override { |
| 95 views::ViewsTestBase::TearDown(); | 88 views::ViewsTestBase::TearDown(); |
| 96 if (testing_for_rtl_locale()) | 89 if (testing_for_rtl_locale()) |
| 97 base::i18n::SetICUDefaultLocale(original_locale_); | 90 base::i18n::SetICUDefaultLocale(original_locale_); |
| 98 } | 91 } |
| 99 | 92 |
| 100 static void CheckForExpectedLayoutAndVisibilityOfElements(const Tab& tab) { | 93 static void CheckForExpectedLayoutAndVisibilityOfElements(const Tab& tab) { |
| 101 // Check whether elements are visible when they are supposed to be, given | 94 // Check whether elements are visible when they are supposed to be, given |
| 102 // Tab size and TabRendererData state. | 95 // Tab size and TabRendererData state. |
| 103 if (tab.data_.mini) { | 96 if (tab.data_.mini) { |
| 104 EXPECT_EQ(1, tab.IconCapacity()); | 97 EXPECT_EQ(1, tab.IconCapacity()); |
| (...skipping 286 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 391 EXPECT_EQ(50, tab.close_button_->bounds().height()); | 384 EXPECT_EQ(50, tab.close_button_->bounds().height()); |
| 392 } | 385 } |
| 393 | 386 |
| 394 // Test in both a LTR and a RTL locale. Note: The fact that the UI code is | 387 // Test in both a LTR and a RTL locale. Note: The fact that the UI code is |
| 395 // configured for an RTL locale does *not* change how the coordinates are | 388 // configured for an RTL locale does *not* change how the coordinates are |
| 396 // examined in the tests above because views::View and friends are supposed to | 389 // examined in the tests above because views::View and friends are supposed to |
| 397 // auto-mirror the widgets when painting. Thus, what we're testing here is that | 390 // auto-mirror the widgets when painting. Thus, what we're testing here is that |
| 398 // there's no code in Tab that will erroneously subvert this automatic | 391 // there's no code in Tab that will erroneously subvert this automatic |
| 399 // coordinate translation. http://crbug.com/384179 | 392 // coordinate translation. http://crbug.com/384179 |
| 400 INSTANTIATE_TEST_CASE_P(, TabTest, ::testing::Values(false, true)); | 393 INSTANTIATE_TEST_CASE_P(, TabTest, ::testing::Values(false, true)); |
| OLD | NEW |