1 /*
   2  * Copyright (c) 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 package javafx.scene.control.test.jfxpanel;
  26 
  27 import client.test.ScreenshotCheck;
  28 import client.test.Smoke;
  29 import javafx.scene.Node;
  30 import javafx.scene.Scene;
  31 import javafx.scene.control.test.ControlsTestBase;
  32 import org.jemmy.Rectangle;
  33 import org.jemmy.control.Wrap;
  34 import org.jemmy.fx.ByID;
  35 import org.jemmy.fx.Root;
  36 import org.jemmy.interfaces.Parent;
  37 import org.junit.After;
  38 import org.junit.AfterClass;
  39 import org.junit.Before;
  40 import org.junit.BeforeClass;
  41 import org.junit.Test;
  42 import org.junit.runner.RunWith;
  43 import org.netbeans.jemmy.JemmyProperties;
  44 import test.javaclient.shared.FilteredTestRunner;
  45 import test.javaclient.shared.TestUtil;
  46 import test.javaclient.shared.screenshots.ScreenshotUtils;
  47 
  48 @RunWith(FilteredTestRunner.class)
  49 public class JFXPanelBrowserTest extends ControlsTestBase {
  50 
  51     static final int LOADING_DELAY = 7000;
  52     static final int SEQUENTIAL_REFRESH_DELAY = 2000;
  53 
  54     private static String proxyHost;
  55     private static String proxyPort;
  56 
  57     @BeforeClass
  58     public static void setUpClass() throws Exception {
  59         System.setProperty("javafx.swinginteroperability", "true");
  60         JFXPanelBrowserApp.main(null);
  61 
  62         //Save proxy settings
  63         proxyHost = System.getProperty("http.proxyHost");
  64         proxyPort = System.getProperty("http.proxyPort");
  65 
  66         System.setProperty("http.proxyHost", "www-proxy.us.oracle.com");
  67         System.setProperty("http.proxyPort", "80");
  68         //BrowserApp.main(null);
  69         JemmyProperties.setCurrentDispatchingModel(JemmyProperties.ROBOT_MODEL_MASK);
  70     }
  71 
  72     @AfterClass
  73     public static void tearDownClass() throws Exception {
  74         //Restore proxy settinigs
  75         System.setProperty("http.proxyHost", null == proxyHost ? "" : proxyHost);
  76         System.setProperty("http.proxyPort", null == proxyPort ? "" : proxyPort);
  77     }
  78 
  79     @Before
  80     public void setUp() {
  81     }
  82 
  83     @After
  84     public void tearDown() {
  85     }
  86 
  87 //    @ScreenshotCheck
  88 //    @Smoke
  89     @Test(timeout = 300000)
  90     public void browserTest() throws InterruptedException {
  91         Wrap<? extends Scene> scene = Root.ROOT.lookup().wrap();
  92         Parent<Node> parent = scene.as(Parent.class, Node.class);
  93         Wrap refresh = parent.lookup(new ByID<Node>(JFXPanelBrowserApp.BUTTON_ID)).wrap();
  94         Wrap content = parent.lookup(new ByID<Node>(JFXPanelBrowserApp.CONTENT_ID)).wrap();
  95         for (int i = 0; i < 3; i++) { // WebEngine bug
  96             refresh.mouse().click();
  97             Thread.sleep(SEQUENTIAL_REFRESH_DELAY);
  98         }
  99         Thread.sleep(LOADING_DELAY);
 100         Rectangle content_bounds = content.getScreenBounds();
 101         ScreenshotUtils.checkScreenshot("BrowserTest", content, new Rectangle((int) content_bounds.getWidth() - 25, (int) content_bounds.getHeight() - 25));
 102     }
 103 }