diff options
author | Matt A. Tobin <mattatobin@localhost.localdomain> | 2018-02-02 04:16:08 -0500 |
---|---|---|
committer | Matt A. Tobin <mattatobin@localhost.localdomain> | 2018-02-02 04:16:08 -0500 |
commit | 5f8de423f190bbb79a62f804151bc24824fa32d8 (patch) | |
tree | 10027f336435511475e392454359edea8e25895d /dom/presentation/tests/mochitest/PresentationDeviceInfoChromeScript.js | |
parent | 49ee0794b5d912db1f95dce6eb52d781dc210db5 (diff) | |
download | UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.tar UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.tar.gz UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.tar.lz UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.tar.xz UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.zip |
Add m-esr52 at 52.6.0
Diffstat (limited to 'dom/presentation/tests/mochitest/PresentationDeviceInfoChromeScript.js')
-rw-r--r-- | dom/presentation/tests/mochitest/PresentationDeviceInfoChromeScript.js | 150 |
1 files changed, 150 insertions, 0 deletions
diff --git a/dom/presentation/tests/mochitest/PresentationDeviceInfoChromeScript.js b/dom/presentation/tests/mochitest/PresentationDeviceInfoChromeScript.js new file mode 100644 index 000000000..2bc069f6b --- /dev/null +++ b/dom/presentation/tests/mochitest/PresentationDeviceInfoChromeScript.js @@ -0,0 +1,150 @@ +/* -*- indent-tabs-mode: nil; js-indent-level: 2 -*- */ +/* Any copyright is dedicated to the Public Domain. + http://creativecommons.org/publicdomain/zero/1.0/ */ +'use strict'; + +const { classes: Cc, interfaces: Ci, utils: Cu } = Components; + +Cu.import('resource://gre/modules/PresentationDeviceInfoManager.jsm'); + +const { XPCOMUtils } = Cu.import('resource://gre/modules/XPCOMUtils.jsm'); + +const manager = Cc['@mozilla.org/presentation-device/manager;1'] + .getService(Ci.nsIPresentationDeviceManager); + +var testProvider = { + QueryInterface: XPCOMUtils.generateQI([Ci.nsIPresentationDeviceProvider]), + forceDiscovery: function() { + sendAsyncMessage('force-discovery'); + }, + listener: null, +}; + +var testDevice = { + QueryInterface: XPCOMUtils.generateQI([Ci.nsIPresentationDevice]), + establishControlChannel: function() { + return null; + }, + disconnect: function() {}, + isRequestedUrlSupported: function(requestedUrl) { + return true; + }, + id: null, + name: null, + type: null, + listener: null, +}; + +var testDevice1 = { + QueryInterface: XPCOMUtils.generateQI([Ci.nsIPresentationDevice]), + id: 'dummyid', + name: 'dummyName', + type: 'dummyType', + establishControlChannel: function(url, presentationId) { + return null; + }, + disconnect: function() {}, + isRequestedUrlSupported: function(requestedUrl) { + return true; + }, +}; + +var testDevice2 = { + QueryInterface: XPCOMUtils.generateQI([Ci.nsIPresentationDevice]), + id: 'dummyid', + name: 'dummyName', + type: 'dummyType', + establishControlChannel: function(url, presentationId) { + return null; + }, + disconnect: function() {}, + isRequestedUrlSupported: function(requestedUrl) { + return true; + }, +}; + +var mockedDeviceWithoutSupportedURL = { + QueryInterface: XPCOMUtils.generateQI([Ci.nsIPresentationDevice]), + id: 'dummyid', + name: 'dummyName', + type: 'dummyType', + establishControlChannel: function(url, presentationId) { + return null; + }, + disconnect: function() {}, + isRequestedUrlSupported: function(requestedUrl) { + return false; + }, +}; + +var mockedDeviceSupportHttpsURL = { + QueryInterface: XPCOMUtils.generateQI([Ci.nsIPresentationDevice]), + id: 'dummyid', + name: 'dummyName', + type: 'dummyType', + establishControlChannel: function(url, presentationId) { + return null; + }, + disconnect: function() {}, + isRequestedUrlSupported: function(requestedUrl) { + if (requestedUrl.indexOf("https://") != -1) { + return true; + } + return false; + }, +}; + +addMessageListener('setup', function() { + manager.addDeviceProvider(testProvider); + + sendAsyncMessage('setup-complete'); +}); + +addMessageListener('trigger-device-add', function(device) { + testDevice.id = device.id; + testDevice.name = device.name; + testDevice.type = device.type; + manager.addDevice(testDevice); +}); + +addMessageListener('trigger-add-unsupport-url-device', function() { + manager.addDevice(mockedDeviceWithoutSupportedURL); +}); + +addMessageListener('trigger-add-multiple-devices', function() { + manager.addDevice(testDevice1); + manager.addDevice(testDevice2); +}); + +addMessageListener('trigger-add-https-devices', function() { + manager.addDevice(mockedDeviceSupportHttpsURL); +}); + + +addMessageListener('trigger-device-update', function(device) { + testDevice.id = device.id; + testDevice.name = device.name; + testDevice.type = device.type; + manager.updateDevice(testDevice); +}); + +addMessageListener('trigger-device-remove', function() { + manager.removeDevice(testDevice); +}); + +addMessageListener('trigger-remove-unsupported-device', function() { + manager.removeDevice(mockedDeviceWithoutSupportedURL); +}); + +addMessageListener('trigger-remove-multiple-devices', function() { + manager.removeDevice(testDevice1); + manager.removeDevice(testDevice2); +}); + +addMessageListener('trigger-remove-https-devices', function() { + manager.removeDevice(mockedDeviceSupportHttpsURL); +}); + +addMessageListener('teardown', function() { + manager.removeDeviceProvider(testProvider); +}); |