New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
event should not work on iframe content (closes #1791, closes #1822 in testcafe) #1789
Changes from 5 commits
aa68f5e
b4d81fa
a6e2559
b310334
1352847
b2775b9
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -226,6 +226,26 @@ export function getElementRectangle (el) { | |
return rectangle; | ||
} | ||
|
||
export function shouldIgnoreMouseEventInsideIframe (el, x, y) { | ||
if (domUtils.getTagName(el) !== 'iframe') | ||
return false; | ||
|
||
const rect = getElementRectangle(el); | ||
const borders = styleUtils.getBordersWidth(el); | ||
const padding = styleUtils.getElementPadding(el); | ||
|
||
// NOTE: we detect element's 'content' position: left, right, top and bottom | ||
// which does not consider borders and paddings, so we need to | ||
// subtract it for right and bottom, and add for left and top | ||
|
||
const left = rect.left + borders.left + padding.left; | ||
const top = rect.top + borders.top + padding.top; | ||
const right = rect.left + rect.width - borders.right - padding.right; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Add comment for this line |
||
const bottom = rect.top + rect.height - borders.bottom - padding.bottom; | ||
|
||
return x >= left && x <= right && y >= top && y <= bottom; | ||
} | ||
|
||
function calcOffsetPosition (el, borders, offsetPosition) { | ||
const isSvg = domUtils.isSVGElementOrChild(el); | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,5 @@ | ||
var browserUtils = hammerhead.utils.browser; | ||
var eventUtils = hammerhead.utils.event; | ||
var nativeMethods = hammerhead.nativeMethods; | ||
var listeners = hammerhead.sandbox.event.listeners; | ||
var focusBlur = hammerhead.sandbox.event.focusBlur; | ||
|
@@ -314,6 +315,17 @@ test('should not wrap invalid event handlers (GH-1251)', function () { | |
}); | ||
|
||
strictEqual(listeningCtx.getEventCtx(target, 'click').wrappers.length, storedHandlerWrappersCount); | ||
|
||
// NOTE: we need to remove global event handlers before next test starts | ||
// we need try/catch statement because we have incorrect handler object | ||
handlers.forEach(function (handler) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why do we need a There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It is a test for invalid event handlers. See the line above: |
||
try { | ||
nativeMethods.windowRemoveEventListener.call(target, 'click', handler); | ||
} | ||
catch (e) { | ||
// | ||
} | ||
}); | ||
}; | ||
|
||
testHandlers(window); | ||
|
@@ -336,3 +348,132 @@ test('event.preventDefault call should change the event.defaultPrevented propert | |
|
||
eventSimulator.keydown(input); | ||
}); | ||
|
||
asyncTest('mouse events in iframe', function () { | ||
return createTestIframe() | ||
.then(function (iframe) { | ||
iframe.style.width = '300px'; | ||
iframe.style.height = '100px'; | ||
iframe.style.border = '5px solid black'; | ||
iframe.style.padding = '20px'; | ||
iframe.style.backgroundColor = 'yellow'; | ||
|
||
var div = document.createElement('div'); | ||
|
||
div.style.display = 'inline-block'; | ||
|
||
div.appendChild(iframe); | ||
document.body.appendChild(div); | ||
|
||
var actualEvents = []; | ||
|
||
var simulatorMethods = [ | ||
'mousedown', | ||
'mouseup', | ||
'mousemove', | ||
'mouseover', | ||
'mouseenter', | ||
'click', | ||
'dblclick', | ||
'contextmenu' | ||
]; | ||
|
||
var allEvents = [ | ||
'pointerdown', | ||
'mousedown', | ||
'pointerup', | ||
'mouseup', | ||
'pointermove', | ||
'mousemove', | ||
'pointerover', | ||
'mouseover', | ||
'mouseenter', | ||
'click', | ||
'dblclick', | ||
'contextmenu' | ||
]; | ||
|
||
var eventsInsideFrame = ['pointerover', 'mouseover', 'mouseenter']; | ||
|
||
if (!eventUtils.hasPointerEvents) { | ||
const pointerRegExp = /pointer(down|up|move|over)/; | ||
|
||
allEvents = allEvents.filter(function (eventName) { | ||
return !pointerRegExp.test(eventName); | ||
}); | ||
|
||
eventsInsideFrame = eventsInsideFrame.filter(function (eventName) { | ||
return !pointerRegExp.test(eventName); | ||
}); | ||
} | ||
|
||
var getHandler = function (i) { | ||
return function () { | ||
actualEvents.push(allEvents[i]); | ||
}; | ||
}; | ||
|
||
for (var i = 0; i < allEvents.length; i++) | ||
iframe.addEventListener(allEvents[i], getHandler(i)); | ||
|
||
for (i = 0; i < simulatorMethods.length; i++) | ||
eventSimulator[simulatorMethods[i]](iframe, { clientX: 190, clientY: 130 }); | ||
|
||
deepEqual(actualEvents, eventsInsideFrame); | ||
|
||
actualEvents = []; | ||
|
||
for (i = 0; i < simulatorMethods.length; i++) | ||
eventSimulator[simulatorMethods[i]](iframe, { clientX: 190, clientY: 70 }); | ||
|
||
deepEqual(actualEvents, allEvents); | ||
|
||
document.body.removeChild(div); | ||
|
||
start(); | ||
}); | ||
|
||
}); | ||
|
||
asyncTest('hover style in iframe', function () { | ||
return createTestIframe() | ||
.then(function (iframe) { | ||
var style = document.createElement('style'); | ||
var div = document.createElement('div'); | ||
|
||
div.style.display = 'inline-block'; | ||
style.innerHTML = 'iframe: hover { background-color: blue!important; }'; | ||
|
||
document.body.appendChild(style); | ||
document.body.appendChild(div); | ||
|
||
iframe.style.width = '300px'; | ||
iframe.style.height = '100px'; | ||
iframe.style.border = '5px solid black'; | ||
iframe.style.padding = '20px'; | ||
iframe.style.backgroundColor = 'yellow'; | ||
|
||
div.appendChild(iframe); | ||
|
||
var initialBackgroundColor = window.getComputedStyle(iframe).backgroundColor; | ||
|
||
eventSimulator.mouseover(iframe, { clientX: 190, clientY: 130 }); | ||
|
||
if (browserUtils.isIE) | ||
equal(window.getComputedStyle(iframe).backgroundColor, initialBackgroundColor); | ||
else | ||
notEqual(window.getComputedStyle(iframe).backgroundColor, initialBackgroundColor); | ||
|
||
eventSimulator.mouseover(div, { clientX: 0, clientY: 0 }); | ||
equal(window.getComputedStyle(iframe).backgroundColor, initialBackgroundColor); | ||
|
||
eventSimulator.mouseover(iframe, { clientX: 190, clientY: 70 }); | ||
notEqual(window.getComputedStyle(iframe).backgroundColor, initialBackgroundColor); | ||
|
||
document.body.removeChild(div); | ||
document.body.removeChild(style); | ||
|
||
start(); | ||
}); | ||
|
||
}); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think that the type conditions should be the first for performance improvement.