Best JavaScript code snippet using wpt
webxr-test.js
Source:webxr-test.js  
...118      this.client_.onDeviceChanged();119    }120    this.runtimes_ = [];121  }122  _removeRuntime(device) {123    const index = this.runtimes_.indexOf(device);124    if (index >= 0) {125      this.runtimes_.splice(index, 1);126      if (this.client_) {127        this.client_.onDeviceChanged();128      }129    }130  }131  // VRService overrides132  setClient(client) {133    if (this.client_) {134      throw new Error("setClient should only be called once");135    }136    this.client_ = client;137  }138  requestSession(sessionOptions) {139    const requests = [];140    // Request a session from all the runtimes.141    for (let i = 0; i < this.runtimes_.length; i++) {142      requests[i] = this.runtimes_[i]._requestRuntimeSession(sessionOptions);143    }144    return Promise.all(requests).then((results) => {145      // Find and return the first successful result.146      for (let i = 0; i < results.length; i++) {147        if (results[i].session) {148          // Construct a dummy metrics recorder149          const metricsRecorderPtr = new vrMojom.XRSessionMetricsRecorderRemote();150          metricsRecorderPtr.$.bindNewPipeAndPassReceiver().handle.close();151          const success = {152            session: results[i].session,153            metricsRecorder: metricsRecorderPtr,154          };155          return {result: {success}};156        }157      }158      // If there were no successful results, returns a null session.159      return {160        result: {failureReason: vrMojom.RequestSessionError.NO_RUNTIME_FOUND}161      };162    });163  }164  supportsSession(sessionOptions) {165    const requests = [];166    // Check supports on all the runtimes.167    for (let i = 0; i < this.runtimes_.length; i++) {168      requests[i] = this.runtimes_[i]._runtimeSupportsSession(sessionOptions);169    }170    return Promise.all(requests).then((results) => {171      // Find and return the first successful result.172      for (let i = 0; i < results.length; i++) {173        if (results[i].supportsSession) {174          return results[i];175        }176      }177      // If there were no successful results, returns false.178      return {supportsSession: false};179    });180  }181  exitPresent() {182    return Promise.resolve();183  }184  setFramesThrottled(throttled) {185    this.setFramesThrottledImpl(throttled);186  }187  // We cannot override the mojom interceptors via the prototype; so this method188  // and the above indirection exist to allow overrides by internal code.189  setFramesThrottledImpl(throttled) {}190  // Only handles asynchronous calls to makeXrCompatible. Synchronous calls are191  // not supported in Javascript.192  makeXrCompatible() {193    if (this.runtimes_.length == 0) {194      return {195        xrCompatibleResult: vrMojom.XrCompatibleResult.kNoDeviceAvailable196      };197    }198    return {xrCompatibleResult: vrMojom.XrCompatibleResult.kAlreadyCompatible};199  }200}201class FakeXRAnchorController {202  constructor() {203    // Private properties.204    this.device_ = null;205    this.id_ = null;206    this.dirty_ = true;207    // Properties backing up public attributes / methods.208    this.deleted_ = false;209    this.paused_ = false;210    this.anchorOrigin_ = XRMathHelper.identity();211  }212  // WebXR Test API (Anchors Extension)213  get deleted() {214    return this.deleted_;215  }216  pauseTracking() {217    if(!this.paused_) {218      this.paused_ = true;219      this.dirty_ = true;220    }221  }222  resumeTracking() {223    if(this.paused_) {224      this.paused_ = false;225      this.dirty_ = true;226    }227  }228  stopTracking() {229    if(!this.deleted_) {230      this.device_._deleteAnchorController(this.id_);231      this.deleted_ = true;232      this.dirty_ = true;233    }234  }235  setAnchorOrigin(anchorOrigin) {236    this.anchorOrigin_ = getMatrixFromTransform(anchorOrigin);237    this.dirty_ = true;238  }239  // Internal implementation:240  set id(value) {241    this.id_ = value;242  }243  set device(value) {244    this.device_ = value;245  }246  get dirty() {247    return this.dirty_;248  }249  get paused() {250    return this.paused_;251  }252  _markProcessed() {253    this.dirty_ = false;254  }255  _getAnchorOrigin() {256    return this.anchorOrigin_;257  }258}259// Implements XRFrameDataProvider and XRPresentationProvider. Maintains a mock260// for XRPresentationProvider. Implements FakeXRDevice test API.261class MockRuntime {262  // Mapping from string feature names to the corresponding mojo types.263  // This is exposed as a member for extensibility.264  static _featureToMojoMap = {265    'viewer': vrMojom.XRSessionFeature.REF_SPACE_VIEWER,266    'local': vrMojom.XRSessionFeature.REF_SPACE_LOCAL,267    'local-floor': vrMojom.XRSessionFeature.REF_SPACE_LOCAL_FLOOR,268    'bounded-floor': vrMojom.XRSessionFeature.REF_SPACE_BOUNDED_FLOOR,269    'unbounded': vrMojom.XRSessionFeature.REF_SPACE_UNBOUNDED,270    'hit-test': vrMojom.XRSessionFeature.HIT_TEST,271    'dom-overlay': vrMojom.XRSessionFeature.DOM_OVERLAY,272    'light-estimation': vrMojom.XRSessionFeature.LIGHT_ESTIMATION,273    'anchors': vrMojom.XRSessionFeature.ANCHORS,274    'depth-sensing': vrMojom.XRSessionFeature.DEPTH,275    'secondary-views': vrMojom.XRSessionFeature.SECONDARY_VIEWS,276  };277  static _sessionModeToMojoMap = {278    "inline": vrMojom.XRSessionMode.kInline,279    "immersive-vr": vrMojom.XRSessionMode.kImmersiveVr,280    "immersive-ar": vrMojom.XRSessionMode.kImmersiveAr,281  };282  static _environmentBlendModeToMojoMap = {283    "opaque": vrMojom.XREnvironmentBlendMode.kOpaque,284    "alpha-blend": vrMojom.XREnvironmentBlendMode.kAlphaBlend,285    "additive": vrMojom.XREnvironmentBlendMode.kAdditive,286  };287  static _interactionModeToMojoMap = {288    "screen-space": vrMojom.XRInteractionMode.kScreenSpace,289    "world-space": vrMojom.XRInteractionMode.kWorldSpace,290  };291  constructor(fakeDeviceInit, service) {292    this.sessionClient_ = null;293    this.presentation_provider_ = new MockXRPresentationProvider();294    this.pose_ = null;295    this.next_frame_id_ = 0;296    this.bounds_ = null;297    this.send_mojo_space_reset_ = false;298    this.stageParameters_ = null;299    this.stageParametersId_ = 1;300    this.service_ = service;301    this.framesOfReference = {};302    this.input_sources_ = new Map();303    this.next_input_source_index_ = 1;304    // Currently active hit test subscriptons.305    this.hitTestSubscriptions_ = new Map();306    // Currently active transient hit test subscriptions.307    this.transientHitTestSubscriptions_ = new Map();308    // ID of the next subscription to be assigned.309    this.next_hit_test_id_ = 1n;310    this.anchor_controllers_ = new Map();311    // ID of the next anchor to be assigned.312    this.next_anchor_id_ = 1n;313    // Anchor creation callback (initially null, can be set by tests).314    this.anchor_creation_callback_ = null;315    this.depthSensingData_ = null;316    this.depthSensingDataDirty_ = false;317    let supportedModes = [];318    if (fakeDeviceInit.supportedModes) {319      supportedModes = fakeDeviceInit.supportedModes.slice();320      if (fakeDeviceInit.supportedModes.length === 0) {321        supportedModes = ["inline"];322      }323    } else {324      // Back-compat mode.325      console.warn("Please use `supportedModes` to signal which modes are supported by this device.");326      if (fakeDeviceInit.supportsImmersive == null) {327        throw new TypeError("'supportsImmersive' must be set");328      }329      supportedModes = ["inline"];330      if (fakeDeviceInit.supportsImmersive) {331        supportedModes.push("immersive-vr");332      }333    }334    this.supportedModes_ = this._convertModesToEnum(supportedModes);335    // Initialize DisplayInfo first to set the defaults, then override with336    // anything from the deviceInit337    if (this.supportedModes_.includes(vrMojom.XRSessionMode.kImmersiveVr) ||338        this.supportedModes_.includes(vrMojom.XRSessionMode.kImmersiveAr)) {339      this.displayInfo_ = this._getImmersiveDisplayInfo();340    } else if (this.supportedModes_.includes(vrMojom.XRSessionMode.kInline)) {341      this.displayInfo_ = this._getNonImmersiveDisplayInfo();342    } else {343      // This should never happen!344      console.error("Device has empty supported modes array!");345      throw new InvalidStateError();346    }347    if (fakeDeviceInit.viewerOrigin != null) {348      this.setViewerOrigin(fakeDeviceInit.viewerOrigin);349    }350    if (fakeDeviceInit.floorOrigin != null) {351      this.setFloorOrigin(fakeDeviceInit.floorOrigin);352    }353    if (fakeDeviceInit.world) {354      this.setWorld(fakeDeviceInit.world);355    }356    if (fakeDeviceInit.depthSensingData) {357      this.setDepthSensingData(fakeDeviceInit.depthSensingData);358    }359    this.defaultFramebufferScale_ = default_framebuffer_scale;360    this.enviromentBlendMode_ = this._convertBlendModeToEnum(fakeDeviceInit.environmentBlendMode);361    this.interactionMode_ = this._convertInteractionModeToEnum(fakeDeviceInit.interactionMode);362    // This appropriately handles if the coordinates are null363    this.setBoundsGeometry(fakeDeviceInit.boundsCoordinates);364    this.setViews(fakeDeviceInit.views, fakeDeviceInit.secondaryViews);365    // Need to support webVR which doesn't have a notion of features366    this._setFeatures(fakeDeviceInit.supportedFeatures || []);367  }368  // WebXR Test API369  setViews(primaryViews, secondaryViews) {370    this.primaryViews_ = [];371    this.secondaryViews_ = [];372    let xOffset = 0;373    if (primaryViews) {374      this.primaryViews_ = [];375      xOffset = this._setViews(primaryViews, xOffset, this.primaryViews_);376    }377    if (secondaryViews) {378      this.secondaryViews_ = [];379      this._setViews(secondaryViews, xOffset, this.secondaryViews_);380    }381    // Do not include secondary views here because they are only exposed to382    // WebXR if requested by the session. getFrameData() will send back the383    // secondary views when enabled.384    this.displayInfo_.views = this.primaryViews_;385    if (this.sessionClient_) {386      this.sessionClient_.onChanged(this.displayInfo_);387    }388  }389  disconnect() {390    this.service_._removeRuntime(this);391    this.presentation_provider_._close();392    if (this.sessionClient_) {393      this.sessionClient_.$.close();394      this.sessionClient_ = null;395    }396    return Promise.resolve();397  }398  setViewerOrigin(origin, emulatedPosition = false) {399    const p = origin.position;400    const q = origin.orientation;401    this.pose_ = {402      orientation: { x: q[0], y: q[1], z: q[2], w: q[3] },403      position: { x: p[0], y: p[1], z: p[2] },404      emulatedPosition: emulatedPosition,...Using AI Code Generation
1var wpt = require('webpagetest');2var wpt = new WebPageTest('www.webpagetest.org');3  if (err) return console.log(err);4  wpt._removeRuntime(data.data.testId, function(err, data) {5    if (err) return console.log(err);6    console.log(data);7  });8});Using AI Code Generation
1var wpt = require('wpt');2var wpt = new WebPageTest('www.webpagetest.org');3  if (err) {4    console.log(err);5  } else {6    wpt._removeRuntime(data);7    console.log(data);8  }9});10var wpt = require('wpt');11var wpt = new WebPageTest('www.webpagetest.org');12  if (err) {13    console.log(err);14  } else {15    console.log(data);16  }17});18var wpt = require('wpt');19var wpt = new WebPageTest('www.webpagetest.org');20wpt.getLocations(function(err, data) {21  if (err) {22    console.log(err);23  } else {24    console.log(data);25  }26});27var wpt = require('wpt');28var wpt = new WebPageTest('www.webpagetest.org');29wpt.getTesters(function(err, data) {30  if (err) {31    console.log(err);32  } else {33    console.log(data);34  }35});36var wpt = require('wpt');37var wpt = new WebPageTest('www.webpagetest.org');38wpt.getTestStatus('140308_9Q_1', function(err, data) {39  if (err) {40    console.log(err);41  } else {42    console.log(data);43  }44});Using AI Code Generation
1var wptoolkit = require('wptoolkit');2var wp = new wptoolkit();3wp._removeRuntime(function(err, data){4	if(err){5		console.log(err);6	}else{7		console.log(data);8	}9});10### wp._removeRuntime()11var wptoolkit = require('wptoolkit');12var wp = new wptoolkit();13wp._removeRuntime(function(err, data){14	if(err){15		console.log(err);16	}else{17		console.log(data);18	}19});20### wp._removeRuntime()21var wptoolkit = require('wptoolkit');22var wp = new wptoolkit();23wp._removeRuntime(function(err, data){24	if(err){25		console.log(err);26	}else{27		console.log(data);28	}29});30### wp._createRuntime()31var wptoolkit = require('wptoolkit');32var wp = new wptoolkit();33wp._createRuntime(function(err, data){34	if(err){35		console.log(err);36	}else{37		console.log(data);38	}39});40### wp._installPlugin()41var wptoolkit = require('wptoolkit');42var wp = new wptoolkit();Using AI Code Generation
1var wpt = require('webpagetest');2var wpt = new WebPageTest('www.webpagetest.org');3  if (err) return console.error(err);4  wpt.getTestResults(data.data.testId, function(err, data) {5    if (err) return console.error(err);6    console.log(data);7  });8});Using AI Code Generation
1var wptoolkit = require('wptoolkit');2wptoolkit._removeRuntime('test.js');3var wptoolkit = require('wptoolkit');4wptoolkit._removeRuntimeSync('test.js');5var wptoolkit = require('wptoolkit');6wptoolkit._addRuntime('test.js');7var wptoolkit = require('wptoolkit');8wptoolkit._addRuntimeSync('test.js');Using AI Code Generation
1var wpt = require('webpagetest');2var options = {3};4var wpt = new wpt(options);5    if (err) return console.log(err);6    console.log(data);7    wpt._removeRuntime(data.data.testId, function(err, data) {8        if (err) return console.log(err);9        console.log(data);10    });11});Using AI Code Generation
1var wpt = require('wpt');2var wpt = new WebPageTest('www.webpagetest.org', 'A.0a5e2e2b5b5c8a1d0b9e2b7c2d2a8e7c');3wpt.getTestStatus( '150612_6E_7f3f3a0c9b3b1d3c3a5b5c5f1e0f2a2d', function( err, data ) {4  if ( err ) {5    console.log( 'Error: ' + err );6  } else {7    console.log( data );8  }9});10## getLocations(callback)11- `callback` **Function** Function to call when the request is complete (optional, default `null`)12var wpt = require('wpt');13var wpt = new WebPageTest('www.webpagetest.org', 'A.0a5e2e2b5b5c8a1d0b9e2b7c2d2a8e7c');14wpt.getLocations(function(err, data) {15  if (err) {16    console.log('Error: ' + err);17  } else {18    console.log(data);19  }20});21## getLocations(callback)22- `callback` **Function** Function to call when the request is complete (optional, default `null`)23var wpt = require('wpt');24var wpt = new WebPageTest('www.webpagetest.org', 'A.0a5e2e2b5b5c8a1d0b9e2b7c2d2a8e7c');25wpt.getLocations(function(err, data) {26  if (err) {27    console.log('Error: ' + err);28  } else {29    console.log(data);30  }31});32## getLocationInfo(location, callback)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.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!
