OLD | NEW |
---|---|
(Empty) | |
1 // Copyright (c) 2012 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 // Array of each device list update. | |
6 var devices = []; | |
7 | |
8 function handleOnDeviceList(deviceList) { | |
9 var newDevices = []; | |
10 for (var i = 0; i < deviceList.length; ++i) { | |
11 newDevices.push(deviceList[i]); | |
12 } | |
13 devices.push(newDevices); | |
14 } | |
15 chrome.dial.onDeviceList.addListener(handleOnDeviceList); | |
16 | |
17 chrome.test.sendMessage('ready', function(message) { | |
18 if (message == 'events') { | |
Matt Perry
2012/12/07 23:52:52
You can split these up into multiple files and use
justinlin
2012/12/11 00:11:29
Done. One of the tests couldn't use this because i
| |
19 chrome.test.runTests([ | |
20 function testEvents() { | |
21 // Make sure there were 3 devices. | |
22 chrome.test.assertEq(3, devices.length); | |
23 | |
24 // Make sure each update contained 1 more device than the previous. | |
25 for (var i = 0; i < devices.length; ++i) { | |
26 chrome.test.assertEq(i + 1, devices[i].length); | |
27 } | |
28 | |
29 // Just check the first device in the first update and the last device | |
30 // in the last update. | |
31 // Not exposing the device id right now. | |
32 chrome.test.assertTrue(!('deviceId' in devices[0][0])); | |
33 chrome.test.assertEq("1", devices[0][0].deviceLabel); | |
34 chrome.test.assertEq("http://1", devices[0][0].deviceDescriptionUrl); | |
35 | |
36 chrome.test.assertTrue(!('deviceId' in devices[2][2])); | |
37 chrome.test.assertEq("3", devices[2][2].deviceLabel); | |
38 chrome.test.assertEq("http://3", devices[2][2].deviceDescriptionUrl); | |
39 | |
40 chrome.test.succeed(); | |
41 } | |
42 ]); | |
43 } else if (message == 'discovery') { | |
44 chrome.test.runTests([ | |
45 function testFunctional() { | |
46 // Remove all listeners first. | |
47 chrome.dial.onDeviceList.removeListener(handleOnDeviceList); | |
48 | |
49 var discoverNowShouldSucceed = function(result) { | |
50 if (result) | |
51 chrome.test.succeed(); | |
52 else | |
53 chrome.test.fail(); | |
54 }; | |
55 | |
56 var onDeviceList = function(deviceList) { | |
57 // Unused. | |
58 }; | |
59 | |
60 var discoverNowShouldFail = function(result) { | |
61 if (!result) { | |
62 chrome.test.succeed(); | |
63 chrome.dial.onDeviceList.addListener(onDeviceList); | |
64 chrome.dial.discoverNow(discoverNowShouldSucceed); | |
65 } else { | |
66 chrome.test.fail(); | |
67 } | |
68 }; | |
69 chrome.dial.discoverNow(discoverNowShouldFail); | |
70 } | |
71 ]); | |
72 } else { | |
73 chrome.test.fail(); | |
74 } | |
75 }); | |
OLD | NEW |