Upstream version 7.36.149.0
[platform/framework/web/crosswalk.git] / src / chrome / test / data / extensions / api_test / bluetooth_private / adapter_state / test.js
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 var newAdapterName = 'Dome';
6
7 function testSetAdapterState() {
8   chrome.bluetooth.getAdapterState(function(state) {
9     chrome.test.assertNoLastError();
10     chrome.test.assertFalse(state.powered);
11     chrome.test.assertTrue(state.name != newAdapterName);
12     // TODO(tengs): Check if adapter is discoverable when the attribute is
13     // exposed to the chrome.bluetooth API.
14     setAdapterState();
15   });
16 }
17
18 function setAdapterState() {
19   var newState = {
20     name: newAdapterName,
21     powered: true,
22     discoverable: true
23   };
24
25   chrome.bluetoothPrivate.setAdapterState(newState, function() {
26     chrome.test.assertNoLastError();
27     if (chrome.runtime.lastError)
28       chrome.test.fail(chrome.runtime.lastError);
29     checkFinalAdapterState();
30   });
31 }
32
33 var adapterStateSet = false;
34 function checkFinalAdapterState() {
35   chrome.bluetooth.getAdapterState(function(state) {
36     chrome.test.assertNoLastError();
37     chrome.test.assertTrue(state.powered);
38     chrome.test.assertTrue(state.name == newAdapterName);
39     // TODO(tengs): Check if adapter is discoverable when the attribute is
40     // exposed to the chrome.bluetooth API.
41     if (!adapterStateSet) {
42       adapterStateSet = true;
43       // Check indempotence of bluetoothPrivate.setAdapterState.
44       setAdapterState();
45     } else {
46       chrome.test.succeed();
47     }
48   });
49 }
50
51 chrome.test.runTests([ testSetAdapterState ]);