nashorn/test/script/jfx.js
author ssadetsky
Tue, 04 Aug 2015 12:58:50 +0300
changeset 32131 f6daa59ae211
parent 21690 ffbb4611d1f4
permissions -rw-r--r--
8130892: Test javax/swing/plaf/basic/BasicTextUI/8001470/bug8001470.java fails in Solaris Sparcv9 Reviewed-by: alexsch, serb
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
21443
85671274e5fb 8026871: NASHORN TEST: Enable possibility to test Nashorn use of JavaFX canvas.
kshefov
parents:
diff changeset
     1
/*
85671274e5fb 8026871: NASHORN TEST: Enable possibility to test Nashorn use of JavaFX canvas.
kshefov
parents:
diff changeset
     2
 * Copyright (c) 2013, Oracle and/or its affiliates. All rights reserved.
85671274e5fb 8026871: NASHORN TEST: Enable possibility to test Nashorn use of JavaFX canvas.
kshefov
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
85671274e5fb 8026871: NASHORN TEST: Enable possibility to test Nashorn use of JavaFX canvas.
kshefov
parents:
diff changeset
     4
 * 
85671274e5fb 8026871: NASHORN TEST: Enable possibility to test Nashorn use of JavaFX canvas.
kshefov
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
85671274e5fb 8026871: NASHORN TEST: Enable possibility to test Nashorn use of JavaFX canvas.
kshefov
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
85671274e5fb 8026871: NASHORN TEST: Enable possibility to test Nashorn use of JavaFX canvas.
kshefov
parents:
diff changeset
     7
 * published by the Free Software Foundation.
85671274e5fb 8026871: NASHORN TEST: Enable possibility to test Nashorn use of JavaFX canvas.
kshefov
parents:
diff changeset
     8
 * 
85671274e5fb 8026871: NASHORN TEST: Enable possibility to test Nashorn use of JavaFX canvas.
kshefov
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
85671274e5fb 8026871: NASHORN TEST: Enable possibility to test Nashorn use of JavaFX canvas.
kshefov
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
85671274e5fb 8026871: NASHORN TEST: Enable possibility to test Nashorn use of JavaFX canvas.
kshefov
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
85671274e5fb 8026871: NASHORN TEST: Enable possibility to test Nashorn use of JavaFX canvas.
kshefov
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
85671274e5fb 8026871: NASHORN TEST: Enable possibility to test Nashorn use of JavaFX canvas.
kshefov
parents:
diff changeset
    13
 * accompanied this code).
85671274e5fb 8026871: NASHORN TEST: Enable possibility to test Nashorn use of JavaFX canvas.
kshefov
parents:
diff changeset
    14
 * 
85671274e5fb 8026871: NASHORN TEST: Enable possibility to test Nashorn use of JavaFX canvas.
kshefov
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
85671274e5fb 8026871: NASHORN TEST: Enable possibility to test Nashorn use of JavaFX canvas.
kshefov
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
85671274e5fb 8026871: NASHORN TEST: Enable possibility to test Nashorn use of JavaFX canvas.
kshefov
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
85671274e5fb 8026871: NASHORN TEST: Enable possibility to test Nashorn use of JavaFX canvas.
kshefov
parents:
diff changeset
    18
 * 
85671274e5fb 8026871: NASHORN TEST: Enable possibility to test Nashorn use of JavaFX canvas.
kshefov
parents:
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
85671274e5fb 8026871: NASHORN TEST: Enable possibility to test Nashorn use of JavaFX canvas.
kshefov
parents:
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
85671274e5fb 8026871: NASHORN TEST: Enable possibility to test Nashorn use of JavaFX canvas.
kshefov
parents:
diff changeset
    21
 * questions.
85671274e5fb 8026871: NASHORN TEST: Enable possibility to test Nashorn use of JavaFX canvas.
kshefov
parents:
diff changeset
    22
 */
85671274e5fb 8026871: NASHORN TEST: Enable possibility to test Nashorn use of JavaFX canvas.
kshefov
parents:
diff changeset
    23
85671274e5fb 8026871: NASHORN TEST: Enable possibility to test Nashorn use of JavaFX canvas.
kshefov
parents:
diff changeset
    24
/**
85671274e5fb 8026871: NASHORN TEST: Enable possibility to test Nashorn use of JavaFX canvas.
kshefov
parents:
diff changeset
    25
 * Base library for JavaFX canvas run by Nashorn testing.
85671274e5fb 8026871: NASHORN TEST: Enable possibility to test Nashorn use of JavaFX canvas.
kshefov
parents:
diff changeset
    26
 * @subtest
85671274e5fb 8026871: NASHORN TEST: Enable possibility to test Nashorn use of JavaFX canvas.
kshefov
parents:
diff changeset
    27
 * 
85671274e5fb 8026871: NASHORN TEST: Enable possibility to test Nashorn use of JavaFX canvas.
kshefov
parents:
diff changeset
    28
 * 
85671274e5fb 8026871: NASHORN TEST: Enable possibility to test Nashorn use of JavaFX canvas.
kshefov
parents:
diff changeset
    29
 */
85671274e5fb 8026871: NASHORN TEST: Enable possibility to test Nashorn use of JavaFX canvas.
kshefov
parents:
diff changeset
    30
85671274e5fb 8026871: NASHORN TEST: Enable possibility to test Nashorn use of JavaFX canvas.
kshefov
parents:
diff changeset
    31
var System               = Java.type("java.lang.System");
85671274e5fb 8026871: NASHORN TEST: Enable possibility to test Nashorn use of JavaFX canvas.
kshefov
parents:
diff changeset
    32
var AWTImage             = Java.type("org.jemmy.image.AWTImage");
85671274e5fb 8026871: NASHORN TEST: Enable possibility to test Nashorn use of JavaFX canvas.
kshefov
parents:
diff changeset
    33
var PNGDecoder           = Java.type("org.jemmy.image.PNGDecoder");
85671274e5fb 8026871: NASHORN TEST: Enable possibility to test Nashorn use of JavaFX canvas.
kshefov
parents:
diff changeset
    34
var JemmyFxRoot          = Java.type("org.jemmy.fx.Root");
85671274e5fb 8026871: NASHORN TEST: Enable possibility to test Nashorn use of JavaFX canvas.
kshefov
parents:
diff changeset
    35
var AWTRobotCapturer     = Java.type("org.jemmy.image.AWTRobotCapturer");
85671274e5fb 8026871: NASHORN TEST: Enable possibility to test Nashorn use of JavaFX canvas.
kshefov
parents:
diff changeset
    36
var ByWindowType         = Java.type("org.jemmy.fx.ByWindowType");
85671274e5fb 8026871: NASHORN TEST: Enable possibility to test Nashorn use of JavaFX canvas.
kshefov
parents:
diff changeset
    37
var Scene                = Java.type("javafx.scene.Scene");
85671274e5fb 8026871: NASHORN TEST: Enable possibility to test Nashorn use of JavaFX canvas.
kshefov
parents:
diff changeset
    38
var Stage                = Java.type("javafx.stage.Stage");
85671274e5fb 8026871: NASHORN TEST: Enable possibility to test Nashorn use of JavaFX canvas.
kshefov
parents:
diff changeset
    39
var File                 = Java.type("java.io.File");
85671274e5fb 8026871: NASHORN TEST: Enable possibility to test Nashorn use of JavaFX canvas.
kshefov
parents:
diff changeset
    40
var OSInfo               = Java.type("sun.awt.OSInfo");
85671274e5fb 8026871: NASHORN TEST: Enable possibility to test Nashorn use of JavaFX canvas.
kshefov
parents:
diff changeset
    41
var OSType               = Java.type("sun.awt.OSInfo.OSType");
85671274e5fb 8026871: NASHORN TEST: Enable possibility to test Nashorn use of JavaFX canvas.
kshefov
parents:
diff changeset
    42
var StringBuffer         = Java.type("java.lang.StringBuffer");
21690
ffbb4611d1f4 8027708: NASHORN TEST: Create Nashorn test that draws image step-by-step using JavaFX canvas.
kshefov
parents: 21443
diff changeset
    43
var Paint                = Java.type("javafx.scene.paint.Paint");
ffbb4611d1f4 8027708: NASHORN TEST: Create Nashorn test that draws image step-by-step using JavaFX canvas.
kshefov
parents: 21443
diff changeset
    44
var Color                = Java.type("javafx.scene.paint.Color");
ffbb4611d1f4 8027708: NASHORN TEST: Create Nashorn test that draws image step-by-step using JavaFX canvas.
kshefov
parents: 21443
diff changeset
    45
var Image                = Java.type("javafx.scene.image.Image");
ffbb4611d1f4 8027708: NASHORN TEST: Create Nashorn test that draws image step-by-step using JavaFX canvas.
kshefov
parents: 21443
diff changeset
    46
var Canvas               = Java.type("javafx.scene.canvas.Canvas");
ffbb4611d1f4 8027708: NASHORN TEST: Create Nashorn test that draws image step-by-step using JavaFX canvas.
kshefov
parents: 21443
diff changeset
    47
var BorderPane           = Java.type("javafx.scene.layout.BorderPane");
ffbb4611d1f4 8027708: NASHORN TEST: Create Nashorn test that draws image step-by-step using JavaFX canvas.
kshefov
parents: 21443
diff changeset
    48
var StackPane            = Java.type("javafx.scene.layout.StackPane");
ffbb4611d1f4 8027708: NASHORN TEST: Create Nashorn test that draws image step-by-step using JavaFX canvas.
kshefov
parents: 21443
diff changeset
    49
var StrokeLineCap        = Java.type("javafx.scene.shape.StrokeLineCap");
ffbb4611d1f4 8027708: NASHORN TEST: Create Nashorn test that draws image step-by-step using JavaFX canvas.
kshefov
parents: 21443
diff changeset
    50
var Platform             = Java.type("javafx.application.Platform");
ffbb4611d1f4 8027708: NASHORN TEST: Create Nashorn test that draws image step-by-step using JavaFX canvas.
kshefov
parents: 21443
diff changeset
    51
var Runnable             = Java.type("java.lang.Runnable");
ffbb4611d1f4 8027708: NASHORN TEST: Create Nashorn test that draws image step-by-step using JavaFX canvas.
kshefov
parents: 21443
diff changeset
    52
var RunnableExtend       = Java.extend(Runnable);
ffbb4611d1f4 8027708: NASHORN TEST: Create Nashorn test that draws image step-by-step using JavaFX canvas.
kshefov
parents: 21443
diff changeset
    53
var AnimationTimer       = Java.type("javafx.animation.AnimationTimer");
ffbb4611d1f4 8027708: NASHORN TEST: Create Nashorn test that draws image step-by-step using JavaFX canvas.
kshefov
parents: 21443
diff changeset
    54
var AnimationTimerExtend = Java.extend(AnimationTimer);
ffbb4611d1f4 8027708: NASHORN TEST: Create Nashorn test that draws image step-by-step using JavaFX canvas.
kshefov
parents: 21443
diff changeset
    55
var Timer                = Java.type("java.util.Timer");
ffbb4611d1f4 8027708: NASHORN TEST: Create Nashorn test that draws image step-by-step using JavaFX canvas.
kshefov
parents: 21443
diff changeset
    56
var TimerTask            = Java.type("java.util.TimerTask");
21443
85671274e5fb 8026871: NASHORN TEST: Enable possibility to test Nashorn use of JavaFX canvas.
kshefov
parents:
diff changeset
    57
85671274e5fb 8026871: NASHORN TEST: Enable possibility to test Nashorn use of JavaFX canvas.
kshefov
parents:
diff changeset
    58
var TESTNAME = "test";
85671274e5fb 8026871: NASHORN TEST: Enable possibility to test Nashorn use of JavaFX canvas.
kshefov
parents:
diff changeset
    59
var fsep = System.getProperty("file.separator");
85671274e5fb 8026871: NASHORN TEST: Enable possibility to test Nashorn use of JavaFX canvas.
kshefov
parents:
diff changeset
    60
85671274e5fb 8026871: NASHORN TEST: Enable possibility to test Nashorn use of JavaFX canvas.
kshefov
parents:
diff changeset
    61
function checkImageAndExit() {
85671274e5fb 8026871: NASHORN TEST: Enable possibility to test Nashorn use of JavaFX canvas.
kshefov
parents:
diff changeset
    62
    var raceTimer = new Timer(true);
85671274e5fb 8026871: NASHORN TEST: Enable possibility to test Nashorn use of JavaFX canvas.
kshefov
parents:
diff changeset
    63
    var timerTask = new TimerTask() {
85671274e5fb 8026871: NASHORN TEST: Enable possibility to test Nashorn use of JavaFX canvas.
kshefov
parents:
diff changeset
    64
        run: function run() {
85671274e5fb 8026871: NASHORN TEST: Enable possibility to test Nashorn use of JavaFX canvas.
kshefov
parents:
diff changeset
    65
            var tmpdir = System.getProperty("java.io.tmpdir");
85671274e5fb 8026871: NASHORN TEST: Enable possibility to test Nashorn use of JavaFX canvas.
kshefov
parents:
diff changeset
    66
            var timenow = (new Date()).getTime();
21690
ffbb4611d1f4 8027708: NASHORN TEST: Create Nashorn test that draws image step-by-step using JavaFX canvas.
kshefov
parents: 21443
diff changeset
    67
            var scrShotTmp = tmpdir + fsep + "screenshot" + timenow +".png";
ffbb4611d1f4 8027708: NASHORN TEST: Create Nashorn test that draws image step-by-step using JavaFX canvas.
kshefov
parents: 21443
diff changeset
    68
            var goldenImageDir = __DIR__ + "jfx" + fsep + TESTNAME + fsep + "golden";
ffbb4611d1f4 8027708: NASHORN TEST: Create Nashorn test that draws image step-by-step using JavaFX canvas.
kshefov
parents: 21443
diff changeset
    69
            makeScreenShot(scrShotTmp);
ffbb4611d1f4 8027708: NASHORN TEST: Create Nashorn test that draws image step-by-step using JavaFX canvas.
kshefov
parents: 21443
diff changeset
    70
            var dupImg = isDuplicateImages(scrShotTmp, goldenImageDir);
ffbb4611d1f4 8027708: NASHORN TEST: Create Nashorn test that draws image step-by-step using JavaFX canvas.
kshefov
parents: 21443
diff changeset
    71
            (new File(scrShotTmp)).delete();
ffbb4611d1f4 8027708: NASHORN TEST: Create Nashorn test that draws image step-by-step using JavaFX canvas.
kshefov
parents: 21443
diff changeset
    72
            if (!dupImg) System.err.println("ERROR: screenshot does not match the golden image");
21443
85671274e5fb 8026871: NASHORN TEST: Enable possibility to test Nashorn use of JavaFX canvas.
kshefov
parents:
diff changeset
    73
            exit(0);
85671274e5fb 8026871: NASHORN TEST: Enable possibility to test Nashorn use of JavaFX canvas.
kshefov
parents:
diff changeset
    74
        }
85671274e5fb 8026871: NASHORN TEST: Enable possibility to test Nashorn use of JavaFX canvas.
kshefov
parents:
diff changeset
    75
    };
21690
ffbb4611d1f4 8027708: NASHORN TEST: Create Nashorn test that draws image step-by-step using JavaFX canvas.
kshefov
parents: 21443
diff changeset
    76
    raceTimer.schedule(timerTask, 100);
21443
85671274e5fb 8026871: NASHORN TEST: Enable possibility to test Nashorn use of JavaFX canvas.
kshefov
parents:
diff changeset
    77
}
85671274e5fb 8026871: NASHORN TEST: Enable possibility to test Nashorn use of JavaFX canvas.
kshefov
parents:
diff changeset
    78
85671274e5fb 8026871: NASHORN TEST: Enable possibility to test Nashorn use of JavaFX canvas.
kshefov
parents:
diff changeset
    79
function makeScreenShot(shootToImg) {
85671274e5fb 8026871: NASHORN TEST: Enable possibility to test Nashorn use of JavaFX canvas.
kshefov
parents:
diff changeset
    80
   JemmyFxRoot.ROOT.getEnvironment().setImageCapturer(new AWTRobotCapturer());
85671274e5fb 8026871: NASHORN TEST: Enable possibility to test Nashorn use of JavaFX canvas.
kshefov
parents:
diff changeset
    81
   var wrap = JemmyFxRoot.ROOT.lookup(new ByWindowType($STAGE.class)).lookup(Scene.class).wrap(0);
85671274e5fb 8026871: NASHORN TEST: Enable possibility to test Nashorn use of JavaFX canvas.
kshefov
parents:
diff changeset
    82
   var imageJemmy = wrap.getScreenImage();
85671274e5fb 8026871: NASHORN TEST: Enable possibility to test Nashorn use of JavaFX canvas.
kshefov
parents:
diff changeset
    83
   imageJemmy.save(shootToImg);
85671274e5fb 8026871: NASHORN TEST: Enable possibility to test Nashorn use of JavaFX canvas.
kshefov
parents:
diff changeset
    84
}
85671274e5fb 8026871: NASHORN TEST: Enable possibility to test Nashorn use of JavaFX canvas.
kshefov
parents:
diff changeset
    85
21690
ffbb4611d1f4 8027708: NASHORN TEST: Create Nashorn test that draws image step-by-step using JavaFX canvas.
kshefov
parents: 21443
diff changeset
    86
function isDuplicateImages(screenShot, goldenDir) {
ffbb4611d1f4 8027708: NASHORN TEST: Create Nashorn test that draws image step-by-step using JavaFX canvas.
kshefov
parents: 21443
diff changeset
    87
    var f1 = new File(screenShot);
21443
85671274e5fb 8026871: NASHORN TEST: Enable possibility to test Nashorn use of JavaFX canvas.
kshefov
parents:
diff changeset
    88
    var f2;
21690
ffbb4611d1f4 8027708: NASHORN TEST: Create Nashorn test that draws image step-by-step using JavaFX canvas.
kshefov
parents: 21443
diff changeset
    89
    var sb = new StringBuffer(goldenDir);
21443
85671274e5fb 8026871: NASHORN TEST: Enable possibility to test Nashorn use of JavaFX canvas.
kshefov
parents:
diff changeset
    90
    if (OSInfo.getOSType() == OSType.WINDOWS) {
85671274e5fb 8026871: NASHORN TEST: Enable possibility to test Nashorn use of JavaFX canvas.
kshefov
parents:
diff changeset
    91
        f2 = new File(sb.append(fsep + "windows.png").toString());
85671274e5fb 8026871: NASHORN TEST: Enable possibility to test Nashorn use of JavaFX canvas.
kshefov
parents:
diff changeset
    92
    } else if (OSInfo.getOSType() == OSType.LINUX) {
85671274e5fb 8026871: NASHORN TEST: Enable possibility to test Nashorn use of JavaFX canvas.
kshefov
parents:
diff changeset
    93
        f2 = new File(sb.append(fsep + "linux.png").toString());
85671274e5fb 8026871: NASHORN TEST: Enable possibility to test Nashorn use of JavaFX canvas.
kshefov
parents:
diff changeset
    94
    } else if (OSInfo.getOSType() == OSType.MACOSX) {
85671274e5fb 8026871: NASHORN TEST: Enable possibility to test Nashorn use of JavaFX canvas.
kshefov
parents:
diff changeset
    95
        f2 = new File(sb.append(fsep + "macosx.png").toString());
85671274e5fb 8026871: NASHORN TEST: Enable possibility to test Nashorn use of JavaFX canvas.
kshefov
parents:
diff changeset
    96
    }
85671274e5fb 8026871: NASHORN TEST: Enable possibility to test Nashorn use of JavaFX canvas.
kshefov
parents:
diff changeset
    97
    if (f1.exists() && f2.exists()) {
85671274e5fb 8026871: NASHORN TEST: Enable possibility to test Nashorn use of JavaFX canvas.
kshefov
parents:
diff changeset
    98
        var image1 = new AWTImage(PNGDecoder.decode(f1.getAbsolutePath()));
85671274e5fb 8026871: NASHORN TEST: Enable possibility to test Nashorn use of JavaFX canvas.
kshefov
parents:
diff changeset
    99
        var image2 = new AWTImage(PNGDecoder.decode(f2.getAbsolutePath()));
85671274e5fb 8026871: NASHORN TEST: Enable possibility to test Nashorn use of JavaFX canvas.
kshefov
parents:
diff changeset
   100
        return image1.compareTo(image2) == null ? true : false;
85671274e5fb 8026871: NASHORN TEST: Enable possibility to test Nashorn use of JavaFX canvas.
kshefov
parents:
diff changeset
   101
    }
85671274e5fb 8026871: NASHORN TEST: Enable possibility to test Nashorn use of JavaFX canvas.
kshefov
parents:
diff changeset
   102
    return false;
85671274e5fb 8026871: NASHORN TEST: Enable possibility to test Nashorn use of JavaFX canvas.
kshefov
parents:
diff changeset
   103
}