1 /* 2 * Copyright (c) 2012, 2014, 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. Oracle designates this 8 * particular file as subject to the "Classpath" exception as provided 9 * by Oracle in the LICENSE file that accompanied this code. 10 * 11 * This code is distributed in the hope that it will be useful, but WITHOUT 12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 14 * version 2 for more details (a copy is included in the LICENSE file that 15 * accompanied this code). 16 * 17 * You should have received a copy of the GNU General Public License version 18 * 2 along with this work; if not, write to the Free Software Foundation, 19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 20 * 21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 22 * or visit www.oracle.com if you need additional information or have any 23 * questions. 24 */ 25 26 package test.com.sun.javafx.application; 27 28 import com.sun.javafx.application.PlatformImpl; 29 import com.sun.javafx.application.PlatformImplShim; 30 import java.util.concurrent.CountDownLatch; 31 import java.util.concurrent.TimeUnit; 32 import javafx.application.Platform; 33 import junit.framework.AssertionFailedError; 34 35 import static org.junit.Assert.*; 36 import static test.util.Util.TIMEOUT; 37 38 39 /** 40 * Test program for PlatformImpl 41 * Each of the tests must be run in a separate JVM which is why each 42 * is in its own subclass. 43 */ 44 public class TaskbarAppCommon { 45 46 // Used to launch the platform before running any test 47 private final CountDownLatch launchLatch = new CountDownLatch(1); 48 49 private void startup() { 50 // Start the FX Platform 51 new Thread(() -> PlatformImpl.startup(() -> { 52 assertTrue(Platform.isFxApplicationThread()); 53 launchLatch.countDown(); 54 })).start(); 55 56 try { 57 if (!launchLatch.await(TIMEOUT, TimeUnit.MILLISECONDS)) { 58 throw new AssertionFailedError("Timeout waiting for Platform to start"); 59 } 60 } catch (InterruptedException ex) { 61 AssertionFailedError err = new AssertionFailedError("Unexpected exception"); 62 err.initCause(ex); 63 throw err; 64 } 65 assertEquals(0, launchLatch.getCount()); 66 final CountDownLatch exitLatch = PlatformImplShim.test_getPlatformExitLatch(); 67 assertEquals(1, exitLatch.getCount()); 68 } 69 70 // ========================== TEST CASES ========================== 71 72 public void doTestTaskbarAppDefault() { 73 assertTrue(PlatformImpl.isTaskbarApplication()); 74 } 75 76 public void doTestTaskbarAppSetGet() { 77 PlatformImpl.setTaskbarApplication(false); 78 assertFalse(PlatformImpl.isTaskbarApplication()); 79 PlatformImpl.setTaskbarApplication(true); 80 assertTrue(PlatformImpl.isTaskbarApplication()); 81 } 82 83 public void doTestTaskbarAppStartDefault() { 84 assertTrue(PlatformImpl.isTaskbarApplication()); 85 String taskbarAppProp = System.getProperty("glass.taskbarApplication"); 86 assertNull(taskbarAppProp); 87 startup(); 88 taskbarAppProp = System.getProperty("glass.taskbarApplication"); 89 assertNull(taskbarAppProp); 90 boolean isTaskbarApp = !"false".equalsIgnoreCase(taskbarAppProp); 91 assertTrue(isTaskbarApp); 92 taskbarAppProp = System.getProperty("glass.taskbarApplication", "true"); 93 isTaskbarApp = !"false".equalsIgnoreCase(taskbarAppProp); 94 assertTrue(isTaskbarApp); 95 Platform.exit(); 96 } 97 98 public void doTestTaskbarAppStartFalse() { 99 PlatformImpl.setTaskbarApplication(false); 100 assertFalse(PlatformImpl.isTaskbarApplication()); 101 String taskbarAppProp = System.getProperty("glass.taskbarApplication"); 102 assertNull(taskbarAppProp); 103 startup(); 104 taskbarAppProp = System.getProperty("glass.taskbarApplication"); 105 assertNotNull(taskbarAppProp); 106 boolean isTaskbarApp = !"false".equalsIgnoreCase(taskbarAppProp); 107 assertFalse(isTaskbarApp); 108 taskbarAppProp = System.getProperty("glass.taskbarApplication", "true"); 109 isTaskbarApp = !"false".equalsIgnoreCase(taskbarAppProp); 110 assertFalse(isTaskbarApp); 111 Platform.exit(); 112 } 113 114 public void doTestTaskbarAppStartTrue() { 115 PlatformImpl.setTaskbarApplication(true); 116 assertTrue(PlatformImpl.isTaskbarApplication()); 117 String taskbarAppProp = System.getProperty("glass.taskbarApplication"); 118 assertNull(taskbarAppProp); 119 startup(); 120 taskbarAppProp = System.getProperty("glass.taskbarApplication"); 121 assertNull(taskbarAppProp); 122 boolean isTaskbarApp = !"false".equalsIgnoreCase(taskbarAppProp); 123 assertTrue(isTaskbarApp); 124 taskbarAppProp = System.getProperty("glass.taskbarApplication", "true"); 125 isTaskbarApp = !"false".equalsIgnoreCase(taskbarAppProp); 126 assertTrue(isTaskbarApp); 127 Platform.exit(); 128 } 129 130 }