test/jdk/sanity/client/SwingSet/src/ButtonDemoScreenshotTest.java
changeset 49218 3f825ec26b01
parent 47841 3b6fc119b32b
child 51921 372cbac1a862
equal deleted inserted replaced
49217:3b820b878ebe 49218:3f825ec26b01
    81         }
    81         }
    82     }
    82     }
    83 
    83 
    84     private void checkButton(JFrameOperator jfo, int i, Robot rob) {
    84     private void checkButton(JFrameOperator jfo, int i, Robot rob) {
    85         JButtonOperator button = new JButtonOperator(jfo, i);
    85         JButtonOperator button = new JButtonOperator(jfo, i);
       
    86 
       
    87         //additional instrumentation for JDK-8198920. To be removed after the bug is fixed
       
    88         java.util.concurrent.atomic.AtomicBoolean actionListenerCalled = new java.util.concurrent.atomic.AtomicBoolean(false);
       
    89         button.addActionListener(e -> actionListenerCalled.set(true));
       
    90         //end of instrumentation for JDK-8198920
       
    91 
    86         button.moveMouse(button.getCenterX(), button.getCenterY());
    92         button.moveMouse(button.getCenterX(), button.getCenterY());
    87 
    93 
    88         BufferedImage initialButtonImage = capture(rob, button);
    94         BufferedImage initialButtonImage = capture(rob, button);
    89         assertNotBlack(initialButtonImage);
    95         assertNotBlack(initialButtonImage);
    90         save(initialButtonImage, "button" + i + ".png");
    96         save(initialButtonImage, "button" + i + ".png");
    91 
    97 
    92         BufferedImage[] pressedImage = new BufferedImage[1];
    98         BufferedImage[] pressedImage = new BufferedImage[1];
    93 
    99 
    94         button.pressMouse();
   100         button.pressMouse();
       
   101         //additional instrumentation for JDK-8198920. To be removed after the bug is fixed
       
   102         button.getOutput().printTrace("JDK-8198920: Button pressed at " + System.currentTimeMillis());
       
   103         //end of instrumentation for JDK-8198920
    95         try {
   104         try {
    96             waitPressed(button);
   105             waitPressed(button);
       
   106             //additional instrumentation for JDK-8198920. To be removed after the bug is fixed
       
   107             button.getOutput().printTrace("JDK-8198920: Button press confirmed by " + System.currentTimeMillis());
       
   108             //end of instrumentation for JDK-8198920
    97             button.waitState(new ComponentChooser() {
   109             button.waitState(new ComponentChooser() {
    98                 public boolean checkComponent(Component c) {
   110                 public boolean checkComponent(Component c) {
    99                     pressedImage[0] = capture(rob, button);
   111                     pressedImage[0] = capture(rob, button);
   100                     assertNotBlack(pressedImage[0]);
   112                     assertNotBlack(pressedImage[0]);
   101                     return !sComparator.compare(initialButtonImage, pressedImage[0]);
   113                     return !sComparator.compare(initialButtonImage, pressedImage[0]);
   105                 }
   117                 }
   106             });
   118             });
   107         } finally {
   119         } finally {
   108             if(pressedImage[0] != null) save(pressedImage[0], "button" + i + "_pressed.png");
   120             if(pressedImage[0] != null) save(pressedImage[0], "button" + i + "_pressed.png");
   109             button.releaseMouse();
   121             button.releaseMouse();
       
   122             //additional instrumentation for JDK-8198920. To be removed after the bug is fixed
       
   123             button.getOutput().printTrace("JDK-8198920: Button released at " + System.currentTimeMillis());
       
   124             try {
       
   125                 button.waitState(comp -> actionListenerCalled.get());
       
   126                 button.getOutput().printTrace("JDK-8198920: Action listener was called by " + System.currentTimeMillis());
       
   127             } catch(org.netbeans.jemmy.TimeoutExpiredException e) {
       
   128                 button.getOutput().printTrace("JDK-8198920: Action listener was not called by " + System.currentTimeMillis());
       
   129             }
       
   130             //end of instrumentation for JDK-8198920
   110         }
   131         }
   111     }
   132     }
   112 }
   133 }