test/script/jfx.js

Mon, 21 Oct 2013 13:31:03 +0400

author
kshefov
date
Mon, 21 Oct 2013 13:31:03 +0400
changeset 638
f22742d5daa3
child 667
bda654c6d59c
permissions
-rw-r--r--

8026871: NASHORN TEST: Enable possibility to test Nashorn use of JavaFX canvas.
Reviewed-by: jlaskey, sundar

kshefov@638 1 /*
kshefov@638 2 * Copyright (c) 2013, Oracle and/or its affiliates. All rights reserved.
kshefov@638 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
kshefov@638 4 *
kshefov@638 5 * This code is free software; you can redistribute it and/or modify it
kshefov@638 6 * under the terms of the GNU General Public License version 2 only, as
kshefov@638 7 * published by the Free Software Foundation.
kshefov@638 8 *
kshefov@638 9 * This code is distributed in the hope that it will be useful, but WITHOUT
kshefov@638 10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
kshefov@638 11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
kshefov@638 12 * version 2 for more details (a copy is included in the LICENSE file that
kshefov@638 13 * accompanied this code).
kshefov@638 14 *
kshefov@638 15 * You should have received a copy of the GNU General Public License version
kshefov@638 16 * 2 along with this work; if not, write to the Free Software Foundation,
kshefov@638 17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
kshefov@638 18 *
kshefov@638 19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
kshefov@638 20 * or visit www.oracle.com if you need additional information or have any
kshefov@638 21 * questions.
kshefov@638 22 */
kshefov@638 23
kshefov@638 24 /**
kshefov@638 25 * Base library for JavaFX canvas run by Nashorn testing.
kshefov@638 26 * @subtest
kshefov@638 27 *
kshefov@638 28 *
kshefov@638 29 */
kshefov@638 30
kshefov@638 31 var System = Java.type("java.lang.System");
kshefov@638 32 var AWTImage = Java.type("org.jemmy.image.AWTImage");
kshefov@638 33 var PNGDecoder = Java.type("org.jemmy.image.PNGDecoder");
kshefov@638 34 var JemmyFxRoot = Java.type("org.jemmy.fx.Root");
kshefov@638 35 var AWTRobotCapturer = Java.type("org.jemmy.image.AWTRobotCapturer");
kshefov@638 36 var ByWindowType = Java.type("org.jemmy.fx.ByWindowType");
kshefov@638 37 var Scene = Java.type("javafx.scene.Scene");
kshefov@638 38 var Stage = Java.type("javafx.stage.Stage");
kshefov@638 39 var File = Java.type("java.io.File");
kshefov@638 40 var Timer = Java.type("java.util.Timer");
kshefov@638 41 var TimerTask = Java.type("java.util.TimerTask");
kshefov@638 42 var OSInfo = Java.type("sun.awt.OSInfo");
kshefov@638 43 var OSType = Java.type("sun.awt.OSInfo.OSType");
kshefov@638 44 var StringBuffer = Java.type("java.lang.StringBuffer");
kshefov@638 45
kshefov@638 46 var WAIT = 2000;
kshefov@638 47 var TESTNAME = "test";
kshefov@638 48 var fsep = System.getProperty("file.separator");
kshefov@638 49
kshefov@638 50 function checkImageAndExit() {
kshefov@638 51 var raceTimer = new Timer(true);
kshefov@638 52 var timerTask = new TimerTask() {
kshefov@638 53 run: function run() {
kshefov@638 54 var tmpdir = System.getProperty("java.io.tmpdir");
kshefov@638 55 var timenow = (new Date()).getTime();
kshefov@638 56 makeScreenShot(tmpdir + fsep + "screenshot" + timenow +".png");
kshefov@638 57 var dupImg = isDuplicateImages(tmpdir + fsep + "screenshot" + timenow +".png", __DIR__ + "jfx" + fsep + TESTNAME + fsep + "golden");
kshefov@638 58 (new File(mpdir + fsep + "screenshot" + timenow +".png")).delete();
kshefov@638 59 if (!dupImg) System.err.println("ERROR: screenshot does not match golden image");
kshefov@638 60 exit(0);
kshefov@638 61 }
kshefov@638 62 };
kshefov@638 63 raceTimer.schedule(timerTask, WAIT);
kshefov@638 64 }
kshefov@638 65
kshefov@638 66 function makeScreenShot(shootToImg) {
kshefov@638 67 JemmyFxRoot.ROOT.getEnvironment().setImageCapturer(new AWTRobotCapturer());
kshefov@638 68 var wrap = JemmyFxRoot.ROOT.lookup(new ByWindowType($STAGE.class)).lookup(Scene.class).wrap(0);
kshefov@638 69 var imageJemmy = wrap.getScreenImage();
kshefov@638 70 imageJemmy.save(shootToImg);
kshefov@638 71 }
kshefov@638 72
kshefov@638 73 function isDuplicateImages(file1, file2) {
kshefov@638 74 var f1 = new File(file1);
kshefov@638 75 var f2;
kshefov@638 76 var sb = new StringBuffer(file2);
kshefov@638 77 if (OSInfo.getOSType() == OSType.WINDOWS) {
kshefov@638 78 f2 = new File(sb.append(fsep + "windows.png").toString());
kshefov@638 79 } else if (OSInfo.getOSType() == OSType.LINUX) {
kshefov@638 80 f2 = new File(sb.append(fsep + "linux.png").toString());
kshefov@638 81 } else if (OSInfo.getOSType() == OSType.MACOSX) {
kshefov@638 82 f2 = new File(sb.append(fsep + "macosx.png").toString());
kshefov@638 83 }
kshefov@638 84 print(f1.getAbsolutePath());
kshefov@638 85 print(f2.getAbsolutePath());
kshefov@638 86 if (f1.exists() && f2.exists()) {
kshefov@638 87 var image1 = new AWTImage(PNGDecoder.decode(f1.getAbsolutePath()));
kshefov@638 88 var image2 = new AWTImage(PNGDecoder.decode(f2.getAbsolutePath()));
kshefov@638 89 return image1.compareTo(image2) == null ? true : false;
kshefov@638 90 }
kshefov@638 91 return false;
kshefov@638 92 }

mercurial