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 <wayland-server-core.h> | 5 #include <wayland-server-core.h> |
6 #include <xdg-shell-unstable-v5-server-protocol.h> | 6 #include <xdg-shell-unstable-v5-server-protocol.h> |
7 | 7 |
8 #include "base/strings/utf_string_conversions.h" | 8 #include "base/strings/utf_string_conversions.h" |
9 #include "testing/gmock/include/gmock/gmock.h" | 9 #include "testing/gmock/include/gmock/gmock.h" |
10 #include "testing/gtest/include/gtest/gtest.h" | 10 #include "testing/gtest/include/gtest/gtest.h" |
11 #include "ui/ozone/platform/wayland/fake_server.h" | 11 #include "ui/ozone/platform/wayland/fake_server.h" |
12 #include "ui/ozone/platform/wayland/mock_platform_window_delegate.h" | 12 #include "ui/ozone/platform/wayland/mock_platform_window_delegate.h" |
13 #include "ui/ozone/platform/wayland/wayland_display.h" | 13 #include "ui/ozone/platform/wayland/wayland_test.h" |
14 #include "ui/ozone/platform/wayland/wayland_window.h" | 14 #include "ui/ozone/platform/wayland/wayland_window.h" |
15 | 15 |
16 using ::testing::Eq; | 16 using ::testing::Eq; |
17 using ::testing::Mock; | 17 using ::testing::Mock; |
18 using ::testing::SaveArg; | 18 using ::testing::SaveArg; |
19 using ::testing::StrEq; | 19 using ::testing::StrEq; |
20 using ::testing::_; | 20 using ::testing::_; |
21 | 21 |
22 namespace ui { | 22 namespace ui { |
23 | 23 |
24 TEST(WaylandWindowInitializeTest, Initialize) { | 24 class WaylandWindowTest : public WaylandTest { |
25 wl::FakeServer server; | |
26 ASSERT_TRUE(server.Start()); | |
27 WaylandDisplay display; | |
28 ASSERT_TRUE(display.Initialize()); | |
29 MockPlatformWindowDelegate delegate; | |
30 gfx::AcceleratedWidget widget = gfx::kNullAcceleratedWidget; | |
31 EXPECT_CALL(delegate, OnAcceleratedWidgetAvailable(_, _)) | |
32 .WillOnce(SaveArg<0>(&widget)); | |
33 WaylandWindow window(&delegate, &display, gfx::Rect(0, 0, 800, 600)); | |
34 ASSERT_TRUE(window.Initialize()); | |
35 EXPECT_EQ(widget, window.GetWidget()); | |
36 wl_display_roundtrip(display.display()); | |
37 | |
38 server.Pause(); | |
39 | |
40 EXPECT_TRUE(server.GetObject<wl::MockSurface>(window.GetWidget())); | |
41 server.Resume(); | |
42 } | |
43 | |
44 class WaylandWindowTest : public testing::Test { | |
45 public: | 25 public: |
46 WaylandWindowTest() | 26 WaylandWindowTest() {} |
47 : window(&delegate, &display, gfx::Rect(0, 0, 800, 600)) {} | |
48 | 27 |
49 void SetUp() override { | 28 void SetUp() override { |
50 ASSERT_TRUE(server.Start()); | 29 WaylandTest::SetUp(); |
51 ASSERT_TRUE(display.Initialize()); | |
52 ASSERT_TRUE(window.Initialize()); | |
53 wl_display_roundtrip(display.display()); | |
54 | 30 |
55 server.Pause(); | |
56 | |
57 auto surface = server.GetObject<wl::MockSurface>(window.GetWidget()); | |
58 ASSERT_TRUE(surface); | |
59 xdg_surface = surface->xdg_surface.get(); | 31 xdg_surface = surface->xdg_surface.get(); |
60 ASSERT_TRUE(xdg_surface); | 32 ASSERT_TRUE(xdg_surface); |
61 initialized = true; | |
62 } | 33 } |
63 | 34 |
64 void TearDown() override { | |
65 server.Resume(); | |
66 if (initialized) | |
67 wl_display_roundtrip(display.display()); | |
68 } | |
69 | |
70 void Sync() { | |
71 server.Resume(); | |
72 wl_display_roundtrip(display.display()); | |
73 server.Pause(); | |
74 } | |
75 | |
76 private: | |
77 wl::FakeServer server; | |
78 bool initialized = false; | |
79 | |
80 protected: | 35 protected: |
81 WaylandDisplay display; | |
82 | |
83 MockPlatformWindowDelegate delegate; | |
84 WaylandWindow window; | |
85 | |
86 wl::MockXdgSurface* xdg_surface; | 36 wl::MockXdgSurface* xdg_surface; |
87 | 37 |
88 private: | 38 private: |
89 DISALLOW_COPY_AND_ASSIGN(WaylandWindowTest); | 39 DISALLOW_COPY_AND_ASSIGN(WaylandWindowTest); |
90 }; | 40 }; |
91 | 41 |
92 TEST_F(WaylandWindowTest, SetTitle) { | 42 TEST_F(WaylandWindowTest, SetTitle) { |
93 EXPECT_CALL(*xdg_surface, SetTitle(StrEq("hello"))); | 43 EXPECT_CALL(*xdg_surface, SetTitle(StrEq("hello"))); |
94 window.SetTitle(base::ASCIIToUTF16("hello")); | 44 window.SetTitle(base::ASCIIToUTF16("hello")); |
95 } | 45 } |
(...skipping 24 matching lines...) Expand all Loading... |
120 EXPECT_CALL(delegate, OnBoundsChanged(_)).Times(0); | 70 EXPECT_CALL(delegate, OnBoundsChanged(_)).Times(0); |
121 Sync(); | 71 Sync(); |
122 Mock::VerifyAndClearExpectations(&delegate); | 72 Mock::VerifyAndClearExpectations(&delegate); |
123 | 73 |
124 EXPECT_CALL(delegate, OnBoundsChanged(Eq(gfx::Rect(0, 0, 1500, 1000)))); | 74 EXPECT_CALL(delegate, OnBoundsChanged(Eq(gfx::Rect(0, 0, 1500, 1000)))); |
125 EXPECT_CALL(*xdg_surface, AckConfigure(13)); | 75 EXPECT_CALL(*xdg_surface, AckConfigure(13)); |
126 window.ApplyPendingBounds(); | 76 window.ApplyPendingBounds(); |
127 } | 77 } |
128 | 78 |
129 } // namespace ui | 79 } // namespace ui |
OLD | NEW |