From 0c99e9e6a385be4aeabeedc4c72d0fef01fd4ffd Mon Sep 17 00:00:00 2001 From: sandeep-vedam Date: Tue, 3 Mar 2020 10:01:02 +0530 Subject: [PATCH] Added test cases related to Bluetoothcontrol --- src/commonMethods/commonFunctions.js | 147 +++++++++++++++++- src/commonMethods/constants.js | 5 +- .../BluetoothControl_Adapter_001.test.js | 62 ++++++++ .../BluetoothControl_Adapter_002.test.js | 41 +++++ .../BluetoothControl_Adapters_001.test.js | 41 +++++ .../BluetoothControl_Scan_001.test.js | 82 ++++++++++ .../BluetoothControl_Scan_002.test.js | 49 ++++++ 7 files changed, 425 insertions(+), 2 deletions(-) mode change 100755 => 100644 src/commonMethods/commonFunctions.js mode change 100755 => 100644 src/commonMethods/constants.js create mode 100644 src/tests/bluetoothcontrol/BluetoothControl_Adapter_001.test.js create mode 100644 src/tests/bluetoothcontrol/BluetoothControl_Adapter_002.test.js create mode 100644 src/tests/bluetoothcontrol/BluetoothControl_Adapters_001.test.js create mode 100644 src/tests/bluetoothcontrol/BluetoothControl_Scan_001.test.js create mode 100644 src/tests/bluetoothcontrol/BluetoothControl_Scan_002.test.js diff --git a/src/commonMethods/commonFunctions.js b/src/commonMethods/commonFunctions.js old mode 100755 new mode 100644 index 107f2e3..a0ff786 --- a/src/commonMethods/commonFunctions.js +++ b/src/commonMethods/commonFunctions.js @@ -2,6 +2,7 @@ import constants from './constants' import moment from 'moment' import _http from 'http' import { Client } from 'ssh2' + import URL from 'url' /** @@ -84,6 +85,39 @@ export const setWebKitUrl = function(URL) { .catch(err => err) } +/** + * This function resumes or suspends Youtube plugin + * @param action + */ +export const youtubeActions = function(action) { + return this.$thunder.api.Cobalt.state(action) + .then(() => { + return this.$thunder.api.call(constants.controllerPlugin, 'status').then( + result => + result.filter(p => { + return p.callsign === 'Cobalt' + })[0].state + ) + }) + .catch(err => err) +} + +/** + * This function gets the URL + * @param URL + * @returns URL + */ +export const getYoutubeUrl = function(URL) { + return this.$thunder.api.Cobalt.url(URL) + .then(() => + this.$thunder.api.Cobalt.url().then(url => { + this.$log('URL is', url) + return url + }) + ) + .catch(err => err) +} + /** * This function checks if the process is running by getting the process id and comparing it to the number. * - If the process id is a number, then false is returned @@ -142,10 +176,12 @@ export const exec = async function(opts) { conn.on('timeout', function(e) { throw new Error(`{opts.cmd}: Timeout while connecting to ${constants.host}`) }) + conn.on('error', function(err) { throw new Error(`${opts.cmd}: ${err}`) }) }) + let result = await execCmd return result } @@ -174,7 +210,6 @@ export const screenshot = async function() { let url = `http://${constants.host}:80/Service/Snapshot/Capture?${moment().valueOf()}` // create a new promise inside of the async function let bufferData = new Promise((resolve, reject) => { - //TODO : Replace _http by using this.$http helper _http .get(url, function(res) { if (res.headers['content-length'] === undefined) @@ -183,9 +218,11 @@ export const screenshot = async function() { ) var buffers = [] var imageSize = res.headers['content-length'] + res.on('data', function(chunk) { buffers.push(Buffer.from(chunk)) }) + res.on('end', function() { return resolve(Buffer.concat(buffers, parseInt(imageSize))) }) @@ -194,6 +231,7 @@ export const screenshot = async function() { return reject(e) }) }) + // wait for the promise to resolve let result = await bufferData this.$data.write('screenshotResult', result) @@ -246,6 +284,20 @@ export const webKitBrowserStartAndResume = function() { ]) } +/** + * This function performs below operations on Youtube Plugin + * - Deactivate + * - Activate + * - Resume + */ +export const youtubeStartAndResume = function() { + return this.$sequence([ + () => pluginDeactivate.call(this, constants.youTubePlugin), + () => pluginActivate.call(this, constants.youTubePlugin), + () => youtubeActions().call(this, constants.resume), + ]) +} + /** * This function is used to get Plugin Info * @param plugin @@ -443,3 +495,96 @@ export const stopWPEFramework = function() { stopProcess('WPEFramework') return true } + +/** + * This function is used to scan Info of Bluetooth Control Plugin + * @param type , timeout + * @returns {Promise>} + */ +export const scanDevices = function(type, timeout) { + return this.$thunder.api.BluetoothControl.scan(type, timeout) + .then(result => result) + .catch(err => err) +} +/** + * This function is used to get available Bluetooth devices + * @returns {Promise>} + */ +export const getBluetoothDevices = function() { + return this.$thunder.api.BluetoothControl.devices() + .then(result => result) + .catch(err => err) +} + +/** + * This function is used to pair with the available Bluetooth devices + * @param address + * @returns {Promise>} + */ +export const pairBTDevice = function(address) { + return this.$thunder.api.BluetoothControl.pair(address) + .then(result => result) + .catch(err => err) +} +/** + * This function is used to connect with the available Bluetooth devices + * @param address + * @returns {Promise>} + */ +export const connectBTDevice = function(address) { + return this.$thunder.api.BluetoothControl.connect(address) + .then(result => result) + .catch(err => err) +} +/** + * This function is used to disconnect with the available Bluetooth devices + * @param address + * @returns {Promise>} + */ +export const disconnectBTDevice = function(address) { + return this.$thunder.api.BluetoothControl.disconnect(address) + .then(result => result) + .catch(err => err) +} + +/** + * This function is used to disconnect with the available Bluetooth devices + * @param address + * @returns {Promise>} + */ +export const unpairBTDevice = function(address) { + return this.$thunder.api.BluetoothControl.unpair(address) + .then(result => result) + .catch(err => err) +} +/** + * This function is used to get available Bluetooth adapters + * @returns {Promise>} + */ +export const getBluetoothAdapters = function() { + return this.$thunder.api.BluetoothControl.adapters() + .then(result => result) + .catch(err => err) +} + +/** + * This function is used to get info of particular Bluetooth adapters + * @param adaptername + * @returns {Promise>} + */ +export const getBluetoothAdapterInfo = function(adaptername) { + return this.$thunder.api.BluetoothControl.adapter(adaptername) + .then(result => result) + .catch(err => err) +} + +/** + * This function is used to get info of particular Bluetooth device + * @param devicemac + * @returns {Promise>} + */ +export const getBluetoothDeviceInfo = function(devicemac) { + return this.$thunder.api.BluetoothControl.adapter(devicemac) + .then(result => result) + .catch(err => err) +} diff --git a/src/commonMethods/constants.js b/src/commonMethods/constants.js old mode 100755 new mode 100644 index 82a3657..39dd039 --- a/src/commonMethods/constants.js +++ b/src/commonMethods/constants.js @@ -5,9 +5,10 @@ export default { monitorPlugin: 'Monitor', controllerPlugin: 'Controller', webKitBrowserPlugin: 'WebKitBrowser', + bluetoothControlPlugin: 'BluetoothControl', webKitImplementation: 'WebKitImplementation', deviceInfo: 'DeviceInfo', - youTubePlugin: 'YouTube', + youTubePlugin: 'Cobalt', netFlixPlugin: 'Netflix', ocdmPlugin: 'OCDM', ocdmImplementation: 'OCDMImplementation', @@ -18,6 +19,8 @@ export default { provisioningPlugin: 'Provisioning', WPEProcess: 'WPEProcess', remoteControlPlugin: 'RemoteControl', + youtubeImplementation: 'CobaltImplementation', + invalidAddress: 'invalidstring', //Plugin states activate: 'activate', diff --git a/src/tests/bluetoothcontrol/BluetoothControl_Adapter_001.test.js b/src/tests/bluetoothcontrol/BluetoothControl_Adapter_001.test.js new file mode 100644 index 0000000..8d5438a --- /dev/null +++ b/src/tests/bluetoothcontrol/BluetoothControl_Adapter_001.test.js @@ -0,0 +1,62 @@ +import { + pluginDeactivate, + pluginActivate, + getBluetoothAdapters, + getBluetoothAdapterInfo, +} from '../../commonMethods/commonFunctions' + +import constants from '../../commonMethods/constants' + +let adapterList + +export default { + title: 'Bluetooth Control Adapter 001', + description: 'Check Bluetooth Control Adapter Info', + steps: [ + { + description: 'Check if Bluetooth Control Plugin is stopped correctly', + test: pluginDeactivate, + params: constants.bluetoothControlPlugin, + assert: 'deactivated', + }, + { + description: 'Check if Bluetooth Control Plugin is started correctly', + test: pluginActivate, + params: constants.bluetoothControlPlugin, + assert: 'activated', + }, + { + description: 'Get Bluetooth Adapter list', + sleep: 10, + test() { + return getBluetoothAdapters.call(this) + }, + validate(result) { + this.$data.write('adapterList', result) + adapterList = this.$data.read('adapterList') + this.$log('adapter list is ===========>', adapterList) + if (result === undefined || result === null) { + this.$log('Result does not have adapter list') + return false + } else { + return true + } + }, + }, + { + description: 'Get Bluetooth Adapter info', + sleep: 10, + test() { + return getBluetoothAdapterInfo.call(this, adapterList[0]) + }, + validate(result) { + if (result === undefined || result === null) { + this.$log('Adapter Info is not available') + return false + } else { + return true + } + }, + }, + ], +} diff --git a/src/tests/bluetoothcontrol/BluetoothControl_Adapter_002.test.js b/src/tests/bluetoothcontrol/BluetoothControl_Adapter_002.test.js new file mode 100644 index 0000000..457a962 --- /dev/null +++ b/src/tests/bluetoothcontrol/BluetoothControl_Adapter_002.test.js @@ -0,0 +1,41 @@ +import { + pluginDeactivate, + pluginActivate, + getBluetoothAdapterInfo, +} from '../../commonMethods/commonFunctions' + +import constants from '../../commonMethods/constants' + +export default { + title: 'Bluetooth Control Adapter 002', + description: 'Check Bluetooth Control Adapter Info with invalid adapter and validate the error', + steps: [ + { + description: 'Check if Bluetooth Control Plugin is stopped correctly', + test: pluginDeactivate, + params: constants.bluetoothControlPlugin, + assert: 'deactivated', + }, + { + description: 'Check if Bluetooth Control Plugin is started correctly', + test: pluginActivate, + params: constants.bluetoothControlPlugin, + assert: 'activated', + }, + { + description: 'Get Bluetooth Adapter info with invalid adapter and validate the error', + sleep: 10, + test() { + return getBluetoothAdapterInfo.call(this, constants.invalidAddress) + }, + validate(res) { + if (res.code === 22 && res.message === 'ERROR_UNKNOWN_KEY') { + return true + } else { + this.$log('Proper error message is not shown') + return false + } + }, + }, + ], +} diff --git a/src/tests/bluetoothcontrol/BluetoothControl_Adapters_001.test.js b/src/tests/bluetoothcontrol/BluetoothControl_Adapters_001.test.js new file mode 100644 index 0000000..2e80f68 --- /dev/null +++ b/src/tests/bluetoothcontrol/BluetoothControl_Adapters_001.test.js @@ -0,0 +1,41 @@ +import { + pluginDeactivate, + pluginActivate, + getBluetoothAdapters, +} from '../../commonMethods/commonFunctions' + +import constants from '../../commonMethods/constants' + +export default { + title: 'Bluetooth Control Adapters 001', + description: 'Check Bluetooth Control Adapter list', + steps: [ + { + description: 'Check if Bluetooth Control Plugin is stopped correctly', + test: pluginDeactivate, + params: constants.bluetoothControlPlugin, + assert: 'deactivated', + }, + { + description: 'Check if Bluetooth Control Plugin is started correctly', + test: pluginActivate, + params: constants.bluetoothControlPlugin, + assert: 'activated', + }, + { + description: 'Get Bluetooth Adapter list', + sleep: 10, + test() { + return getBluetoothAdapters.call(this) + }, + validate(result) { + if (result === undefined || result === null) { + this.$log('Result does not have adapter list') + return false + } else { + return true + } + }, + }, + ], +} diff --git a/src/tests/bluetoothcontrol/BluetoothControl_Scan_001.test.js b/src/tests/bluetoothcontrol/BluetoothControl_Scan_001.test.js new file mode 100644 index 0000000..47672f3 --- /dev/null +++ b/src/tests/bluetoothcontrol/BluetoothControl_Scan_001.test.js @@ -0,0 +1,82 @@ +import { + pluginDeactivate, + pluginActivate, + scanDevices, + getBluetoothDevices, +} from '../../commonMethods/commonFunctions' +import constants from '../../commonMethods/constants' + +let listener + +export default { + title: 'Bluetooth Control Scan 001', + description: 'Check the Scan Functionality of Bluetooth Control Module', + setup() { + listener = this.$thunder.api.BluetoothControl.on('scancomplete', () => { + this.$data.write('scancompleted', 'scancompleted') //TODO Need to update this line + }) + }, + steps: [ + { + description: 'Check if Bluetooth Control Plugin is stopped correctly', + test: pluginDeactivate, + params: constants.bluetoothControlPlugin, + assert: 'deactivated', + }, + { + description: 'Check if Bluetooth Control Plugin is started correctly', + test: pluginActivate, + params: constants.bluetoothControlPlugin, + assert: 'activated', + }, + { + description: 'Invoke Scan', + sleep: 5, + test() { + return scanDevices.call(this, 'LowEnergy', 10) + }, + validate(res) { + if (res == null) { + return true + } else { + this.$log('Scan does not start') + return false + } + }, + }, + { + description: 'Check whether scanning is success', + sleep: 5, + test() { + return new Promise((resolve, reject) => { + let attempts = 0 + const interval = setInterval(() => { + attempts++ + if (this.$data.read('scancompleted') === 'scancompleted') { + clearInterval(interval) + resolve() + } else if (attempts > 1000) { + clearInterval(interval) + reject('Scanning not completed') + } + }, 1000) + }) + }, + }, + { + description: 'Get scan results', + sleep: 10, + test() { + return getBluetoothDevices.call(this) + }, + validate(result) { + if (result === undefined || result.length === 0) { + this.$log('Result does not have device list') + return false + } else { + return true + } + }, + }, + ], +} diff --git a/src/tests/bluetoothcontrol/BluetoothControl_Scan_002.test.js b/src/tests/bluetoothcontrol/BluetoothControl_Scan_002.test.js new file mode 100644 index 0000000..558db33 --- /dev/null +++ b/src/tests/bluetoothcontrol/BluetoothControl_Scan_002.test.js @@ -0,0 +1,49 @@ +import { pluginDeactivate, pluginActivate, scanDevices } from '../../commonMethods/commonFunctions' +import constants from '../../commonMethods/constants' + +export default { + title: 'Bluetooth Control Scan 002', + description: 'Check error message when scanning is performed while previous scan is in progress', + steps: [ + { + description: 'Check if Bluetooth Control Plugin is stopped correctly', + test: pluginDeactivate, + params: constants.bluetoothControlPlugin, + assert: 'deactivated', + }, + { + description: 'Check if Bluetooth Control Plugin is started correctly', + test: pluginActivate, + params: constants.bluetoothControlPlugin, + assert: 'activated', + }, + { + description: 'Invoke Scan', + test() { + return scanDevices.call(this, 'LowEnergy', 10) + }, + validate(res) { + if (res == null) { + return true + } else { + this.$log('Scan does not start') + return false + } + }, + }, + { + description: 'Invoke Scan', + test() { + return scanDevices.call(this, 'LowEnergy', 10) + }, + validate(res) { + if (res.code == 12 && res.message == 'ERROR_INPROGRESS') { + return true + } else { + this.$log('Proper error message is not shown') + return false + } + }, + }, + ], +}