1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/test/script/jfx.js Mon Oct 21 13:31:03 2013 +0400 1.3 @@ -0,0 +1,92 @@ 1.4 +/* 1.5 + * Copyright (c) 2013, Oracle and/or its affiliates. All rights reserved. 1.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 1.7 + * 1.8 + * This code is free software; you can redistribute it and/or modify it 1.9 + * under the terms of the GNU General Public License version 2 only, as 1.10 + * published by the Free Software Foundation. 1.11 + * 1.12 + * This code is distributed in the hope that it will be useful, but WITHOUT 1.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 1.14 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 1.15 + * version 2 for more details (a copy is included in the LICENSE file that 1.16 + * accompanied this code). 1.17 + * 1.18 + * You should have received a copy of the GNU General Public License version 1.19 + * 2 along with this work; if not, write to the Free Software Foundation, 1.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 1.21 + * 1.22 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 1.23 + * or visit www.oracle.com if you need additional information or have any 1.24 + * questions. 1.25 + */ 1.26 + 1.27 +/** 1.28 + * Base library for JavaFX canvas run by Nashorn testing. 1.29 + * @subtest 1.30 + * 1.31 + * 1.32 + */ 1.33 + 1.34 +var System = Java.type("java.lang.System"); 1.35 +var AWTImage = Java.type("org.jemmy.image.AWTImage"); 1.36 +var PNGDecoder = Java.type("org.jemmy.image.PNGDecoder"); 1.37 +var JemmyFxRoot = Java.type("org.jemmy.fx.Root"); 1.38 +var AWTRobotCapturer = Java.type("org.jemmy.image.AWTRobotCapturer"); 1.39 +var ByWindowType = Java.type("org.jemmy.fx.ByWindowType"); 1.40 +var Scene = Java.type("javafx.scene.Scene"); 1.41 +var Stage = Java.type("javafx.stage.Stage"); 1.42 +var File = Java.type("java.io.File"); 1.43 +var Timer = Java.type("java.util.Timer"); 1.44 +var TimerTask = Java.type("java.util.TimerTask"); 1.45 +var OSInfo = Java.type("sun.awt.OSInfo"); 1.46 +var OSType = Java.type("sun.awt.OSInfo.OSType"); 1.47 +var StringBuffer = Java.type("java.lang.StringBuffer"); 1.48 + 1.49 +var WAIT = 2000; 1.50 +var TESTNAME = "test"; 1.51 +var fsep = System.getProperty("file.separator"); 1.52 + 1.53 +function checkImageAndExit() { 1.54 + var raceTimer = new Timer(true); 1.55 + var timerTask = new TimerTask() { 1.56 + run: function run() { 1.57 + var tmpdir = System.getProperty("java.io.tmpdir"); 1.58 + var timenow = (new Date()).getTime(); 1.59 + makeScreenShot(tmpdir + fsep + "screenshot" + timenow +".png"); 1.60 + var dupImg = isDuplicateImages(tmpdir + fsep + "screenshot" + timenow +".png", __DIR__ + "jfx" + fsep + TESTNAME + fsep + "golden"); 1.61 + (new File(mpdir + fsep + "screenshot" + timenow +".png")).delete(); 1.62 + if (!dupImg) System.err.println("ERROR: screenshot does not match golden image"); 1.63 + exit(0); 1.64 + } 1.65 + }; 1.66 + raceTimer.schedule(timerTask, WAIT); 1.67 +} 1.68 + 1.69 +function makeScreenShot(shootToImg) { 1.70 + JemmyFxRoot.ROOT.getEnvironment().setImageCapturer(new AWTRobotCapturer()); 1.71 + var wrap = JemmyFxRoot.ROOT.lookup(new ByWindowType($STAGE.class)).lookup(Scene.class).wrap(0); 1.72 + var imageJemmy = wrap.getScreenImage(); 1.73 + imageJemmy.save(shootToImg); 1.74 +} 1.75 + 1.76 +function isDuplicateImages(file1, file2) { 1.77 + var f1 = new File(file1); 1.78 + var f2; 1.79 + var sb = new StringBuffer(file2); 1.80 + if (OSInfo.getOSType() == OSType.WINDOWS) { 1.81 + f2 = new File(sb.append(fsep + "windows.png").toString()); 1.82 + } else if (OSInfo.getOSType() == OSType.LINUX) { 1.83 + f2 = new File(sb.append(fsep + "linux.png").toString()); 1.84 + } else if (OSInfo.getOSType() == OSType.MACOSX) { 1.85 + f2 = new File(sb.append(fsep + "macosx.png").toString()); 1.86 + } 1.87 + print(f1.getAbsolutePath()); 1.88 + print(f2.getAbsolutePath()); 1.89 + if (f1.exists() && f2.exists()) { 1.90 + var image1 = new AWTImage(PNGDecoder.decode(f1.getAbsolutePath())); 1.91 + var image2 = new AWTImage(PNGDecoder.decode(f2.getAbsolutePath())); 1.92 + return image1.compareTo(image2) == null ? true : false; 1.93 + } 1.94 + return false; 1.95 +}