/jdk/test/java/awt/Focus/RemoveAfterRequest/RemoveAfterRequest.java

https://github.com/Morriar/ProxyJDK · Java · 102 lines · 48 code · 12 blank · 42 comment · 3 complexity · 3065014916ece232f9b907c3bd51e49f MD5 · raw file

  1. /*
  2. * Copyright (c) 2009, Oracle and/or its affiliates. All rights reserved.
  3. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  4. *
  5. * This code is free software; you can redistribute it and/or modify it
  6. * under the terms of the GNU General Public License version 2 only, as
  7. * published by the Free Software Foundation.
  8. *
  9. * This code is distributed in the hope that it will be useful, but WITHOUT
  10. * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  11. * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
  12. * version 2 for more details (a copy is included in the LICENSE file that
  13. * accompanied this code).
  14. *
  15. * You should have received a copy of the GNU General Public License version
  16. * 2 along with this work; if not, write to the Free Software Foundation,
  17. * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  18. *
  19. * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  20. * or visit www.oracle.com if you need additional information or have any
  21. * questions.
  22. */
  23. /*
  24. @test
  25. @bug 6411406
  26. @summary Components automatically transfer focus on removal, even if developer requests focus elsewhere first
  27. @author oleg.sukhodolsky, anton.tarasov: area=awt.focus
  28. @library ../../regtesthelpers
  29. @build Util
  30. @run main RemoveAfterRequest
  31. */
  32. /**
  33. * RemoveAfterRequest.java
  34. *
  35. * summary: Components automatically transfer focus on removal, even if developer requests focus elsewhere first
  36. */
  37. import java.awt.*;
  38. import java.awt.event.*;
  39. import test.java.awt.regtesthelpers.Util;
  40. public class RemoveAfterRequest {
  41. final static Frame frame = new Frame("test frame");
  42. final static Button btn1 = new Button("btn1");
  43. final static Button btn2 = new Button("btn2");
  44. final static Button btn3 = new Button("btn3");
  45. public static void main(String[] args) {
  46. frame.setLayout(new GridLayout(3, 1));
  47. frame.add(btn1);
  48. frame.add(btn2);
  49. frame.add(btn3);
  50. frame.pack();
  51. frame.setVisible(true);
  52. Util.waitForIdle(null);
  53. if (!btn1.hasFocus()) {
  54. btn1.requestFocus();
  55. Util.waitForIdle(null);
  56. if (!btn1.hasFocus()) {
  57. throw new TestErrorException("couldn't focus " + btn1);
  58. }
  59. }
  60. if (!Util.trackFocusGained(btn3, new Runnable() {
  61. public void run() {
  62. btn3.requestFocus();
  63. frame.remove(btn1);
  64. frame.invalidate();
  65. frame.validate();
  66. frame.repaint();
  67. }
  68. }, 2000, true))
  69. {
  70. throw new TestFailedException("focus request on removal failed");
  71. }
  72. System.out.println("Test passed.");
  73. }
  74. }
  75. /**
  76. * Thrown when the behavior being verified is found wrong.
  77. */
  78. class TestFailedException extends RuntimeException {
  79. TestFailedException(String msg) {
  80. super("Test failed: " + msg);
  81. }
  82. }
  83. /**
  84. * Thrown when an error not related to the behavior being verified is encountered.
  85. */
  86. class TestErrorException extends RuntimeException {
  87. TestErrorException(String msg) {
  88. super("Unexpected error: " + msg);
  89. }
  90. }