#include "ash/bubble/simple_grid_layout.h"
#include <memory>
#include "testing/gtest/include/gtest/gtest.h"
#include "ui/views/test/test_views.h"
#include "ui/views/test/views_test_utils.h"
#include "ui/views/view.h"
#include "ui/views/view_class_properties.h"
namespace ash {
class SimpleGridLayoutTest : public testing::Test {
public:
void SetUp() override { host_ = std::make_unique<views::View>(); }
std::unique_ptr<views::View> host_;
};
TEST_F(SimpleGridLayoutTest, ChildIgnoredByLayout) {
views::LayoutManagerBase* layout =
host_->SetLayoutManager(std::make_unique<SimpleGridLayout>(2, 0, 0));
views::StaticSizedView* v1 = host_->AddChildView(
std::make_unique<views::StaticSizedView>(gfx::Size(20, 20)));
EXPECT_EQ(gfx::Size(40, 20), layout->GetPreferredSize(host_.get()));
views::StaticSizedView* v2 = host_->AddChildView(
std::make_unique<views::StaticSizedView>(gfx::Size(10, 10)));
EXPECT_EQ(gfx::Size(40, 20), layout->GetPreferredSize(host_.get()));
views::StaticSizedView* v3 = host_->AddChildView(
std::make_unique<views::StaticSizedView>(gfx::Size(10, 10)));
EXPECT_EQ(gfx::Size(40, 40), layout->GetPreferredSize(host_.get()));
v1->SetProperty(views::kViewIgnoredByLayoutKey, true);
EXPECT_EQ(gfx::Size(20, 10), layout->GetPreferredSize(host_.get()));
views::test::RunScheduledLayout(host_.get());
EXPECT_EQ(gfx::Rect(0, 0, 0, 0), v1->bounds());
EXPECT_EQ(gfx::Rect(0, 0, 10, 10), v2->bounds());
EXPECT_EQ(gfx::Rect(10, 0, 10, 10), v3->bounds());
host_->SetBounds(0, 0, 30, 30);
views::test::RunScheduledLayout(host_.get());
EXPECT_EQ(gfx::Rect(0, 0, 0, 0), v1->bounds());
EXPECT_EQ(gfx::Rect(0, 0, 10, 10), v2->bounds());
EXPECT_EQ(gfx::Rect(10, 0, 10, 10), v3->bounds());
}
}