From 93daea4c949b278bf9fe4857f1ecee4c26f71053 Mon Sep 17 00:00:00 2001 From: Popov Aleksey Date: Tue, 12 Sep 2023 23:37:51 -0700 Subject: [PATCH] refactor: removed IE leftovers from src\client (#8001) ## 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 --- .../browser/idle-page/index.html.mustache | 2 +- .../selector-executor/node-snapshots.ts | 30 +++---------------- src/client/test-run/index.js.mustache | 7 +---- src/client/ui/cursor/iframe-cursor.js | 11 ++----- src/client/ui/cursor/index.js | 5 +--- src/client/ui/select-element.js | 23 ++++++-------- 6 files changed, 18 insertions(+), 60 deletions(-) diff --git a/src/client/browser/idle-page/index.html.mustache b/src/client/browser/idle-page/index.html.mustache index 117bba06dce..099e4c24b5b 100644 --- a/src/client/browser/idle-page/index.html.mustache +++ b/src/client/browser/idle-page/index.html.mustache @@ -2,7 +2,7 @@ - + diff --git a/src/client/driver/command-executors/client-functions/selector-executor/node-snapshots.ts b/src/client/driver/command-executors/client-functions/selector-executor/node-snapshots.ts index c1d5e73bb2e..20aed04cb9a 100644 --- a/src/client/driver/command-executors/client-functions/selector-executor/node-snapshots.ts +++ b/src/client/driver/command-executors/client-functions/selector-executor/node-snapshots.ts @@ -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 { diff --git a/src/client/test-run/index.js.mustache b/src/client/test-run/index.js.mustache index eeb3170e265..794b3a83aa3 100644 --- a/src/client/test-run/index.js.mustache +++ b/src/client/test-run/index.js.mustache @@ -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) diff --git a/src/client/ui/cursor/iframe-cursor.js b/src/client/ui/cursor/iframe-cursor.js index 1d2484a7dac..3951a5bd491 100644 --- a/src/client/ui/cursor/iframe-cursor.js +++ b/src/client/ui/cursor/iframe-cursor.js @@ -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); diff --git a/src/client/ui/cursor/index.js b/src/client/ui/cursor/index.js index 8ff3f0568b7..4d236ddd8ef 100644 --- a/src/client/ui/cursor/index.js +++ b/src/client/ui/cursor/index.js @@ -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; @@ -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 diff --git a/src/client/ui/select-element.js b/src/client/ui/select-element.js index cd3bbd911c9..8a65fa8d6c6 100644 --- a/src/client/ui/select-element.js +++ b/src/client/ui/select-element.js @@ -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) { @@ -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(); @@ -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 = []; @@ -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); }