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

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

Issue 2572323002: Delete WebGamepads::length. (Closed)
Patch Set: Rebase Created 3 years, 11 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 | « components/exo/gamepad.cc ('k') | components/test_runner/gamepad_controller.cc » ('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 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/gamepad.h" 10 #include "components/exo/gamepad.h"
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after
98 98
99 testing::StrictMock<MockGamepadDelegate> delegate; 99 testing::StrictMock<MockGamepadDelegate> delegate;
100 EXPECT_CALL(delegate, CanAcceptGamepadEventsForSurface(testing::_)) 100 EXPECT_CALL(delegate, CanAcceptGamepadEventsForSurface(testing::_))
101 .WillOnce(testing::Return(true)); 101 .WillOnce(testing::Return(true));
102 102
103 InitializeGamepad(&delegate); 103 InitializeGamepad(&delegate);
104 104
105 // Gamepad connected. 105 // Gamepad connected.
106 EXPECT_CALL(delegate, OnStateChange(true)).Times(1); 106 EXPECT_CALL(delegate, OnStateChange(true)).Times(1);
107 blink::WebGamepads gamepad_connected; 107 blink::WebGamepads gamepad_connected;
108 gamepad_connected.length = 1;
109 gamepad_connected.items[0].connected = true; 108 gamepad_connected.items[0].connected = true;
110 gamepad_connected.items[0].timestamp = 1; 109 gamepad_connected.items[0].timestamp = 1;
111 SetDataAndPostToDelegate(gamepad_connected); 110 SetDataAndPostToDelegate(gamepad_connected);
112 111
113 // Gamepad disconnected. 112 // Gamepad disconnected.
114 blink::WebGamepads all_disconnected; 113 blink::WebGamepads all_disconnected;
115 EXPECT_CALL(delegate, OnStateChange(false)).Times(1); 114 EXPECT_CALL(delegate, OnStateChange(false)).Times(1);
116 SetDataAndPostToDelegate(all_disconnected); 115 SetDataAndPostToDelegate(all_disconnected);
117 116
118 DestroyGamepad(&delegate); 117 DestroyGamepad(&delegate);
119 } 118 }
120 119
121 TEST_F(GamepadTest, OnAxis) { 120 TEST_F(GamepadTest, OnAxis) {
122 std::unique_ptr<Surface> surface(new Surface); 121 std::unique_ptr<Surface> surface(new Surface);
123 std::unique_ptr<ShellSurface> shell_surface(new ShellSurface(surface.get())); 122 std::unique_ptr<ShellSurface> shell_surface(new ShellSurface(surface.get()));
124 gfx::Size buffer_size(10, 10); 123 gfx::Size buffer_size(10, 10);
125 std::unique_ptr<Buffer> buffer( 124 std::unique_ptr<Buffer> buffer(
126 new Buffer(exo_test_helper()->CreateGpuMemoryBuffer(buffer_size))); 125 new Buffer(exo_test_helper()->CreateGpuMemoryBuffer(buffer_size)));
127 surface->Attach(buffer.get()); 126 surface->Attach(buffer.get());
128 surface->Commit(); 127 surface->Commit();
129 128
130 testing::StrictMock<MockGamepadDelegate> delegate; 129 testing::StrictMock<MockGamepadDelegate> delegate;
131 EXPECT_CALL(delegate, CanAcceptGamepadEventsForSurface(testing::_)) 130 EXPECT_CALL(delegate, CanAcceptGamepadEventsForSurface(testing::_))
132 .WillOnce(testing::Return(true)); 131 .WillOnce(testing::Return(true));
133 132
134 InitializeGamepad(&delegate); 133 InitializeGamepad(&delegate);
135 134
136 blink::WebGamepads axis_moved; 135 blink::WebGamepads axis_moved;
137 axis_moved.length = 1;
138 axis_moved.items[0].connected = true; 136 axis_moved.items[0].connected = true;
139 axis_moved.items[0].timestamp = 1; 137 axis_moved.items[0].timestamp = 1;
140 axis_moved.items[0].axesLength = 1; 138 axis_moved.items[0].axesLength = 1;
141 axis_moved.items[0].axes[0] = 1.0; 139 axis_moved.items[0].axes[0] = 1.0;
142 140
143 EXPECT_CALL(delegate, OnStateChange(true)).Times(1); 141 EXPECT_CALL(delegate, OnStateChange(true)).Times(1);
144 EXPECT_CALL(delegate, OnAxis(0, 1.0)).Times(1); 142 EXPECT_CALL(delegate, OnAxis(0, 1.0)).Times(1);
145 EXPECT_CALL(delegate, OnFrame()).Times(1); 143 EXPECT_CALL(delegate, OnFrame()).Times(1);
146 SetDataAndPostToDelegate(axis_moved); 144 SetDataAndPostToDelegate(axis_moved);
147 145
148 DestroyGamepad(&delegate); 146 DestroyGamepad(&delegate);
149 } 147 }
150 148
151 TEST_F(GamepadTest, OnButton) { 149 TEST_F(GamepadTest, OnButton) {
152 std::unique_ptr<Surface> surface(new Surface); 150 std::unique_ptr<Surface> surface(new Surface);
153 std::unique_ptr<ShellSurface> shell_surface(new ShellSurface(surface.get())); 151 std::unique_ptr<ShellSurface> shell_surface(new ShellSurface(surface.get()));
154 gfx::Size buffer_size(10, 10); 152 gfx::Size buffer_size(10, 10);
155 std::unique_ptr<Buffer> buffer( 153 std::unique_ptr<Buffer> buffer(
156 new Buffer(exo_test_helper()->CreateGpuMemoryBuffer(buffer_size))); 154 new Buffer(exo_test_helper()->CreateGpuMemoryBuffer(buffer_size)));
157 surface->Attach(buffer.get()); 155 surface->Attach(buffer.get());
158 surface->Commit(); 156 surface->Commit();
159 157
160 testing::StrictMock<MockGamepadDelegate> delegate; 158 testing::StrictMock<MockGamepadDelegate> delegate;
161 EXPECT_CALL(delegate, CanAcceptGamepadEventsForSurface(testing::_)) 159 EXPECT_CALL(delegate, CanAcceptGamepadEventsForSurface(testing::_))
162 .WillOnce(testing::Return(true)); 160 .WillOnce(testing::Return(true));
163 161
164 InitializeGamepad(&delegate); 162 InitializeGamepad(&delegate);
165 163
166 blink::WebGamepads axis_moved; 164 blink::WebGamepads axis_moved;
167 axis_moved.length = 1;
168 axis_moved.items[0].connected = true; 165 axis_moved.items[0].connected = true;
169 axis_moved.items[0].timestamp = 1; 166 axis_moved.items[0].timestamp = 1;
170 axis_moved.items[0].buttonsLength = 1; 167 axis_moved.items[0].buttonsLength = 1;
171 axis_moved.items[0].buttons[0].pressed = true; 168 axis_moved.items[0].buttons[0].pressed = true;
172 axis_moved.items[0].buttons[0].value = 1.0; 169 axis_moved.items[0].buttons[0].value = 1.0;
173 170
174 EXPECT_CALL(delegate, OnStateChange(true)).Times(1); 171 EXPECT_CALL(delegate, OnStateChange(true)).Times(1);
175 EXPECT_CALL(delegate, OnButton(0, true, 1.0)).Times(1); 172 EXPECT_CALL(delegate, OnButton(0, true, 1.0)).Times(1);
176 EXPECT_CALL(delegate, OnFrame()).Times(1); 173 EXPECT_CALL(delegate, OnFrame()).Times(1);
177 SetDataAndPostToDelegate(axis_moved); 174 SetDataAndPostToDelegate(axis_moved);
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
213 // scheduled in the next round. 210 // scheduled in the next round.
214 polling_task_runner_->RunPendingTasks(); 211 polling_task_runner_->RunPendingTasks();
215 polling_task_runner_->RunPendingTasks(); 212 polling_task_runner_->RunPendingTasks();
216 ASSERT_FALSE(polling_task_runner_->HasPendingTask()); 213 ASSERT_FALSE(polling_task_runner_->HasPendingTask());
217 214
218 DestroyGamepad(&delegate); 215 DestroyGamepad(&delegate);
219 } 216 }
220 217
221 } // namespace 218 } // namespace
222 } // namespace exo 219 } // namespace exo
OLDNEW
« no previous file with comments | « components/exo/gamepad.cc ('k') | components/test_runner/gamepad_controller.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698