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

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

Issue 2477713003: Custom Elements: Check Definition in createElement, Create Customized Built-in Elements Sync (Closed)
Patch Set: V1 definition check in document::createElement Created 4 years, 1 month 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
Index: third_party/WebKit/LayoutTests/custom-elements/spec/create-element.html
diff --git a/third_party/WebKit/LayoutTests/custom-elements/spec/create-element.html b/third_party/WebKit/LayoutTests/custom-elements/spec/create-element.html
new file mode 100644
index 0000000000000000000000000000000000000000..abb31fb5a8b05d49ca41653d1f27ef00a733d061
--- /dev/null
+++ b/third_party/WebKit/LayoutTests/custom-elements/spec/create-element.html
@@ -0,0 +1,86 @@
+<!DOCTYPE html>
+<title>Custom Elements: Create an element when definition is non-null and synchronous flag set</title>
+<script src="../../resources/testharness.js"></script>
+<script src="../../resources/testharnessreport.js"></script>
+<script src="resources/custom-elements-helpers.js"></script>
+<body>
+<script>
+'use strict';
+
+// https://dom.spec.whatwg.org/#dom-document-createelement
+// 1. If localName does not match the Name production, then throw an InvalidCharacterError
+// 2. If context object is an HTML document, let localName be converted to ASCII lowercase
+// 5. If 'is' is non-null and definition can't be found, then throw a NotFoundError
+// 6. If 'is' is non-null, then set is attribute to 'is'
+
+function setup(w) {
+ class A extends w.HTMLElement {
+ constructor() {
dominicc (has gone to gerrit) 2016/11/15 07:39:53 There's no need to write super-only constructors l
+ super();
+ }
+ }
+ w.customElements.define('a-a', A);
+
+ class B extends w.HTMLDivElement {
+ constructor() {
+ super();
+ }
+ }
+ w.customElements.define('b-b', B, {extends: 'div'});
+}
+
+test_with_window((w) => {
+ setup(w);
dominicc (has gone to gerrit) 2016/11/15 07:39:53 Why do you need any custom elements for this test?
+ assert_throws_dom_exception(w, 'InvalidCharacterError', () => {
+ w.document.createElement('.invalid.name.');
+ });
+}, '1. If localName does not match the Name production, then throw an InvalidCharacterError');
+
+test_with_window((w) => {
+ class A extends w.HTMLElement {
+ constructor() {
+ super();
+ }
+ }
+ w.customElements.define('a-a', A);
+
+ class B extends w.HTMLDivElement {
+ constructor() {
+ super();
+ }
+ }
+ w.customElements.define('b-b', B, {extends: 'div'});
dominicc (has gone to gerrit) 2016/11/15 07:39:53 Why not use setup?
+
+ assert_equals(w.document.createElement('A-a').constructor, A);
+ assert_equals(w.document.createElement('div', {is: 'b-B'}).constructor, B);
+}, '2. If context object is an HTML document, let localName be converted to ASCII lowercase');
dominicc (has gone to gerrit) 2016/11/15 07:39:53 I don't think "is" is a local name. Consider split
+
+test_with_window((w) => {
+ setup(w);
+ assert_throws_dom_exception(w, 'NotFoundError', () => {
+ w.document.createElement('div', {is: 'a-a'});
+ });
dominicc (has gone to gerrit) 2016/11/15 07:39:53 These are good test cases. Add a third parameter
+ assert_throws_dom_exception(w, 'NotFoundError', () => {
+ w.document.createElement('button', {is: 'b-b'});
+ });
+ assert_throws_dom_exception(w, 'NotFoundError', () => {
+ w.document.createElement('button', {id: 'b-b'});
+ });
+ assert_throws_dom_exception(w, 'NotFoundError', () => {
+ w.document.createElement('div', {is: ''});
+ });
+ assert_throws_dom_exception(w, 'NotFoundError', () => {
+ w.document.createElement('div', {});
+ });
+}, '5. If \'is\' is non-null and definition can not be found, then throw a NotFoundError');
+
+test_with_window((w) => {
+ setup(w);
+ let a = w.document.createElement('a-a');
+ let b = w.document.createElement('div', {is : 'b-b'});
+ assert_equals(a.getAttribute('is'), null);
+ assert_equals(b.getAttribute('is'), 'b-b');
+}, '6. If \'is\' is non-null, then set is-attribute to \'is\'');
+
+</script>
+</body>

Powered by Google App Engine
This is Rietveld 408576698