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

Side by Side Diff: content/shell/browser/layout_test/layout_test_bluetooth_adapter_provider.cc

Issue 1264323002: bluetooth: Return specific message if Bluetooth Adapter is off (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@bluetooth-web-bluetooth-action
Patch Set: Add issue to TODO Created 5 years, 4 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 "content/shell/browser/layout_test/layout_test_bluetooth_adapter_provid er.h" 5 #include "content/shell/browser/layout_test/layout_test_bluetooth_adapter_provid er.h"
6 6
7 #include "base/format_macros.h" 7 #include "base/format_macros.h"
8 #include "base/strings/stringprintf.h" 8 #include "base/strings/stringprintf.h"
9 #include "device/bluetooth/bluetooth_adapter.h" 9 #include "device/bluetooth/bluetooth_adapter.h"
10 #include "device/bluetooth/bluetooth_device.h" 10 #include "device/bluetooth/bluetooth_device.h"
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after
93 } // namespace 93 } // namespace
94 94
95 namespace content { 95 namespace content {
96 96
97 // static 97 // static
98 scoped_refptr<BluetoothAdapter> 98 scoped_refptr<BluetoothAdapter>
99 LayoutTestBluetoothAdapterProvider::GetBluetoothAdapter( 99 LayoutTestBluetoothAdapterProvider::GetBluetoothAdapter(
100 const std::string& fake_adapter_name) { 100 const std::string& fake_adapter_name) {
101 if (fake_adapter_name == "BaseAdapter") 101 if (fake_adapter_name == "BaseAdapter")
102 return GetBaseAdapter(); 102 return GetBaseAdapter();
103 else if (fake_adapter_name == "NotPresentAdapter")
104 return GetNotPresentAdapter();
105 else if (fake_adapter_name == "NotPoweredAdapter")
106 return GetNotPoweredAdapter();
103 else if (fake_adapter_name == "ScanFilterCheckingAdapter") 107 else if (fake_adapter_name == "ScanFilterCheckingAdapter")
104 return GetScanFilterCheckingAdapter(); 108 return GetScanFilterCheckingAdapter();
105 else if (fake_adapter_name == "EmptyAdapter") 109 else if (fake_adapter_name == "EmptyAdapter")
106 return GetEmptyAdapter(); 110 return GetEmptyAdapter();
107 else if (fake_adapter_name == "FailStartDiscoveryAdapter") 111 else if (fake_adapter_name == "FailStartDiscoveryAdapter")
108 return GetFailStartDiscoveryAdapter(); 112 return GetFailStartDiscoveryAdapter();
109 else if (fake_adapter_name == "GlucoseHeartRateAdapter") 113 else if (fake_adapter_name == "GlucoseHeartRateAdapter")
110 return GetGlucoseHeartRateAdapter(); 114 return GetGlucoseHeartRateAdapter();
111 else if (fake_adapter_name == "MissingServiceGenericAccessAdapter") 115 else if (fake_adapter_name == "MissingServiceGenericAccessAdapter")
112 return GetMissingServiceGenericAccessAdapter(); 116 return GetMissingServiceGenericAccessAdapter();
(...skipping 29 matching lines...) Expand all
142 146
143 // The call to ::GetDevice will invoke GetMockDevice which returns a device 147 // The call to ::GetDevice will invoke GetMockDevice which returns a device
144 // matching the address provided if the device was added to the mock. 148 // matching the address provided if the device was added to the mock.
145 ON_CALL(*adapter, GetDevice(_)).WillByDefault(GetMockDevice(adapter.get())); 149 ON_CALL(*adapter, GetDevice(_)).WillByDefault(GetMockDevice(adapter.get()));
146 150
147 return adapter.Pass(); 151 return adapter.Pass();
148 } 152 }
149 153
150 // static 154 // static
151 scoped_refptr<NiceMockBluetoothAdapter> 155 scoped_refptr<NiceMockBluetoothAdapter>
156 LayoutTestBluetoothAdapterProvider::GetPresentAdapter() {
157 scoped_refptr<NiceMockBluetoothAdapter> adapter(GetBaseAdapter());
158 ON_CALL(*adapter, IsPresent()).WillByDefault(Return(true));
159
160 return adapter.Pass();
161 }
162
163 // static
164 scoped_refptr<NiceMockBluetoothAdapter>
165 LayoutTestBluetoothAdapterProvider::GetNotPresentAdapter() {
166 scoped_refptr<NiceMockBluetoothAdapter> adapter(GetBaseAdapter());
167 ON_CALL(*adapter, IsPresent()).WillByDefault(Return(false));
168
169 return adapter.Pass();
170 }
171
172 // static
173 scoped_refptr<NiceMockBluetoothAdapter>
174 LayoutTestBluetoothAdapterProvider::GetPoweredAdapter() {
175 scoped_refptr<NiceMockBluetoothAdapter> adapter(GetPresentAdapter());
176 ON_CALL(*adapter, IsPowered()).WillByDefault(Return(true));
177
178 return adapter.Pass();
179 }
180
181 // static
182 scoped_refptr<NiceMockBluetoothAdapter>
183 LayoutTestBluetoothAdapterProvider::GetNotPoweredAdapter() {
184 scoped_refptr<NiceMockBluetoothAdapter> adapter(GetPresentAdapter());
185 ON_CALL(*adapter, IsPowered()).WillByDefault(Return(false));
186
187 return adapter.Pass();
188 }
189
190 // static
191 scoped_refptr<NiceMockBluetoothAdapter>
152 LayoutTestBluetoothAdapterProvider::GetScanFilterCheckingAdapter() { 192 LayoutTestBluetoothAdapterProvider::GetScanFilterCheckingAdapter() {
153 scoped_refptr<NiceMockBluetoothAdapter> adapter(GetBaseAdapter()); 193 scoped_refptr<NiceMockBluetoothAdapter> adapter(GetPoweredAdapter());
154 194
155 // This fails the test with an error message listing actual and expected UUIDs 195 // This fails the test with an error message listing actual and expected UUIDs
156 // if StartDiscoverySessionWithFilter() is called with the wrong argument. 196 // if StartDiscoverySessionWithFilter() is called with the wrong argument.
157 EXPECT_CALL( 197 EXPECT_CALL(
158 *adapter, 198 *adapter,
159 StartDiscoverySessionWithFilterRaw( 199 StartDiscoverySessionWithFilterRaw(
160 ResultOf(&GetUUIDs, ElementsAre(BluetoothUUID(kGlucoseServiceUUID), 200 ResultOf(&GetUUIDs, ElementsAre(BluetoothUUID(kGlucoseServiceUUID),
161 BluetoothUUID(kHeartRateServiceUUID), 201 BluetoothUUID(kHeartRateServiceUUID),
162 BluetoothUUID(kBatteryServiceUUID))), 202 BluetoothUUID(kBatteryServiceUUID))),
163 _, _)) 203 _, _))
164 .WillRepeatedly(RunCallbackWithResult<1 /* success_callback */>( 204 .WillRepeatedly(RunCallbackWithResult<1 /* success_callback */>(
165 []() { return GetDiscoverySession(); })); 205 []() { return GetDiscoverySession(); }));
166 206
167 // Any unexpected call results in the failure callback. 207 // Any unexpected call results in the failure callback.
168 ON_CALL(*adapter, StartDiscoverySessionWithFilterRaw(_, _, _)) 208 ON_CALL(*adapter, StartDiscoverySessionWithFilterRaw(_, _, _))
169 .WillByDefault(RunCallback<2 /* error_callback */>()); 209 .WillByDefault(RunCallback<2 /* error_callback */>());
170 210
171 // We need to add a device otherwise requestDevice would reject. 211 // We need to add a device otherwise requestDevice would reject.
172 adapter->AddMockDevice(GetBatteryDevice(adapter.get())); 212 adapter->AddMockDevice(GetBatteryDevice(adapter.get()));
173 213
174 return adapter.Pass(); 214 return adapter.Pass();
175 } 215 }
176 216
177 // static 217 // static
178 scoped_refptr<NiceMockBluetoothAdapter> 218 scoped_refptr<NiceMockBluetoothAdapter>
179 LayoutTestBluetoothAdapterProvider::GetFailStartDiscoveryAdapter() { 219 LayoutTestBluetoothAdapterProvider::GetFailStartDiscoveryAdapter() {
180 scoped_refptr<NiceMockBluetoothAdapter> adapter(GetBaseAdapter()); 220 scoped_refptr<NiceMockBluetoothAdapter> adapter(GetPoweredAdapter());
181 221
182 ON_CALL(*adapter, StartDiscoverySessionWithFilterRaw(_, _, _)) 222 ON_CALL(*adapter, StartDiscoverySessionWithFilterRaw(_, _, _))
183 .WillByDefault(RunCallback<2 /* error_callback */>()); 223 .WillByDefault(RunCallback<2 /* error_callback */>());
184 224
185 return adapter.Pass(); 225 return adapter.Pass();
186 } 226 }
187 227
188 // static 228 // static
189 scoped_refptr<NiceMockBluetoothAdapter> 229 scoped_refptr<NiceMockBluetoothAdapter>
190 LayoutTestBluetoothAdapterProvider::GetEmptyAdapter() { 230 LayoutTestBluetoothAdapterProvider::GetEmptyAdapter() {
191 scoped_refptr<NiceMockBluetoothAdapter> adapter(GetBaseAdapter()); 231 scoped_refptr<NiceMockBluetoothAdapter> adapter(GetPoweredAdapter());
192 232
193 ON_CALL(*adapter, StartDiscoverySessionWithFilterRaw(_, _, _)) 233 ON_CALL(*adapter, StartDiscoverySessionWithFilterRaw(_, _, _))
194 .WillByDefault(RunCallbackWithResult<1 /* success_callback */>( 234 .WillByDefault(RunCallbackWithResult<1 /* success_callback */>(
195 []() { return GetDiscoverySession(); })); 235 []() { return GetDiscoverySession(); }));
196 236
197 return adapter.Pass(); 237 return adapter.Pass();
198 } 238 }
199 239
200 // static 240 // static
201 scoped_refptr<NiceMockBluetoothAdapter> 241 scoped_refptr<NiceMockBluetoothAdapter>
(...skipping 309 matching lines...) Expand 10 before | Expand all | Expand 10 after
511 return base::StringPrintf("%08x-97e5-4cd7-b9f1-f5a427670c59", alias); 551 return base::StringPrintf("%08x-97e5-4cd7-b9f1-f5a427670c59", alias);
512 } 552 }
513 553
514 // static 554 // static
515 std::string LayoutTestBluetoothAdapterProvider::makeMACAddress(uint64_t addr) { 555 std::string LayoutTestBluetoothAdapterProvider::makeMACAddress(uint64_t addr) {
516 return BluetoothDevice::CanonicalizeAddress( 556 return BluetoothDevice::CanonicalizeAddress(
517 base::StringPrintf("%012" PRIx64, addr)); 557 base::StringPrintf("%012" PRIx64, addr));
518 } 558 }
519 559
520 } // namespace content 560 } // namespace content
OLDNEW
« no previous file with comments | « content/shell/browser/layout_test/layout_test_bluetooth_adapter_provider.h ('k') | tools/metrics/histograms/histograms.xml » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698