diff options
Diffstat (limited to 'dom/origin-trials/tests')
11 files changed, 226 insertions, 0 deletions
diff --git a/dom/origin-trials/tests/mochitest/common.js b/dom/origin-trials/tests/mochitest/common.js new file mode 100644 index 0000000000..a38a975ea7 --- /dev/null +++ b/dom/origin-trials/tests/mochitest/common.js @@ -0,0 +1,114 @@ +/* import-globals-from ../../../../testing/mochitest/tests/SimpleTest/SimpleTest.js */ + +// This would be a bit nicer with `self`, but Worklet doesn't have that, so +// `globalThis` it is, see https://github.com/whatwg/html/issues/7696 +function workerReply(port) { + port.postMessage({ + testTrialInterfaceExposed: !!globalThis.TestTrialInterface, + }); +} + +if ( + globalThis.SharedWorkerGlobalScope && + globalThis instanceof globalThis.SharedWorkerGlobalScope +) { + globalThis.addEventListener("connect", function (e) { + const port = e.ports[0]; + workerReply(port); + }); +} else if ( + globalThis.WorkerGlobalScope && + globalThis instanceof globalThis.WorkerGlobalScope +) { + workerReply(globalThis); +} else if ( + globalThis.WorkletGlobalScope && + globalThis instanceof globalThis.WorkletGlobalScope +) { + class Processor extends AudioWorkletProcessor { + constructor() { + super(); + this.port.start(); + workerReply(this.port); + } + + process(inputs, outputs, parameters) { + // Do nothing, output silence + return true; + } + } + registerProcessor("test-processor", Processor); +} + +function assertTestTrialActive(shouldBeActive) { + add_task(async function () { + info("Main thread test: " + document.URL); + is( + !!navigator.testTrialGatedAttribute, + shouldBeActive, + "Should match active status for Navigator.testTrialControlledAttribute" + ); + is( + !!self.TestTrialInterface, + shouldBeActive, + "Should match active status for TestTrialInterface" + ); + if (shouldBeActive) { + ok( + new self.TestTrialInterface(), + "Should be able to construct interface" + ); + } + + function promiseWorkerWorkletMessage(target, context) { + info(`promiseWorkerWorkletMessage(${context})`); + return new Promise(resolve => { + target.addEventListener( + "message", + function (e) { + is( + e.data.testTrialInterfaceExposed, + shouldBeActive, + "Should work as expected in " + context + ); + info(`got ${context} message`); + resolve(); + }, + { once: true } + ); + }); + } + + { + info("Worker test"); + const worker = new Worker("common.js"); + await promiseWorkerWorkletMessage(worker, "worker"); + worker.terminate(); + } + + { + info("SharedWorker test"); + // We want a unique worker per page since the trial state depends on the + // creator document. + const worker = new SharedWorker("common.js", document.URL); + const promise = promiseWorkerWorkletMessage(worker.port, "shared worker"); + worker.port.start(); + await promise; + } + + { + info("AudioWorklet test"); + const audioContext = new AudioContext(); + await audioContext.audioWorklet.addModule("common.js"); + audioContext.resume(); + const workletNode = new AudioWorkletNode(audioContext, "test-processor"); + const promise = promiseWorkerWorkletMessage(workletNode.port, "worklet"); + workletNode.port.start(); + await promise; + await audioContext.close(); + } + + // FIXME(emilio): Add more tests. + // * Stuff hanging off Window or Document (bug 1757935). + }); +} diff --git a/dom/origin-trials/tests/mochitest/file_subdomain_bad_frame.html b/dom/origin-trials/tests/mochitest/file_subdomain_bad_frame.html new file mode 100644 index 0000000000..fe5dae7bc1 --- /dev/null +++ b/dom/origin-trials/tests/mochitest/file_subdomain_bad_frame.html @@ -0,0 +1,8 @@ +<!doctype html> +<!-- Created with: mktoken --origin 'https://example.com' --feature TestTrial --expiry '01 Jan 3000 01:00:00 +0100' --sign test-keys/test-ecdsa.pkcs8 --> +<meta http-equiv="origin-trial" content="A2BnUbfkkbKU8524UJACNw8UH6czqkmu+hkn9EhLesuleoBBPuthuTU8DCu7H80TgWmfCROkcZpBtXnEn7jYmhMAAABLeyJvcmlnaW4iOiJodHRwczovL2V4YW1wbGUuY29tIiwiZmVhdHVyZSI6IlRlc3RUcmlhbCIsImV4cGlyeSI6MzI1MDM2ODAwMDB9"> +<script> + parent.postMessage({ + testTrialInterfaceExposed: !!globalThis.TestTrialInterface, + }, "https://example.com"); +</script> diff --git a/dom/origin-trials/tests/mochitest/file_subdomain_good_frame.html b/dom/origin-trials/tests/mochitest/file_subdomain_good_frame.html new file mode 100644 index 0000000000..a5cbb13db6 --- /dev/null +++ b/dom/origin-trials/tests/mochitest/file_subdomain_good_frame.html @@ -0,0 +1,8 @@ +<!doctype html> +<!-- Created with: mktoken --origin 'https://example.com' --subdomain --feature TestTrial --expiry '01 Jan 3000 01:00:00 +0100' --sign test-keys/test-ecdsa.pkcs8 --> +<meta http-equiv="origin-trial" content="A/RnDeJo/c3P5otcVhRW7z00y2KtbiAH18HjGpZiBBdkvlFlafDSitJMb3SXavmnz7HXJyljoPsoa7nLN3XJLNYAAABeeyJvcmlnaW4iOiJodHRwczovL2V4YW1wbGUuY29tIiwiZmVhdHVyZSI6IlRlc3RUcmlhbCIsImV4cGlyeSI6MzI1MDM2ODAwMDAsImlzU3ViZG9tYWluIjp0cnVlfQ=="> +<script> + parent.postMessage({ + testTrialInterfaceExposed: !!globalThis.TestTrialInterface, + }, "https://example.com"); +</script> diff --git a/dom/origin-trials/tests/mochitest/mochitest.ini b/dom/origin-trials/tests/mochitest/mochitest.ini new file mode 100644 index 0000000000..c05d2cc55d --- /dev/null +++ b/dom/origin-trials/tests/mochitest/mochitest.ini @@ -0,0 +1,26 @@ +[DEFAULT] +prefs = + dom.origin-trials.enabled=true + dom.origin-trials.test-key.enabled=true + browser.tabs.remote.coep.credentialless=false +support-files = + test_header_simple.html^headers^ + common.js +# * Test interfaces only exposed on DEBUG builds. +# * xorigin tests run in example.org rather than example.com, so token +# verification fails, expectedly. +skip-if = !debug || xorigin +# AudioWorklet requires secure context +scheme = https + +[test_meta_simple.html] +[test_header_simple.html] +[test_trial_hidden.html] +[test_expired_token.html] +[test_wrong_origin.html] +[test_subdomain.html] +support-files = + file_subdomain_good_frame.html + file_subdomain_bad_frame.html +skip-if = + http3 diff --git a/dom/origin-trials/tests/mochitest/test_expired_token.html b/dom/origin-trials/tests/mochitest/test_expired_token.html new file mode 100644 index 0000000000..48bd4d1215 --- /dev/null +++ b/dom/origin-trials/tests/mochitest/test_expired_token.html @@ -0,0 +1,8 @@ +<!doctype html> +<!-- Created with: mktoken --origin 'https://example.com' --feature TestTrial --expiry '01 Jan 2000 01:00:00 +0100' --sign test-keys/test-ecdsa.pkcs8 --> +<meta http-equiv="origin-trial" content="A41+wSMhPQeR9B+AofdiFzheyZVF+gP4ubTNzrt6v8Qcjv68j1eINNFCxVe5/vdy4cO9dGDkwd9eizsib70RgAQAAABJeyJvcmlnaW4iOiJodHRwczovL2V4YW1wbGUuY29tIiwiZmVhdHVyZSI6IlRlc3RUcmlhbCIsImV4cGlyeSI6OTQ2Njg0ODAwfQ=="> +<script src="/tests/SimpleTest/SimpleTest.js"></script> +<script src="common.js"></script> +<script> + assertTestTrialActive(false); +</script> diff --git a/dom/origin-trials/tests/mochitest/test_header_simple.html b/dom/origin-trials/tests/mochitest/test_header_simple.html new file mode 100644 index 0000000000..2c378d3524 --- /dev/null +++ b/dom/origin-trials/tests/mochitest/test_header_simple.html @@ -0,0 +1,6 @@ +<!doctype html> +<script src="/tests/SimpleTest/SimpleTest.js"></script> +<script src="common.js"></script> +<script> + assertTestTrialActive(true); +</script> diff --git a/dom/origin-trials/tests/mochitest/test_header_simple.html^headers^ b/dom/origin-trials/tests/mochitest/test_header_simple.html^headers^ new file mode 100644 index 0000000000..2765b5bd11 --- /dev/null +++ b/dom/origin-trials/tests/mochitest/test_header_simple.html^headers^ @@ -0,0 +1 @@ +Origin-Trial: AyGdETIKWLLqe+chG57f74gZcjYSfbdYAapEq7DA49E6CmaYaPmaoXh/4tAe5XJJJdwwpFVal7hz/irC+Wvp1HgAAABLeyJvcmlnaW4iOiJodHRwczovL2V4YW1wbGUuY29tIiwiZmVhdHVyZSI6IlRlc3RUcmlhbCIsImV4cGlyeSI6MzI1MDM2ODAwMDB9 diff --git a/dom/origin-trials/tests/mochitest/test_meta_simple.html b/dom/origin-trials/tests/mochitest/test_meta_simple.html new file mode 100644 index 0000000000..8b853a8774 --- /dev/null +++ b/dom/origin-trials/tests/mochitest/test_meta_simple.html @@ -0,0 +1,13 @@ +<!doctype html> +<!-- Created with: mktoken --origin 'https://example.com' --feature TestTrial --expiry 'Wed, 01 Jan 3000 01:00:00 +0100' --sign test-keys/test-ecdsa.pkcs8 --> +<meta http-equiv="origin-trial" content="AyGdETIKWLLqe+chG57f74gZcjYSfbdYAapEq7DA49E6CmaYaPmaoXh/4tAe5XJJJdwwpFVal7hz/irC+Wvp1HgAAABLeyJvcmlnaW4iOiJodHRwczovL2V4YW1wbGUuY29tIiwiZmVhdHVyZSI6IlRlc3RUcmlhbCIsImV4cGlyeSI6MzI1MDM2ODAwMDB9"> +<!-- Created with: mktoken --origin 'https://example.com' --feature CoepCredentialless --expiry 'Wed, 01 Jan 3000 01:00:00 +0100' --sign test-keys/test-ecdsa.pkcs8 --> +<meta http-equiv="origin-trial" content="Az+DK2Kczk8Xz1cAlD+TkvPZmuM2uJZ2CFefbp2hLuCU9FbUqxWTyQ2tEYr50r0syKELcOZLAPaABw8aYTLHn5YAAABUeyJvcmlnaW4iOiJodHRwczovL2V4YW1wbGUuY29tIiwiZmVhdHVyZSI6IkNvZXBDcmVkZW50aWFsbGVzcyIsImV4cGlyeSI6MzI1MDM2ODAwMDB9"> +<script src="/tests/SimpleTest/SimpleTest.js"></script> +<script src="common.js"></script> +<script> + assertTestTrialActive(true); + add_task(function() { + ok(!!SpecialPowers.DOMWindowUtils.isCoepCredentialless(), "CoepCredentialless trial works."); + }); +</script> diff --git a/dom/origin-trials/tests/mochitest/test_subdomain.html b/dom/origin-trials/tests/mochitest/test_subdomain.html new file mode 100644 index 0000000000..3814e1e95b --- /dev/null +++ b/dom/origin-trials/tests/mochitest/test_subdomain.html @@ -0,0 +1,28 @@ +<!doctype html> +<script src="/tests/SimpleTest/SimpleTest.js"></script> +<iframe></iframe> +<script> + async function testFrame(file, expectEnabled) { + let reply = new Promise(resolve => { + window.addEventListener("message", function(e) { + resolve(e.data); + }, { once: true }); + }); + + let iframe = document.querySelector("iframe"); + let load = new Promise(resolve => { + iframe.addEventListener("load", resolve, { once: true }); + }); + + iframe.src = "https://www.example.com/" + location.pathname.replace("test_subdomain.html", file); + info("loading " + iframe.src); + await load; + let data = await reply; + is(data.testTrialInterfaceExposed, expectEnabled); + } + + add_task(async function test_subdomain() { + await testFrame("file_subdomain_good_frame.html", true); + await testFrame("file_subdomain_bad_frame.html", false); + }); +</script> diff --git a/dom/origin-trials/tests/mochitest/test_trial_hidden.html b/dom/origin-trials/tests/mochitest/test_trial_hidden.html new file mode 100644 index 0000000000..90f7f8da0a --- /dev/null +++ b/dom/origin-trials/tests/mochitest/test_trial_hidden.html @@ -0,0 +1,6 @@ +<!doctype html> +<script src="/tests/SimpleTest/SimpleTest.js"></script> +<script src="common.js"></script> +<script> + assertTestTrialActive(false); +</script> diff --git a/dom/origin-trials/tests/mochitest/test_wrong_origin.html b/dom/origin-trials/tests/mochitest/test_wrong_origin.html new file mode 100644 index 0000000000..adb3a0e900 --- /dev/null +++ b/dom/origin-trials/tests/mochitest/test_wrong_origin.html @@ -0,0 +1,8 @@ +<!doctype html> +<!-- Created with: mktoken --origin 'https://not-example.com' --feature TestTrial --expiry '01 Jan 3000 01:00:00 +0100' --sign test-keys/test-ecdsa.pkcs8 --> +<meta http-equiv="origin-trial" content="A1nUsa3CwtYj28syX2jYUogdrg+ZsjjNfAvmdg3SGybXxaJFbNq7i8AmY6Fo3OUe6Xvza3R0YYfaGTqM0TOU2OAAAABPeyJvcmlnaW4iOiJodHRwczovL25vdC1leGFtcGxlLmNvbSIsImZlYXR1cmUiOiJUZXN0VHJpYWwiLCJleHBpcnkiOjMyNTAzNjgwMDAwfQ=="> +<script src="/tests/SimpleTest/SimpleTest.js"></script> +<script src="common.js"></script> +<script> + assertTestTrialActive(false); +</script> |