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

Side by Side Diff: third_party/WebKit/LayoutTests/imported/web-platform-tests/shadow-dom/Element-interface-attachShadow.html

Issue 1993513002: Move the shadow-dom directory from web-platform-tests/ to wpt/. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Rebased Created 4 years, 7 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 unified diff | Download patch
OLDNEW
(Empty)
1 <!DOCTYPE html>
2 <html>
3 <head>
4 <title>Shadow DOM: Attaching a ShadowRoot</title>
5 <meta name="author" title="Ryosuke Niwa" href="mailto:rniwa@webkit.org">
6 <meta name="assert" content="Element.prototype.attachShadow should create an ins tance of ShadowRoot">
7 <link rel="help" href="https://w3c.github.io/webcomponents/spec/shadow/#widl-Ele ment-attachShadow-ShadowRoot-ShadowRootInit-shadowRootInitDict">
8 <script src="../../../resources/testharness.js"></script>
9 <script src="../../../resources/testharnessreport.js"></script>
10 </head>
11 <body>
12 <div id="log"></div>
13 <script>
14
15 test(function () {
16 assert_true('attachShadow' in Element.prototype, 'Element.prototype.attachSh adow must exist');
17 assert_equals(typeof(document.createElement('div').attachShadow), 'function' , 'An instance of div must have attachShadow which is a function');
18 }, 'Check the existence of Element.attachShadow');
19
20 test(function () {
21 assert_false('attachShadow' in Node.prototype, 'Node.prototype.attachShadow must not exist');
22 assert_false('attachShadow' in CharacterData.prototype, 'CharacterData.proto type.attachShadow must not exist');
23 assert_false('attachShadow' in Comment.prototype, 'Comment.prototype.attachS hadow must not exist');
24 assert_equals(typeof(document.createComment('').attachShadow), 'undefined', 'An instance of comment must not have attachShadow');
25 assert_false('attachShadow' in Document.prototype, 'Document.prototype.attac hShadow must not exist');
26 assert_equals(typeof(document.attachShadow), 'undefined', 'An instance of do cument must not have attachShadow which is a function');
27 assert_false('attachShadow' in DocumentFragment.prototype, 'DocumentFragment .prototype.attachShadow must not exist');
28 assert_equals(typeof((new DOMParser()).parseFromString('', 'text/html').atta chShadow), 'undefined', 'An instance of document must not have attachShadow whic h is a function');
29 assert_false('attachShadow' in Text.prototype, 'Text.prototype.attachShadow must not exist');
30 assert_equals(typeof(document.createTextNode('').attachShadow), 'undefined', 'An instance of text node must not have attachShadow');
31 }, 'Nodes other than Element should not have attachShadow');
32
33 test(function () {
34 assert_throws({'name': 'TypeError'}, function () {
35 document.createElement('div').attachShadow({})
36 }, 'attachShadow must throw a TypeError when mode is omitted');
37
38 assert_throws({'name': 'TypeError'}, function () {
39 document.createElement('div').attachShadow({mode: true})
40 }, 'attachShadow must throw a TypeError when mode is a boolean');
41
42 assert_throws({'name': 'TypeError'}, function () {
43 document.createElement('div').attachShadow({mode: 1})
44 }, 'attachShadow must throw a TypeError when mode is 1');
45 }, 'Element.attachShadow must throw a TypeError if mode is not "open" or "closed "');
46
47 test(function () {
48 assert_true(document.createElement('div').attachShadow({mode: "open"}) insta nceof ShadowRoot,
49 'attachShadow({mode: "open"}) should create an instance of ShadowRoot');
50 assert_true(document.createElement('div').attachShadow({mode: "closed"}) ins tanceof ShadowRoot,
51 'attachShadow({mode: "closed"}) should create an instance of ShadowRoot' );
52 }, 'Element.attachShadow must create an instance of ShadowRoot');
53
54 test(function () {
55 assert_throws({'name': 'InvalidStateError'}, function () {
56 var div = document.createElement('div');
57 div.attachShadow({mode: "open"});
58 div.attachShadow({mode: "open"});
59 }, 'Calling attachShadow({mode: "open"}) twice on the same element must thro w');
60
61 assert_throws({'name': 'InvalidStateError'}, function () {
62 var div = document.createElement('div');
63 div.attachShadow({mode: "closed"});
64 div.attachShadow({mode: "closed"});
65 }, 'Calling attachShadow({mode: "closed"}) twice on the same element must th row');
66
67 assert_throws({'name': 'InvalidStateError'}, function () {
68 var div = document.createElement('div');
69 div.attachShadow({mode: "open"});
70 div.attachShadow({mode: "closed"});
71 }, 'Calling attachShadow({mode: "closed"}) after attachShadow({mode: "open"} ) on the same element must throw');
72
73 assert_throws({'name': 'InvalidStateError'}, function () {
74 var div = document.createElement('div');
75 div.attachShadow({mode: "closed"});
76 div.attachShadow({mode: "open"});
77 }, 'Calling attachShadow({mode: "open"}) after attachShadow({mode: "closed"} ) on the same element must throw');
78 }, 'Element.attachShadow must throw a InvalidStateError if the context object al ready hosts a shadow tree');
79
80 test(function () {
81 for (var elementName of ['button', 'details', 'input', 'marquee', 'meter', ' progress', 'select', 'textarea', 'keygen']) {
82 assert_throws({'name': 'NotSupportedError'}, function () {
83 document.createElement(elementName).attachShadow({mode: "open"});
84 }, 'Calling attachShadow({mode: "open"}) on ' + elementName + ' element must throw');
85
86 assert_throws({'name': 'NotSupportedError'}, function () {
87 document.createElement(elementName).attachShadow({mode: "closed"});
88 }, 'Calling attachShadow({mode: "closed"}) on ' + elementName + ' elemen t must throw');
89 }
90 }, 'Element.attachShadow must throw a NotSupportedError for button, details, inp ut, marquee, meter, progress, select, textarea, and keygen elements');
91
92 </script>
93 </body>
94 </html>
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698