- add sources.
[platform/framework/web/crosswalk.git] / src / chrome / test / data / extensions / api_test / usb_manual / list_interfaces / test.js
1 // Copyright (c) 2013 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 usb = chrome.usb;
6
7 var DEVICE_ID = {
8   // Google Nexus S
9   'vendorId': 6353,
10   'productId': 20194
11 };
12
13 var tests = [
14   function listInterfaces() {
15     chrome.permissions.request({
16         permissions: [{'usbDevices': [DEVICE_ID]}]
17     }, function(granted) {
18       if (!granted) {
19         chrome.test.fail('Could not get optional permisson');
20       } else {
21         usb.findDevices(DEVICE_ID, function(devices) {
22           if (typeof devices === 'undefined') {
23             chrome.test.fail('Device optional_permissions seem to be missing');
24           } else {
25             for (var i = 0; i < devices.length; i++) {
26               var device = devices[i];
27               console.log('device: ' + JSON.stringify(device));
28               usb.listInterfaces(device, function(result) {
29                 if (typeof result !== 'object') {
30                   chrome.test.fail('should be object type. was: '
31                       + typeof result);
32                 } else {
33                   console.log(JSON.stringify(result));
34                   chrome.test.succeed();
35                 }
36               });
37             }
38           }
39         });
40       }
41     });
42   },
43 ];
44
45 chrome.test.runTests(tests);