Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(100)

Unified Diff: third_party/WebKit/LayoutTests/custom-elements/spec/construct.html

Issue 2320553002: Custom Elements: HTMLElement constructor tests (Closed)
Patch Set: wraping up long stringl literal Created 4 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | third_party/WebKit/LayoutTests/custom-elements/spec/define-element.html » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: third_party/WebKit/LayoutTests/custom-elements/spec/construct.html
diff --git a/third_party/WebKit/LayoutTests/custom-elements/spec/construct.html b/third_party/WebKit/LayoutTests/custom-elements/spec/construct.html
index 18a7f79884e7d286444dc8fade2b131305fc5363..d8396829b51388a2adc9ea987b22eb15271ab25d 100644
--- a/third_party/WebKit/LayoutTests/custom-elements/spec/construct.html
+++ b/third_party/WebKit/LayoutTests/custom-elements/spec/construct.html
@@ -58,6 +58,7 @@ test_with_window((w) => {
assert_equals(num_constructor_invocations,
1,
'the constructor should have been invoked once');
+ assert_true(e.matches(':defined'), 'custom element constructed with new should be "custom"');
}, 'Custom element constructor, construct');
test_with_window((w) => {
@@ -74,4 +75,76 @@ test_with_window((w) => {
}, 'constructing a custom element with a non-object new.target should ' +
'throw a TypeError');
}, 'Custom element constructor, construct invalid new.target');
+
+test_with_window((w) => {
+ w.customElements.define('a-a', w.HTMLButtonElement);
+ assert_throws(TypeError.prototype, () => {
+ w.document.createElement('a-a');
+ }, 'If NewTarget is equal to active function object, TypeError should be thrown');
+}, 'Custom element constructor, NewTarget is equal to active function object');
+
+test_with_window((w) => {
+ w.customElements.define('a-a', class extends w.HTMLButtonElement {} );
+ assert_throws(TypeError.prototype, () => {
+ w.document.createElement('a-a');
+ }, 'If NewTarget is equal to active function object, TypeError should be thrown');
+}, 'Custom element constructor, active function object is not equal to HTMLElement');
+
+test_with_window((w) => {
+ let flag = true;
+ class A extends w.HTMLElement {
+ constructor() {
+ if (flag) {
+ flag = false;
+ new A();
+ }
+ super();
+ }
+ }
+ w.customElements.define('a-a', A);
+ let e = new A();
+ assert_true(e.matches(':defined'),
+ 'constructing a custom element with new should not throw InvalidStateError ' +
+ 'and should return a "custom" element');
+}, 'Already constructed marker, construct with new');
+
+test_with_window((w) => {
+ let flag = true;
+ class A extends w.HTMLElement {
+ constructor() {
+ if (flag) {
+ flag = false;
+ new A();
+ }
+ super();
+ }
+ }
+ w.customElements.define('a-a', A);
+ assert_throws_dom_exception(w, 'INVALID_STATE_ERR', () => {
+ w.document.createElement('a-a');
+ }, 'Creating an element that is already constructed marker should throw InvalidStateError');
+}, 'Already constructed marker, create element');
+
+test_with_window((w) => {
+ let errors = [];
+ w.onerror = function (event, source, lineno, colno, error) {
+ errors.push(error.name);
+ return true;
+ };
+ let flag = true;
+ let e = w.document.createElement('a-a');
+ class A extends w.HTMLElement {
+ constructor() {
+ if (flag) {
+ flag = false;
+ new A();
+ }
+ super();
+ }
+ }
+ w.customElements.define('a-a', A);
+ w.document.body.appendChild(e);
+ assert_array_equals(errors, ['InvalidStateError'], 'Upgrading an element ' +
+ 'that is already constructed marker should throw InvalidStateError');
+}, 'Already constructed marker, upgrade element');
</script>
« no previous file with comments | « no previous file | third_party/WebKit/LayoutTests/custom-elements/spec/define-element.html » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698