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

Side by Side Diff: content/browser/gamepad/gamepad_test_helpers.cc

Issue 1586663006: Refactoring gamepad polling to support dynamically added sources (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Avoid crash on Android content_unittests Created 4 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
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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 "content/browser/gamepad/gamepad_test_helpers.h" 5 #include "content/browser/gamepad/gamepad_test_helpers.h"
6 6
7 #include "content/browser/gamepad/gamepad_service.h" 7 #include "content/browser/gamepad/gamepad_service.h"
8 8
9 namespace content { 9 namespace content {
10 10
11 MockGamepadDataFetcher::MockGamepadDataFetcher( 11 MockGamepadDataFetcher::MockGamepadDataFetcher(
12 const blink::WebGamepads& test_data) 12 const blink::WebGamepads& test_data)
13 : test_data_(test_data), 13 : test_data_(test_data),
14 read_data_(false, false) { 14 read_data_(false, false) {
15 } 15 }
16 16
17 MockGamepadDataFetcher::~MockGamepadDataFetcher() { 17 MockGamepadDataFetcher::~MockGamepadDataFetcher() {
18 } 18 }
19 19
20 void MockGamepadDataFetcher::GetGamepadData(blink::WebGamepads* pads, 20 void MockGamepadDataFetcher::GetGamepadData(bool devices_changed_hint) {
21 bool devices_changed_hint) {
22 { 21 {
23 base::AutoLock lock(lock_); 22 base::AutoLock lock(lock_);
24 *pads = test_data_; 23
24 for (unsigned int i = 0; i < blink::WebGamepads::itemsLengthCap; ++i) {
25 if (test_data_.items[i].connected) {
26 PadState* pad = provider()->GetPadState(GAMEPAD_SOURCE_TEST, i);
27 if (pad)
28 memcpy(&pad->data, &test_data_.items[i], sizeof(blink::WebGamepad));
29 }
30 }
25 } 31 }
26 read_data_.Signal(); 32 read_data_.Signal();
27 } 33 }
28 34
29 void MockGamepadDataFetcher::WaitForDataRead() { 35 void MockGamepadDataFetcher::WaitForDataRead() {
30 return read_data_.Wait(); 36 return read_data_.Wait();
31 } 37 }
32 38
33 void MockGamepadDataFetcher::WaitForDataReadAndCallbacksIssued() { 39 void MockGamepadDataFetcher::WaitForDataReadAndCallbacksIssued() {
34 // The provider will read the data on the background thread (setting the 40 // The provider will read the data on the background thread (setting the
(...skipping 20 matching lines...) Expand all
55 data_fetcher_ = new MockGamepadDataFetcher(test_data); 61 data_fetcher_ = new MockGamepadDataFetcher(test_data);
56 gamepad_service_ = 62 gamepad_service_ =
57 new GamepadService(scoped_ptr<GamepadDataFetcher>(data_fetcher_)); 63 new GamepadService(scoped_ptr<GamepadDataFetcher>(data_fetcher_));
58 } 64 }
59 65
60 GamepadServiceTestConstructor::~GamepadServiceTestConstructor() { 66 GamepadServiceTestConstructor::~GamepadServiceTestConstructor() {
61 delete gamepad_service_; 67 delete gamepad_service_;
62 } 68 }
63 69
64 } // namespace content 70 } // namespace content
OLDNEW
« no previous file with comments | « content/browser/gamepad/gamepad_test_helpers.h ('k') | content/browser/gamepad/raw_input_data_fetcher_win.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698