Skip to content

Commit 5eb8c3e

Browse files
committed
Firefox: fixing events generated as a result of click on an element that disappears after the click.
1 parent 0eec81d commit 5eb8c3e

File tree

4 files changed

+16
-12
lines changed

4 files changed

+16
-12
lines changed

java/client/test/org/openqa/selenium/CorrectEventFiringTest.java

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -31,23 +31,23 @@
3131
import static org.openqa.selenium.WaitingConditions.elementTextToEqual;
3232
import static org.openqa.selenium.WaitingConditions.elementValueToEqual;
3333
import static org.openqa.selenium.support.ui.ExpectedConditions.visibilityOfElementLocated;
34-
import static org.openqa.selenium.testing.Ignore.Driver.FIREFOX;
34+
import static org.openqa.selenium.testing.Ignore.Driver.CHROME;
3535
import static org.openqa.selenium.testing.Ignore.Driver.HTMLUNIT;
3636
import static org.openqa.selenium.testing.Ignore.Driver.IE;
3737
import static org.openqa.selenium.testing.Ignore.Driver.MARIONETTE;
3838
import static org.openqa.selenium.testing.Ignore.Driver.SAFARI;
3939

40-
import java.io.File;
41-
import java.io.IOException;
42-
import java.util.List;
43-
4440
import org.junit.Test;
4541
import org.openqa.selenium.testing.Ignore;
4642
import org.openqa.selenium.testing.JUnit4TestBase;
4743
import org.openqa.selenium.testing.JavascriptEnabled;
4844
import org.openqa.selenium.testing.TestUtilities;
4945
import org.openqa.selenium.testing.drivers.SauceDriver;
5046

47+
import java.io.File;
48+
import java.io.IOException;
49+
import java.util.List;
50+
5151
public class CorrectEventFiringTest extends JUnit4TestBase {
5252

5353
@JavascriptEnabled
@@ -414,7 +414,7 @@ public void testClickEventsShouldBubble() {
414414
}
415415

416416
@JavascriptEnabled
417-
@Ignore(value = {MARIONETTE, SAFARI, HTMLUNIT})
417+
@Ignore(value = {CHROME, MARIONETTE, SAFARI, HTMLUNIT})
418418
@Test
419419
public void testClickOverlappingElements() {
420420
driver.get(appServer.whereIs("click_tests/overlapping_elements.html"));
@@ -430,7 +430,7 @@ public void testClickOverlappingElements() {
430430
}
431431

432432
@JavascriptEnabled
433-
@Ignore(value = {FIREFOX, MARIONETTE, SAFARI, HTMLUNIT})
433+
@Ignore(value = {MARIONETTE, SAFARI, HTMLUNIT})
434434
@Test
435435
public void testClickAnElementThatDisappear() {
436436
driver.get(appServer.whereIs("click_tests/disappearing_element.html"));

javascript/atoms/action.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -253,14 +253,16 @@ bot.action.moveMouse = function(element, opt_coords, opt_mouse) {
253253
* @param {goog.math.Coordinate=} opt_coords Mouse position relative to the
254254
* element.
255255
* @param {bot.Mouse=} opt_mouse Mouse to use; if not provided, constructs one.
256+
* @param {boolean=} opt_force Whether the release event should be fired even if the
257+
* element is not interactable.
256258
* @throws {bot.Error} If the element cannot be interacted with.
257259
*/
258-
bot.action.click = function(element, opt_coords, opt_mouse) {
260+
bot.action.click = function(element, opt_coords, opt_mouse, opt_force) {
259261
var coords = bot.action.prepareToInteractWith_(element, opt_coords);
260262
var mouse = opt_mouse || new bot.Mouse();
261263
mouse.move(element, coords);
262264
mouse.pressButton(bot.Mouse.Button.LEFT);
263-
mouse.releaseButton();
265+
mouse.releaseButton(opt_force);
264266
};
265267

266268

javascript/atoms/mouse.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -277,8 +277,10 @@ bot.Mouse.prototype.pressButton = function(button) {
277277
/**
278278
* Releases the pressed mouse button. Throws exception if no button pressed.
279279
*
280+
* @param {boolean=} opt_force Whether the event should be fired even if the
281+
* element is not interactable.
280282
*/
281-
bot.Mouse.prototype.releaseButton = function() {
283+
bot.Mouse.prototype.releaseButton = function(opt_force) {
282284
if (goog.isNull(this.buttonPressed_)) {
283285
throw new bot.Error(bot.ErrorCode.UNKNOWN_ERROR,
284286
'Cannot release a button when no button is pressed.');
@@ -291,7 +293,7 @@ bot.Mouse.prototype.releaseButton = function() {
291293
// element becomes non-interactable after the mouseup.
292294
var elementInteractableBeforeMouseup =
293295
bot.dom.isInteractable(this.getElement());
294-
this.fireMouseEvent_(bot.events.EventType.MOUSEUP);
296+
this.fireMouseEvent_(bot.events.EventType.MOUSEUP, null, null, opt_force);
295297

296298
// TODO: Middle button can also trigger click.
297299
if (this.buttonPressed_ == bot.Mouse.Button.LEFT &&

javascript/firefox-driver/js/syntheticMouse.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -199,7 +199,7 @@ SyntheticMouse.prototype.click = function(target) {
199199

200200
} else {
201201
goog.log.info(SyntheticMouse.LOG_, 'About to do a bot.action.click on ' + element);
202-
bot.action.click(element, this.lastMousePosition, this.getMouse_());
202+
bot.action.click(element, this.lastMousePosition, this.getMouse_(), true);
203203
}
204204

205205
if (bot.dom.isEditable(element) && element.value !== undefined) {

0 commit comments

Comments
 (0)