1
+ <!doctype html>
2
+ < html >
3
+ < head >
4
+ < script src ="../../../webcomponentsjs/webcomponents-lite.js "> </ script >
5
+ < script src ="../../../web-component-tester/browser.js "> </ script >
6
+ < link rel ="import " href ="../../polymer.html ">
7
+ < link rel ="import " href ="shady-unscoped-style-import.html ">
8
+ </ head >
9
+ < body >
10
+
11
+ < custom-style >
12
+ < style is ="custom-style ">
13
+ html {
14
+ --foo : {
15
+ padding : 10px ;
16
+ }
17
+ }
18
+ </ style >
19
+ </ custom-style >
20
+
21
+ < dom-module id ="my-element ">
22
+
23
+ < template >
24
+ < style include ="global-shared1 global-shared2 ">
25
+ : host {
26
+ dis play: block;
27
+ }
28
+
29
+ .happy {
30
+ @apply --foo;
31
+ }
32
+ </ style >
33
+ < div id ="fromStyle " class ="happy "> Happy: green</ div >
34
+ < div id ="fromImport " class ="import "> Happy: yellow</ div >
35
+ < div id ="normal " class ="normal "> Happy: orange</ div >
36
+ </ template >
37
+
38
+ < script >
39
+ HTMLImports . whenReady ( function ( ) {
40
+ Polymer ( {
41
+ is : 'my-element'
42
+ } ) ;
43
+ } ) ;
44
+ </ script >
45
+
46
+ </ dom-module >
47
+
48
+ < dom-module id ="my-element2 ">
49
+
50
+ < template >
51
+ < style include ="global-shared1 ">
52
+ : host {
53
+ dis play: block;
54
+ }
55
+
56
+ </ style >
57
+ < div id ="fromStyle " class ="happy "> Happy: green</ div >
58
+ < div id ="fromImport " class ="import "> Happy: yellow</ div >
59
+ < div id ="normal " class ="normal "> Happy: orange</ div >
60
+ </ template >
61
+
62
+ < script >
63
+ HTMLImports . whenReady ( function ( ) {
64
+ Polymer ( { is : 'my-element2' } ) ;
65
+ } ) ;
66
+ </ script >
67
+
68
+ </ dom-module >
69
+
70
+ < my-element > </ my-element >
71
+ < my-element2 > </ my-element2 >
72
+
73
+ < script >
74
+ suite ( 'shady-unscoped styles' , function ( ) {
75
+
76
+ function assertComputed ( element , value , property , pseudo ) {
77
+ var computed = getComputedStyle ( element , pseudo ) ;
78
+ property = property || 'border-top-width' ;
79
+ if ( Array . isArray ( value ) ) {
80
+ assert . oneOf ( computed [ property ] , value , 'computed style incorrect for ' + property ) ;
81
+ } else {
82
+ assert . equal ( computed [ property ] , value , 'computed style incorrect for ' + property ) ;
83
+ }
84
+ }
85
+
86
+ var el1 = document . querySelector ( 'my-element' ) ;
87
+ var el2 = document . querySelector ( 'my-element2' ) ;
88
+
89
+ test ( 'unscoped styles apply' , function ( ) {
90
+ assertComputed ( el1 . $ . fromStyle , '1px' ) ;
91
+ assertComputed ( el1 . $ . fromImport , '2px' ) ;
92
+ assertComputed ( el2 . $ . fromStyle , '1px' ) ;
93
+ assertComputed ( el2 . $ . fromImport , '2px' ) ;
94
+ } ) ;
95
+
96
+ test ( 'shared and @apply apply when used with unscoped styles' , function ( ) {
97
+ assertComputed ( el1 . $ . fromStyle , '10px' , 'padding' ) ;
98
+ assertComputed ( el1 . $ . normal , '3px' ) ;
99
+ assertComputed ( el2 . $ . normal , '3px' ) ;
100
+ } )
101
+
102
+ test ( 'unscoped styling de-duped in ShadyDOM' , function ( ) {
103
+ if ( ! window . ShadyDOM ) {
104
+ this . skip ( ) ;
105
+ }
106
+ assert . equal ( document . head . querySelectorAll ( 'style[shady-unscoped]' ) . length , 2 ) ;
107
+ } ) ;
108
+
109
+ test ( '@apply does not apply under ShadyDOM for shady-unscoped styles' , function ( ) {
110
+ if ( ! window . ShadyDOM ) {
111
+ this . skip ( ) ;
112
+ }
113
+ assertComputed ( el1 . $ . fromStyle , '0px' , 'margin' ) ;
114
+ assertComputed ( el2 . $ . fromStyle , '0px' , 'margin' ) ;
115
+ } )
116
+
117
+
118
+ } ) ;
119
+ </ script >
120
+ </ body >
121
+ </ html >
0 commit comments