summaryrefslogtreecommitdiffstats
path: root/device/bluetooth/test/bluetooth_test_android.h
blob: 8fbf61ccd6298a66e2539ce3dd97a17b4fcd56d3 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
// Copyright 2015 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#ifndef DEVICE_BLUETOOTH_TEST_BLUETOOTH_TEST_ANDROID_H_
#define DEVICE_BLUETOOTH_TEST_BLUETOOTH_TEST_ANDROID_H_

#include <stdint.h>

#include "base/android/scoped_java_ref.h"
#include "device/bluetooth/test/bluetooth_test.h"

namespace device {

class BluetoothAdapterAndroid;

// Android implementation of BluetoothTestBase.
class BluetoothTestAndroid : public BluetoothTestBase {
 public:
  BluetoothTestAndroid();
  ~BluetoothTestAndroid() override;

  // Test overrides:
  void SetUp() override;
  void TearDown() override;

  // BluetoothTestBase overrides:
  bool PlatformSupportsLowEnergy() override;
  void InitWithDefaultAdapter() override;
  void InitWithoutDefaultAdapter() override;
  void InitWithFakeAdapter() override;
  bool DenyPermission() override;
  BluetoothDevice* DiscoverLowEnergyDevice(int device_ordinal) override;
  void SimulateGattConnection(BluetoothDevice* device) override;
  void SimulateGattConnectionError(BluetoothDevice* device,
                                   BluetoothDevice::ConnectErrorCode) override;
  void SimulateGattDisconnection(BluetoothDevice* device) override;
  void SimulateGattServicesDiscovered(
      BluetoothDevice* device,
      const std::vector<std::string>& uuids) override;
  void SimulateGattServicesDiscoveryError(BluetoothDevice* device) override;
  void SimulateGattCharacteristic(BluetoothGattService* service,
                                  const std::string& uuid,
                                  int properties) override;
  void RememberCharacteristicForSubsequentAction(
      BluetoothGattCharacteristic* characteristic) override;
  void SimulateGattNotifySessionStarted(
      BluetoothGattCharacteristic* characteristic) override;
  void SimulateGattCharacteristicSetNotifyWillFailSynchronouslyOnce(
      BluetoothGattCharacteristic* characteristic) override;
  void SimulateGattCharacteristicChanged(
      BluetoothGattCharacteristic* characteristic,
      const std::vector<uint8_t>& value) override;

  void SimulateGattCharacteristicRead(
      BluetoothGattCharacteristic* characteristic,
      const std::vector<uint8_t>& value) override;
  void SimulateGattCharacteristicReadError(
      BluetoothGattCharacteristic* characteristic,
      BluetoothGattService::GattErrorCode) override;
  void SimulateGattCharacteristicReadWillFailSynchronouslyOnce(
      BluetoothGattCharacteristic* characteristic) override;

  void SimulateGattCharacteristicWrite(
      BluetoothGattCharacteristic* characteristic) override;
  void SimulateGattCharacteristicWriteError(
      BluetoothGattCharacteristic* characteristic,
      BluetoothGattService::GattErrorCode) override;
  void SimulateGattCharacteristicWriteWillFailSynchronouslyOnce(
      BluetoothGattCharacteristic* characteristic) override;

  void SimulateGattDescriptor(BluetoothGattCharacteristic* characteristic,
                              const std::string& uuid) override;
  void RememberDescriptorForSubsequentAction(
      BluetoothGattDescriptor* descriptor) override;

  void SimulateGattDescriptorRead(BluetoothGattDescriptor* descriptor,
                                  const std::vector<uint8_t>& value) override;
  void SimulateGattDescriptorReadError(
      BluetoothGattDescriptor* descriptor,
      BluetoothGattService::GattErrorCode) override;
  void SimulateGattDescriptorReadWillFailSynchronouslyOnce(
      BluetoothGattDescriptor* descriptor) override;

  void SimulateGattDescriptorWrite(
      BluetoothGattDescriptor* descriptor) override;
  void SimulateGattDescriptorWriteError(
      BluetoothGattDescriptor* descriptor,
      BluetoothGattService::GattErrorCode) override;
  void SimulateGattDescriptorWriteWillFailSynchronouslyOnce(
      BluetoothGattDescriptor* descriptor) override;

  // Instruct the fake adapter to throw an IllegalStateException for
  // startScan and stopScan.
  void ForceIllegalStateException();

  // Records that Java FakeBluetoothDevice connectGatt was called.
  void OnFakeBluetoothDeviceConnectGattCalled(
      JNIEnv* env,
      const base::android::JavaParamRef<jobject>& caller);

  // Records that Java FakeBluetoothGatt disconnect was called.
  void OnFakeBluetoothGattDisconnect(
      JNIEnv* env,
      const base::android::JavaParamRef<jobject>& caller);

  // Records that Java FakeBluetoothGatt close was called.
  void OnFakeBluetoothGattClose(
      JNIEnv* env,
      const base::android::JavaParamRef<jobject>& caller);

  // Records that Java FakeBluetoothGatt discoverServices was called.
  void OnFakeBluetoothGattDiscoverServices(
      JNIEnv* env,
      const base::android::JavaParamRef<jobject>& caller);

  // Records that Java FakeBluetoothGatt setCharacteristicNotification was
  // called.
  void OnFakeBluetoothGattSetCharacteristicNotification(
      JNIEnv* env,
      const base::android::JavaParamRef<jobject>& caller);

  // Records that Java FakeBluetoothGatt readCharacteristic was called.
  void OnFakeBluetoothGattReadCharacteristic(
      JNIEnv* env,
      const base::android::JavaParamRef<jobject>& caller);

  // Records that Java FakeBluetoothGatt writeCharacteristic was called.
  void OnFakeBluetoothGattWriteCharacteristic(
      JNIEnv* env,
      const base::android::JavaParamRef<jobject>& caller,
      const base::android::JavaParamRef<jbyteArray>& value);

  // Records that Java FakeBluetoothGatt readDescriptor was called.
  void OnFakeBluetoothGattReadDescriptor(
      JNIEnv* env,
      const base::android::JavaParamRef<jobject>& caller);

  // Records that Java FakeBluetoothGatt writeDescriptor was called.
  void OnFakeBluetoothGattWriteDescriptor(
      JNIEnv* env,
      const base::android::JavaParamRef<jobject>& caller,
      const base::android::JavaParamRef<jbyteArray>& value);

  // Records that Java FakeBluetoothAdapter onAdapterStateChanged was called.
  void OnFakeAdapterStateChanged(
      JNIEnv* env,
      const base::android::JavaParamRef<jobject>& caller,
      const bool powered);

  base::android::ScopedJavaGlobalRef<jobject> j_fake_bluetooth_adapter_;

  int gatt_open_connections_ = 0;
};

// Defines common test fixture name. Use TEST_F(BluetoothTest, YourTestName).
typedef BluetoothTestAndroid BluetoothTest;

}  // namespace device

#endif  // DEVICE_BLUETOOTH_TEST_BLUETOOTH_TEST_ANDROID_H_