1 /* JToJSFuncParamTest.java 2 Copyright (C) 2012 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.ServerAccess; 40 import net.sourceforge.jnlp.browsertesting.BrowserTest; 41 import net.sourceforge.jnlp.browsertesting.Browsers; 42 import net.sourceforge.jnlp.closinglisteners.CountingClosingListener; 43 import net.sourceforge.jnlp.annotations.NeedsDisplay; 44 import net.sourceforge.jnlp.annotations.TestInBrowsers; 45 import net.sourceforge.jnlp.annotations.KnownToFail; 46 import org.junit.Assert; 47 48 import org.junit.Test; 49 50 public class JavascriptFuncParamTest extends BrowserTest { 51 52 public final boolean doNotRunInOpera = false; 53 54 private final String initStr = "JToJSFuncParam applet initialized."; 55 private final String afterStr = "afterTests"; 56 private final String globStart = "Call with "; 57 private final String globEnd = " from JS"; 58 private final String jEnd = " from J"; 59 60 private class CountingClosingListenerImpl extends CountingClosingListener { 61 62 @Override isAlowedToFinish(String s)63 protected boolean isAlowedToFinish(String s) { 64 return (s.contains(initStr) && s.contains(afterStr)); 65 } 66 } 67 evaluateStdoutContents(ProcessResult pr)68 private void evaluateStdoutContents(ProcessResult pr) { 69 // Assert that the applet was initialized. 70 Assert.assertTrue("JToJSFuncParamTest stdout should contain " + initStr + " but it didnt.", pr.stdout.contains(initStr)); 71 72 // Assert that the results of two calls of js func are the same 73 74 int gs = pr.stdout.indexOf(globStart); 75 int ge = pr.stdout.indexOf(globEnd); 76 int je = pr.stdout.indexOf(jEnd); 77 int jss = je + jEnd.length() + 1; 78 79 String javaOutput = pr.stdout.substring(gs, je); 80 String jsOutput = pr.stdout.substring(jss, ge); 81 82 Assert.assertTrue("JToJSFuncParam: the J and JS outputs are not equal!", javaOutput.equals(jsOutput)); 83 } 84 javaToJSFuncParamTest(String funcStr)85 private void javaToJSFuncParamTest(String funcStr) throws Exception { 86 87 if( doNotRunInOpera){ 88 Browsers b = server.getCurrentBrowser().getID(); 89 if(b == Browsers.opera){ 90 return; 91 } 92 } 93 94 String strURL = "/JavascriptFuncParam.html?" + funcStr; 95 ProcessResult pr = server.executeBrowser(strURL, new CountingClosingListenerImpl(), new CountingClosingListenerImpl()); 96 evaluateStdoutContents(pr); 97 } 98 99 @Test 100 @TestInBrowsers(testIn = { Browsers.all }) 101 @NeedsDisplay AppletJToJSFuncParam_int_Test()102 public void AppletJToJSFuncParam_int_Test() throws Exception { 103 javaToJSFuncParamTest("jjsCallintParam"); 104 } 105 106 @Test 107 @TestInBrowsers(testIn = { Browsers.all }) 108 @NeedsDisplay AppletJToJSFuncParam_double_Test()109 public void AppletJToJSFuncParam_double_Test() throws Exception { 110 javaToJSFuncParamTest("jjsCalldoubleParam"); 111 } 112 113 @Test 114 @TestInBrowsers(testIn = { Browsers.all }) 115 @NeedsDisplay AppletJToJSFuncParam_float_Test()116 public void AppletJToJSFuncParam_float_Test() throws Exception { 117 javaToJSFuncParamTest("jjsCallfloatParam"); 118 } 119 120 @Test 121 @TestInBrowsers(testIn = { Browsers.all }) 122 @NeedsDisplay AppletJToJSFuncParam_long_Test()123 public void AppletJToJSFuncParam_long_Test() throws Exception { 124 javaToJSFuncParamTest("jjsCalllongParam"); 125 } 126 127 @Test 128 @TestInBrowsers(testIn = { Browsers.all }) 129 @NeedsDisplay AppletJToJSFuncParam_short_Test()130 public void AppletJToJSFuncParam_short_Test() throws Exception { 131 javaToJSFuncParamTest("jjsCallshortParam"); 132 } 133 134 @Test 135 @TestInBrowsers(testIn = { Browsers.all }) 136 @NeedsDisplay AppletJToJSFuncParam_byte_Test()137 public void AppletJToJSFuncParam_byte_Test() throws Exception { 138 javaToJSFuncParamTest("jjsCallbyteParam"); 139 } 140 141 142 @Test 143 @TestInBrowsers(testIn = { Browsers.all }) 144 @NeedsDisplay AppletJToJSFuncParam_char_Test()145 public void AppletJToJSFuncParam_char_Test() throws Exception { 146 javaToJSFuncParamTest("jjsCallcharParam"); 147 } 148 149 @Test 150 @TestInBrowsers(testIn = { Browsers.all }) 151 @NeedsDisplay AppletJToJSFuncParam_boolean_Test()152 public void AppletJToJSFuncParam_boolean_Test() throws Exception { 153 javaToJSFuncParamTest("jjsCallbooleanParam"); 154 } 155 156 @Test 157 @TestInBrowsers(testIn = { Browsers.all }) 158 @NeedsDisplay AppletJToJSFuncParam_Integer_Test()159 public void AppletJToJSFuncParam_Integer_Test() throws Exception { 160 javaToJSFuncParamTest("jjsCallIntegerParam"); 161 } 162 163 @Test 164 @TestInBrowsers(testIn = { Browsers.all }) 165 @NeedsDisplay AppletJToJSFuncParam_Double_Test()166 public void AppletJToJSFuncParam_Double_Test() throws Exception { 167 javaToJSFuncParamTest("jjsCallDoubleParam"); 168 } 169 170 @Test 171 @TestInBrowsers(testIn = { Browsers.all }) 172 @NeedsDisplay AppletJToJSFuncParam_Float_Test()173 public void AppletJToJSFuncParam_Float_Test() throws Exception { 174 javaToJSFuncParamTest("jjsCallFloatParam"); 175 } 176 177 @Test 178 @TestInBrowsers(testIn = { Browsers.all }) 179 @NeedsDisplay AppletJToJSFuncParam_Long_Test()180 public void AppletJToJSFuncParam_Long_Test() throws Exception { 181 javaToJSFuncParamTest("jjsCallLongParam"); 182 } 183 184 @Test 185 @TestInBrowsers(testIn = { Browsers.all }) 186 @NeedsDisplay AppletJToJSFuncParam_Short_Test()187 public void AppletJToJSFuncParam_Short_Test() throws Exception { 188 javaToJSFuncParamTest("jjsCallShortParam"); 189 } 190 191 @Test 192 @TestInBrowsers(testIn = { Browsers.all }) 193 @NeedsDisplay AppletJToJSFuncParam_Byte_Test()194 public void AppletJToJSFuncParam_Byte_Test() throws Exception { 195 javaToJSFuncParamTest("jjsCallByteParam"); 196 } 197 198 @Test 199 @TestInBrowsers(testIn = { Browsers.all }) 200 @NeedsDisplay AppletJToJSFuncParam_Boolean_Test()201 public void AppletJToJSFuncParam_Boolean_Test() throws Exception { 202 javaToJSFuncParamTest("jjsCallBooleanParam"); 203 } 204 205 @Test 206 @TestInBrowsers(testIn = { Browsers.all }) 207 @NeedsDisplay AppletJToJSFuncParam_Character_Test()208 public void AppletJToJSFuncParam_Character_Test() throws Exception { 209 javaToJSFuncParamTest("jjsCallCharacterParam"); 210 } 211 212 @Test 213 @TestInBrowsers(testIn = { Browsers.all }) 214 @NeedsDisplay AppletJToJSFuncParam_String_Test()215 public void AppletJToJSFuncParam_String_Test() throws Exception { 216 javaToJSFuncParamTest("jjsCallStringParam"); 217 } 218 219 @Test 220 @TestInBrowsers(testIn = { Browsers.all }) 221 @NeedsDisplay AppletJToJSFuncParam_DummyObject_Test()222 public void AppletJToJSFuncParam_DummyObject_Test() throws Exception { 223 javaToJSFuncParamTest("jjsCallDummyObjectParam"); 224 } 225 226 @Test 227 @TestInBrowsers(testIn = { Browsers.all }) 228 @NeedsDisplay 229 @KnownToFail(failsIn={Browsers.googleChrome, Browsers.chromiumBrowser}) AppletJToJSFuncParam_JSObject_Test()230 public void AppletJToJSFuncParam_JSObject_Test() throws Exception { 231 javaToJSFuncParamTest("jjsCallJSObjectParam"); 232 } 233 } 234