changeset 666:37741b256ff4

adding JSToJFuncReturn reproducer (testing Liveconnect JS->J function return types)
author Jana Fabrikova <jfabriko@redhat.com>
date Wed, 10 Apr 2013 14:07:14 +0200
parents 89d62a76c9f9
children 29db8f77bae4
files ChangeLog tests/reproducers/simple/JSToJFuncReturn/resources/JSToJFuncReturn.html tests/reproducers/simple/JSToJFuncReturn/resources/JSToJava_FuncReturn.js tests/reproducers/simple/JSToJFuncReturn/resources/jstoj-funcreturn.jnlp tests/reproducers/simple/JSToJFuncReturn/srcs/JSToJFuncReturn.java tests/reproducers/simple/JSToJFuncReturn/testcases/JSToJFuncReturnTest.java
diffstat 6 files changed, 464 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- a/ChangeLog	Mon Apr 08 15:08:11 2013 +0200
+++ b/ChangeLog	Wed Apr 10 14:07:14 2013 +0200
@@ -1,3 +1,17 @@
+2013-04-10  Jana Fabrikova  <jfabriko@redhat.com>
+
+	* /tests/reproducers/simple/JToJSFuncReturn/testcases/JToJSFuncReturnTest.java:
+	adding 5 testcases based on the interactive Liveconnect JS->Java
+	function return type tests
+	* /tests/reproducers/simple/JToJSFuncReturn/srcs/JToJSFuncReturn.java:
+	the applet that calls JS functions
+	* tests/reproducers/simple/JToJSFuncReturn/resources/JToJS_FuncReturn.js:
+	auxiliary JavaScript code
+	* /tests/reproducers/simple/JToJSFuncReturn/resources/jtojs-funcreturn.jnlp:
+	jnlp file for displaying applet in the html page
+	* /tests/reproducers/simple/JToJSFuncReturn/resources/JToJSFuncReturn.html:
+	the html page where the applet calling JS functions is embedded
+
 2013-04-08  Jiri Vanek <jvanek@redhat.com>
 
 	* tests/test-extensions/net/sourceforge/jnlp/browsertesting/browsers/Epiphany.java:
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/tests/reproducers/simple/JSToJFuncReturn/resources/JSToJFuncReturn.html	Wed Apr 10 14:07:14 2013 +0200
@@ -0,0 +1,26 @@
+<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
+<html lang="en-US">
+  <head>
+    <title>JavaScript to Java LiveConnect - Function return values from applet</title>
+    <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
+
+    <script language="JavaScript" src="JSToJava_FuncReturn.js"></script>
+
+  </head>
+  <body>
+
+    <h2> The JSToJFuncReturn html page</h2> 
+
+
+    <applet code="JSToJFuncReturn" width="1000" height="100" id="jstojFuncReturnApplet" MAYSCRIPT>
+      <param name="jnlp_href" value="jstoj-funcreturn.jnlp">
+    </applet>
+
+    <div id="messageDiv"></div>
+
+    <script laguage="javascript">
+        doFuncReturnTests();
+    </script> 
+
+  </body>
+</html>
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/tests/reproducers/simple/JSToJFuncReturn/resources/JSToJava_FuncReturn.js	Wed Apr 10 14:07:14 2013 +0200
@@ -0,0 +1,17 @@
+function doFuncReturnTests(){
+    var urlArgs = document.URL.split("?");
+    var applet = document.getElementById('jstojFuncReturnApplet');
+    var method = urlArgs[1];
+
+    eval('var value = applet.' + method + '()');
+
+    var checked_string = typeof(value)+' ';
+    if( method === '_JSObject'){
+        checked_string = checked_string +value.key1;
+    }else{
+        checked_string = checked_string +value;
+    }
+
+    applet.printStringAndFinish(checked_string);
+}
+
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/tests/reproducers/simple/JSToJFuncReturn/resources/jstoj-funcreturn.jnlp	Wed Apr 10 14:07:14 2013 +0200
@@ -0,0 +1,23 @@
+
+<?xml version="1.0" encoding="UTF-8"?>
+<jnlp spec="1.0+" codebase="" href="jstoj-funcreturn.jnlp">
+    <information>
+        <title>JavaScript to Java LiveConnect - FuncReturn</title>
+        <vendor>RedHat</vendor>
+        <homepage href="http://icedtea.classpath.org/wiki/IcedTea-Web#Testing_IcedTea-Web"/>
+        <description>LiveConnect - tests to process various return types from Java side function calls.</description>
+    </information>
+    <resources>
+        <!-- Application Resources -->
+        <j2se version="1.6+"
+              href="http://java.sun.com/products/autodl/j2se"/>
+        <jar href="JSToJFuncReturn.jar" main="true" />
+
+    </resources>
+    <applet-desc 
+         name="JS to J FuncReturn"
+         main-class="JSToJFuncReturn"
+         width="1000"
+         height="100">
+     </applet-desc>
+</jnlp>
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/tests/reproducers/simple/JSToJFuncReturn/srcs/JSToJFuncReturn.java	Wed Apr 10 14:07:14 2013 +0200
@@ -0,0 +1,142 @@
+import java.applet.Applet;
+import java.awt.Label;
+import java.awt.BorderLayout;
+import netscape.javascript.JSObject;
+
+public class JSToJFuncReturn extends Applet {
+
+    private Label statusLabel;
+
+    public int _int() {
+        int i = 1;
+        return i;
+    }
+
+    public double _double() {
+        double d = 1.1;
+        return d;
+    }
+
+    public float _float() {
+        float f = 1.1F;
+        return f;
+    }
+    
+    public long _long() {
+        long l = 10000L;
+        return l;
+    }
+    
+    public boolean _boolean() {
+        boolean b = true;
+        return b;
+    }
+
+    public char _char() {
+        char c = 'a';
+        return c;
+    }
+
+    public byte _byte() {
+        byte by = 10; 
+        return by;
+    }
+
+    public char _charArrayElement(){
+        char[] ca = new char[]{'a', 'b', 'c'};
+
+        return ca[0];
+    }
+
+    public char[] _charArray() {
+        char[] ca = new char[]{'a', 'b', 'c'};
+
+        return ca;
+    }
+
+    public String _regularString() {
+        String rs = "test";
+        return rs;
+    }
+
+    public String _specialString() {
+        String ss = "𠁎〒£$ǣ€𝍖";
+        return ss;
+    }
+
+    public void _void() {
+    }
+
+    public Object _null() {
+        return null;
+    }
+
+    public Integer _Integer() {
+        Integer I = 1;
+        return I;
+    }
+
+    public Double _Double() {
+        Double D = 1.1;
+        return D;
+    }
+
+    public Float _Float() {
+        Float F = 1.1F;
+        return F;
+    }
+
+    public Long _Long() {
+        Long L = 10000L;
+        return L;
+    }
+
+    public Boolean _Boolean() {
+        Boolean B = true;
+        return B;
+    }
+
+    public Character _CharacterArrayElement(){
+        Character[] Ca = new Character[]{'A', 'B', 'C'};
+
+        return Ca[0];
+    }
+
+    public Character _Character() {
+        Character C = 'A';
+        return C;
+    }
+
+    public Byte _Byte() {
+        Byte By = 10;
+        return By;
+    }
+
+    public Character[] _CharacterArray() {
+        Character[] Ca = new Character[]{'A', 'B', 'C'};
+
+        return Ca;
+    }
+
+    public JSObject _JSObject(){
+        JSObject win = JSObject.getWindow(this);
+        JSObject jso = (JSObject) win.getMember("document");
+        jso.setMember("key1","value1");
+  
+        return jso;
+    }
+
+    public void init() {
+        setLayout(new BorderLayout());
+        statusLabel = new Label();
+        add(statusLabel);
+        String initStr = "JSToJFuncReturn applet initialized.";
+        System.out.println(initStr);
+        statusLabel.setText(initStr);
+    }
+
+    public void printStringAndFinish(String str){
+        System.out.println(str);
+        System.out.println("afterTests");
+    }
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/tests/reproducers/simple/JSToJFuncReturn/testcases/JSToJFuncReturnTest.java	Wed Apr 10 14:07:14 2013 +0200
@@ -0,0 +1,242 @@
+/* JSToJFuncReturnTest.java
+Copyright (C) 2012 Red Hat, Inc.
+
+This file is part of IcedTea.
+
+IcedTea is free software; you can redistribute it and/or
+modify it under the terms of the GNU General Public License as published by
+the Free Software Foundation, version 2.
+
+IcedTea 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 for more details.
+
+You should have received a copy of the GNU General Public License
+along with IcedTea; see the file COPYING.  If not, write to
+the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+02110-1301 USA.
+
+Linking this library statically or dynamically with other modules is
+making a combined work based on this library.  Thus, the terms and
+conditions of the GNU General Public License cover the whole
+combination.
+
+As a special exception, the copyright holders of this library give you
+permission to link this library with independent modules to produce an
+executable, regardless of the license terms of these independent
+modules, and to copy and distribute the resulting executable under
+terms of your choice, provided that you also meet, for each linked
+independent module, the terms and conditions of the license of that
+module.  An independent module is a module which is not derived from
+or based on this library.  If you modify this library, you may extend
+this exception to your version of the library, but you are not
+obligated to do so.  If you do not wish to do so, delete this
+exception statement from your version.
+ */
+
+import net.sourceforge.jnlp.ProcessResult;
+import net.sourceforge.jnlp.ServerAccess;
+import net.sourceforge.jnlp.browsertesting.BrowserTest;
+import net.sourceforge.jnlp.browsertesting.Browsers;
+import net.sourceforge.jnlp.closinglisteners.CountingClosingListener;
+import net.sourceforge.jnlp.annotations.KnownToFail;
+import net.sourceforge.jnlp.annotations.NeedsDisplay;
+import net.sourceforge.jnlp.annotations.TestInBrowsers;
+import org.junit.Assert;
+
+import org.junit.Test;
+
+public class JSToJFuncReturnTest extends BrowserTest {
+
+    private final String initStr = "JSToJFuncReturn applet initialized.";
+    private final String afterStr = "afterTests";
+
+    private class CountingClosingListenerImpl extends CountingClosingListener {
+
+        @Override
+        protected boolean isAlowedToFinish(String s) {
+            
+            return (s.contains(initStr) && s.contains(afterStr));
+        }
+    }
+
+    private void evaluateStdoutContents(String expectedStdout, ProcessResult pr) {
+        // Assert that the applet was initialized.
+        Assert.assertTrue("JSToJFuncReturnTest stdout should contain "+ initStr + " but it didnt.", pr.stdout.contains(initStr));
+
+        // Assert that the tests have passed.
+        Assert.assertTrue("JSToJFuncReturnTest stdout should contain "+ expectedStdout + " but it didnt.", pr.stdout.contains(expectedStdout));
+    }
+
+
+    private void jsToJavaFuncReturnNormalTest(String methodStr, String expectedStdout) throws Exception {
+        String strURL = "/JSToJFuncReturn.html?" + methodStr;
+        ProcessResult pr = server.executeBrowser(strURL, new CountingClosingListenerImpl(), new CountingClosingListenerImpl());
+        evaluateStdoutContents(expectedStdout, pr);
+    }
+
+    @Test
+    @TestInBrowsers(testIn = { Browsers.all })
+    @NeedsDisplay
+    public void AppletJSToJFuncReturn_int_Test() throws Exception {
+        jsToJavaFuncReturnNormalTest("_int", "number 1");
+    }
+
+    @Test
+    @TestInBrowsers(testIn = { Browsers.all })
+    @NeedsDisplay
+    public void AppletJSToJFuncReturn_double_Test() throws Exception {
+        jsToJavaFuncReturnNormalTest("_double", "number 1.1");
+    }
+
+    @Test
+    @TestInBrowsers(testIn = { Browsers.all })
+    @NeedsDisplay
+    public void AppletJSToJFuncReturn_float_Test() throws Exception {
+        jsToJavaFuncReturnNormalTest("_float", "number 1.1");
+    }
+
+    @Test
+    @TestInBrowsers(testIn = { Browsers.all })
+    @NeedsDisplay
+    public void AppletJSToJFuncReturn_long_Test() throws Exception {
+        jsToJavaFuncReturnNormalTest("_long", "number 10000");
+    }
+
+    @Test
+    @TestInBrowsers(testIn = { Browsers.all })
+    @NeedsDisplay
+    public void AppletJSToJFuncReturn_boolean_Test() throws Exception {
+        jsToJavaFuncReturnNormalTest("_boolean", "boolean true");
+    }
+
+    @Test
+    @TestInBrowsers(testIn = { Browsers.all })
+    @NeedsDisplay
+    public void AppletJSToJFuncReturn_char_Test() throws Exception {
+        jsToJavaFuncReturnNormalTest("_char", "number 97"); //'a'
+    }
+
+    @Test
+    @TestInBrowsers(testIn = { Browsers.all })
+    @NeedsDisplay
+    public void AppletJSToJFuncReturn_byte_Test() throws Exception {
+        jsToJavaFuncReturnNormalTest("_byte", "number 10");
+    }
+
+    @Test
+    @TestInBrowsers(testIn = { Browsers.all })
+    @NeedsDisplay
+    public void AppletJSToJFuncReturn_charArrayElement_Test() throws Exception {
+        jsToJavaFuncReturnNormalTest("_charArrayElement", "number 97");
+    }
+
+    @Test
+    @TestInBrowsers(testIn = { Browsers.all })
+    @NeedsDisplay
+    public void AppletJSToJFuncReturn_void_Test() throws Exception {
+        jsToJavaFuncReturnNormalTest("_void", "undefined undefined");
+    }
+
+    @Test
+    @TestInBrowsers(testIn = { Browsers.all })
+    @NeedsDisplay
+    public void AppletJSToJFuncReturn_regularString_Test() throws Exception {
+        jsToJavaFuncReturnNormalTest("_regularString", "string test");
+    }
+
+    @Test
+    @TestInBrowsers(testIn = { Browsers.all })
+    @NeedsDisplay
+    public void AppletJSToJFuncReturn_specialCharsString_Test() throws Exception {
+        jsToJavaFuncReturnNormalTest("_specialString", "string 𠁎〒£$ǣ€𝍖");
+    }
+
+    @Test
+    @TestInBrowsers(testIn = { Browsers.all })
+    @NeedsDisplay
+    public void AppletJSToJFuncReturn_null_Test() throws Exception {
+        jsToJavaFuncReturnNormalTest("_null", "object null");
+    }
+
+    @Test
+    @TestInBrowsers(testIn = { Browsers.all })
+    @NeedsDisplay
+    @KnownToFail
+    public void AppletJSToJFuncReturn_Integer_Test() throws Exception {
+        jsToJavaFuncReturnNormalTest("_Integer", "object 1");
+    }
+
+    @Test
+    @TestInBrowsers(testIn = { Browsers.all })
+    @NeedsDisplay
+    @KnownToFail
+    public void AppletJSToJFuncReturn_Double_Test() throws Exception {
+        jsToJavaFuncReturnNormalTest("_Double", "object 1.1");
+    }
+
+    @Test
+    @TestInBrowsers(testIn = { Browsers.all })
+    @NeedsDisplay
+    @KnownToFail
+    public void AppletJSToJFuncReturn_Float_Test() throws Exception {
+        jsToJavaFuncReturnNormalTest("_Float", "object 1.1");
+    }
+
+    @Test
+    @TestInBrowsers(testIn = { Browsers.all })
+    @NeedsDisplay
+    @KnownToFail
+    public void AppletJSToJFuncReturn_Long_Test() throws Exception {
+        jsToJavaFuncReturnNormalTest("_Long", "object 10000");
+    }
+
+    @Test
+    @TestInBrowsers(testIn = { Browsers.all })
+    @NeedsDisplay
+    @KnownToFail
+    public void AppletJSToJFuncReturn_Boolean_Test() throws Exception {
+        jsToJavaFuncReturnNormalTest("_Boolean", "object true");
+    }
+
+    @Test
+    @TestInBrowsers(testIn = { Browsers.all })
+    @NeedsDisplay
+    @KnownToFail
+    public void AppletJSToJFuncReturn_Character_Test() throws Exception {
+        jsToJavaFuncReturnNormalTest("_Character", "object A");
+    }
+
+    @Test
+    @TestInBrowsers(testIn = { Browsers.all })
+    @NeedsDisplay
+    @KnownToFail
+    public void AppletJSToJFuncReturn_Byte_Test() throws Exception {
+        jsToJavaFuncReturnNormalTest("_Byte", "object 10");
+    }
+
+    @Test
+    @TestInBrowsers(testIn = { Browsers.all })
+    @NeedsDisplay
+    @KnownToFail
+    public void AppletJSToJFuncReturn_CharArrayElement_Test() throws Exception {
+        jsToJavaFuncReturnNormalTest("_CharacterArrayElement", "object A");
+    }
+
+    @Test
+    @TestInBrowsers(testIn = { Browsers.all })
+    @NeedsDisplay
+    public void AppletJSToJFuncReturn_CharFullArray_Test() throws Exception {
+        jsToJavaFuncReturnNormalTest("_CharacterArray", "object [Ljava.lang.Character;@");
+    }
+
+    @Test
+    @TestInBrowsers(testIn = { Browsers.all })
+    @NeedsDisplay
+    public void AppletJSToJFuncReturn_JSObject_Test() throws Exception {
+        jsToJavaFuncReturnNormalTest("_JSObject", "object value1");
+    }
+
+
+}