Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 14 additions & 6 deletions sdk/tests/conformance/more/functions/readPixelsBadArgs.html
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,10 @@
<script type="application/javascript" src="../unit.js"></script>
<script type="application/javascript" src="../util.js"></script>
<script type="application/javascript" src="../../../js/webgl-test-utils.js"></script>
</head><body>
<canvas id="gl" width="16" height="16"></canvas>
<canvas id="c" width="128" height="128"></canvas>
<img id="i">
<script type="application/javascript">
var wtu = WebGLTestUtils;
var defaultImgUrl = "https://get.webgl.org/conformance-resources/opengl_logo.jpg";
Expand Down Expand Up @@ -92,12 +96,16 @@
}

Tests.endUnit = function(gl) {
}
};

wtu.setupImageForCrossOriginTest("#i", defaultImgUrl, localImgUrl, initTests);
(async function() {
const img = document.getElementById('i');
try {
await wtu.awaitOrTimeout(wtu.loadCrossOriginImage(img, defaultImgUrl, localImgUrl), 1000);
} catch (e) {
console.log(`Image setup failed (${e}), running tests anyway.`);
}
initTests();
})();
</script>
</head><body>
<canvas id="gl" width="16" height="16"></canvas>
<canvas id="c" width="128" height="128"></canvas>
<img id="i">
</body></html>
15 changes: 2 additions & 13 deletions sdk/tests/conformance/more/functions/texImage2DHTML.html
Original file line number Diff line number Diff line change
Expand Up @@ -133,21 +133,10 @@
Tests.endUnit = function(gl) {
};

async function setupNonSOPImage() {
const img = document.getElementById('i2');
const url = wtu.chooseUrlForCrossOriginImage(defaultImgUrl, localImgUrl);
img.src = url;
await img.decode();
}

async function throwOnTimeout(ms) {
await wtu.awaitTimeout(ms);
throw 'timeout';
}

(async function() {
const img = document.getElementById('i2');
try {
await Promise.race([setupNonSOPImage(), throwOnTimeout(1000)]);
await wtu.awaitOrTimeout(wtu.loadCrossOriginImage(img, defaultImgUrl, localImgUrl), 1000);
} catch (e) {
console.log(`Image setup failed (${e}), running tests anyway.`);
}
Expand Down
17 changes: 3 additions & 14 deletions sdk/tests/conformance/more/functions/texSubImage2DHTML.html
Original file line number Diff line number Diff line change
Expand Up @@ -143,23 +143,12 @@
}

Tests.endUnit = function(gl) {
}

async function setupNonSOPImage() {
const img = document.getElementById('i2');
const url = wtu.chooseUrlForCrossOriginImage(defaultImgUrl, localImgUrl);
img.src = url;
await img.decode();
}

async function throwOnTimeout(ms) {
await wtu.awaitTimeout(ms);
throw 'timeout';
}
};

(async function() {
const img = document.getElementById('i2');
try {
await Promise.race([setupNonSOPImage(), throwOnTimeout(1000)]);
await wtu.awaitOrTimeout(wtu.loadCrossOriginImage(img, defaultImgUrl, localImgUrl), 1000);
} catch (e) {
console.log(`Image setup failed (${e}), running tests anyway.`);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,12 @@
<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>
</head>
<body>
<div id="description"></div>
<div id="console"></div>
<canvas id="canvas"></canvas>
<img id="img" style="display:none;">
<script>
"use strict";
var wtu = WebGLTestUtils;
Expand All @@ -33,7 +39,7 @@
var imgDomain;
var pageDomain;

function imageLoaded() {
function imageLoaded(img) {
description("This test ensures WebGL implementations for OffscreenCanvas follow proper same-origin restrictions.");

if (!window.OffscreenCanvas) {
Expand All @@ -42,8 +48,6 @@
return;
}

var img = this;

assertMsg(img.width > 0 && img.height > 0, "img was loaded");
imgDomain = wtu.getBaseDomain(wtu.getHost(img.src));
pageDomain = wtu.getBaseDomain(window.location.host);
Expand Down Expand Up @@ -105,13 +109,15 @@
finishTest();
}

wtu.setupImageForCrossOriginTest("#img", defaultImgUrl, localImgUrl, imageLoaded);
(async function() {
const img = document.getElementById('img');
try {
await wtu.awaitOrTimeout(wtu.loadCrossOriginImage(img, defaultImgUrl, localImgUrl), 1000);
} catch (e) {
console.log(`Image setup failed (${e}), running tests anyway.`);
}
imageLoaded(img);
})();
</script>
</head>
<body>
<div id="description"></div>
<div id="console"></div>
<canvas id="canvas"></canvas>
<img id="img" style="display:none;">
</body>
</html>
27 changes: 17 additions & 10 deletions sdk/tests/conformance/textures/misc/origin-clean-conformance.html
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,13 @@
<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>
</head>
<body>
<div id="description"></div>
<div id="console"></div>
<canvas id="canvas1"></canvas>
<canvas id="canvas2"></canvas>
<img id="img" style="display:none;">
<script>
"use strict";
var wtu = WebGLTestUtils;
Expand All @@ -34,9 +41,8 @@
var pageDomain;
var successfullyParsed;

function imageLoaded() {
function imageLoaded(img) {
description("This test ensures WebGL implementations follow proper same-origin restrictions.");
var img = this;

assertMsg(img.width > 0 && img.height > 0, "img was loaded");
imgDomain = wtu.getBaseDomain(wtu.getHost(img.src));
Expand Down Expand Up @@ -115,14 +121,15 @@
notifyFinishedToHarness();
}

wtu.setupImageForCrossOriginTest("#img", defaultImgUrl, localImgUrl, imageLoaded);
(async function() {
const img = document.getElementById('img');
try {
await wtu.awaitOrTimeout(wtu.loadCrossOriginImage(img, defaultImgUrl, localImgUrl), 1000);
} catch (e) {
console.log(`Image setup failed (${e}), running tests anyway.`);
}
imageLoaded(img);
})();
</script>
</head>
<body>
<div id="description"></div>
<div id="console"></div>
<canvas id="canvas1"></canvas>
<canvas id="canvas2"></canvas>
<img id="img" style="display:none;">
</body>
</html>
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,12 @@
<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>
</head>
<body>
<div id="description"></div>
<div id="console"></div>
<canvas id="canvas"></canvas>
<img id="img" style="display:none;">
<script>
"use strict";
var wtu = WebGLTestUtils;
Expand All @@ -33,7 +39,7 @@
var imgDomain;
var pageDomain;

function imageLoaded() {
function imageLoaded(img) {
description("This test ensures WebGL2 implementations for OffscreenCanvas follow proper same-origin restrictions.");

if (!window.OffscreenCanvas) {
Expand All @@ -42,8 +48,6 @@
return;
}

var img = this;

assertMsg(img.width > 0 && img.height > 0, "img was loaded");
imgDomain = wtu.getBaseDomain(wtu.getHost(img.src));
pageDomain = wtu.getBaseDomain(window.location.host);
Expand Down Expand Up @@ -126,13 +130,15 @@
finishTest();
}

wtu.setupImageForCrossOriginTest("#img", defaultImgUrl, localImgUrl, imageLoaded);
(async function() {
const img = document.getElementById('img');
try {
await wtu.awaitOrTimeout(wtu.loadCrossOriginImage(img, defaultImgUrl, localImgUrl), 1000);
} catch (e) {
console.log(`Image setup failed (${e}), running tests anyway.`);
}
imageLoaded(img);
})();
</script>
</head>
<body>
<div id="description"></div>
<div id="console"></div>
<canvas id="canvas"></canvas>
<img id="img" style="display:none;">
</body>
</html>
44 changes: 25 additions & 19 deletions sdk/tests/js/webgl-test-utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -3194,25 +3194,22 @@ var getRelativePath = function(path) {
return relparts.join("/");
}

function chooseUrlForCrossOriginImage(imgUrl, localUrl) {
if (runningOnLocalhost())
return getLocalCrossOrigin() + getRelativePath(localUrl);

return img.src = getUrlOptions().imgUrl || imgUrl;
}

var setupImageForCrossOriginTest = function(img, imgUrl, localUrl, callback) {
window.addEventListener("load", function() {
if (typeof(img) == "string")
img = document.querySelector(img);
if (!img)
img = new Image();
async function loadCrossOriginImage(img, webUrl, localUrl) {
img.src = getUrlOptions().imgUrl || webUrl;
try {
console.log('[loadCrossOriginImage]', 'trying', img.src);
await img.decode();
return;
} catch {}

img.addEventListener("load", callback, false);
img.addEventListener("error", callback, false);
if (runningOnLocalhost()) {
img.src = getLocalCrossOrigin() + getRelativePath(localUrl);
console.log('[loadCrossOriginImage]', ' trying', img.src);
await img.decode();
return;
}

img.src = chooseUrlForCrossOriginImage(imgUrl, localUrl);
}, false);
throw 'createCrossOriginImage failed';
}

/**
Expand Down Expand Up @@ -3357,6 +3354,15 @@ async function awaitTimeout(ms) {
});
}

async function awaitOrTimeout(promise, timeout_ms) {
async function throwOnTimeout(ms) {
await awaitTimeout(ms);
throw 'timeout';
}

await Promise.race([promise, throwOnTimeout(timeout_ms)]);
}

var API = {
addShaderSource: addShaderSource,
addShaderSources: addShaderSources,
Expand Down Expand Up @@ -3412,6 +3418,7 @@ var API = {
insertImage: insertImage,
isWebGL2: isWebGL2,
linkProgram: linkProgram,
loadCrossOriginImage: loadCrossOriginImage,
loadImageAsync: loadImageAsync,
loadImagesAsync: loadImagesAsync,
loadProgram: loadProgram,
Expand Down Expand Up @@ -3484,8 +3491,7 @@ var API = {
runningOnLocalhost: runningOnLocalhost,
getLocalCrossOrigin: getLocalCrossOrigin,
getRelativePath: getRelativePath,
chooseUrlForCrossOriginImage: chooseUrlForCrossOriginImage,
setupImageForCrossOriginTest: setupImageForCrossOriginTest,
awaitOrTimeout: awaitOrTimeout,
awaitTimeout: awaitTimeout,

none: false
Expand Down