From 2aa4a82499d4becd2284cdb482213d541b8804dd Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Sun, 28 Apr 2024 16:29:10 +0200 Subject: Adding upstream version 86.0.1. Signed-off-by: Daniel Baumann --- dom/vr/test/crashtests/crashtests.list | 1 + .../crashtests/enumerate_vr_on_dying_window.html | 14 ++ dom/vr/test/mochitest/VRSimulationDriver.js | 95 ++++++++++++ dom/vr/test/mochitest/WebVRHelpers.js | 19 +++ dom/vr/test/mochitest/mochitest.ini | 31 ++++ dom/vr/test/mochitest/requestPresent.js | 74 +++++++++ dom/vr/test/mochitest/runVRTest.js | 17 +++ .../mochitest/test_vrController_displayId.html | 57 +++++++ dom/vr/test/mochitest/test_vrDisplay_canvas2d.html | 55 +++++++ .../test/mochitest/test_vrDisplay_exitPresent.html | 51 +++++++ .../mochitest/test_vrDisplay_getFrameData.html | 148 ++++++++++++++++++ .../test_vrDisplay_onvrdisplayconnect.html | 43 ++++++ ...Display_onvrdisplaydeactivate_crosscontent.html | 54 +++++++ .../mochitest/test_vrDisplay_requestPresent.html | 130 ++++++++++++++++ dom/vr/test/reftest/VRSimulationDriver.js | 60 ++++++++ dom/vr/test/reftest/change_size.html | 168 ++++++++++++++++++++ dom/vr/test/reftest/change_size.png | Bin 0 -> 1439 bytes dom/vr/test/reftest/draw_rect.html | 136 +++++++++++++++++ dom/vr/test/reftest/draw_rect.png | Bin 0 -> 1747 bytes dom/vr/test/reftest/reftest.list | 10 ++ dom/vr/test/reftest/webgl-util.js | 170 +++++++++++++++++++++ dom/vr/test/reftest/wrapper.html | 26 ++++ 22 files changed, 1359 insertions(+) create mode 100644 dom/vr/test/crashtests/crashtests.list create mode 100644 dom/vr/test/crashtests/enumerate_vr_on_dying_window.html create mode 100644 dom/vr/test/mochitest/VRSimulationDriver.js create mode 100644 dom/vr/test/mochitest/WebVRHelpers.js create mode 100644 dom/vr/test/mochitest/mochitest.ini create mode 100644 dom/vr/test/mochitest/requestPresent.js create mode 100644 dom/vr/test/mochitest/runVRTest.js create mode 100644 dom/vr/test/mochitest/test_vrController_displayId.html create mode 100644 dom/vr/test/mochitest/test_vrDisplay_canvas2d.html create mode 100644 dom/vr/test/mochitest/test_vrDisplay_exitPresent.html create mode 100644 dom/vr/test/mochitest/test_vrDisplay_getFrameData.html create mode 100644 dom/vr/test/mochitest/test_vrDisplay_onvrdisplayconnect.html create mode 100644 dom/vr/test/mochitest/test_vrDisplay_onvrdisplaydeactivate_crosscontent.html create mode 100644 dom/vr/test/mochitest/test_vrDisplay_requestPresent.html create mode 100644 dom/vr/test/reftest/VRSimulationDriver.js create mode 100644 dom/vr/test/reftest/change_size.html create mode 100644 dom/vr/test/reftest/change_size.png create mode 100644 dom/vr/test/reftest/draw_rect.html create mode 100644 dom/vr/test/reftest/draw_rect.png create mode 100644 dom/vr/test/reftest/reftest.list create mode 100644 dom/vr/test/reftest/webgl-util.js create mode 100644 dom/vr/test/reftest/wrapper.html (limited to 'dom/vr/test') diff --git a/dom/vr/test/crashtests/crashtests.list b/dom/vr/test/crashtests/crashtests.list new file mode 100644 index 0000000000..1cc06896f8 --- /dev/null +++ b/dom/vr/test/crashtests/crashtests.list @@ -0,0 +1 @@ +pref(dom.vr.always_support_vr,true) load enumerate_vr_on_dying_window.html diff --git a/dom/vr/test/crashtests/enumerate_vr_on_dying_window.html b/dom/vr/test/crashtests/enumerate_vr_on_dying_window.html new file mode 100644 index 0000000000..2906faa79c --- /dev/null +++ b/dom/vr/test/crashtests/enumerate_vr_on_dying_window.html @@ -0,0 +1,14 @@ + + + + + + + diff --git a/dom/vr/test/mochitest/VRSimulationDriver.js b/dom/vr/test/mochitest/VRSimulationDriver.js new file mode 100644 index 0000000000..5129485926 --- /dev/null +++ b/dom/vr/test/mochitest/VRSimulationDriver.js @@ -0,0 +1,95 @@ +var VRServiceTest; +var vrMockDisplay; + +var VRSimulationDriver = (function() { + "use strict"; + + var AttachWebVRDisplay = function() { + if (vrMockDisplay) { + // Avoid creating multiple displays + return Promise.resolve(vrMockDisplay); + } + var promise = VRServiceTest.attachVRDisplay("VRDisplayTest"); + promise.then(function(display) { + assert_true(display != null, "AttachWebVRDisplay should success."); + vrMockDisplay = display; + }); + + return promise; + }; + + var SetVRDisplayPose = function( + position, + linearVelocity, + linearAcceleration, + orientation, + angularVelocity, + angularAcceleration + ) { + vrMockDisplay.setPose( + position, + linearVelocity, + linearAcceleration, + orientation, + angularVelocity, + angularAcceleration + ); + }; + + var SetEyeResolution = function(width, height) { + vrMockDisplay.setEyeResolution(width, height); + }; + + var SetEyeParameter = function( + eye, + offsetX, + offsetY, + offsetZ, + upDegree, + rightDegree, + downDegree, + leftDegree + ) { + vrMockDisplay.setEyeParameter( + eye, + offsetX, + offsetY, + offsetZ, + upDegree, + rightDegree, + downDegree, + leftDegree + ); + }; + + var SetMountState = function(isMounted) { + vrMockDisplay.setMountState(isMounted); + }; + + var UpdateVRDisplay = function() { + vrMockDisplay.update(); + }; + + var AttachVRController = function() { + var promise = VRServiceTest.attachVRController("VRControllerTest"); + promise.then(function(controller) { + assert_true(controller != null, "AttachVRController should success."); + }); + + return promise; + }; + + var API = { + AttachWebVRDisplay, + SetVRDisplayPose, + SetEyeResolution, + SetEyeParameter, + SetMountState, + UpdateVRDisplay, + AttachVRController, + + none: false, + }; + + return API; +})(); diff --git a/dom/vr/test/mochitest/WebVRHelpers.js b/dom/vr/test/mochitest/WebVRHelpers.js new file mode 100644 index 0000000000..a2037bf821 --- /dev/null +++ b/dom/vr/test/mochitest/WebVRHelpers.js @@ -0,0 +1,19 @@ +var WebVRHelpers = (function() { + "use strict"; + + var RequestPresentOnVRDisplay = function(vrDisplay, vrLayers, callback) { + if (callback) { + callback(); + } + + return vrDisplay.requestPresent(vrLayers); + }; + + var API = { + RequestPresentOnVRDisplay, + + none: false, + }; + + return API; +})(); diff --git a/dom/vr/test/mochitest/mochitest.ini b/dom/vr/test/mochitest/mochitest.ini new file mode 100644 index 0000000000..87a4174a21 --- /dev/null +++ b/dom/vr/test/mochitest/mochitest.ini @@ -0,0 +1,31 @@ +# Please confirm there is no other VR display connected. Otherwise, VRPuppetDisplay can't be attached. +[DEFAULT] +support-files = + VRSimulationDriver.js + requestPresent.js + runVRTest.js + WebVRHelpers.js +[test_vrController_displayId.html] +# Enable Linux after Bug 1310655 # TIMED_OUT for Android. +# skip-if = (os != "win" && release_or_beta) || (os == "android") +# Dependencies for re-enabling these are tracked by meta bug 1555185. +skip-if = true +[test_vrDisplay_canvas2d.html] +# skip-if = (os != "win" && release_or_beta) # Enable Linux after Bug 1310655 +# Dependencies for re-enabling these are tracked by meta bug 1555185. +skip-if = true +[test_vrDisplay_exitPresent.html] +# skip-if = (os != "win" && release_or_beta) # Enable Linux after Bug 1310655 +# Dependencies for re-enabling these are tracked by meta bug 1555185. +skip-if = true +[test_vrDisplay_getFrameData.html] +# Enable Linux after Bug 1310655, enable Android after Bug 1348246 +# skip-if = (os != "win" && release_or_beta) || (os == "android") +# Dependencies for re-enabling these are tracked by meta bug 1555185. +skip-if = true +[test_vrDisplay_onvrdisplayconnect.html] +skip-if = true +[test_vrDisplay_onvrdisplaydeactivate_crosscontent.html] +skip-if = true +[test_vrDisplay_requestPresent.html] +skip-if = true diff --git a/dom/vr/test/mochitest/requestPresent.js b/dom/vr/test/mochitest/requestPresent.js new file mode 100644 index 0000000000..a2f9dd4d11 --- /dev/null +++ b/dom/vr/test/mochitest/requestPresent.js @@ -0,0 +1,74 @@ +// requestPresent.js +// +// This file provides helpers for testing VRDisplay requestPresent. + +function attachVRDisplay(test) { + assert_equals( + typeof navigator.getVRDisplays, + "function", + "'navigator.getVRDisplays()' must be defined." + ); + return VRSimulationDriver.AttachWebVRDisplay(); +} + +function setupVRDisplay(test) { + assert_equals( + typeof navigator.getVRDisplays, + "function", + "'navigator.getVRDisplays()' must be defined." + ); + return VRSimulationDriver.AttachWebVRDisplay() + .then(() => { + return navigator.getVRDisplays(); + }) + .then(displays => { + assert_equals( + displays.length, + 1, + "displays.length must be one after attach." + ); + vrDisplay = displays[0]; + return validateNewVRDisplay(test, vrDisplay); + }); +} + +// Validate the settings off a freshly created VRDisplay (prior to calling +// requestPresent). +function validateNewVRDisplay(test, display) { + assert_true( + display.capabilities.canPresent, + "display.capabilities.canPresent must always be true for HMDs." + ); + assert_equals( + display.capabilities.maxLayers, + 1, + "display.capabilities.maxLayers must always be 1 when display.capabilities.canPresent is true for current spec revision." + ); + assert_false( + display.isPresenting, + "display.isPresenting must be false before calling requestPresent." + ); + assert_equals( + display.getLayers().length, + 0, + "display.getLayers() should have no layers if not presenting." + ); + var promise = display.exitPresent(); + return promise_rejects(test, null, promise); +} + +// Validate the settings off a VRDisplay after requestPresent promise is +// rejected or after exitPresent is fulfilled. +function validateDisplayNotPresenting(test, display) { + assert_false( + display.isPresenting, + "display.isPresenting must be false if requestPresent is rejected or after exitPresent is fulfilled." + ); + assert_equals( + display.getLayers().length, + 0, + "display.getLayers() should have no layers if requestPresent is rejected or after exitPresent is fulfilled." + ); + var promise = display.exitPresent(); + return promise_rejects(test, null, promise); +} diff --git a/dom/vr/test/mochitest/runVRTest.js b/dom/vr/test/mochitest/runVRTest.js new file mode 100644 index 0000000000..d5a80853e0 --- /dev/null +++ b/dom/vr/test/mochitest/runVRTest.js @@ -0,0 +1,17 @@ +function runVRTest(callback) { + SpecialPowers.pushPrefEnv( + { + set: [ + ["dom.vr.puppet.enabled", true], + ["dom.vr.require-gesture", false], + ["dom.vr.test.enabled", true], + ["dom.vr.display.enumerate.interval", 0], + ["dom.vr.controller.enumerate.interval", 0], + ], + }, + () => { + VRServiceTest = navigator.requestVRServiceTest(); + callback(); + } + ); +} diff --git a/dom/vr/test/mochitest/test_vrController_displayId.html b/dom/vr/test/mochitest/test_vrController_displayId.html new file mode 100644 index 0000000000..e69e3920d2 --- /dev/null +++ b/dom/vr/test/mochitest/test_vrController_displayId.html @@ -0,0 +1,57 @@ + + + + VRController DisplayId + + + + + + + + + + + diff --git a/dom/vr/test/mochitest/test_vrDisplay_canvas2d.html b/dom/vr/test/mochitest/test_vrDisplay_canvas2d.html new file mode 100644 index 0000000000..4d20e21352 --- /dev/null +++ b/dom/vr/test/mochitest/test_vrDisplay_canvas2d.html @@ -0,0 +1,55 @@ + + + + VRDisplay Canvas2D + + + + + + + + + + + diff --git a/dom/vr/test/mochitest/test_vrDisplay_exitPresent.html b/dom/vr/test/mochitest/test_vrDisplay_exitPresent.html new file mode 100644 index 0000000000..dc2c700723 --- /dev/null +++ b/dom/vr/test/mochitest/test_vrDisplay_exitPresent.html @@ -0,0 +1,51 @@ + + + + VRDisplay ExitPresent + + + + + + + + + + + + + + diff --git a/dom/vr/test/mochitest/test_vrDisplay_getFrameData.html b/dom/vr/test/mochitest/test_vrDisplay_getFrameData.html new file mode 100644 index 0000000000..c8a986ae8e --- /dev/null +++ b/dom/vr/test/mochitest/test_vrDisplay_getFrameData.html @@ -0,0 +1,148 @@ + + + + VRDisplay GetFrameData + + + + + + + + + + + + + diff --git a/dom/vr/test/mochitest/test_vrDisplay_onvrdisplayconnect.html b/dom/vr/test/mochitest/test_vrDisplay_onvrdisplayconnect.html new file mode 100644 index 0000000000..e1912c7c41 --- /dev/null +++ b/dom/vr/test/mochitest/test_vrDisplay_onvrdisplayconnect.html @@ -0,0 +1,43 @@ + + + VRDisplay onvrdisplayconnect test + + + + + + + + + + + + + + diff --git a/dom/vr/test/mochitest/test_vrDisplay_onvrdisplaydeactivate_crosscontent.html b/dom/vr/test/mochitest/test_vrDisplay_onvrdisplaydeactivate_crosscontent.html new file mode 100644 index 0000000000..6c58e5efd1 --- /dev/null +++ b/dom/vr/test/mochitest/test_vrDisplay_onvrdisplaydeactivate_crosscontent.html @@ -0,0 +1,54 @@ + + + VRDisplay onvrdisplaydeactivate Crosscontent test + + + + + + + + + + + + + + + diff --git a/dom/vr/test/mochitest/test_vrDisplay_requestPresent.html b/dom/vr/test/mochitest/test_vrDisplay_requestPresent.html new file mode 100644 index 0000000000..4d021b6e0f --- /dev/null +++ b/dom/vr/test/mochitest/test_vrDisplay_requestPresent.html @@ -0,0 +1,130 @@ + + + + VRDisplay RequestPresent + + + + + + + + + + +
+ + + diff --git a/dom/vr/test/reftest/VRSimulationDriver.js b/dom/vr/test/reftest/VRSimulationDriver.js new file mode 100644 index 0000000000..971cdb8626 --- /dev/null +++ b/dom/vr/test/reftest/VRSimulationDriver.js @@ -0,0 +1,60 @@ + +var VRServiceTest; +var vrMockDisplay; + +var VRSimulationDriver = (function() { +"use strict"; + +var AttachWebVRDisplay = function() { + if (vrMockDisplay) { + // Avoid creating multiple displays + return Promise.resolve(vrMockDisplay); + } + var promise = VRServiceTest.attachVRDisplay("VRDisplayTest"); + promise.then(function (display) { + vrMockDisplay = display; + }); + + return promise; +}; + +var SetVRDisplayPose = function(position, + linearVelocity, linearAcceleration, + orientation, angularVelocity, + angularAcceleration) { + vrMockDisplay.setPose(position, linearVelocity, linearAcceleration, + orientation, angularVelocity, angularAcceleration); +}; + +var SetEyeResolution = function(width, height) { + vrMockDisplay.setEyeResolution(width, height); +} + +var SetEyeParameter = function(eye, offsetX, offsetY, offsetZ, + upDegree, rightDegree, downDegree, leftDegree) { + vrMockDisplay.setEyeParameter(eye, offsetX, offsetY, offsetZ, upDegree, rightDegree, + downDegree, leftDegree); +} + +var SetMountState = function(isMounted) { + vrMockDisplay.setMountState(isMounted); +} + +var UpdateVRDisplay = function() { + vrMockDisplay.update(); +} + +var API = { + AttachWebVRDisplay: AttachWebVRDisplay, + SetVRDisplayPose: SetVRDisplayPose, + SetEyeResolution: SetEyeResolution, + SetEyeParameter: SetEyeParameter, + SetMountState: SetMountState, + UpdateVRDisplay: UpdateVRDisplay, + + none: false +}; + +return API; + +}()); \ No newline at end of file diff --git a/dom/vr/test/reftest/change_size.html b/dom/vr/test/reftest/change_size.html new file mode 100644 index 0000000000..f810f30821 --- /dev/null +++ b/dom/vr/test/reftest/change_size.html @@ -0,0 +1,168 @@ + + + + + + + + + + + + + + +
+ + + diff --git a/dom/vr/test/reftest/change_size.png b/dom/vr/test/reftest/change_size.png new file mode 100644 index 0000000000..fe03114b20 Binary files /dev/null and b/dom/vr/test/reftest/change_size.png differ diff --git a/dom/vr/test/reftest/draw_rect.html b/dom/vr/test/reftest/draw_rect.html new file mode 100644 index 0000000000..c6f52736c0 --- /dev/null +++ b/dom/vr/test/reftest/draw_rect.html @@ -0,0 +1,136 @@ + + + + + + + + + + + + + + +
+ + + diff --git a/dom/vr/test/reftest/draw_rect.png b/dom/vr/test/reftest/draw_rect.png new file mode 100644 index 0000000000..0f4d24a0d1 Binary files /dev/null and b/dom/vr/test/reftest/draw_rect.png differ diff --git a/dom/vr/test/reftest/reftest.list b/dom/vr/test/reftest/reftest.list new file mode 100644 index 0000000000..53ecc53c63 --- /dev/null +++ b/dom/vr/test/reftest/reftest.list @@ -0,0 +1,10 @@ +# WebVR Reftests +# Please confirm there is no other VR display connected. Otherwise, VRPuppetDisplay can't be attached. +defaults pref(dom.vr.puppet.enabled,true) pref(dom.vr.test.enabled,true) pref(dom.vr.require-gesture,false) pref(dom.vr.puppet.submitframe,1) pref(dom.vr.display.rafMaxDuration,200) pref(dom.vr.display.enumerate.interval,0) pref(dom.vr.controller.enumerate.interval,0) +# WebVR Tests have been disabled as refactoring of gfxVRPuppet is landing. Dependencies for re-enabling these are tracked by meta bug 1555185. +# VR SubmitFrame is only implemented for D3D11.1 and MacOSX now. +# Our Windows 7 test machines don't support D3D11.1, so we run these tests on Windows 8+ only. +# skip-if((!winWidget&&release_or_beta)||Android||gtkWidget||!layersGPUAccelerated||/^Windows\x20NT\x206\.1/.test(http.oscpu)) == draw_rect.html wrapper.html?draw_rect.png +# On MacOSX platform, getting different color interpolation result. +# For lower resolution Mac hardware, we need to adjust it to fuzzy-if(cocoaWidget,0-1,0-1200). +# fuzzy-if(/^Windows\x20NT\x2010\.0/.test(http.oscpu)||cocoaWidget,0-1,0-600) skip-if((!winWidget&&release_or_beta)||Android||gtkWidget||!layersGPUAccelerated||/^Windows\x20NT\x206\.1/.test(http.oscpu)) == change_size.html wrapper.html?change_size.png diff --git a/dom/vr/test/reftest/webgl-util.js b/dom/vr/test/reftest/webgl-util.js new file mode 100644 index 0000000000..21ef9cf0ff --- /dev/null +++ b/dom/vr/test/reftest/webgl-util.js @@ -0,0 +1,170 @@ +WebGLUtil = (function() { + // --------------------------------------------------------------------------- + // Error handling (for obvious failures, such as invalid element ids) + + function defaultErrorFunc(str) { + console.log('Error: ' + str); + } + + var gErrorFunc = defaultErrorFunc; + function setErrorFunc(func) { + gErrorFunc = func; + } + + function error(str) { + gErrorFunc(str); + } + + // --------------------------------------------------------------------------- + // Warning handling (for failures that may be intentional) + + function defaultWarningFunc(str) { + console.log('Warning: ' + str); + } + + var gWarningFunc = defaultWarningFunc; + function setWarningFunc(func) { + gWarningFunc = func; + } + + function warning(str) { + gWarningFunc(str); + } + + // --------------------------------------------------------------------------- + // WebGL helpers + + function getWebGL(canvasId, requireConformant, attributes) { + // `requireConformant` will default to falsey if it is not supplied. + + var canvas = document.getElementById(canvasId); + + var gl = null; + try { + gl = canvas.getContext('webgl', attributes); + } catch(e) {} + + if (!gl && !requireConformant) { + try { + gl = canvas.getContext('experimental-webgl', attributes); + } catch(e) {} + } + + if (!gl) { + error('WebGL context could not be retrieved from \'' + canvasId + '\'.'); + return null; + } + + return gl; + } + + function withWebGL2(canvasId, callback, onFinished) { + var run = function() { + var canvas = document.getElementById(canvasId); + + var gl = null; + try { + gl = canvas.getContext('webgl2'); + } catch(e) {} + + if (!gl) { + todo(false, 'WebGL2 is not supported'); + onFinished(); + return; + } + + function errorFunc(str) { + ok(false, 'Error: ' + str); + } + setErrorFunc(errorFunc); + setWarningFunc(errorFunc); + + callback(gl); + onFinished(); + }; + + try { + var prefArrArr = [ + ['webgl.force-enabled', true], + ['webgl.enable-webgl2', true], + ]; + var prefEnv = {'set': prefArrArr}; + SpecialPowers.pushPrefEnv(prefEnv, run); + } catch (e) { + warning('No SpecialPowers, but trying WebGL2 anyway...'); + run(); + } + } + + function getContentFromElem(elem) { + var str = ""; + var k = elem.firstChild; + while (k) { + if (k.nodeType == 3) + str += k.textContent; + + k = k.nextSibling; + } + + return str; + } + + // Returns a valid shader, or null on errors. + function createShaderById(gl, id) { + var elem = document.getElementById(id); + if (!elem) { + error('Failed to create shader from non-existent id \'' + id + '\'.'); + return null; + } + + var src = getContentFromElem(elem); + + var shader; + if (elem.type == "x-shader/x-fragment") { + shader = gl.createShader(gl.FRAGMENT_SHADER); + } else if (elem.type == "x-shader/x-vertex") { + shader = gl.createShader(gl.VERTEX_SHADER); + } else { + error('Bad MIME type for shader \'' + id + '\': ' + elem.type + '.'); + return null; + } + + gl.shaderSource(shader, src); + gl.compileShader(shader); + + return shader; + } + + function createProgramByIds(gl, vsId, fsId) { + var vs = createShaderById(gl, vsId); + var fs = createShaderById(gl, fsId); + if (!vs || !fs) + return null; + + var prog = gl.createProgram(); + gl.attachShader(prog, vs); + gl.attachShader(prog, fs); + gl.linkProgram(prog); + + if (!gl.getProgramParameter(prog, gl.LINK_STATUS)) { + var str = "Shader program linking failed:"; + str += "\nShader program info log:\n" + gl.getProgramInfoLog(prog); + str += "\n\nVert shader log:\n" + gl.getShaderInfoLog(vs); + str += "\n\nFrag shader log:\n" + gl.getShaderInfoLog(fs); + warning(str); + return null; + } + + return prog; + } + + return { + setErrorFunc: setErrorFunc, + setWarningFunc: setWarningFunc, + + getWebGL: getWebGL, + withWebGL2: withWebGL2, + createShaderById: createShaderById, + createProgramByIds: createProgramByIds, + }; +})(); diff --git a/dom/vr/test/reftest/wrapper.html b/dom/vr/test/reftest/wrapper.html new file mode 100644 index 0000000000..40d0de6e42 --- /dev/null +++ b/dom/vr/test/reftest/wrapper.html @@ -0,0 +1,26 @@ + + + +Image reftest wrapper + + + + + + + + -- cgit v1.2.3