nashorn/test/script/jfx.js
author kshefov
Mon, 21 Oct 2013 13:31:03 +0400
changeset 21443 85671274e5fb
child 21690 ffbb4611d1f4
permissions -rw-r--r--
8026871: NASHORN TEST: Enable possibility to test Nashorn use of JavaFX canvas. Reviewed-by: jlaskey, sundar
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 Timer                = Java.type("java.util.Timer");
85671274e5fb 8026871: NASHORN TEST: Enable possibility to test Nashorn use of JavaFX canvas.
kshefov
parents:
diff changeset
    41
var TimerTask            = Java.type("java.util.TimerTask");
85671274e5fb 8026871: NASHORN TEST: Enable possibility to test Nashorn use of JavaFX canvas.
kshefov
parents:
diff changeset
    42
var OSInfo               = Java.type("sun.awt.OSInfo");
85671274e5fb 8026871: NASHORN TEST: Enable possibility to test Nashorn use of JavaFX canvas.
kshefov
parents:
diff changeset
    43
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
    44
var StringBuffer         = Java.type("java.lang.StringBuffer");
85671274e5fb 8026871: NASHORN TEST: Enable possibility to test Nashorn use of JavaFX canvas.
kshefov
parents:
diff changeset
    45
85671274e5fb 8026871: NASHORN TEST: Enable possibility to test Nashorn use of JavaFX canvas.
kshefov
parents:
diff changeset
    46
var WAIT = 2000;
85671274e5fb 8026871: NASHORN TEST: Enable possibility to test Nashorn use of JavaFX canvas.
kshefov
parents:
diff changeset
    47
var TESTNAME = "test";
85671274e5fb 8026871: NASHORN TEST: Enable possibility to test Nashorn use of JavaFX canvas.
kshefov
parents:
diff changeset
    48
var fsep = System.getProperty("file.separator");
85671274e5fb 8026871: NASHORN TEST: Enable possibility to test Nashorn use of JavaFX canvas.
kshefov
parents:
diff changeset
    49
85671274e5fb 8026871: NASHORN TEST: Enable possibility to test Nashorn use of JavaFX canvas.
kshefov
parents:
diff changeset
    50
function checkImageAndExit() {
85671274e5fb 8026871: NASHORN TEST: Enable possibility to test Nashorn use of JavaFX canvas.
kshefov
parents:
diff changeset
    51
    var raceTimer = new Timer(true);
85671274e5fb 8026871: NASHORN TEST: Enable possibility to test Nashorn use of JavaFX canvas.
kshefov
parents:
diff changeset
    52
    var timerTask = new TimerTask() {
85671274e5fb 8026871: NASHORN TEST: Enable possibility to test Nashorn use of JavaFX canvas.
kshefov
parents:
diff changeset
    53
        run: function run() {
85671274e5fb 8026871: NASHORN TEST: Enable possibility to test Nashorn use of JavaFX canvas.
kshefov
parents:
diff changeset
    54
            var tmpdir = System.getProperty("java.io.tmpdir");
85671274e5fb 8026871: NASHORN TEST: Enable possibility to test Nashorn use of JavaFX canvas.
kshefov
parents:
diff changeset
    55
            var timenow = (new Date()).getTime();
85671274e5fb 8026871: NASHORN TEST: Enable possibility to test Nashorn use of JavaFX canvas.
kshefov
parents:
diff changeset
    56
            makeScreenShot(tmpdir + fsep + "screenshot" + timenow +".png");
85671274e5fb 8026871: NASHORN TEST: Enable possibility to test Nashorn use of JavaFX canvas.
kshefov
parents:
diff changeset
    57
            var dupImg = isDuplicateImages(tmpdir + fsep + "screenshot" + timenow +".png", __DIR__ + "jfx" + fsep + TESTNAME + fsep + "golden");
85671274e5fb 8026871: NASHORN TEST: Enable possibility to test Nashorn use of JavaFX canvas.
kshefov
parents:
diff changeset
    58
            (new File(mpdir + fsep + "screenshot" + timenow +".png")).delete();
85671274e5fb 8026871: NASHORN TEST: Enable possibility to test Nashorn use of JavaFX canvas.
kshefov
parents:
diff changeset
    59
            if (!dupImg) System.err.println("ERROR: screenshot does not match golden image");
85671274e5fb 8026871: NASHORN TEST: Enable possibility to test Nashorn use of JavaFX canvas.
kshefov
parents:
diff changeset
    60
            exit(0);
85671274e5fb 8026871: NASHORN TEST: Enable possibility to test Nashorn use of JavaFX canvas.
kshefov
parents:
diff changeset
    61
        }
85671274e5fb 8026871: NASHORN TEST: Enable possibility to test Nashorn use of JavaFX canvas.
kshefov
parents:
diff changeset
    62
    };
85671274e5fb 8026871: NASHORN TEST: Enable possibility to test Nashorn use of JavaFX canvas.
kshefov
parents:
diff changeset
    63
    raceTimer.schedule(timerTask, WAIT);
85671274e5fb 8026871: NASHORN TEST: Enable possibility to test Nashorn use of JavaFX canvas.
kshefov
parents:
diff changeset
    64
}
85671274e5fb 8026871: NASHORN TEST: Enable possibility to test Nashorn use of JavaFX canvas.
kshefov
parents:
diff changeset
    65
85671274e5fb 8026871: NASHORN TEST: Enable possibility to test Nashorn use of JavaFX canvas.
kshefov
parents:
diff changeset
    66
function makeScreenShot(shootToImg) {
85671274e5fb 8026871: NASHORN TEST: Enable possibility to test Nashorn use of JavaFX canvas.
kshefov
parents:
diff changeset
    67
   JemmyFxRoot.ROOT.getEnvironment().setImageCapturer(new AWTRobotCapturer());
85671274e5fb 8026871: NASHORN TEST: Enable possibility to test Nashorn use of JavaFX canvas.
kshefov
parents:
diff changeset
    68
   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
    69
   var imageJemmy = wrap.getScreenImage();
85671274e5fb 8026871: NASHORN TEST: Enable possibility to test Nashorn use of JavaFX canvas.
kshefov
parents:
diff changeset
    70
   imageJemmy.save(shootToImg);
85671274e5fb 8026871: NASHORN TEST: Enable possibility to test Nashorn use of JavaFX canvas.
kshefov
parents:
diff changeset
    71
}
85671274e5fb 8026871: NASHORN TEST: Enable possibility to test Nashorn use of JavaFX canvas.
kshefov
parents:
diff changeset
    72
85671274e5fb 8026871: NASHORN TEST: Enable possibility to test Nashorn use of JavaFX canvas.
kshefov
parents:
diff changeset
    73
function isDuplicateImages(file1, file2) {
85671274e5fb 8026871: NASHORN TEST: Enable possibility to test Nashorn use of JavaFX canvas.
kshefov
parents:
diff changeset
    74
    var f1 = new File(file1);
85671274e5fb 8026871: NASHORN TEST: Enable possibility to test Nashorn use of JavaFX canvas.
kshefov
parents:
diff changeset
    75
    var f2;
85671274e5fb 8026871: NASHORN TEST: Enable possibility to test Nashorn use of JavaFX canvas.
kshefov
parents:
diff changeset
    76
    var sb = new StringBuffer(file2);
85671274e5fb 8026871: NASHORN TEST: Enable possibility to test Nashorn use of JavaFX canvas.
kshefov
parents:
diff changeset
    77
    if (OSInfo.getOSType() == OSType.WINDOWS) {
85671274e5fb 8026871: NASHORN TEST: Enable possibility to test Nashorn use of JavaFX canvas.
kshefov
parents:
diff changeset
    78
        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
    79
    } else if (OSInfo.getOSType() == OSType.LINUX) {
85671274e5fb 8026871: NASHORN TEST: Enable possibility to test Nashorn use of JavaFX canvas.
kshefov
parents:
diff changeset
    80
        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
    81
    } else if (OSInfo.getOSType() == OSType.MACOSX) {
85671274e5fb 8026871: NASHORN TEST: Enable possibility to test Nashorn use of JavaFX canvas.
kshefov
parents:
diff changeset
    82
        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
    83
    }
85671274e5fb 8026871: NASHORN TEST: Enable possibility to test Nashorn use of JavaFX canvas.
kshefov
parents:
diff changeset
    84
    print(f1.getAbsolutePath());
85671274e5fb 8026871: NASHORN TEST: Enable possibility to test Nashorn use of JavaFX canvas.
kshefov
parents:
diff changeset
    85
    print(f2.getAbsolutePath());
85671274e5fb 8026871: NASHORN TEST: Enable possibility to test Nashorn use of JavaFX canvas.
kshefov
parents:
diff changeset
    86
    if (f1.exists() && f2.exists()) {
85671274e5fb 8026871: NASHORN TEST: Enable possibility to test Nashorn use of JavaFX canvas.
kshefov
parents:
diff changeset
    87
        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
    88
        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
    89
        return image1.compareTo(image2) == null ? true : false;
85671274e5fb 8026871: NASHORN TEST: Enable possibility to test Nashorn use of JavaFX canvas.
kshefov
parents:
diff changeset
    90
    }
85671274e5fb 8026871: NASHORN TEST: Enable possibility to test Nashorn use of JavaFX canvas.
kshefov
parents:
diff changeset
    91
    return false;
85671274e5fb 8026871: NASHORN TEST: Enable possibility to test Nashorn use of JavaFX canvas.
kshefov
parents:
diff changeset
    92
}