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

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: Use two WaitableEvents to prevent race, re-arrange some definitions, other minor test robustness fi… 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 ASSERT_TRUE(server.Start());
31 ASSERT_TRUE(display.Initialize());
32 ASSERT_TRUE(window.Initialize());
33 wl_display_roundtrip(display.display());
34
35 server.Pause();
36
37 surface = server.GetObject<wl::MockSurface>(window.GetWidget());
38 ASSERT_TRUE(surface);
39 initialized = true;
40 }
41
42 void TearDown() override {
43 server.Resume();
44 if (initialized)
45 wl_display_roundtrip(display.display());
46 }
47
48 void Sync() {
49 server.Resume();
50 wl_display_roundtrip(display.display());
51 server.Pause();
52 }
53
54 private:
55 wl::FakeServer server;
56 bool initialized = false;
57
58 protected:
59 WaylandDisplay display;
60 WaylandSurfaceFactory surface_factory;
61 MockPlatformWindowDelegate delegate;
62 WaylandWindow window;
63 wl::MockSurface* surface;
64
65 private:
66 DISALLOW_COPY_AND_ASSIGN(WaylandSurfaceFactoryTest);
67 };
68
69 TEST_F(WaylandSurfaceFactoryTest, Canvas) {
70 auto canvas = surface_factory.CreateCanvasForWidget(window.GetWidget());
71 ASSERT_TRUE(canvas);
72
73 canvas->GetSurface();
74 canvas->PresentCanvas(gfx::Rect(5, 10, 20, 15));
75
76 Expectation damage = EXPECT_CALL(*surface, Damage(5, 10, 20, 15));
77 wl_resource* buffer_resource = nullptr;
78 Expectation attach = EXPECT_CALL(*surface, Attach(_, 0, 0))
79 .WillOnce(SaveArg<0>(&buffer_resource));
80 EXPECT_CALL(*surface, Commit()).After(damage, attach);
81
82 Sync();
83
84 ASSERT_TRUE(buffer_resource);
85 wl_shm_buffer* buffer = wl_shm_buffer_get(buffer_resource);
86 ASSERT_TRUE(buffer);
87 EXPECT_EQ(wl_shm_buffer_get_width(buffer), 80);
88 EXPECT_EQ(wl_shm_buffer_get_height(buffer), 60);
89
90 // TODO(forney): We could check that the contents match something drawn to the
91 // SkSurface above.
92 }
93
94 TEST_F(WaylandSurfaceFactoryTest, CanvasResize) {
95 auto canvas = surface_factory.CreateCanvasForWidget(window.GetWidget());
96 ASSERT_TRUE(canvas);
97
98 canvas->GetSurface();
99 canvas->ResizeCanvas(gfx::Size(100, 50));
100 canvas->GetSurface();
101 canvas->PresentCanvas(gfx::Rect(0, 0, 100, 50));
102
103 Expectation damage = EXPECT_CALL(*surface, Damage(0, 0, 100, 50));
104 wl_resource* buffer_resource = nullptr;
105 Expectation attach = EXPECT_CALL(*surface, Attach(_, 0, 0))
106 .WillOnce(SaveArg<0>(&buffer_resource));
107 EXPECT_CALL(*surface, Commit()).After(damage, attach);
108
109 Sync();
110
111 ASSERT_TRUE(buffer_resource);
112 wl_shm_buffer* buffer = wl_shm_buffer_get(buffer_resource);
113 ASSERT_TRUE(buffer);
114 EXPECT_EQ(wl_shm_buffer_get_width(buffer), 100);
115 EXPECT_EQ(wl_shm_buffer_get_height(buffer), 50);
116 }
117
118 } // namespace ui
OLDNEW
« no previous file with comments | « ui/ozone/platform/wayland/wayland_surface_factory.cc ('k') | ui/ozone/platform/wayland/wayland_window.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698