jdk/test/sanity/client/SwingSet/src/ButtonDemoScreenshotTest.java
author prr
Fri, 27 May 2016 13:26:56 -0700
changeset 39006 fd8c3312d043
parent 37677 9774eca96b01
permissions -rw-r--r--
8157339: Further stabilization for the SwingSet client sanity tests Reviewed-by: serb, alexsch
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
36744
a00905527ec2 8153141: Develop initial set of tests for SwingSet
mrkam
parents:
diff changeset
     1
/*
a00905527ec2 8153141: Develop initial set of tests for SwingSet
mrkam
parents:
diff changeset
     2
 * Copyright (c) 2011, 2016, Oracle and/or its affiliates. All rights reserved.
a00905527ec2 8153141: Develop initial set of tests for SwingSet
mrkam
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
a00905527ec2 8153141: Develop initial set of tests for SwingSet
mrkam
parents:
diff changeset
     4
 *
a00905527ec2 8153141: Develop initial set of tests for SwingSet
mrkam
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
a00905527ec2 8153141: Develop initial set of tests for SwingSet
mrkam
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
a00905527ec2 8153141: Develop initial set of tests for SwingSet
mrkam
parents:
diff changeset
     7
 * published by the Free Software Foundation.
a00905527ec2 8153141: Develop initial set of tests for SwingSet
mrkam
parents:
diff changeset
     8
 *
a00905527ec2 8153141: Develop initial set of tests for SwingSet
mrkam
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
a00905527ec2 8153141: Develop initial set of tests for SwingSet
mrkam
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
a00905527ec2 8153141: Develop initial set of tests for SwingSet
mrkam
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
a00905527ec2 8153141: Develop initial set of tests for SwingSet
mrkam
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
a00905527ec2 8153141: Develop initial set of tests for SwingSet
mrkam
parents:
diff changeset
    13
 * accompanied this code).
a00905527ec2 8153141: Develop initial set of tests for SwingSet
mrkam
parents:
diff changeset
    14
 *
a00905527ec2 8153141: Develop initial set of tests for SwingSet
mrkam
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
a00905527ec2 8153141: Develop initial set of tests for SwingSet
mrkam
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
a00905527ec2 8153141: Develop initial set of tests for SwingSet
mrkam
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
a00905527ec2 8153141: Develop initial set of tests for SwingSet
mrkam
parents:
diff changeset
    18
 *
a00905527ec2 8153141: Develop initial set of tests for SwingSet
mrkam
parents:
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
a00905527ec2 8153141: Develop initial set of tests for SwingSet
mrkam
parents:
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
a00905527ec2 8153141: Develop initial set of tests for SwingSet
mrkam
parents:
diff changeset
    21
 * questions.
a00905527ec2 8153141: Develop initial set of tests for SwingSet
mrkam
parents:
diff changeset
    22
 */
a00905527ec2 8153141: Develop initial set of tests for SwingSet
mrkam
parents:
diff changeset
    23
37677
9774eca96b01 8154381: SwingSet tests are not auto closed in jtreg
mrkam
parents: 36744
diff changeset
    24
import com.sun.swingset3.demos.button.ButtonDemo;
9774eca96b01 8154381: SwingSet tests are not auto closed in jtreg
mrkam
parents: 36744
diff changeset
    25
import org.jtregext.GuiTestListener;
36744
a00905527ec2 8153141: Develop initial set of tests for SwingSet
mrkam
parents:
diff changeset
    26
import java.awt.Point;
a00905527ec2 8153141: Develop initial set of tests for SwingSet
mrkam
parents:
diff changeset
    27
import java.awt.Robot;
a00905527ec2 8153141: Develop initial set of tests for SwingSet
mrkam
parents:
diff changeset
    28
import java.awt.event.InputEvent;
a00905527ec2 8153141: Develop initial set of tests for SwingSet
mrkam
parents:
diff changeset
    29
import java.awt.image.BufferedImage;
a00905527ec2 8153141: Develop initial set of tests for SwingSet
mrkam
parents:
diff changeset
    30
import org.netbeans.jemmy.ClassReference;
a00905527ec2 8153141: Develop initial set of tests for SwingSet
mrkam
parents:
diff changeset
    31
import org.netbeans.jemmy.image.StrictImageComparator;
a00905527ec2 8153141: Develop initial set of tests for SwingSet
mrkam
parents:
diff changeset
    32
import org.netbeans.jemmy.operators.JButtonOperator;
a00905527ec2 8153141: Develop initial set of tests for SwingSet
mrkam
parents:
diff changeset
    33
import org.netbeans.jemmy.operators.JFrameOperator;
a00905527ec2 8153141: Develop initial set of tests for SwingSet
mrkam
parents:
diff changeset
    34
import static org.jemmy2ext.JemmyExt.*;
a00905527ec2 8153141: Develop initial set of tests for SwingSet
mrkam
parents:
diff changeset
    35
import org.testng.annotations.Test;
a00905527ec2 8153141: Develop initial set of tests for SwingSet
mrkam
parents:
diff changeset
    36
import static com.sun.swingset3.demos.button.ButtonDemo.*;
37677
9774eca96b01 8154381: SwingSet tests are not auto closed in jtreg
mrkam
parents: 36744
diff changeset
    37
import org.testng.annotations.Listeners;
36744
a00905527ec2 8153141: Develop initial set of tests for SwingSet
mrkam
parents:
diff changeset
    38
a00905527ec2 8153141: Develop initial set of tests for SwingSet
mrkam
parents:
diff changeset
    39
/*
a00905527ec2 8153141: Develop initial set of tests for SwingSet
mrkam
parents:
diff changeset
    40
 * @test
39006
fd8c3312d043 8157339: Further stabilization for the SwingSet client sanity tests
prr
parents: 37677
diff changeset
    41
 * @key headful screenshots intermittent
36744
a00905527ec2 8153141: Develop initial set of tests for SwingSet
mrkam
parents:
diff changeset
    42
 * @summary Verifies buttons on SwingSet3 ButtonDemo page by clicking each
a00905527ec2 8153141: Develop initial set of tests for SwingSet
mrkam
parents:
diff changeset
    43
 *          button, taking its screenshots and checking that pressed button
a00905527ec2 8153141: Develop initial set of tests for SwingSet
mrkam
parents:
diff changeset
    44
 *          image is different from initial button image.
a00905527ec2 8153141: Develop initial set of tests for SwingSet
mrkam
parents:
diff changeset
    45
 *
a00905527ec2 8153141: Develop initial set of tests for SwingSet
mrkam
parents:
diff changeset
    46
 * @library /sanity/client/lib/jemmy/src
37677
9774eca96b01 8154381: SwingSet tests are not auto closed in jtreg
mrkam
parents: 36744
diff changeset
    47
 * @library /sanity/client/lib/Extensions/src
36744
a00905527ec2 8153141: Develop initial set of tests for SwingSet
mrkam
parents:
diff changeset
    48
 * @library /sanity/client/lib/SwingSet3/src
39006
fd8c3312d043 8157339: Further stabilization for the SwingSet client sanity tests
prr
parents: 37677
diff changeset
    49
 * @modules java.desktop
fd8c3312d043 8157339: Further stabilization for the SwingSet client sanity tests
prr
parents: 37677
diff changeset
    50
 *          java.logging
36744
a00905527ec2 8153141: Develop initial set of tests for SwingSet
mrkam
parents:
diff changeset
    51
 * @build org.jemmy2ext.JemmyExt
a00905527ec2 8153141: Develop initial set of tests for SwingSet
mrkam
parents:
diff changeset
    52
 * @build com.sun.swingset3.demos.button.ButtonDemo
a00905527ec2 8153141: Develop initial set of tests for SwingSet
mrkam
parents:
diff changeset
    53
 * @run testng ButtonDemoScreenshotTest
a00905527ec2 8153141: Develop initial set of tests for SwingSet
mrkam
parents:
diff changeset
    54
 */
37677
9774eca96b01 8154381: SwingSet tests are not auto closed in jtreg
mrkam
parents: 36744
diff changeset
    55
@Listeners(GuiTestListener.class)
36744
a00905527ec2 8153141: Develop initial set of tests for SwingSet
mrkam
parents:
diff changeset
    56
public class ButtonDemoScreenshotTest {
a00905527ec2 8153141: Develop initial set of tests for SwingSet
mrkam
parents:
diff changeset
    57
a00905527ec2 8153141: Develop initial set of tests for SwingSet
mrkam
parents:
diff changeset
    58
    private static final int BUTTON_COUNT = 6; // TODO: Decide about "open browser" buttons (value was 8 originally)
a00905527ec2 8153141: Develop initial set of tests for SwingSet
mrkam
parents:
diff changeset
    59
a00905527ec2 8153141: Develop initial set of tests for SwingSet
mrkam
parents:
diff changeset
    60
    @Test
a00905527ec2 8153141: Develop initial set of tests for SwingSet
mrkam
parents:
diff changeset
    61
    public void test() throws Exception {
37677
9774eca96b01 8154381: SwingSet tests are not auto closed in jtreg
mrkam
parents: 36744
diff changeset
    62
        Robot rob = new Robot();
36744
a00905527ec2 8153141: Develop initial set of tests for SwingSet
mrkam
parents:
diff changeset
    63
37677
9774eca96b01 8154381: SwingSet tests are not auto closed in jtreg
mrkam
parents: 36744
diff changeset
    64
        new ClassReference(ButtonDemo.class.getCanonicalName()).startApplication();
36744
a00905527ec2 8153141: Develop initial set of tests for SwingSet
mrkam
parents:
diff changeset
    65
37677
9774eca96b01 8154381: SwingSet tests are not auto closed in jtreg
mrkam
parents: 36744
diff changeset
    66
        JFrameOperator mainFrame = new JFrameOperator(DEMO_TITLE);
9774eca96b01 8154381: SwingSet tests are not auto closed in jtreg
mrkam
parents: 36744
diff changeset
    67
        waitImageIsStill(rob, mainFrame);
36744
a00905527ec2 8153141: Develop initial set of tests for SwingSet
mrkam
parents:
diff changeset
    68
37677
9774eca96b01 8154381: SwingSet tests are not auto closed in jtreg
mrkam
parents: 36744
diff changeset
    69
        // Check all the buttons
9774eca96b01 8154381: SwingSet tests are not auto closed in jtreg
mrkam
parents: 36744
diff changeset
    70
        for (int i = 0; i < BUTTON_COUNT; i++) {
9774eca96b01 8154381: SwingSet tests are not auto closed in jtreg
mrkam
parents: 36744
diff changeset
    71
            checkButton(mainFrame, i, rob);
9774eca96b01 8154381: SwingSet tests are not auto closed in jtreg
mrkam
parents: 36744
diff changeset
    72
        }
36744
a00905527ec2 8153141: Develop initial set of tests for SwingSet
mrkam
parents:
diff changeset
    73
    }
a00905527ec2 8153141: Develop initial set of tests for SwingSet
mrkam
parents:
diff changeset
    74
a00905527ec2 8153141: Develop initial set of tests for SwingSet
mrkam
parents:
diff changeset
    75
    public void checkButton(JFrameOperator jfo, int i, Robot rob) {
a00905527ec2 8153141: Develop initial set of tests for SwingSet
mrkam
parents:
diff changeset
    76
        JButtonOperator button = new JButtonOperator(jfo, i);
a00905527ec2 8153141: Develop initial set of tests for SwingSet
mrkam
parents:
diff changeset
    77
a00905527ec2 8153141: Develop initial set of tests for SwingSet
mrkam
parents:
diff changeset
    78
        Point loc = button.getLocationOnScreen();
a00905527ec2 8153141: Develop initial set of tests for SwingSet
mrkam
parents:
diff changeset
    79
        rob.mouseMove(loc.x, loc.y);
a00905527ec2 8153141: Develop initial set of tests for SwingSet
mrkam
parents:
diff changeset
    80
a00905527ec2 8153141: Develop initial set of tests for SwingSet
mrkam
parents:
diff changeset
    81
        BufferedImage initialButtonImage = capture(rob, button);
a00905527ec2 8153141: Develop initial set of tests for SwingSet
mrkam
parents:
diff changeset
    82
        assertNotBlack(initialButtonImage);
a00905527ec2 8153141: Develop initial set of tests for SwingSet
mrkam
parents:
diff changeset
    83
        save(initialButtonImage, "button" + i + "_0initial.png");
a00905527ec2 8153141: Develop initial set of tests for SwingSet
mrkam
parents:
diff changeset
    84
        rob.mousePress(InputEvent.BUTTON1_MASK);
a00905527ec2 8153141: Develop initial set of tests for SwingSet
mrkam
parents:
diff changeset
    85
        try {
a00905527ec2 8153141: Develop initial set of tests for SwingSet
mrkam
parents:
diff changeset
    86
            waitPressed(button);
a00905527ec2 8153141: Develop initial set of tests for SwingSet
mrkam
parents:
diff changeset
    87
            BufferedImage pressedButtonImage = capture(rob, button);
a00905527ec2 8153141: Develop initial set of tests for SwingSet
mrkam
parents:
diff changeset
    88
            assertNotBlack(pressedButtonImage);
a00905527ec2 8153141: Develop initial set of tests for SwingSet
mrkam
parents:
diff changeset
    89
            save(pressedButtonImage, "button" + i + "_1pressed.png");
a00905527ec2 8153141: Develop initial set of tests for SwingSet
mrkam
parents:
diff changeset
    90
a00905527ec2 8153141: Develop initial set of tests for SwingSet
mrkam
parents:
diff changeset
    91
            StrictImageComparator sComparator = new StrictImageComparator();
a00905527ec2 8153141: Develop initial set of tests for SwingSet
mrkam
parents:
diff changeset
    92
            assertNotEquals("Button " + i + " Test", sComparator, initialButtonImage, pressedButtonImage);
a00905527ec2 8153141: Develop initial set of tests for SwingSet
mrkam
parents:
diff changeset
    93
        } finally {
a00905527ec2 8153141: Develop initial set of tests for SwingSet
mrkam
parents:
diff changeset
    94
            rob.mouseRelease(InputEvent.BUTTON1_MASK);
a00905527ec2 8153141: Develop initial set of tests for SwingSet
mrkam
parents:
diff changeset
    95
        }
a00905527ec2 8153141: Develop initial set of tests for SwingSet
mrkam
parents:
diff changeset
    96
    }
a00905527ec2 8153141: Develop initial set of tests for SwingSet
mrkam
parents:
diff changeset
    97
a00905527ec2 8153141: Develop initial set of tests for SwingSet
mrkam
parents:
diff changeset
    98
}