/hg/icedtea-web: Added reproducer for PR1794

aazores at icedtea.classpath.org aazores at icedtea.classpath.org
Fri May 30 20:08:04 UTC 2014


changeset ef96a1c8776b in /hg/icedtea-web
details: http://icedtea.classpath.org/hg/icedtea-web?cmd=changeset;node=ef96a1c8776b
author: Andrew Azores <aazores at redhat.com>
date: Fri May 30 16:07:45 2014 -0400

	Added reproducer for PR1794

	Added reproducer for PR1794: Bug where Java variables are not accessed
	correctly through Javascript. Attempt to access a string array results
	in undefined result. However, attempt to access a string results in
	receiving correct value of string. Tests html applet and jnlp-href
	applet
	* tests/reproducers/simple/JToJSString/testcases/JToJSStringTest.java:
	New reproducer for PR1794
	* tests/reproducers/simple/JToJSString/resources/JToJSString.html:
	same
	* tests/reproducers/simple/JToJSString/resources/JToJSJnlpApplet.html:
	same
	* tests/reproducers/simple/JToJSString/resources/JToJSString.js:
	same
	* tests/reproducers/simple/JToJSString/resources/JToJSApplet.jnlp:
	same
	* tests/reproducers/simple/JToJSString/srcs/JToJSString.java:
	same


diffstat:

 ChangeLog                                                                 |   20 +
 tests/reproducers/simple/JToJSString/resources/JToJSString.html           |   59 +++++
 tests/reproducers/simple/JToJSString/resources/JToJSString.js             |   49 ++++
 tests/reproducers/simple/JToJSString/resources/JToJSStringApplet.jnlp     |   53 ++++
 tests/reproducers/simple/JToJSString/resources/JToJSStringJnlpApplet.html |   60 +++++
 tests/reproducers/simple/JToJSString/srcs/JToJSString.java                |   98 ++++++++
 tests/reproducers/simple/JToJSString/testcases/JToJSStringTest.java       |  112 ++++++++++
 7 files changed, 451 insertions(+), 0 deletions(-)

diffs (486 lines):

diff -r e5a7d39eecbb -r ef96a1c8776b ChangeLog
--- a/ChangeLog	Fri May 23 15:02:48 2014 +0200
+++ b/ChangeLog	Fri May 30 16:07:45 2014 -0400
@@ -1,3 +1,23 @@
+2014-05-29  Jie Kang  <jkang at redhat.com>
+
+	Added reproducer for PR1794: Bug where Java variables are not accessed
+	correctly through Javascript. Attempt to access a string array results
+	in undefined result. However, attempt to access a string results in
+	receiving correct value of string. Tests html applet and jnlp-href
+	applet
+	* tests/reproducers/simple/JToJSString/testcases/JToJSStringTest.java:
+	New reproducer for PR1794
+	* tests/reproducers/simple/JToJSString/resources/JToJSString.html:
+	same
+	* tests/reproducers/simple/JToJSString/resources/JToJSJnlpApplet.html:
+	same
+	* tests/reproducers/simple/JToJSString/resources/JToJSString.js:
+	same
+	* tests/reproducers/simple/JToJSString/resources/JToJSApplet.jnlp:
+	same
+	* tests/reproducers/simple/JToJSString/srcs/JToJSString.java:
+	same
+
 2014-05-23  Jiri Vanek  <jvanek at redhat.com>
 
 	Fixed cache tests
diff -r e5a7d39eecbb -r ef96a1c8776b tests/reproducers/simple/JToJSString/resources/JToJSString.html
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/tests/reproducers/simple/JToJSString/resources/JToJSString.html	Fri May 30 16:07:45 2014 -0400
@@ -0,0 +1,59 @@
+<!-- 
+Copyright (C) 2014 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.
+ -->
+
+<html>
+<body>
+    <div id="notice"></div>
+    <div id="failMessage"></div>
+    <div id="byids"></div>
+    <br>
+    <div id="writetojss"></div>
+    <br> ------------
+    <br>
+    <br>
+    <div id="byid"></div>
+    <br>
+    <div id="writetojs"></div>
+    <applet id='testapplet' code='JToJSString'
+        archive='./JToJSString.jar' 
+        width=640 height=480 MAYSCRIPT
+        scriptable=true>
+    </applet>
+
+    <script type="text/javascript" src="JToJSString.js"></script>
+</body>
+</html>
\ No newline at end of file
diff -r e5a7d39eecbb -r ef96a1c8776b tests/reproducers/simple/JToJSString/resources/JToJSString.js
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/tests/reproducers/simple/JToJSString/resources/JToJSString.js	Fri May 30 16:07:45 2014 -0400
@@ -0,0 +1,49 @@
+function writeToJS(myStringArray) {
+    var tojs = document.getElementById("writetojs");
+    tojs.innerHTML = "" + myStringArray[0] + myStringArray[1]
+            + myStringArray[2];
+}
+
+function writeToJSs(myString) {
+    var tojss = document.getElementById("writetojss");
+    tojss.innerHTML = myString;
+}
+
+function getDOMElementByID(id) {
+    return document.getElementById(id).innerHTML;
+}
+
+function attemptTest() {
+    try {
+        failMessage.innerHTML = failMessage.innerHTML + new Date().getTime() / 1000
+        notice.innerHTML = "1";
+        testapplet.printFromJS("Stage 1 reached");
+
+        var byids = document.getElementById("byids");
+        notice.innerHTML = "2";
+        testapplet.printFromJS("Stage 2 reached");
+
+        byids.innerHTML = "String by Id: " + testapplet.myString;
+        notice.innerHTML = "3";
+        testapplet.printFromJS("Stage 3 reached");
+
+        var byid = document.getElementById("byid");
+        notice.innerHTML = "4";
+        testapplet.printFromJS("Stage 4 reached");
+
+        byid.innerHTML = "StringArray by Id: " + testapplet.myStringArray[0]
+                + ", " + testapplet.myStringArray[1] + ", "
+                + testapplet.myStringArray[2];
+        notice.innerHTML = "5";
+        testapplet.printFromJS("Stage 5 reached");
+
+        testapplet.readStringAndFinish();
+        notice.innerHTML = "6";
+        testapplet.printFromJS("Stage 6 reached");
+    } catch (err) {
+        failMessage.innerHTML = failMessage.innerHTML + err.message;
+        setTimeout(attemptTest, 100);
+    }
+}
+
+attemptTest();
\ No newline at end of file
diff -r e5a7d39eecbb -r ef96a1c8776b tests/reproducers/simple/JToJSString/resources/JToJSStringApplet.jnlp
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/tests/reproducers/simple/JToJSString/resources/JToJSStringApplet.jnlp	Fri May 30 16:07:45 2014 -0400
@@ -0,0 +1,53 @@
+<!--
+
+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; either version 2, or (at your option)
+any later version.
+
+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.
+
+ -->
+<?xml version="1.0" encoding="utf-8"?>
+<jnlp spec="1.0" href="JToJSStringApplet.jnlp">
+  <information>
+    <title>JavaToJS</title>
+    <vendor>IcedTea</vendor>
+    <homepage href="http://icedtea.classpath.org/wiki/IcedTea-Web#Testing_IcedTea-Web"/>
+    <description>LiveConnect - Output Strings from Array from Java to JS</description>
+    <offline-allowed/>
+  </information>
+  <resources>
+    <j2se version="1.4+"/>
+    <jar href="JToJSString.jar"/>
+  </resources>
+  <applet-desc main-class="JToJSString">
+  </applet-desc>
+</jnlp>
\ No newline at end of file
diff -r e5a7d39eecbb -r ef96a1c8776b tests/reproducers/simple/JToJSString/resources/JToJSStringJnlpApplet.html
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/tests/reproducers/simple/JToJSString/resources/JToJSStringJnlpApplet.html	Fri May 30 16:07:45 2014 -0400
@@ -0,0 +1,60 @@
+<!-- 
+Copyright (C) 2014 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.
+ -->
+
+<html>
+<body>
+    <div id="notice"></div>
+    <div id="failMessage"></div>
+    <div id="test"></div>
+    <div id="byids"></div>
+    <br>
+    <div id="writetojss"></div>
+    <br> ------------
+    <br>
+    <br>
+    <div id="byid"></div>
+    <br>
+    <div id="writetojs"></div>
+    <applet id='testapplet' code='JToJSString'
+        jnlp_href='JToJSStringApplet.jnlp'
+        width=640 height=480 MAYSCRIPT
+        scriptable=true>
+    </applet>
+
+    <script type="text/javascript" src="JToJSString.js"></script>
+</body>
+</html>
\ No newline at end of file
diff -r e5a7d39eecbb -r ef96a1c8776b tests/reproducers/simple/JToJSString/srcs/JToJSString.java
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/tests/reproducers/simple/JToJSString/srcs/JToJSString.java	Fri May 30 16:07:45 2014 -0400
@@ -0,0 +1,98 @@
+/* 
+Copyright (C) 2014 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 java.applet.Applet;
+import netscape.javascript.JSObject;
+
+public class JToJSString extends Applet {
+
+    public String[] myStringArray = { "a", "b", "c" };
+    public String myString = "notarrayitem";
+
+    private final String writetojs = "writetojs";
+    private final String writetojss = "writetojss";
+
+    private JSObject window;
+
+    @Override
+    public void init() {
+        System.out.println("init");
+        // JSObject window = JSObject.getWindow(this);
+        window = JSObject.getWindow(this);
+
+        if (window == null) {
+            System.out.println("init stage: window is null");
+        } else {
+            System.out.println(window.toString());
+
+            window.call("writeToJS", new Object[] { myStringArray });
+            window.call("writeToJSs", new Object[] { myString });
+
+            System.out.println("init stage: complete");
+        }
+    }
+
+    public void jjsReadString(String element) {
+        System.out.println("jjsReadString " + element);
+        if (window == null) {
+            window = JSObject.getWindow(this);
+            System.out.println("jjsReadString stage: window is null");
+        }
+
+        Object value = window.call("getDOMElementByID", new Object[] { element });
+        System.out.println(value);
+
+    }
+
+    public void readStringAndFinish() {
+        System.out.println("readStringAndFinish");
+
+        jjsReadString("writetojs");
+        jjsReadString("writetojss");
+
+        System.out.println("afterTests");
+    }
+
+    public void printFromJS(String text) {
+        System.out.println(text);
+    }
+
+    @Override
+    public void destroy() {
+        System.out.println("destroy");
+    }
+}
diff -r e5a7d39eecbb -r ef96a1c8776b tests/reproducers/simple/JToJSString/testcases/JToJSStringTest.java
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/tests/reproducers/simple/JToJSString/testcases/JToJSStringTest.java	Fri May 30 16:07:45 2014 -0400
@@ -0,0 +1,112 @@
+/* 
+Copyright (C) 2014 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.annotations.Bug;
+import net.sourceforge.jnlp.annotations.KnownToFail;
+import net.sourceforge.jnlp.annotations.NeedsDisplay;
+import net.sourceforge.jnlp.annotations.TestInBrowsers;
+import net.sourceforge.jnlp.browsertesting.BrowserTest;
+import net.sourceforge.jnlp.browsertesting.Browsers;
+import net.sourceforge.jnlp.closinglisteners.AutoOkClosingListener;
+import net.sourceforge.jnlp.closinglisteners.CountingClosingListener;
+
+import org.junit.Assert;
+import org.junit.Test;
+
+public class JToJSStringTest extends BrowserTest {
+    // the JS<->J tests tend to make Opera unusable
+    private static final boolean doNotRunInOpera = true;
+
+    private static final String initStr = "init";
+    private static final String afterStr = "afterTests";
+
+    private class CountingClosingListenerImpl extends CountingClosingListener {
+        @Override
+        protected boolean isAlowedToFinish(String s) {
+            return (s.contains(initStr) && s.contains(afterStr));
+        }
+    }
+
+    private static void evaluateStdoutContents(String expectedStdout, ProcessResult pr) {
+        Assert.assertTrue("JSToJSet: the stdout should contain " + initStr + ", but it didnt.", pr.stdout.contains(initStr));
+        Assert.assertTrue("JSToJSet: the output should include: " + expectedStdout + ", but it didnt.", pr.stdout.contains(expectedStdout));
+    }
+
+    private void javaToJSTest(String url, String expectedStdout) throws Exception {
+        if (doNotRunInOpera) {
+            if (server.getCurrentBrowser().getID() == Browsers.opera) {
+                return;
+            }
+            ProcessResult pr = server.executeBrowser(url, new CountingClosingListenerImpl(), new CountingClosingListenerImpl());
+            evaluateStdoutContents(expectedStdout, pr);
+        }
+    }
+
+    @Test
+    @TestInBrowsers(testIn = { Browsers.all })
+    @NeedsDisplay
+    @KnownToFail
+    @Bug(id = { "PR1794" })
+    public void StringArrayTest() throws Exception {
+        javaToJSTest("/JToJSString.html", "abc");
+    }
+
+    @Test
+    @TestInBrowsers(testIn = { Browsers.all })
+    @NeedsDisplay
+    public void StringTest() throws Exception {
+        javaToJSTest("/JToJSString.html", "notarrayitem");
+    }
+
+    @Test
+    @TestInBrowsers(testIn = { Browsers.all })
+    @NeedsDisplay
+    @KnownToFail
+    @Bug(id = { "PR1794" })
+    public void jnlpStringArrayAppletTest() throws Exception {
+        javaToJSTest("/JToJSStringJnlpApplet.html", "abc");
+    }
+
+    @Test
+    @TestInBrowsers(testIn = { Browsers.all })
+    @NeedsDisplay
+    @Bug(id = { "PR1794" })
+    public void jnlpStringAppletTest() throws Exception {
+        javaToJSTest("/JToJSStringJnlpApplet.html", "notarrayitem");
+    }
+}


More information about the distro-pkg-dev mailing list