Skip to content

Commit

Permalink
refactor: removed IE leftovers from src\client (#8001)
Browse files Browse the repository at this point in the history
<!--
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 13, 2023
1 parent 444e02d commit 93daea4
Show file tree
Hide file tree
Showing 6 changed files with 18 additions and 60 deletions.
2 changes: 1 addition & 1 deletion src/client/browser/idle-page/index.html.mustache
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge"/>
<meta http-equiv="X-UA-Compatible"/>
<title></title>
<script type="application/x-javascript" src="/browser/assets/index.js"></script>
<link rel="stylesheet" href="/browser/assets/styles.css"/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,35 +9,13 @@ import { utils } from '../../../deps/hammerhead';
// @ts-ignore
import { positionUtils } from '../../../deps/testcafe-core';


const nodeSnapshotPropertyInitializers = {
// eslint-disable-next-line no-restricted-properties
childNodeCount: (node: Node) => node.childNodes.length,
hasChildNodes: (node: Node) => !!nodeSnapshotPropertyInitializers.childNodeCount(node),

childElementCount: (node: Element) => {
const children = node.children;

if (children)
// eslint-disable-next-line no-restricted-properties
return children.length;

// NOTE: IE doesn't have `children` for non-element nodes =/
let childElementCount = 0;
// eslint-disable-next-line no-restricted-properties
const childNodeCount = node.childNodes.length;

for (let i = 0; i < childNodeCount; i++) {
// eslint-disable-next-line no-restricted-properties
if (node.childNodes[i].nodeType === 1)
childElementCount++;
}

return childElementCount;
},

childNodeCount: (node: Node) => node.childNodes.length,
hasChildNodes: (node: Node) => !!nodeSnapshotPropertyInitializers.childNodeCount(node),
childElementCount: (node: Element) => node.children?.length || 0,
// eslint-disable-next-line no-restricted-properties
hasChildElements: (node: Element) => !!nodeSnapshotPropertyInitializers.childElementCount(node),
hasChildElements: (node: Element) => !!nodeSnapshotPropertyInitializers.childElementCount(node),
};

class BaseSnapshot {
Expand Down
7 changes: 1 addition & 6 deletions src/client/test-run/index.js.mustache
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,7 @@
if (window !== window.top)
return;
var origin = location.origin;
// NOTE: location.origin doesn't exist in IE11 on Windows 10.10240 LTSB
if (!origin)
origin = location.protocol + '//' + location.hostname + (location.port ? ':' + location.port : '');
var origin = location.origin;
var nativeAutomation = {{{nativeAutomation}}};

if (nativeAutomation)
Expand Down
11 changes: 2 additions & 9 deletions src/client/ui/cursor/iframe-cursor.js
Original file line number Diff line number Diff line change
@@ -1,20 +1,13 @@
import hammerhead from '../deps/hammerhead';
import { sendRequestToFrame } from '../deps/testcafe-core';
import CURSOR_UI_MESSAGES from './messages';

const browserUtils = hammerhead.utils.browser;

// HACK: In most browsers, the iframe's getElementFromPoint function ignores elements
// from the parent frame. But in IE it doesn't, and our cursor overlaps the target
// element. So, we move the cursor to a position one pixel farther to avoid this.
const RECOGNITION_INCREMENT = browserUtils.isIE ? 1 : 0;

export default {
move (position) {
const msg = {
cmd: CURSOR_UI_MESSAGES.moveRequest,
x: position.x + RECOGNITION_INCREMENT,
y: position.y + RECOGNITION_INCREMENT,
x: position.x,
y: position.y,
};

return sendRequestToFrame(msg, CURSOR_UI_MESSAGES.moveResponse, window.parent);
Expand Down
5 changes: 1 addition & 4 deletions src/client/ui/cursor/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import CURSOR_UI_MESSAGES from './messages';

const Promise = hammerhead.Promise;
const shadowUI = hammerhead.shadowUI;
const browserUtils = hammerhead.utils.browser;
const featureDetection = hammerhead.utils.featureDetection;
const messageSandbox = hammerhead.eventSandbox.message;

Expand Down Expand Up @@ -55,9 +54,7 @@ const CursorUI = {
this.cursorElement = document.createElement('div');
shadowUI.addClass(this.cursorElement, CURSOR_CLASS);

// NOTE: For IE, we can't use the touch cursor in a cross-domain iframe
// because we won't be able to get an element under the cursor
if (featureDetection.isTouchDevice && !browserUtils.isIE) {
if (featureDetection.isTouchDevice) {
shadowUI.addClass(this.cursorElement, TOUCH_CLASS);

// NOTE: in touch mode, the pointer should be in the center of the cursor
Expand Down
23 changes: 9 additions & 14 deletions src/client/ui/select-element.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ const selectController = testCafeCore.selectController;

const OPTION_LIST_CLASS = 'tcOptionList';
const DISABLED_CLASS = 'disabled';
const MAX_OPTION_LIST_LENGTH = browserUtils.isIE ? 30 : 20;
const MAX_OPTION_LIST_LENGTH = 20;


function onDocumentMouseDown (e) {
Expand Down Expand Up @@ -57,32 +57,28 @@ function clickOnOption (optionIndex, isOptionDisabled) {
const realOption = curSelectEl.getElementsByTagName('option')[optionIndex];
const clickLeadChanges = !isOptionDisabled && optionIndex !== curSelectIndex;

if (clickLeadChanges && !browserUtils.isIE)
if (clickLeadChanges)
curSelectEl.selectedIndex = optionIndex;

if (!browserUtils.isFirefox && !browserUtils.isIE && clickLeadChanges) {
if (!browserUtils.isFirefox && clickLeadChanges) {
eventSimulator.input(curSelectEl);
eventSimulator.change(curSelectEl);
}

if (browserUtils.isFirefox || browserUtils.isIE)
if (browserUtils.isFirefox)
eventSimulator.mousedown(browserUtils.isFirefox ? realOption : curSelectEl);

if (!featureDetection.isTouchDevice)
eventSimulator.mouseup(browserUtils.isFirefox ? realOption : curSelectEl);

if ((browserUtils.isFirefox || browserUtils.isIE) && clickLeadChanges) {
if (browserUtils.isIE)
curSelectEl.selectedIndex = optionIndex;

if (!browserUtils.isIE)
eventSimulator.input(curSelectEl);
if (browserUtils.isFirefox && clickLeadChanges) {
eventSimulator.input(curSelectEl);

eventSimulator.change(curSelectEl);
}

if (!featureDetection.isTouchDevice)
eventSimulator.click(browserUtils.isFirefox || browserUtils.isIE ? realOption : curSelectEl);
eventSimulator.click(browserUtils.isFirefox ? realOption : curSelectEl);

if (!isOptionDisabled)
collapseOptionList();
Expand Down Expand Up @@ -198,7 +194,7 @@ export function switchOptionsByKeys (element, command) {
const optionListHidden = !styleUtils.hasDimensions(shadowUI.select('.' + OPTION_LIST_CLASS)[0]);

if (/down|up/.test(command) ||
!browserUtils.isIE && (selectSize <= 1 || browserUtils.isFirefox) &&
(selectSize <= 1 || browserUtils.isFirefox) &&
(optionListHidden || browserUtils.isFirefox) && /left|right/.test(command)) {
const realOptions = element.querySelectorAll('option');
const enabledOptions = [];
Expand All @@ -216,8 +212,7 @@ export function switchOptionsByKeys (element, command) {
if (nextIndex >= 0 && nextIndex < enabledOptions.length) {
element.selectedIndex = arrayUtils.indexOf(realOptions, enabledOptions[nextIndex]);

if (!browserUtils.isIE)
eventSimulator.input(element);
eventSimulator.input(element);

eventSimulator.change(element);
}
Expand Down

0 comments on commit 93daea4

Please sign in to comment.