1
+ <!doctype html>
2
+ <!--
3
+ @license
4
+ Copyright (c) 2019 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 >
15
+ window . ShadyDOM = { force : true , noPatch : true } ;
16
+ </ script >
17
+ < script src ="../../node_modules/@webcomponents/webcomponentsjs/webcomponents-bundle.js "> </ script >
18
+ < script src ="wct-browser-config.js "> </ script >
19
+ < script src ="../../node_modules/wct-browser-legacy/browser.js "> </ script >
20
+ </ head >
21
+ < body >
22
+
23
+ < script type ="module ">
24
+ import { Polymer , html } from '../../polymer-legacy.js' ;
25
+ Polymer ( {
26
+ is : 'scope-subtree-legacy' ,
27
+ _template : html `
28
+ < style >
29
+ # container * {
30
+ border : 10px solid black;
31
+ }
32
+ </ style >
33
+ < div id ="container "> </ div > `
34
+ } ) ;
35
+ </ script >
36
+
37
+ < script type ="module ">
38
+ import { PolymerElement , html } from '../../polymer-element.js' ;
39
+ class ScopeSubtreeElement extends PolymerElement {
40
+ static get template ( ) {
41
+ return html `
42
+ < style >
43
+ # container * {
44
+ border : 10px solid black;
45
+ }
46
+ </ style >
47
+ < div id ="container "> </ div > ` ;
48
+ }
49
+ }
50
+ customElements . define ( 'scope-subtree-element' , ScopeSubtreeElement ) ;
51
+ </ script >
52
+
53
+ < test-fixture id ="legacy ">
54
+ < template >
55
+ < scope-subtree-legacy > </ scope-subtree-legacy >
56
+ </ template >
57
+ </ test-fixture >
58
+
59
+ < test-fixture id ="element ">
60
+ < template >
61
+ < scope-subtree-element > </ scope-subtree-element >
62
+ </ template >
63
+ </ test-fixture >
64
+
65
+ < script type ="module ">
66
+ import { scopeSubtree } from '../../lib/utils/scope-subtree.js' ;
67
+
68
+ function assertComputed ( element , value , property , pseudo ) {
69
+ var computed = getComputedStyle ( element , pseudo ) ;
70
+ property = property || 'border-top-width' ;
71
+ if ( Array . isArray ( value ) ) {
72
+ assert . oneOf ( computed [ property ] , value , 'computed style incorrect for ' + property ) ;
73
+ } else {
74
+ assert . equal ( computed [ property ] , value , 'computed style incorrect for ' + property ) ;
75
+ }
76
+ }
77
+
78
+ suite ( 'LegacyElement.scopeSubtree' , function ( ) {
79
+ let el ;
80
+ setup ( function ( ) {
81
+ el = fixture ( 'legacy' ) ;
82
+ } ) ;
83
+ test ( 'elements are scoped' , function ( ) {
84
+ const div = document . createElement ( 'div' ) ;
85
+ const innerDiv = document . createElement ( 'div' ) ;
86
+ div . appendChild ( innerDiv ) ;
87
+ el . $ . container . appendChild ( div ) ;
88
+ el . scopeSubtree ( el . $ . container ) ;
89
+ assertComputed ( div , '10px' ) ;
90
+ assertComputed ( innerDiv , '10px' ) ;
91
+ } ) ;
92
+ test ( 'second argument creates a mutation observer' , async function ( ) {
93
+ const mo = el . scopeSubtree ( el . $ . container , true ) ;
94
+ assert . instanceOf ( mo , MutationObserver ) ;
95
+ const div = document . createElement ( 'div' ) ;
96
+ const innerDiv = document . createElement ( 'div' ) ;
97
+ div . appendChild ( innerDiv ) ;
98
+ el . $ . container . appendChild ( div ) ;
99
+ await new Promise ( ( resolve ) => setTimeout ( resolve , 0 ) ) ;
100
+ assertComputed ( div , '10px' ) ;
101
+ assertComputed ( innerDiv , '10px' ) ;
102
+ } ) ;
103
+ } ) ;
104
+
105
+ suite ( 'PolymerElement and scopeSubtree util' , function ( ) {
106
+ let el ;
107
+ setup ( function ( ) {
108
+ el = fixture ( 'element' ) ;
109
+ } ) ;
110
+ test ( 'elements are scoped' , function ( ) {
111
+ const div = document . createElement ( 'div' ) ;
112
+ const innerDiv = document . createElement ( 'div' ) ;
113
+ div . appendChild ( innerDiv ) ;
114
+ el . $ . container . appendChild ( div ) ;
115
+ scopeSubtree ( el . $ . container ) ;
116
+ assertComputed ( div , '10px' ) ;
117
+ assertComputed ( innerDiv , '10px' ) ;
118
+ } ) ;
119
+ test ( 'second argument creates a mutation observer' , async function ( ) {
120
+ const mo = scopeSubtree ( el . $ . container , true ) ;
121
+ assert . instanceOf ( mo , MutationObserver ) ;
122
+ const div = document . createElement ( 'div' ) ;
123
+ const innerDiv = document . createElement ( 'div' ) ;
124
+ div . appendChild ( innerDiv ) ;
125
+ el . $ . container . appendChild ( div ) ;
126
+ await new Promise ( ( resolve ) => setTimeout ( resolve , 0 ) ) ;
127
+ assertComputed ( div , '10px' ) ;
128
+ assertComputed ( innerDiv , '10px' ) ;
129
+ } ) ;
130
+ } ) ;
131
+ </ script >
132
+ </ body >
133
+ </ html >
0 commit comments