This source file includes following definitions.
- CreateImage
- TEST_F
- TEST_F
- TEST_F
- TEST_F
- TEST_F
- TEST_F
#include "ui/wm/core/image_grid.h"
#include "testing/gtest/include/gtest/gtest.h"
#include "third_party/skia/include/core/SkBitmap.h"
#include "ui/aura/test/aura_test_base.h"
#include "ui/gfx/image/image.h"
#include "ui/gfx/image/image_skia.h"
namespace wm {
namespace {
gfx::Image* CreateImage(const gfx::Size& size) {
SkBitmap bitmap;
bitmap.setConfig(SkBitmap::kARGB_8888_Config, size.width(), size.height());
return new gfx::Image(gfx::ImageSkia::CreateFrom1xBitmap(bitmap));
}
}
typedef aura::test::AuraTestBase ImageGridTest;
TEST_F(ImageGridTest, Basic) {
const int kBorder = 2;
scoped_ptr<gfx::Image> image_1x1(CreateImage(gfx::Size(1, 1)));
scoped_ptr<gfx::Image> image_1xB(CreateImage(gfx::Size(1, kBorder)));
scoped_ptr<gfx::Image> image_Bx1(CreateImage(gfx::Size(kBorder, 1)));
scoped_ptr<gfx::Image> image_BxB(CreateImage(gfx::Size(kBorder, kBorder)));
ImageGrid grid;
grid.SetImages(image_BxB.get(), image_1xB.get(), image_BxB.get(),
image_Bx1.get(), image_1x1.get(), image_Bx1.get(),
image_BxB.get(), image_1xB.get(), image_BxB.get());
ImageGrid::TestAPI test_api(&grid);
ASSERT_TRUE(grid.top_left_layer() != NULL);
ASSERT_TRUE(grid.top_layer() != NULL);
ASSERT_TRUE(grid.top_right_layer() != NULL);
ASSERT_TRUE(grid.left_layer() != NULL);
ASSERT_TRUE(grid.center_layer() != NULL);
ASSERT_TRUE(grid.right_layer() != NULL);
ASSERT_TRUE(grid.bottom_left_layer() != NULL);
ASSERT_TRUE(grid.bottom_layer() != NULL);
ASSERT_TRUE(grid.bottom_right_layer() != NULL);
const gfx::Size size(20, 30);
grid.SetSize(size);
EXPECT_EQ(gfx::RectF(0, 0, kBorder, kBorder).ToString(),
test_api.GetTransformedLayerBounds(
*grid.top_left_layer()).ToString());
EXPECT_EQ(gfx::RectF(
kBorder, 0, size.width() - 2 * kBorder, kBorder).ToString(),
test_api.GetTransformedLayerBounds(
*grid.top_layer()).ToString());
EXPECT_EQ(gfx::RectF(size.width() - kBorder, 0, kBorder, kBorder).ToString(),
test_api.GetTransformedLayerBounds(
*grid.top_right_layer()).ToString());
EXPECT_EQ(gfx::RectF(
0, kBorder, kBorder, size.height() - 2 * kBorder).ToString(),
test_api.GetTransformedLayerBounds(
*grid.left_layer()).ToString());
EXPECT_EQ(gfx::RectF(
kBorder, kBorder, size.width() - 2 * kBorder,
size.height() - 2 * kBorder).ToString(),
test_api.GetTransformedLayerBounds(
*grid.center_layer()).ToString());
EXPECT_EQ(gfx::RectF(
size.width() - kBorder, kBorder,
kBorder, size.height() - 2 * kBorder).ToString(),
test_api.GetTransformedLayerBounds(
*grid.right_layer()).ToString());
EXPECT_EQ(gfx::RectF(0, size.height() - kBorder, kBorder, kBorder).ToString(),
test_api.GetTransformedLayerBounds(
*grid.bottom_left_layer()).ToString());
EXPECT_EQ(gfx::RectF(
kBorder, size.height() - kBorder,
size.width() - 2 * kBorder, kBorder).ToString(),
test_api.GetTransformedLayerBounds(
*grid.bottom_layer()).ToString());
EXPECT_EQ(gfx::RectF(
size.width() - kBorder, size.height() - kBorder,
kBorder, kBorder).ToString(),
test_api.GetTransformedLayerBounds(
*grid.bottom_right_layer()).ToString());
}
TEST_F(ImageGridTest, SetContentBounds) {
const int kBorder = 2;
scoped_ptr<gfx::Image> image_1x1(CreateImage(gfx::Size(1, 1)));
scoped_ptr<gfx::Image> image_1xB(CreateImage(gfx::Size(1, kBorder)));
scoped_ptr<gfx::Image> image_Bx1(CreateImage(gfx::Size(kBorder, 1)));
scoped_ptr<gfx::Image> image_BxB(CreateImage(gfx::Size(kBorder, kBorder)));
ImageGrid grid;
grid.SetImages(image_BxB.get(), image_1xB.get(), image_BxB.get(),
image_Bx1.get(), image_1x1.get(), image_Bx1.get(),
image_BxB.get(), image_1xB.get(), image_BxB.get());
ImageGrid::TestAPI test_api(&grid);
const gfx::Point origin(5, 10);
const gfx::Size size(20, 30);
grid.SetContentBounds(gfx::Rect(origin, size));
EXPECT_EQ(gfx::RectF(origin.x() - kBorder,
origin.y() - kBorder,
size.width() + 2 * kBorder,
size.height() + 2 * kBorder).ToString(),
test_api.GetTransformedLayerBounds(*grid.layer()).ToString());
}
TEST_F(ImageGridTest, SingleImage) {
const int kBorder = 1;
scoped_ptr<gfx::Image> image(CreateImage(gfx::Size(kBorder, kBorder)));
ImageGrid grid;
grid.SetImages(NULL, image.get(), NULL,
NULL, NULL, NULL,
NULL, NULL, NULL);
ImageGrid::TestAPI test_api(&grid);
EXPECT_TRUE(grid.top_left_layer() == NULL);
ASSERT_TRUE(grid.top_layer() != NULL);
EXPECT_TRUE(grid.top_right_layer() == NULL);
EXPECT_TRUE(grid.left_layer() == NULL);
EXPECT_TRUE(grid.center_layer() == NULL);
EXPECT_TRUE(grid.right_layer() == NULL);
EXPECT_TRUE(grid.bottom_left_layer() == NULL);
EXPECT_TRUE(grid.bottom_layer() == NULL);
EXPECT_TRUE(grid.bottom_right_layer() == NULL);
const gfx::Size kSize(10, 10);
grid.SetSize(kSize);
EXPECT_EQ(gfx::RectF(0, 0, kSize.width(), kBorder).ToString(),
test_api.GetTransformedLayerBounds(
*grid.top_layer()).ToString());
}
TEST_F(ImageGridTest, ResetImages) {
const int kBorder = 1;
scoped_ptr<gfx::Image> image(CreateImage(gfx::Size(kBorder, kBorder)));
ImageGrid grid;
grid.SetImages(NULL, image.get(), NULL,
NULL, NULL, NULL,
NULL, NULL, NULL);
ImageGrid::TestAPI test_api(&grid);
ASSERT_TRUE(grid.top_left_layer() == NULL);
ASSERT_FALSE(grid.top_layer() == NULL);
ASSERT_TRUE(grid.top_right_layer() == NULL);
ASSERT_TRUE(grid.left_layer() == NULL);
ASSERT_TRUE(grid.center_layer() == NULL);
ASSERT_TRUE(grid.right_layer() == NULL);
ASSERT_TRUE(grid.bottom_left_layer() == NULL);
ASSERT_TRUE(grid.bottom_layer() == NULL);
ASSERT_TRUE(grid.bottom_right_layer() == NULL);
grid.SetImages(NULL, NULL, NULL,
NULL, NULL, NULL,
NULL, image.get(), NULL);
ASSERT_TRUE(grid.top_left_layer() == NULL);
ASSERT_TRUE(grid.top_layer() == NULL);
ASSERT_TRUE(grid.top_right_layer() == NULL);
ASSERT_TRUE(grid.left_layer() == NULL);
ASSERT_TRUE(grid.center_layer() == NULL);
ASSERT_TRUE(grid.right_layer() == NULL);
ASSERT_TRUE(grid.bottom_left_layer() == NULL);
ASSERT_FALSE(grid.bottom_layer() == NULL);
ASSERT_TRUE(grid.bottom_right_layer() == NULL);
}
TEST_F(ImageGridTest, SmallerSides) {
const int kCorner = 2;
const int kEdge = 1;
scoped_ptr<gfx::Image> top_left_image(
CreateImage(gfx::Size(kCorner, kCorner)));
scoped_ptr<gfx::Image> top_image(CreateImage(gfx::Size(kEdge, kEdge)));
scoped_ptr<gfx::Image> top_right_image(
CreateImage(gfx::Size(kCorner, kCorner)));
scoped_ptr<gfx::Image> left_image(CreateImage(gfx::Size(kEdge, kEdge)));
scoped_ptr<gfx::Image> right_image(CreateImage(gfx::Size(kEdge, kEdge)));
ImageGrid grid;
grid.SetImages(top_left_image.get(), top_image.get(), top_right_image.get(),
left_image.get(), NULL, right_image.get(),
NULL, NULL, NULL);
ImageGrid::TestAPI test_api(&grid);
const gfx::Size kSize(20, 30);
grid.SetSize(kSize);
EXPECT_EQ(gfx::RectF(
kCorner, 0, kSize.width() - 2 * kCorner, kEdge).ToString(),
test_api.GetTransformedLayerBounds(
*grid.top_layer()).ToString());
EXPECT_EQ(gfx::RectF(
0, kCorner, kEdge, kSize.height() - kCorner).ToString(),
test_api.GetTransformedLayerBounds(
*grid.left_layer()).ToString());
EXPECT_EQ(gfx::RectF(
kSize.width() - kEdge, kCorner,
kEdge, kSize.height() - kCorner).ToString(),
test_api.GetTransformedLayerBounds(
*grid.right_layer()).ToString());
}
TEST_F(ImageGridTest, TooSmall) {
const int kCorner = 5;
const int kCenter = 3;
const int kEdge = 3;
scoped_ptr<gfx::Image> top_left_image(
CreateImage(gfx::Size(kCorner, kCorner)));
scoped_ptr<gfx::Image> top_image(CreateImage(gfx::Size(kEdge, kEdge)));
scoped_ptr<gfx::Image> top_right_image(
CreateImage(gfx::Size(kCorner, kCorner)));
scoped_ptr<gfx::Image> left_image(CreateImage(gfx::Size(kEdge, kEdge)));
scoped_ptr<gfx::Image> center_image(CreateImage(gfx::Size(kCenter, kCenter)));
scoped_ptr<gfx::Image> right_image(CreateImage(gfx::Size(kEdge, kEdge)));
scoped_ptr<gfx::Image> bottom_left_image(
CreateImage(gfx::Size(kCorner, kCorner)));
scoped_ptr<gfx::Image> bottom_image(CreateImage(gfx::Size(kEdge, kEdge)));
scoped_ptr<gfx::Image> bottom_right_image(
CreateImage(gfx::Size(kCorner, kCorner)));
ImageGrid grid;
grid.SetImages(
top_left_image.get(), top_image.get(), top_right_image.get(),
left_image.get(), center_image.get(), right_image.get(),
bottom_left_image.get(), bottom_image.get(), bottom_right_image.get());
ImageGrid::TestAPI test_api(&grid);
const gfx::Size kSmallSize(kCorner + kCorner - 3, kCorner + kCorner - 5);
grid.SetSize(kSmallSize);
EXPECT_FALSE(grid.top_layer()->visible());
EXPECT_FALSE(grid.bottom_layer()->visible());
EXPECT_FALSE(grid.left_layer()->visible());
EXPECT_FALSE(grid.right_layer()->visible());
EXPECT_FALSE(grid.center_layer()->visible());
EXPECT_EQ(kSmallSize.width(),
test_api.top_left_clip_rect().width() +
test_api.top_right_clip_rect().width());
EXPECT_EQ(kSmallSize.width(),
test_api.bottom_left_clip_rect().width() +
test_api.bottom_right_clip_rect().width());
EXPECT_EQ(kSmallSize.height(),
test_api.top_left_clip_rect().height() +
test_api.bottom_left_clip_rect().height());
EXPECT_EQ(kSmallSize.height(),
test_api.top_right_clip_rect().height() +
test_api.bottom_right_clip_rect().height());
const gfx::Size kLargeSize(kCorner + kCorner + kCenter,
kCorner + kCorner + kCenter);
grid.SetSize(kLargeSize);
EXPECT_TRUE(grid.top_layer()->visible());
EXPECT_TRUE(grid.bottom_layer()->visible());
EXPECT_TRUE(grid.left_layer()->visible());
EXPECT_TRUE(grid.right_layer()->visible());
EXPECT_TRUE(grid.center_layer()->visible());
EXPECT_TRUE(test_api.top_left_clip_rect().IsEmpty());
EXPECT_TRUE(test_api.top_right_clip_rect().IsEmpty());
EXPECT_TRUE(test_api.bottom_left_clip_rect().IsEmpty());
EXPECT_TRUE(test_api.bottom_right_clip_rect().IsEmpty());
}
}