Factor out shared context-methods.js, backport to 2.0.0/1.0.3.
diff --git a/conformance-suites/1.0.3/conformance/context/context-methods.js b/conformance-suites/1.0.3/conformance/context/context-methods.js
new file mode 100644
index 0000000..f647646
--- /dev/null
+++ b/conformance-suites/1.0.3/conformance/context/context-methods.js
@@ -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.");
+ }
+}
diff --git a/conformance-suites/1.0.3/conformance/context/methods.html b/conformance-suites/1.0.3/conformance/context/methods.html
index cc63665..2a36ca1 100644
--- a/conformance-suites/1.0.3/conformance/context/methods.html
+++ b/conformance-suites/1.0.3/conformance/context/methods.html
@@ -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>
@@ -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;
diff --git a/conformance-suites/2.0.0/conformance/context/methods.html b/conformance-suites/2.0.0/conformance/context/methods.html
index a086a16..56fab88 100644
--- a/conformance-suites/2.0.0/conformance/context/methods.html
+++ b/conformance-suites/2.0.0/conformance/context/methods.html
@@ -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>
@@ -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;
diff --git a/conformance-suites/2.0.0/conformance2/context/methods-2.html b/conformance-suites/2.0.0/conformance2/context/methods-2.html
index 4dbf368..0b6955a 100644
--- a/conformance-suites/2.0.0/conformance2/context/methods-2.html
+++ b/conformance-suites/2.0.0/conformance2/context/methods-2.html
@@ -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>
@@ -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;
diff --git a/conformance-suites/2.0.0/js/tests/context-methods.js b/conformance-suites/2.0.0/js/tests/context-methods.js
new file mode 100644
index 0000000..f647646
--- /dev/null
+++ b/conformance-suites/2.0.0/js/tests/context-methods.js
@@ -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.");
+ }
+}
diff --git a/sdk/tests/conformance/context/methods.html b/sdk/tests/conformance/context/methods.html
index 1c6f006..d1e47f3 100644
--- a/sdk/tests/conformance/context/methods.html
+++ b/sdk/tests/conformance/context/methods.html
@@ -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>
@@ -159,59 +160,14 @@
"viewport"
];
-// Properties to be ignored because they were added in versions of the
-// spec that are backward-compatible with this version
-const ignoredMethods = [
- // There is no official spec for the commit API yet, the proposal link is:
- // https://wiki.whatwg.org/wiki/OffscreenCanvas
- "commit"
-];
-
-const optionalMethods = [
- "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()}`);
- }
-}
-
debug("");
debug("Canvas.getContext");
const wtu = WebGLTestUtils;
const canvas = document.getElementById("canvas");
const gl = wtu.create3DContext(canvas);
-let passed = true;
-methods.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" && !methods.includes(propertyName) && !ignoredMethods.includes(propertyName) && !optionalMethods.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.");
-}
+testContextMethods(gl, methods);
debug("");
var successfullyParsed = true;
diff --git a/sdk/tests/conformance2/context/methods-2.html b/sdk/tests/conformance2/context/methods-2.html
index 0c05844..a389329 100644
--- a/sdk/tests/conformance2/context/methods-2.html
+++ b/sdk/tests/conformance2/context/methods-2.html
@@ -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>
@@ -249,59 +250,14 @@
"bindVertexArray",
];
-// Properties to be ignored because they were added in versions of the
-// spec that are backward-compatible with this version
-const ignoredMethods = [
- // There is no official spec for the commit API yet, the proposal link is:
- // https://wiki.whatwg.org/wiki/OffscreenCanvas
- "commit"
-];
-
-const optionalMethods = [
- "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()}`);
- }
-}
-
debug("");
debug("Canvas.getContext");
const wtu = WebGLTestUtils;
const canvas = document.getElementById("canvas");
const gl = wtu.create3DContext(canvas, null, 2);
-let passed = true;
-methods.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" && !methods.includes(propertyName) && !ignoredMethods.includes(propertyName) && !optionalMethods.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.");
-}
+testContextMethods(gl, methods);
debug("");
var successfullyParsed = true;
diff --git a/sdk/tests/js/tests/context-methods.js b/sdk/tests/js/tests/context-methods.js
new file mode 100644
index 0000000..f647646
--- /dev/null
+++ b/sdk/tests/js/tests/context-methods.js
@@ -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.");
+ }
+}