Skip to content
This repository has been archived by the owner on Jun 24, 2021. It is now read-only.

JDK-8207369 Add more robot tests. #215

Merged
merged 1 commit into from
Dec 6, 2018

Conversation

brcolow
Copy link
Contributor

@brcolow brcolow commented Sep 24, 2018

(Partially? at least a step in the right direction...) resolves robot API follow-up issue JDK-8207369.

@eugener eugener added the enhancement New feature or request label Sep 25, 2018
Copy link
Collaborator

@kevinrushforth kevinrushforth left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks like the right set of tests. I get several failures, though (I only tested Linux).

test.robot.javafx.scene.RobotTest > testKeyRelease FAILED
    org.junit.ComparisonFailure: letter 'a' should be RELEASED by Robot expected:<[a]> but was:<[]>
        at org.junit.Assert.assertEquals(Assert.java:123)
        at test.robot.javafx.scene.RobotTest.testKeyboard(RobotTest.java:190)
        at test.robot.javafx.scene.RobotTest.testKeyRelease(RobotTest.java:136)

test.robot.javafx.scene.RobotTest > testMouseReleasePrimary FAILED
    java.lang.AssertionError: Timeout while waiting for button.onMouseRELEASED().
        at org.junit.Assert.fail(Assert.java:91)
        at test.robot.javafx.scene.RobotTest.waitForLatch(RobotTest.java:728)
        at test.robot.javafx.scene.RobotTest.testMouseAction(RobotTest.java:417)
        at test.robot.javafx.scene.RobotTest.testMouseReleasePrimary(RobotTest.java:311)

test.robot.javafx.scene.RobotTest > testMouseReleaseSecondary FAILED
    java.lang.AssertionError: Timeout while waiting for button.onMouseRELEASED().
        at org.junit.Assert.fail(Assert.java:91)
        at test.robot.javafx.scene.RobotTest.waitForLatch(RobotTest.java:728)
        at test.robot.javafx.scene.RobotTest.testMouseAction(RobotTest.java:417)
        at test.robot.javafx.scene.RobotTest.testMouseReleaseSecondary(RobotTest.java:316)

test.robot.javafx.scene.RobotTest > testMouseRelaseMiddle FAILED
    java.lang.AssertionError: Timeout while waiting for button.onMouseRELEASED().
        at org.junit.Assert.fail(Assert.java:91)
        at test.robot.javafx.scene.RobotTest.waitForLatch(RobotTest.java:728)
        at test.robot.javafx.scene.RobotTest.testMouseAction(RobotTest.java:417)
        at test.robot.javafx.scene.RobotTest.testMouseRelaseMiddle(RobotTest.java:321)

test.robot.javafx.scene.RobotTest > testMouseWheelPositiveAmount FAILED
    org.junit.ComparisonFailure: mouse wheel should be scrolled 5 vertical units by Robot expected:<Scrolled [5]> but was:<Scrolled [-40.0]>
        at org.junit.Assert.assertEquals(Assert.java:123)
        at test.robot.javafx.scene.RobotTest.testMouseWheel(RobotTest.java:525)
        at test.robot.javafx.scene.RobotTest.testMouseWheelPositiveAmount(RobotTest.java:490)

test.robot.javafx.scene.RobotTest > testMouseWheelNegativeAmount FAILED
    org.junit.ComparisonFailure: mouse wheel should be scrolled -5 vertical units by Robot expected:<Scrolled [-5]> but was:<Scrolled [40.0]>
        at org.junit.Assert.assertEquals(Assert.java:123)
        at test.robot.javafx.scene.RobotTest.testMouseWheel(RobotTest.java:525)
        at test.robot.javafx.scene.RobotTest.testMouseWheelNegativeAmount(RobotTest.java:495)

@brcolow
Copy link
Contributor Author

brcolow commented Nov 26, 2018

I think the failures (besides the mouse scroll amount which seems to be hardcoded to a value of (-)40 on Linux) are happening because you can't release "in a vacuum" without a preceding press. I will remove the keyboard and mouse tests that only release, but will keep the press only and press and release tests.

@brcolow
Copy link
Contributor Author

brcolow commented Nov 26, 2018

The mouse scroll wheel failure is kind of interesting. Basically the GtkRobot sends multiple fake mouse buttons presses (4 for scroll up, 5 for scroll down), one for each int of the wheelAmt. Therefore I think what I can do is add a sort of timed collection to accumulate all scroll events sent to the Button and then add them up. I may still need to mess with the multiplier though on a system-dependent basis which is going to be ugly. The reason for this is that the JavaFX event handler will get 5 scroll events each with a scroll amount of (+/-) 40 for a total of 200. Then one would need to divide by the multiplier to match the passed-in wheelAmt.

Edit: Actually I may be able to use event.getTotalDeltaY...investigating that now.

@brcolow
Copy link
Contributor Author

brcolow commented Nov 27, 2018

For some reason event.getTotalDeltaY() reports 0. But I was able to hack something together that passes on Windows and Linux. Still need to test macOS.

@brcolow
Copy link
Contributor Author

brcolow commented Nov 28, 2018

I finally was able to test and fix the new tests on macOS. I have now confirmed that the new tests pass locally for me on all 3 operating systems. I am not really happy with the approach I took in order to get a unified scroll amount between platforms but wasn't sure of an alternative approach.

@brcolow
Copy link
Contributor Author

brcolow commented Nov 30, 2018

The new drag tests pass locally for me on Windows but seem to fail in a Linux virtual machine but I can't tell if that's because it's really slow or because there is an actual problem. Do you have a local Linux install you could test them on?

@kevinrushforth
Copy link
Collaborator

I can test them later this morning when I get into the office.

@kevinrushforth
Copy link
Collaborator

The tests all PASS on my Linux system (a physical machine running Ubuntu 18.04). I'll run on Windows and Mac and then finish my review.

I don't have a good answer to your question about the platform differences regarding the scrolling multiplier (-1 on Mac versus 40 on Windows and Linux). The negative versus positive might be related to the "natural scrolling order" on Mac, which is intentionally backwards by default from the other platforms. However, a difference of 40x in magnitude points to something wrong in the implementation.

Copy link
Collaborator

@kevinrushforth kevinrushforth left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I ran on 4 different systems: Linux, Mac (Retina display), Windows 10, Windows 7. With 125% scaling on Windows (which is what I run by default), the scroll tests fail with a timeout, but they pass if I set the scale to 100%. I didn't look at the code to see what the problem might be, but if there isn't an an obvious solution, one possible fix is to either skip those tests on Windows if the scale is not 1 or else force it to 1.

I also left a comment in the code about the platform-specific scroll scale.

CountDownLatch onScrollLatch = new CountDownLatch(1);
CountDownLatch setSceneLatch = new CountDownLatch(1);
Button button = new Button("Scroll me");
InvalidationListener invalidationListener = observable -> setSceneLatch.countDown();
int[] totalScroll = new int[]{0};
long[] firstScrollMillis = new long[]{0};
int scrollMultiplier = System.getProperty("os.name").toLowerCase().startsWith("mac") ? -1 : 40;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you add a comment here? This suggests that there might be an issue with scrolling in the Mac robot implementation. We might want to file a follow-up issue to investigate.

@brcolow
Copy link
Contributor Author

brcolow commented Dec 1, 2018

I see why it is failing on non 1.0 scales, I will add a commit as soon as I confirm it's fixed (need to multiply event.getDeltaY() by Screen.getPrimary().getOutputScaleY(). I will also add the comment you mentioned.

@brcolow
Copy link
Contributor Author

brcolow commented Dec 1, 2018

Added a commit which addresses both issues.

@@ -474,10 +474,12 @@ private static void testMouseWheel(int amount) {
InvalidationListener invalidationListener = observable -> setSceneLatch.countDown();
int[] totalScroll = new int[]{0};
long[] firstScrollMillis = new long[]{0};
// The scroll wheel amount is multiplied by 40 on Linux and Windows, but not on macOS. The
// directions are also reversed.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I filed JDK-8214580 to investigate this. Can you add to this comment that the difference in behavior is unexpected and might be a bug? Something like:

// This difference in behavior is unexplained and might be a bug. See JDK-8214580.

int scrollMultiplier = System.getProperty("os.name").toLowerCase().startsWith("mac") ? -1 : 40;
Util.runAndWait(() -> {
button.setOnScroll(event -> {
totalScroll[0] += event.getDeltaY();
totalScroll[0] += event.getDeltaY() * Screen.getPrimary().getOutputScaleY();
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good. I'll test it on Monday.

int scrollMultiplier = System.getProperty("os.name").toLowerCase().startsWith("mac") ? -1 : 40;
Util.runAndWait(() -> {
button.setOnScroll(event -> {
totalScroll[0] += event.getDeltaY();
totalScroll[0] += event.getDeltaY() * Screen.getPrimary().getOutputScaleY();
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Multiplying by the output scale works correctly on Windows. It doesn't work on a Mac with a retina display, though. The test now fails for me. This suggests another platform difference between how Robot::mouseWheel works on Mac versus the other platforms.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you think we should skip the test on Mac for now and un-skip it as part of JDK-8214580?

Copy link
Collaborator

@kevinrushforth kevinrushforth Dec 3, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was starting to think the same thing. That would be fine with me. Please update JDK-8214580 with the additional information.

And then you can add an assumeTrue(!isMac) at the top of this test with the JBS bug ID in the comment.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Okay, I added a new commit and updated the bug.

@kevinrushforth
Copy link
Collaborator

That looks good. One quick thought: for consistency, the following could also use PlatformUtil.isMac() now that the test imports it:

    int scrollMultiplier = System.getProperty("os.name").toLowerCase().startsWith("mac") ? -1 : 40;

I'll do a quick final test on Mac and Windows and then I think we can get this in.

@kevinrushforth
Copy link
Collaborator

Btw, this would have been easier for me to review without the squash / force-push

@brcolow
Copy link
Contributor Author

brcolow commented Dec 6, 2018

Ah, sorry about that. Will keep that in mind going forward.

Copy link
Collaborator

@kevinrushforth kevinrushforth left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good. I'll merge it in shortly.

@kevinrushforth kevinrushforth merged commit 1703d45 into javafxports:develop Dec 6, 2018
@brcolow brcolow deleted the JDK-8207369 branch December 6, 2018 05:56
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants