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

Side by Side Diff: ui/ozone/platform/wayland/wayland_surface_factory_unittest.cc

Issue 1673063002: ozone/platform/wayland: Add some tests (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 10 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 unified diff | Download patch
OLDNEW
(Empty)
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
3 // found in the LICENSE file.
4
5 #include "testing/gtest/include/gtest/gtest.h"
6 #include "third_party/skia/include/core/SkSurface.h"
7 #include "ui/ozone/platform/wayland/fake_server.h"
8 #include "ui/ozone/platform/wayland/mock_platform_window_delegate.h"
9 #include "ui/ozone/platform/wayland/wayland_display.h"
10 #include "ui/ozone/platform/wayland/wayland_surface_factory.h"
11 #include "ui/ozone/platform/wayland/wayland_window.h"
12 #include "ui/ozone/public/surface_ozone_canvas.h"
13
14 using ::testing::Expectation;
15 using ::testing::Mock;
16 using ::testing::SaveArg;
17 using ::testing::_;
18
19 namespace ui {
20
21 class WaylandSurfaceFactoryTest : public testing::Test {
22 public:
23 WaylandSurfaceFactoryTest()
24 : surface_factory(&display),
25 window(&delegate, &display, gfx::Rect(0, 0, 80, 60)) {}
26
27 ~WaylandSurfaceFactoryTest() override {}
28
29 void SetUp() override {
30 using ::testing::_;
31
32 ASSERT_TRUE(server.Start());
33 ASSERT_TRUE(display.Initialize());
34
35 EXPECT_CALL(delegate, OnAcceleratedWidgetAvailable(_, _));
36 ASSERT_TRUE(window.Initialize());
37
38 wl_display_roundtrip(display.display());
39 surface = server.GetObject<wl::FakeSurface>(window.GetWidget());
40 ASSERT_TRUE(surface);
41 surface->mock = &mock_surface;
42
43 initialized = true;
44 }
45
46 void TearDown() override {
47 if (initialized)
48 wl_display_roundtrip(display.display());
49 }
50
51 protected:
52 wl::FakeServer server;
53 WaylandDisplay display;
54 WaylandSurfaceFactory surface_factory;
55 MockPlatformWindowDelegate delegate;
56 WaylandWindow window;
57 wl::MockSurface mock_surface;
58 wl::FakeSurface* surface;
59
60 private:
61 bool initialized = false;
62
63 DISALLOW_COPY_AND_ASSIGN(WaylandSurfaceFactoryTest);
64 };
65
66 TEST_F(WaylandSurfaceFactoryTest, Canvas) {
67 auto canvas = surface_factory.CreateCanvasForWidget(window.GetWidget());
68 ASSERT_TRUE(canvas);
69
70 canvas->GetSurface();
71 Expectation damage = EXPECT_CALL(mock_surface, Damage(5, 10, 20, 15));
72 wl_resource* buffer_resource = nullptr;
73 Expectation attach = EXPECT_CALL(mock_surface, Attach(_, 0, 0))
74 .WillOnce(SaveArg<0>(&buffer_resource));
75 EXPECT_CALL(mock_surface, Commit()).After(damage, attach);
76 canvas->PresentCanvas(gfx::Rect(5, 10, 20, 15));
77
78 wl_display_roundtrip(display.display());
79
80 Mock::VerifyAndClearExpectations(&mock_surface);
81 ASSERT_TRUE(buffer_resource);
82 wl_shm_buffer* buffer = wl_shm_buffer_get(buffer_resource);
83 ASSERT_TRUE(buffer);
84 EXPECT_EQ(wl_shm_buffer_get_width(buffer), 80);
85 EXPECT_EQ(wl_shm_buffer_get_height(buffer), 60);
86
87 // TODO(forney): We could check that the contents match something drawn to the
88 // SkSurface above.
89 }
90
91 TEST_F(WaylandSurfaceFactoryTest, CanvasResize) {
92 auto canvas = surface_factory.CreateCanvasForWidget(window.GetWidget());
93 ASSERT_TRUE(canvas);
94
95 canvas->GetSurface();
96 canvas->ResizeCanvas(gfx::Size(100, 50));
97 canvas->GetSurface();
98
99 Expectation damage = EXPECT_CALL(mock_surface, Damage(0, 0, 100, 50));
100 wl_resource* buffer_resource = nullptr;
101 Expectation attach = EXPECT_CALL(mock_surface, Attach(_, 0, 0))
102 .WillOnce(SaveArg<0>(&buffer_resource));
103 EXPECT_CALL(mock_surface, Commit()).After(damage, attach);
104 canvas->PresentCanvas(gfx::Rect(0, 0, 100, 50));
105
106 wl_display_roundtrip(display.display());
107
108 Mock::VerifyAndClearExpectations(&mock_surface);
109 ASSERT_TRUE(buffer_resource);
110 wl_shm_buffer* buffer = wl_shm_buffer_get(buffer_resource);
111 ASSERT_TRUE(buffer);
112 EXPECT_EQ(wl_shm_buffer_get_width(buffer), 100);
113 EXPECT_EQ(wl_shm_buffer_get_height(buffer), 50);
114 }
115
116 } // namespace ui
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698