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

Side by Side Diff: components/exo/gamepad_unittest.cc

Issue 2396883003: exo: Fix dragging edge cases (Closed)
Patch Set: Fix unit tests Created 4 years, 2 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
1 // Copyright 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 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 "ash/shell.h" 5 #include "ash/shell.h"
6 #include "base/command_line.h" 6 #include "base/command_line.h"
7 #include "base/run_loop.h" 7 #include "base/run_loop.h"
8 #include "base/test/test_simple_task_runner.h" 8 #include "base/test/test_simple_task_runner.h"
9 #include "components/exo/buffer.h" 9 #include "components/exo/buffer.h"
10 #include "components/exo/display.h"
10 #include "components/exo/gamepad.h" 11 #include "components/exo/gamepad.h"
11 #include "components/exo/gamepad_delegate.h" 12 #include "components/exo/gamepad_delegate.h"
12 #include "components/exo/shell_surface.h" 13 #include "components/exo/shell_surface.h"
13 #include "components/exo/surface.h" 14 #include "components/exo/surface.h"
14 #include "components/exo/test/exo_test_base.h" 15 #include "components/exo/test/exo_test_base.h"
15 #include "components/exo/test/exo_test_helper.h" 16 #include "components/exo/test/exo_test_helper.h"
16 #include "device/gamepad/gamepad_test_helpers.h" 17 #include "device/gamepad/gamepad_test_helpers.h"
17 #include "testing/gmock/include/gmock/gmock.h" 18 #include "testing/gmock/include/gmock/gmock.h"
18 #include "testing/gtest/include/gtest/gtest.h" 19 #include "testing/gtest/include/gtest/gtest.h"
19 #include "ui/aura/client/focus_client.h" 20 #include "ui/aura/client/focus_client.h"
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after
81 82
82 // Weak reference to the mock data fetcher provided by MockDataFetcherFactory. 83 // Weak reference to the mock data fetcher provided by MockDataFetcherFactory.
83 // This instance is valid until both gamepad_ and polling_task_runner_ are 84 // This instance is valid until both gamepad_ and polling_task_runner_ are
84 // shut down. 85 // shut down.
85 device::MockGamepadDataFetcher* mock_data_fetcher_; 86 device::MockGamepadDataFetcher* mock_data_fetcher_;
86 87
87 DISALLOW_COPY_AND_ASSIGN(GamepadTest); 88 DISALLOW_COPY_AND_ASSIGN(GamepadTest);
88 }; 89 };
89 90
90 TEST_F(GamepadTest, OnStateChange) { 91 TEST_F(GamepadTest, OnStateChange) {
92 const Display display;
91 std::unique_ptr<Surface> surface(new Surface); 93 std::unique_ptr<Surface> surface(new Surface);
92 std::unique_ptr<ShellSurface> shell_surface(new ShellSurface(surface.get())); 94 std::unique_ptr<ShellSurface> shell_surface(
95 new ShellSurface(display, surface.get()));
93 gfx::Size buffer_size(10, 10); 96 gfx::Size buffer_size(10, 10);
94 std::unique_ptr<Buffer> buffer( 97 std::unique_ptr<Buffer> buffer(
95 new Buffer(exo_test_helper()->CreateGpuMemoryBuffer(buffer_size))); 98 new Buffer(exo_test_helper()->CreateGpuMemoryBuffer(buffer_size)));
96 surface->Attach(buffer.get()); 99 surface->Attach(buffer.get());
97 surface->Commit(); 100 surface->Commit();
98 101
99 testing::StrictMock<MockGamepadDelegate> delegate; 102 testing::StrictMock<MockGamepadDelegate> delegate;
100 EXPECT_CALL(delegate, CanAcceptGamepadEventsForSurface(testing::_)) 103 EXPECT_CALL(delegate, CanAcceptGamepadEventsForSurface(testing::_))
101 .WillOnce(testing::Return(true)); 104 .WillOnce(testing::Return(true));
102 105
103 InitializeGamepad(&delegate); 106 InitializeGamepad(&delegate);
104 107
105 // Gamepad connected. 108 // Gamepad connected.
106 EXPECT_CALL(delegate, OnStateChange(true)).Times(1); 109 EXPECT_CALL(delegate, OnStateChange(true)).Times(1);
107 blink::WebGamepads gamepad_connected; 110 blink::WebGamepads gamepad_connected;
108 gamepad_connected.length = 1; 111 gamepad_connected.length = 1;
109 gamepad_connected.items[0].connected = true; 112 gamepad_connected.items[0].connected = true;
110 gamepad_connected.items[0].timestamp = 1; 113 gamepad_connected.items[0].timestamp = 1;
111 SetDataAndPostToDelegate(gamepad_connected); 114 SetDataAndPostToDelegate(gamepad_connected);
112 115
113 // Gamepad disconnected. 116 // Gamepad disconnected.
114 blink::WebGamepads all_disconnected; 117 blink::WebGamepads all_disconnected;
115 EXPECT_CALL(delegate, OnStateChange(false)).Times(1); 118 EXPECT_CALL(delegate, OnStateChange(false)).Times(1);
116 SetDataAndPostToDelegate(all_disconnected); 119 SetDataAndPostToDelegate(all_disconnected);
117 120
118 DestroyGamepad(&delegate); 121 DestroyGamepad(&delegate);
119 } 122 }
120 123
121 TEST_F(GamepadTest, OnAxis) { 124 TEST_F(GamepadTest, OnAxis) {
125 const Display display;
122 std::unique_ptr<Surface> surface(new Surface); 126 std::unique_ptr<Surface> surface(new Surface);
123 std::unique_ptr<ShellSurface> shell_surface(new ShellSurface(surface.get())); 127 std::unique_ptr<ShellSurface> shell_surface(
128 new ShellSurface(display, surface.get()));
124 gfx::Size buffer_size(10, 10); 129 gfx::Size buffer_size(10, 10);
125 std::unique_ptr<Buffer> buffer( 130 std::unique_ptr<Buffer> buffer(
126 new Buffer(exo_test_helper()->CreateGpuMemoryBuffer(buffer_size))); 131 new Buffer(exo_test_helper()->CreateGpuMemoryBuffer(buffer_size)));
127 surface->Attach(buffer.get()); 132 surface->Attach(buffer.get());
128 surface->Commit(); 133 surface->Commit();
129 134
130 testing::StrictMock<MockGamepadDelegate> delegate; 135 testing::StrictMock<MockGamepadDelegate> delegate;
131 EXPECT_CALL(delegate, CanAcceptGamepadEventsForSurface(testing::_)) 136 EXPECT_CALL(delegate, CanAcceptGamepadEventsForSurface(testing::_))
132 .WillOnce(testing::Return(true)); 137 .WillOnce(testing::Return(true));
133 138
134 InitializeGamepad(&delegate); 139 InitializeGamepad(&delegate);
135 140
136 blink::WebGamepads axis_moved; 141 blink::WebGamepads axis_moved;
137 axis_moved.length = 1; 142 axis_moved.length = 1;
138 axis_moved.items[0].connected = true; 143 axis_moved.items[0].connected = true;
139 axis_moved.items[0].timestamp = 1; 144 axis_moved.items[0].timestamp = 1;
140 axis_moved.items[0].axesLength = 1; 145 axis_moved.items[0].axesLength = 1;
141 axis_moved.items[0].axes[0] = 1.0; 146 axis_moved.items[0].axes[0] = 1.0;
142 147
143 EXPECT_CALL(delegate, OnStateChange(true)).Times(1); 148 EXPECT_CALL(delegate, OnStateChange(true)).Times(1);
144 EXPECT_CALL(delegate, OnAxis(0, 1.0)).Times(1); 149 EXPECT_CALL(delegate, OnAxis(0, 1.0)).Times(1);
145 EXPECT_CALL(delegate, OnFrame()).Times(1); 150 EXPECT_CALL(delegate, OnFrame()).Times(1);
146 SetDataAndPostToDelegate(axis_moved); 151 SetDataAndPostToDelegate(axis_moved);
147 152
148 DestroyGamepad(&delegate); 153 DestroyGamepad(&delegate);
149 } 154 }
150 155
151 TEST_F(GamepadTest, OnButton) { 156 TEST_F(GamepadTest, OnButton) {
157 const Display display;
152 std::unique_ptr<Surface> surface(new Surface); 158 std::unique_ptr<Surface> surface(new Surface);
153 std::unique_ptr<ShellSurface> shell_surface(new ShellSurface(surface.get())); 159 std::unique_ptr<ShellSurface> shell_surface(
160 new ShellSurface(display, surface.get()));
154 gfx::Size buffer_size(10, 10); 161 gfx::Size buffer_size(10, 10);
155 std::unique_ptr<Buffer> buffer( 162 std::unique_ptr<Buffer> buffer(
156 new Buffer(exo_test_helper()->CreateGpuMemoryBuffer(buffer_size))); 163 new Buffer(exo_test_helper()->CreateGpuMemoryBuffer(buffer_size)));
157 surface->Attach(buffer.get()); 164 surface->Attach(buffer.get());
158 surface->Commit(); 165 surface->Commit();
159 166
160 testing::StrictMock<MockGamepadDelegate> delegate; 167 testing::StrictMock<MockGamepadDelegate> delegate;
161 EXPECT_CALL(delegate, CanAcceptGamepadEventsForSurface(testing::_)) 168 EXPECT_CALL(delegate, CanAcceptGamepadEventsForSurface(testing::_))
162 .WillOnce(testing::Return(true)); 169 .WillOnce(testing::Return(true));
163 170
(...skipping 10 matching lines...) Expand all
174 EXPECT_CALL(delegate, OnStateChange(true)).Times(1); 181 EXPECT_CALL(delegate, OnStateChange(true)).Times(1);
175 EXPECT_CALL(delegate, OnButton(0, true, 1.0)).Times(1); 182 EXPECT_CALL(delegate, OnButton(0, true, 1.0)).Times(1);
176 EXPECT_CALL(delegate, OnFrame()).Times(1); 183 EXPECT_CALL(delegate, OnFrame()).Times(1);
177 SetDataAndPostToDelegate(axis_moved); 184 SetDataAndPostToDelegate(axis_moved);
178 185
179 DestroyGamepad(&delegate); 186 DestroyGamepad(&delegate);
180 } 187 }
181 188
182 TEST_F(GamepadTest, OnWindowFocused) { 189 TEST_F(GamepadTest, OnWindowFocused) {
183 // Create surface and move focus to it. 190 // Create surface and move focus to it.
191 const Display display;
184 std::unique_ptr<Surface> surface(new Surface); 192 std::unique_ptr<Surface> surface(new Surface);
185 std::unique_ptr<ShellSurface> shell_surface(new ShellSurface(surface.get())); 193 std::unique_ptr<ShellSurface> shell_surface(
194 new ShellSurface(display, surface.get()));
186 gfx::Size buffer_size(10, 10); 195 gfx::Size buffer_size(10, 10);
187 std::unique_ptr<Buffer> buffer( 196 std::unique_ptr<Buffer> buffer(
188 new Buffer(exo_test_helper()->CreateGpuMemoryBuffer(buffer_size))); 197 new Buffer(exo_test_helper()->CreateGpuMemoryBuffer(buffer_size)));
189 surface->Attach(buffer.get()); 198 surface->Attach(buffer.get());
190 surface->Commit(); 199 surface->Commit();
191 200
192 testing::StrictMock<MockGamepadDelegate> delegate; 201 testing::StrictMock<MockGamepadDelegate> delegate;
193 EXPECT_CALL(delegate, CanAcceptGamepadEventsForSurface(testing::_)) 202 EXPECT_CALL(delegate, CanAcceptGamepadEventsForSurface(testing::_))
194 .WillOnce(testing::Return(true)); 203 .WillOnce(testing::Return(true));
195 204
(...skipping 17 matching lines...) Expand all
213 // scheduled in the next round. 222 // scheduled in the next round.
214 polling_task_runner_->RunPendingTasks(); 223 polling_task_runner_->RunPendingTasks();
215 polling_task_runner_->RunPendingTasks(); 224 polling_task_runner_->RunPendingTasks();
216 ASSERT_FALSE(polling_task_runner_->HasPendingTask()); 225 ASSERT_FALSE(polling_task_runner_->HasPendingTask());
217 226
218 DestroyGamepad(&delegate); 227 DestroyGamepad(&delegate);
219 } 228 }
220 229
221 } // namespace 230 } // namespace
222 } // namespace exo 231 } // namespace exo
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698