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

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

Issue 1138913006: bluetooth: Refactor LayoutTestBluetoothAdapterProvider. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@bluetooth-testing-remove-mocking
Patch Set: Created 5 years, 7 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 "device/bluetooth/bluetooth_adapter.h" 7 #include "device/bluetooth/bluetooth_adapter.h"
8 #include "device/bluetooth/bluetooth_device.h" 8 #include "device/bluetooth/bluetooth_device.h"
9 #include "device/bluetooth/bluetooth_discovery_session.h" 9 #include "device/bluetooth/bluetooth_discovery_session.h"
10 #include "device/bluetooth/bluetooth_uuid.h" 10 #include "device/bluetooth/bluetooth_uuid.h"
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
46 NOTREACHED(); 46 NOTREACHED();
47 return NULL; 47 return NULL;
48 } 48 }
49 49
50 // static 50 // static
51 scoped_refptr<NiceMock<MockBluetoothAdapter>> 51 scoped_refptr<NiceMock<MockBluetoothAdapter>>
52 LayoutTestBluetoothAdapterProvider::GetEmptyAdapter() { 52 LayoutTestBluetoothAdapterProvider::GetEmptyAdapter() {
53 scoped_refptr<NiceMock<MockBluetoothAdapter>> adapter( 53 scoped_refptr<NiceMock<MockBluetoothAdapter>> adapter(
54 new NiceMock<MockBluetoothAdapter>()); 54 new NiceMock<MockBluetoothAdapter>());
55 55
56 scoped_ptr<NiceMock<MockBluetoothDiscoverySession>> discovery_session(
57 GetDiscoverySession());
58
56 ON_CALL(*adapter, StartDiscoverySession(_, _)) 59 ON_CALL(*adapter, StartDiscoverySession(_, _))
57 .WillByDefault(Invoke( 60 .WillByDefault(RunCallbackScoped<0 /* success_callback */,
58 &LayoutTestBluetoothAdapterProvider::SuccessfulDiscoverySession)); 61 BluetoothDiscoverySession>(
62 discovery_session.release()));
Jeffrey Yasskin 2015/05/19 01:09:01 This will crash if StartDiscoverySession is called
ortuno 2015/05/19 01:51:53 Ah but then you can't construct the session before
Jeffrey Yasskin 2015/05/19 17:13:59 Hm, why do you need to construct the session befor
ortuno 2015/05/19 19:51:18 For BluetoothDiscoverySession we don't. But we wil
Jeffrey Yasskin 2015/05/19 20:47:49 Mhmm. Note that you can use lambdas to embed other
ortuno 2015/05/19 23:03:34 Completely forgot about lambdas. Done. Please let
59 63
60 ON_CALL(*adapter, GetDevices()) 64 ON_CALL(*adapter, GetDevices())
61 .WillByDefault(Return(adapter->GetMockDevices())); 65 .WillByDefault(
66 Invoke(adapter.get(), &MockBluetoothAdapter::GetMockDevices));
62 67
63 return adapter.Pass(); 68 return adapter.Pass();
64 } 69 }
65 70
66 // static 71 // static
67 scoped_refptr<NiceMock<MockBluetoothAdapter>> 72 scoped_refptr<NiceMock<MockBluetoothAdapter>>
68 LayoutTestBluetoothAdapterProvider::GetSingleEmptyDeviceAdapter() { 73 LayoutTestBluetoothAdapterProvider::GetSingleEmptyDeviceAdapter() {
69 scoped_refptr<NiceMock<MockBluetoothAdapter>> adapter( 74 scoped_refptr<NiceMock<MockBluetoothAdapter>> adapter(GetEmptyAdapter());
70 new NiceMock<MockBluetoothAdapter>());
71
72 ON_CALL(*adapter, StartDiscoverySession(_, _))
73 .WillByDefault(Invoke(
74 &LayoutTestBluetoothAdapterProvider::SuccessfulDiscoverySession));
75 75
76 adapter->AddMockDevice(GetEmptyDevice(adapter.get())); 76 adapter->AddMockDevice(GetEmptyDevice(adapter.get()));
77 77
78 ON_CALL(*adapter, GetDevices())
79 .WillByDefault(Return(adapter->GetMockDevices()));
80
81 return adapter.Pass(); 78 return adapter.Pass();
82 } 79 }
83 80
84 // static 81 // static
85 scoped_ptr<NiceMock<MockBluetoothDevice>> 82 scoped_ptr<NiceMock<MockBluetoothDevice>>
86 LayoutTestBluetoothAdapterProvider::GetEmptyDevice( 83 LayoutTestBluetoothAdapterProvider::GetEmptyDevice(
87 MockBluetoothAdapter* adapter) { 84 MockBluetoothAdapter* adapter) {
88 scoped_ptr<NiceMock<MockBluetoothDevice>> empty_device( 85 scoped_ptr<NiceMock<MockBluetoothDevice>> empty_device(
89 new NiceMock<MockBluetoothDevice>( 86 new NiceMock<MockBluetoothDevice>(
90 adapter, 0x1F00 /* Bluetooth Class */, "Empty Mock Device name", 87 adapter, 0x1F00 /* Bluetooth Class */, "Empty Mock Device name",
91 "Empty Mock Device instanceID", true /* Paired */, 88 "Empty Mock Device instanceID", true /* Paired */,
92 true /* Connected */)); 89 true /* Connected */));
93 90
94 ON_CALL(*empty_device, GetVendorIDSource()) 91 ON_CALL(*empty_device, GetVendorIDSource())
95 .WillByDefault(Return(BluetoothDevice::VENDOR_ID_BLUETOOTH)); 92 .WillByDefault(Return(BluetoothDevice::VENDOR_ID_BLUETOOTH));
96 ON_CALL(*empty_device, GetVendorID()).WillByDefault(Return(0xFFFF)); 93 ON_CALL(*empty_device, GetVendorID()).WillByDefault(Return(0xFFFF));
97 ON_CALL(*empty_device, GetProductID()).WillByDefault(Return(1)); 94 ON_CALL(*empty_device, GetProductID()).WillByDefault(Return(1));
98 ON_CALL(*empty_device, GetDeviceID()).WillByDefault(Return(2)); 95 ON_CALL(*empty_device, GetDeviceID()).WillByDefault(Return(2));
99 96
100 BluetoothDevice::UUIDList list; 97 BluetoothDevice::UUIDList list;
101 list.push_back(BluetoothUUID("1800")); 98 list.push_back(BluetoothUUID("1800"));
102 list.push_back(BluetoothUUID("1801")); 99 list.push_back(BluetoothUUID("1801"));
103 ON_CALL(*empty_device, GetUUIDs()).WillByDefault(Return(list)); 100 ON_CALL(*empty_device, GetUUIDs()).WillByDefault(Return(list));
104 return empty_device.Pass(); 101 return empty_device.Pass();
105 } 102 }
106 103
107 // static 104 // static
108 void LayoutTestBluetoothAdapterProvider::SuccessfulDiscoverySession( 105 scoped_ptr<NiceMock<MockBluetoothDiscoverySession>>
109 const BluetoothAdapter::DiscoverySessionCallback& callback, 106 LayoutTestBluetoothAdapterProvider::GetDiscoverySession() {
110 const BluetoothAdapter::ErrorCallback& error_callback) {
111 scoped_ptr<NiceMock<MockBluetoothDiscoverySession>> discovery_session( 107 scoped_ptr<NiceMock<MockBluetoothDiscoverySession>> discovery_session(
112 new NiceMock<MockBluetoothDiscoverySession>()); 108 new NiceMock<MockBluetoothDiscoverySession>());
113 109
114 ON_CALL(*discovery_session, Stop(_, _)) 110 ON_CALL(*discovery_session, Stop(_, _))
115 .WillByDefault(Invoke( 111 .WillByDefault(RunCallback<0 /* success_callback */>());
116 &LayoutTestBluetoothAdapterProvider::SuccessfulDiscoverySessionStop));
117 112
118 callback.Run(discovery_session.Pass()); 113 return discovery_session.Pass();
119 }
120
121 // static
122 void LayoutTestBluetoothAdapterProvider::SuccessfulDiscoverySessionStop(
123 const base::Closure& callback,
124 const base::Closure& error_callback) {
125 callback.Run();
126 } 114 }
127 115
128 } // namespace content 116 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698