~didrocks/+junk/face-detection-15.04

« back to all changes in this revision

Viewing changes to facedetection/www/bower_components/paper-radio-group/test/basic.html

  • Committer: Didier Roche
  • Date: 2016-05-10 23:09:11 UTC
  • Revision ID: didier.roche@canonical.com-20160510230911-c7xr490zrj3yrzxd
New version

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
<!doctype html>
 
2
<!--
 
3
@license
 
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.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
    <title>paper-radio-group basic tests</title>
 
15
    <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0">
 
16
 
 
17
    <script src="../../webcomponentsjs/webcomponents-lite.js"></script>
 
18
    <script src="../../web-component-tester/browser.js"></script>
 
19
    <script src="../../iron-test-helpers/mock-interactions.js"></script>
 
20
    <link rel="import" href="../paper-radio-group.html">
 
21
 
 
22
  </head>
 
23
  <body>
 
24
 
 
25
    <test-fixture id="NoSelection">
 
26
      <template>
 
27
        <paper-radio-group>
 
28
          <paper-radio-button name="r1">r1</paper-radio-button>
 
29
          <paper-radio-button name="r2">r2</paper-radio-button>
 
30
          <paper-radio-button name="r3">r3</paper-radio-button>
 
31
        </paper-radio-group>
 
32
      </template>
 
33
    </test-fixture>
 
34
 
 
35
    <test-fixture id="WithSelection">
 
36
      <template>
 
37
        <paper-radio-group selected="r1">
 
38
          <paper-radio-button name="r1">r1</paper-radio-button>
 
39
          <paper-radio-button name="r2">r2</paper-radio-button>
 
40
          <paper-radio-button name="r3">r3</paper-radio-button>
 
41
        </paper-radio-group>
 
42
      </template>
 
43
    </test-fixture>
 
44
 
 
45
    <test-fixture id="WithDisabled">
 
46
      <template>
 
47
        <paper-radio-group selected="r1">
 
48
          <paper-radio-button name="r1">r1</paper-radio-button>
 
49
          <paper-radio-button name="r2" disabled>r2</paper-radio-button>
 
50
          <paper-radio-button name="r3">r3</paper-radio-button>
 
51
        </paper-radio-group>
 
52
      </template>
 
53
    </test-fixture>
 
54
 
 
55
    <script>
 
56
      suite('defaults', function() {
 
57
        var LEFT_ARROW = 37;
 
58
        var RIGHT_ARROW = 39;
 
59
 
 
60
        test('group can have no selection', function (done) {
 
61
          var g = fixture('NoSelection');
 
62
 
 
63
          // Needs to be async since the underlying iron-selector uses observeNodes.
 
64
          Polymer.Base.async(function() {
 
65
            expect(g.selected).to.not.be.ok;
 
66
            var items = g.items;
 
67
            expect(items.length).to.be.equal(3);
 
68
 
 
69
            expect(items[0].checked).to.be.equal(false);
 
70
            expect(items[1].checked).to.be.equal(false);
 
71
            expect(items[2].checked).to.be.equal(false);
 
72
 
 
73
            done();
 
74
          }, 1);
 
75
 
 
76
        });
 
77
 
 
78
        test('group can have a selection', function (done) {
 
79
          var g = fixture('WithSelection');
 
80
 
 
81
          // Needs to be async since the underlying iron-selector uses observeNodes.
 
82
          Polymer.Base.async(function() {
 
83
            expect(g.selected).to.be.ok;
 
84
            var items = g.items;
 
85
            expect(items.length).to.be.equal(3);
 
86
 
 
87
            expect(items[0].checked).to.be.equal(true);
 
88
            expect(items[1].checked).to.be.equal(false);
 
89
            expect(items[2].checked).to.be.equal(false);
 
90
            expect(items[0].getAttribute('name')).to.be.equal(g.selected);
 
91
 
 
92
            done();
 
93
          }, 1);
 
94
        });
 
95
 
 
96
        test('right arrow advances the selection', function (done) {
 
97
          var g = fixture('WithSelection');
 
98
 
 
99
          // Needs to be async since the underlying iron-selector uses observeNodes.
 
100
          Polymer.Base.async(function() {
 
101
            var items = g.items;
 
102
            expect(items[0].checked).to.be.equal(true);
 
103
 
 
104
            g.addEventListener('paper-radio-group-changed', function () {
 
105
              expect(items[0].checked).to.be.equal(false);
 
106
              expect(items[1].checked).to.be.equal(true);
 
107
              expect(items[2].checked).to.be.equal(false);
 
108
              done();
 
109
            });
 
110
            MockInteractions.keyDownOn(g, RIGHT_ARROW);
 
111
          }, 1);
 
112
        });
 
113
 
 
114
        test('left arrow reverses the selection', function (done) {
 
115
          var g = fixture('WithSelection');
 
116
 
 
117
          // Needs to be async since the underlying iron-selector uses observeNodes.
 
118
          Polymer.Base.async(function() {
 
119
            var items = g.items;
 
120
            expect(items[0].checked).to.be.equal(true);
 
121
 
 
122
            g.addEventListener('paper-radio-group-changed', function () {
 
123
              expect(items[0].checked).to.be.equal(false);
 
124
              expect(items[1].checked).to.be.equal(false);
 
125
              expect(items[2].checked).to.be.equal(true);
 
126
              done();
 
127
            });
 
128
            MockInteractions.keyDownOn(g, LEFT_ARROW);
 
129
          }, 1);
 
130
        });
 
131
 
 
132
        test('selection should skip disabled items', function (done) {
 
133
          var g = fixture('WithDisabled');
 
134
 
 
135
          // Needs to be async since the underlying iron-selector uses observeNodes.
 
136
          Polymer.Base.async(function() {
 
137
            var items = g.items;
 
138
            expect(items[0].checked).to.be.equal(true);
 
139
 
 
140
            g.addEventListener('paper-radio-group-changed', function () {
 
141
              expect(items[0].checked).to.be.equal(false);
 
142
              expect(items[1].checked).to.be.equal(false);
 
143
              expect(items[2].checked).to.be.equal(true);
 
144
              done();
 
145
            });
 
146
            MockInteractions.keyDownOn(g, RIGHT_ARROW);
 
147
          }, 1);
 
148
        });
 
149
 
 
150
        test('clicking should change the selection', function (done) {
 
151
          var g = fixture('WithSelection');
 
152
 
 
153
          // Needs to be async since the underlying iron-selector uses observeNodes.
 
154
          Polymer.Base.async(function() {
 
155
            var items = g.items;
 
156
            expect(items[0].checked).to.be.equal(true);
 
157
 
 
158
            g.addEventListener('paper-radio-group-changed', function () {
 
159
              expect(items[0].checked).to.be.equal(false);
 
160
              expect(items[1].checked).to.be.equal(true);
 
161
              expect(items[2].checked).to.be.equal(false);
 
162
              done();
 
163
            });
 
164
            MockInteractions.tap(items[1]);
 
165
          }, 1);
 
166
        });
 
167
 
 
168
        test('clicking the selected item should not deselect', function (done) {
 
169
          var g = fixture('WithSelection');
 
170
 
 
171
          // Needs to be async since the underlying iron-selector uses observeNodes.
 
172
          Polymer.Base.async(function() {
 
173
            var items = g.items;
 
174
            expect(items[0].checked).to.be.equal(true);
 
175
 
 
176
            // The selection should not change, but wait for a little bit just
 
177
            // in case it would and an event would be fired.
 
178
            setTimeout(function() {
 
179
              expect(items[0].checked).to.be.equal(true);
 
180
              expect(items[1].checked).to.be.equal(false);
 
181
              expect(items[2].checked).to.be.equal(false);
 
182
              done();
 
183
            }, 1);
 
184
            MockInteractions.tap(items[0]);
 
185
          }, 1);
 
186
        });
 
187
 
 
188
        test('clicking the selected item should deselect if allow-empty-selection is set', function (done) {
 
189
          var g = fixture('WithSelection');
 
190
          g.allowEmptySelection = true;
 
191
 
 
192
          // Needs to be async since the underlying iron-selector uses observeNodes.
 
193
          Polymer.Base.async(function() {
 
194
            var items = g.items;
 
195
            expect(items[0].checked).to.be.equal(true);
 
196
 
 
197
            // The selection should not change, but wait for a little bit just
 
198
            // in case it would and an event would be fired.
 
199
            setTimeout(function() {
 
200
              expect(items[0].checked).to.be.equal(false);
 
201
              expect(items[1].checked).to.be.equal(false);
 
202
              expect(items[2].checked).to.be.equal(false);
 
203
              done();
 
204
            }, 1);
 
205
            MockInteractions.tap(items[0]);
 
206
          }, 1);
 
207
        });
 
208
 
 
209
        test('arrow keys cause iron-activate events', function(done) {
 
210
          var g = fixture('WithSelection');
 
211
 
 
212
          // Needs to be async since the underlying iron-selector uses observeNodes.
 
213
          Polymer.Base.async(function() {
 
214
            g.items[0].focus();
 
215
 
 
216
            var i = 0;
 
217
            g.addEventListener('iron-activate', function() {
 
218
              switch (i++) {
 
219
                case 0:
 
220
                  MockInteractions.pressAndReleaseKeyOn(g, 38);
 
221
                break;
 
222
 
 
223
                case 1:
 
224
                  MockInteractions.pressAndReleaseKeyOn(g, 39);
 
225
                break;
 
226
 
 
227
                case 2:
 
228
                  MockInteractions.pressAndReleaseKeyOn(g, 40);
 
229
                break;
 
230
 
 
231
                default:
 
232
                  done();
 
233
              }
 
234
            });
 
235
 
 
236
            MockInteractions.pressAndReleaseKeyOn(g, 37);
 
237
          }, 1);
 
238
        });
 
239
 
 
240
      });
 
241
    </script>
 
242
  </body>
 
243
</html>