|
52 | 52 | </script> |
53 | 53 | </dom-module> |
54 | 54 |
|
| 55 | + <dom-module id="my-type-extension"> |
| 56 | + <template> |
| 57 | + <style> |
| 58 | + div { |
| 59 | + height: 50px; |
| 60 | + width: 50px; |
| 61 | + color: var(--text-color); |
| 62 | + } |
| 63 | + |
| 64 | + :host { |
| 65 | + display: block; |
| 66 | + background: blue; |
| 67 | + height: 100px; |
| 68 | + --text-color: white; |
| 69 | + } |
| 70 | + |
| 71 | + :host([foo]) { |
| 72 | + --text-color: black; |
| 73 | + } |
| 74 | + |
| 75 | + :host-context([bar]) { |
| 76 | + --text-color: lightgray; |
| 77 | + } |
| 78 | + </style> |
| 79 | + |
| 80 | + <div id="inner">text</div> |
| 81 | + </template> |
| 82 | + <script> |
| 83 | + HTMLImports.whenReady(function() { |
| 84 | + Polymer({ |
| 85 | + is: 'my-type-extension', |
| 86 | + extends: 'div' |
| 87 | + }); |
| 88 | + }); |
| 89 | + </script> |
| 90 | + </dom-module> |
| 91 | + |
55 | 92 | <test-fixture id="test"> |
56 | 93 | <template> |
57 | 94 | <div id="owner" bar> |
|
60 | 97 | </template> |
61 | 98 | </test-fixture> |
62 | 99 |
|
| 100 | + <test-fixture id="test-type-extension"> |
| 101 | + <template> |
| 102 | + <div id="owner" bar> |
| 103 | + <div is="my-type-extension" id="element" foo></div> |
| 104 | + </div> |
| 105 | + </template> |
| 106 | + </test-fixture> |
| 107 | + |
63 | 108 | <script> |
64 | 109 | suite('Style Cache', function() { |
65 | 110 |
|
|
74 | 119 | test(':host-context()', function() { |
75 | 120 | assert.equal(getComputedStyle(inner).color, 'rgb(211, 211, 211)'); |
76 | 121 | owner.removeAttribute('bar'); |
77 | | - Polymer.updateStyles(); |
| 122 | + element.updateStyles(); |
78 | 123 | assert.equal(getComputedStyle(inner).color, 'rgb(0, 0, 0)'); |
79 | 124 | }); |
80 | 125 |
|
81 | 126 | test(':host()', function() { |
82 | 127 | owner.removeAttribute('bar'); |
83 | | - Polymer.updateStyles(); |
| 128 | + element.updateStyles(); |
84 | 129 | assert.equal(getComputedStyle(inner).color, 'rgb(0, 0, 0)'); |
85 | 130 | element.removeAttribute('foo'); |
86 | | - Polymer.updateStyles(); |
| 131 | + element.updateStyles(); |
87 | 132 | assert.equal(getComputedStyle(inner).color, 'rgb(255, 255, 255)'); |
88 | 133 | }); |
89 | 134 | }); |
90 | 135 |
|
91 | 136 | suite('global cache', function() { |
92 | 137 | test(':host-context', function() { |
93 | 138 | owner.removeAttribute('bar') |
94 | | - Polymer.updateStyles(); |
| 139 | + element.updateStyles(); |
95 | 140 | assert.include(element.className, 'my-element-1'); |
96 | 141 | owner.setAttribute('bar', ''); |
97 | | - Polymer.updateStyles(); |
| 142 | + element.updateStyles(); |
98 | 143 | assert.include(element.className, 'my-element-0'); |
99 | 144 | }); |
100 | 145 |
|
101 | 146 | test(':host()', function() { |
102 | 147 | assert.include(element.className, 'my-element-0'); |
103 | 148 | owner.removeAttribute('bar'); |
104 | 149 | element.removeAttribute('foo'); |
105 | | - Polymer.updateStyles(); |
| 150 | + element.updateStyles(); |
106 | 151 | assert.include(element.className, 'my-element-2'); |
107 | 152 | element.setAttribute('foo', ''); |
108 | | - Polymer.updateStyles(); |
| 153 | + element.updateStyles(); |
109 | 154 | assert.include(element.className, 'my-element-1'); |
110 | 155 | }); |
111 | 156 | }); |
112 | 157 | }); |
| 158 | + |
| 159 | + suite('Style Cache Type Extension', function() { |
| 160 | + |
| 161 | + var owner, element, inner; |
| 162 | + setup(function() { |
| 163 | + owner = fixture('test-type-extension'); |
| 164 | + element = owner.querySelector('#element'); |
| 165 | + inner = element.$.inner; |
| 166 | + }); |
| 167 | + |
| 168 | + suite('scope cache', function() { |
| 169 | + test(':host-context()', function() { |
| 170 | + assert.equal(getComputedStyle(inner).color, 'rgb(211, 211, 211)'); |
| 171 | + owner.removeAttribute('bar'); |
| 172 | + element.updateStyles(); |
| 173 | + assert.equal(getComputedStyle(inner).color, 'rgb(0, 0, 0)'); |
| 174 | + }); |
| 175 | + |
| 176 | + test(':host()', function() { |
| 177 | + owner.removeAttribute('bar'); |
| 178 | + element.updateStyles(); |
| 179 | + assert.equal(getComputedStyle(inner).color, 'rgb(0, 0, 0)'); |
| 180 | + element.removeAttribute('foo'); |
| 181 | + element.updateStyles(); |
| 182 | + assert.equal(getComputedStyle(inner).color, 'rgb(255, 255, 255)'); |
| 183 | + }); |
| 184 | + }); |
| 185 | + |
| 186 | + suite('global cache', function() { |
| 187 | + test(':host-context', function() { |
| 188 | + owner.removeAttribute('bar') |
| 189 | + element.updateStyles(); |
| 190 | + assert.include(element.className, 'my-type-extension-1'); |
| 191 | + owner.setAttribute('bar', ''); |
| 192 | + element.updateStyles(); |
| 193 | + assert.include(element.className, 'my-type-extension-0'); |
| 194 | + }); |
| 195 | + |
| 196 | + test(':host()', function() { |
| 197 | + assert.include(element.className, 'my-type-extension-0'); |
| 198 | + owner.removeAttribute('bar'); |
| 199 | + element.removeAttribute('foo'); |
| 200 | + element.updateStyles(); |
| 201 | + assert.include(element.className, 'my-type-extension-2'); |
| 202 | + element.setAttribute('foo', ''); |
| 203 | + element.updateStyles(); |
| 204 | + assert.include(element.className, 'my-type-extension-1'); |
| 205 | + }); |
| 206 | + }); |
| 207 | + }); |
113 | 208 | </script> |
114 | 209 | </body> |
115 | 210 | </html> |
0 commit comments