Best JavaScript code snippet using wpt
webxr_util.js
Source:webxr_util.js
1// These tests rely on the User Agent providing an implementation of the2// WebXR Testing API (https://github.com/immersive-web/webxr-test-api).3//4// In Chromium-based browsers, this implementation is provided by a JavaScript5// shim in order to reduce the amount of test-only code shipped to users. To6// enable these tests the browser must be run with these options:7//8// --enable-blink-features=MojoJS,MojoJSTest9function xr_promise_test(name, func, properties) {10 promise_test(async (t) => {11 // Perform any required test setup:12 if (window.XRTest === undefined) {13 // Chrome setup14 await loadChromiumResources;15 }16 // Ensure that any devices are disconnected when done. If this were done in17 // a .then() for the success case, a test that expected failure would18 // already be marked done at the time that runs and the shutdown would19 // interfere with the next test.20 t.add_cleanup(async () => {21 // Ensure system state is cleaned up.22 await navigator.xr.test.disconnectAllDevices();23 });24 return func(t);25 }, name, properties);26}27// A test function which runs through the common steps of requesting a session.28// Calls the passed in test function with the session, the controller for the29// device, and the test object.30// Requires a webglCanvas on the page.31function xr_session_promise_test(32 name, func, fakeDeviceInit, sessionMode, sessionInit, properties, glcontextPropertiesParam, gllayerPropertiesParam) {33 let testDeviceController;34 let testSession;35 let sessionObjects = {};36 const glcontextProperties = (glcontextPropertiesParam) ? glcontextPropertiesParam : {};37 const gllayerProperties = (gllayerPropertiesParam) ? gllayerPropertiesParam : {};38 const webglCanvas = document.getElementsByTagName('canvas')[0];39 // We can't use assert_true here because it causes the wpt testharness to treat40 // this as a test page and not as a test.41 if (!webglCanvas) {42 promise_test(async (t) => {43 Promise.reject('xr_session_promise_test requires a canvas on the page!');44 }, name, properties);45 }46 let gl = webglCanvas.getContext('webgl', {alpha: false, antialias: false, ...glcontextProperties});47 sessionObjects.gl = gl;48 xr_promise_test(49 name,50 (t) => {51 // Ensure that any pending sessions are ended when done. This needs to52 // use a cleanup function to ensure proper sequencing. If this were53 // done in a .then() for the success case, a test that expected54 // failure would already be marked done at the time that runs, and the55 // shutdown would interfere with the next test which may have started.56 t.add_cleanup(async () => {57 // If a session was created, end it.58 if (testSession) {59 await testSession.end().catch(() => {});60 }61 });62 return navigator.xr.test.simulateDeviceConnection(fakeDeviceInit)63 .then((controller) => {64 testDeviceController = controller;65 return gl.makeXRCompatible();66 })67 .then(() => new Promise((resolve, reject) => {68 // Perform the session request in a user gesture.69 navigator.xr.test.simulateUserActivation(() => {70 navigator.xr.requestSession(sessionMode, sessionInit || {})71 .then((session) => {72 testSession = session;73 session.mode = sessionMode;74 let glLayer = new XRWebGLLayer(session, gl, gllayerProperties);75 glLayer.context = gl;76 // Session must have a baseLayer or frame requests77 // will be ignored.78 session.updateRenderState({79 baseLayer: glLayer80 });81 sessionObjects.glLayer = glLayer;82 resolve(func(session, testDeviceController, t, sessionObjects));83 })84 .catch((err) => {85 reject(86 'Session with params ' +87 JSON.stringify(sessionMode) +88 ' was rejected on device ' +89 JSON.stringify(fakeDeviceInit) +90 ' with error: ' + err);91 });92 });93 }));94 },95 properties);96}97// This function wraps the provided function in a98// simulateUserActivation() call, and resolves the promise with the99// result of func(), or an error if one is thrown100function promise_simulate_user_activation(func) {101 return new Promise((resolve, reject) => {102 navigator.xr.test.simulateUserActivation(() => {103 try { let a = func(); resolve(a); } catch(e) { reject(e); }104 });105 });106}107// This functions calls a callback with each API object as specified108// by https://immersive-web.github.io/webxr/spec/latest/, allowing109// checks to be made on all ojects.110// Arguements:111// callback: A callback function with two arguements, the first112// being the API object, the second being the name of113// that API object.114function forEachWebxrObject(callback) {115 callback(window.navigator.xr, 'navigator.xr');116 callback(window.XRSession, 'XRSession');117 callback(window.XRSessionCreationOptions, 'XRSessionCreationOptions');118 callback(window.XRFrameRequestCallback, 'XRFrameRequestCallback');119 callback(window.XRPresentationContext, 'XRPresentationContext');120 callback(window.XRFrame, 'XRFrame');121 callback(window.XRView, 'XRView');122 callback(window.XRViewport, 'XRViewport');123 callback(window.XRViewerPose, 'XRViewerPose');124 callback(window.XRWebGLLayer, 'XRWebGLLayer');125 callback(window.XRWebGLLayerInit, 'XRWebGLLayerInit');126 callback(window.XRCoordinateSystem, 'XRCoordinateSystem');127 callback(window.XRFrameOfReference, 'XRFrameOfReference');128 callback(window.XRStageBounds, 'XRStageBounds');129 callback(window.XRSessionEvent, 'XRSessionEvent');130 callback(window.XRCoordinateSystemEvent, 'XRCoordinateSystemEvent');131}132// Code for loading test API in Chromium.133let loadChromiumResources = Promise.resolve().then(() => {134 if (!('MojoInterfaceInterceptor' in self)) {135 // Do nothing on non-Chromium-based browsers or when the Mojo bindings are136 // not present in the global namespace.137 return;138 }139 let chromiumResources = [140 '/gen/layout_test_data/mojo/public/js/mojo_bindings.js',141 '/gen/mojo/public/mojom/base/time.mojom.js',142 '/gen/gpu/ipc/common/mailbox_holder.mojom.js',143 '/gen/gpu/ipc/common/sync_token.mojom.js',144 '/gen/ui/display/mojom/display.mojom.js',145 '/gen/ui/gfx/geometry/mojom/geometry.mojom.js',146 '/gen/ui/gfx/mojom/gpu_fence_handle.mojom.js',147 '/gen/ui/gfx/mojom/transform.mojom.js',148 '/gen/device/vr/public/mojom/vr_service.mojom.js',149 '/resources/chromium/webxr-test-math-helper.js',150 '/resources/chromium/webxr-test.js',151 '/resources/testdriver.js',152 '/resources/testdriver-vendor.js',153 ];154 // This infrastructure is also used by Chromium-specific internal tests that155 // may need additional resources (e.g. internal API extensions), this allows156 // those tests to rely on this infrastructure while ensuring that no tests157 // make it into public WPTs that rely on APIs outside of the webxr test API.158 if (typeof(additionalChromiumResources) !== 'undefined') {159 chromiumResources = chromiumResources.concat(additionalChromiumResources);160 }161 let chain = Promise.resolve();162 chromiumResources.forEach(path => {163 let script = document.createElement('script');164 script.src = path;165 script.async = false;166 chain = chain.then(() => new Promise(resolve => {167 script.onload = () => resolve();168 }));169 document.head.appendChild(script);170 });171 return chain;...
Using AI Code Generation
1var wpt = require('webpagetest');2var wpt = new WebPageTest('www.webpagetest.org');3wpt.gllayerProperties('www.webpagetest.org', function(err, data) {4 if (err) return console.error(err);5 console.log(data);6});7var wpt = require('webpagetest');8var wpt = new WebPageTest('www.webpagetest.org');9wpt.getLocations(function(err, data) {10 if (err) return console.error(err);11 console.log(data);12});13var wpt = require('webpagetest');14var wpt = new WebPageTest('www.webpagetest.org');15wpt.getLocations(function(err, data) {16 if (err) return console.error(err);17 console.log(data);18});19var wpt = require('webpagetest');20var wpt = new WebPageTest('www.webpagetest.org');21wpt.getTesters(function(err, data) {22 if (err) return console.error(err);23 console.log(data);24});25var wpt = require('webpagetest');26var wpt = new WebPageTest('www.webpagetest.org');27wpt.getTesters(function(err, data) {28 if (err) return console.error(err);29 console.log(data);30});31var wpt = require('webpagetest');32var wpt = new WebPageTest('www.webpagetest.org');33wpt.getTesters(function(err, data) {34 if (err) return console.error(err);35 console.log(data);36});37var wpt = require('webpagetest');38var wpt = new WebPageTest('www.webpagetest.org');39wpt.getTesters(function(err, data) {40 if (err) return console.error(err);41 console.log(data);42});
Using AI Code Generation
1var wptoolkit = require('wptoolkit');2var map = new wptoolkit.Map('map', {3});4});5map.addLayer(glLayer);6glLayer.on('load', function () {7 var props = glLayer.glLayerProperties();8 console.log(props);9});10 #viewDiv {11 padding: 0;12 margin: 0;13 height: 100%;14 width: 100%;15 }
Using AI Code Generation
1var wptiles = require('wptiles.js');2var gllayerProperties = wptiles.gllayerProperties;3var layer = {4 "paint": {5 }6};7var props = gllayerProperties(layer);8console.log(props);
Using AI Code Generation
1var wptoolkit = require('wptoolkit');2var layer = wptoolkit.gllayerProperties('test');3console.log(layer);4var layer = wptoolkit.gllayerProperties('test');5console.log(layer);6var wptoolkit = require('wptoolkit');7var layer = wptoolkit.gllayerProperties('test');8console.log(layer);9var layer = wptoolkit.gllayerProperties('test');10console.log(layer);11var wptoolkit = require('wptoolkit');12var layer = wptoolkit.gllayerProperties('test');13console.log(layer);14var layer = wptoolkit.gllayerProperties('test');15console.log(layer);16var wptoolkit = require('wptoolkit');17var layer = wptoolkit.gllayerProperties('test');18console.log(layer);19var layer = wptoolkit.gllayerProperties('test');20console.log(layer);21var wptoolkit = require('wptoolkit');22var layer = wptoolkit.gllayerProperties('test');23console.log(layer);24var layer = wptoolkit.gllayerProperties('test');25console.log(layer);
Using AI Code Generation
1var WPTools = require('wptools');2var options = {3};4var wpt = new WPTools(options);5wpt.gllayerProperties(function(err, data) {6 if (err) {7 console.log(err);8 } else {9 console.log(data);10 }11});12{13 {14 "geometry": {15 },16 "properties": {17 "description": "The Eiffel Tower (French: la Tour Eiffel, French pronunciation: [tuʁ‿ɛfɛl] (listen)) is an iron lattice tower located on the Champ de Mars in Paris, France. It is named after the engineer Gustave Eiffel, whose company designed and built the tower.",18 "coordinates": {19 }20 }21 }22}23var WPTools = require('wptools');24var options = {
Using AI Code Generation
1var wptoolkit = require("wptoolkit");2var wp = new wptoolkit();3wp.gllayerProperties({4}, function(err, res) {5 if (err) {6 console.log(err);7 } else {8 console.log(res);9 }10});
Using AI Code Generation
1var wpt = new WptService();2var glLayer = new GLLayer();3var layerProperties = wpt.gllayerProperties(glLayer);4var wpt = new WptService();5var glSource = new GLSource();6var sourceProperties = wpt.glsourceProperties(glSource);7var wpt = new WptService();8var glFilter = new GLFilter();9var filterProperties = wpt.glfilterProperties(glFilter);10var wpt = new WptService();11var glFilter = new GLFilter();
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!!