OLD | NEW |
(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 <wayland-server-core.h> |
| 6 #include <xdg-shell-unstable-v5-server-protocol.h> |
| 7 |
| 8 #include "base/strings/utf_string_conversions.h" |
| 9 #include "testing/gmock/include/gmock/gmock.h" |
| 10 #include "testing/gtest/include/gtest/gtest.h" |
| 11 #include "ui/ozone/platform/wayland/fake_server.h" |
| 12 #include "ui/ozone/platform/wayland/mock_platform_window_delegate.h" |
| 13 #include "ui/ozone/platform/wayland/wayland_display.h" |
| 14 #include "ui/ozone/platform/wayland/wayland_window.h" |
| 15 |
| 16 using ::testing::Eq; |
| 17 using ::testing::Mock; |
| 18 using ::testing::SaveArg; |
| 19 using ::testing::StrEq; |
| 20 using ::testing::_; |
| 21 |
| 22 namespace ui { |
| 23 |
| 24 TEST(WaylandWindowInitializeTest, Initialize) { |
| 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: |
| 46 WaylandWindowTest() |
| 47 : window(&delegate, &display, gfx::Rect(0, 0, 800, 600)) {} |
| 48 |
| 49 void SetUp() override { |
| 50 ASSERT_TRUE(server.Start()); |
| 51 ASSERT_TRUE(display.Initialize()); |
| 52 ASSERT_TRUE(window.Initialize()); |
| 53 wl_display_roundtrip(display.display()); |
| 54 |
| 55 server.Pause(); |
| 56 |
| 57 auto surface = server.GetObject<wl::MockSurface>(window.GetWidget()); |
| 58 ASSERT_TRUE(surface); |
| 59 xdg_surface = surface->xdg_surface.get(); |
| 60 ASSERT_TRUE(xdg_surface); |
| 61 initialized = true; |
| 62 } |
| 63 |
| 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: |
| 81 WaylandDisplay display; |
| 82 |
| 83 MockPlatformWindowDelegate delegate; |
| 84 WaylandWindow window; |
| 85 |
| 86 wl::MockXdgSurface* xdg_surface; |
| 87 |
| 88 private: |
| 89 DISALLOW_COPY_AND_ASSIGN(WaylandWindowTest); |
| 90 }; |
| 91 |
| 92 TEST_F(WaylandWindowTest, SetTitle) { |
| 93 EXPECT_CALL(*xdg_surface, SetTitle(StrEq("hello"))); |
| 94 window.SetTitle(base::ASCIIToUTF16("hello")); |
| 95 } |
| 96 |
| 97 TEST_F(WaylandWindowTest, Maximize) { |
| 98 EXPECT_CALL(*xdg_surface, SetMaximized()); |
| 99 window.Maximize(); |
| 100 } |
| 101 |
| 102 TEST_F(WaylandWindowTest, Minimize) { |
| 103 EXPECT_CALL(*xdg_surface, SetMinimized()); |
| 104 window.Minimize(); |
| 105 } |
| 106 |
| 107 TEST_F(WaylandWindowTest, Restore) { |
| 108 EXPECT_CALL(*xdg_surface, UnsetMaximized()); |
| 109 window.Restore(); |
| 110 } |
| 111 |
| 112 TEST_F(WaylandWindowTest, ConfigureEvent) { |
| 113 wl_array states; |
| 114 wl_array_init(&states); |
| 115 xdg_surface_send_configure(xdg_surface->resource(), 1000, 1000, &states, 12); |
| 116 xdg_surface_send_configure(xdg_surface->resource(), 1500, 1000, &states, 13); |
| 117 |
| 118 // Make sure that the implementation does not call OnBoundsChanged for each |
| 119 // configure event if it receives multiple in a row. |
| 120 EXPECT_CALL(delegate, OnBoundsChanged(_)).Times(0); |
| 121 Sync(); |
| 122 Mock::VerifyAndClearExpectations(&delegate); |
| 123 |
| 124 EXPECT_CALL(delegate, OnBoundsChanged(Eq(gfx::Rect(0, 0, 1500, 1000)))); |
| 125 EXPECT_CALL(*xdg_surface, AckConfigure(13)); |
| 126 window.ApplyPendingBounds(); |
| 127 } |
| 128 |
| 129 } // namespace ui |
OLD | NEW |