OLD | NEW |
---|---|
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 <string.h> | 5 #include <string.h> |
6 | 6 |
7 #include "chrome/browser/chromeos/bluetooth/bluetooth_adapter.h" | 7 #include "chrome/browser/chromeos/bluetooth/bluetooth_adapter.h" |
8 #include "chrome/browser/chromeos/bluetooth/test/mock_bluetooth_adapter.h" | 8 #include "chrome/browser/chromeos/bluetooth/test/mock_bluetooth_adapter.h" |
9 #include "chrome/browser/chromeos/bluetooth/test/mock_bluetooth_device.h" | 9 #include "chrome/browser/chromeos/bluetooth/test/mock_bluetooth_device.h" |
10 #include "chrome/browser/chromeos/extensions/bluetooth_event_router.h" | 10 #include "chrome/browser/chromeos/extensions/bluetooth_event_router.h" |
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
68 | 68 |
69 chromeos::ExtensionBluetoothEventRouter* event_router() { | 69 chromeos::ExtensionBluetoothEventRouter* event_router() { |
70 return browser()->profile()->GetExtensionService()-> | 70 return browser()->profile()->GetExtensionService()-> |
71 bluetooth_event_router(); | 71 bluetooth_event_router(); |
72 } | 72 } |
73 | 73 |
74 private: | 74 private: |
75 scoped_refptr<Extension> empty_extension_; | 75 scoped_refptr<Extension> empty_extension_; |
76 }; | 76 }; |
77 | 77 |
78 // This is the canonical UUID for the short UUID 0010. | |
79 static const char kCanonicalUuid[] = "00000010-0000-1000-8000-00805f9b34fb"; | |
78 static const char kOutOfBandPairingDataHash[] = "0123456789ABCDEh"; | 80 static const char kOutOfBandPairingDataHash[] = "0123456789ABCDEh"; |
79 static const char kOutOfBandPairingDataRandomizer[] = "0123456789ABCDEr"; | 81 static const char kOutOfBandPairingDataRandomizer[] = "0123456789ABCDEr"; |
80 | 82 |
81 static chromeos::BluetoothOutOfBandPairingData GetOutOfBandPairingData() { | 83 static chromeos::BluetoothOutOfBandPairingData GetOutOfBandPairingData() { |
82 chromeos::BluetoothOutOfBandPairingData data; | 84 chromeos::BluetoothOutOfBandPairingData data; |
83 memcpy(&(data.hash), kOutOfBandPairingDataHash, | 85 memcpy(&(data.hash), kOutOfBandPairingDataHash, |
84 chromeos::kBluetoothOutOfBandPairingDataSize); | 86 chromeos::kBluetoothOutOfBandPairingDataSize); |
85 memcpy(&(data.randomizer), kOutOfBandPairingDataRandomizer, | 87 memcpy(&(data.randomizer), kOutOfBandPairingDataRandomizer, |
86 chromeos::kBluetoothOutOfBandPairingDataSize); | 88 chromeos::kBluetoothOutOfBandPairingDataSize); |
87 return data; | 89 return data; |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
133 | 135 |
134 is_powered = setupFunction(new api::BluetoothIsPoweredFunction); | 136 is_powered = setupFunction(new api::BluetoothIsPoweredFunction); |
135 expectBooleanResult(true, is_powered, "[]"); | 137 expectBooleanResult(true, is_powered, "[]"); |
136 } | 138 } |
137 | 139 |
138 IN_PROC_BROWSER_TEST_F(BluetoothApiTest, GetDevices) { | 140 IN_PROC_BROWSER_TEST_F(BluetoothApiTest, GetDevices) { |
139 chromeos::BluetoothAdapter::ConstDeviceList devices; | 141 chromeos::BluetoothAdapter::ConstDeviceList devices; |
140 devices.push_back(device1_.get()); | 142 devices.push_back(device1_.get()); |
141 devices.push_back(device2_.get()); | 143 devices.push_back(device2_.get()); |
142 | 144 |
143 EXPECT_CALL(*device1_, ProvidesServiceWithUUID("foo")) | 145 EXPECT_CALL(*device1_, ProvidesServiceWithUUID(kCanonicalUuid)) |
144 .WillOnce(testing::Return(false)); | 146 .WillOnce(testing::Return(false)); |
145 EXPECT_CALL(*device2_, ProvidesServiceWithUUID("foo")) | 147 EXPECT_CALL(*device2_, ProvidesServiceWithUUID(kCanonicalUuid)) |
146 .WillOnce(testing::Return(true)); | 148 .WillOnce(testing::Return(true)); |
147 | 149 |
148 EXPECT_CALL(*mock_adapter_, GetDevices()) | 150 EXPECT_CALL(*mock_adapter_, GetDevices()) |
149 .WillOnce(testing::Return(devices)); | 151 .WillOnce(testing::Return(devices)); |
150 | 152 |
151 scoped_refptr<api::BluetoothGetDevicesFunction> get_devices; | 153 scoped_refptr<api::BluetoothGetDevicesFunction> get_devices; |
152 | 154 |
153 get_devices = setupFunction(new api::BluetoothGetDevicesFunction); | 155 get_devices = setupFunction(new api::BluetoothGetDevicesFunction); |
154 scoped_ptr<base::Value> result(utils::RunFunctionAndReturnSingleResult( | 156 scoped_ptr<base::Value> result(utils::RunFunctionAndReturnSingleResult( |
155 get_devices, | 157 get_devices, |
156 "[{\"uuid\":\"foo\"}]", | 158 "[{\"uuid\":\"0010\"}]", |
157 browser())); | 159 browser())); |
158 | 160 |
159 ASSERT_EQ(base::Value::TYPE_LIST, result->GetType()); | 161 ASSERT_EQ(base::Value::TYPE_LIST, result->GetType()); |
160 base::ListValue* list; | 162 base::ListValue* list; |
161 ASSERT_TRUE(result->GetAsList(&list)); | 163 ASSERT_TRUE(result->GetAsList(&list)); |
162 | 164 |
163 EXPECT_EQ(1u, list->GetSize()); | 165 EXPECT_EQ(1u, list->GetSize()); |
164 base::Value* device_value; | 166 base::Value* device_value; |
165 EXPECT_TRUE(list->Get(0, &device_value)); | 167 EXPECT_TRUE(list->Get(0, &device_value)); |
166 EXPECT_EQ(base::Value::TYPE_DICTIONARY, device_value->GetType()); | 168 EXPECT_EQ(base::Value::TYPE_DICTIONARY, device_value->GetType()); |
(...skipping 22 matching lines...) Expand all Loading... | |
189 .WillOnce(testing::Return(devices)); | 191 .WillOnce(testing::Return(devices)); |
190 | 192 |
191 get_devices = setupFunction(new api::BluetoothGetDevicesFunction); | 193 get_devices = setupFunction(new api::BluetoothGetDevicesFunction); |
192 result.reset( | 194 result.reset( |
193 utils::RunFunctionAndReturnSingleResult(get_devices, "[{}]", browser())); | 195 utils::RunFunctionAndReturnSingleResult(get_devices, "[{}]", browser())); |
194 | 196 |
195 ASSERT_EQ(base::Value::TYPE_LIST, result->GetType()); | 197 ASSERT_EQ(base::Value::TYPE_LIST, result->GetType()); |
196 ASSERT_TRUE(result->GetAsList(&list)); | 198 ASSERT_TRUE(result->GetAsList(&list)); |
197 | 199 |
198 EXPECT_EQ(2u, list->GetSize()); | 200 EXPECT_EQ(2u, list->GetSize()); |
201 | |
202 // Try again with an error | |
203 testing::Mock::VerifyAndClearExpectations(mock_adapter_); | |
204 | |
205 get_devices = setupFunction(new api::BluetoothGetDevicesFunction); | |
206 std::string error( | |
207 utils::RunFunctionAndReturnError(get_devices, | |
208 "[{\"uuid\":\"foo\"}]", | |
209 browser())); | |
210 EXPECT_FALSE(error.empty()); | |
satorux1
2012/07/24 18:29:21
would it make sense to check the error contents wi
bryeung
2012/07/24 19:50:09
Doesn't really seem worthwhile: I don't think it a
| |
199 } | 211 } |
200 | 212 |
201 IN_PROC_BROWSER_TEST_F(BluetoothApiTest, GetLocalOutOfBandPairingData) { | 213 IN_PROC_BROWSER_TEST_F(BluetoothApiTest, GetLocalOutOfBandPairingData) { |
202 EXPECT_CALL(*mock_adapter_, | 214 EXPECT_CALL(*mock_adapter_, |
203 ReadLocalOutOfBandPairingData( | 215 ReadLocalOutOfBandPairingData( |
204 testing::Truly(CallOutOfBandPairingDataCallback), | 216 testing::Truly(CallOutOfBandPairingDataCallback), |
205 testing::_)); | 217 testing::_)); |
206 | 218 |
207 scoped_refptr<api::BluetoothGetLocalOutOfBandPairingDataFunction> | 219 scoped_refptr<api::BluetoothGetLocalOutOfBandPairingDataFunction> |
208 get_oob_function(setupFunction( | 220 get_oob_function(setupFunction( |
(...skipping 153 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
362 | 374 |
363 event_router()->AdapterPoweredChanged(mock_adapter_, true); | 375 event_router()->AdapterPoweredChanged(mock_adapter_, true); |
364 event_router()->AdapterPoweredChanged(mock_adapter_, false); | 376 event_router()->AdapterPoweredChanged(mock_adapter_, false); |
365 event_router()->AdapterPresentChanged(mock_adapter_, true); | 377 event_router()->AdapterPresentChanged(mock_adapter_, true); |
366 event_router()->AdapterPresentChanged(mock_adapter_, false); | 378 event_router()->AdapterPresentChanged(mock_adapter_, false); |
367 | 379 |
368 listener.Reply("go"); | 380 listener.Reply("go"); |
369 | 381 |
370 EXPECT_TRUE(catcher.GetNextResult()) << catcher.message(); | 382 EXPECT_TRUE(catcher.GetNextResult()) << catcher.message(); |
371 } | 383 } |
OLD | NEW |