var assert = chai.assert;
describe('Attachment API', function() {
this.timeout(kmwconfig.timeouts.standard);
before(function(done) {
assert.isFalse(com.keyman.karma.DEVICE_DETECT_FAILURE, "Cannot run due to device detection failure.");
fixture.setBase('unit_tests/fixtures');
this.timeout(kmwconfig.timeouts.scriptLoad * 3);
setupKMW({ attachType:'manual' }, function() {
loadKeyboardFromJSON("/keyboards/lao_2008_basic.json", function() {
// Sequential so we don't have to worry about race conditions and such
// to signal completion with done().
loadKeyboardFromJSON("/keyboards/khmer_angkor.json", function() {
keyman.setActiveKeyboard("lao_2008_basic");
done();
}, kmwconfig.timeouts.scriptLoad);
}, kmwconfig.timeouts.scriptLoad);
}, kmwconfig.timeouts.scriptLoad);
});
after(function() {
keyman.removeKeyboards('lao_2008_basic');
teardownKMW();
});
beforeEach(function() {
fixture.load("robustAttachment.html");
});
afterEach(function(done) {
fixture.cleanup();
window.setTimeout(function(){
done();
}, kmwconfig.timeouts.eventDelay);
});
it("Attachment/Detachment", function(done) {
// Since we're in 'manual', we start detached.
var ele = document.getElementById(DynamicElements.addInput());
window.setTimeout(function() {
// Ensure we didn't auto-attach.
DynamicElements.assertDetached(ele);
DynamicElements.keyCommand.simulateEventOn(ele);
var val = ele.value;
ele.value = "";
assert.equal(val, DynamicElements.disabledOutput, "'Detached' element performed keystroke processing!");
keyman.attachToControl(ele);
DynamicElements.assertAttached(ele); // Happens in-line, since we directly request the attachment.
// A keystroke must target the input-receiving element. For touch, that's the alias.
DynamicElements.keyCommand.simulateEventOn(ele['kmw_ip'] ? ele['kmw_ip'] : ele);
val = retrieveAndReset(ele);
assert.equal(val, DynamicElements.enabledLaoOutput, "'Attached' element did not perform keystroke processing!");
done();
}, kmwconfig.timeouts.eventDelay);
});
it("Enablement/Disablement", function(done) {
// Since we're in 'manual', we start detached.
var ele = document.getElementById(DynamicElements.addInput());
window.setTimeout(function() {
keyman.attachToControl(ele);
keyman.disableControl(ele);
// It appears that mobile devices do not instantly trigger the MutationObserver, so we need a small timeout
// for the change to take effect.
window.setTimeout(function() {
DynamicElements.assertAttached(ele);
DynamicElements.keyCommand.simulateEventOn(ele['kmw_ip'] ? ele['kmw_ip'] : ele);
val = retrieveAndReset(ele);
assert.equal(val, DynamicElements.disabledOutput, "'Disabled' element performed keystroke processing!");
keyman.enableControl(ele);
window.setTimeout(function() {
DynamicElements.assertAttached(ele); // Happens in-line, since we directly request the attachment.
DynamicElements.keyCommand.simulateEventOn(ele['kmw_ip'] ? ele['kmw_ip'] : ele);
val = retrieveAndReset(ele);
assert.equal(val, DynamicElements.enabledLaoOutput, "'Enabled' element did not perform keystroke processing!");
done();
}, kmwconfig.timeouts.eventDelay);
}, kmwconfig.timeouts.eventDelay);
}, kmwconfig.timeouts.eventDelay);
});
it("Keyboard Management (active control)", function() {
// It appears that event generation + inline event dispatching is a bit time-intensive on some browsers.
this.timeout(kmwconfig.timeouts.standard * 2);
var input = document.getElementById(DynamicElements.addInput());
var textarea = document.getElementById(DynamicElements.addText());
keyman.attachToControl(input);
keyman.attachToControl(textarea);
keyman.setActiveElement(input);
// We assume from the other tests that running on the Lao keyboard will give proper output.
// It'd be a redundant check.
// Set control with independent keyboard.
keyman.setKeyboardForControl(input, "khmer_angkor", "km");
DynamicElements.keyCommand.simulateEventOn(input['kmw_ip'] ? input['kmw_ip'] : input);
val = retrieveAndReset(input);
assert.equal(val, DynamicElements.enabledKhmerOutput, "KMW did not use control's keyboard settings!");
// Swap to a global-linked control...
keyman.setActiveElement(textarea);
DynamicElements.keyCommand.simulateEventOn(textarea['kmw_ip'] ? textarea['kmw_ip'] : textarea);
val = retrieveAndReset(textarea);
assert.equal(val, DynamicElements.enabledLaoOutput, "KMW did not use manage keyboard settings correctly for global-linked control!");
// Swap back and check that the settings persist.
keyman.setActiveElement(input);
DynamicElements.keyCommand.simulateEventOn(input['kmw_ip'] ? input['kmw_ip'] : input);
val = retrieveAndReset(input);
assert.equal(val, DynamicElements.enabledKhmerOutput, "KMW forgot control's independent keyboard settings!");
// Finally, clear the independent setting.
keyman.setKeyboardForControl(input, null, null);
DynamicElements.keyCommand.simulateEventOn(input['kmw_ip'] ? input['kmw_ip'] : input);
val = retrieveAndReset(input);
assert.equal(val, DynamicElements.enabledLaoOutput, "KMW did not properly clear control's independent keyboard settings!");
});
it("Keyboard Management (inactive control)", function() {
// It appears that event generation + inline event dispatching is a bit time-intensive on some browsers.
this.timeout(kmwconfig.timeouts.standard * 2);
var input = document.getElementById(DynamicElements.addInput());
var textarea = document.getElementById(DynamicElements.addText());
keyman.attachToControl(input);
keyman.attachToControl(textarea);
keyman.setActiveElement(input);
// We assume from the other tests that running on the Lao keyboard will give proper output.
// It'd be a redundant check.
// Set control with independent keyboard.
keyman.setKeyboardForControl(textarea, "khmer_angkor", "km");
DynamicElements.keyCommand.simulateEventOn(input['kmw_ip'] ? input['kmw_ip'] : input);
val = retrieveAndReset(input);
assert.equal(val, DynamicElements.enabledLaoOutput, "KMW set independent keyboard for the incorrect control!");
// Swap to a global-linked control...
keyman.setActiveElement(textarea);
DynamicElements.keyCommand.simulateEventOn(textarea['kmw_ip'] ? textarea['kmw_ip'] : textarea);
val = retrieveAndReset(textarea);
assert.equal(val, DynamicElements.enabledKhmerOutput, "KMW did not properly store keyboard for the previously-inactive control!");
// Swap back and check that the settings persist.
keyman.setActiveElement(input);
keyman.setKeyboardForControl(textarea, null, null);
DynamicElements.keyCommand.simulateEventOn(input['kmw_ip'] ? input['kmw_ip'] : input);
val = retrieveAndReset(input);
assert.equal(val, DynamicElements.enabledLaoOutput, "KMW made a strange error when clearing an inactive control's keyboard setting!");
keyman.setActiveElement(textarea);
// Finally, clear the independent setting.
DynamicElements.keyCommand.simulateEventOn(input['kmw_ip'] ? input['kmw_ip'] : input);
val = retrieveAndReset(input);
assert.equal(val, DynamicElements.enabledLaoOutput, "KMW did not properly clear control's independent keyboard settings!");
});
});
Modernizr.on('touchevents', function(result) {
if(result) {
describe('Device-specific Attachment Checks (Touch, \'auto\')', function() {
this.timeout(kmwconfig.timeouts.standard);
before(function(done) {
this.timeout(kmwconfig.timeouts.scriptLoad);
fixture.setBase('unit_tests/fixtures');
setupKMW({ attachType:'auto' }, done, kmwconfig.timeouts.scriptLoad);
});
beforeEach(function() {
fixture.load("robustAttachment.html");
});
after(function() {
teardownKMW();
});
afterEach(function(done) {
fixture.cleanup();
window.setTimeout(function(){
done();
}, kmwconfig.timeouts.eventDelay);
});
describe('Element Type', function() {
it('', function(done) {
var ID = DynamicElements.addInput();
var ele = document.getElementById(ID);
DynamicElements.assertAttached(ele, done);
});
it('