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

Unified Diff: ash/common/system/tray/size_range_layout_unittest.cc

Issue 2439093002: Reland of "Added common layout framework for system menu rows." (Closed)
Patch Set: Addressed review comments. Created 4 years, 2 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « ash/common/system/tray/size_range_layout.cc ('k') | ash/common/system/tray/tray_constants.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: ash/common/system/tray/size_range_layout_unittest.cc
diff --git a/ash/common/system/tray/size_range_layout_unittest.cc b/ash/common/system/tray/size_range_layout_unittest.cc
new file mode 100644
index 0000000000000000000000000000000000000000..4db8c247b724c6720a42feb2dbff52199bf0a3c8
--- /dev/null
+++ b/ash/common/system/tray/size_range_layout_unittest.cc
@@ -0,0 +1,182 @@
+// Copyright 2016 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "ash/common/system/tray/size_range_layout.h"
+#include "base/memory/ptr_util.h"
+#include "testing/gtest/include/gtest/gtest.h"
+#include "ui/views/test/test_layout_manager.h"
+#include "ui/views/view.h"
+
+namespace ash {
+
+class SizeRangeLayoutTest : public testing::Test {
+ public:
+ SizeRangeLayoutTest();
+
+ // Wrapper function to access the minimum preferred size of |layout|.
+ gfx::Size GetMinSize(const SizeRangeLayout* layout) const;
+
+ // Wrapper function to access the maximum preferred size of |layout|.
+ gfx::Size GetMaxSize(const SizeRangeLayout* layout) const;
+
+ protected:
+ views::View host_;
+
+ private:
+ DISALLOW_COPY_AND_ASSIGN(SizeRangeLayoutTest);
+};
+
+SizeRangeLayoutTest::SizeRangeLayoutTest() {}
+
+gfx::Size SizeRangeLayoutTest::GetMinSize(const SizeRangeLayout* layout) const {
+ return layout->min_size_;
+}
+
+gfx::Size SizeRangeLayoutTest::GetMaxSize(const SizeRangeLayout* layout) const {
+ return layout->max_size_;
+}
+
+TEST_F(SizeRangeLayoutTest, SizeRangeForDefaultConstruction) {
+ SizeRangeLayout layout;
+ EXPECT_EQ(SizeRangeLayout::AbsoluteMinSize(), GetMinSize(&layout));
+ EXPECT_EQ(SizeRangeLayout::AbsoluteMaxSize(), GetMaxSize(&layout));
+}
+
+TEST_F(SizeRangeLayoutTest, SizeRangeForExplicitConstruction) {
+ const gfx::Size kSmallSize = gfx::Size(13, 14);
+ const gfx::Size kLargeSize = gfx::Size(25, 26);
+
+ SizeRangeLayout layout(kSmallSize, kLargeSize);
+ EXPECT_EQ(kSmallSize, GetMinSize(&layout));
+ EXPECT_EQ(kLargeSize, GetMaxSize(&layout));
+}
+
+TEST_F(SizeRangeLayoutTest, InvalidMinSizeForExplicitConstruction) {
+ const gfx::Size kInvalidSmallSize(-1, 2);
+ const gfx::Size kExpectedMinSize(0, 2);
+
+ SizeRangeLayout layout(kInvalidSmallSize, SizeRangeLayout::AbsoluteMaxSize());
+ EXPECT_EQ(kExpectedMinSize, GetMinSize(&layout));
+}
+
+TEST_F(SizeRangeLayoutTest, InvalidMaxSizeForExplicitConstruction) {
+ const gfx::Size kInvalidSmallSize(-1, 2);
+ const gfx::Size kExpectedMinSize(0, 2);
+
+ SizeRangeLayout layout(kInvalidSmallSize, SizeRangeLayout::AbsoluteMaxSize());
+ EXPECT_EQ(kExpectedMinSize, GetMinSize(&layout));
+}
+
+TEST_F(SizeRangeLayoutTest, MaxSizeSmallerThanMinSizeConstruction) {
+ const gfx::Size kMinSize(10, 11);
+ const gfx::Size kMaxSize(5, 6);
+
+ SizeRangeLayout layout(kMinSize, kMaxSize);
+ EXPECT_EQ(kMaxSize, GetMinSize(&layout));
+ EXPECT_EQ(kMaxSize, GetMaxSize(&layout));
+}
+
+TEST_F(SizeRangeLayoutTest, SizeRangeForExplicitSetSize) {
+ const gfx::Size kSize = gfx::Size(13, 14);
+
+ SizeRangeLayout layout;
+ EXPECT_NE(kSize, GetMinSize(&layout));
+ EXPECT_NE(kSize, GetMaxSize(&layout));
+
+ layout.SetSize(kSize);
+ EXPECT_EQ(kSize, GetMinSize(&layout));
+ EXPECT_EQ(kSize, GetMaxSize(&layout));
+}
+
+TEST_F(SizeRangeLayoutTest, InvalidSizeRangesForExplicitSetSize) {
+ const gfx::Size kInvalidSize(-7, 8);
+ const gfx::Size kExpectedSize(0, 8);
+
+ SizeRangeLayout layout;
+ layout.SetSize(kInvalidSize);
+ EXPECT_EQ(kExpectedSize, GetMinSize(&layout));
+ EXPECT_EQ(kExpectedSize, GetMaxSize(&layout));
+}
+
+TEST_F(SizeRangeLayoutTest, InternalLayoutManagerPreferredSizeIsUsed) {
+ const gfx::Size kSize(7, 8);
+ std::unique_ptr<views::test::TestLayoutManager> child_layout =
+ base::MakeUnique<views::test::TestLayoutManager>();
+ child_layout->set_preferred_size(kSize);
+
+ SizeRangeLayout layout;
+ EXPECT_NE(kSize, layout.GetPreferredSize(&host_));
+
+ layout.SetLayoutManager(std::move(child_layout));
+ EXPECT_EQ(kSize, layout.GetPreferredSize(&host_));
+}
+
+TEST_F(SizeRangeLayoutTest, SmallPreferredSizeIsClamped) {
+ const gfx::Size kMinSize(10, 10);
+ const gfx::Size kMaxSize(20, 20);
+ const gfx::Size kLayoutPreferredSize(5, 5);
+ std::unique_ptr<views::test::TestLayoutManager> child_layout =
+ base::MakeUnique<views::test::TestLayoutManager>();
+ child_layout->set_preferred_size(kLayoutPreferredSize);
+
+ SizeRangeLayout layout;
+ layout.SetLayoutManager(std::move(child_layout));
+ layout.SetMinSize(kMinSize);
+ layout.SetMaxSize(kMaxSize);
+ EXPECT_EQ(kMinSize, layout.GetPreferredSize(&host_));
+}
+
+TEST_F(SizeRangeLayoutTest, LargePreferredSizeIsClamped) {
+ const gfx::Size kMinSize(10, 10);
+ const gfx::Size kMaxSize(20, 20);
+ const gfx::Size kLayoutPreferredSize(25, 25);
+ std::unique_ptr<views::test::TestLayoutManager> child_layout =
+ base::MakeUnique<views::test::TestLayoutManager>();
+ child_layout->set_preferred_size(kLayoutPreferredSize);
+
+ SizeRangeLayout layout;
+ layout.SetLayoutManager(std::move(child_layout));
+ layout.SetMinSize(kMinSize);
+ layout.SetMaxSize(kMaxSize);
+ EXPECT_EQ(kMaxSize, layout.GetPreferredSize(&host_));
+}
+
+TEST_F(SizeRangeLayoutTest, MaxSizeLargerThanMinSizeUpdatesMinSize) {
+ const gfx::Size kMinSize(10, 10);
+ const gfx::Size kMaxSize(5, 5);
+
+ SizeRangeLayout layout;
+ layout.SetMinSize(kMinSize);
+ EXPECT_EQ(kMinSize, GetMinSize(&layout));
+ layout.SetMaxSize(kMaxSize);
+ EXPECT_EQ(kMaxSize, GetMinSize(&layout));
+}
+
+TEST_F(SizeRangeLayoutTest, MinSizeSmallerThanMaxSizeUpdatesMaxSize) {
+ const gfx::Size kMinSize(10, 10);
+ const gfx::Size kMaxSize(5, 5);
+
+ SizeRangeLayout layout;
+ layout.SetMaxSize(kMaxSize);
+ EXPECT_EQ(kMaxSize, GetMaxSize(&layout));
+ layout.SetMinSize(kMinSize);
+ EXPECT_EQ(kMinSize, GetMaxSize(&layout));
+}
+
+TEST_F(SizeRangeLayoutTest,
+ InternalLayoutManagerPreferredHeightForWidthIsUsed) {
+ const int kWidth = 5;
+ const int kHeight = 9;
+ std::unique_ptr<views::test::TestLayoutManager> child_layout =
+ base::MakeUnique<views::test::TestLayoutManager>();
+ child_layout->set_preferred_height_for_width(kHeight);
+
+ SizeRangeLayout layout;
+ EXPECT_NE(kHeight, layout.GetPreferredHeightForWidth(&host_, kWidth));
+
+ layout.SetLayoutManager(std::move(child_layout));
+ EXPECT_EQ(kHeight, layout.GetPreferredHeightForWidth(&host_, kWidth));
+}
+
+} // namespace ash
« no previous file with comments | « ash/common/system/tray/size_range_layout.cc ('k') | ash/common/system/tray/tray_constants.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698