Ejemplo n.º 1
0
  void test3(Window owner, Window child1, Window child2) {
    System.out.println("* * * STAGE 3 * * *\nWidow owner: " + owner);

    owner.setFocusableWindowState(true);
    owner.setVisible(true);

    child1.setFocusableWindowState(false);
    child1.setVisible(true);

    child2.setFocusableWindowState(true);
    child2.add(button);
    child2.setVisible(true);

    Util.waitTillShown(child2);

    Util.clickOnComp(button, robot);
    System.err.println(
        "focus owner: " + KeyboardFocusManager.getCurrentKeyboardFocusManager().getFocusOwner());
    if (button != KeyboardFocusManager.getCurrentKeyboardFocusManager().getFocusOwner()) {
      throw new RuntimeException("Test failed.");
    }
    child1.dispose();
    child2.dispose();
    owner.dispose();
  }
Ejemplo n.º 2
0
  public void start() {
    menu.setMnemonic('f');
    submenu.setMnemonic('m');
    menu.add(submenu);
    submenu.add(item);
    bar.add(menu);
    frame.setJMenuBar(bar);
    frame.pack();

    item.addActionListener(
        new ActionListener() {
          public void actionPerformed(ActionEvent e) {
            Sysout.println(e.toString());
            synchronized (activated) {
              activated.set(true);
              activated.notifyAll();
            }
          }
        });

    frame.setVisible(true);
    Util.waitForIdle(robot);

    boolean isMacOSX = (OSInfo.getOSType() == OSInfo.OSType.MACOSX);
    if (isMacOSX) {
      robot.keyPress(KeyEvent.VK_CONTROL);
      robot.delay(20);
    }
    robot.keyPress(KeyEvent.VK_ALT);
    robot.delay(20);
    robot.keyPress(KeyEvent.VK_F);
    robot.delay(20);
    robot.keyRelease(KeyEvent.VK_F);
    robot.delay(20);
    robot.keyRelease(KeyEvent.VK_ALT);
    if (isMacOSX) {
      robot.keyRelease(KeyEvent.VK_CONTROL);
      robot.delay(20);
    }
    Util.waitForIdle(robot);

    robot.keyPress(KeyEvent.VK_M);
    robot.delay(20);
    robot.keyRelease(KeyEvent.VK_M);
    Util.waitForIdle(robot);

    robot.keyPress(KeyEvent.VK_SPACE);
    robot.delay(20);
    robot.keyRelease(KeyEvent.VK_SPACE);
    Util.waitForIdle(robot);

    if (!Util.waitForCondition(activated, 2000)) {
      throw new TestFailedException("a submenu wasn't activated by mnemonic key press");
    }

    Sysout.println("Test passed.");
  }
Ejemplo n.º 3
0
  @Override
  protected boolean performTest() {
    try {
      SwingUtilities.invokeAndWait(
          new Runnable() {
            public void run() {
              // prepare test data
              frameClicked = 0;

              b.requestFocus();

              scrollPane.getHorizontalScrollBar().setUnitIncrement(40);
              scrollPane.getVerticalScrollBar().setUnitIncrement(40);

              hLoc = scrollPane.getHorizontalScrollBar().getLocationOnScreen();
              hLoc.translate(scrollPane.getHorizontalScrollBar().getWidth() - 3, 3);
              vLoc = scrollPane.getVerticalScrollBar().getLocationOnScreen();
              vLoc.translate(3, scrollPane.getVerticalScrollBar().getHeight() - 3);

              testLoc = p.getLocationOnScreen();
              testLoc.translate(-3, -3);

              resizeLoc = f.getLocationOnScreen();
              resizeLoc.translate(f.getWidth() - 1, f.getHeight() - 1);
            }
          });
    } catch (Exception e) {
      e.printStackTrace();
      throw new RuntimeException("Problem preparing test GUI.");
    }
    // run robot
    Robot robot = Util.createRobot();
    robot.setAutoDelay(ROBOT_DELAY);

    robot.mouseMove(hLoc.x, hLoc.y);
    robot.mousePress(InputEvent.BUTTON1_MASK);
    robot.mouseRelease(InputEvent.BUTTON1_MASK);
    Util.waitForIdle(robot);

    robot.mouseMove(vLoc.x, vLoc.y);
    robot.mousePress(InputEvent.BUTTON1_MASK);
    robot.mouseRelease(InputEvent.BUTTON1_MASK);
    Util.waitForIdle(robot);

    clickAndBlink(robot, testLoc, false);
    robot.mouseMove(resizeLoc.x, resizeLoc.y);
    robot.mousePress(InputEvent.BUTTON1_MASK);
    robot.mouseMove(resizeLoc.x + 5, resizeLoc.y + 5);
    robot.mouseRelease(InputEvent.BUTTON1_MASK);
    Util.waitForIdle(robot);

    clickAndBlink(robot, testLoc, false);
    return frameClicked == 2;
  }
Ejemplo n.º 4
0
  public static void main(String[] s) {
    JFrame frame = new JFrame("A test frame");
    JPanel outputBox = new JPanel();
    JButton jButton = new JButton();

    frame.setSize(200, 200);
    frame.addMouseWheelListener(
        new MouseWheelListener() {
          public void mouseWheelMoved(MouseWheelEvent e) {
            System.out.println("Wheel moved on FRAME : " + e);
            actualEvents++;
          }
        });

    outputBox.addMouseListener(
        new MouseAdapter() {
          public void mousePressed(MouseEvent e) {
            System.out.println("MousePressed on OUTBOX : " + e);
          }
        });
    frame.add(outputBox);
    outputBox.add(jButton);

    frame.setVisible(true);

    Util.waitForIdle(robot);

    Util.pointOnComp(jButton, robot);
    Util.waitForIdle(robot);

    for (int i = 0; i < MOVE_COUNT; i++) {
      robot.mouseWheel(1);
      robot.delay(10);
    }

    for (int i = 0; i < MOVE_COUNT; i++) {
      robot.mouseWheel(-1);
      robot.delay(10);
    }

    Util.waitForIdle(robot);
    // Not fair to check for multiplier 4 as it's not specified actual number of WheelEvents
    // result in a single wheel rotation.
    if (actualEvents != EXPECTED_COUNT) {
      AbstractTest.fail(
          "Expected events count: " + EXPECTED_COUNT + " Actual events count: " + actualEvents);
    }
  }
Ejemplo n.º 5
0
  private static void init() {
    // *** Create instructions for the user here ***
    String[] instructions = {
      "This is an AUTOMATIC test, simply wait until it is done.",
      "The result (passed or failed) will be shown in the",
      "message window below."
    };
    Sysout.createDialog();
    Sysout.printInstructions(instructions);

    Frame frame = new Frame("test for 6418028");
    frame.setLayout(new FlowLayout());
    Button btn1 = new Button("Button1");
    frame.add(btn1);
    TestButton btn2 = new TestButton("Button2");
    frame.add(btn2);
    frame.pack();
    frame.addWindowListener(
        new WindowAdapter() {
          @Override
          public void windowClosing(WindowEvent we) {
            we.getWindow().dispose();
          }
        });
    frame.setVisible(true);

    Util.waitForIdle(null);

    btn2.instrumentPeer();
    btn2.requestFocusInWindow();
    btn2.restorePeer();
    frame.dispose();
    RequestOnCompWithNullParent1.pass();
  } // End  init()
Ejemplo n.º 6
0
public class InfiniteRecursion_1 {
  static final Robot robot = Util.createRobot();
  static final int MOVE_COUNT = 5;
  // *2 for both rotation directions,
  // *2 as Java sends the wheel event to every for nested component in hierarchy under cursor
  static final int EXPECTED_COUNT = MOVE_COUNT * 2 * 2;
  static int actualEvents = 0;

  public static void main(String[] s) {
    JFrame frame = new JFrame("A test frame");
    JPanel outputBox = new JPanel();
    JButton jButton = new JButton();

    frame.setSize(200, 200);
    frame.addMouseWheelListener(
        new MouseWheelListener() {
          public void mouseWheelMoved(MouseWheelEvent e) {
            System.out.println("Wheel moved on FRAME : " + e);
            actualEvents++;
          }
        });

    outputBox.addMouseListener(
        new MouseAdapter() {
          public void mousePressed(MouseEvent e) {
            System.out.println("MousePressed on OUTBOX : " + e);
          }
        });
    frame.add(outputBox);
    outputBox.add(jButton);

    frame.setVisible(true);

    Util.waitForIdle(robot);

    Util.pointOnComp(jButton, robot);
    Util.waitForIdle(robot);

    for (int i = 0; i < MOVE_COUNT; i++) {
      robot.mouseWheel(1);
      robot.delay(10);
    }

    for (int i = 0; i < MOVE_COUNT; i++) {
      robot.mouseWheel(-1);
      robot.delay(10);
    }

    Util.waitForIdle(robot);
    // Not fair to check for multiplier 4 as it's not specified actual number of WheelEvents
    // result in a single wheel rotation.
    if (actualEvents != EXPECTED_COUNT) {
      AbstractTest.fail(
          "Expected events count: " + EXPECTED_COUNT + " Actual events count: " + actualEvents);
    }
  }
}
Ejemplo n.º 7
0
  void test1(Window owner, Window child) {
    System.out.println("* * * STAGE 1 * * *\nWindow owner: " + owner);

    owner.setFocusableWindowState(false);
    owner.setVisible(true);

    child.add(button);
    child.setVisible(true);

    Util.waitTillShown(child);

    Util.clickOnComp(button, robot);
    if (button == KeyboardFocusManager.getCurrentKeyboardFocusManager().getFocusOwner()) {
      throw new RuntimeException("Test Failed.");
    }
    child.dispose();
    owner.dispose();
  }
Ejemplo n.º 8
0
  public void init() {
    robot = Util.createRobot();

    // Create instructions for the user here, as well as set up
    // the environment -- set the layout manager, add buttons,
    // etc.
    this.setLayout(new BorderLayout());
    Sysout.createDialogWithInstructions(
        new String[] {"This is a manual test. Simple wait until it is done."});
  }
Ejemplo n.º 9
0
  // We need in this constructor to pass frame position between JVMs
  public FileListBetweenJVMsTest(
      Point targetFrameLocation, Point dragSourcePoint, int transferredFilesNumber)
      throws InterruptedException {
    TargetFileListFrame targetFrame =
        new TargetFileListFrame(targetFrameLocation, transferredFilesNumber);

    Util.waitForIdle(null);

    final Robot robot = Util.createRobot();

    robot.mouseMove((int) dragSourcePoint.getX(), (int) dragSourcePoint.getY());
    sleep(100);
    robot.mousePress(InputEvent.BUTTON1_MASK);
    sleep(100);
    robot.mouseRelease(InputEvent.BUTTON1_MASK);
    sleep(100);

    Util.drag(robot, dragSourcePoint, targetFrame.getDropTargetPoint(), InputEvent.BUTTON1_MASK);
  }
Ejemplo n.º 10
0
  public void start() {

    SourceFileListFrame sourceFrame = new SourceFileListFrame();

    Util.waitForIdle(null);

    String[] args =
        new String[] {
          String.valueOf(sourceFrame.getNextLocationX()),
          String.valueOf(sourceFrame.getNextLocationY()),
          String.valueOf(sourceFrame.getDragSourcePointX()),
          String.valueOf(sourceFrame.getDragSourcePointY()),
          String.valueOf(sourceFrame.getSourceFilesNumber())
        };

    ProcessResults processResults = ProcessCommunicator.executeChildProcess(this.getClass(), args);

    verifyTestResults(processResults);
  } // start()
  public static void main(String[] args) throws Exception {

    if (!OS.contains("mac")) {
      System.out.println("The test is applicable only to Mac OS X. Passed");
      return;
    }

    // Move the mouse out, because it could interfere with the test.
    Robot r = Util.createRobot();
    Util.waitForIdle(r);
    r.mouseMove(0, 0);
    Util.waitForIdle(r);

    SwingUtilities.invokeAndWait(
        new Runnable() {
          @Override
          public void run() {
            createAndShowGUI();
          }
        });

    // Move the mouse away from the frame and check the View-base full screen mode
    Util.waitForIdle(r);
    r.mouseMove(500, 500);
    Util.waitForIdle(r);
    mouseEnterCount = 0;
    SwingUtilities.invokeAndWait(
        new Runnable() {
          @Override
          public void run() {
            GraphicsEnvironment.getLocalGraphicsEnvironment()
                .getDefaultScreenDevice()
                .setFullScreenWindow(frame);
          }
        });
    Util.waitForIdle(r);
    if (mouseEnterCount != 1) {
      throw new RuntimeException("No MouseEntered event for view-base full screen. Failed.");
    }
    SwingUtilities.invokeAndWait(
        new Runnable() {
          @Override
          public void run() {
            GraphicsEnvironment.getLocalGraphicsEnvironment()
                .getDefaultScreenDevice()
                .setFullScreenWindow(null);
          }
        });

    // Test native full screen support
    Util.waitForIdle(r);
    Point fullScreenButtonPos = frame.getLocation();
    fullScreenButtonPos.translate(frame.getWidth() - 10, 10);
    r.mouseMove(fullScreenButtonPos.x, fullScreenButtonPos.y);
    mouseEnterCount = 0;

    // Cant use waitForIdle for full screen transition.
    int waitCount = 0;
    while (!windowEnteringFullScreen) {
      r.mousePress(InputEvent.BUTTON1_MASK);
      r.mouseRelease(InputEvent.BUTTON1_MASK);
      Thread.sleep(100);
      if (waitCount++ > 10) throw new RuntimeException("Can't enter full screen mode. Failed");
    }

    waitCount = 0;
    while (!windowEnteredFullScreen) {
      Thread.sleep(200);
      if (waitCount++ > 10) throw new RuntimeException("Can't enter full screen mode. Failed");
    }

    if (mouseEnterCount != 1) {
      throw new RuntimeException("No MouseEntered event for native full screen. Failed.");
    }
  }
Ejemplo n.º 12
0
public class NonfocusableOwnerTest extends Applet {
  Robot robot = Util.createRobot();
  Frame frame;
  Dialog dialog;
  Window window1;
  Window window2;
  Button button = new Button("button");

  public static void main(String[] args) {
    NonfocusableOwnerTest test = new NonfocusableOwnerTest();
    test.start();
  }

  public void start() {
    Toolkit.getDefaultToolkit()
        .addAWTEventListener(
            new AWTEventListener() {
              public void eventDispatched(AWTEvent e) {
                System.out.println(e.toString());
              }
            },
            FocusEvent.FOCUS_EVENT_MASK
                | WindowEvent.WINDOW_FOCUS_EVENT_MASK
                | WindowEvent.WINDOW_EVENT_MASK);

    frame = new Frame("Frame");
    frame.setName("Frame-owner");
    frame.setBounds(100, 0, 100, 100);
    dialog = new Dialog(frame, "Dialog");
    dialog.setName("Dialog-owner");
    dialog.setBounds(100, 0, 100, 100);

    window1 = new Window(frame);
    window1.setName("1st child");
    window1.setBounds(100, 300, 100, 100);
    window2 = new Window(window1);
    window2.setName("2nd child");
    window2.setBounds(100, 500, 100, 100);

    test1(frame, window1);
    test2(frame, window1, window2);
    test3(frame, window1, window2);

    window1 = new Window(dialog);
    window1.setBounds(100, 300, 100, 100);
    window1.setName("1st child");
    window2 = new Window(window1);
    window2.setName("2nd child");
    window2.setBounds(100, 500, 100, 100);

    test1(dialog, window1);
    test2(dialog, window1, window2);
    test3(dialog, window1, window2);

    System.out.println("Test passed.");
  }

  void test1(Window owner, Window child) {
    System.out.println("* * * STAGE 1 * * *\nWindow owner: " + owner);

    owner.setFocusableWindowState(false);
    owner.setVisible(true);

    child.add(button);
    child.setVisible(true);

    Util.waitTillShown(child);

    Util.clickOnComp(button, robot);
    if (button == KeyboardFocusManager.getCurrentKeyboardFocusManager().getFocusOwner()) {
      throw new RuntimeException("Test Failed.");
    }
    child.dispose();
    owner.dispose();
  }

  void test2(Window owner, Window child1, Window child2) {
    System.out.println("* * * STAGE 2 * * *\nWindow nowner: " + owner);

    owner.setFocusableWindowState(false);
    owner.setVisible(true);

    child1.setFocusableWindowState(true);
    child1.setVisible(true);

    child2.add(button);
    child2.setVisible(true);

    Util.waitTillShown(child2);

    Util.clickOnComp(button, robot);
    if (button == KeyboardFocusManager.getCurrentKeyboardFocusManager().getFocusOwner()) {
      throw new RuntimeException("Test failed.");
    }
    child2.dispose();
    child1.dispose();
    owner.dispose();
  }

  void test3(Window owner, Window child1, Window child2) {
    System.out.println("* * * STAGE 3 * * *\nWidow owner: " + owner);

    owner.setFocusableWindowState(true);
    owner.setVisible(true);

    child1.setFocusableWindowState(false);
    child1.setVisible(true);

    child2.setFocusableWindowState(true);
    child2.add(button);
    child2.setVisible(true);

    Util.waitTillShown(child2);

    Util.clickOnComp(button, robot);
    System.err.println(
        "focus owner: " + KeyboardFocusManager.getCurrentKeyboardFocusManager().getFocusOwner());
    if (button != KeyboardFocusManager.getCurrentKeyboardFocusManager().getFocusOwner()) {
      throw new RuntimeException("Test failed.");
    }
    child1.dispose();
    child2.dispose();
    owner.dispose();
  }
}
Ejemplo n.º 13
0
  public void start() {
    frame.setSize(480, 300);
    frame.setVisible(true);
    try {
      robot = new Robot();
    } catch (AWTException e) {
      throw new RuntimeException(e);
    }

    Util.waitForIdle(robot); // a time to show Frame

    fp = frame.getLocationOnScreen();

    for (int i = 0; i < TRIALS; i++) {
      checkClicked();
      clearFlags();
    }

    for (int i = 0; i < TRIALS; i++) {
      oneDrag(2);
      clearFlags();
    }

    for (int i = 0; i < TRIALS; i++) {
      oneDrag(5);
      clearFlags();
    }

    for (int i = 0; i < TRIALS; i++) {
      oneDrag(70);
      clearFlags();
    }

    // Check that no Drag event occur in the SMUDGE area
    String sToolkit = Toolkit.getDefaultToolkit().getClass().getName();
    System.out.println("Toolkit == " + sToolkit);
    if ("sun.awt.windows.WToolkit".equals(sToolkit)) {
      int dragWidth =
          ((Integer) Toolkit.getDefaultToolkit().getDesktopProperty("win.drag.width")).intValue();
      int dragHeight =
          ((Integer) Toolkit.getDefaultToolkit().getDesktopProperty("win.drag.height")).intValue();
      System.out.println("dragWidth==" + dragWidth + ":: dragHeight==" + dragHeight);
      // DragWidth and dragHeight may be equal to 1. In that case the SMUDGE rectangle
      // narrowed into 1x1 pixel and we can't drag a mouse in it.
      // In that case we may skip following testcase but I'd prefer if we move mouse on 1 pixel
      // only.
      // And that should pass as well.
      dragWidth = dragWidth > 1 ? dragWidth / 2 : 1;
      dragHeight = dragHeight > 1 ? dragHeight / 2 : 1;
      for (int i = 0; i < TRIALS; i++) {
        smallWin32Drag(dragWidth, dragHeight);
        clearFlags();
      }
    } else if ("sun.lwawt.macosx.LWCToolkit".equals(sToolkit)) {
      // On MacOS X every mouse move event is MOUSE_DRAGGED event and
      // MOUSE_DRAGGED is sent back form the Native code to the java code
      // for every mouse move. Therefore 'smallDrag test should be
      // disabled for toolkit 'sun.lwawt.macosx.LWCToolkit'.
    } else {
      for (int i = 0; i < TRIALS; i++) {
        smallDrag(
            SMUDGE_WIDTH - 1, SMUDGE_HEIGHT - 1); // on Motif and XAWT SMUDGE area is 4-pixels wide
        clearFlags();
      }
    }
    System.out.println("Test passed.");
  } // start()