Skip to content

Commit

Permalink
Allow makeXRCompatible as an optional method (KhronosGroup#3198)
Browse files Browse the repository at this point in the history
* Allow makeXRCompatible as an optional method

The WebXR device specification mixes in a new function makeXRCompatible.
The methods.html and methods-2.html tests should allow for the possibility
of the method existing.

While here, update the code to more modern JavaScript.

* Factor out shared context-methods.js, backport to 2.0.0/1.0.3.

Co-authored-by: Jeff Gilbert <[email protected]>
  • Loading branch information
grorg and kdashg authored May 7, 2021
1 parent b027b53 commit 4295495
Show file tree
Hide file tree
Showing 8 changed files with 174 additions and 215 deletions.
52 changes: 52 additions & 0 deletions conformance-suites/1.0.3/conformance/context/context-methods.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
"use strict";

// Properties to be ignored because they were added in versions of the
// spec that are backward-compatible with this version
const IGNORED_METHODS = [
// There is no official spec for the commit API yet, the proposal link is:
// https://wiki.whatwg.org/wiki/OffscreenCanvas
"commit",

// For WebXR integration:
"makeXRCompatible",
];

function assertFunction(v, f) {
try {
if (typeof v[f] != "function") {
testFailed(`Property either does not exist or is not a function: ${f}`);
return false;
} else {
return true;
}
} catch(e) {
testFailed(`Trying to access the property '${f}' threw an error: ${e.toString()}`);
}
}

function testContextMethods(gl, requiredContextMethods) {
const acceptableMethods = [].concat(requiredContextMethods, IGNORED_METHODS);

let passed = true;
requiredContextMethods.forEach(method => {
const r = assertFunction(gl, method);
passed = passed && r;
});
if (passed) {
testPassed("All WebGL methods found.");
}
let extended = false;
for (let propertyName of Object.getOwnPropertyNames(gl)) {
if (typeof gl[propertyName] == "function" && !acceptableMethods.includes(propertyName)) {
if (!extended) {
extended = true;
testFailed("Also found the following extra methods:");
}
testFailed(propertyName);
}
}

if (!extended) {
testPassed("No extra methods found on WebGL context.");
}
}
41 changes: 2 additions & 39 deletions conformance-suites/1.0.3/conformance/context/methods.html
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
<link rel="stylesheet" href="../../resources/js-test-style.css"/>
<script src="../../resources/js-test-pre.js"></script>
<script src="../resources/webgl-test-utils.js"></script>
<script src="context-methods.js"></script>
</head>
<body>
<div id="description"></div>
Expand Down Expand Up @@ -180,52 +181,14 @@
"viewport"
];

// Properties to be ignored because they were added in versions of the
// spec that are backward-compatible with this version
var ignoredMethods = [
];

function assertFunction(v, f) {
try {
if (typeof v[f] != "function") {
testFailed("Property either does not exist or is not a function: " + f);
return false;
} else {
return true;
}
} catch(e) {
testFailed("Trying to access the property '" + f + "' threw an error: "+e.toString());
}
}

debug("");
debug("Canvas.getContext");

var wtu = WebGLTestUtils;
var canvas = document.getElementById("canvas");
var gl = wtu.create3DContext(canvas);
var passed = true;
for (var i=0; i<methods.length; i++) {
var r = assertFunction(gl, methods[i]);
passed = passed && r;
}
if (passed) {
testPassed("All WebGL methods found.");
}
var extended = false;
for (var i in gl) {
if (typeof gl[i] == "function" && methods.indexOf(i) == -1 && ignoredMethods.indexOf(i) == -1) {
if (!extended) {
extended = true;
testFailed("Also found the following extra methods:");
}
testFailed(i);
}
}

if (!extended) {
testPassed("No extra methods found on WebGL context.");
}
testContextMethods(gl, methods);

debug("");
var successfullyParsed = true;
Expand Down
44 changes: 2 additions & 42 deletions conformance-suites/2.0.0/conformance/context/methods.html
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
<link rel="stylesheet" href="../../resources/js-test-style.css"/>
<script src="../../js/js-test-pre.js"></script>
<script src="../../js/webgl-test-utils.js"></script>
<script src="../../js/tests/context-methods.js"></script>
</head>
<body>
<div id="description"></div>
Expand Down Expand Up @@ -180,55 +181,14 @@
"viewport"
];

// Properties to be ignored because they were added in versions of the
// spec that are backward-compatible with this version
var ignoredMethods = [
// There is no official spec for the commit API yet, the proposal link is:
// https://wiki.whatwg.org/wiki/OffscreenCanvas
"commit"
];

function assertFunction(v, f) {
try {
if (typeof v[f] != "function") {
testFailed("Property either does not exist or is not a function: " + f);
return false;
} else {
return true;
}
} catch(e) {
testFailed("Trying to access the property '" + f + "' threw an error: "+e.toString());
}
}

debug("");
debug("Canvas.getContext");

var wtu = WebGLTestUtils;
var canvas = document.getElementById("canvas");
var gl = wtu.create3DContext(canvas);
var passed = true;
for (var i=0; i<methods.length; i++) {
var r = assertFunction(gl, methods[i]);
passed = passed && r;
}
if (passed) {
testPassed("All WebGL methods found.");
}
var extended = false;
for (var i in gl) {
if (typeof gl[i] == "function" && methods.indexOf(i) == -1 && ignoredMethods.indexOf(i) == -1) {
if (!extended) {
extended = true;
testFailed("Also found the following extra methods:");
}
testFailed(i);
}
}

if (!extended) {
testPassed("No extra methods found on WebGL context.");
}
testContextMethods(gl, methods);

debug("");
var successfullyParsed = true;
Expand Down
44 changes: 2 additions & 42 deletions conformance-suites/2.0.0/conformance2/context/methods-2.html
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
<link rel="stylesheet" href="../../resources/js-test-style.css"/>
<script src="../../js/js-test-pre.js"></script>
<script src="../../js/webgl-test-utils.js"></script>
<script src="../../js/tests/context-methods.js"></script>
</head>
<body>
<div id="description"></div>
Expand Down Expand Up @@ -270,55 +271,14 @@
"bindVertexArray",
];

// Properties to be ignored because they were added in versions of the
// spec that are backward-compatible with this version
var ignoredMethods = [
// There is no official spec for the commit API yet, the proposal link is:
// https://wiki.whatwg.org/wiki/OffscreenCanvas
"commit"
];

function assertFunction(v, f) {
try {
if (typeof v[f] != "function") {
testFailed("Property either does not exist or is not a function: " + f);
return false;
} else {
return true;
}
} catch(e) {
testFailed("Trying to access the property '" + f + "' threw an error: "+e.toString());
}
}

debug("");
debug("Canvas.getContext");

var wtu = WebGLTestUtils;
var canvas = document.getElementById("canvas");
var gl = wtu.create3DContext(canvas, null, 2);
var passed = true;
for (var i=0; i<methods.length; i++) {
var r = assertFunction(gl, methods[i]);
passed = passed && r;
}
if (passed) {
testPassed("All WebGL methods found.");
}
var extended = false;
for (var i in gl) {
if (typeof gl[i] == "function" && methods.indexOf(i) == -1 && ignoredMethods.indexOf(i) == -1) {
if (!extended) {
extended = true;
testFailed("Also found the following extra methods:");
}
testFailed(i);
}
}

if (!extended) {
testPassed("No extra methods found on WebGL context.");
}
testContextMethods(gl, methods);

debug("");
var successfullyParsed = true;
Expand Down
52 changes: 52 additions & 0 deletions conformance-suites/2.0.0/js/tests/context-methods.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
"use strict";

// Properties to be ignored because they were added in versions of the
// spec that are backward-compatible with this version
const IGNORED_METHODS = [
// There is no official spec for the commit API yet, the proposal link is:
// https://wiki.whatwg.org/wiki/OffscreenCanvas
"commit",

// For WebXR integration:
"makeXRCompatible",
];

function assertFunction(v, f) {
try {
if (typeof v[f] != "function") {
testFailed(`Property either does not exist or is not a function: ${f}`);
return false;
} else {
return true;
}
} catch(e) {
testFailed(`Trying to access the property '${f}' threw an error: ${e.toString()}`);
}
}

function testContextMethods(gl, requiredContextMethods) {
const acceptableMethods = [].concat(requiredContextMethods, IGNORED_METHODS);

let passed = true;
requiredContextMethods.forEach(method => {
const r = assertFunction(gl, method);
passed = passed && r;
});
if (passed) {
testPassed("All WebGL methods found.");
}
let extended = false;
for (let propertyName of Object.getOwnPropertyNames(gl)) {
if (typeof gl[propertyName] == "function" && !acceptableMethods.includes(propertyName)) {
if (!extended) {
extended = true;
testFailed("Also found the following extra methods:");
}
testFailed(propertyName);
}
}

if (!extended) {
testPassed("No extra methods found on WebGL context.");
}
}
52 changes: 6 additions & 46 deletions sdk/tests/conformance/context/methods.html
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
<link rel="stylesheet" href="../../resources/js-test-style.css"/>
<script src="../../js/js-test-pre.js"></script>
<script src="../../js/webgl-test-utils.js"></script>
<script src="../../js/tests/context-methods.js"></script>
</head>
<body>
<div id="description"></div>
Expand All @@ -20,7 +21,7 @@
"use strict";
description("This test ensures that the WebGL context has all the methods in the specification.");

var methods = [
const methods = [
"getContextAttributes",
"activeTexture",
"attachShader",
Expand Down Expand Up @@ -159,55 +160,14 @@
"viewport"
];

// Properties to be ignored because they were added in versions of the
// spec that are backward-compatible with this version
var ignoredMethods = [
// There is no official spec for the commit API yet, the proposal link is:
// https://wiki.whatwg.org/wiki/OffscreenCanvas
"commit"
];

function assertFunction(v, f) {
try {
if (typeof v[f] != "function") {
testFailed("Property either does not exist or is not a function: " + f);
return false;
} else {
return true;
}
} catch(e) {
testFailed("Trying to access the property '" + f + "' threw an error: "+e.toString());
}
}

debug("");
debug("Canvas.getContext");

var wtu = WebGLTestUtils;
var canvas = document.getElementById("canvas");
var gl = wtu.create3DContext(canvas);
var passed = true;
for (var i=0; i<methods.length; i++) {
var r = assertFunction(gl, methods[i]);
passed = passed && r;
}
if (passed) {
testPassed("All WebGL methods found.");
}
var extended = false;
for (var i in gl) {
if (typeof gl[i] == "function" && methods.indexOf(i) == -1 && ignoredMethods.indexOf(i) == -1) {
if (!extended) {
extended = true;
testFailed("Also found the following extra methods:");
}
testFailed(i);
}
}
const wtu = WebGLTestUtils;
const canvas = document.getElementById("canvas");
const gl = wtu.create3DContext(canvas);

if (!extended) {
testPassed("No extra methods found on WebGL context.");
}
testContextMethods(gl, methods);

debug("");
var successfullyParsed = true;
Expand Down
Loading

0 comments on commit 4295495

Please sign in to comment.