How to use xr_promise_test method in wpt

Best JavaScript code snippet using wpt

webxr_util.js

Source:webxr_util.js Github

copy

Full Screen

...9// --enable-blink-features=MojoJS,MojoJSTest10// Debugging message helper, by default does nothing. Implementations can11// override this.12var xr_debug = function(name, msg) {};13function xr_promise_test(name, func, properties, glContextType, glContextProperties) {14 promise_test(async (t) => {15 // Perform any required test setup:16 xr_debug(name, 'setup');17 assert_implements(navigator.xr, 'missing navigator.xr');18 // Only set up once.19 if (!navigator.xr.test) {20 // Load test-only API helpers.21 const script = document.createElement('script');22 script.src = '/resources/test-only-api.js';23 script.async = false;24 const p = new Promise((resolve, reject) => {25 script.onload = () => { resolve(); };26 script.onerror = e => { reject(e); };27 })28 document.head.appendChild(script);29 await p;30 if (isChromiumBased) {31 // Chrome setup32 await loadChromiumResources();33 } else if (isWebKitBased) {34 // WebKit setup35 await setupWebKitWebXRTestAPI();36 }37 }38 // Either the test api needs to be polyfilled and it's not set up above, or39 // something happened to one of the known polyfills and it failed to be40 // setup properly. Either way, the fact that xr_promise_test is being used41 // means that the tests expect navigator.xr.test to be set. By rejecting now42 // we can hopefully provide a clearer indication of what went wrong.43 assert_implements(navigator.xr.test, 'missing navigator.xr.test, even after attempted load');44 let gl = null;45 let canvas = null;46 if (glContextType) {47 canvas = document.createElement('canvas');48 document.body.appendChild(canvas);49 gl = canvas.getContext(glContextType, glContextProperties);50 }51 // Ensure that any devices are disconnected when done. If this were done in52 // a .then() for the success case, a test that expected failure would53 // already be marked done at the time that runs and the shutdown would54 // interfere with the next test.55 t.add_cleanup(async () => {56 // Ensure system state is cleaned up.57 xr_debug(name, 'cleanup');58 await navigator.xr.test.disconnectAllDevices();59 });60 xr_debug(name, 'main');61 return func(t, gl);62 }, name, properties);63}64// A utility function for waiting one animation frame before running the callback65//66// This is only needed after calling FakeXRDevice methods outside of an animation frame67//68// This is so that we can paper over the potential race allowed by the "next animation frame"69// concept https://immersive-web.github.io/webxr-test-api/#xrsession-next-animation-frame70function requestSkipAnimationFrame(session, callback) {71 session.requestAnimationFrame(() => {72 session.requestAnimationFrame(callback);73 });74}75// A test function which runs through the common steps of requesting a session.76// Calls the passed in test function with the session, the controller for the77// device, and the test object.78function xr_session_promise_test(79 name, func, fakeDeviceInit, sessionMode, sessionInit, properties, glcontextPropertiesParam, gllayerPropertiesParam) {80 const glcontextProperties = (glcontextPropertiesParam) ? glcontextPropertiesParam : {};81 const gllayerProperties = (gllayerPropertiesParam) ? gllayerPropertiesParam : {};82 function runTest(t, glContext) {83 let testSession;84 let testDeviceController;85 let sessionObjects = {gl: glContext};86 // Ensure that any pending sessions are ended when done. This needs to87 // use a cleanup function to ensure proper sequencing. If this were88 // done in a .then() for the success case, a test that expected89 // failure would already be marked done at the time that runs, and the90 // shutdown would interfere with the next test which may have started.91 t.add_cleanup(async () => {92 // If a session was created, end it.93 if (testSession) {94 await testSession.end().catch(() => {});95 }96 });97 return navigator.xr.test.simulateDeviceConnection(fakeDeviceInit)98 .then((controller) => {99 testDeviceController = controller;100 return sessionObjects.gl.makeXRCompatible();101 })102 .then(() => new Promise((resolve, reject) => {103 // Perform the session request in a user gesture.104 xr_debug(name, 'simulateUserActivation');105 navigator.xr.test.simulateUserActivation(() => {106 xr_debug(name, 'document.hasFocus()=' + document.hasFocus());107 navigator.xr.requestSession(sessionMode, sessionInit || {})108 .then((session) => {109 xr_debug(name, 'session start');110 testSession = session;111 session.mode = sessionMode;112 let glLayer = new XRWebGLLayer(session, sessionObjects.gl, gllayerProperties);113 glLayer.context = sessionObjects.gl;114 // Session must have a baseLayer or frame requests115 // will be ignored.116 session.updateRenderState({117 baseLayer: glLayer118 });119 sessionObjects.glLayer = glLayer;120 xr_debug(name, 'session.visibilityState=' + session.visibilityState);121 resolve(func(session, testDeviceController, t, sessionObjects));122 })123 .catch((err) => {124 xr_debug(name, 'error: ' + err);125 reject(126 'Session with params ' +127 JSON.stringify(sessionMode) +128 ' was rejected on device ' +129 JSON.stringify(fakeDeviceInit) +130 ' with error: ' + err);131 });132 });133 }));134 }135 xr_promise_test(136 name + ' - webgl',137 runTest,138 properties,139 'webgl',140 {alpha: false, antialias: false, ...glcontextProperties}141 );142 xr_promise_test(143 name + ' - webgl2',144 runTest,145 properties,146 'webgl2',147 {alpha: false, antialias: false, ...glcontextProperties});148}149// This function wraps the provided function in a150// simulateUserActivation() call, and resolves the promise with the151// result of func(), or an error if one is thrown152function promise_simulate_user_activation(func) {153 return new Promise((resolve, reject) => {154 navigator.xr.test.simulateUserActivation(() => {155 try { let a = func(); resolve(a); } catch(e) { reject(e); }156 });...

Full Screen

Full Screen

Using AI Code Generation

copy

Full Screen

1'use strict';2promise_test(async testCase => {3 const session = await navigator.xr.requestSession('immersive-ar');4 const gl = session.renderState.baseLayer.getContext('webgl');5 const xrFrame = await session.requestAnimationFrame();6 await xrFrame.getViewerPose(session.renderState.baseLayer);7 assert_true(true);8}, 'Test that assert_true is working');9'use strict';10xr_test(async testCase => {11 const session = await navigator.xr.requestSession('immersive-ar');12 const gl = session.renderState.baseLayer.getContext('webgl');13 const xrFrame = await session.requestAnimationFrame();14 await xrFrame.getViewerPose(session.renderState.baseLayer);15 assert_true(true);16}, 'Test that assert_true is working');17Uncaught (in promise) Error: Test timed out18 at Timeout._onTimeout (test.js:15)19 at listOnTimeout (timers.js:324)20 at processTimers (timers.js:268)

Full Screen

Using AI Code Generation

copy

Full Screen

1importScripts('/resources/testharness.js');2importScripts('/resources/testharnessreport.js');3importScripts('test_utils.js');4xr_promise_test(async (t) => {5 await navigator.xr.requestDevice();6 const session = await navigator.xr.requestSession('immersive-vr');7 t.add_cleanup(() => session.end());8 await session.updateRenderState({ baseLayer: new XRWebGLLayer(session, getGlLayer()) });9 t.add_cleanup(() => session.end());10 window.location = 'about:blank';11 await new Promise(resolve => window.addEventListener('pagehide', resolve, { once: true }));12 await assert_sessionended_event(session);13}, 'Session ends when page is navigated away from.');14'use strict';15function assert_sessionended_event(session) {16 return new Promise((resolve, reject) => {17 session.addEventListener('end', resolve, { once: true });18 session.addEventListener('select', reject, { once: true });19 session.addEventListener('selectstart', reject, { once: true });20 session.addEventListener('selectend', reject, { once: true });21 session.addEventListener('inputsourceschange', reject, { once: true });22 });23}24function getGlLayer() {25 const canvas = document.createElement('canvas');26 const gl = canvas.getContext('webgl', { xrCompatible: true });27 return new XRWebGLLayer(session, gl);28}29'use strict';30function assert_sessionended_event(session) {31 return new Promise((resolve, reject) => {32 session.addEventListener('end', resolve, { once: true });33 session.addEventListener('select', reject, { once: true });34 session.addEventListener('selectstart', reject, { once: true });35 session.addEventListener('selectend', reject, { once: true });36 session.addEventListener('inputsourceschange', reject, { once: true });37 });38}39function getGlLayer() {40 const canvas = document.createElement('canvas');41 const gl = canvas.getContext('webgl', { xrCompatible: true });42 return new XRWebGLLayer(session, gl);43}

Full Screen

Using AI Code Generation

copy

Full Screen

1import {xr_promise_test} from "../resources/xr-test-utils.js"2const {session, sessionInit} = XrSessionTest.makeFakeXrSession();3const gl = document.createElement("canvas").getContext("webgl", {xrCompatible: true});4xr_promise_test(t => {5 return session.updateRenderState({baseLayer: new XRWebGLLayer(session, gl)}).then(() => {6 assert_true(session.renderState.baseLayer instanceof XRWebGLLayer);7 });8}, 'session.updateRenderState() with XRWebGLLayer');9export function xr_promise_test(func, name, properties) {10 promise_test(async t => {11 await func(t);12 }, name, properties);13}14export class XrSessionTest {15 static makeFakeXrSession() {16 const fakeSession = {};17 const fakeSessionInit = {};18 return {session: fakeSession, sessionInit: fakeSessionInit};19 }20}21export class XRWebGLLayer {22 constructor(session, context, options) {23 this.session = session;24 this.context = context;25 this.options = options;26 }27}28export function assert_true(condition, message) {29 if (!condition) {30 throw new Error(message);31 }32}33export function promise_test(func, name, properties) {34 test(() => {35 const promise = Promise.resolve().then(func);36 promise_test(() => promise, name, properties);37 }, name, properties);38}39export function test(func, name, properties) {40 QUnit.test(name, assert => {41 const done = assert.async();42 Promise.resolve().then(() => {43 func(assert);

Full Screen

Using AI Code Generation

copy

Full Screen

1importScripts("resources/testharness.js");2promise_test(async t => {3 await navigator.xr.requestDevice();4}, "Test that navigator.xr.requestDevice() works");5 setup({explicit_done: true});6 window.onload = () => {7 done();8 };9 setup({explicit_done: true});10 window.onload = () => {11 done();12 };13importScripts("resources/testharness.js");14importScripts("test.js");

Full Screen

Using AI Code Generation

copy

Full Screen

1const { XRTest } = require('web-platform-tests');2const { test } = new XRTest();3test(async t => {4});5const { XRTest } = require('web-platform-tests');6const { test } = new XRTest();7test(async t => {8});9const { XRTest } = require('web-platform-tests');10const { test } = new XRTest();11test(async t => {12});13const { XRTest } = require('web-platform-tests');14const { test } = new XRTest();15test(async t => {16});17const { XRTest } = require('web-platform-tests');18const { test } = new XRTest();19test(async t => {20});21const { XRTest } = require('web-platform-tests');22const { test } = new XRTest();23test(async t => {24});25const { XRTest } = require('web-platform-tests');26const { test } = new XRTest();27test(async t => {28});29const { XRTest } = require('web-platform-tests');30const { test } = new XRTest();

Full Screen

Using AI Code Generation

copy

Full Screen

1import {xr_promise_test, XRPose} from './resources/webxr-test-utils.js';2xr_promise_test(async t => {3 const session = await navigator.xr.requestSession('immersive-vr');4 const pose = new XRPose();5 assert_true(pose instanceof XRPose);6}, 'XRPose is an instance of XRPose');7xr_promise_test(async t => {8 const session = await navigator.xr.requestSession('immersive-vr');9 const pose = new XRPose();10 assert_true(pose instanceof Float32Array);11}, 'XRPose is an instance of Float32Array');12xr_promise_test(async t => {13 const session = await navigator.xr.requestSession('immersive-vr');14 const pose = new XRPose();15 assert_true(pose instanceof Array);16}, 'XRPose is an instance of Array');17xr_promise_test(async t => {18 const session = await navigator.xr.requestSession('immersive-vr');19 const pose = new XRPose();20 assert_true(pose instanceof Object);21}, 'XRPose is an instance of Object');22xr_promise_test(async t => {23 const session = await navigator.xr.requestSession('immersive-vr');24 const pose = new XRPose();25 assert_true(pose instanceof XRSpace);26}, 'XRPose is an instance of XRSpace');27xr_promise_test(async t => {28 const session = await navigator.xr.requestSession('immersive-vr');29 const pose = new XRPose();30 assert_true(pose instanceof Float64Array);31}, 'XRPose is an instance of Float64Array');32xr_promise_test(async t => {33 const session = await navigator.xr.requestSession('immersive-vr');34 const pose = new XRPose();35 assert_true(pose instanceof DataView);36}, 'XRPose is an instance of DataView');37xr_promise_test(async t => {38 const session = await navigator.xr.requestSession('immersive-vr');39 const pose = new XRPose();40 assert_true(pose instanceof Int16Array);41}, 'XRPose is an instance of Int16Array');42xr_promise_test(async t => {43 const session = await navigator.xr.requestSession('immersive-vr');44 const pose = new XRPose();45 assert_true(pose instanceof Uint8Array);

Full Screen

Using AI Code Generation

copy

Full Screen

1var wpt = require('web-platform-tests');2var webdriver = require('selenium-webdriver');3var assert = require('assert');4var test = require('selenium-webdriver/testing');5var By = webdriver.By;6var until = webdriver.until;7test.describe('WebXR', function() {8 test.it('should return an identity matrix when calling getPose', function() {9 var driver = new webdriver.Builder()10 .forBrowser('chrome')11 .build();12 driver.wait(until.titleIs('WebXR Test'), 10000);13 var canvas = driver.findElement(By.id('renderCanvas'));14 driver.wait(until.elementIsVisible(canvas), 10000);15 var xrButton = driver.findElement(By.id('xrButton'));16 driver.wait(until.elementIsVisible(xrButton), 10000);17 xrButton.click();18 driver.sleep(1000);19 var viewerRefSpace = driver.executeScript('return navigator.xr.requestReferenceSpace("viewer")');20 var pose = driver.executeScript('return navigator.xr.requestAnimationFrame((time, frame) => {return frame.getViewerPose(viewerRefSpace);})');21 assert.equal(pose.transform.matrix, [1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1]);22 driver.quit();23 });24});

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