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 /* 25 @test 26 @key headful 27 @bug 6492970 28 @summary Tests that showing a toplvel in a not foreground Java process activates it. 29 @library ../../regtesthelpers 30 @build Util 31 @author Anton Tarasov: area=awt-focus 32 @run main ShowFrameCheckForegroundTest 33 */ 34 35 import java.awt.*; 36 import java.awt.event.*; 37 import java.applet.Applet; 38 import java.util.concurrent.atomic.AtomicBoolean; 39 import java.lang.reflect.InvocationTargetException; 40 import test.java.awt.regtesthelpers.Util; 41 42 public class ShowFrameCheckForegroundTest extends Applet { 43 Robot robot; 44 Frame nofocusFrame = new Frame("Non-focusable"); 45 Frame frame = new Frame("Frame"); 46 Dialog dialog1 = new Dialog(nofocusFrame, "Owned Dialog", false); 47 Dialog dialog2 = new Dialog((Frame)null, "Owned Dialog", false); 48 Window testToplevel = null; 49 Button testButton = new Button("button"); 50 Button showButton = new Button("show"); 51 Runnable action = new Runnable() { 52 public void run() { 53 robot.keyPress(KeyEvent.VK_SPACE); 54 robot.delay(50); 55 robot.keyRelease(KeyEvent.VK_SPACE); 56 } 57 }; 58 59 60 public static void main(String[] args) { 61 ShowFrameCheckForegroundTest app = new ShowFrameCheckForegroundTest(); 62 app.init(); 63 app.start(); 64 } 65 66 public void init() { 67 robot = Util.createRobot(); 68 } 69 70 public void start() { 71 showButton.addActionListener(new ActionListener() { 72 public void actionPerformed(ActionEvent e) { 73 testToplevel.setVisible(true); 74 } 75 }); 76 nofocusFrame.add(showButton); 77 nofocusFrame.pack(); 78 nofocusFrame.setFocusableWindowState(false); 79 nofocusFrame.setVisible(true); 80 Util.waitForIdle(robot); 81 82 robot.delay(3000); 83 84 // 1. Show the toplvel without clicking into the non-focusable frame. 85 test(frame, 1); 86 test(dialog1, 1); 87 test(dialog2, 1); 88 89 // 2. Showing the toplvel via clicking into the non-focusable frame. 90 test(frame, 2); 91 test(dialog1, 2); 92 test(dialog2, 2); 93 94 System.out.println("Test passed."); 95 } 96 97 private void test(Window toplevel, int stage) { 98 toplevel.add(testButton); 99 toplevel.pack(); 100 toplevel.setLocation(200, 0); 101 102 switch (stage) { 103 case 1: 104 toplevel.setVisible(true); 105 break; 106 case 2: 107 testToplevel = toplevel; 108 Util.clickOnComp(showButton, robot); 109 break; 110 } 111 Util.waitForIdle(robot); 112 113 if (!Util.trackActionPerformed(testButton, action, 2000, false)) { 114 throw new TestFailedException("Stage " + stage + ". The toplevel " + toplevel + " wasn't made foreground on showing"); 115 } 116 System.out.println("Stage " + stage + ". Toplevel " + toplevel + " - passed"); 117 toplevel.dispose(); 118 } 119 } 120 | 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 /* 25 @test 26 @key headful 27 @bug 6492970 28 @summary Tests that showing a toplvel in a not foreground Java process activates it. 29 @library ../../regtesthelpers 30 @build Util 31 @run main ShowFrameCheckForegroundTest 32 */ 33 34 import java.awt.*; 35 import java.awt.event.*; 36 import test.java.awt.regtesthelpers.Util; 37 38 public class ShowFrameCheckForegroundTest { 39 Robot robot; 40 Frame nofocusFrame = new Frame("Non-focusable"); 41 Frame frame = new Frame("Frame"); 42 Dialog dialog1 = new Dialog(nofocusFrame, "Owned Dialog", false); 43 Dialog dialog2 = new Dialog((Frame)null, "Owned Dialog", false); 44 Window testToplevel = null; 45 Button testButton = new Button("button"); 46 Button showButton = new Button("show"); 47 Runnable action = new Runnable() { 48 public void run() { 49 robot.keyPress(KeyEvent.VK_SPACE); 50 robot.delay(50); 51 robot.keyRelease(KeyEvent.VK_SPACE); 52 } 53 }; 54 55 56 public static void main(String[] args) { 57 ShowFrameCheckForegroundTest app = new ShowFrameCheckForegroundTest(); 58 app.init(); 59 app.start(); 60 } 61 62 public void init() { 63 robot = Util.createRobot(); 64 } 65 66 public void start() { 67 showButton.addActionListener(new ActionListener() { 68 public void actionPerformed(ActionEvent e) { 69 testToplevel.setVisible(true); 70 } 71 }); 72 nofocusFrame.add(showButton); 73 nofocusFrame.pack(); 74 nofocusFrame.setFocusableWindowState(false); 75 nofocusFrame.setLocation(200, 200); 76 nofocusFrame.setVisible(true); 77 Util.waitForIdle(robot); 78 79 robot.delay(3000); 80 81 // 1. Show the toplvel without clicking into the non-focusable frame. 82 test(frame, 1); 83 test(dialog1, 1); 84 test(dialog2, 1); 85 86 // 2. Showing the toplvel via clicking into the non-focusable frame. 87 test(frame, 2); 88 test(dialog1, 2); 89 test(dialog2, 2); 90 91 System.out.println("Test passed."); 92 } 93 94 private void test(Window toplevel, int stage) { 95 toplevel.add(testButton); 96 toplevel.pack(); 97 toplevel.setLocation(400, 200); 98 99 switch (stage) { 100 case 1: 101 toplevel.setVisible(true); 102 break; 103 case 2: 104 testToplevel = toplevel; 105 Util.clickOnComp(showButton, robot); 106 break; 107 } 108 Util.waitForIdle(robot); 109 110 if (!Util.trackActionPerformed(testButton, action, 2000, false)) { 111 throw new TestFailedException("Stage " + stage + ". The toplevel " + toplevel + " wasn't made foreground on showing"); 112 } 113 System.out.println("Stage " + stage + ". Toplevel " + toplevel + " - passed"); 114 toplevel.dispose(); 115 } 116 } 117 |