| 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 "testing/gtest/include/gtest/gtest.h" | 5 #include "testing/gtest/include/gtest/gtest.h" |
| 6 #include "third_party/skia/include/core/SkSurface.h" | 6 #include "third_party/skia/include/core/SkSurface.h" |
| 7 #include "ui/ozone/platform/wayland/fake_server.h" | 7 #include "ui/ozone/platform/wayland/fake_server.h" |
| 8 #include "ui/ozone/platform/wayland/mock_platform_window_delegate.h" | 8 #include "ui/ozone/platform/wayland/mock_platform_window_delegate.h" |
| 9 #include "ui/ozone/platform/wayland/wayland_surface_factory.h" | 9 #include "ui/ozone/platform/wayland/wayland_surface_factory.h" |
| 10 #include "ui/ozone/platform/wayland/wayland_test.h" | 10 #include "ui/ozone/platform/wayland/wayland_test.h" |
| 11 #include "ui/ozone/platform/wayland/wayland_window.h" | 11 #include "ui/ozone/platform/wayland/wayland_window.h" |
| 12 #include "ui/ozone/public/surface_ozone_canvas.h" | 12 #include "ui/ozone/public/surface_ozone_canvas.h" |
| 13 | 13 |
| 14 using ::testing::Expectation; | 14 using ::testing::Expectation; |
| 15 using ::testing::SaveArg; | 15 using ::testing::SaveArg; |
| 16 using ::testing::_; | 16 using ::testing::_; |
| 17 | 17 |
| 18 namespace ui { | 18 namespace ui { |
| 19 | 19 |
| 20 class WaylandSurfaceFactoryTest : public WaylandTest { | 20 class WaylandSurfaceFactoryTest : public WaylandTest { |
| 21 public: | 21 public: |
| 22 WaylandSurfaceFactoryTest() : surface_factory(&display) {} | 22 WaylandSurfaceFactoryTest() : surface_factory(&display) {} |
| 23 | 23 |
| 24 ~WaylandSurfaceFactoryTest() override {} | 24 ~WaylandSurfaceFactoryTest() override {} |
| 25 | 25 |
| 26 void SetUp() override { |
| 27 WaylandTest::SetUp(); |
| 28 canvas = surface_factory.CreateCanvasForWidget(widget); |
| 29 ASSERT_TRUE(canvas); |
| 30 } |
| 31 |
| 26 protected: | 32 protected: |
| 27 WaylandSurfaceFactory surface_factory; | 33 WaylandSurfaceFactory surface_factory; |
| 34 scoped_ptr<SurfaceOzoneCanvas> canvas; |
| 28 | 35 |
| 29 private: | 36 private: |
| 30 DISALLOW_COPY_AND_ASSIGN(WaylandSurfaceFactoryTest); | 37 DISALLOW_COPY_AND_ASSIGN(WaylandSurfaceFactoryTest); |
| 31 }; | 38 }; |
| 32 | 39 |
| 33 TEST_F(WaylandSurfaceFactoryTest, Canvas) { | 40 TEST_F(WaylandSurfaceFactoryTest, Canvas) { |
| 34 auto canvas = surface_factory.CreateCanvasForWidget(window.GetWidget()); | |
| 35 ASSERT_TRUE(canvas); | |
| 36 | |
| 37 canvas->GetSurface(); | 41 canvas->GetSurface(); |
| 38 canvas->PresentCanvas(gfx::Rect(5, 10, 20, 15)); | 42 canvas->PresentCanvas(gfx::Rect(5, 10, 20, 15)); |
| 39 | 43 |
| 40 Expectation damage = EXPECT_CALL(*surface, Damage(5, 10, 20, 15)); | 44 Expectation damage = EXPECT_CALL(*surface, Damage(5, 10, 20, 15)); |
| 41 wl_resource* buffer_resource = nullptr; | 45 wl_resource* buffer_resource = nullptr; |
| 42 Expectation attach = EXPECT_CALL(*surface, Attach(_, 0, 0)) | 46 Expectation attach = EXPECT_CALL(*surface, Attach(_, 0, 0)) |
| 43 .WillOnce(SaveArg<0>(&buffer_resource)); | 47 .WillOnce(SaveArg<0>(&buffer_resource)); |
| 44 EXPECT_CALL(*surface, Commit()).After(damage, attach); | 48 EXPECT_CALL(*surface, Commit()).After(damage, attach); |
| 45 | 49 |
| 46 Sync(); | 50 Sync(); |
| 47 | 51 |
| 48 ASSERT_TRUE(buffer_resource); | 52 ASSERT_TRUE(buffer_resource); |
| 49 wl_shm_buffer* buffer = wl_shm_buffer_get(buffer_resource); | 53 wl_shm_buffer* buffer = wl_shm_buffer_get(buffer_resource); |
| 50 ASSERT_TRUE(buffer); | 54 ASSERT_TRUE(buffer); |
| 51 EXPECT_EQ(wl_shm_buffer_get_width(buffer), 800); | 55 EXPECT_EQ(wl_shm_buffer_get_width(buffer), 800); |
| 52 EXPECT_EQ(wl_shm_buffer_get_height(buffer), 600); | 56 EXPECT_EQ(wl_shm_buffer_get_height(buffer), 600); |
| 53 | 57 |
| 54 // TODO(forney): We could check that the contents match something drawn to the | 58 // TODO(forney): We could check that the contents match something drawn to the |
| 55 // SkSurface above. | 59 // SkSurface above. |
| 56 } | 60 } |
| 57 | 61 |
| 58 TEST_F(WaylandSurfaceFactoryTest, CanvasResize) { | 62 TEST_F(WaylandSurfaceFactoryTest, CanvasResize) { |
| 59 auto canvas = surface_factory.CreateCanvasForWidget(window.GetWidget()); | |
| 60 ASSERT_TRUE(canvas); | |
| 61 | |
| 62 canvas->GetSurface(); | 63 canvas->GetSurface(); |
| 63 canvas->ResizeCanvas(gfx::Size(100, 50)); | 64 canvas->ResizeCanvas(gfx::Size(100, 50)); |
| 64 canvas->GetSurface(); | 65 canvas->GetSurface(); |
| 65 canvas->PresentCanvas(gfx::Rect(0, 0, 100, 50)); | 66 canvas->PresentCanvas(gfx::Rect(0, 0, 100, 50)); |
| 66 | 67 |
| 67 Expectation damage = EXPECT_CALL(*surface, Damage(0, 0, 100, 50)); | 68 Expectation damage = EXPECT_CALL(*surface, Damage(0, 0, 100, 50)); |
| 68 wl_resource* buffer_resource = nullptr; | 69 wl_resource* buffer_resource = nullptr; |
| 69 Expectation attach = EXPECT_CALL(*surface, Attach(_, 0, 0)) | 70 Expectation attach = EXPECT_CALL(*surface, Attach(_, 0, 0)) |
| 70 .WillOnce(SaveArg<0>(&buffer_resource)); | 71 .WillOnce(SaveArg<0>(&buffer_resource)); |
| 71 EXPECT_CALL(*surface, Commit()).After(damage, attach); | 72 EXPECT_CALL(*surface, Commit()).After(damage, attach); |
| 72 | 73 |
| 73 Sync(); | 74 Sync(); |
| 74 | 75 |
| 75 ASSERT_TRUE(buffer_resource); | 76 ASSERT_TRUE(buffer_resource); |
| 76 wl_shm_buffer* buffer = wl_shm_buffer_get(buffer_resource); | 77 wl_shm_buffer* buffer = wl_shm_buffer_get(buffer_resource); |
| 77 ASSERT_TRUE(buffer); | 78 ASSERT_TRUE(buffer); |
| 78 EXPECT_EQ(wl_shm_buffer_get_width(buffer), 100); | 79 EXPECT_EQ(wl_shm_buffer_get_width(buffer), 100); |
| 79 EXPECT_EQ(wl_shm_buffer_get_height(buffer), 50); | 80 EXPECT_EQ(wl_shm_buffer_get_height(buffer), 50); |
| 80 } | 81 } |
| 81 | 82 |
| 82 } // namespace ui | 83 } // namespace ui |
| OLD | NEW |