3 Distributed under both the W3C Test Suite License [1] and the W3C
4 3-clause BSD License [2]. To contribute to a W3C Test Suite, see the
5 policies and contribution forms [3].
7 [1] http://www.w3.org/Consortium/Legal/2008/04-testsuite-license
8 [2] http://www.w3.org/Consortium/Legal/2008/03-bsd-license
9 [3] http://www.w3.org/2004/10/27-testcases
13 <title>Shadow DOM Test: A_06_00_02</title>
14 <link rel="author" title="Sergey G. Grekhov" href="mailto:sgrekhov@unipro.ru">
15 <link rel="help" href="http://www.w3.org/TR/2013/WD-shadow-dom-20130514/#styles">
16 <meta name="assert" content="Styles: CSS rules declared in an enclosing tree must be applied in a shadow tree if apply-author-styles flag is set to true for this tree">
17 <script src="../../../../resources/testharness.js"></script>
18 <script src="../../../../resources/testharnessreport.js"></script>
19 <script src="../testcommon.js"></script>
20 <link rel="stylesheet" href="../../../../resources/testharness.css">
25 //test apply-author-styles flag of ShadowRoot object
26 test(unit(function (ctx) {
28 var d = newRenderedHTMLDocument(ctx);
30 d.head.innerHTML = '<style>' +
36 var host = d.createElement('div');
37 d.body.appendChild(host);
39 //Shadow root to play with
40 var s = host.createShadowRoot();
41 s.applyAuthorStyles = true;
43 var div1 = d.createElement('div');
44 div1.innerHTML ='<span id="shd" class="invis">This is the shadow tree</span>';
47 //apply-author-styles flag is set to true. Invisible style should be applied
48 assert_equals(s.querySelector('#shd').offsetTop, 0,
49 'CSS styles declared in enclosing tree must be applied in a shadow tree ' +
50 'if the apply-author-styles flag is set to true');
53 }), 'A_06_00_02_T01');
56 //test apply-author-styles flag in a nested tree (set it)
57 test(unit(function (ctx) {
59 var d = newRenderedHTMLDocument(ctx);
61 d.head.innerHTML = '<style>' +
67 var host = d.createElement('div');
68 d.body.appendChild(host);
70 //Shadow root to play with
71 var s1 = host.createShadowRoot();
72 s1.applyAuthorStyles = true;
74 var div1 = d.createElement('div');
75 div1.innerHTML = '<span id="shd1" class="invis">This is an old shadow tree</span>';
79 var s2 = host.createShadowRoot();
80 s2.applyAuthorStyles = true;
81 var div1 = d.createElement('div');
82 div1.innerHTML = '<span id="shd2" class="invis">This is a young shadow tree</span>' +
83 '<shadow><span id="shd3" class="invis">This is the shadow tree fallback content</span></shadow>';
87 //apply-author-styles flag is set to true. Invisible style should be applied
88 //shd1 and shd2 should be invisible. sh3 invisible too because the tree should be active
89 assert_equals(s1.querySelector('#shd1').offsetTop, 0,
90 'Point 1: CSS styles declared in enclosing tree must be applied in a shadow tree ' +
91 'if the apply-author-styles flag is set to true');
92 assert_equals(s2.querySelector('#shd2').offsetTop, 0,
93 'Point 2: CSS styles declared in enclosing tree must be applied in a shadow tree ' +
94 'if the apply-author-styles flag is set to true');
95 assert_equals(s2.querySelector('#shd3').offsetTop, 0,
96 'Fallback content shouldn\'t be rendered for active tree');
99 }), 'A_06_00_02_T02');
103 //test different apply-author-styles flag values in a nested young and old trees
104 test(unit(function (ctx) {
106 var d = newRenderedHTMLDocument(ctx);
108 d.head.innerHTML = '<style>' +
114 var host = d.createElement('div');
115 d.body.appendChild(host);
117 //Shadow root to play with
118 var s1 = host.createShadowRoot();
119 s1.applyAuthorStyles = true;
121 var div1 = d.createElement('div');
122 div1.innerHTML = '<span id="shd1" class="invis">This is an old shadow tree</span>';
123 s1.appendChild(div1);
126 var s2 = host.createShadowRoot();
127 //applyAuthorStyles false by default
128 var div1 = d.createElement('div');
129 div1.innerHTML = '<span id="shd2" class="invis">This is a young shadow tree</span>' +
130 '<shadow><span id="shd3" class="invis">This is the shadow tree fallback content</span></shadow>';
131 s2.appendChild(div1);
134 //apply-author-styles flag is set to true. Invisible style should be applied
135 //shd1 and shd2 should be invisible. sh3 invisible too because the tree should be active
136 assert_equals(s1.querySelector('#shd1').offsetTop, 0,
137 'Point 1: CSS styles declared in enclosing tree must be applied in a shadow tree ' +
138 'if the apply-author-styles flag is set to true');
139 assert_true(s2.querySelector('#shd2').offsetTop > 0,
140 'Point 2: CSS styles declared in enclosing tree must be applied in a shadow tree ' +
141 'if the apply-author-styles flag is set to true');
142 assert_equals(s2.querySelector('#shd3').offsetTop, 0,
143 'Fallback content shouldn\'t be rendered for active tree');
146 }), 'A_06_00_02_T03');