Skip to content

Commit 1a03198

Browse files
committed
Convert Browser test strings to test blocks
It's really cumbersome to edit them while experimenting thus converting.
1 parent 4bf1af8 commit 1a03198

File tree

1 file changed

+119
-90
lines changed

1 file changed

+119
-90
lines changed

tests/org.eclipse.swt.tests/JUnit Tests/org/eclipse/swt/tests/junit/Test_org_eclipse_swt_browser_Browser.java

Lines changed: 119 additions & 90 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*******************************************************************************
2-
* Copyright (c) 2000, 2022 IBM Corporation and others.
2+
* Copyright (c) 2000, 2024 IBM Corporation and others.
33
*
44
* This program and the accompanying materials
55
* are made available under the terms of the Eclipse Public License 2.0
@@ -803,8 +803,10 @@ public void test_OpenWindowListener_openHasValidEventDetails() {
803803
});
804804

805805
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+
""");
808810

809811
boolean passed = waitForPassCondition(openFiredCorrectly::get);
810812
assertTrue("Test timed out. OpenWindow event not fired.", passed);
@@ -833,15 +835,17 @@ public void test_OpenWindowListener_open_ChildPopup() {
833835

834836
shell.open();
835837

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>""");
841845

842846
boolean passed = waitForPassCondition(childCompleted::get);
843847

844-
String errMsg = "\nTest timed out.";
848+
String errMsg = "Test timed out.";
845849
assertTrue(errMsg, passed);
846850
}
847851

@@ -880,11 +884,13 @@ public void test_OpenWindow_Progress_Listener_ValidateEventOrder() {
880884

881885
shell.open();
882886

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>""");
888894

889895
boolean passed = waitForPassCondition(() -> windowOpenFired.get() && visibilityShowed.get() && childCompleted.get());
890896

@@ -1323,12 +1329,14 @@ public void completed(ProgressEvent event) {
13231329
});
13241330

13251331
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>""");
13321340

13331341
boolean passed = waitForPassCondition(secondChildCompleted::get);
13341342

@@ -1365,11 +1373,13 @@ public void test_VisibilityWindowListener_eventSize() {
13651373
}));
13661374

13671375
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>""");
13731383

13741384
boolean finishedWithoutTimeout = waitForPassCondition(childCompleted::get);
13751385
browserChild.dispose();
@@ -1720,7 +1730,10 @@ public void test_getText_script() {
17201730
if (SwtTestUtil.isWindows) {
17211731
// Windows' Browser implementation returns the processed HTML rather than the original one.
17221732
// 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>""");
17241737
} else {
17251738
// Linux Webkit1, Webkit2
17261739
// Cocoa
@@ -2154,16 +2167,19 @@ public Object function(Object[] arguments) {
21542167
}
21552168
}
21562169

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+
""";
21672183

21682184
browser.setText(htmlWithScript);
21692185
new JavascriptCallback(browser, "jsCallbackToJava");
@@ -2197,16 +2213,19 @@ public Object function(Object[] arguments) {
21972213
}
21982214
}
21992215

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+
""";
22102229

22112230
browser.setText(htmlWithScript);
22122231
new JavascriptCallback(browser, "jsCallbackToJava");
@@ -2241,17 +2260,19 @@ public Object function(Object[] arguments) {
22412260
return null;
22422261
}
22432262
}
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+
""";
22552276

22562277
browser.setText(htmlWithScript);
22572278
new JavascriptCallback(browser, "jsCallbackToJava");
@@ -2285,16 +2306,19 @@ public Object function(Object[] arguments) {
22852306
}
22862307
}
22872308

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+
""";
22982322

22992323
browser.setText(htmlWithScript);
23002324
new JavascriptCallback(browser, "jsCallbackToJava");
@@ -2332,16 +2356,19 @@ public Object function(Object[] arguments) {
23322356
}
23332357
}
23342358

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+
""";
23452372

23462373
browser.setText(htmlWithScript);
23472374
new JavascriptCallback(browser, "jsCallbackToJava");
@@ -2410,19 +2437,21 @@ public Object function(Object[] arguments) {
24102437
return null;
24112438
}
24122439
}
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+
""";
24262455
// 1)
24272456
browser.setText(htmlWithScript);
24282457
new JavascriptCallback(browser, "jsCallbackToJava");

0 commit comments

Comments
 (0)