Tue, 15 Sep 2015 16:17:33 +0530
8055917: jdk.nashorn.internal.codegen.CompilationPhase$N should be renamed to proper classes
Reviewed-by: attila, hannesw, mhaupt
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 OSInfo = Java.type("sun.awt.OSInfo"); |
kshefov@638 | 41 | var OSType = Java.type("sun.awt.OSInfo.OSType"); |
kshefov@638 | 42 | var StringBuffer = Java.type("java.lang.StringBuffer"); |
kshefov@667 | 43 | var Paint = Java.type("javafx.scene.paint.Paint"); |
kshefov@667 | 44 | var Color = Java.type("javafx.scene.paint.Color"); |
kshefov@667 | 45 | var Image = Java.type("javafx.scene.image.Image"); |
kshefov@667 | 46 | var Canvas = Java.type("javafx.scene.canvas.Canvas"); |
kshefov@667 | 47 | var BorderPane = Java.type("javafx.scene.layout.BorderPane"); |
kshefov@667 | 48 | var StackPane = Java.type("javafx.scene.layout.StackPane"); |
kshefov@667 | 49 | var StrokeLineCap = Java.type("javafx.scene.shape.StrokeLineCap"); |
kshefov@667 | 50 | var Platform = Java.type("javafx.application.Platform"); |
kshefov@667 | 51 | var Runnable = Java.type("java.lang.Runnable"); |
kshefov@667 | 52 | var RunnableExtend = Java.extend(Runnable); |
kshefov@667 | 53 | var AnimationTimer = Java.type("javafx.animation.AnimationTimer"); |
kshefov@667 | 54 | var AnimationTimerExtend = Java.extend(AnimationTimer); |
kshefov@667 | 55 | var Timer = Java.type("java.util.Timer"); |
kshefov@667 | 56 | var TimerTask = Java.type("java.util.TimerTask"); |
kshefov@638 | 57 | |
kshefov@638 | 58 | var TESTNAME = "test"; |
kshefov@638 | 59 | var fsep = System.getProperty("file.separator"); |
kshefov@638 | 60 | |
kshefov@638 | 61 | function checkImageAndExit() { |
kshefov@638 | 62 | var raceTimer = new Timer(true); |
kshefov@638 | 63 | var timerTask = new TimerTask() { |
kshefov@638 | 64 | run: function run() { |
kshefov@638 | 65 | var tmpdir = System.getProperty("java.io.tmpdir"); |
kshefov@638 | 66 | var timenow = (new Date()).getTime(); |
kshefov@667 | 67 | var scrShotTmp = tmpdir + fsep + "screenshot" + timenow +".png"; |
kshefov@667 | 68 | var goldenImageDir = __DIR__ + "jfx" + fsep + TESTNAME + fsep + "golden"; |
kshefov@667 | 69 | makeScreenShot(scrShotTmp); |
kshefov@667 | 70 | var dupImg = isDuplicateImages(scrShotTmp, goldenImageDir); |
kshefov@667 | 71 | (new File(scrShotTmp)).delete(); |
kshefov@667 | 72 | if (!dupImg) System.err.println("ERROR: screenshot does not match the golden image"); |
kshefov@638 | 73 | exit(0); |
kshefov@638 | 74 | } |
kshefov@638 | 75 | }; |
kshefov@667 | 76 | raceTimer.schedule(timerTask, 100); |
kshefov@638 | 77 | } |
kshefov@638 | 78 | |
kshefov@638 | 79 | function makeScreenShot(shootToImg) { |
kshefov@638 | 80 | JemmyFxRoot.ROOT.getEnvironment().setImageCapturer(new AWTRobotCapturer()); |
kshefov@638 | 81 | var wrap = JemmyFxRoot.ROOT.lookup(new ByWindowType($STAGE.class)).lookup(Scene.class).wrap(0); |
kshefov@638 | 82 | var imageJemmy = wrap.getScreenImage(); |
kshefov@638 | 83 | imageJemmy.save(shootToImg); |
kshefov@638 | 84 | } |
kshefov@638 | 85 | |
kshefov@667 | 86 | function isDuplicateImages(screenShot, goldenDir) { |
kshefov@667 | 87 | var f1 = new File(screenShot); |
kshefov@638 | 88 | var f2; |
kshefov@667 | 89 | var sb = new StringBuffer(goldenDir); |
kshefov@638 | 90 | if (OSInfo.getOSType() == OSType.WINDOWS) { |
kshefov@638 | 91 | f2 = new File(sb.append(fsep + "windows.png").toString()); |
kshefov@638 | 92 | } else if (OSInfo.getOSType() == OSType.LINUX) { |
kshefov@638 | 93 | f2 = new File(sb.append(fsep + "linux.png").toString()); |
kshefov@638 | 94 | } else if (OSInfo.getOSType() == OSType.MACOSX) { |
kshefov@638 | 95 | f2 = new File(sb.append(fsep + "macosx.png").toString()); |
kshefov@638 | 96 | } |
kshefov@638 | 97 | if (f1.exists() && f2.exists()) { |
kshefov@638 | 98 | var image1 = new AWTImage(PNGDecoder.decode(f1.getAbsolutePath())); |
kshefov@638 | 99 | var image2 = new AWTImage(PNGDecoder.decode(f2.getAbsolutePath())); |
kshefov@638 | 100 | return image1.compareTo(image2) == null ? true : false; |
kshefov@638 | 101 | } |
kshefov@638 | 102 | return false; |
kshefov@638 | 103 | } |