Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added test cases related to Bluetoothcontrol #19

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
147 changes: 146 additions & 1 deletion src/commonMethods/commonFunctions.js
100755 → 100644
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import constants from './constants'
import moment from 'moment'
import _http from 'http'
import { Client } from 'ssh2'

import URL from 'url'

/**
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
}
Expand Down Expand Up @@ -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)
Expand All @@ -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)))
})
Expand All @@ -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)
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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<AxiosResponse<any>>}
*/
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<AxiosResponse<any>>}
*/
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<AxiosResponse<any>>}
*/
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<AxiosResponse<any>>}
*/
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<AxiosResponse<any>>}
*/
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<AxiosResponse<any>>}
*/
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<AxiosResponse<any>>}
*/
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<AxiosResponse<any>>}
*/
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<AxiosResponse<any>>}
*/
export const getBluetoothDeviceInfo = function(devicemac) {
return this.$thunder.api.BluetoothControl.adapter(devicemac)
.then(result => result)
.catch(err => err)
}
5 changes: 4 additions & 1 deletion src/commonMethods/constants.js
100755 → 100644
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand All @@ -18,6 +19,8 @@ export default {
provisioningPlugin: 'Provisioning',
WPEProcess: 'WPEProcess',
remoteControlPlugin: 'RemoteControl',
youtubeImplementation: 'CobaltImplementation',
invalidAddress: 'invalidstring',

//Plugin states
activate: 'activate',
Expand Down
62 changes: 62 additions & 0 deletions src/tests/bluetoothcontrol/BluetoothControl_Adapter_001.test.js
Original file line number Diff line number Diff line change
@@ -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
}
},
},
],
}
41 changes: 41 additions & 0 deletions src/tests/bluetoothcontrol/BluetoothControl_Adapter_002.test.js
Original file line number Diff line number Diff line change
@@ -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
}
},
},
],
}
41 changes: 41 additions & 0 deletions src/tests/bluetoothcontrol/BluetoothControl_Adapters_001.test.js
Original file line number Diff line number Diff line change
@@ -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
}
},
},
],
}
Loading