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 com.sun.javafx.application;
  27 
  28 import java.util.concurrent.CountDownLatch;
  29 import java.util.concurrent.TimeUnit;
  30 import javafx.application.Platform;
  31 import junit.framework.AssertionFailedError;
  32 
  33 import static org.junit.Assert.*;
  34 import static util.Util.TIMEOUT;
  35 
  36 
  37 /**
  38  * Test program for PlatformImpl
  39  * Each of the tests must be run in a separate JVM which is why each
  40  * is in its own subclass.
  41  */
  42 public class TaskbarAppCommon {
  43 
  44     // Used to launch the platform before running any test
  45     private final CountDownLatch launchLatch = new CountDownLatch(1);
  46 
  47     private void startup() {
  48         // Start the FX Platform
  49         new Thread(() -> PlatformImpl.startup(() -> {
  50             assertTrue(Platform.isFxApplicationThread());
  51             launchLatch.countDown();
  52         })).start();
  53 
  54         try {
  55             if (!launchLatch.await(TIMEOUT, TimeUnit.MILLISECONDS)) {
  56                 throw new AssertionFailedError("Timeout waiting for Platform to start");
  57             }
  58         } catch (InterruptedException ex) {
  59             AssertionFailedError err = new AssertionFailedError("Unexpected exception");
  60             err.initCause(ex);
  61             throw err;
  62         }
  63         assertEquals(0, launchLatch.getCount());
  64         final CountDownLatch exitLatch = PlatformImpl.test_getPlatformExitLatch();
  65         assertEquals(1, exitLatch.getCount());
  66     }
  67 
  68     // ========================== TEST CASES ==========================
  69 
  70     public void doTestTaskbarAppDefault() {
  71         assertTrue(PlatformImpl.isTaskbarApplication());
  72     }
  73 
  74     public void doTestTaskbarAppSetGet() {
  75         PlatformImpl.setTaskbarApplication(false);
  76         assertFalse(PlatformImpl.isTaskbarApplication());
  77         PlatformImpl.setTaskbarApplication(true);
  78         assertTrue(PlatformImpl.isTaskbarApplication());
  79     }
  80 
  81     public void doTestTaskbarAppStartDefault() {
  82         assertTrue(PlatformImpl.isTaskbarApplication());
  83         String taskbarAppProp = System.getProperty("glass.taskbarApplication");
  84         assertNull(taskbarAppProp);
  85         startup();
  86         taskbarAppProp = System.getProperty("glass.taskbarApplication");
  87         assertNull(taskbarAppProp);
  88         boolean isTaskbarApp = !"false".equalsIgnoreCase(taskbarAppProp);
  89         assertTrue(isTaskbarApp);
  90         taskbarAppProp = System.getProperty("glass.taskbarApplication", "true");
  91         isTaskbarApp = !"false".equalsIgnoreCase(taskbarAppProp);
  92         assertTrue(isTaskbarApp);
  93         Platform.exit();
  94     }
  95 
  96     public void doTestTaskbarAppStartFalse() {
  97         PlatformImpl.setTaskbarApplication(false);
  98         assertFalse(PlatformImpl.isTaskbarApplication());
  99         String taskbarAppProp = System.getProperty("glass.taskbarApplication");
 100         assertNull(taskbarAppProp);
 101         startup();
 102         taskbarAppProp = System.getProperty("glass.taskbarApplication");
 103         assertNotNull(taskbarAppProp);
 104         boolean isTaskbarApp = !"false".equalsIgnoreCase(taskbarAppProp);
 105         assertFalse(isTaskbarApp);
 106         taskbarAppProp = System.getProperty("glass.taskbarApplication", "true");
 107         isTaskbarApp = !"false".equalsIgnoreCase(taskbarAppProp);
 108         assertFalse(isTaskbarApp);
 109         Platform.exit();
 110     }
 111 
 112     public void doTestTaskbarAppStartTrue() {
 113         PlatformImpl.setTaskbarApplication(true);
 114         assertTrue(PlatformImpl.isTaskbarApplication());
 115         String taskbarAppProp = System.getProperty("glass.taskbarApplication");
 116         assertNull(taskbarAppProp);
 117         startup();
 118         taskbarAppProp = System.getProperty("glass.taskbarApplication");
 119         assertNull(taskbarAppProp);
 120         boolean isTaskbarApp = !"false".equalsIgnoreCase(taskbarAppProp);
 121         assertTrue(isTaskbarApp);
 122         taskbarAppProp = System.getProperty("glass.taskbarApplication", "true");
 123         isTaskbarApp = !"false".equalsIgnoreCase(taskbarAppProp);
 124         assertTrue(isTaskbarApp);
 125         Platform.exit();
 126     }
 127 
 128 }