Path: blob/aarch64-shenandoah-jdk8u272-b10/nashorn/test/script/jfx.js
32281 views
/*1* Copyright (c) 2013, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation.7*8* This code is distributed in the hope that it will be useful, but WITHOUT9* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or10* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License11* version 2 for more details (a copy is included in the LICENSE file that12* accompanied this code).13*14* You should have received a copy of the GNU General Public License version15* 2 along with this work; if not, write to the Free Software Foundation,16* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.17*18* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA19* or visit www.oracle.com if you need additional information or have any20* questions.21*/2223/**24* Base library for JavaFX canvas run by Nashorn testing.25* @subtest26*27*28*/2930var System = Java.type("java.lang.System");31var AWTImage = Java.type("org.jemmy.image.AWTImage");32var PNGDecoder = Java.type("org.jemmy.image.PNGDecoder");33var JemmyFxRoot = Java.type("org.jemmy.fx.Root");34var AWTRobotCapturer = Java.type("org.jemmy.image.AWTRobotCapturer");35var ByWindowType = Java.type("org.jemmy.fx.ByWindowType");36var Scene = Java.type("javafx.scene.Scene");37var Stage = Java.type("javafx.stage.Stage");38var File = Java.type("java.io.File");39var OSInfo = Java.type("sun.awt.OSInfo");40var OSType = Java.type("sun.awt.OSInfo.OSType");41var StringBuffer = Java.type("java.lang.StringBuffer");42var Paint = Java.type("javafx.scene.paint.Paint");43var Color = Java.type("javafx.scene.paint.Color");44var Image = Java.type("javafx.scene.image.Image");45var Canvas = Java.type("javafx.scene.canvas.Canvas");46var BorderPane = Java.type("javafx.scene.layout.BorderPane");47var StackPane = Java.type("javafx.scene.layout.StackPane");48var StrokeLineCap = Java.type("javafx.scene.shape.StrokeLineCap");49var Platform = Java.type("javafx.application.Platform");50var Runnable = Java.type("java.lang.Runnable");51var RunnableExtend = Java.extend(Runnable);52var AnimationTimer = Java.type("javafx.animation.AnimationTimer");53var AnimationTimerExtend = Java.extend(AnimationTimer);54var Timer = Java.type("java.util.Timer");55var TimerTask = Java.type("java.util.TimerTask");5657var TESTNAME = "test";58var fsep = System.getProperty("file.separator");5960function checkImageAndExit() {61var raceTimer = new Timer(true);62var timerTask = new TimerTask() {63run: function run() {64var tmpdir = System.getProperty("java.io.tmpdir");65var timenow = (new Date()).getTime();66var scrShotTmp = tmpdir + fsep + "screenshot" + timenow +".png";67var goldenImageDir = __DIR__ + "jfx" + fsep + TESTNAME + fsep + "golden";68makeScreenShot(scrShotTmp);69var dupImg = isDuplicateImages(scrShotTmp, goldenImageDir);70(new File(scrShotTmp)).delete();71if (!dupImg) System.err.println("ERROR: screenshot does not match the golden image");72exit(0);73}74};75raceTimer.schedule(timerTask, 100);76}7778function makeScreenShot(shootToImg) {79JemmyFxRoot.ROOT.getEnvironment().setImageCapturer(new AWTRobotCapturer());80var wrap = JemmyFxRoot.ROOT.lookup(new ByWindowType($STAGE.class)).lookup(Scene.class).wrap(0);81var imageJemmy = wrap.getScreenImage();82imageJemmy.save(shootToImg);83}8485function isDuplicateImages(screenShot, goldenDir) {86var f1 = new File(screenShot);87var f2;88var sb = new StringBuffer(goldenDir);89if (OSInfo.getOSType() == OSType.WINDOWS) {90f2 = new File(sb.append(fsep + "windows.png").toString());91} else if (OSInfo.getOSType() == OSType.LINUX) {92f2 = new File(sb.append(fsep + "linux.png").toString());93} else if (OSInfo.getOSType() == OSType.MACOSX) {94f2 = new File(sb.append(fsep + "macosx.png").toString());95}96if (f1.exists() && f2.exists()) {97var image1 = new AWTImage(PNGDecoder.decode(f1.getAbsolutePath()));98var image2 = new AWTImage(PNGDecoder.decode(f2.getAbsolutePath()));99return image1.compareTo(image2) == null ? true : false;100}101return false;102}103104105