Skip to content

Commit

Permalink
fix issues with Chrome and whitespaces (DevExpress#2365)
Browse files Browse the repository at this point in the history
  • Loading branch information
AlexKamaev committed May 11, 2018
1 parent b3bb34c commit 1159c35
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 4 deletions.
7 changes: 5 additions & 2 deletions src/client/automation/playback/type/type-text.js
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,9 @@ function _typeTextToContentEditable (element, text) {
var endNode = currentSelection.endPos.node;
var needProcessInput = true;
var needRaiseInputEvent = true;
var textInputData = text;

text = text === ' ' ? String.fromCharCode(160) : text;

// NOTE: some browsers raise the 'input' event after the element
// content is changed, but in others we should do it manually.
Expand All @@ -156,7 +159,7 @@ function _typeTextToContentEditable (element, text) {
// NOTE: IE11 does not raise input event when type to contenteditable

var beforeContentChanged = () => {
needProcessInput = simulateTextInput(element, text);
needProcessInput = simulateTextInput(element, textInputData);
needRaiseInputEvent = needProcessInput && !browserUtils.isIE11;
};

Expand Down Expand Up @@ -251,7 +254,7 @@ function _typeTextToNonTextEditable (element, text, caretPos) {

export default function (element, text, caretPos) {
if (domUtils.isContentEditableElement(element))
_typeTextToContentEditable(element, text === ' ' ? String.fromCharCode(160) : text);
_typeTextToContentEditable(element, text);

if (!domUtils.isElementReadOnly(element)) {
if (domUtils.isTextEditableElement(element))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,6 @@ $(document).ready(function () {
var secondElementInnerHTML = null;
var thirdElementInnerHTML = null;

$('body').css('height', 1500).attr('contenteditable', 'true');

var startNext = function () {
if (browserUtils.isIE) {
removeTestElements();
Expand Down Expand Up @@ -91,6 +89,7 @@ $(document).ready(function () {
var nodeValue = node.nodeValue;
var typingText = '123 test';

$body.css('height', 1500).attr('contenteditable', 'true');
$body.focus();
equal(document.activeElement, $body[0]);

Expand All @@ -107,7 +106,39 @@ $(document).ready(function () {
nodeValue + typingText.replace(' ', String.fromCharCode(160)),
'typing must be in the end of element from a parameter of act.type');

$body.attr('contenteditable', 'false');

startNext();
});
});

if (!browserUtils.isFirefox) {
asyncTest('textInput eventArgs.data should contain space but not  )', function () {
var editor = document.createElement('div');
var text = ' ';
var type = new TypeAutomation(editor, text, {});

editor.className = TEST_ELEMENT_CLASS;
editor.contentEditable = true;

document.body.appendChild(editor);

var onTextInput = function (e) {
equal(e.data, text);

document.removeEventListener('textInput', onTextInput, true);
document.removeEventListener('textinput', onTextInput, true);
};

document.addEventListener('textInput', onTextInput, true);
document.addEventListener('textinput', onTextInput, true);

type
.run()
.then(function () {
startNext();
});
});
}

});

0 comments on commit 1159c35

Please sign in to comment.