[ChromeDriver] Fixed Selenium test bugs

In W3C mode the offset of an element is measured relative to
the center of the element and in legacy mode the offset
is measured relative to the upper-left corner.
Changed some Selenium tests to conform these W3C standards.


Change-Id: I1a9098785b07a347ee0e416b90482b55c90f90c1
diff --git a/jar/tests-selenium.jar b/jar/tests-selenium.jar
index 4dfba12..47e05d1 100644
--- a/jar/tests-selenium.jar
+++ b/jar/tests-selenium.jar
Binary files differ
diff --git a/seleniumHQ.patch b/seleniumHQ.patch
index 58a7575..33855a2 100644
--- a/seleniumHQ.patch
+++ b/seleniumHQ.patch
@@ -1,5 +1,5 @@
 diff --git a/java/client/src/org/openqa/selenium/chrome/ChromeOptions.java b/java/client/src/org/openqa/selenium/chrome/ChromeOptions.java
-index 2a72c55ab7..4cfabe2510 100644
+index f6c9071d23..de319b3811 100644
 --- a/java/client/src/org/openqa/selenium/chrome/ChromeOptions.java
 +++ b/java/client/src/org/openqa/selenium/chrome/ChromeOptions.java
 @@ -70,6 +70,9 @@
@@ -191,6 +191,95 @@
  
      TemporaryFilesystem tempFs = TemporaryFilesystem.getDefaultTmpFS();
      tempPageDir = tempFs.createTempDir("pages", "test");
+diff --git a/java/client/test/org/openqa/selenium/interactions/BasicKeyboardInterfaceTest.java b/java/client/test/org/openqa/selenium/interactions/BasicKeyboardInterfaceTest.java
+index f79ae7d559..3a3602df07 100644
+--- a/java/client/test/org/openqa/selenium/interactions/BasicKeyboardInterfaceTest.java
++++ b/java/client/test/org/openqa/selenium/interactions/BasicKeyboardInterfaceTest.java
+@@ -257,6 +257,8 @@ public void testSelectionSelectByWord() {
+     getBuilder(driver).click(input).sendKeys("abc def").perform();
+     wait.until(ExpectedConditions.attributeToBe(input, "value", "abc def"));
+ 
++    ((Interactive)driver).resetInputState();
++
+     getBuilder(driver).click(input)
+         .keyDown(Keys.SHIFT)
+         .keyDown(Keys.CONTROL)
+diff --git a/java/client/test/org/openqa/selenium/interactions/BasicMouseInterfaceTest.java b/java/client/test/org/openqa/selenium/interactions/BasicMouseInterfaceTest.java
+index e52e8f46cb..2ec8da142d 100644
+--- a/java/client/test/org/openqa/selenium/interactions/BasicMouseInterfaceTest.java
++++ b/java/client/test/org/openqa/selenium/interactions/BasicMouseInterfaceTest.java
+@@ -373,7 +373,7 @@ public void testMovingMouseToRelativeElementOffset() {
+     driver.get(pages.mouseTrackerPage);
+ 
+     WebElement trackerDiv = driver.findElement(By.id("mousetracker"));
+-    new Actions(driver).moveToElement(trackerDiv, 95, 195).perform();
++    new Actions(driver).moveToElement(trackerDiv, 45, -5).perform();
+ 
+     WebElement reporter = driver.findElement(By.id("status"));
+ 
+@@ -389,7 +389,7 @@ public void testMovingMouseToRelativeZeroElementOffset() {
+     driver.get(pages.mouseTrackerPage);
+ 
+     WebElement trackerDiv = driver.findElement(By.id("mousetracker"));
+-    new Actions(driver).moveToElement(trackerDiv, 0, 0).perform();
++    new Actions(driver).moveToElement(trackerDiv, -50, -200).perform();
+ 
+     WebElement reporter = driver.findElement(By.id("status"));
+ 
+@@ -430,15 +430,16 @@ public void testMoveMouseByOffsetOverAndOutOfAnElement() {
+     int shiftX = redboxPosition.getX() - greenboxPosition.getX();
+     int shiftY = redboxPosition.getY() - greenboxPosition.getY();
+ 
+-    new Actions(driver).moveToElement(greenbox, 2, 2).perform();
++    Dimension greenBoxSize = greenbox.getSize();
+ 
++    new Actions(driver).moveToElement(greenbox, 2 - greenBoxSize.getWidth()/2, 2 - greenBoxSize.getHeight()/2).perform();
+     shortWait.until(attributeToBe(redbox, "background-color", Colors.GREEN.getColorValue().asRgba()));
+ 
+-    new Actions(driver).moveToElement(greenbox, 2, 2)
++    new Actions(driver).moveToElement(greenbox, 2 - greenBoxSize.getWidth()/2, 2 - greenBoxSize.getHeight()/2)
+       .moveByOffset(shiftX, shiftY).perform();
+     shortWait.until(attributeToBe(redbox, "background-color", Colors.RED.getColorValue().asRgba()));
+ 
+-    new Actions(driver).moveToElement(greenbox, 2, 2)
++    new Actions(driver).moveToElement(greenbox, 2 - greenBoxSize.getWidth()/2, 2 - greenBoxSize.getHeight()/2)
+       .moveByOffset(shiftX, shiftY)
+       .moveByOffset(-shiftX, -shiftY).perform();
+ 
+@@ -457,7 +458,7 @@ public void testCanMoveOverAndOutOfAnElement() {
+     WebElement redbox = driver.findElement(By.id("redbox"));
+     Dimension size = redbox.getSize();
+ 
+-    new Actions(driver).moveToElement(greenbox, 1, 1).perform();
++    new Actions(driver).moveToElement(greenbox, 1 - size.getWidth()/2, 1 - size.getHeight()/2).perform();
+ 
+     assertThat(Color.fromString(redbox.getCssValue("background-color")))
+         .isEqualTo(GREEN.getColorValue());
+diff --git a/java/client/test/org/openqa/selenium/interactions/CombinedInputActionsTest.java b/java/client/test/org/openqa/selenium/interactions/CombinedInputActionsTest.java
+index db1bdb6a73..ec2e2a0bb4 100644
+--- a/java/client/test/org/openqa/selenium/interactions/CombinedInputActionsTest.java
++++ b/java/client/test/org/openqa/selenium/interactions/CombinedInputActionsTest.java
+@@ -46,6 +46,7 @@
+ import org.openqa.selenium.testing.JUnit4TestBase;
+ import org.openqa.selenium.testing.NotYetImplemented;
+ import org.openqa.selenium.testing.SwitchToTopAfterTest;
++import org.openqa.selenium.Dimension;
+ 
+ import java.util.List;
+ 
+@@ -226,10 +227,11 @@ public void testClickAfterMoveToAnElementWithAnOffsetShouldUseLastMousePosition(
+     driver.get(pages.clickEventPage);
+ 
+     WebElement element = driver.findElement(By.id("eventish"));
++    Dimension elementSize = element.getSize();
+     Point location = element.getLocation();
+ 
+     new Actions(driver)
+-        .moveToElement(element, 20, 10)
++        .moveToElement(element, 20 - elementSize.getWidth()/2, 10 - elementSize.getHeight()/2)
+         .click()
+         .perform();
+ 
 diff --git a/java/client/test/org/openqa/selenium/testing/JUnit4TestBase.java b/java/client/test/org/openqa/selenium/testing/JUnit4TestBase.java
 index 1cd5ef93ab..49b3a64b69 100644
 --- a/java/client/test/org/openqa/selenium/testing/JUnit4TestBase.java
@@ -419,10 +508,10 @@
        options.merge(originalCapabilities);
      }
 diff --git a/java/client/test/org/openqa/selenium/testing/drivers/WebDriverBuilder.java b/java/client/test/org/openqa/selenium/testing/drivers/WebDriverBuilder.java
-index 0a19551a9a..bbf82e7a38 100644
+index e9eef28687..5b7fe7ea6b 100644
 --- a/java/client/test/org/openqa/selenium/testing/drivers/WebDriverBuilder.java
 +++ b/java/client/test/org/openqa/selenium/testing/drivers/WebDriverBuilder.java
-@@ -47,8 +47,12 @@
+@@ -49,8 +49,12 @@
    private static LinkedList<Runnable> shutdownActions = new LinkedList<>();
    private static Set<WebDriver> managedDrivers = new HashSet<>();
    static {