1<!doctype html>
2<!--
3@license
4Copyright (c) 2014 The Polymer Project Authors. All rights reserved.
5This code may only be used under the BSD style license found at http://polymer.github.io/LICENSE.txt
6The complete set of authors may be found at http://polymer.github.io/AUTHORS.txt
7The complete set of contributors may be found at http://polymer.github.io/CONTRIBUTORS.txt
8Code distributed by Google as part of the polymer project is also
9subject to an additional IP rights grant found at http://polymer.github.io/PATENTS.txt
10-->
11<script>
12WCT = {waitFor: function (cb) {HTMLImports.whenReady(cb)}}
13</script>
14<script src="./test-flags.js"></script>
15<script src="../node_modules/wct-browser-legacy/browser.js"></script>
16<script src="../node_modules/@webcomponents/webcomponents-platform/webcomponents-platform.js"></script>
17<script src="../node_modules/es6-promise/dist/es6-promise.auto.min.js"></script>
18<script src="../node_modules/@webcomponents/template/template.js"></script>
19<script src="../node_modules/@webcomponents/html-imports/html-imports.min.js"></script>
20<script src="../node_modules/@webcomponents/shadydom/shadydom.min.js"></script>
21<script src="../node_modules/@webcomponents/custom-elements/custom-elements.min.js"></script>
22<script src="../scoping-shim.min.js"></script>
23<script src="../apply-shim.min.js"></script>
24<script src="../custom-style-interface.min.js"></script>
25<script src="module/generated/make-element.js"></script>
26<script src="module/generated/custom-style-element.js"></script>
27
28<custom-style>
29  <style>
30  html {
31    --foo: rgb(123, 123, 123);
32    --bar: {
33      border: 2px solid red;
34    }
35  }
36
37  </style>
38</custom-style>
39<custom-style>
40  <style>
41  :root {
42    --svg-icon: url("data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7");
43    --svg-icon-2: url("data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7");
44  }
45  .base64 {
46    background-image: var(--svg-icon);
47  }
48  </style>
49</custom-style>
50
51<template id="x-inner">
52  <style>
53    :host {
54      display: block;
55      height: 100px;
56      width: 100px;
57      border: 4px solid blue;
58      background-color: var(--foo);
59      @apply --bar;
60    }
61  </style>
62</template>
63
64<template id="x-outer">
65  <style>
66  :host {
67    display: block;
68    @apply --bar;
69  }
70  </style>
71  <x-inner></x-inner>
72</template>
73
74<x-outer id="target"></x-outer>
75
76<div class="base64">base64</div>
77
78<script>
79  suite('Custom Style upgrades', function() {
80    suiteSetup(function() {
81      makeElement('x-inner');
82      makeElement('x-outer');
83    });
84    test('custom-style applies to deeply nested elements', function() {
85      var target = document.querySelector('#target');
86      var inner = target.shadowRoot.querySelector('x-inner');
87      assert.equal(getComputedStyle(inner).backgroundColor, 'rgb(123, 123, 123)');
88    });
89    test('custom-style applied mixins update', function() {
90      var target = document.querySelector('#target');
91      var inner = target.shadowRoot.querySelector('x-inner');
92      assert.equal(getComputedStyle(target).borderTopWidth.trim(), '2px');
93      assert.equal(getComputedStyle(inner).borderTopWidth.trim(), '2px');
94    });
95    test('custom-style with base64 in variable', function() {
96      var target = document.querySelector('.base64');
97      assert.match(getComputedStyle(target).backgroundImage, /url\("?data\:image\/gif;base64,R0lGODlhAQABAIAAAAAAAP\/\/\/yH5BAEAAAAALAAAAAABAAEAAAIBRAA7"?\)/);
98    });
99  });
100</script>
101