OLD | NEW |
1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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 <memory> | 5 #include <memory> |
6 | 6 |
7 #include "ash/common/system/tray/tri_view.h" | 7 #include "ash/common/system/tray/tri_view.h" |
8 #include "base/memory/ptr_util.h" | 8 #include "base/memory/ptr_util.h" |
9 #include "testing/gtest/include/gtest/gtest.h" | 9 #include "testing/gtest/include/gtest/gtest.h" |
10 #include "ui/gfx/geometry/insets.h" | 10 #include "ui/gfx/geometry/insets.h" |
(...skipping 16 matching lines...) Expand all Loading... |
27 return std::move(layout); | 27 return std::move(layout); |
28 } | 28 } |
29 | 29 |
30 } // namespace | 30 } // namespace |
31 | 31 |
32 class TriViewTest : public testing::Test { | 32 class TriViewTest : public testing::Test { |
33 public: | 33 public: |
34 TriViewTest(); | 34 TriViewTest(); |
35 | 35 |
36 protected: | 36 protected: |
| 37 // Convenience function to get the minimum height of |container|. |
| 38 int GetMinHeight(TriView::Container container) const; |
| 39 |
37 // Returns the bounds of |child| in the coordinate space of | 40 // Returns the bounds of |child| in the coordinate space of |
38 // |tri_view_|. | 41 // |tri_view_|. |
39 gfx::Rect GetBoundsInHost(const views::View* child) const; | 42 gfx::Rect GetBoundsInHost(const views::View* child) const; |
40 | 43 |
41 // Wrapper functions to access the internals of |tri_view_|. | 44 // Wrapper functions to access the internals of |tri_view_|. |
42 views::View* GetContainer(TriView::Container container) const; | 45 views::View* GetContainer(TriView::Container container) const; |
43 | 46 |
44 // The test target. | 47 // The test target. |
45 std::unique_ptr<TriView> tri_view_; | 48 std::unique_ptr<TriView> tri_view_; |
46 | 49 |
47 private: | 50 private: |
48 DISALLOW_COPY_AND_ASSIGN(TriViewTest); | 51 DISALLOW_COPY_AND_ASSIGN(TriViewTest); |
49 }; | 52 }; |
50 | 53 |
51 TriViewTest::TriViewTest() : tri_view_(base::MakeUnique<TriView>()) {} | 54 TriViewTest::TriViewTest() : tri_view_(base::MakeUnique<TriView>()) {} |
52 | 55 |
| 56 int TriViewTest::GetMinHeight(TriView::Container container) const { |
| 57 return tri_view_->GetMinSize(container).height(); |
| 58 } |
| 59 |
53 gfx::Rect TriViewTest::GetBoundsInHost(const views::View* child) const { | 60 gfx::Rect TriViewTest::GetBoundsInHost(const views::View* child) const { |
54 gfx::RectF rect_f(child->bounds()); | 61 gfx::RectF rect_f(child->bounds()); |
55 views::View::ConvertRectToTarget(child, tri_view_.get(), &rect_f); | 62 views::View::ConvertRectToTarget(child, tri_view_.get(), &rect_f); |
56 return ToNearestRect(rect_f); | 63 return ToNearestRect(rect_f); |
57 } | 64 } |
58 | 65 |
59 views::View* TriViewTest::GetContainer(TriView::Container container) const { | 66 views::View* TriViewTest::GetContainer(TriView::Container container) const { |
60 return tri_view_->GetContainer(container); | 67 return tri_view_->GetContainer(container); |
61 } | 68 } |
62 | 69 |
(...skipping 286 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
349 new views::ProportionallySizedView(1); | 356 new views::ProportionallySizedView(1); |
350 tri_view_->AddView(TriView::Container::START, child_view); | 357 tri_view_->AddView(TriView::Container::START, child_view); |
351 | 358 |
352 child_view->SetPreferredWidth(1); | 359 child_view->SetPreferredWidth(1); |
353 EXPECT_EQ(child_view->GetPreferredSize(), child_view->size()); | 360 EXPECT_EQ(child_view->GetPreferredSize(), child_view->size()); |
354 | 361 |
355 child_view->SetPreferredWidth(2); | 362 child_view->SetPreferredWidth(2); |
356 EXPECT_EQ(child_view->GetPreferredSize(), child_view->size()); | 363 EXPECT_EQ(child_view->GetPreferredSize(), child_view->size()); |
357 } | 364 } |
358 | 365 |
| 366 TEST_F(TriViewTest, SetMinHeight) { |
| 367 const int kMinHeight = 10; |
| 368 |
| 369 EXPECT_NE(kMinHeight, GetMinHeight(TriView::Container::START)); |
| 370 EXPECT_NE(kMinHeight, GetMinHeight(TriView::Container::CENTER)); |
| 371 EXPECT_NE(kMinHeight, GetMinHeight(TriView::Container::END)); |
| 372 |
| 373 tri_view_->SetMinHeight(kMinHeight); |
| 374 |
| 375 EXPECT_EQ(kMinHeight, GetMinHeight(TriView::Container::START)); |
| 376 EXPECT_EQ(kMinHeight, GetMinHeight(TriView::Container::CENTER)); |
| 377 EXPECT_EQ(kMinHeight, GetMinHeight(TriView::Container::END)); |
| 378 } |
| 379 |
359 } // namespace ash | 380 } // namespace ash |
OLD | NEW |