Esempio n. 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.");
  }
Esempio n. 2
0
  private void doTest() throws InterruptedException, InvocationTargetException {

    boolean isWin = false;
    if (OSInfo.getOSType() == OSInfo.OSType.WINDOWS) {
      isWin = true;
    } else if (OSInfo.getOSType() == OSInfo.OSType.MACOSX) {
      System.out.println("Not for OS X");
      return;
    }

    System.out.println("multiple? selectedMoved? ?scrollMoved keyID? template? action?");
    test(new TestState(false, false, false, KeyEvent.VK_PAGE_UP, isWin ? false : false));
    // SelectedMoved (false) != ScrollMoved (true) for single list not emulated
    test(new TestState(false, true, false, KeyEvent.VK_PAGE_UP, isWin ? true : false));
    test(new TestState(false, true, true, KeyEvent.VK_PAGE_UP, isWin ? true : true));
    test(new TestState(true, false, false, KeyEvent.VK_PAGE_UP, isWin ? true : false));
    test(new TestState(true, false, true, KeyEvent.VK_PAGE_UP, isWin ? true : false));
    test(new TestState(true, true, false, KeyEvent.VK_PAGE_UP, isWin ? true : false));
    test(new TestState(true, true, true, KeyEvent.VK_PAGE_UP, isWin ? true : false));

    test(new TestState(false, false, false, KeyEvent.VK_PAGE_DOWN, isWin ? false : false));
    test(new TestState(false, true, false, KeyEvent.VK_PAGE_DOWN, isWin ? true : false));
    test(new TestState(false, true, true, KeyEvent.VK_PAGE_DOWN, isWin ? true : true));
    test(new TestState(true, false, false, KeyEvent.VK_PAGE_DOWN, isWin ? true : false));
    test(new TestState(true, false, true, KeyEvent.VK_PAGE_DOWN, isWin ? true : false));
    test(new TestState(true, true, false, KeyEvent.VK_PAGE_DOWN, isWin ? true : false));
    test(new TestState(true, true, true, KeyEvent.VK_PAGE_DOWN, isWin ? true : false));

    test(new TestState(false, false, false, KeyEvent.VK_HOME, isWin ? false : true));
    test(new TestState(false, true, false, KeyEvent.VK_HOME, isWin ? true : true));
    test(new TestState(false, true, true, KeyEvent.VK_HOME, isWin ? true : true));
    test(new TestState(true, false, false, KeyEvent.VK_HOME, isWin ? true : false));
    test(new TestState(true, false, true, KeyEvent.VK_HOME, isWin ? true : false));
    test(new TestState(true, true, false, KeyEvent.VK_HOME, isWin ? true : false));
    test(new TestState(true, true, true, KeyEvent.VK_HOME, isWin ? true : false));

    test(new TestState(false, false, false, KeyEvent.VK_END, isWin ? false : true));
    test(new TestState(false, true, false, KeyEvent.VK_END, isWin ? true : true));
    test(new TestState(false, true, true, KeyEvent.VK_END, isWin ? true : true));
    test(new TestState(true, false, false, KeyEvent.VK_END, isWin ? true : false));
    test(new TestState(true, false, true, KeyEvent.VK_END, isWin ? true : false));
    test(new TestState(true, true, false, KeyEvent.VK_END, isWin ? true : false));
    test(new TestState(true, true, true, KeyEvent.VK_END, isWin ? true : false));
  }
  void test() {

    robot.waitForIdle();

    if (!text.isFocusOwner()) {
      robot.mouseMove(text.getLocationOnScreen().x + 5, text.getLocationOnScreen().y + 5);
      robot.delay(100);
      robot.mousePress(MouseEvent.BUTTON1_MASK);
      robot.delay(100);
      robot.mouseRelease(MouseEvent.BUTTON1_MASK);

      int iter = 10;
      while (!text.isFocusOwner() && iter-- > 0) {
        robot.delay(200);
      }
      if (iter <= 0) {
        Sysout.println("Test: text field couldn't be focused!");
        return;
      }
    }

    robot.keyPress(KeyEvent.VK_A);
    robot.delay(100);
    robot.keyRelease(KeyEvent.VK_A);

    robot.waitForIdle();

    String charA = text.getText();
    System.err.println("Test: character typed with VK_A: " + charA);

    robot.keyPress(KeyEvent.VK_BACK_SPACE);
    robot.delay(100);
    robot.keyRelease(KeyEvent.VK_BACK_SPACE);

    robot.waitForIdle();

    if (jdk.testlibrary.OSInfo.getOSType() == jdk.testlibrary.OSInfo.OSType.MACOSX) {
      robot.keyPress(KeyEvent.VK_CONTROL);
    }
    robot.keyPress(KeyEvent.VK_ALT);
    robot.keyPress(KeyEvent.VK_F);
    robot.delay(100);
    robot.keyRelease(KeyEvent.VK_F);
    robot.keyRelease(KeyEvent.VK_ALT);
    if (jdk.testlibrary.OSInfo.getOSType() == jdk.testlibrary.OSInfo.OSType.MACOSX) {
      robot.keyRelease(KeyEvent.VK_CONTROL);
    }

    robot.waitForIdle();

    String string = text.getText();

    robot.keyPress(KeyEvent.VK_I);
    robot.delay(100);
    robot.keyRelease(KeyEvent.VK_I);

    robot.waitForIdle();

    Sysout.println("Test: character typed after mnemonic key press: " + text.getText());

    if (!text.getText().equals(string)) {
      throw new RuntimeException("Test failed!");
    }

    robot.keyPress(KeyEvent.VK_A);
    robot.delay(100);
    robot.keyRelease(KeyEvent.VK_A);

    robot.waitForIdle();

    System.err.println("Test: chracter typed with VK_A: " + text.getText());

    if (!charA.equals(text.getText())) {
      throw new RuntimeException("Test failed!");
    }

    Sysout.println("Test passed.");
  }