|
1 | 1 | /*******************************************************************************
|
2 |
| - * Copyright (c) 2000, 2022 IBM Corporation and others. |
| 2 | + * Copyright (c) 2000, 2024 IBM Corporation and others. |
3 | 3 | *
|
4 | 4 | * This program and the accompanying materials
|
5 | 5 | * are made available under the terms of the Eclipse Public License 2.0
|
@@ -803,8 +803,10 @@ public void test_OpenWindowListener_openHasValidEventDetails() {
|
803 | 803 | });
|
804 | 804 |
|
805 | 805 | shell.open();
|
806 |
| - browser.setText("<html><script type='text/javascript'>window.open('about:blank')</script>\n" + |
807 |
| - "<body>This test uses Javascript to open a new window.</body></html>"); |
| 806 | + browser.setText(""" |
| 807 | + <html><script type='text/javascript'>window.open('about:blank')</script> |
| 808 | + <body>This test uses Javascript to open a new window.</body></html> |
| 809 | + """); |
808 | 810 |
|
809 | 811 | boolean passed = waitForPassCondition(openFiredCorrectly::get);
|
810 | 812 | assertTrue("Test timed out. OpenWindow event not fired.", passed);
|
@@ -833,15 +835,17 @@ public void test_OpenWindowListener_open_ChildPopup() {
|
833 | 835 |
|
834 | 836 | shell.open();
|
835 | 837 |
|
836 |
| - browser.setText("<html>" |
837 |
| - + "<script type='text/javascript'>" |
838 |
| - + "var newWin = window.open('about:blank');" // opens child window. |
839 |
| - + "</script>\n" + |
840 |
| - "<body>This test uses javascript to open a new window.</body></html>"); |
| 838 | + browser.setText(""" |
| 839 | + <html> |
| 840 | + <script type='text/javascript'> |
| 841 | + var newWin = window.open('about:blank'); |
| 842 | + </script> |
| 843 | + <body>This test uses javascript to open a new window.</body> |
| 844 | + </html>"""); |
841 | 845 |
|
842 | 846 | boolean passed = waitForPassCondition(childCompleted::get);
|
843 | 847 |
|
844 |
| - String errMsg = "\nTest timed out."; |
| 848 | + String errMsg = "Test timed out."; |
845 | 849 | assertTrue(errMsg, passed);
|
846 | 850 | }
|
847 | 851 |
|
@@ -880,11 +884,13 @@ public void test_OpenWindow_Progress_Listener_ValidateEventOrder() {
|
880 | 884 |
|
881 | 885 | shell.open();
|
882 | 886 |
|
883 |
| - browser.setText("<html>" |
884 |
| - + "<script type='text/javascript'>" |
885 |
| - + "var newWin = window.open('about:blank');" // opens child window. |
886 |
| - + "</script>\n" + |
887 |
| - "<body>This test uses javascript to open a new window.</body></html>"); |
| 887 | + browser.setText(""" |
| 888 | + <html> |
| 889 | + <script type='text/javascript'> |
| 890 | + var newWin = window.open('about:blank'); |
| 891 | + </script> |
| 892 | + <body>This test uses javascript to open a new window.</body> |
| 893 | + </html>"""); |
888 | 894 |
|
889 | 895 | boolean passed = waitForPassCondition(() -> windowOpenFired.get() && visibilityShowed.get() && childCompleted.get());
|
890 | 896 |
|
@@ -1323,12 +1329,14 @@ public void completed(ProgressEvent event) {
|
1323 | 1329 | });
|
1324 | 1330 |
|
1325 | 1331 | shell.open();
|
1326 |
| - browser.setText("<html>" |
1327 |
| - + "<script type='text/javascript'>" |
1328 |
| - + "window.open('about:blank');" // opens child window. |
1329 |
| - + "window.open('about:blank');" |
1330 |
| - + "</script>\n" + |
1331 |
| - "<body>This test uses javascript to open a new window.</body></html>"); |
| 1332 | + browser.setText(""" |
| 1333 | + <html>\ |
| 1334 | + <script type='text/javascript'>\ |
| 1335 | + window.open('about:blank');\ |
| 1336 | + window.open('about:blank');\ |
| 1337 | + </script> |
| 1338 | + <body>This test uses javascript to open a new window.</body> |
| 1339 | + </html>"""); |
1332 | 1340 |
|
1333 | 1341 | boolean passed = waitForPassCondition(secondChildCompleted::get);
|
1334 | 1342 |
|
@@ -1365,11 +1373,13 @@ public void test_VisibilityWindowListener_eventSize() {
|
1365 | 1373 | }));
|
1366 | 1374 |
|
1367 | 1375 | shell.open();
|
1368 |
| - browser.setText("<html>" |
1369 |
| - + "<script type='text/javascript'>" |
1370 |
| - + "window.open('javascript:\"Child Window\"','', \"height=200,width=300\")\n" |
1371 |
| - + "</script>\n" + |
1372 |
| - "<body>This test uses javascript to open a new window.</body></html>"); |
| 1376 | + browser.setText(""" |
| 1377 | + <html> |
| 1378 | + <script type='text/javascript'> |
| 1379 | + window.open('javascript:"Child Window"','', "height=200,width=300") |
| 1380 | + </script> |
| 1381 | + <body>This test uses javascript to open a new window.</body> |
| 1382 | + </html>"""); |
1373 | 1383 |
|
1374 | 1384 | boolean finishedWithoutTimeout = waitForPassCondition(childCompleted::get);
|
1375 | 1385 | browserChild.dispose();
|
@@ -1720,7 +1730,10 @@ public void test_getText_script() {
|
1720 | 1730 | if (SwtTestUtil.isWindows) {
|
1721 | 1731 | // Windows' Browser implementation returns the processed HTML rather than the original one.
|
1722 | 1732 | // The processed page injects "style" property into the body from the script.
|
1723 |
| - getText_helper(testString, "<html><head></head><body style=\"background-color: red;\">hello World<script>document.body.style.backgroundColor = \"red\";</script></body></html>"); |
| 1733 | + getText_helper(testString, """ |
| 1734 | + <html><head></head><body style="background-color: red;">hello World |
| 1735 | + <script>document.body.style.backgroundColor = "red";</script> |
| 1736 | + </body></html>"""); |
1724 | 1737 | } else {
|
1725 | 1738 | // Linux Webkit1, Webkit2
|
1726 | 1739 | // Cocoa
|
@@ -2154,16 +2167,19 @@ public Object function(Object[] arguments) {
|
2154 | 2167 | }
|
2155 | 2168 | }
|
2156 | 2169 |
|
2157 |
| - String htmlWithScript = "<html><head>\n" |
2158 |
| - + "<script language=\"JavaScript\">\n" |
2159 |
| - + "function callCustomFunction() {\n" // Define a javascript function. |
2160 |
| - + " document.body.style.backgroundColor = 'red'\n" |
2161 |
| - + " jsCallbackToJava()\n" // This calls the javafunction that we registered. |
2162 |
| - + "}" |
2163 |
| - + "</script>\n" |
2164 |
| - + "</head>\n" |
2165 |
| - + "<body> Going to make a callback to Java </body>\n" |
2166 |
| - + "</html>\n"; |
| 2170 | + // Define a javascript function and calls it |
| 2171 | + String htmlWithScript = """ |
| 2172 | + <html><head> |
| 2173 | + <script language="JavaScript"> |
| 2174 | + function callCustomFunction() { |
| 2175 | + document.body.style.backgroundColor = 'red' |
| 2176 | + jsCallbackToJava() |
| 2177 | + } |
| 2178 | + </script> |
| 2179 | + </head> |
| 2180 | + <body> Going to make a callback to Java </body> |
| 2181 | + </html> |
| 2182 | + """; |
2167 | 2183 |
|
2168 | 2184 | browser.setText(htmlWithScript);
|
2169 | 2185 | new JavascriptCallback(browser, "jsCallbackToJava");
|
@@ -2197,16 +2213,19 @@ public Object function(Object[] arguments) {
|
2197 | 2213 | }
|
2198 | 2214 | }
|
2199 | 2215 |
|
2200 |
| - String htmlWithScript = "<html><head>\n" |
2201 |
| - + "<script language=\"JavaScript\">\n" |
2202 |
| - + "function callCustomFunction() {\n" // Define a javascript function. |
2203 |
| - + " document.body.style.backgroundColor = 'red'\n" |
2204 |
| - + " jsCallbackToJava(5)\n" // This calls the javafunction that we registered ** with value of 5. |
2205 |
| - + "}" |
2206 |
| - + "</script>\n" |
2207 |
| - + "</head>\n" |
2208 |
| - + "<body> Going to make a callback to Java </body>\n" |
2209 |
| - + "</html>\n"; |
| 2216 | + // Define a javascript function and calls it with value of 5 |
| 2217 | + String htmlWithScript = """ |
| 2218 | + <html><head> |
| 2219 | + <script language="JavaScript"> |
| 2220 | + function callCustomFunction() { |
| 2221 | + document.body.style.backgroundColor = 'red' |
| 2222 | + jsCallbackToJava(5) |
| 2223 | + } |
| 2224 | + </script> |
| 2225 | + </head> |
| 2226 | + <body> Going to make a callback to Java </body> |
| 2227 | + </html> |
| 2228 | + """; |
2210 | 2229 |
|
2211 | 2230 | browser.setText(htmlWithScript);
|
2212 | 2231 | new JavascriptCallback(browser, "jsCallbackToJava");
|
@@ -2241,17 +2260,19 @@ public Object function(Object[] arguments) {
|
2241 | 2260 | return null;
|
2242 | 2261 | }
|
2243 | 2262 | }
|
2244 |
| - |
2245 |
| - String htmlWithScript = "<html><head>\n" |
2246 |
| - + "<script language=\"JavaScript\">\n" |
2247 |
| - + "function callCustomFunction() {\n" // Define a javascript function. |
2248 |
| - + " document.body.style.backgroundColor = 'red'\n" |
2249 |
| - + " jsCallbackToJava(true)\n" // This calls the javafunction that we registered. |
2250 |
| - + "}" |
2251 |
| - + "</script>\n" |
2252 |
| - + "</head>\n" |
2253 |
| - + "<body> Going to make a callback to Java </body>\n" |
2254 |
| - + "</html>\n"; |
| 2263 | + // Define a javascript function and call it |
| 2264 | + String htmlWithScript = """ |
| 2265 | + <html><head> |
| 2266 | + <script language="JavaScript"> |
| 2267 | + function callCustomFunction() { |
| 2268 | + document.body.style.backgroundColor = 'red' |
| 2269 | + jsCallbackToJava(true) |
| 2270 | + } |
| 2271 | + </script> |
| 2272 | + </head> |
| 2273 | + <body> Going to make a callback to Java </body> |
| 2274 | + </html> |
| 2275 | + """; |
2255 | 2276 |
|
2256 | 2277 | browser.setText(htmlWithScript);
|
2257 | 2278 | new JavascriptCallback(browser, "jsCallbackToJava");
|
@@ -2285,16 +2306,19 @@ public Object function(Object[] arguments) {
|
2285 | 2306 | }
|
2286 | 2307 | }
|
2287 | 2308 |
|
2288 |
| - String htmlWithScript = "<html><head>\n" |
2289 |
| - + "<script language=\"JavaScript\">\n" |
2290 |
| - + "function callCustomFunction() {\n" // Define a javascript function. |
2291 |
| - + " document.body.style.backgroundColor = 'red'\n" |
2292 |
| - + " jsCallbackToJava('hellojava')\n" // This calls the javafunction that we registered. |
2293 |
| - + "}" |
2294 |
| - + "</script>\n" |
2295 |
| - + "</head>\n" |
2296 |
| - + "<body> Going to make a callback to Java </body>\n" |
2297 |
| - + "</html>\n"; |
| 2309 | + // Define a javascript function and call it |
| 2310 | + String htmlWithScript = """ |
| 2311 | + <html><head> |
| 2312 | + <script language="JavaScript"> |
| 2313 | + function callCustomFunction() { |
| 2314 | + document.body.style.backgroundColor = 'red' |
| 2315 | + jsCallbackToJava('hellojava') |
| 2316 | + } |
| 2317 | + </script> |
| 2318 | + </head> |
| 2319 | + <body> Going to make a callback to Java </body> |
| 2320 | + </html> |
| 2321 | + """; |
2298 | 2322 |
|
2299 | 2323 | browser.setText(htmlWithScript);
|
2300 | 2324 | new JavascriptCallback(browser, "jsCallbackToJava");
|
@@ -2332,16 +2356,19 @@ public Object function(Object[] arguments) {
|
2332 | 2356 | }
|
2333 | 2357 | }
|
2334 | 2358 |
|
2335 |
| - String htmlWithScript = "<html><head>\n" |
2336 |
| - + "<script language=\"JavaScript\">\n" |
2337 |
| - + "function callCustomFunction() {\n" // Define a javascript function. |
2338 |
| - + " document.body.style.backgroundColor = 'red'\n" |
2339 |
| - + " jsCallbackToJava('hellojava', 5, true)\n" // This calls the javafunction that we registered. |
2340 |
| - + "}" |
2341 |
| - + "</script>\n" |
2342 |
| - + "</head>\n" |
2343 |
| - + "<body> Going to make a callback to Java </body>\n" |
2344 |
| - + "</html>\n"; |
| 2359 | + // Define a javascript function and call it |
| 2360 | + String htmlWithScript = """ |
| 2361 | + <html><head> |
| 2362 | + <script language="JavaScript"> |
| 2363 | + function callCustomFunction() { |
| 2364 | + document.body.style.backgroundColor = 'red' |
| 2365 | + jsCallbackToJava('hellojava', 5, true) |
| 2366 | + } |
| 2367 | + </script> |
| 2368 | + </head> |
| 2369 | + <body> Going to make a callback to Java </body> |
| 2370 | + </html> |
| 2371 | + """; |
2345 | 2372 |
|
2346 | 2373 | browser.setText(htmlWithScript);
|
2347 | 2374 | new JavascriptCallback(browser, "jsCallbackToJava");
|
@@ -2410,19 +2437,21 @@ public Object function(Object[] arguments) {
|
2410 | 2437 | return null;
|
2411 | 2438 | }
|
2412 | 2439 | }
|
2413 |
| - |
2414 |
| - String htmlWithScript = "<html><head>\n" |
2415 |
| - + "<script language=\"JavaScript\">\n" |
2416 |
| - + "function callCustomFunction() {\n" // Define a javascript function. |
2417 |
| - + " document.body.style.backgroundColor = 'red'\n" |
2418 |
| - + " var retVal = jsCallbackToJava()\n" // 2) |
2419 |
| - + " document.write(retVal)\n" // This calls the javafunction that we registered. Set HTML body to return value. |
2420 |
| - + " jsSuccess(retVal)\n" // 3) |
2421 |
| - + "}" |
2422 |
| - + "</script>\n" |
2423 |
| - + "</head>\n" |
2424 |
| - + "<body> If you see this, Javascript did not receive anything from Java. This page should just be '42' </body>\n" |
2425 |
| - + "</html>\n"; |
| 2440 | + // Define a javascript function and call it, return value to be checked in html body |
| 2441 | + String htmlWithScript = """ |
| 2442 | + <html><head> |
| 2443 | + <script language="JavaScript"> |
| 2444 | + function callCustomFunction() { |
| 2445 | + document.body.style.backgroundColor = 'red' |
| 2446 | + var retVal = jsCallbackToJava() |
| 2447 | + document.write(retVal) |
| 2448 | + jsSuccess(retVal) |
| 2449 | + } |
| 2450 | + </script> |
| 2451 | + </head> |
| 2452 | + <body> If you see this, Javascript did not receive anything from Java. This page should just be '42' </body> |
| 2453 | + </html> |
| 2454 | + """; |
2426 | 2455 | // 1)
|
2427 | 2456 | browser.setText(htmlWithScript);
|
2428 | 2457 | new JavascriptCallback(browser, "jsCallbackToJava");
|
|
0 commit comments