~didrocks/+junk/face-detection-15.04

« back to all changes in this revision

Viewing changes to facedetection/www/bower_components/paper-input/test/paper-input.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
 
 
14
  <title>paper-input tests</title>
 
15
 
 
16
  <meta charset="utf-8">
 
17
  <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
 
18
  <meta name="viewport" content="width=device-width, minimum-scale=1.0, initial-scale=1, user-scalable=yes">
 
19
 
 
20
  <script src="../../webcomponentsjs/webcomponents-lite.js"></script>
 
21
 
 
22
  <script src="../../web-component-tester/browser.js"></script>
 
23
  <script src="../../iron-test-helpers/test-helpers.js"></script>
 
24
  <script src="../../iron-test-helpers/mock-interactions.js"></script>
 
25
 
 
26
  <link rel="import" href="../paper-input.html">
 
27
  <link rel="import" href="letters-only.html">
 
28
 
 
29
</head>
 
30
<body>
 
31
 
 
32
  <test-fixture id="basic">
 
33
    <template>
 
34
      <paper-input></paper-input>
 
35
    </template>
 
36
  </test-fixture>
 
37
 
 
38
  <test-fixture id="has-tabindex">
 
39
    <template>
 
40
      <paper-input tabindex="0"></paper-input>
 
41
    </template>
 
42
  </test-fixture>
 
43
 
 
44
  <test-fixture id="label">
 
45
    <template>
 
46
      <paper-input label="foo"></paper-input>
 
47
    </template>
 
48
  </test-fixture>
 
49
 
 
50
  <test-fixture id="label-has-value">
 
51
    <template>
 
52
      <paper-input label="foo" value="bar"></paper-input>
 
53
    </template>
 
54
  </test-fixture>
 
55
 
 
56
  <test-fixture id="error">
 
57
    <template>
 
58
      <paper-input auto-validate pattern="[0-9]*" value="foobar" error-message="error"></paper-input>
 
59
    </template>
 
60
  </test-fixture>
 
61
 
 
62
  <test-fixture id="required">
 
63
    <template>
 
64
      <paper-input auto-validate required error-message="error"></paper-input>
 
65
    </template>
 
66
  </test-fixture>
 
67
 
 
68
  <test-fixture id="required-no-auto-validate">
 
69
    <template>
 
70
      <paper-input required error-message="error"></paper-input>
 
71
    </template>
 
72
  </test-fixture>
 
73
 
 
74
  <test-fixture id="required-char-counter">
 
75
    <template>
 
76
      <paper-input auto-validate char-counter required error-message="error"></paper-input>
 
77
    </template>
 
78
  </test-fixture>
 
79
 
 
80
  <test-fixture id="char-counter">
 
81
    <template>
 
82
      <paper-input char-counter value="foobar"></paper-input>
 
83
    </template>
 
84
  </test-fixture>
 
85
 
 
86
  <test-fixture id="always-float-label">
 
87
    <template>
 
88
      <paper-input always-float-label label="foo"></paper-input>
 
89
    </template>
 
90
  </test-fixture>
 
91
 
 
92
  <test-fixture id="placeholder">
 
93
    <template>
 
94
      <paper-input label="foo" placeholder="bar"></paper-input>
 
95
    </template>
 
96
  </test-fixture>
 
97
 
 
98
  <test-fixture id="date">
 
99
    <template>
 
100
      <paper-input label="foo" type="date"></paper-input>
 
101
    </template>
 
102
  </test-fixture>
 
103
 
 
104
  <letters-only></letters-only>
 
105
 
 
106
  <test-fixture id="validator">
 
107
    <template>
 
108
      <paper-input value="123123" validator="letters-only" auto-validate></paper-input>
 
109
    </template>
 
110
  </test-fixture>
 
111
 
 
112
  <test-fixture id="multiple-inputs">
 
113
    <template>
 
114
      <paper-input label="one"></paper-input>
 
115
      <paper-input label="two"></paper-input>
 
116
      <paper-input label="three"></paper-input>
 
117
      <paper-input label="four"></paper-input>
 
118
    </template>
 
119
  </test-fixture>
 
120
 
 
121
  <script>
 
122
 
 
123
    suite('basic', function() {
 
124
 
 
125
      test('setting value sets the input value', function() {
 
126
        var input = fixture('basic');
 
127
        input.value = 'foobar';
 
128
        assert.equal(input.inputElement.value, input.value, 'inputElement.value equals input.value');
 
129
      });
 
130
 
 
131
      test('placeholder does not overlap label', function() {
 
132
        var input = fixture('placeholder');
 
133
        assert.equal(input.inputElement.placeholder, input.placeholder, 'inputElement.placeholder equals input.placeholder');
 
134
        assert.equal(input.noLabelFloat, false);
 
135
        var floatingLabel = Polymer.dom(Polymer.dom(input.root).querySelector('paper-input-container').root).querySelector('.label-is-floating');
 
136
        assert.ok(floatingLabel);
 
137
      });
 
138
 
 
139
      test('special types autofloat the label', function() {
 
140
        var input = fixture('date');
 
141
        // Browsers that don't support special <input> types like `date` fallback
 
142
        // to `text`, so make sure to only test if type is still preserved after
 
143
        // the element is attached.
 
144
        if (input.inputElement.type === "date") {
 
145
          assert.equal(input.alwaysFloatLabel, true);
 
146
          var floatingLabel = Polymer.dom(Polymer.dom(input.root).querySelector('paper-input-container').root).querySelector('.label-is-floating');
 
147
          assert.ok(floatingLabel);
 
148
        }
 
149
      });
 
150
 
 
151
      test('always-float-label attribute works without placeholder', function() {
 
152
        var input = fixture('always-float-label');
 
153
        var container = Polymer.dom(input.root).querySelector('paper-input-container');
 
154
        var inputContent = Polymer.dom(container.root).querySelector('.input-content');
 
155
        assert.isTrue(inputContent.classList.contains('label-is-floating'), 'label is floating');
 
156
      });
 
157
 
 
158
      test('error message is displayed', function() {
 
159
        var input = fixture('error');
 
160
        forceXIfStamp(input);
 
161
        var error = Polymer.dom(input.root).querySelector('paper-input-error');
 
162
        assert.ok(error, 'paper-input-error exists');
 
163
        assert.notEqual(getComputedStyle(error).display, 'none', 'error is not display:none');
 
164
      });
 
165
 
 
166
      test('empty required input shows error', function() {
 
167
        var input = fixture('required');
 
168
        forceXIfStamp(input);
 
169
        var error = Polymer.dom(input.root).querySelector('paper-input-error');
 
170
        assert.ok(error, 'paper-input-error exists');
 
171
        assert.notEqual(getComputedStyle(error).display, 'none', 'error is not display:none');
 
172
      });
 
173
 
 
174
      test('character counter is displayed', function() {
 
175
        var input = fixture('char-counter');
 
176
        forceXIfStamp(input);
 
177
        var counter = Polymer.dom(input.root).querySelector('paper-input-char-counter')
 
178
        assert.ok(counter, 'paper-input-char-counter exists');
 
179
        assert.equal(counter._charCounterStr, input.value.length, 'character counter shows the value length');
 
180
      });
 
181
 
 
182
      test('validator is used', function() {
 
183
        var input = fixture('validator');
 
184
        assert.ok(input.inputElement.invalid, 'input is invalid');
 
185
      });
 
186
 
 
187
      test('caret position is preserved', function() {
 
188
        var input = fixture('basic');
 
189
        var ironInput = Polymer.dom(input.root).querySelector('input[is="iron-input"]');
 
190
        input.value = 'nananana';
 
191
        ironInput.selectionStart = 2;
 
192
        ironInput.selectionEnd = 2;
 
193
 
 
194
        input.updateValueAndPreserveCaret('nanananabatman');
 
195
 
 
196
        assert.equal(ironInput.selectionStart, 2, 'selectionStart is preserved');
 
197
        assert.equal(ironInput.selectionEnd, 2, 'selectionEnd is preserved');
 
198
      });
 
199
 
 
200
    });
 
201
 
 
202
    suite('focus/blur events', function() {
 
203
      var input;
 
204
 
 
205
      setup(function() {
 
206
        input = fixture('basic');
 
207
      });
 
208
 
 
209
      // At the moment, it is very hard to correctly fire exactly
 
210
      // one focus/blur events on a paper-input. This is because
 
211
      // when a paper-input is focused, it needs to focus
 
212
      // its underlying native input, which will also fire a `blur`
 
213
      // event.
 
214
      test('focus events fired on host element', function() {
 
215
        input.addEventListener('focus', function(event) {
 
216
          assert(input.focused, 'input is focused');
 
217
        });
 
218
        MockInteractions.focus(input);
 
219
      });
 
220
 
 
221
      test('focus events fired on host element if nested element is focused', function() {
 
222
        input.addEventListener('focus', function(event) {
 
223
          assert(input.focused, 'input is focused');
 
224
        });
 
225
        MockInteractions.focus(input.inputElement);
 
226
      });
 
227
 
 
228
      test('blur events fired on host element', function() {
 
229
        MockInteractions.focus(input);
 
230
        input.addEventListener('blur', function(event) {
 
231
          assert(!input.focused, 'input is blurred');
 
232
        });
 
233
        MockInteractions.blur(input);
 
234
      });
 
235
 
 
236
      test('blur events fired on host element nested element is blurred', function() {
 
237
        MockInteractions.focus(input);
 
238
        input.addEventListener('blur', function(event) {
 
239
          assert(!input.focused, 'input is blurred');
 
240
        });
 
241
        MockInteractions.blur(input.inputElement);
 
242
      });
 
243
 
 
244
      test('focusing then bluring sets the focused attribute correctly', function() {
 
245
        MockInteractions.focus(input);
 
246
        assert(input.focused, 'input is focused');
 
247
        MockInteractions.blur(input);
 
248
        assert(!input.focused, 'input is blurred');
 
249
        MockInteractions.focus(input.inputElement);
 
250
        assert(input.focused, 'input is focused');
 
251
        MockInteractions.blur(input.inputElement);
 
252
        assert(!input.focused, 'input is blurred');
 
253
      });
 
254
    });
 
255
 
 
256
    suite('focused styling (integration test)', function() {
 
257
 
 
258
      test('underline is colored when input is focused', function(done) {
 
259
        var input = fixture('basic');
 
260
        var container = Polymer.dom(input.root).querySelector('paper-input-container');
 
261
        var line = Polymer.dom(container.root).querySelector('.underline');
 
262
        assert.isFalse(line.classList.contains('is-highlighted'), 'line is not highlighted when input is not focused');
 
263
        MockInteractions.focus(input.inputElement);
 
264
        requestAnimationFrame(function() {
 
265
          assert.isTrue(line.classList.contains('is-highlighted'), 'line is highlighted when input is focused');
 
266
          done();
 
267
        });
 
268
      });
 
269
 
 
270
    });
 
271
 
 
272
    suite('validation', function() {
 
273
 
 
274
      test('invalid attribute updated after calling validate()', function() {
 
275
        var input = fixture('required-no-auto-validate');
 
276
        forceXIfStamp(input);
 
277
        input.validate();
 
278
        var error = Polymer.dom(input.root).querySelector('paper-input-error');
 
279
        assert.ok(error, 'paper-input-error exists');
 
280
        assert.notEqual(getComputedStyle(error).display, 'none', 'error is not display:none');
 
281
        assert.isTrue(input.invalid, 'invalid is true');
 
282
      });
 
283
 
 
284
    });
 
285
 
 
286
    suite('a11y', function() {
 
287
      test('has aria-labelledby, which is monotonically increasing', function() {
 
288
        var inputs = fixture('multiple-inputs');
 
289
 
 
290
        // Find the first index of the input in this fixture. Since the label
 
291
        // ids monotonically increase every time a new input is created, and
 
292
        // this fixture isn't the first one in the document, we're going to start
 
293
        // at an ID > 1.
 
294
        var firstLabel = Polymer.dom(inputs[0].root).querySelector('label').id;
 
295
        var index = parseInt(firstLabel.substr(firstLabel.lastIndexOf('-') + 1));
 
296
 
 
297
        for (var i = 0; i < inputs.length; i++ ) {
 
298
          var input = inputs[i].inputElement;
 
299
          var label = Polymer.dom(inputs[i].root).querySelector('label').id;
 
300
 
 
301
          assert.isTrue(input.hasAttribute('aria-labelledby'));
 
302
          assert.equal(label, 'paper-input-label-' + (index++));
 
303
          assert.equal(input.getAttribute('aria-labelledby'), label);
 
304
        }
 
305
      });
 
306
 
 
307
      test('has aria-describedby for error message', function() {
 
308
        var input = fixture('required');
 
309
        forceXIfStamp(input);
 
310
        assert.isTrue(input.inputElement.hasAttribute('aria-describedby'));
 
311
        assert.equal(input.inputElement.getAttribute('aria-describedby'), Polymer.dom(input.root).querySelector('paper-input-error').id, 'aria-describedby points to the error message');
 
312
      });
 
313
 
 
314
      test('has aria-describedby for character counter', function() {
 
315
        var input = fixture('char-counter');
 
316
        forceXIfStamp(input);
 
317
        assert.isTrue(input.inputElement.hasAttribute('aria-describedby'));
 
318
        assert.equal(input.inputElement.getAttribute('aria-describedby'), Polymer.dom(input.root).querySelector('paper-input-char-counter').id, 'aria-describedby points to the character counter');
 
319
      });
 
320
 
 
321
      test('has aria-describedby for character counter and error', function() {
 
322
        var input = fixture('required-char-counter');
 
323
        forceXIfStamp(input);
 
324
        assert.isTrue(input.inputElement.hasAttribute('aria-describedby'));
 
325
        assert.equal(input.inputElement.getAttribute('aria-describedby'), Polymer.dom(input.root).querySelector('paper-input-error').id + ' ' + Polymer.dom(input.root).querySelector('paper-input-char-counter').id, 'aria-describedby points to the error message and character counter');
 
326
      });
 
327
 
 
328
      test('focus an input with tabindex', function(done) {
 
329
        var input = fixture('has-tabindex');
 
330
        flush(function() {
 
331
          MockInteractions.focus(input);
 
332
          flush(function() {
 
333
            assert.equal(input.shadowRoot ? input.shadowRoot.activeElement :
 
334
                document.activeElement, input._focusableElement);
 
335
            done();
 
336
          });
 
337
        });
 
338
      });
 
339
    });
 
340
 
 
341
  </script>
 
342
 
 
343
</body>
 
344
</html>