Example #1
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.");
  }
  @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;
  }
  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);
    }
  }
Example #4
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()
Example #5
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);
  }
Example #6
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.");
    }
  }
Example #8
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()