Skip to content

Commit

Permalink
refactor: removed IE leftovers from src\client\automation (part 1) (#…
Browse files Browse the repository at this point in the history
…7995)

<!--
Thank you for your contribution.

Before making a PR, please read our contributing guidelines at

https://github.com/DevExpress/testcafe/blob/master/CONTRIBUTING.md#code-contribution

We recommend creating a *draft* PR, so that you can mark it as 'ready
for review' when you are done.
-->

## Purpose
_Describe the problem you want to address or the feature you want to
implement._

## Approach
_Describe how your changes address the issue or implement the desired
functionality in as much detail as possible._

## References
_Provide a link to the existing issue(s), if any._

## Pre-Merge TODO
- [ ] Write tests for your proposed changes
- [ ] Make sure that existing tests do not fail
  • Loading branch information
Aleksey28 authored Sep 11, 2023
1 parent f2b4cd9 commit 74306a2
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 79 deletions.
31 changes: 6 additions & 25 deletions src/client/automation/playback/click/browser-click-strategy.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import hammerhead from '../../deps/hammerhead';
import testCafeCore from '../../deps/testcafe-core';
import { focusAndSetSelection } from '../../utils/utils';
import nextTick from '../../../core/utils/next-tick';
import createClickCommand from './click-command';

import { MouseEventArgs } from '../../visible-element-automation';
Expand Down Expand Up @@ -82,10 +81,9 @@ export class MouseClickStrategy {

this.activeElementBeforeMouseDown = activeElement;

// NOTE: In WebKit and IE, the mousedown event opens the select element's dropdown;
// NOTE: In WebKit, the mousedown event opens the select element's dropdown;
// therefore, we should prevent mousedown and hide the dropdown (B236416).
const needCloseSelectDropDown = (browserUtils.isWebKit || browserUtils.isIE) &&
domUtils.isSelectElement(this.mouseDownElement);
const needCloseSelectDropDown = browserUtils.isWebKit && domUtils.isSelectElement(this.mouseDownElement);

if (needCloseSelectDropDown)
this._bindMousedownHandler();
Expand Down Expand Up @@ -115,8 +113,7 @@ export class MouseClickStrategy {
listeners.removeInternalEventBeforeListener(window, ['mouseup'], getTimeStamp);
};

if (!browserUtils.isIE)
listeners.addInternalEventBeforeListener(window, ['mouseup'], getTimeStamp);
listeners.addInternalEventBeforeListener(window, ['mouseup'], getTimeStamp);

if (!this._isTouchEventWasCancelled())
eventSimulator.mouseup(element, eventArgs.options);
Expand Down Expand Up @@ -174,21 +171,8 @@ export class MouseClickStrategy {
return;
}

if (browserUtils.isIE && browserUtils.version < 12) {
// NOTE: In whatever way an element is blurred from the client script, the
// blur event is raised asynchronously in IE (in MSEdge focus/blur is sync)
nextTick()
.then(() => {
if (!this.eventState.blurRaised)
eventSimulator.blur(element);

resolve();
});
}
else {
eventSimulator.blur(element);
resolve();
}
eventSimulator.blur(element);
resolve();
});
}

Expand All @@ -201,10 +185,7 @@ export class MouseClickStrategy {
// element, a selection position may be calculated incorrectly (by using the caretPos option).
const elementForFocus = domUtils.isContentEditableElement(this.element) ? this.element : eventArgs.element;

// NOTE: IE doesn't perform focus if active element has been changed while executing mousedown
const simulateFocus = !browserUtils.isIE || this.activeElementBeforeMouseDown === domUtils.getActiveElement();

return focusAndSetSelection(elementForFocus, simulateFocus, this.caretPos);
return focusAndSetSelection(elementForFocus, true, this.caretPos);
}

private _raiseTouchEvents (eventArgs: MouseEventArgs): void {
Expand Down
20 changes: 3 additions & 17 deletions src/client/automation/playback/click/select-child.js
Original file line number Diff line number Diff line change
Expand Up @@ -64,11 +64,10 @@ export default class SelectChildClickAutomation {

_calculateEventArguments () {
const childElement = this.optionListExpanded ? selectController.getEmulatedChildElement(this.element) : this.element;
const parentSelectSize = styleUtils.getSelectElementSize(this.parentSelect) > 1;

return {
options: this.modifiers,
element: browserUtils.isIE && parentSelectSize ? this.parentSelect : childElement,
element: childElement,
};
}

Expand Down Expand Up @@ -123,12 +122,6 @@ export default class SelectChildClickAutomation {
return this._focus();
}

if (browserUtils.isIE) {
eventSimulator.mousedown(this.eventsArgs.element, this.eventsArgs.options);

return this._focus();
}

// NOTE: In Chrome, document.activeElement is 'select' after mousedown. But we need to
// raise blur and change the event for a previously active element during focus raising.
// That's why we should change the event order and raise focus before mousedown.
Expand All @@ -150,22 +143,15 @@ export default class SelectChildClickAutomation {
}

_mouseup () {
const elementForMouseupEvent = browserUtils.isIE ? this.parentSelect : this.eventsArgs.element;

eventSimulator.mouseup(elementForMouseupEvent, this.eventsArgs.options);

if (browserUtils.isIE && this.clickCausesChange)
this.parentSelect.selectedIndex = this.childIndex;
eventSimulator.mouseup(this.eventsArgs.element, this.eventsArgs.options);

const simulateInputEventOnValueChange = browserUtils.isFirefox || browserUtils.isSafari ||
browserUtils.isChrome && browserUtils.version >= 53;

const simulateChangeEventOnValueChange = simulateInputEventOnValueChange || browserUtils.isIE;

if (simulateInputEventOnValueChange && this.clickCausesChange)
eventSimulator.input(this.parentSelect);

if (simulateChangeEventOnValueChange && this.clickCausesChange)
if (simulateInputEventOnValueChange && this.clickCausesChange)
eventSimulator.change(this.parentSelect);

return Promise.resolve();
Expand Down
18 changes: 1 addition & 17 deletions src/client/automation/playback/move/event-sequence/base.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
import hammerhead from '../../../deps/hammerhead';
import { domUtils } from '../../../deps/testcafe-core';

const browserUtils = hammerhead.utils.browser;

export default class MoveEventSequenceBase {
constructor ({ moveEvent }) {
Expand Down Expand Up @@ -31,16 +29,6 @@ export default class MoveEventSequenceBase {
}

run (currentElement, prevElement, options, dragElement, dragDataStore) {
// NOTE: if last hovered element was in an iframe that has been removed, IE
// raises an exception when we try to compare it with the current element
const prevElementInDocument = prevElement && domUtils.isElementInDocument(prevElement);

const prevElementInRemovedIframe = prevElement && domUtils.isElementInIframe(prevElement) &&
!domUtils.getIframeByElement(prevElement);

if (!prevElementInDocument || prevElementInRemovedIframe)
prevElement = null;

const elementChanged = currentElement !== prevElement;
const commonAncestor = elementChanged ? domUtils.getCommonAncestor(currentElement, prevElement) : null;

Expand All @@ -49,14 +37,10 @@ export default class MoveEventSequenceBase {
if (elementChanged && !!prevElement)
this.leaveElement(currentElement, prevElement, commonAncestor, options);

if (browserUtils.isIE)
this.move(currentElement, options);

if (elementChanged && domUtils.isElementInDocument(currentElement))
this.enterElement(currentElement, prevElement, commonAncestor, options);

if (!browserUtils.isIE)
this.move(currentElement, options);
this.move(currentElement, options);

this.dragAndDrop(dragElement, currentElement, prevElement, options, dragDataStore);
this.teardown(currentElement, options, prevElement);
Expand Down
27 changes: 9 additions & 18 deletions src/client/automation/playback/press/key-press-simulator.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,27 +35,18 @@ export default class KeyPressSimulator {
const isActiveElementEditable = domUtils.isEditableElement(element);
const isStoredElementEditable = domUtils.isEditableElement(this.storedActiveElement);

// Unnecessary typing happens if an element was changed after the keydown/keypress event (T210448)
// In IE, this error may occur when we try to determine if the removed element is in an iframe
try {
if (elementChanged) {
const isActiveElementInIframe = domUtils.isElementInIframe(element);
const isStoredElementInIframe = domUtils.isElementInIframe(this.storedActiveElement);

const shouldTypeInWebKit = isActiveElementInIframe === isStoredElementInIframe || isStoredElementEditable;

shouldType = (!browserUtils.isFirefox || isStoredElementEditable) &&
(!browserUtils.isWebKit || shouldTypeInWebKit);
}
}
/*eslint-disable no-empty */
catch (err) {
}
/*eslint-disable no-empty */
if (elementChanged) {
const isActiveElementInIframe = domUtils.isElementInIframe(element);
const isStoredElementInIframe = domUtils.isElementInIframe(this.storedActiveElement);

const shouldTypeInWebKit = isActiveElementInIframe === isStoredElementInIframe || isStoredElementEditable;

shouldType = (!browserUtils.isFirefox || isStoredElementEditable) &&
(!browserUtils.isWebKit || shouldTypeInWebKit);
}

if (shouldType) {
if (!browserUtils.isIE && elementChanged && isStoredElementEditable && isActiveElementEditable)
if (elementChanged && isStoredElementEditable && isActiveElementEditable)
elementForTyping = this.storedActiveElement;

typeText(elementForTyping, char);
Expand Down
3 changes: 1 addition & 2 deletions src/client/automation/playback/press/shortcuts.js
Original file line number Diff line number Diff line change
Expand Up @@ -491,8 +491,7 @@ function enter (element) {

//submit form on enter pressed
if (domUtils.isInputElement(element)) {
if (!browserUtils.isIE)
elementEditingWatcher.processElementChanging(element);
elementEditingWatcher.processElementChanging(element);

const form = domUtils.getParents(element, 'form')[0];

Expand Down

0 comments on commit 74306a2

Please sign in to comment.