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 "ui/ozone/platform/wayland/wayland_test.h" | 5 #include "ui/ozone/platform/wayland/wayland_test.h" |
6 | 6 |
| 7 #include "base/run_loop.h" |
| 8 |
7 using ::testing::SaveArg; | 9 using ::testing::SaveArg; |
8 using ::testing::_; | 10 using ::testing::_; |
9 | 11 |
10 namespace ui { | 12 namespace ui { |
11 | 13 |
12 WaylandTest::WaylandTest() | 14 WaylandTest::WaylandTest() |
13 : window(&delegate, &display, gfx::Rect(0, 0, 800, 600)) {} | 15 : window(&delegate, &display, gfx::Rect(0, 0, 800, 600)) {} |
14 | 16 |
15 WaylandTest::~WaylandTest() {} | 17 WaylandTest::~WaylandTest() {} |
16 | 18 |
17 void WaylandTest::SetUp() { | 19 void WaylandTest::SetUp() { |
18 ASSERT_TRUE(server.Start()); | 20 ASSERT_TRUE(server.Start()); |
19 ASSERT_TRUE(display.Initialize()); | 21 ASSERT_TRUE(display.Initialize()); |
| 22 display.StartProcessingEvents(); |
20 EXPECT_CALL(delegate, OnAcceleratedWidgetAvailable(_, _)) | 23 EXPECT_CALL(delegate, OnAcceleratedWidgetAvailable(_, _)) |
21 .WillOnce(SaveArg<0>(&widget)); | 24 .WillOnce(SaveArg<0>(&widget)); |
22 ASSERT_TRUE(window.Initialize()); | 25 ASSERT_TRUE(window.Initialize()); |
23 ASSERT_NE(widget, gfx::kNullAcceleratedWidget); | 26 ASSERT_NE(widget, gfx::kNullAcceleratedWidget); |
24 wl_display_roundtrip(display.display()); | |
25 | 27 |
| 28 // Wait for the client to flush all pending requests from initialization. |
| 29 base::RunLoop().RunUntilIdle(); |
| 30 |
| 31 // Pause the server after it has responded to all incoming events. |
26 server.Pause(); | 32 server.Pause(); |
27 | 33 |
28 surface = server.GetObject<wl::MockSurface>(widget); | 34 surface = server.GetObject<wl::MockSurface>(widget); |
29 ASSERT_TRUE(surface); | 35 ASSERT_TRUE(surface); |
| 36 |
30 initialized = true; | 37 initialized = true; |
31 } | 38 } |
32 | 39 |
33 void WaylandTest::TearDown() { | 40 void WaylandTest::TearDown() { |
34 server.Resume(); | |
35 if (initialized) | 41 if (initialized) |
36 wl_display_roundtrip(display.display()); | 42 Sync(); |
37 } | 43 } |
38 | 44 |
39 void WaylandTest::Sync() { | 45 void WaylandTest::Sync() { |
| 46 // Resume the server, flushing its pending events. |
40 server.Resume(); | 47 server.Resume(); |
41 wl_display_roundtrip(display.display()); | 48 |
| 49 // Wait for the client to finish processing these events. |
| 50 base::RunLoop().RunUntilIdle(); |
| 51 |
| 52 // Pause the server, after it has finished processing any follow-up requests |
| 53 // from the client. |
42 server.Pause(); | 54 server.Pause(); |
43 } | 55 } |
44 | 56 |
45 } // namespace ui | 57 } // namespace ui |
OLD | NEW |