OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 "base/bind.h" | 5 #include "base/bind.h" |
6 #include "base/run_loop.h" | 6 #include "base/run_loop.h" |
7 #include "base/thread_task_runner_handle.h" | 7 #include "base/thread_task_runner_handle.h" |
8 #include "device/hid/hid_collection_info.h" | 8 #include "device/hid/hid_collection_info.h" |
9 #include "device/hid/hid_connection.h" | 9 #include "device/hid/hid_connection.h" |
10 #include "device/hid/hid_device_info.h" | 10 #include "device/hid/hid_device_info.h" |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
51 scoped_refptr<IOBuffer> buffer(new IOBuffer(sizeof(kResult))); | 51 scoped_refptr<IOBuffer> buffer(new IOBuffer(sizeof(kResult))); |
52 buffer->data()[0] = report_id; | 52 buffer->data()[0] = report_id; |
53 memcpy(buffer->data() + 1, kResult, sizeof(kResult) - 1); | 53 memcpy(buffer->data() + 1, kResult, sizeof(kResult) - 1); |
54 ThreadTaskRunnerHandle::Get()->PostTask( | 54 ThreadTaskRunnerHandle::Get()->PostTask( |
55 FROM_HERE, base::Bind(callback, true, buffer, sizeof(kResult))); | 55 FROM_HERE, base::Bind(callback, true, buffer, sizeof(kResult))); |
56 } | 56 } |
57 | 57 |
58 void PlatformWrite(scoped_refptr<net::IOBuffer> buffer, | 58 void PlatformWrite(scoped_refptr<net::IOBuffer> buffer, |
59 size_t size, | 59 size_t size, |
60 const WriteCallback& callback) override { | 60 const WriteCallback& callback) override { |
61 const char kExpected[] = "This is a HID output report."; | 61 const char kExpected[] = "o-report"; // 8 bytes |
62 bool result = false; | 62 bool result = false; |
63 if (size == sizeof(kExpected)) { | 63 if (size == sizeof(kExpected)) { |
64 uint8_t report_id = buffer->data()[0]; | 64 uint8_t report_id = buffer->data()[0]; |
65 uint8_t expected_report_id = device_info()->has_report_id() ? 1 : 0; | 65 uint8_t expected_report_id = device_info()->has_report_id() ? 1 : 0; |
66 if (report_id == expected_report_id) { | 66 if (report_id == expected_report_id) { |
67 if (memcmp(buffer->data() + 1, kExpected, sizeof(kExpected) - 1) == 0) { | 67 if (memcmp(buffer->data() + 1, kExpected, sizeof(kExpected) - 1) == 0) { |
68 result = true; | 68 result = true; |
69 } | 69 } |
70 } | 70 } |
71 } | 71 } |
(...skipping 135 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
207 // Device C was not returned by chrome.hid.getDevices, the app will not get | 207 // Device C was not returned by chrome.hid.getDevices, the app will not get |
208 // a notification. | 208 // a notification. |
209 hid_service_->RemoveDevice("C"); | 209 hid_service_->RemoveDevice("C"); |
210 // Device A was returned, the app will get a notification. | 210 // Device A was returned, the app will get a notification. |
211 hid_service_->RemoveDevice("A"); | 211 hid_service_->RemoveDevice("A"); |
212 ASSERT_TRUE(result_listener.WaitUntilSatisfied()); | 212 ASSERT_TRUE(result_listener.WaitUntilSatisfied()); |
213 EXPECT_EQ("success", result_listener.message()); | 213 EXPECT_EQ("success", result_listener.message()); |
214 } | 214 } |
215 | 215 |
216 } // namespace extensions | 216 } // namespace extensions |
OLD | NEW |