From fe16afbca41496046ddf52727274f89bde8bcf2b Mon Sep 17 00:00:00 2001 From: Adil Rakhaliyev <67043367+Bayheck@users.noreply.github.com> Date: Wed, 29 May 2024 15:05:40 +0500 Subject: [PATCH] Positioning to multiline elements (#3004) * testing * fix tests * fix pr comments * fix pr comments * isolate windows 10 chrome cloud tests * isolate windows 10 chrome cloud tests * test skipped for chrome * test skipped for chrome * fixing tests * testing * restore * testing * testing * testing * testing * testing * testing * testing * testing * testing * testing * testing * testing * testing * testing * testing * testing * testing * testing * testing * testing * testing --------- Co-authored-by: Bayheck --- src/client/utils/dom.ts | 4 ++ src/client/utils/position.ts | 2 +- src/client/utils/style.ts | 4 +- .../fixtures/sandbox/node/classes-test.js | 47 +++++++++++++++++-- 4 files changed, 50 insertions(+), 7 deletions(-) diff --git a/src/client/utils/dom.ts b/src/client/utils/dom.ts index 2fba46243..8cc00e5a8 100644 --- a/src/client/utils/dom.ts +++ b/src/client/utils/dom.ts @@ -898,3 +898,7 @@ export function getAssociatedElement (el: HTMLElement): HTMLElement | null { return el.control || el.htmlFor && nativeMethods.getElementById.call(doc, el.htmlFor); } + +export function getClientRectangle (el: HTMLElement): DOMRect { + return el.getClientRects()[0] ?? el.getBoundingClientRect(); +} diff --git a/src/client/utils/position.ts b/src/client/utils/position.ts index df0427d34..bb7b055cc 100644 --- a/src/client/utils/position.ts +++ b/src/client/utils/position.ts @@ -209,7 +209,7 @@ export function getElementRectangle (el) { rectangle = getSelectChildRectangle(el); else { const elementOffset = getOffsetPosition(el); - const relativeRectangle = domUtils.isSVGElementOrChild(el) ? getSvgElementRelativeRectangle(el) : el.getBoundingClientRect(); + const relativeRectangle = domUtils.isSVGElementOrChild(el) ? getSvgElementRelativeRectangle(el) : domUtils.getClientRectangle(el); rectangle = { height: relativeRectangle.height, diff --git a/src/client/utils/style.ts b/src/client/utils/style.ts index 2f307350b..7bf584f07 100644 --- a/src/client/utils/style.ts +++ b/src/client/utils/style.ts @@ -319,7 +319,7 @@ export function getOffset (el) { if (!el || domUtils.isWindow(el) || domUtils.isDocument(el)) return null; - let clientRect = el.getBoundingClientRect(); + let clientRect = domUtils.getClientRectangle(el); // NOTE: A detached node or documentElement. const doc = el.ownerDocument; @@ -338,7 +338,7 @@ export function getOffset (el) { const scrollTop = win.pageYOffset || docElement.scrollTop || doc.body.scrollTop; const scrollLeft = win.pageXOffset || docElement.scrollLeft || doc.body.scrollLeft; - clientRect = el.getBoundingClientRect(); + clientRect = domUtils.getClientRectangle(el); return { top: clientRect.top + scrollTop - clientTop, diff --git a/test/client/fixtures/sandbox/node/classes-test.js b/test/client/fixtures/sandbox/node/classes-test.js index 1c0047c77..ddc2494db 100644 --- a/test/client/fixtures/sandbox/node/classes-test.js +++ b/test/client/fixtures/sandbox/node/classes-test.js @@ -10,6 +10,35 @@ var browserUtils = hammerhead.utils.browser; var nativeMethods = hammerhead.nativeMethods; var isFirefox = browserUtils.isFirefox; +var isChrome = browserUtils.isChrome; + +function testInvalidWebSocketUrl (url) { + asyncTest('WebSocket constructor with invalid URL ' + url + ' throws async error', function () { + expect(1); + + var socket; + + try { + socket = new WebSocket(url); + } + catch (e) { + ok(true, 'WebSocket connection failed as expected for ' + url + '.'); + start(); + } + + if (socket) { + socket.onerror = function () { + ok(true, 'WebSocket connection failed as expected for ' + url + '.'); + start(); + }; + + socket.onopen = function () { + ok(false, 'WebSocket connection unexpectedly succeeded for ' + url + '.'); + start(); + }; + } + }); +} if (window.PerformanceNavigationTiming) { test('PerformanceNavigationTiming.name', function () { @@ -542,11 +571,11 @@ if (window.WebSocket) { new WebSocket(); }); - throws(function () { - new WebSocket(''); - }); + if (!(isFirefox || isChrome)) { + throws(function () { + new WebSocket(''); + }); - if (!isFirefox) { throws(function () { new WebSocket('/path'); }); @@ -561,6 +590,16 @@ if (window.WebSocket) { } }); /* eslint-enable no-new */ + + const invalidUrls = [ + { url: '' }, + { url: '/path' }, + { url: '//example.com' }, + { url: 'http://example.com' }, + ]; + + for (let i = 0; i < invalidUrls.length; i++) + testInvalidWebSocketUrl(invalidUrls[i].url); } module('regression');