|
| 1 | +<!doctype html> |
| 2 | +<!-- |
| 3 | +@license |
| 4 | +Copyright (c) 2014 The Polymer Project Authors. All rights reserved. |
| 5 | +This code may only be used under the BSD style license found at http://polymer.github.io/LICENSE.txt |
| 6 | +The complete set of authors may be found at http://polymer.github.io/AUTHORS.txt |
| 7 | +The complete set of contributors may be found at http://polymer.github.io/CONTRIBUTORS.txt |
| 8 | +Code distributed by Google as part of the polymer project is also |
| 9 | +subject to an additional IP rights grant found at http://polymer.github.io/PATENTS.txt |
| 10 | +--> |
| 11 | +<html> |
| 12 | +<head> |
| 13 | + <meta charset="utf-8"> |
| 14 | + <script src="../../../webcomponentsjs/webcomponents-lite.js"></script> |
| 15 | + <script src="../../../web-component-tester/browser.js"></script> |
| 16 | + <link rel="import" href="../../polymer.html"> |
| 17 | + |
| 18 | +</head> |
| 19 | +<body> |
| 20 | + <style is="custom-style"> |
| 21 | + .c { |
| 22 | + --cache-element-border: 8px solid blue; |
| 23 | + } |
| 24 | + </style> |
| 25 | + <dom-module id="cache-element"> |
| 26 | + <template> |
| 27 | + <style> |
| 28 | + :host { |
| 29 | + display: block; |
| 30 | + border: var(--cache-element-border, 4px solid orange); |
| 31 | + } |
| 32 | + </style> |
| 33 | + cache-element |
| 34 | + </template> |
| 35 | + <script> |
| 36 | + HTMLImports.whenReady(function() { |
| 37 | + Polymer({ |
| 38 | + is: 'cache-element' |
| 39 | + }); |
| 40 | + }); |
| 41 | + </script> |
| 42 | + </dom-module> |
| 43 | + |
| 44 | + <cache-element id="cache1" class="c"></cache-element> |
| 45 | + <cache-element id="cache2"></cache-element> |
| 46 | + |
| 47 | + <script> |
| 48 | + |
| 49 | + suite('custom-style scope cache', function() { |
| 50 | + |
| 51 | + test('elements created declaratively conditionally styled via custom style receive correct properties', function() { |
| 52 | + var t1 = document.querySelector('#cache1'); |
| 53 | + var t2 = document.querySelector('#cache2');; |
| 54 | + assertComputed(t1, '8px'); |
| 55 | + assertComputed(t2, '4px'); |
| 56 | + }); |
| 57 | + |
| 58 | + |
| 59 | + test('elements created imperatively conditionally styled via custom style receive correct properties', function() { |
| 60 | + var t1 = document.createElement('cache-element'); |
| 61 | + t1.classList.add('c'); |
| 62 | + var t2 = document.createElement('cache-element'); |
| 63 | + document.body.appendChild(t1); |
| 64 | + document.body.appendChild(t2); |
| 65 | + CustomElements.takeRecords(); |
| 66 | + assertComputed(t1, '8px'); |
| 67 | + assertComputed(t2, '4px'); |
| 68 | + }); |
| 69 | + |
| 70 | + }); |
| 71 | + |
| 72 | + |
| 73 | + function assertComputed(element, value, property, pseudo) { |
| 74 | + var computed = getComputedStyle(element, pseudo); |
| 75 | + property = property || 'border-top-width'; |
| 76 | + assert.equal(computed[property], value, 'computed style incorrect for ' + property); |
| 77 | + } |
| 78 | + |
| 79 | + </script> |
| 80 | + |
| 81 | +</body> |
| 82 | +</html> |
0 commit comments