OLD | NEW |
1 <!doctype html> | 1 <!doctype html> |
2 <!-- | 2 <!-- |
3 @license | 3 @license |
4 Copyright (c) 2015 The Polymer Project Authors. All rights reserved. | 4 Copyright (c) 2015 The Polymer Project Authors. All rights reserved. |
5 This code may only be used under the BSD style license found at http://polymer.g
ithub.io/LICENSE.txt | 5 This code may only be used under the BSD style license found at http://polymer.g
ithub.io/LICENSE.txt |
6 The complete set of authors may be found at http://polymer.github.io/AUTHORS.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/CONTRI
BUTORS.txt | 7 The complete set of contributors may be found at http://polymer.github.io/CONTRI
BUTORS.txt |
8 Code distributed by Google as part of the polymer project is also | 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/PATEN
TS.txt | 9 subject to an additional IP rights grant found at http://polymer.github.io/PATEN
TS.txt |
10 --> | 10 --> |
11 <html> | 11 <html> |
12 <head> | 12 <head> |
13 | 13 |
14 <meta charset="UTF-8"> | 14 <meta charset="UTF-8"> |
15 <title>paper-ripple</title> | 15 <title>paper-ripple</title> |
16 <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-
scale=1.0"> | 16 <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-
scale=1.0"> |
17 | 17 |
18 <script src="../../webcomponentsjs/webcomponents-lite.js"></script> | 18 <script src="../../webcomponentsjs/webcomponents-lite.js"></script> |
19 <script src="../../web-component-tester/browser.js"></script> | 19 <script src="../../web-component-tester/browser.js"></script> |
20 <script src="../../test-fixture/test-fixture-mocha.js"></script> | 20 <script src="../../iron-test-helpers/mock-interactions.js"></script> |
21 | 21 |
22 <link rel="import" href="../../test-fixture/test-fixture.html"> | |
23 <link rel="import" href="../paper-ripple.html"> | 22 <link rel="import" href="../paper-ripple.html"> |
24 | 23 |
25 <style> | 24 <style> |
26 #RippleContainer { | 25 #RippleContainer { |
27 display: block; | 26 display: block; |
28 position: relative; | 27 position: relative; |
29 width: 100px; | 28 width: 100px; |
30 height: 50px; | 29 height: 50px; |
31 } | 30 } |
32 </style> | 31 </style> |
(...skipping 16 matching lines...) Expand all Loading... |
49 </test-fixture> | 48 </test-fixture> |
50 | 49 |
51 <test-fixture id="RecenteringRipple"> | 50 <test-fixture id="RecenteringRipple"> |
52 <template> | 51 <template> |
53 <div id="RippleContainer"> | 52 <div id="RippleContainer"> |
54 <paper-ripple recenters></paper-ripple> | 53 <paper-ripple recenters></paper-ripple> |
55 </div> | 54 </div> |
56 </template> | 55 </template> |
57 </test-fixture> | 56 </test-fixture> |
58 | 57 |
| 58 <test-fixture id="NoinkTarget"> |
| 59 <template> |
| 60 <div id="RippleContainer"> |
| 61 <paper-ripple noink></paper-ripple> |
| 62 </div> |
| 63 </template> |
| 64 </test-fixture> |
| 65 |
59 <script> | 66 <script> |
60 function FakeMouseEvent (target, relativeX, relativeX) { | |
61 var rect = target.getBoundingClientRect(); | |
62 | |
63 return { | |
64 detail: { | |
65 x: rect.left + relativeX, | |
66 y: rect.top + relativeX | |
67 } | |
68 }; | |
69 } | |
70 | |
71 suite('<paper-ripple>', function () { | 67 suite('<paper-ripple>', function () { |
72 var mouseEvent; | 68 var mouseEvent; |
73 var rippleContainer; | 69 var rippleContainer; |
74 var ripple; | 70 var ripple; |
75 | 71 |
76 suite('when tapped', function () { | 72 suite('when tapped', function () { |
77 setup(function () { | 73 setup(function () { |
78 rippleContainer = fixture('TrivialRipple'); | 74 rippleContainer = fixture('TrivialRipple'); |
79 ripple = rippleContainer.firstElementChild; | 75 ripple = rippleContainer.firstElementChild; |
80 | |
81 mouseEvent = new FakeMouseEvent(ripple, 10, 10); | |
82 }); | 76 }); |
83 | 77 |
84 test('creates a ripple', function () { | 78 test('creates a ripple', function () { |
85 expect(ripple.ripples.length).to.be.eql(0); | 79 expect(ripple.ripples.length).to.be.eql(0); |
86 ripple.downAction(mouseEvent); | 80 MockInteractions.down(ripple); |
87 expect(ripple.ripples.length).to.be.eql(1); | 81 expect(ripple.ripples.length).to.be.eql(1); |
88 }); | 82 }); |
89 | 83 |
90 test('may create multiple ripples that overlap', function () { | 84 test('may create multiple ripples that overlap', function () { |
91 expect(ripple.ripples.length).to.be.eql(0); | 85 expect(ripple.ripples.length).to.be.eql(0); |
92 | 86 |
93 for (var i = 0; i < 3; ++i) { | 87 for (var i = 0; i < 3; ++i) { |
94 ripple.downAction(mouseEvent); | 88 MockInteractions.down(ripple); |
95 expect(ripple.ripples.length).to.be.eql(i + 1); | 89 expect(ripple.ripples.length).to.be.eql(i + 1); |
96 } | 90 } |
97 }); | 91 }); |
98 }); | 92 }); |
99 | 93 |
| 94 suite('when holdDown is togggled', function() { |
| 95 setup(function () { |
| 96 rippleContainer = fixture('TrivialRipple'); |
| 97 ripple = rippleContainer.firstElementChild; |
| 98 }); |
| 99 |
| 100 test('generates a ripple', function() { |
| 101 ripple.holdDown = true; |
| 102 expect(ripple.ripples.length).to.be.eql(1); |
| 103 }); |
| 104 |
| 105 test('generates a ripple when noink', function() { |
| 106 ripple.noink = true; |
| 107 ripple.holdDown = true; |
| 108 expect(ripple.ripples.length).to.be.eql(1); |
| 109 |
| 110 }); |
| 111 |
| 112 }); |
| 113 |
| 114 suite('when target is noink', function () { |
| 115 setup(function () { |
| 116 rippleContainer = fixture('NoinkTarget'); |
| 117 ripple = rippleContainer.firstElementChild; |
| 118 }); |
| 119 |
| 120 test('tapping does not create a ripple', function () { |
| 121 expect(ripple.ripples.length).to.be.eql(0); |
| 122 MockInteractions.down(ripple); |
| 123 expect(ripple.ripples.length).to.be.eql(0); |
| 124 }); |
| 125 |
| 126 test('ripples can be manually created', function () { |
| 127 expect(ripple.ripples.length).to.be.eql(0); |
| 128 ripple.simulatedRipple() |
| 129 expect(ripple.ripples.length).to.be.eql(1); |
| 130 }); |
| 131 }); |
| 132 |
| 133 |
| 134 |
100 suite('with the `center` attribute set to true', function () { | 135 suite('with the `center` attribute set to true', function () { |
101 setup(function () { | 136 setup(function () { |
102 rippleContainer = fixture('CenteringRipple'); | 137 rippleContainer = fixture('CenteringRipple'); |
103 ripple = rippleContainer.firstElementChild; | 138 ripple = rippleContainer.firstElementChild; |
104 | |
105 mouseEvent = new FakeMouseEvent(ripple, 10, 10); | |
106 }); | 139 }); |
107 | 140 |
108 test('ripples will center', function (done) { | 141 test('ripples will center', function (done) { |
109 var waveContainerElement; | 142 var waveContainerElement; |
110 // let's ask the browser what `translate3d(0px, 0px, 0)` will actually
look like | 143 // let's ask the browser what `translate3d(0px, 0px, 0)` will actually
look like |
111 var div = document.createElement('div'); | 144 var div = document.createElement('div'); |
112 div.style.webkitTransform = 'translate3d(0px, 0px, 0px)'; | 145 div.style.webkitTransform = 'translate3d(0px, 0px, 0px)'; |
113 div.style.transform = 'translate3d(0px, 0px, 0)'; | 146 div.style.transform = 'translate3d(0px, 0px, 0)'; |
114 | 147 |
115 ripple.downAction(mouseEvent); | 148 MockInteractions.down(ripple); |
116 | 149 |
117 waveContainerElement = ripple.ripples[0].waveContainer; | 150 waveContainerElement = ripple.ripples[0].waveContainer; |
118 | 151 |
119 ripple.upAction(mouseEvent); | 152 MockInteractions.up(ripple); |
120 | 153 |
121 window.requestAnimationFrame(function () { | 154 window.requestAnimationFrame(function () { |
122 var currentTransform = waveContainerElement.style.transform; | 155 var currentTransform = waveContainerElement.style.transform; |
123 try { | 156 try { |
124 expect(div.style.transform).to.be.ok; | 157 expect(div.style.transform).to.be.ok; |
125 expect(currentTransform).to.be.ok; | 158 expect(currentTransform).to.be.ok; |
126 expect(currentTransform).to.be.eql(div.style.transform); | 159 expect(currentTransform).to.be.eql(div.style.transform); |
127 | 160 |
128 done(); | 161 done(); |
129 } catch (e) { | 162 } catch (e) { |
130 done(e); | 163 done(e); |
131 } | 164 } |
132 }); | 165 }); |
133 }); | 166 }); |
134 }); | 167 }); |
135 | 168 |
136 suite('with the `recenters` attribute set to true', function () { | 169 suite('with the `recenters` attribute set to true', function () { |
137 setup(function () { | 170 setup(function () { |
138 rippleContainer = fixture('RecenteringRipple'); | 171 rippleContainer = fixture('RecenteringRipple'); |
139 ripple = rippleContainer.firstElementChild; | 172 ripple = rippleContainer.firstElementChild; |
140 mouseEvent = new FakeMouseEvent(ripple, 10, 10); | |
141 }); | 173 }); |
142 test('ripples will gravitate towards the center', function (done) { | 174 test('ripples will gravitate towards the center', function (done) { |
143 var waveContainerElement; | 175 var waveContainerElement; |
144 var waveTranslateString; | 176 var waveTranslateString; |
145 ripple.downAction(mouseEvent); | 177 MockInteractions.down(ripple, {x: 10, y: 10}); |
146 waveContainerElement = ripple.ripples[0].waveContainer; | 178 waveContainerElement = ripple.ripples[0].waveContainer; |
147 waveTranslateString = waveContainerElement.style.transform; | 179 waveTranslateString = waveContainerElement.style.transform; |
148 ripple.upAction(mouseEvent); | 180 MockInteractions.up(ripple); |
149 window.requestAnimationFrame(function () { | 181 window.requestAnimationFrame(function () { |
150 try { | 182 try { |
151 expect(waveTranslateString).to.be.ok; | 183 expect(waveTranslateString).to.be.ok; |
152 expect(waveContainerElement.style.transform).to.be.ok; | 184 expect(waveContainerElement.style.transform).to.be.ok; |
153 expect(waveContainerElement.style.transform).to.not.be.eql(waveTra
nslateString); | 185 expect(waveContainerElement.style.transform).to.not.be.eql(waveTra
nslateString); |
154 done(); | 186 done(); |
155 } catch (e) { | 187 } catch (e) { |
156 done(e); | 188 done(e); |
157 } | 189 } |
158 }); | 190 }); |
159 }); | 191 }); |
160 }); | 192 }); |
161 | 193 |
162 }); | 194 }); |
163 </script> | 195 </script> |
164 | 196 |
165 </body> | 197 </body> |
166 </html> | 198 </html> |
OLD | NEW |