Index: chrome/test/data/extensions/api_test/dial/experimental/runtest.js |
diff --git a/chrome/test/data/extensions/api_test/dial/experimental/runtest.js b/chrome/test/data/extensions/api_test/dial/experimental/runtest.js |
new file mode 100644 |
index 0000000000000000000000000000000000000000..8a53588848ebca5ddc9803d4a4bc312c9e0be2e9 |
--- /dev/null |
+++ b/chrome/test/data/extensions/api_test/dial/experimental/runtest.js |
@@ -0,0 +1,75 @@ |
+// Copyright (c) 2012 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. |
+ |
+// Array of each device list update. |
+var devices = []; |
+ |
+function handleOnDeviceList(deviceList) { |
+ var newDevices = []; |
+ for (var i = 0; i < deviceList.length; ++i) { |
+ newDevices.push(deviceList[i]); |
+ } |
+ devices.push(newDevices); |
+} |
+chrome.dial.onDeviceList.addListener(handleOnDeviceList); |
+ |
+chrome.test.sendMessage('ready', function(message) { |
+ 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
|
+ chrome.test.runTests([ |
+ function testEvents() { |
+ // Make sure there were 3 devices. |
+ chrome.test.assertEq(3, devices.length); |
+ |
+ // Make sure each update contained 1 more device than the previous. |
+ for (var i = 0; i < devices.length; ++i) { |
+ chrome.test.assertEq(i + 1, devices[i].length); |
+ } |
+ |
+ // Just check the first device in the first update and the last device |
+ // in the last update. |
+ // Not exposing the device id right now. |
+ chrome.test.assertTrue(!('deviceId' in devices[0][0])); |
+ chrome.test.assertEq("1", devices[0][0].deviceLabel); |
+ chrome.test.assertEq("http://1", devices[0][0].deviceDescriptionUrl); |
+ |
+ chrome.test.assertTrue(!('deviceId' in devices[2][2])); |
+ chrome.test.assertEq("3", devices[2][2].deviceLabel); |
+ chrome.test.assertEq("http://3", devices[2][2].deviceDescriptionUrl); |
+ |
+ chrome.test.succeed(); |
+ } |
+ ]); |
+ } else if (message == 'discovery') { |
+ chrome.test.runTests([ |
+ function testFunctional() { |
+ // Remove all listeners first. |
+ chrome.dial.onDeviceList.removeListener(handleOnDeviceList); |
+ |
+ var discoverNowShouldSucceed = function(result) { |
+ if (result) |
+ chrome.test.succeed(); |
+ else |
+ chrome.test.fail(); |
+ }; |
+ |
+ var onDeviceList = function(deviceList) { |
+ // Unused. |
+ }; |
+ |
+ var discoverNowShouldFail = function(result) { |
+ if (!result) { |
+ chrome.test.succeed(); |
+ chrome.dial.onDeviceList.addListener(onDeviceList); |
+ chrome.dial.discoverNow(discoverNowShouldSucceed); |
+ } else { |
+ chrome.test.fail(); |
+ } |
+ }; |
+ chrome.dial.discoverNow(discoverNowShouldFail); |
+ } |
+ ]); |
+ } else { |
+ chrome.test.fail(); |
+ } |
+}); |