| 1 |
/* JSToJSetTest.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.Bug; |
| 44 |
import net.sourceforge.jnlp.annotations.KnownToFail; |
| 45 |
import net.sourceforge.jnlp.annotations.NeedsDisplay; |
| 46 |
import net.sourceforge.jnlp.annotations.TestInBrowsers; |
| 47 |
import org.junit.Assert; |
| 48 |
|
| 49 |
import org.junit.Test; |
| 50 |
|
| 51 |
@Bug(id = { "PR1298" }) |
| 52 |
public class JSToJSetTest extends BrowserTest { |
| 53 |
|
| 54 |
// the JS<->J tests tend to make Opera unusable |
| 55 |
public final boolean doNotRunInOpera = false; |
| 56 |
|
| 57 |
private final String initStr = "JSToJSet applet initialized."; |
| 58 |
private final String afterStr = "afterTests"; |
| 59 |
|
| 60 |
public enum TestType { |
| 61 |
ARRAY_ELEMENT, WHOLE_ARRAY, NORMAL_VALUE |
| 62 |
} |
| 63 |
|
| 64 |
private class CountingClosingListenerImpl extends CountingClosingListener { |
| 65 |
|
| 66 |
@Override |
| 67 |
protected boolean isAlowedToFinish(String s) { |
| 68 |
return (s.contains(initStr) && s.contains(afterStr)); |
| 69 |
} |
| 70 |
} |
| 71 |
|
| 72 |
private void evaluateStdoutContents(String expectedStdout, ProcessResult pr) { |
| 73 |
// Assert that the applet was initialized. |
| 74 |
Assert.assertTrue("JSToJSet: the stdout should contain " + initStr + ", but it didnt.", pr.stdout.contains(initStr)); |
| 75 |
|
| 76 |
// Assert that the values set by JavaScript are ok |
| 77 |
Assert.assertTrue("JSToJSet: the output should include: " + expectedStdout + ", but it didnt.", pr.stdout.contains(expectedStdout)); |
| 78 |
|
| 79 |
} |
| 80 |
|
| 81 |
private void jsToJavaSetNormalTest(String fieldStr, String valueStr) throws Exception { |
| 82 |
|
| 83 |
if (doNotRunInOpera) { |
| 84 |
if (server.getCurrentBrowser().getID() == Browsers.opera) { |
| 85 |
return; |
| 86 |
} |
| 87 |
} |
| 88 |
|
| 89 |
String strURL = "/JSToJSet.html?" + fieldStr + ";" + valueStr; |
| 90 |
ProcessResult pr = server.executeBrowser(strURL, new CountingClosingListenerImpl(), new CountingClosingListenerImpl()); |
| 91 |
String expectedStdout = "New value is: " + valueStr; |
| 92 |
evaluateStdoutContents(expectedStdout, pr); |
| 93 |
} |
| 94 |
|
| 95 |
private void jsToJavaSetSpecialTest(String fieldStr, String valueStr, TestType testType) throws Exception { |
| 96 |
|
| 97 |
if (doNotRunInOpera) { |
| 98 |
Browsers b = server.getCurrentBrowser().getID(); |
| 99 |
if (b == Browsers.opera) { |
| 100 |
return; |
| 101 |
} |
| 102 |
} |
| 103 |
|
| 104 |
String strURL = "/JSToJSet.html?"; |
| 105 |
String expectedStdout = ""; |
| 106 |
switch (testType) { |
| 107 |
case ARRAY_ELEMENT:// array element |
| 108 |
strURL += fieldStr + ";" + valueStr; |
| 109 |
expectedStdout = "New array value is: " + valueStr; |
| 110 |
break; |
| 111 |
case WHOLE_ARRAY:// whole array, set 1st element |
| 112 |
strURL += fieldStr + ";[" + valueStr; |
| 113 |
expectedStdout = "New array value is: " + valueStr; |
| 114 |
break; |
| 115 |
case NORMAL_VALUE:// char et al - to be set at JS side |
| 116 |
strURL += fieldStr + ";JavaScript"; |
| 117 |
expectedStdout = "New value is: " + valueStr; |
| 118 |
break; |
| 119 |
default: |
| 120 |
break; |
| 121 |
} |
| 122 |
|
| 123 |
ProcessResult pr = server.executeBrowser(strURL, new CountingClosingListenerImpl(), new CountingClosingListenerImpl()); |
| 124 |
evaluateStdoutContents(expectedStdout, pr); |
| 125 |
} |
| 126 |
|
| 127 |
@Test |
| 128 |
@TestInBrowsers(testIn = { Browsers.all }) |
| 129 |
@NeedsDisplay |
| 130 |
public void AppletJSToJSet_int_Test() throws Exception { |
| 131 |
jsToJavaSetNormalTest("_int", "1"); |
| 132 |
} |
| 133 |
|
| 134 |
@Test |
| 135 |
@TestInBrowsers(testIn = { Browsers.all }) |
| 136 |
@NeedsDisplay |
| 137 |
public void AppletJSToJSet_double_Test() throws Exception { |
| 138 |
jsToJavaSetNormalTest("_double", "1.0"); |
| 139 |
} |
| 140 |
|
| 141 |
@Test |
| 142 |
@TestInBrowsers(testIn = { Browsers.all }) |
| 143 |
@NeedsDisplay |
| 144 |
public void AppletJSToJSet_float_Test() throws Exception { |
| 145 |
jsToJavaSetNormalTest("_float", "1.1"); |
| 146 |
} |
| 147 |
|
| 148 |
@Test |
| 149 |
@TestInBrowsers(testIn = { Browsers.all }) |
| 150 |
@NeedsDisplay |
| 151 |
public void AppletJSToJSet_long_Test() throws Exception { |
| 152 |
jsToJavaSetNormalTest("_long", "10000"); |
| 153 |
} |
| 154 |
|
| 155 |
@Test |
| 156 |
@TestInBrowsers(testIn = { Browsers.all }) |
| 157 |
@NeedsDisplay |
| 158 |
public void AppletJSToJSet_boolean_Test() throws Exception { |
| 159 |
jsToJavaSetNormalTest("_boolean", "true"); |
| 160 |
} |
| 161 |
|
| 162 |
@Test |
| 163 |
@TestInBrowsers(testIn = { Browsers.all }) |
| 164 |
@NeedsDisplay |
| 165 |
public void AppletJSToJSet_char_Test() throws Exception { |
| 166 |
jsToJavaSetSpecialTest("_char", "a", TestType.NORMAL_VALUE); |
| 167 |
} |
| 168 |
|
| 169 |
@Test |
| 170 |
@TestInBrowsers(testIn = { Browsers.all }) |
| 171 |
@NeedsDisplay |
| 172 |
public void AppletJSToJSet_byte_Test() throws Exception { |
| 173 |
jsToJavaSetNormalTest("_byte", "10"); |
| 174 |
} |
| 175 |
|
| 176 |
@Test |
| 177 |
@TestInBrowsers(testIn = { Browsers.all }) |
| 178 |
@NeedsDisplay |
| 179 |
@Bug(id = { "PR1298" }) |
| 180 |
public void AppletJSToJSet_intArrayElement_Test() throws Exception { |
| 181 |
jsToJavaSetSpecialTest("_intArray[0]", "1", TestType.ARRAY_ELEMENT); |
| 182 |
} |
| 183 |
|
| 184 |
@Test |
| 185 |
@TestInBrowsers(testIn = { Browsers.all }) |
| 186 |
@NeedsDisplay |
| 187 |
public void AppletJSToJSet_regularString_Test() throws Exception { |
| 188 |
jsToJavaSetNormalTest("_String", "teststring"); |
| 189 |
} |
| 190 |
|
| 191 |
@Test |
| 192 |
@TestInBrowsers(testIn = { Browsers.all }) |
| 193 |
@NeedsDisplay |
| 194 |
public void AppletJSToJSet_specialCharsString_Test() throws Exception { |
| 195 |
jsToJavaSetSpecialTest("_specialString", "𠁎〒£$ǣ€𝍖", TestType.NORMAL_VALUE); |
| 196 |
} |
| 197 |
|
| 198 |
@Test |
| 199 |
@TestInBrowsers(testIn = { Browsers.all }) |
| 200 |
@NeedsDisplay |
| 201 |
public void AppletJSToJSet_null_Test() throws Exception { |
| 202 |
jsToJavaSetNormalTest("_Object", "null"); |
| 203 |
} |
| 204 |
|
| 205 |
@Test |
| 206 |
@TestInBrowsers(testIn = { Browsers.all }) |
| 207 |
@NeedsDisplay |
| 208 |
@KnownToFail |
| 209 |
public void AppletJSToJSet_Integer_Test() throws Exception { |
| 210 |
jsToJavaSetNormalTest("_Integer", "1"); |
| 211 |
} |
| 212 |
|
| 213 |
@Test |
| 214 |
@TestInBrowsers(testIn = { Browsers.all }) |
| 215 |
@NeedsDisplay |
| 216 |
@KnownToFail |
| 217 |
public void AppletJSToJSet_Double_Test() throws Exception { |
| 218 |
jsToJavaSetNormalTest("_Double", "1.0"); |
| 219 |
} |
| 220 |
|
| 221 |
@Test |
| 222 |
@TestInBrowsers(testIn = { Browsers.all }) |
| 223 |
@NeedsDisplay |
| 224 |
@KnownToFail |
| 225 |
public void AppletJSToJSet_Float_Test() throws Exception { |
| 226 |
jsToJavaSetNormalTest("_Float", "1.1"); |
| 227 |
} |
| 228 |
|
| 229 |
@Test |
| 230 |
@TestInBrowsers(testIn = { Browsers.all }) |
| 231 |
@NeedsDisplay |
| 232 |
@KnownToFail |
| 233 |
public void AppletJSToJSet_Long_Test() throws Exception { |
| 234 |
jsToJavaSetNormalTest("_Long", "10000"); |
| 235 |
} |
| 236 |
|
| 237 |
@Test |
| 238 |
@TestInBrowsers(testIn = { Browsers.all }) |
| 239 |
@NeedsDisplay |
| 240 |
public void AppletJSToJSet_Boolean_Test() throws Exception { |
| 241 |
jsToJavaSetNormalTest("_Boolean", "true"); |
| 242 |
} |
| 243 |
|
| 244 |
@Test |
| 245 |
@TestInBrowsers(testIn = { Browsers.all }) |
| 246 |
@NeedsDisplay |
| 247 |
public void AppletJSToJSet_Character_Test() throws Exception { |
| 248 |
jsToJavaSetSpecialTest("_Character", "A", TestType.NORMAL_VALUE); |
| 249 |
} |
| 250 |
|
| 251 |
@Test |
| 252 |
@TestInBrowsers(testIn = { Browsers.all }) |
| 253 |
@NeedsDisplay |
| 254 |
@KnownToFail |
| 255 |
public void AppletJSToJSet_Byte_Test() throws Exception { |
| 256 |
jsToJavaSetNormalTest("_Byte", "100"); |
| 257 |
} |
| 258 |
|
| 259 |
@Test |
| 260 |
@TestInBrowsers(testIn = { Browsers.all }) |
| 261 |
@NeedsDisplay |
| 262 |
@KnownToFail |
| 263 |
@Bug(id = { "PR1298" }) |
| 264 |
public void AppletJSToJSet_DoubleArrayElement_Test() throws Exception { |
| 265 |
jsToJavaSetSpecialTest("_DoubleArray[0]", "1.1", TestType.ARRAY_ELEMENT); |
| 266 |
} |
| 267 |
|
| 268 |
@Test |
| 269 |
@TestInBrowsers(testIn = { Browsers.all }) |
| 270 |
@NeedsDisplay |
| 271 |
@KnownToFail |
| 272 |
public void AppletJSToJSet_DoubleFullArray_Test() throws Exception { |
| 273 |
jsToJavaSetSpecialTest("_DoubleArray2", "0.1", TestType.WHOLE_ARRAY); |
| 274 |
} |
| 275 |
|
| 276 |
@Test |
| 277 |
@TestInBrowsers(testIn = { Browsers.all }) |
| 278 |
@NeedsDisplay |
| 279 |
public void AppletJSToJSet_JSObject_Test() throws Exception { |
| 280 |
jsToJavaSetSpecialTest("_JSObject", "100, red", TestType.NORMAL_VALUE); |
| 281 |
} |
| 282 |
} |