This repository has been archived by the owner on Nov 3, 2021. It is now read-only.
/
keyboard_manager_test.js
778 lines (631 loc) · 25.2 KB
/
keyboard_manager_test.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
/*global
KeyboardManager, sinon, KeyboardHelper, MockKeyboardHelper,
MocksHelper, TransitionEvent, MockNavigatorSettings */
'use strict';
require('/shared/test/unit/mocks/mock_lazy_loader.js');
require('/shared/test/unit/mocks/mock_keyboard_helper.js');
require('/shared/test/unit/mocks/mock_settings_listener.js');
require('/shared/test/unit/mocks/mock_navigator_moz_settings.js');
require('/test/unit/mock_applications.js');
require('/test/unit/mock_homescreen_launcher.js');
requireApp('system/js/keyboard_manager.js');
var mocksHelperForKeyboardManager = new MocksHelper([
'SettingsListener',
'KeyboardHelper',
'LazyLoader',
'Applications'
]).init();
suite('KeyboardManager', function() {
var BLUR_CHANGE_DELAY = 100;
function trigger(event, detail) {
if (!detail) {
detail = {};
}
var evt = document.createEvent('CustomEvent');
evt.initCustomEvent(event, true, false, detail);
window.dispatchEvent(evt);
}
function inputChangeEvent(inputType) {
return new CustomEvent('mozChromeEvent', {
detail: {
type: 'inputmethod-contextchange',
inputType: inputType
}
});
}
function simulateInputChangeEvent(inputType) {
// we call the method directly because we can't send a direct event
// because otherwise in this test, we'll have n mozChromeEvent listeners
KeyboardManager.inputFocusChange(inputChangeEvent(inputType));
}
function setupHTML() {
var rc = document.querySelector('#run-container');
rc.innerHTML = '';
rc.innerHTML += '<div id="keyboard-show-ime-list">' +
'<div class="fake-notification"><div class="message tip"></div></div>' +
'</div>';
rc.innerHTML += '<div id="keyboards" class="hide">hoi</div>';
}
function dispatchEventForOpacity() {
var transitionEnd = new TransitionEvent(
'transitionend',
{
propertyName: 'opacity',
elapsedTime: 0.2
}
);
KeyboardManager.keyboardFrameContainer.dispatchEvent(transitionEnd);
}
function dispatchEventForTransform() {
var transitionEnd = new TransitionEvent(
'transitionend',
{
propertyName: 'transform',
elapsedTime: 0.4
}
);
KeyboardManager.keyboardFrameContainer.dispatchEvent(transitionEnd);
}
function dispatchTransitionEvents() {
dispatchEventForOpacity();
dispatchEventForTransform();
}
mocksHelperForKeyboardManager.attachTestHelpers();
var realMozSettings = null;
var realKeyboard = null;
suiteSetup(function() {
document.body.innerHTML += '<div id="run-container"></div>';
navigator.mozSettings = MockNavigatorSettings;
realKeyboard = window.navigator.mozInputMethod;
window.navigator.mozInputMethod = {
removeFocus: function() {}
};
});
suiteTeardown(function() {
navigator.mozSettings = realMozSettings;
window.navigator.mozInputMethod = realKeyboard;
});
setup(function() {
// we use sinon's fake timers for all the tests so that the timeouts used in
// the tested code in one test don't disturb the next test.
this.sinon.useFakeTimers();
setupHTML();
KeyboardManager.init();
});
suite('Transitions', function() {
setup(function() {
this.sinon.stub(KeyboardManager, 'showIMESwitcher');
});
suite('showKeyboard', function() {
test('triggers transition', function() {
assert.isTrue(
KeyboardManager.keyboardFrameContainer.classList.contains('hide')
);
KeyboardManager.showKeyboard();
assert.isFalse(
KeyboardManager.keyboardFrameContainer.classList.contains('hide')
);
});
test('waits the transition end before calling callback', function() {
var callback = sinon.stub();
KeyboardManager.showKeyboard(callback);
sinon.assert.notCalled(callback);
dispatchEventForOpacity();
sinon.assert.notCalled(callback,
'transitionend for opacity does not trigger the callback');
assert.isTrue(
'transitionIn' in KeyboardManager.keyboardFrameContainer.dataset,
'TransitionIn canceled due to opacity');
dispatchEventForTransform();
sinon.assert.called(callback,
'KeyboardChange was dispatched after the transform transition');
assert.isFalse(
'transitionIn' in KeyboardManager.keyboardFrameContainer.dataset,
'TransitionIn canceled due to opacity');
});
test('does not wait transition if already visible', function() {
KeyboardManager.showKeyboard();
dispatchTransitionEvents();
var callback = sinon.stub();
KeyboardManager.showKeyboard(callback);
// should be called immediately
sinon.assert.callCount(callback, 1);
});
});
});
suite('UpdateHeight', function() {
setup(function() {
this.sinon.stub(KeyboardManager, 'showIMESwitcher');
});
test('waits until transition finished', function() {
var called = false;
window.addEventListener('keyboardchange', function() {
called = true;
});
KeyboardManager.setKeyboardToShow('text');
KeyboardManager.resizeKeyboard({
detail: { height: 200 },
stopPropagation: sinon.stub()
});
assert.isFalse(called, 'KeyboardChange wait for the transition');
dispatchEventForOpacity();
assert.isFalse(called,
'KeyboardChange is not triggered for the opacity transition');
assert.isTrue(
'transitionIn' in KeyboardManager.keyboardFrameContainer.dataset,
'TransitionIn canceled due to opacity');
dispatchEventForTransform();
assert.isTrue(called,
'KeyboardChange was dispatched after the transform transition');
assert.isFalse(
'transitionIn' in KeyboardManager.keyboardFrameContainer.dataset,
'TransitionIn canceled due to opacity');
});
test('Second updateHeight evt triggers keyboardchange', function() {
var kcEvent = sinon.stub();
window.addEventListener('keyboardchange', kcEvent);
KeyboardManager.showKeyboard();
dispatchTransitionEvents();
KeyboardManager.resizeKeyboard({
detail: { height: 100 },
stopPropagation: function() {}
});
sinon.assert.callCount(kcEvent, 1);
sinon.assert.calledWithMatch(kcEvent, { detail: { height: 100 }});
kcEvent.reset();
KeyboardManager.resizeKeyboard({
detail: { height: 200 },
stopPropagation: function() {}
});
sinon.assert.callCount(kcEvent, 1);
sinon.assert.calledWithMatch(kcEvent,
{ detail: { height: 200 }});
});
});
suite('Switching keyboard focus', function() {
setup(function() {
this.sinon.stub(KeyboardManager, 'showKeyboard');
this.sinon.stub(KeyboardManager, 'hideKeyboard');
this.sinon.stub(KeyboardManager, 'hideIMESwitcher');
this.sinon.stub(KeyboardManager, 'showIMESwitcher');
this.sinon.stub(KeyboardManager, 'setKeyboardToShow');
this.sinon.stub(KeyboardManager, 'resetShowingKeyboard');
});
test('The event triggers inputFocusChange', function() {
this.sinon.stub(KeyboardManager, 'inputFocusChange');
var event = inputChangeEvent('text');
window.dispatchEvent(event);
sinon.assert.called(KeyboardManager.inputFocusChange);
});
suite('Switching inputType', function() {
setup(function() {
this.getLayouts = this.sinon.stub(KeyboardHelper, 'getLayouts');
this.checkDefaults = this.sinon.stub(KeyboardHelper, 'checkDefaults');
MockKeyboardHelper.watchCallback(KeyboardHelper.layouts,
{ apps: true });
});
test('Switching from "text" to "number"', function() {
simulateInputChangeEvent('text');
this.sinon.clock.tick(BLUR_CHANGE_DELAY);
simulateInputChangeEvent('number');
this.sinon.clock.tick(BLUR_CHANGE_DELAY);
sinon.assert.calledWith(KeyboardManager.setKeyboardToShow, 'text');
sinon.assert.calledWith(KeyboardManager.setKeyboardToShow, 'number');
sinon.assert.callCount(KeyboardManager.resetShowingKeyboard, 0);
});
test('Switching from "text" to "text"', function() {
simulateInputChangeEvent('text');
this.sinon.clock.tick(BLUR_CHANGE_DELAY);
simulateInputChangeEvent('text');
this.sinon.clock.tick(BLUR_CHANGE_DELAY);
sinon.assert.calledWith(KeyboardManager.setKeyboardToShow, 'text');
sinon.assert.notCalled(KeyboardManager.resetShowingKeyboard);
});
test('Switching from "text" to "select-one"', function() {
simulateInputChangeEvent('text');
this.sinon.clock.tick(BLUR_CHANGE_DELAY);
simulateInputChangeEvent('select-one');
this.sinon.clock.tick(BLUR_CHANGE_DELAY);
sinon.assert.called(KeyboardManager.hideKeyboard);
});
});
suite('keyboard type "url" - has enabled layouts', function() {
setup(function() {
this.getLayouts = this.sinon.stub(KeyboardHelper, 'getLayouts');
this.checkDefaults = this.sinon.stub(KeyboardHelper, 'checkDefaults');
MockKeyboardHelper.watchCallback(KeyboardHelper.layouts,
{ apps: true });
simulateInputChangeEvent('url');
this.sinon.clock.tick(BLUR_CHANGE_DELAY);
});
test('does not request layouts or defaults', function() {
assert.isFalse(this.getLayouts.called);
assert.isFalse(this.checkDefaults.called);
});
test('shows "url" keyboard', function() {
assert.ok(KeyboardManager.setKeyboardToShow.calledWith('url'));
});
});
suite('keyboard type "url" - no enabled layout', function() {
setup(function() {
this.saveToSettings = this.sinon.stub(KeyboardHelper, 'saveToSettings');
this.getLayouts = this.sinon.stub(KeyboardHelper, 'getLayouts');
// make this respond automatically
this.getLayouts.yields([]);
// trigger no keyboards in the first place
MockKeyboardHelper.watchCallback([], { apps: true, settings: true });
});
teardown(function() {
MockKeyboardHelper.watchCallback(KeyboardHelper.layouts,
{ apps: true });
});
suite('no defaults enabled', function() {
setup(function() {
this.checkDefaults = this.sinon.stub(KeyboardHelper, 'checkDefaults');
simulateInputChangeEvent('url');
this.sinon.clock.tick(BLUR_CHANGE_DELAY);
});
test('requests layouts', function() {
assert.ok(this.getLayouts.called);
});
test('requests defaults', function() {
assert.ok(this.checkDefaults.calledAfter(this.getLayouts));
});
test('reverts to "text" when no defaults', function() {
assert.ok(KeyboardManager.setKeyboardToShow.calledWith('text'));
});
});
suite('defaults enabled', function() {
setup(function() {
this.checkDefaults = this.sinon.stub(KeyboardHelper, 'checkDefaults',
function overrideCheckDefaults(callback) {
this.getLayouts.yields([KeyboardHelper.layouts[0]]);
callback();
}.bind(this));
simulateInputChangeEvent('url');
this.sinon.clock.tick(BLUR_CHANGE_DELAY);
});
test('requests layouts', function() {
assert.ok(this.getLayouts.called);
});
test('requests defaults', function() {
assert.ok(this.checkDefaults.called);
});
test('requests layouts again', function() {
assert.ok(this.getLayouts.calledAfter(this.checkDefaults));
});
test('saves', function() {
assert.ok(this.saveToSettings.called);
});
test('keeps "url" when defaults found', function() {
assert.ok(KeyboardManager.setKeyboardToShow.calledWith('url'));
});
});
});
});
suite('Switching keyboard focus before keyboard is shown', function() {
setup(function() {
this.sinon.stub(KeyboardManager, 'resetShowingKeyboard');
});
test('Switching from "text" to another field before' +
'the keyboard is shown.', function() {
simulateInputChangeEvent('text');
KeyboardManager.hideKeyboard();
sinon.assert.callCount(KeyboardManager.resetShowingKeyboard, 1);
});
});
suite('removeKeyboard test', function() {
var fakeFrame_A, fakeFrame_B;
setup(function() {
fakeFrame_A = {
manifestURL: 'app://keyboard.gaiamobile.org/manifest.webapp',
id: 'en'};
fakeFrame_B = {
manifestURL: 'app://keyboard-test.gaiamobile.org/manifest.webapp',
id: 'en'};
});
test('Not exist in runningLayouts', function() {
KeyboardManager.runningLayouts[fakeFrame_A.manifestURL] = {};
KeyboardManager.runningLayouts[fakeFrame_A.manifestURL][fakeFrame_A.id] =
this.sinon.stub;
KeyboardManager.removeKeyboard(fakeFrame_B.manifestURL);
assert.equal(
KeyboardManager.runningLayouts.hasOwnProperty(fakeFrame_A.manifestURL),
true);
});
test('Not in showingLayout', function() {
var hideKeyboard = this.sinon.stub(KeyboardManager, 'hideKeyboard');
KeyboardManager.runningLayouts[fakeFrame_B.manifestURL] = {};
KeyboardManager.runningLayouts[fakeFrame_B.manifestURL][fakeFrame_B.id] =
this.sinon.stub;
KeyboardManager.removeKeyboard(fakeFrame_B.manifestURL);
sinon.assert.callCount(hideKeyboard, 0);
assert.equal(
KeyboardManager.runningLayouts.hasOwnProperty(fakeFrame_B.manifestURL),
false);
});
test('In showingLayout', function() {
var hideKeyboard = this.sinon.stub(KeyboardManager, 'hideKeyboard');
var setKeyboardToShow =
this.sinon.stub(KeyboardManager, 'setKeyboardToShow');
KeyboardManager.runningLayouts[fakeFrame_A.manifestURL] = {};
KeyboardManager.runningLayouts[fakeFrame_A.manifestURL][fakeFrame_A.id] =
this.sinon.stub;
var fakeFrame = document.createElement('div');
fakeFrame.dataset.frameManifestURL =
'app://keyboard.gaiamobile.org/manifest.webapp';
KeyboardManager.showingLayout.frame = fakeFrame;
KeyboardManager.showingLayout.type = 'text';
KeyboardManager.removeKeyboard(fakeFrame_A.manifestURL, true);
sinon.assert.callCount(hideKeyboard, 1);
assert.ok(setKeyboardToShow.calledWith('text'));
assert.equal(
KeyboardManager.runningLayouts.hasOwnProperty(fakeFrame_A.manifestURL),
false);
});
});
suite('Event handler', function() {
var resizeKeyboard, hideKeyboardImmediately, removeKeyboard, hideKeyboard;
setup(function() {
resizeKeyboard = this.sinon.stub(KeyboardManager, 'resizeKeyboard');
hideKeyboard = this.sinon.stub(KeyboardManager, 'hideKeyboard');
hideKeyboardImmediately =
this.sinon.stub(KeyboardManager, 'hideKeyboardImmediately');
removeKeyboard = this.sinon.stub(KeyboardManager, 'removeKeyboard');
});
test('OOM event', function() {
var fakeFrame = document.createElement('div');
var fakeManifestURL = 'app://keyboard.gaiamobile.org/manifest.webapp';
fakeFrame.dataset.frameManifestURL = fakeManifestURL;
KeyboardManager.handleEvent({
type: 'mozbrowsererror',
target: fakeFrame
});
assert.ok(removeKeyboard.calledWith(fakeManifestURL));
});
test('mozbrowserresize event', function() {
KeyboardManager.handleEvent({
type: 'mozbrowserresize'
});
assert.ok(resizeKeyboard.called);
});
test('attentionscreenshow event', function() {
trigger('attentionscreenshow');
this.sinon.clock.tick();
sinon.assert.callCount(hideKeyboardImmediately, 1);
});
test('activityclosing event', function() {
trigger('activityclosing');
assert.ok(hideKeyboardImmediately.called);
});
test('activityopening event', function() {
trigger('activityopening');
assert.ok(hideKeyboardImmediately.called);
});
test('activityrequesting event', function() {
trigger('activityrequesting');
assert.ok(hideKeyboardImmediately.called);
});
test('applicationsetupdialogshow event', function() {
trigger('applicationsetupdialogshow');
assert.ok(hideKeyboardImmediately.called);
});
test('sheetstransitionstart event: do nothing if no keyboard', function() {
var spy = this.sinon.spy(navigator.mozInputMethod, 'removeFocus');
trigger('sheetstransitionstart');
assert.ok(spy.notCalled);
});
test('sheetstransitionstart event: hide keyboard if needed', function() {
var realActive = KeyboardManager.hasActiveKeyboard;
KeyboardManager.hasActiveKeyboard = true;
var spy = this.sinon.spy(navigator.mozInputMethod, 'removeFocus');
trigger('sheetstransitionstart');
sinon.assert.calledOnce(spy);
KeyboardManager.hasActiveKeyboard = realActive;
});
test('lock event: do nothing if no keyboard', function() {
var spy = this.sinon.spy(navigator.mozInputMethod, 'removeFocus');
trigger('lock');
assert.ok(spy.notCalled);
});
test('lock event: hide keyboard if needed', function() {
var realActive = KeyboardManager.hasActiveKeyboard;
KeyboardManager.hasActiveKeyboard = true;
var spy = this.sinon.spy(navigator.mozInputMethod, 'removeFocus');
trigger('lock');
sinon.assert.calledOnce(spy);
KeyboardManager.hasActiveKeyboard = realActive;
});
});
suite('Hide Keyboard', function() {
var rsk;
setup(function() {
KeyboardManager.keyboardFrameContainer.classList.remove('hide');
rsk = this.sinon.spy(KeyboardManager, 'resetShowingKeyboard');
});
test('resetShowingKeyboard wait until transition done', function() {
KeyboardManager.hideKeyboard();
sinon.assert.notCalled(rsk, 'Wait for transform transition');
dispatchEventForOpacity();
sinon.assert.notCalled(rsk, 'Still wait for transform transition');
dispatchEventForTransform();
sinon.assert.callCount(rsk, 1, 'resetShowingKeyboard was called');
});
test('Show immediately after hide should not destroy', function() {
KeyboardManager.hideKeyboard();
KeyboardManager.showKeyboard();
dispatchTransitionEvents();
sinon.assert.callCount(rsk, 0);
assert.isFalse(
KeyboardManager.keyboardFrameContainer.classList.contains('hide')
);
});
suite('HideImmediately', function() {
var kh, khed, container;
setup(function() {
kh = sinon.stub();
khed = sinon.stub();
window.addEventListener('keyboardhide', kh);
window.addEventListener('keyboardhidden', khed);
container = KeyboardManager.keyboardFrameContainer;
this.sinon.spy(container.classList, 'add');
KeyboardManager.hideKeyboardImmediately();
});
teardown(function() {
window.removeEventListener('keyboardhide', kh);
window.removeEventListener('keyboardhidden', khed);
});
test('should not play animation', function() {
sinon.assert.calledWith(
container.classList.add, 'notransition'
);
});
test('emits events', function() {
sinon.assert.callCount(rsk, 1, 'resetShowingKeyborad');
sinon.assert.callCount(kh, 1, 'keyboardhide event');
sinon.assert.callCount(khed, 1, 'keyboardhidden event');
});
});
suite('HideImmediately should not trigger event if already hidden',
function() {
var kh, khed, container;
setup(function() {
kh = sinon.stub();
khed = sinon.stub();
window.addEventListener('keyboardhide', kh);
window.addEventListener('keyboardhidden', khed);
container = KeyboardManager.keyboardFrameContainer;
container.classList.add('hide');
KeyboardManager.hideKeyboardImmediately();
});
teardown(function() {
window.removeEventListener('keyboardhide', kh);
window.removeEventListener('keyboardhidden', khed);
});
test('no events', function() {
sinon.assert.callCount(kh, 0, 'keyboardhide event');
sinon.assert.callCount(khed, 0, 'keyboardhidden event');
});
});
test('Hide emits events', function() {
var kh = sinon.stub();
var khed = sinon.stub();
window.addEventListener('keyboardhide', kh);
window.addEventListener('keyboardhidden', khed);
KeyboardManager.hideKeyboard();
sinon.assert.callCount(kh, 1, 'keyboardhide event');
var fakeEvt = new CustomEvent('transitionend');
fakeEvt.propertyName = 'transform';
KeyboardManager.keyboardFrameContainer.dispatchEvent(fakeEvt);
sinon.assert.callCount(rsk, 1, 'resetShowingKeyborad');
sinon.assert.callCount(kh, 1, 'keyboardhide event');
sinon.assert.callCount(khed, 1, 'keyboardhidden event');
});
});
suite('Show Keyboard', function() {
var rsk;
setup(function() {
KeyboardManager.keyboardFrameContainer.classList.add('hide');
this.sinon.stub(KeyboardManager, 'showIMESwitcher');
rsk = this.sinon.spy(KeyboardManager, 'resetShowingKeyboard');
});
test('Hide immediately after show should destroy', function() {
var called = false;
window.addEventListener('keyboardchange', function() {
called = true;
});
KeyboardManager.setKeyboardToShow('text');
KeyboardManager.resizeKeyboard({
detail: { height: 200 },
stopPropagation: sinon.stub()
});
KeyboardManager.hideKeyboard();
dispatchTransitionEvents();
sinon.assert.callCount(rsk, 1, 'ResetShowingKeyboard called');
assert.equal(called, false, 'KeyboardChange event fired');
assert.isTrue(
KeyboardManager.keyboardFrameContainer.classList.contains('hide'));
});
});
suite('mozbrowserresize event test', function() {
var showKeyboard;
setup(function() {
showKeyboard = this.sinon.stub(KeyboardManager, 'showKeyboard');
this.sinon.stub(KeyboardManager, 'showIMESwitcher');
});
function fakeMozbrowserResize(height) {
KeyboardManager.handleEvent({
type: 'mozbrowserresize',
detail: { height: height },
stopPropagation: sinon.stub()
});
}
test('height is zero.', function() {
fakeMozbrowserResize(0);
sinon.assert.callCount(showKeyboard, 0,
'showKeyboard should not be called');
});
test('keyboardFrameContainer is ready to show.', function() {
KeyboardManager.setKeyboardToShow('text');
fakeMozbrowserResize(200);
sinon.assert.callCount(showKeyboard, 1, 'showKeyboard should be called');
});
test('keyboardFrameContainer is hiding.', function() {
KeyboardManager.keyboardFrameContainer.classList.add('hide');
KeyboardManager.keyboardFrameContainer.dataset.transitionOut = 'true';
fakeMozbrowserResize(200);
sinon.assert.callCount(showKeyboard, 0,
'ignore mozbrowserresize event');
});
test('Switching keyboard.', function() {
KeyboardManager.setKeyboardToShow('text');
fakeMozbrowserResize(200);
KeyboardManager.keyboardFrameContainer.classList.remove('hide');
fakeMozbrowserResize(250);
assert.equal(KeyboardManager.keyboardHeight, 250);
sinon.assert.callCount(showKeyboard, 1,
'showKeyboard should be called');
});
test('keyboard is showing.', function() {
KeyboardManager.setKeyboardToShow('text');
fakeMozbrowserResize(300);
KeyboardManager.keyboardFrameContainer.classList.remove('hide');
KeyboardManager.keyboardFrameContainer.dataset.transitionIn = 'true';
fakeMozbrowserResize(350);
assert.equal(KeyboardManager.keyboardHeight, 350);
sinon.assert.callCount(showKeyboard, 1,
'showKeyboard should be called once');
});
});
suite('Focus and Blur', function() {
setup(function() {
this.sinon.stub(KeyboardManager, 'showKeyboard');
this.sinon.stub(KeyboardManager, 'hideKeyboard');
this.sinon.stub(KeyboardManager, 'setKeyboardToShow');
this.sinon.stub(KeyboardManager, 'showIMESwitcher');
KeyboardManager.keyboardLayouts = {
text: {
activeLayout: {}
}
};
});
test('Blur should hide', function() {
simulateInputChangeEvent('blur');
this.sinon.clock.tick(BLUR_CHANGE_DELAY);
sinon.assert.callCount(KeyboardManager.hideKeyboard, 1);
sinon.assert.notCalled(KeyboardManager.setKeyboardToShow);
});
test('Focus should show', function() {
simulateInputChangeEvent('text');
sinon.assert.notCalled(KeyboardManager.hideKeyboard);
sinon.assert.callCount(KeyboardManager.setKeyboardToShow, 1);
});
test('Blur followed by focus should not hide', function() {
simulateInputChangeEvent('blur');
simulateInputChangeEvent('text');
this.sinon.clock.tick(BLUR_CHANGE_DELAY);
sinon.assert.callCount(KeyboardManager.hideKeyboard, 0);
sinon.assert.callCount(KeyboardManager.setKeyboardToShow, 1);
});
});
});