8157338: sanity/client/SwingSet/src/ButtonDemoScreenshotTest.java is unstable
Reviewed-by: serb
This commit is contained in:
parent
c0689879a7
commit
26a4a1a6b3
@ -245,8 +245,6 @@ javax/sound/sampled/Mixers/DisabledAssertionCrash.java 7067310 generic-all
|
|||||||
|
|
||||||
# jdk_swing
|
# jdk_swing
|
||||||
|
|
||||||
sanity/client/SwingSet/src/ButtonDemoScreenshotTest.java 8157338 generic-all
|
|
||||||
|
|
||||||
############################################################################
|
############################################################################
|
||||||
|
|
||||||
# jdk_text
|
# jdk_text
|
||||||
|
@ -23,18 +23,21 @@
|
|||||||
|
|
||||||
import com.sun.swingset3.demos.button.ButtonDemo;
|
import com.sun.swingset3.demos.button.ButtonDemo;
|
||||||
import org.jtregext.GuiTestListener;
|
import org.jtregext.GuiTestListener;
|
||||||
import java.awt.Point;
|
|
||||||
import java.awt.Robot;
|
|
||||||
import java.awt.event.InputEvent;
|
|
||||||
import java.awt.image.BufferedImage;
|
|
||||||
import org.netbeans.jemmy.ClassReference;
|
import org.netbeans.jemmy.ClassReference;
|
||||||
|
import org.netbeans.jemmy.ComponentChooser;
|
||||||
import org.netbeans.jemmy.image.StrictImageComparator;
|
import org.netbeans.jemmy.image.StrictImageComparator;
|
||||||
import org.netbeans.jemmy.operators.JButtonOperator;
|
import org.netbeans.jemmy.operators.JButtonOperator;
|
||||||
import org.netbeans.jemmy.operators.JFrameOperator;
|
import org.netbeans.jemmy.operators.JFrameOperator;
|
||||||
import static org.jemmy2ext.JemmyExt.*;
|
import org.testng.annotations.BeforeClass;
|
||||||
import org.testng.annotations.Test;
|
|
||||||
import static com.sun.swingset3.demos.button.ButtonDemo.*;
|
|
||||||
import org.testng.annotations.Listeners;
|
import org.testng.annotations.Listeners;
|
||||||
|
import org.testng.annotations.Test;
|
||||||
|
|
||||||
|
import java.awt.Component;
|
||||||
|
import java.awt.Robot;
|
||||||
|
import java.awt.image.BufferedImage;
|
||||||
|
|
||||||
|
import static com.sun.swingset3.demos.button.ButtonDemo.DEMO_TITLE;
|
||||||
|
import static org.jemmy2ext.JemmyExt.*;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* @test
|
* @test
|
||||||
@ -55,7 +58,13 @@ import org.testng.annotations.Listeners;
|
|||||||
@Listeners(GuiTestListener.class)
|
@Listeners(GuiTestListener.class)
|
||||||
public class ButtonDemoScreenshotTest {
|
public class ButtonDemoScreenshotTest {
|
||||||
|
|
||||||
private static final int BUTTON_COUNT = 6; // TODO: Decide about "open browser" buttons (value was 8 originally)
|
private static final int[] BUTTONS = {0, 1, 2, 3, 4, 5}; // "open browser" buttons (6, 7) open a browser, so ignore
|
||||||
|
private static StrictImageComparator sComparator = null;
|
||||||
|
|
||||||
|
@BeforeClass
|
||||||
|
public void init() {
|
||||||
|
sComparator = new StrictImageComparator();
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void test() throws Exception {
|
public void test() throws Exception {
|
||||||
@ -67,32 +76,37 @@ public class ButtonDemoScreenshotTest {
|
|||||||
waitImageIsStill(rob, mainFrame);
|
waitImageIsStill(rob, mainFrame);
|
||||||
|
|
||||||
// Check all the buttons
|
// Check all the buttons
|
||||||
for (int i = 0; i < BUTTON_COUNT; i++) {
|
for (int i : BUTTONS) {
|
||||||
checkButton(mainFrame, i, rob);
|
checkButton(mainFrame, i, rob);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void checkButton(JFrameOperator jfo, int i, Robot rob) {
|
private void checkButton(JFrameOperator jfo, int i, Robot rob) {
|
||||||
JButtonOperator button = new JButtonOperator(jfo, i);
|
JButtonOperator button = new JButtonOperator(jfo, i);
|
||||||
|
button.moveMouse(button.getCenterX(), button.getCenterY());
|
||||||
Point loc = button.getLocationOnScreen();
|
|
||||||
rob.mouseMove(loc.x, loc.y);
|
|
||||||
|
|
||||||
BufferedImage initialButtonImage = capture(rob, button);
|
BufferedImage initialButtonImage = capture(rob, button);
|
||||||
assertNotBlack(initialButtonImage);
|
assertNotBlack(initialButtonImage);
|
||||||
save(initialButtonImage, "button" + i + "_0initial.png");
|
save(initialButtonImage, "button" + i + ".png");
|
||||||
rob.mousePress(InputEvent.BUTTON1_MASK);
|
|
||||||
|
BufferedImage[] pressedImage = new BufferedImage[1];
|
||||||
|
|
||||||
|
button.pressMouse();
|
||||||
try {
|
try {
|
||||||
waitPressed(button);
|
waitPressed(button);
|
||||||
BufferedImage pressedButtonImage = capture(rob, button);
|
button.waitState(new ComponentChooser() {
|
||||||
assertNotBlack(pressedButtonImage);
|
public boolean checkComponent(Component c) {
|
||||||
save(pressedButtonImage, "button" + i + "_1pressed.png");
|
pressedImage[0] = capture(rob, button);
|
||||||
|
assertNotBlack(pressedImage[0]);
|
||||||
StrictImageComparator sComparator = new StrictImageComparator();
|
return !sComparator.compare(initialButtonImage, pressedImage[0]);
|
||||||
assertNotEquals("Button " + i + " Test", sComparator, initialButtonImage, pressedButtonImage);
|
}
|
||||||
|
public String getDescription() {
|
||||||
|
return "Button with new image";
|
||||||
|
}
|
||||||
|
});
|
||||||
} finally {
|
} finally {
|
||||||
rob.mouseRelease(InputEvent.BUTTON1_MASK);
|
if(pressedImage[0] != null) save(pressedImage[0], "button" + i + "_pressed.png");
|
||||||
|
button.releaseMouse();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user