Skip to content

Commit f61392c

Browse files
committed
Robustness when running on unsupported configurations
1 parent 8e3acf2 commit f61392c

File tree

5 files changed

+66
-41
lines changed

5 files changed

+66
-41
lines changed

boot-script/src/test/java/net/java/html/boot/script/KnockoutEnvJSTest.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -166,6 +166,8 @@ private static String skipMsg(String methodName) {
166166
return "Does not work on JDK8, due to JDK-8046013";
167167
case "modifyRadioValueOnEnum":
168168
return "Does not work on JDK8";
169+
case "obtainAndComputeTest":
170+
return "Browser doesn't support addEventListener or attachEvent";
169171
}
170172
return null;
171173
}

renderer/src/main/java/org/netbeans/html/presenters/render/Show.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ public static void show(String impl, URI page) throws IOException {
4848
show.show(page);
4949
} catch (IOException ex) {
5050
throw ex;
51-
} catch (Exception ex) {
51+
} catch (LinkageError | Exception ex) {
5252
if (impl == null) {
5353
impl = "xdg-open";
5454
}

webkit/src/test/java/org/netbeans/html/presenters/webkit/Case.java

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,27 +28,33 @@
2828
import org.testng.IHookable;
2929
import org.testng.ITest;
3030
import org.testng.ITestResult;
31+
import org.testng.SkipException;
3132
import org.testng.annotations.Test;
3233

3334
public final class Case implements ITest, IHookable, Runnable {
3435
private static final Timer T = new Timer("Interrupted Exception Handler");
3536
private final Fn.Presenter p;
3637
private final Method m;
38+
private final String skipMsg;
3739
private Object result;
3840
private Object inst;
3941

40-
Case(Fn.Presenter p, Method m) {
42+
Case(Fn.Presenter p, Method m, String skipMsg) {
4143
this.p = p;
4244
this.m = m;
45+
this.skipMsg = skipMsg;
4346
}
4447

4548
@Override
4649
public String getTestName() {
47-
return m.getName();
50+
return m != null ? m.getName() : skipMsg;
4851
}
4952

5053
@Test
5154
public synchronized void executeTest() throws Exception {
55+
if (skipMsg != null) {
56+
throw new SkipException(skipMsg);
57+
}
5258
if (result == null) {
5359
Executor exec = (Executor) p;
5460
exec.execute(this);

webkit/src/test/java/org/netbeans/html/presenters/webkit/GtkJavaScriptTest.java

Lines changed: 23 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -46,22 +46,31 @@ public GtkJavaScriptTest() {
4646
}
4747

4848
@Factory public static Object[] compatibilityTests() throws Exception {
49+
String skipMsg = null;
4950
Runnable onPageLoaded = GtkJavaScriptTest::initialized;
5051

51-
// BEGIN: org.netbeans.html.presenters.webkit.GtkJavaScriptTest
52-
final WebKitPresenter headlessPresenter = new WebKitPresenter(true);
53-
final BrowserBuilder bb = BrowserBuilder.newBrowser(headlessPresenter).
54-
loadFinished(onPageLoaded).
55-
loadPage("empty.html");
56-
// END: org.netbeans.html.presenters.webkit.GtkJavaScriptTest
52+
Future<Void> future;
53+
try {
54+
// BEGIN: org.netbeans.html.presenters.webkit.GtkJavaScriptTest
55+
final WebKitPresenter headlessPresenter = new WebKitPresenter(true);
56+
final BrowserBuilder bb = BrowserBuilder.newBrowser(headlessPresenter).
57+
loadFinished(onPageLoaded).
58+
loadPage("empty.html");
59+
// END: org.netbeans.html.presenters.webkit.GtkJavaScriptTest
5760

58-
Future<Void> future = Executors.newSingleThreadExecutor().submit(new Callable<Void>() {
59-
@Override
60-
public Void call() throws Exception {
61-
bb.showAndWait();
62-
return null;
63-
}
64-
});
61+
future = Executors.newSingleThreadExecutor().submit(new Callable<Void>() {
62+
@Override
63+
public Void call() throws Exception {
64+
bb.showAndWait();
65+
return null;
66+
}
67+
});
68+
} catch (LinkageError err) {
69+
err.printStackTrace();
70+
return new Object[] {
71+
new Case(null, null, err.getMessage())
72+
};
73+
}
6574

6675
List<Object> res = new ArrayList<>();
6776
try {
@@ -78,7 +87,7 @@ public Void call() throws Exception {
7887
for (Class c : arr) {
7988
for (Method m : c.getMethods()) {
8089
if (m.getAnnotation(test) != null) {
81-
res.add(new Case(browserPresenter, m));
90+
res.add(new Case(browserPresenter, m, null));
8291
}
8392
}
8493
}

webkit/src/test/java/org/netbeans/html/presenters/webkit/GtkKnockoutTest.java

Lines changed: 32 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -58,10 +58,10 @@ public final class GtkKnockoutTest extends KnockoutTCK {
5858
private static Class<?> browserClass;
5959
private static Fn.Presenter browserContext;
6060
private static final Timeout WATCHER = new Timeout(60000);
61-
61+
6262
public GtkKnockoutTest() {
6363
}
64-
64+
6565
@Factory public static Object[] compatibilityTests() throws Exception {
6666
Class[] arr = testClasses();
6767
for (int i = 0; i < arr.length; i++) {
@@ -70,22 +70,30 @@ public GtkKnockoutTest() {
7070
"All classes loaded by the same classloader"
7171
);
7272
}
73-
73+
7474
URI uri = DynamicHTTP.initServer();
75-
76-
final BrowserBuilder bb = BrowserBuilder.newBrowser(
77-
new WebKitPresenter(true)
78-
).loadClass(GtkKnockoutTest.class).
79-
loadPage(uri.toString()).
80-
invoke("initialized");
81-
82-
Future<Void> future = Executors.newSingleThreadExecutor().submit(new Callable<Void>() {
83-
@Override
84-
public Void call() {
85-
bb.showAndWait();
86-
return null;
87-
}
88-
});
75+
76+
Future<Void> future;
77+
try {
78+
final BrowserBuilder bb = BrowserBuilder.newBrowser(
79+
new WebKitPresenter(true)
80+
).loadClass(GtkKnockoutTest.class).
81+
loadPage(uri.toString()).
82+
invoke("initialized");
83+
84+
future = Executors.newSingleThreadExecutor().submit(new Callable<Void>() {
85+
@Override
86+
public Void call() {
87+
bb.showAndWait();
88+
return null;
89+
}
90+
});
91+
} catch (LinkageError err) {
92+
err.printStackTrace();
93+
return new Object[]{
94+
new Case(null, null, err.getMessage())
95+
};
96+
}
8997

9098
List<Object> res = new ArrayList<>();
9199
try {
@@ -116,7 +124,7 @@ private static void seekKOTests(Class<?> c, List<Object> res) throws SecurityExc
116124
asSubclass(Annotation.class);
117125
for (Method m : c.getMethods()) {
118126
if (m.getAnnotation(koTest) != null) {
119-
res.add(new Case(browserContext, m));
127+
res.add(new Case(browserContext, m, null));
120128
}
121129
}
122130
}
@@ -127,13 +135,13 @@ static synchronized ClassLoader getClassLoader() throws InterruptedException {
127135
}
128136
return browserClass.getClassLoader();
129137
}
130-
138+
131139
public static synchronized void initialized(Class<?> browserCls) throws Exception {
132140
browserClass = browserCls;
133141
browserContext = Fn.activePresenter();
134142
GtkKnockoutTest.class.notifyAll();
135143
}
136-
144+
137145
public static void initialized() throws Exception {
138146
Assert.assertSame(GtkKnockoutTest.class.getClassLoader(),
139147
ClassLoader.getSystemClassLoader(),
@@ -142,7 +150,7 @@ public static void initialized() throws Exception {
142150
GtkKnockoutTest.initialized(GtkKnockoutTest.class);
143151
browserContext = Fn.activePresenter();
144152
}
145-
153+
146154
@Override
147155
public BrwsrCtx createContext() {
148156
KO4J ko4j = new KO4J();
@@ -166,7 +174,7 @@ public Object createJSON(Map<String, Object> values) {
166174
}
167175
return json;
168176
}
169-
177+
170178
@JavaScriptBody(args = {}, body = "return new Object();")
171179
private static native Object createJSON();
172180
@JavaScriptBody(args = { "json", "key", "value" }, body = "json[key] = value;")
@@ -179,7 +187,7 @@ public Object createJSON(Map<String, Object> values) {
179187
)
180188
public native Object executeScript(String script, Object[] arguments);
181189

182-
@JavaScriptBody(args = { }, body =
190+
@JavaScriptBody(args = { }, body =
183191
"var h;"
184192
+ "if (!!window && !!window.location && !!window.location.href)\n"
185193
+ " h = window.location.href;\n"
@@ -188,7 +196,7 @@ public Object createJSON(Map<String, Object> values) {
188196
+ "return h;\n"
189197
)
190198
private static native String findBaseURL();
191-
199+
192200
@Override
193201
public URI prepareURL(String content, String mimeType, String[] parameters) {
194202
try {

0 commit comments

Comments
 (0)