Skip to content

Commit

Permalink
Move CustomElementRegistry.getName() tests to a tentative test file
Browse files Browse the repository at this point in the history
The spec change [1] hasn't landed yet, so the tests can only be
tentative.

This also prevents affecting interop2023 [2].

[1] whatwg/html#9195
[2] web-platform-tests/interop#358

Bug: 1435389
Change-Id: I1e35d7f06bcf2b005304cdc182a67cfa69b74de1
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/4621660
Auto-Submit: Xiaocheng Hu <[email protected]>
Reviewed-by: Mason Freed <[email protected]>
Commit-Queue: Xiaocheng Hu <[email protected]>
Cr-Commit-Position: refs/heads/main@{#1160209}
  • Loading branch information
xiaochengh authored and chromium-wpt-export-bot committed Jun 20, 2023
1 parent 5cd3700 commit ade90e9
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 39 deletions.
46 changes: 46 additions & 0 deletions custom-elements/CustomElementRegistry-getName.tentative.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
<!DOCTYPE html>
<title>Custom Elements: CustomElementRegistry.getName function</title>
<meta name="author" title="Keith Cirkel" href="mailto:[email protected]">
<meta name="assert" content="CustomElementRegistry.getName function exists">
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<script>
test(function () {
assert_equals(customElements.getName(class extends HTMLElement {}), null);
}, 'customElements.getName must return null when the registry does not contain an entry with the given constructor');

test(function () {
assert_throws_js(TypeError, function () { customElements.getName(undefined); },
'customElements.getName must throw a TypeError when the element interface is undefined');
assert_throws_js(TypeError, function () { customElements.getName(null); },
'customElements.getName must throw a TypeError when the element interface is null');
assert_throws_js(TypeError, function () { customElements.getName('foo-bar'); },
'customElements.getName must throw a TypeError when the element interface is a string');
assert_throws_js(TypeError, function () { customElements.getName(1); },
'customElements.getName must throw a TypeError when the element interface is a number');
assert_throws_js(TypeError, function () { customElements.getName({}); },
'customElements.getName must throw a TypeError when the element interface is an object');
assert_throws_js(TypeError, function () { customElements.getName([]) },
'customElements.getName must throw a TypeError when the element interface is an array');
}, 'customElements.getName must throw when the element interface is not a constructor');

test(function () {
class OtherExistingCustomElement extends HTMLElement {};
class SecondExistingCustomElement extends HTMLElement {};
assert_throws_js(TypeError, function () { customElements.getName(customElements.getName(OtherExistingCustomElement)); },
'customElements.getName must throw a TypeError when the element interface is undefined');
customElements.define('other-existing-custom-element', OtherExistingCustomElement);
customElements.define('second-existing-custom-element', SecondExistingCustomElement);
assert_equals(customElements.getName(OtherExistingCustomElement), 'other-existing-custom-element');
assert_equals(customElements.getName(SecondExistingCustomElement), 'second-existing-custom-element');
}, 'customElements.getName returns the name of the entry with the given constructor when there is a matching entry.');

test(function () {
class ButtonCustomBuiltInElement extends HTMLButtonElement {};
class InputCustomBuiltInElement extends HTMLInputElement {};
customElements.define('button-custom-built-in-element', ButtonCustomBuiltInElement, { extends: 'button' });
customElements.define('input-custom-built-in-element', InputCustomBuiltInElement, { extends: 'input' });
assert_equals(customElements.getName(ButtonCustomBuiltInElement), 'button-custom-built-in-element');
assert_equals(customElements.getName(InputCustomBuiltInElement), 'input-custom-built-in-element');
}, 'customElements.getName returns the name of the entry with the given customized built in constructor when there is a matching entry.');
</script>
39 changes: 0 additions & 39 deletions custom-elements/CustomElementRegistry.html
Original file line number Diff line number Diff line change
Expand Up @@ -623,45 +623,6 @@
assert_equals(customElements.get('existing-custom-element'), ExistingCustomElement);
}, 'customElements.get return the constructor of the entry with the given name when there is a matching entry.');

test(function () {
assert_equals(customElements.getName(class extends HTMLElement {}), null);
}, 'customElements.getName must return null when the registry does not contain an entry with the given constructor');

test(function () {
assert_throws_js(TypeError, function () { customElements.getName(undefined); },
'customElements.getName must throw a TypeError when the element interface is undefined');
assert_throws_js(TypeError, function () { customElements.getName(null); },
'customElements.getName must throw a TypeError when the element interface is null');
assert_throws_js(TypeError, function () { customElements.getName('foo-bar'); },
'customElements.getName must throw a TypeError when the element interface is a string');
assert_throws_js(TypeError, function () { customElements.getName(1); },
'customElements.getName must throw a TypeError when the element interface is a number');
assert_throws_js(TypeError, function () { customElements.getName({}); },
'customElements.getName must throw a TypeError when the element interface is an object');
assert_throws_js(TypeError, function () { customElements.getName([]) },
'customElements.getName must throw a TypeError when the element interface is an array');
}, 'customElements.getName must throw when the element interface is not a constructor');

test(function () {
class OtherExistingCustomElement extends HTMLElement {};
class SecondExistingCustomElement extends HTMLElement {};
assert_throws_js(TypeError, function () { customElements.getName(customElements.getName(OtherExistingCustomElement)); },
'customElements.getName must throw a TypeError when the element interface is undefined');
customElements.define('other-existing-custom-element', OtherExistingCustomElement);
customElements.define('second-existing-custom-element', SecondExistingCustomElement);
assert_equals(customElements.getName(OtherExistingCustomElement), 'other-existing-custom-element');
assert_equals(customElements.getName(SecondExistingCustomElement), 'second-existing-custom-element');
}, 'customElements.getName returns the name of the entry with the given constructor when there is a matching entry.');

test(function () {
class ButtonCustomBuiltInElement extends HTMLButtonElement {};
class InputCustomBuiltInElement extends HTMLInputElement {};
customElements.define('button-custom-built-in-element', ButtonCustomBuiltInElement, { extends: 'button' });
customElements.define('input-custom-built-in-element', InputCustomBuiltInElement, { extends: 'input' });
assert_equals(customElements.getName(ButtonCustomBuiltInElement), 'button-custom-built-in-element');
assert_equals(customElements.getName(InputCustomBuiltInElement), 'input-custom-built-in-element');
}, 'customElements.getName returns the name of the entry with the given customized built in constructor when there is a matching entry.');

test(function () {
assert_true(customElements.whenDefined('some-name') instanceof Promise);
}, 'customElements.whenDefined must return a promise for a valid custom element name');
Expand Down

0 comments on commit ade90e9

Please sign in to comment.