From b2515cf8cf18ad1581d3bc83e9b255ede3cd8389 Mon Sep 17 00:00:00 2001 From: helen-dikareva Date: Wed, 11 Apr 2018 10:29:38 +0300 Subject: [PATCH] test added --- .../client/fixtures/sandbox/selection-test.js | 88 +++++++++++++++++++ 1 file changed, 88 insertions(+) diff --git a/test/client/fixtures/sandbox/selection-test.js b/test/client/fixtures/sandbox/selection-test.js index 89dc645900..97b53302b8 100644 --- a/test/client/fixtures/sandbox/selection-test.js +++ b/test/client/fixtures/sandbox/selection-test.js @@ -7,6 +7,8 @@ var isIE = browserUtils.isIE; var isMobileBrowser = browserUtils.isIOS || browserUtils.isAndroid; var browserVersion = browserUtils.version; +var IE_FOCUS_TIMEOUT = 100; + var createTestInput = function (type, value) { var input = document.createElement('input'); @@ -80,3 +82,89 @@ test('Focus should stay on input with "number" type after setting selection', fu strictEqual(document.activeElement, input); document.body.removeChild(input); }); + +asyncTest('Focus should not be called during setting selection if conteneditable element has been already focused (TestCafe GH - 2301)', function () { + var isOldIE = browserUtils.isIE && browserUtils.version < 12; + var div = document.createElement('div'); + + div.setAttribute('contenteditable', 'true'); + div.textContent = 'some text'; + + document.body.appendChild(div); + + var focused = false; + var selectionSet = false; + + div.addEventListener('focus', function () { + focused = true; + }); + + selectionSandbox.wrapSetterSelection(div, function () { + selectionSet = true; + div.focus(); + }, true, true); + + window.setTimeout(function () { + if (!browserUtils.isFirefox) + ok(focused); + + ok(selectionSet); + strictEqual(document.activeElement, div); + + focused = false; + selectionSet = false; + + selectionSandbox.wrapSetterSelection(div, function () { + selectionSet = true; + }, true, true); + + window.setTimeout(function () { + notOk(focused); + ok(selectionSet); + strictEqual(document.activeElement, div); + + document.body.removeChild(div); + start(); + }, isOldIE ? IE_FOCUS_TIMEOUT : 0); + }, isOldIE ? IE_FOCUS_TIMEOUT : 0); +}); + +asyncTest('Focus should not be called during setting selection if editable element has been already focused (TestCafe GH - 2301)', function () { + var input = createTestInput('text', 'some text'); + var isOldIE = browserUtils.isIE && browserUtils.version < 12; + + var focused = false; + var selectionSet = false; + + input.addEventListener('focus', function () { + focused = true; + }); + + selectionSandbox.wrapSetterSelection(input, function () { + selectionSet = true; + input.focus(); + }, true, true); + + window.setTimeout(function () { + if (isOldIE) + ok(focused); + + ok(selectionSet); + strictEqual(document.activeElement, input); + + focused = false; + selectionSet = false; + + selectionSandbox.wrapSetterSelection(input, function () { + selectionSet = true; + }, true, true); + + window.setTimeout(function () { + notOk(focused); + ok(selectionSet); + strictEqual(document.activeElement, input); + + start(); + }, isOldIE ? IE_FOCUS_TIMEOUT : 0); + }, isOldIE ? IE_FOCUS_TIMEOUT : 0); +});