<!DOCTYPE html>
<script src="../resources/testharness.js"></script>
<script src="../resources/testharnessreport.js"></script>
<script>
'use strict';
// The embedder may define its own elements via the CustomElementRegistry
// whose names are not valid custom element names. Ensure that script does
// not have access to such names.
var embedderName = 'embeddercustomelement';
window.internals.addEmbedderCustomElementName(embedderName);
test(() => {
assert_throws_dom('SyntaxError', () => {
window.customElements.define(
embedderName, class extends HTMLElement {});
});
}, 'customElements.define embedder element name');
test(() => {
assert_throws_dom('NotSupportedError', () => {
window.customElements.define(
'valid-name', class extends HTMLElement {}, {extends: embedderName});
});
}, 'customElements.define extending embedder element name');
promise_test((t) => {
var whenDefinedPromise = window.customElements.whenDefined(embedderName);
// With the correct behaviour, |whenDefinedPromise| will reject immediately
// and so the following will reject.
// With the incorrect behaviour, |whenDefinedPromise| will be forever
// pending. Rather than waiting for the test harness to time out, we'll
// have this resolve once we know that |whenDefinedPromise| hasn't rejected.
var rejectImmediatelyOrResolve =
Promise.race([whenDefinedPromise, Promise.resolve()]);
return promise_rejects_dom(t, 'SyntaxError', rejectImmediatelyOrResolve);
}, 'customElements.whenDefined embedder element name');
</script>