How to use fakeDeviceInitToDeviceInfo method in wpt

Best JavaScript code snippet using wpt

webusb-test.js

Source:webusb-test.js Github

copy

Full Screen

...12 chooser: null,13 chooserInterceptor: null,14 chooserCrossFrameProxy: null,15};16function fakeDeviceInitToDeviceInfo(guid, init) {17 let deviceInfo = {18 guid: guid + "",19 usbVersionMajor: init.usbVersionMajor,20 usbVersionMinor: init.usbVersionMinor,21 usbVersionSubminor: init.usbVersionSubminor,22 classCode: init.deviceClass,23 subclassCode: init.deviceSubclass,24 protocolCode: init.deviceProtocol,25 vendorId: init.vendorId,26 productId: init.productId,27 deviceVersionMajor: init.deviceVersionMajor,28 deviceVersionMinor: init.deviceVersionMinor,29 deviceVersionSubminor: init.deviceVersionSubminor,30 manufacturerName: init.manufacturerName,31 productName: init.productName,32 serialNumber: init.serialNumber,33 activeConfiguration: init.activeConfigurationValue,34 configurations: []35 };36 init.configurations.forEach(config => {37 var configInfo = {38 configurationValue: config.configurationValue,39 configurationName: config.configurationName,40 interfaces: []41 };42 config.interfaces.forEach(iface => {43 var interfaceInfo = {44 interfaceNumber: iface.interfaceNumber,45 alternates: []46 };47 iface.alternates.forEach(alternate => {48 var alternateInfo = {49 alternateSetting: alternate.alternateSetting,50 classCode: alternate.interfaceClass,51 subclassCode: alternate.interfaceSubclass,52 protocolCode: alternate.interfaceProtocol,53 interfaceName: alternate.interfaceName,54 endpoints: []55 };56 alternate.endpoints.forEach(endpoint => {57 var endpointInfo = {58 endpointNumber: endpoint.endpointNumber,59 packetSize: endpoint.packetSize,60 };61 switch (endpoint.direction) {62 case "in":63 endpointInfo.direction = device.mojom.UsbTransferDirection.INBOUND;64 break;65 case "out":66 endpointInfo.direction = device.mojom.UsbTransferDirection.OUTBOUND;67 break;68 }69 switch (endpoint.type) {70 case "bulk":71 endpointInfo.type = device.mojom.UsbTransferType.BULK;72 break;73 case "interrupt":74 endpointInfo.type = device.mojom.UsbTransferType.INTERRUPT;75 break;76 case "isochronous":77 endpointInfo.type = device.mojom.UsbTransferType.ISOCHRONOUS;78 break;79 }80 alternateInfo.endpoints.push(endpointInfo);81 });82 interfaceInfo.alternates.push(alternateInfo);83 });84 configInfo.interfaces.push(interfaceInfo);85 });86 deviceInfo.configurations.push(configInfo);87 });88 return deviceInfo;89}90function convertMojoDeviceFilters(input) {91 let output = [];92 input.forEach(filter => {93 output.push(convertMojoDeviceFilter(filter));94 });95 return output;96}97function convertMojoDeviceFilter(input) {98 let output = {};99 if (input.hasVendorId)100 output.vendorId = input.vendorId;101 if (input.hasProductId)102 output.productId = input.productId;103 if (input.hasClassCode)104 output.classCode = input.classCode;105 if (input.hasSubclassCode)106 output.subclassCode = input.subclassCode;107 if (input.hasProtocolCode)108 output.protocolCode = input.protocolCode;109 if (input.serialNumber)110 output.serialNumber = input.serialNumber;111 return output;112}113class FakeDevice {114 constructor(deviceInit) {115 this.info_ = deviceInit;116 this.opened_ = false;117 this.currentConfiguration_ = null;118 this.claimedInterfaces_ = new Map();119 }120 getConfiguration() {121 if (this.currentConfiguration_) {122 return Promise.resolve({123 value: this.currentConfiguration_.configurationValue });124 } else {125 return Promise.resolve({ value: 0 });126 }127 }128 open() {129 assert_false(this.opened_);130 this.opened_ = true;131 return Promise.resolve({ error: device.mojom.UsbOpenDeviceError.OK });132 }133 close() {134 assert_true(this.opened_);135 this.opened_ = false;136 return Promise.resolve();137 }138 setConfiguration(value) {139 assert_true(this.opened_);140 let selectedConfiguration = this.info_.configurations.find(141 configuration => configuration.configurationValue == value);142 // Blink should never request an invalid configuration.143 assert_not_equals(selectedConfiguration, undefined);144 this.currentConfiguration_ = selectedConfiguration;145 return Promise.resolve({ success: true });146 }147 claimInterface(interfaceNumber) {148 assert_true(this.opened_);149 assert_false(this.currentConfiguration_ == null, 'device configured');150 assert_false(this.claimedInterfaces_.has(interfaceNumber),151 'interface already claimed');152 // Blink should never request an invalid interface.153 assert_true(this.currentConfiguration_.interfaces.some(154 iface => iface.interfaceNumber == interfaceNumber));155 this.claimedInterfaces_.set(interfaceNumber, 0);156 return Promise.resolve({ success: true });157 }158 releaseInterface(interfaceNumber) {159 assert_true(this.opened_);160 assert_false(this.currentConfiguration_ == null, 'device configured');161 assert_true(this.claimedInterfaces_.has(interfaceNumber));162 this.claimedInterfaces_.delete(interfaceNumber);163 return Promise.resolve({ success: true });164 }165 setInterfaceAlternateSetting(interfaceNumber, alternateSetting) {166 assert_true(this.opened_);167 assert_false(this.currentConfiguration_ == null, 'device configured');168 assert_true(this.claimedInterfaces_.has(interfaceNumber));169 let iface = this.currentConfiguration_.interfaces.find(170 iface => iface.interfaceNumber == interfaceNumber);171 // Blink should never request an invalid interface or alternate.172 assert_false(iface == undefined);173 assert_true(iface.alternates.some(174 x => x.alternateSetting == alternateSetting));175 this.claimedInterfaces_.set(interfaceNumber, alternateSetting);176 return Promise.resolve({ success: true });177 }178 reset() {179 assert_true(this.opened_);180 return Promise.resolve({ success: true });181 }182 clearHalt(endpoint) {183 assert_true(this.opened_);184 assert_false(this.currentConfiguration_ == null, 'device configured');185 // TODO(reillyg): Assert that endpoint is valid.186 return Promise.resolve({ success: true });187 }188 controlTransferIn(params, length, timeout) {189 assert_true(this.opened_);190 assert_false(this.currentConfiguration_ == null, 'device configured');191 return Promise.resolve({192 status: device.mojom.UsbTransferStatus.OK,193 data: [length >> 8, length & 0xff, params.request, params.value >> 8,194 params.value & 0xff, params.index >> 8, params.index & 0xff]195 });196 }197 controlTransferOut(params, data, timeout) {198 assert_true(this.opened_);199 assert_false(this.currentConfiguration_ == null, 'device configured');200 return Promise.resolve({201 status: device.mojom.UsbTransferStatus.OK,202 bytesWritten: data.byteLength203 });204 }205 genericTransferIn(endpointNumber, length, timeout) {206 assert_true(this.opened_);207 assert_false(this.currentConfiguration_ == null, 'device configured');208 // TODO(reillyg): Assert that endpoint is valid.209 let data = new Array(length);210 for (let i = 0; i < length; ++i)211 data[i] = i & 0xff;212 return Promise.resolve({213 status: device.mojom.UsbTransferStatus.OK,214 data: data215 });216 }217 genericTransferOut(endpointNumber, data, timeout) {218 assert_true(this.opened_);219 assert_false(this.currentConfiguration_ == null, 'device configured');220 // TODO(reillyg): Assert that endpoint is valid.221 return Promise.resolve({222 status: device.mojom.UsbTransferStatus.OK,223 bytesWritten: data.byteLength224 });225 }226 isochronousTransferIn(endpointNumber, packetLengths, timeout) {227 assert_true(this.opened_);228 assert_false(this.currentConfiguration_ == null, 'device configured');229 // TODO(reillyg): Assert that endpoint is valid.230 let data = new Array(packetLengths.reduce((a, b) => a + b, 0));231 let dataOffset = 0;232 let packets = new Array(packetLengths.length);233 for (let i = 0; i < packetLengths.length; ++i) {234 for (let j = 0; j < packetLengths[i]; ++j)235 data[dataOffset++] = j & 0xff;236 packets[i] = {237 length: packetLengths[i],238 transferredLength: packetLengths[i],239 status: device.mojom.UsbTransferStatus.OK240 };241 }242 return Promise.resolve({ data: data, packets: packets });243 }244 isochronousTransferOut(endpointNumber, data, packetLengths, timeout) {245 assert_true(this.opened_);246 assert_false(this.currentConfiguration_ == null, 'device configured');247 // TODO(reillyg): Assert that endpoint is valid.248 let packets = new Array(packetLengths.length);249 for (let i = 0; i < packetLengths.length; ++i) {250 packets[i] = {251 length: packetLengths[i],252 transferredLength: packetLengths[i],253 status: device.mojom.UsbTransferStatus.OK254 };255 }256 return Promise.resolve({ packets: packets });257 }258}259class FakeDeviceManager {260 constructor() {261 this.bindingSet_ = new mojo.BindingSet(device.mojom.UsbDeviceManager);262 this.devices_ = new Map();263 this.devicesByGuid_ = new Map();264 this.client_ = null;265 this.nextGuid_ = 0;266 }267 addBinding(handle) {268 this.bindingSet_.addBinding(this, handle);269 }270 addDevice(fakeDevice, info) {271 let device = {272 fakeDevice: fakeDevice,273 guid: (this.nextGuid_++).toString(),274 info: info,275 bindingArray: []276 };277 this.devices_.set(fakeDevice, device);278 this.devicesByGuid_.set(device.guid, device);279 if (this.client_)280 this.client_.onDeviceAdded(fakeDeviceInitToDeviceInfo(device.guid, info));281 }282 removeDevice(fakeDevice) {283 let device = this.devices_.get(fakeDevice);284 if (!device)285 throw new Error('Cannot remove unknown device.');286 for (var binding of device.bindingArray)287 binding.close();288 this.devices_.delete(device.fakeDevice);289 this.devicesByGuid_.delete(device.guid);290 if (this.client_) {291 this.client_.onDeviceRemoved(292 fakeDeviceInitToDeviceInfo(device.guid, device.info));293 }294 }295 removeAllDevices() {296 this.devices_.forEach(device => {297 for (var binding of device.bindingArray)298 binding.close();299 this.client_.onDeviceRemoved(300 fakeDeviceInitToDeviceInfo(device.guid, device.info));301 });302 this.devices_.clear();303 this.devicesByGuid_.clear();304 }305 getDevices(options) {306 let devices = [];307 this.devices_.forEach(device => {308 devices.push(fakeDeviceInitToDeviceInfo(device.guid, device.info));309 });310 return Promise.resolve({ results: devices });311 }312 getDevice(guid, request) {313 let device = this.devicesByGuid_.get(guid);314 if (device) {315 let binding = new mojo.Binding(316 window.device.mojom.UsbDevice, new FakeDevice(device.info), request);317 binding.setConnectionErrorHandler(() => {318 if (device.fakeDevice.onclose)319 device.fakeDevice.onclose();320 });321 device.bindingArray.push(binding);322 } else {323 request.close();324 }325 }326 setClient(client) {327 this.client_ = client;328 }329}330class FakeChooserService {331 constructor() {332 this.bindingSet_ = new mojo.BindingSet(device.mojom.UsbChooserService);333 this.chosenDevice_ = null;334 this.lastFilters_ = null;335 }336 addBinding(handle) {337 this.bindingSet_.addBinding(this, handle);338 }339 setChosenDevice(fakeDevice) {340 this.chosenDevice_ = fakeDevice;341 }342 getPermission(deviceFilters) {343 this.lastFilters_ = convertMojoDeviceFilters(deviceFilters);344 let device = internal.deviceManager.devices_.get(this.chosenDevice_);345 if (device) {346 return Promise.resolve({347 result: fakeDeviceInitToDeviceInfo(device.guid, device.info)348 });349 } else {350 return Promise.resolve({ result: null });351 }352 }353}354// Unlike FakeDevice this class is exported to callers of USBTest.addFakeDevice.355class FakeUSBDevice {356 constructor() {357 this.onclose = null;358 }359 disconnect() {360 setTimeout(() => internal.deviceManager.removeDevice(this), 0);361 }...

Full Screen

Full Screen

Using AI Code Generation

copy

Full Screen

1var wptb = require('wptb');2var fakeDeviceInitToDeviceInfo = wptb.fakeDeviceInitToDeviceInfo;3var fakeDeviceInit = {4};5var deviceInfo = fakeDeviceInitToDeviceInfo(fakeDeviceInit);6console.log(deviceInfo);

Full Screen

Using AI Code Generation

copy

Full Screen

1var device = new wpt.device.realDeviceInitToDeviceInfo();2var ui = device.getUi();3var main = ui.getMain();4var app = main.getApplication();5var test = app.getTest();6var testView = test.getTestView();7var testController = test.getTestController();8var testModel = test.getTestModel(

Full Screen

Using AI Code Generation

copy

Full Screen

1var wptbho = WScript.CreateObject("wptbho.WptBho");2var deviceInfo = wptbho.fakeDeviceInitToDeviceInfo("FakeDeviceInit");3WScript.Echo(deviceInfo);4STDMETHODIMP CWptBho::fakeDeviceInitToDeviceInfo(BSTR fakeDeviceInit, BSTR* deviceInfo) {5 if (!fakeDeviceInit || !deviceInfo) {6 return E_INVALIDARG;7 }8 CComBSTR deviceInfoStr;9 deviceInfoStr.Append(L"{\"deviceInfo\": {\"browserVersion\": \"");10 deviceInfoStr.Append(L"

Full Screen

Using AI Code Generation

copy

Full Screen

1var wptDriver = require('./wptDriver.js');2var deviceInfo = wptDriver.fakeDeviceInitToDeviceInfo('iPhone 6', 'iOS', '9.3', 'portrait');3var wptDriver = require('./wptDriver.js');4var deviceInfo = wptDriver.fakeDeviceInitToDeviceInfo('iPhone 6', 'iOS', '9.3', 'landscape');5var wptDriver = require('./wptDriver.js');6var deviceInfo = wptDriver.fakeDeviceInitToDeviceInfo('iPhone 6', 'iOS', '9.3');

Full Screen

Using AI Code Generation

copy

Full Screen

1var wptDriver = require( 'wptdriver' );2 var wptDriver = require( 'wptdriver' );3var wptDriver = require( 'wptdriver' );4var wptDriver = require( 'wptdriver' );5var wptDriver = require( 'wptdriver' );6var wptDriver = require( 'wptdriver' );7var wptDriver = require( 'wptdriver' );8var wptDriver = require( 'wptdriver' );9var wptDriver = require( 'wptdriver' );

Full Screen

Using AI Code Generation

copy

Full Screen

1var driver = require('wptdriver');2var deviceInfo = driver.fakeDeviceInitToDeviceInfo("Nexus 5");3console.log(deviceInfo);4{ deviceName: 'Nexus 5',5 chromeDriverPort: 9515 }6var driver = require('wptdriver');7var deviceInfo = driver.fakeDeviceInitToDeviceInfo("Nexus 5");8console.log(deviceInfo);9{ deviceName: 'Nexus 5',

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run wpt automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful