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

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

Issue 1740303002: ozone/platform/wayland: Add WaylandTest base class to eliminate redundancy (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 9 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
« no previous file with comments | « ui/ozone/platform/wayland/wayland.gypi ('k') | ui/ozone/platform/wayland/wayland_test.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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_display.h"
10 #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"
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::Mock;
16 using ::testing::SaveArg; 15 using ::testing::SaveArg;
17 using ::testing::_; 16 using ::testing::_;
18 17
19 namespace ui { 18 namespace ui {
20 19
21 class WaylandSurfaceFactoryTest : public testing::Test { 20 class WaylandSurfaceFactoryTest : public WaylandTest {
22 public: 21 public:
23 WaylandSurfaceFactoryTest() 22 WaylandSurfaceFactoryTest() : surface_factory(&display) {}
24 : surface_factory(&display),
25 window(&delegate, &display, gfx::Rect(0, 0, 80, 60)) {}
26 23
27 ~WaylandSurfaceFactoryTest() override {} 24 ~WaylandSurfaceFactoryTest() override {}
28 25
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: 26 protected:
59 WaylandDisplay display;
60 WaylandSurfaceFactory surface_factory; 27 WaylandSurfaceFactory surface_factory;
61 MockPlatformWindowDelegate delegate;
62 WaylandWindow window;
63 wl::MockSurface* surface;
64 28
65 private: 29 private:
66 DISALLOW_COPY_AND_ASSIGN(WaylandSurfaceFactoryTest); 30 DISALLOW_COPY_AND_ASSIGN(WaylandSurfaceFactoryTest);
67 }; 31 };
68 32
69 TEST_F(WaylandSurfaceFactoryTest, Canvas) { 33 TEST_F(WaylandSurfaceFactoryTest, Canvas) {
70 auto canvas = surface_factory.CreateCanvasForWidget(window.GetWidget()); 34 auto canvas = surface_factory.CreateCanvasForWidget(window.GetWidget());
71 ASSERT_TRUE(canvas); 35 ASSERT_TRUE(canvas);
72 36
73 canvas->GetSurface(); 37 canvas->GetSurface();
74 canvas->PresentCanvas(gfx::Rect(5, 10, 20, 15)); 38 canvas->PresentCanvas(gfx::Rect(5, 10, 20, 15));
75 39
76 Expectation damage = EXPECT_CALL(*surface, Damage(5, 10, 20, 15)); 40 Expectation damage = EXPECT_CALL(*surface, Damage(5, 10, 20, 15));
77 wl_resource* buffer_resource = nullptr; 41 wl_resource* buffer_resource = nullptr;
78 Expectation attach = EXPECT_CALL(*surface, Attach(_, 0, 0)) 42 Expectation attach = EXPECT_CALL(*surface, Attach(_, 0, 0))
79 .WillOnce(SaveArg<0>(&buffer_resource)); 43 .WillOnce(SaveArg<0>(&buffer_resource));
80 EXPECT_CALL(*surface, Commit()).After(damage, attach); 44 EXPECT_CALL(*surface, Commit()).After(damage, attach);
81 45
82 Sync(); 46 Sync();
83 47
84 ASSERT_TRUE(buffer_resource); 48 ASSERT_TRUE(buffer_resource);
85 wl_shm_buffer* buffer = wl_shm_buffer_get(buffer_resource); 49 wl_shm_buffer* buffer = wl_shm_buffer_get(buffer_resource);
86 ASSERT_TRUE(buffer); 50 ASSERT_TRUE(buffer);
87 EXPECT_EQ(wl_shm_buffer_get_width(buffer), 80); 51 EXPECT_EQ(wl_shm_buffer_get_width(buffer), 800);
88 EXPECT_EQ(wl_shm_buffer_get_height(buffer), 60); 52 EXPECT_EQ(wl_shm_buffer_get_height(buffer), 600);
89 53
90 // TODO(forney): We could check that the contents match something drawn to the 54 // TODO(forney): We could check that the contents match something drawn to the
91 // SkSurface above. 55 // SkSurface above.
92 } 56 }
93 57
94 TEST_F(WaylandSurfaceFactoryTest, CanvasResize) { 58 TEST_F(WaylandSurfaceFactoryTest, CanvasResize) {
95 auto canvas = surface_factory.CreateCanvasForWidget(window.GetWidget()); 59 auto canvas = surface_factory.CreateCanvasForWidget(window.GetWidget());
96 ASSERT_TRUE(canvas); 60 ASSERT_TRUE(canvas);
97 61
98 canvas->GetSurface(); 62 canvas->GetSurface();
(...skipping 10 matching lines...) Expand all
109 Sync(); 73 Sync();
110 74
111 ASSERT_TRUE(buffer_resource); 75 ASSERT_TRUE(buffer_resource);
112 wl_shm_buffer* buffer = wl_shm_buffer_get(buffer_resource); 76 wl_shm_buffer* buffer = wl_shm_buffer_get(buffer_resource);
113 ASSERT_TRUE(buffer); 77 ASSERT_TRUE(buffer);
114 EXPECT_EQ(wl_shm_buffer_get_width(buffer), 100); 78 EXPECT_EQ(wl_shm_buffer_get_width(buffer), 100);
115 EXPECT_EQ(wl_shm_buffer_get_height(buffer), 50); 79 EXPECT_EQ(wl_shm_buffer_get_height(buffer), 50);
116 } 80 }
117 81
118 } // namespace ui 82 } // namespace ui
OLDNEW
« no previous file with comments | « ui/ozone/platform/wayland/wayland.gypi ('k') | ui/ozone/platform/wayland/wayland_test.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698