Upstream version 11.40.271.0
[platform/framework/web/crosswalk.git] / src / content / child / bluetooth / web_bluetooth_impl.cc
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
3 // found in the LICENSE file.
4
5 #include "content/child/bluetooth/web_bluetooth_impl.h"
6
7 namespace content {
8
9 WebBluetoothImpl::WebBluetoothImpl()
10     : m_bluetoothMockDataSet(MockData::NOT_MOCKING),
11       m_bluetoothRequestDeviceRejectType(
12           blink::WebBluetoothError::NotFoundError) {
13 }
14
15 void WebBluetoothImpl::requestDevice(
16     blink::WebBluetoothRequestDeviceCallbacks* callbacks) {
17   // Mock implementation of blink::WebBluetooth until a more complete
18   // implementation is built out.
19   switch (m_bluetoothMockDataSet) {
20     case MockData::NOT_MOCKING: {
21       blink::WebBluetoothError* error = new blink::WebBluetoothError(
22           blink::WebBluetoothError::NotFoundError, "");
23       callbacks->onError(error);
24       break;
25     }
26     case MockData::REJECT: {
27       blink::WebBluetoothError* error =
28           new blink::WebBluetoothError(m_bluetoothRequestDeviceRejectType, "");
29       callbacks->onError(error);
30       break;
31     }
32     case MockData::RESOLVE: {
33       callbacks->onSuccess();
34       break;
35     }
36   }
37 }
38
39 void WebBluetoothImpl::SetBluetoothMockDataSetForTesting(
40     const std::string& name) {
41   if (name == "RejectRequestDevice_NotFoundError") {
42     m_bluetoothMockDataSet = MockData::REJECT;
43     m_bluetoothRequestDeviceRejectType =
44         blink::WebBluetoothError::NotFoundError;
45   } else if (name == "RejectRequestDevice_SecurityError") {
46     m_bluetoothMockDataSet = MockData::REJECT;
47     m_bluetoothRequestDeviceRejectType =
48         blink::WebBluetoothError::SecurityError;
49   } else if (name == "ResolveRequestDevice_Empty") {
50     m_bluetoothMockDataSet = MockData::RESOLVE;
51   } else {
52     m_bluetoothMockDataSet = MockData::NOT_MOCKING;
53   }
54 }
55
56 }  // namespace content