1 /* 2 Copyright (C) 2014 Red Hat, Inc. 3 4 This file is part of IcedTea. 5 6 IcedTea is free software; you can redistribute it and/or 7 modify it under the terms of the GNU General Public License as published by 8 the Free Software Foundation, version 2. 9 10 IcedTea is distributed in the hope that it will be useful, 11 but WITHOUT ANY WARRANTY; without even the implied warranty of 12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 General Public License for more details. 14 15 You should have received a copy of the GNU General Public License 16 along with IcedTea; see the file COPYING. If not, write to 17 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 18 02110-1301 USA. 19 20 Linking this library statically or dynamically with other modules is 21 making a combined work based on this library. Thus, the terms and 22 conditions of the GNU General Public License cover the whole 23 combination. 24 25 As a special exception, the copyright holders of this library give you 26 permission to link this library with independent modules to produce an 27 executable, regardless of the license terms of these independent 28 modules, and to copy and distribute the resulting executable under 29 terms of your choice, provided that you also meet, for each linked 30 independent module, the terms and conditions of the license of that 31 module. An independent module is a module which is not derived from 32 or based on this library. If you modify this library, you may extend 33 this exception to your version of the library, but you are not 34 obligated to do so. If you do not wish to do so, delete this 35 exception statement from your version. 36 */ 37 38 import net.sourceforge.jnlp.ProcessResult; 39 import net.sourceforge.jnlp.annotations.Bug; 40 import net.sourceforge.jnlp.annotations.KnownToFail; 41 import net.sourceforge.jnlp.annotations.NeedsDisplay; 42 import net.sourceforge.jnlp.annotations.TestInBrowsers; 43 import net.sourceforge.jnlp.browsertesting.BrowserTest; 44 import net.sourceforge.jnlp.browsertesting.Browsers; 45 import net.sourceforge.jnlp.closinglisteners.AutoOkClosingListener; 46 import net.sourceforge.jnlp.closinglisteners.CountingClosingListener; 47 48 import org.junit.Assert; 49 import org.junit.Test; 50 51 public class JToJSStringTest extends BrowserTest { 52 // the JS<->J tests tend to make Opera unusable 53 private static final boolean doNotRunInOpera = false; 54 55 private static final String initStr = "init"; 56 private static final String afterStr = "afterTests"; 57 58 private class CountingClosingListenerImpl extends CountingClosingListener { 59 @Override isAlowedToFinish(String s)60 protected boolean isAlowedToFinish(String s) { 61 return (s.contains(initStr) && s.contains(afterStr)); 62 } 63 } 64 evaluateStdoutContents(String expectedStdout, ProcessResult pr)65 private static void evaluateStdoutContents(String expectedStdout, ProcessResult pr) { 66 Assert.assertTrue("JSToJSet: the stdout should contain " + initStr + ", but it didnt.", pr.stdout.contains(initStr)); 67 Assert.assertTrue("JSToJSet: the output should include: " + expectedStdout + ", but it didnt.", pr.stdout.contains(expectedStdout)); 68 } 69 javaToJSTest(String url, String expectedStdout)70 private void javaToJSTest(String url, String expectedStdout) throws Exception { 71 if (doNotRunInOpera) { 72 if (server.getCurrentBrowser().getID() == Browsers.opera) { 73 return; 74 } 75 ProcessResult pr = server.executeBrowser(url, new CountingClosingListenerImpl(), new CountingClosingListenerImpl()); 76 evaluateStdoutContents(expectedStdout, pr); 77 } 78 } 79 80 @Test 81 @TestInBrowsers(testIn = { Browsers.all }) 82 @NeedsDisplay 83 @Bug(id = { "PR1794" }) StringArrayTest()84 public void StringArrayTest() throws Exception { 85 javaToJSTest("/JToJSString.html", "abc"); 86 } 87 88 @Test 89 @TestInBrowsers(testIn = { Browsers.all }) 90 @NeedsDisplay StringTest()91 public void StringTest() throws Exception { 92 javaToJSTest("/JToJSString.html", "notarrayitem"); 93 } 94 95 @Test 96 @TestInBrowsers(testIn = { Browsers.all }) 97 @NeedsDisplay 98 @Bug(id = { "PR1794" }) jnlpStringArrayAppletTest()99 public void jnlpStringArrayAppletTest() throws Exception { 100 javaToJSTest("/JToJSStringJnlpApplet.html", "abc"); 101 } 102 103 @Test 104 @TestInBrowsers(testIn = { Browsers.all }) 105 @NeedsDisplay 106 @Bug(id = { "PR1794" }) jnlpStringAppletTest()107 public void jnlpStringAppletTest() throws Exception { 108 javaToJSTest("/JToJSStringJnlpApplet.html", "notarrayitem"); 109 } 110 } 111