Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add ShadowRealm tests for isSecureContext #49365

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
6 changes: 6 additions & 0 deletions secure-contexts/shadow-realm-audio-worklet.any.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
// META: title=Test ShadowRealm isSecureContext in AudioWorklet
// META: global=shadowrealm-in-audioworklet

test(() => {
assert_false(isSecureContext, "isSecureContext should be false");
}, "ShadowRealm isSecureContext is false when created from an AudioWorklet");
6 changes: 6 additions & 0 deletions secure-contexts/shadow-realm-service-worker.any.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
// META: title=Test ShadowRealm isSecureContext in ServiceWorker
// META: global=shadowrealm-in-serviceworker

test(() => {
assert_true(isSecureContext, "isSecureContext should be true");
}, "ShadowRealm isSecureContext is true when created from a ServiceWorker");
41 changes: 41 additions & 0 deletions secure-contexts/shadow-realm.https.window.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
// META: title=Test ShadowRealm isSecureContext for HTTPS creator

test(() => {
const realm = new ShadowRealm();
assert_true(realm.evaluate("isSecureContext"), "isSecureContext should be true");
}, "ShadowRealm isSecureContext is true when created from a secure Window context");

test(() => {
const outerRealm = new ShadowRealm();
assert_true(outerRealm.evaluate(`
const innerRealm = new ShadowRealm();
innerRealm.evaluate('isSecureContext');
`), "isSecureContext should be true");
}, "ShadowRealm isSecureContext is true when created from a secure ShadowRealm context");

async_test(t => {
const worker = new Worker(`data:text/javascript,postMessage(new ShadowRealm().evaluate('isSecureContext'))`);
worker.onmessage = t.step_func_done(function(e) {
assert_true(e.data, "isSecureContext should be true");
});
worker.onerror = t.step_func_done(function(e) {
assert_unreached("isSecureContext should be supported");
});
}, "ShadowRealm isSecureContext is true when created from a secure Worker context");

async_test(t => {
const worker = new SharedWorker(
`data:text/javascript,addEventListener("connect", function (e) {
var port = e.ports[0];
port.start();
port.postMessage(new ShadowRealm().evaluate('isSecureContext'));
});`
);
worker.port.onmessage = t.step_func_done(function(e) {
assert_true(e.data, "isSecureContext should be true");
});
worker.port.onerror = t.step_func_done(function(e) {
assert_unreached("isSecureContext should be supported");
});
worker.port.start();
}, "ShadowRealm isSecureContext is true when created from a secure SharedWorker context");
41 changes: 41 additions & 0 deletions secure-contexts/shadow-realm.window.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
// META: title=Test ShadowRealm isSecureContext for HTTP creator

test(() => {
const realm = new ShadowRealm();
assert_false(realm.evaluate("isSecureContext"), "isSecureContext should be false");
}, "ShadowRealm isSecureContext is false when created from an insecure Window context");

test(() => {
const outerRealm = new ShadowRealm();
assert_false(outerRealm.evaluate(`
const innerRealm = new ShadowRealm();
innerRealm.evaluate('isSecureContext');
`), "isSecureContext should be false");
}, "ShadowRealm isSecureContext is false when created from an insecure ShadowRealm context");

async_test(t => {
const worker = new Worker(`data:text/javascript,postMessage(new ShadowRealm().evaluate('isSecureContext'))`);
worker.onmessage = t.step_func_done(function(e) {
assert_false(e.data, "isSecureContext should be false");
});
worker.onerror = t.step_func_done(function(e) {
assert_unreached("isSecureContext should be supported");
});
}, "ShadowRealm isSecureContext is false when created from an insecure Worker context");

async_test(t => {
const worker = new SharedWorker(
`data:text/javascript,addEventListener("connect", function (e) {
var port = e.ports[0];
port.start();
port.postMessage(new ShadowRealm().evaluate('isSecureContext'));
});`
);
worker.port.onmessage = t.step_func_done(function(e) {
assert_false(e.data, "isSecureContext should be false");
});
worker.port.onerror = t.step_func_done(function(e) {
assert_unreached("isSecureContext should be supported");
});
worker.port.start();
}, "ShadowRealm isSecureContext is false when created from an insecure SharedWorker context");