# HG changeset patch # User kshefov # Date 1382347863 -14400 # Node ID f22742d5daa358a645f81c3d8294a77f2a1ec372 # Parent 612886fe324d5d7fc8dc239355256cce5c6a8a70 8026871: NASHORN TEST: Enable possibility to test Nashorn use of JavaFX canvas. Reviewed-by: jlaskey, sundar diff -r 612886fe324d -r f22742d5daa3 make/build.xml --- a/make/build.xml Mon Oct 21 10:09:19 2013 +0530 +++ b/make/build.xml Mon Oct 21 13:31:03 2013 +0400 @@ -46,6 +46,16 @@ + + + + + + + + + + @@ -351,6 +361,31 @@ + + + + + + + + + + + + + + + + + + + + + + + + diff -r 612886fe324d -r f22742d5daa3 make/project.properties --- a/make/project.properties Mon Oct 21 10:09:19 2013 +0530 +++ b/make/project.properties Mon Oct 21 13:31:03 2013 +0400 @@ -118,6 +118,7 @@ test.external.dir=test/script/external test262.dir=${test.external.dir}/test262 test262.suite.dir=${test262.dir}/test/suite +testjfx.dir=${test.script.dir}/jfx test-sys-prop.test.dir=${test.dir} test-sys-prop.test.js.roots=${test.basic.dir} ${test.error.dir} ${test.sandbox.dir} ${test.trusted.dir} @@ -208,6 +209,32 @@ ${test262.dir}/test/harness/framework.js \ ${test262.dir}/test/harness/sta.js +# testjfx test root +testjfx-test-sys-prop.test.js.roots=${testjfx.dir} + +# execute testjfx tests in shared nashorn context or not? +testjfx-test-sys-prop.test.js.shared.context=false + +# framework root for our script tests +testjfx-test-sys-prop.test.js.framework=\ + -fx \ + ${test.script.dir}${file.separator}jfx.js + +file.reference.jemmyfx.jar=test${file.separator}lib${file.separator}JemmyFX.jar +file.reference.jemmycore.jar=test${file.separator}lib${file.separator}JemmyCore.jar +file.reference.jemmyawtinput.jar=test${file.separator}lib${file.separator}JemmyAWTInput.jar +file.reference.jfxrt.jar=${java.home}${file.separator}lib${file.separator}ext${file.separator}jfxrt.jar +testjfx.run.test.classpath=\ + ${file.reference.jemmyfx.jar}${path.separator}\ + ${file.reference.jemmycore.jar}${path.separator}\ + ${file.reference.jemmyawtinput.jar}${path.separator}\ + ${file.reference.testng.jar}${path.separator}\ + ${nashorn.internal.tests.jar}${path.separator}\ + ${nashorn.api.tests.jar} + +# testjfx VM options for script tests with @fork option +testjfx-test-sys-prop.test.fork.jvm.options=${run.test.jvmargs.main} -Xmx${run.test.xmx} -cp ${testjfx.run.test.classpath} + run.test.classpath=\ ${file.reference.testng.jar}:\ ${nashorn.internal.tests.jar}:\ diff -r 612886fe324d -r f22742d5daa3 test/script/jfx.js --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/test/script/jfx.js Mon Oct 21 13:31:03 2013 +0400 @@ -0,0 +1,92 @@ +/* + * Copyright (c) 2013, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +/** + * Base library for JavaFX canvas run by Nashorn testing. + * @subtest + * + * + */ + +var System = Java.type("java.lang.System"); +var AWTImage = Java.type("org.jemmy.image.AWTImage"); +var PNGDecoder = Java.type("org.jemmy.image.PNGDecoder"); +var JemmyFxRoot = Java.type("org.jemmy.fx.Root"); +var AWTRobotCapturer = Java.type("org.jemmy.image.AWTRobotCapturer"); +var ByWindowType = Java.type("org.jemmy.fx.ByWindowType"); +var Scene = Java.type("javafx.scene.Scene"); +var Stage = Java.type("javafx.stage.Stage"); +var File = Java.type("java.io.File"); +var Timer = Java.type("java.util.Timer"); +var TimerTask = Java.type("java.util.TimerTask"); +var OSInfo = Java.type("sun.awt.OSInfo"); +var OSType = Java.type("sun.awt.OSInfo.OSType"); +var StringBuffer = Java.type("java.lang.StringBuffer"); + +var WAIT = 2000; +var TESTNAME = "test"; +var fsep = System.getProperty("file.separator"); + +function checkImageAndExit() { + var raceTimer = new Timer(true); + var timerTask = new TimerTask() { + run: function run() { + var tmpdir = System.getProperty("java.io.tmpdir"); + var timenow = (new Date()).getTime(); + makeScreenShot(tmpdir + fsep + "screenshot" + timenow +".png"); + var dupImg = isDuplicateImages(tmpdir + fsep + "screenshot" + timenow +".png", __DIR__ + "jfx" + fsep + TESTNAME + fsep + "golden"); + (new File(mpdir + fsep + "screenshot" + timenow +".png")).delete(); + if (!dupImg) System.err.println("ERROR: screenshot does not match golden image"); + exit(0); + } + }; + raceTimer.schedule(timerTask, WAIT); +} + +function makeScreenShot(shootToImg) { + JemmyFxRoot.ROOT.getEnvironment().setImageCapturer(new AWTRobotCapturer()); + var wrap = JemmyFxRoot.ROOT.lookup(new ByWindowType($STAGE.class)).lookup(Scene.class).wrap(0); + var imageJemmy = wrap.getScreenImage(); + imageJemmy.save(shootToImg); +} + +function isDuplicateImages(file1, file2) { + var f1 = new File(file1); + var f2; + var sb = new StringBuffer(file2); + if (OSInfo.getOSType() == OSType.WINDOWS) { + f2 = new File(sb.append(fsep + "windows.png").toString()); + } else if (OSInfo.getOSType() == OSType.LINUX) { + f2 = new File(sb.append(fsep + "linux.png").toString()); + } else if (OSInfo.getOSType() == OSType.MACOSX) { + f2 = new File(sb.append(fsep + "macosx.png").toString()); + } + print(f1.getAbsolutePath()); + print(f2.getAbsolutePath()); + if (f1.exists() && f2.exists()) { + var image1 = new AWTImage(PNGDecoder.decode(f1.getAbsolutePath())); + var image2 = new AWTImage(PNGDecoder.decode(f2.getAbsolutePath())); + return image1.compareTo(image2) == null ? true : false; + } + return false; +} diff -r 612886fe324d -r f22742d5daa3 test/script/jfx/flyingimage.js --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/test/script/jfx/flyingimage.js Mon Oct 21 13:31:03 2013 +0400 @@ -0,0 +1,83 @@ +/* + * Copyright (c) 2013, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +/** + * Testing JavaFX canvas run by Nashorn. + * + * @test/nocompare + * @run + * @fork + */ + +TESTNAME = "flyingimage"; + +var Image = Java.type("javafx.scene.image.Image"); +var Color = Java.type("javafx.scene.paint.Color"); +var Canvas = Java.type("javafx.scene.canvas.Canvas"); +var BorderPane = Java.type("javafx.scene.layout.BorderPane"); +var StackPane = Java.type("javafx.scene.layout.StackPane"); +var Font = Java.type("javafx.scene.text.Font"); +var FontSmoothingType = Java.type("javafx.scene.text.FontSmoothingType"); +var Text = Java.type("javafx.scene.text.Text"); + +var WIDTH = 800; +var HEIGHT = 600; +var canvas = new Canvas(WIDTH, HEIGHT); +function fileToURL(file) { + return new File(file).toURI().toURL().toExternalForm(); +} +var imageUrl = fileToURL(__DIR__ + "flyingimage/flyingimage.png"); +var img = new Image(imageUrl); +var font = new Font("Arial", 16); +var t = 0; +var isFrameRendered = false; +function renderFrame() { + var gc = canvas.graphicsContext2D; + gc.setFill(Color.web("#cccccc")); + gc.fillRect(0, 0, WIDTH, HEIGHT); + gc.setStroke(Color.web("#000000")); + gc.setLineWidth(1); + gc.strokeRect(5, 5, WIDTH - 10, HEIGHT - 10); + var c = 200; + var msc= 0.5 * HEIGHT / img.height; + var sp0 = 0.003; + for (var h = 0; h < c; h++, t++) { + gc.setTransform(1, 0, 0, 1, 0, 0); + var yh = h / (c - 1); + gc.translate((0.5 + Math.sin(t * sp0 + h * 0.1) / 3) * WIDTH, 25 + (HEIGHT * 3 / 4 - 40) * (yh * yh)); + var sc = 30 / img.height + msc * yh * yh; + gc.rotate(90 * Math.sin(t * sp0 + h * 0.1 + Math.PI)); + gc.scale(sc, sc); + gc.drawImage(img, -img.width / 2, -img.height / 2); + } + gc.setTransform(1, 0, 0, 1, 0, 0); + isFrameRendered = true; +} +var stack = new StackPane(); +var pane = new BorderPane(); + +pane.setCenter(canvas); +stack.getChildren().add(pane); +$STAGE.scene = new Scene(stack); +renderFrame(); +checkImageAndExit(); diff -r 612886fe324d -r f22742d5daa3 test/script/jfx/flyingimage/flyingimage.png Binary file test/script/jfx/flyingimage/flyingimage.png has changed diff -r 612886fe324d -r f22742d5daa3 test/script/jfx/flyingimage/golden/linux.png Binary file test/script/jfx/flyingimage/golden/linux.png has changed diff -r 612886fe324d -r f22742d5daa3 test/script/jfx/flyingimage/golden/macosx.png Binary file test/script/jfx/flyingimage/golden/macosx.png has changed diff -r 612886fe324d -r f22742d5daa3 test/script/jfx/flyingimage/golden/windows.png Binary file test/script/jfx/flyingimage/golden/windows.png has changed diff -r 612886fe324d -r f22742d5daa3 test/script/jfx/kaleidoscope.js --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/test/script/jfx/kaleidoscope.js Mon Oct 21 13:31:03 2013 +0400 @@ -0,0 +1,162 @@ +/* + * Copyright (c) 2013, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +/** + * Testing JavaFX canvas run by Nashorn. + * + * @test/nocompare + * @run + * @fork + */ + +TESTNAME = "kaleidoscope"; +WAIT = 4000; + +var Paint = Java.type("javafx.scene.paint.Paint"); +var Canvas = Java.type("javafx.scene.canvas.Canvas"); +var BorderPane = Java.type("javafx.scene.layout.BorderPane"); +var StackPane = Java.type("javafx.scene.layout.StackPane"); +var StrokeLineCap = Java.type("javafx.scene.shape.StrokeLineCap"); + +var WIDTH = 800; +var HEIGHT = 600; +var canvas = new Canvas(WIDTH, HEIGHT); +var context = canvas.graphicsContext2D; + +var x,y; +var p_x,p_y; +var a=0; +var b=0; +var angle=Math.PI/180*8; +var color=0; +var limit1=Math.PI*1.5; +var limit2=Math.PI*1.79; +var c=new Array(6); +var d=new Array(6); +var r,e; +var fade; +var prv_x,prv_y,prv_x2,prv_y2; + +function renderFrame() { + a=0.2*angle; + b=0.7*angle; + r=0; + fade=32; + for(var i=0;i<6;i++) + { + c[i]=1.0/(i+1)/2; + d[i]=1.0/(i+1)/2; + } + radius=Math.round((WIDTH+HEIGHT)/8); + e=radius*0.2; + p_x=Math.round(WIDTH/2); + p_y=Math.round(HEIGHT/2); + x=(radius*c[0])*Math.cos(a*d[1])+(radius*c[2])*Math.sin(a*d[3])+(radius*c[4])*Math.sin(a*d[5]); + y=(radius*c[5])*Math.sin(a*d[4])+(radius*c[3])*Math.cos(a*d[2])+(radius*c[1])*Math.cos(a*d[0]); + for (i = 0; i < 800; i++) { + anim(); + } +} + +function anim() { + var a1=Math.cos(a*2); + var a2=Math.cos(a*4); + var a3=Math.cos(a); + var a4=Math.sin(a); + if(b>limit1&&b