Skip to content

Commit a9d70fd

Browse files
committed
Fixed CI and tests
1 parent 6e27a6d commit a9d70fd

File tree

8 files changed

+478
-86
lines changed

8 files changed

+478
-86
lines changed

.github/workflows/javase-cef-ffmpeg-smoke.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
name: JavaSE CEF/FFmpeg Smoke
22

3+
permissions:
4+
contents: read
5+
36
on:
47
pull_request:
58
paths:

maven/tests/javase-cef-ffmpeg-smoke/codenameone_settings.properties renamed to maven/tests/javase-cef-ffmpeg-smoke/common/codenameone_settings.properties

File renamed without changes.
Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<project xmlns="http://maven.apache.org/POM/4.0.0"
3+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
4+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
5+
<modelVersion>4.0.0</modelVersion>
6+
7+
<parent>
8+
<groupId>com.codenameone.tests</groupId>
9+
<artifactId>javase-cef-ffmpeg-smoke</artifactId>
10+
<version>8.0-SNAPSHOT</version>
11+
<relativePath>..</relativePath>
12+
</parent>
13+
14+
<groupId>com.codenameone.tests</groupId>
15+
<artifactId>javase-cef-ffmpeg-smoke-common</artifactId>
16+
<version>8.0-SNAPSHOT</version>
17+
<packaging>jar</packaging>
18+
19+
<dependencies>
20+
<dependency>
21+
<groupId>com.codenameone</groupId>
22+
<artifactId>codenameone-core</artifactId>
23+
</dependency>
24+
<dependency>
25+
<groupId>com.codenameone</groupId>
26+
<artifactId>codenameone-javase</artifactId>
27+
<scope>test</scope>
28+
</dependency>
29+
</dependencies>
30+
31+
<build>
32+
<plugins>
33+
<plugin>
34+
<groupId>org.apache.maven.plugins</groupId>
35+
<artifactId>maven-compiler-plugin</artifactId>
36+
<configuration>
37+
<source>1.8</source>
38+
<target>1.8</target>
39+
</configuration>
40+
</plugin>
41+
<plugin>
42+
<groupId>org.codehaus.mojo</groupId>
43+
<artifactId>properties-maven-plugin</artifactId>
44+
<version>1.0.0</version>
45+
<executions>
46+
<execution>
47+
<phase>initialize</phase>
48+
<goals>
49+
<goal>read-project-properties</goal>
50+
</goals>
51+
<configuration>
52+
<files>
53+
<file>${basedir}/codenameone_settings.properties</file>
54+
</files>
55+
</configuration>
56+
</execution>
57+
</executions>
58+
</plugin>
59+
<plugin>
60+
<groupId>com.codenameone</groupId>
61+
<artifactId>codenameone-maven-plugin</artifactId>
62+
<executions>
63+
<execution>
64+
<id>cn1-process-classes</id>
65+
<phase>process-classes</phase>
66+
<goals>
67+
<goal>css</goal>
68+
</goals>
69+
</execution>
70+
</executions>
71+
</plugin>
72+
</plugins>
73+
</build>
74+
75+
<profiles>
76+
<profile>
77+
<id>simulator</id>
78+
<properties>
79+
<codename1.targetPlatform>javase</codename1.targetPlatform>
80+
</properties>
81+
</profile>
82+
</profiles>
83+
</project>

maven/tests/javase-cef-ffmpeg-smoke/src/main/java/com/codenameone/tests/javase/CefFfmpegSmoke.java renamed to maven/tests/javase-cef-ffmpeg-smoke/common/src/main/java/com/codenameone/tests/javase/CefFfmpegSmoke.java

Lines changed: 96 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,29 +14,40 @@
1414
import com.codename1.ui.Form;
1515
import com.codename1.ui.Image;
1616
import com.codename1.ui.Label;
17+
import com.codename1.ui.Toolbar;
1718
import com.codename1.ui.layouts.BorderLayout;
1819
import com.codename1.ui.layouts.GridLayout;
1920
import com.codename1.ui.plaf.Style;
2021
import com.codename1.ui.util.ImageIO;
2122
import com.codename1.ui.util.UITimer;
2223
import java.io.IOException;
2324
import java.io.OutputStream;
25+
import java.lang.reflect.Field;
26+
import java.lang.reflect.Method;
2427

2528
public class CefFfmpegSmoke extends Lifecycle {
2629
private static final String SCREENSHOT_NAME = "cef-ffmpeg-smoke.png";
2730
private static final String STATUS_NAME = "cef-ffmpeg-smoke-status.txt";
28-
private static final int CAPTURE_DELAY_MS = 1500;
31+
private static final int CAPTURE_DELAY_MS = 3000;
2932
private static final int FALLBACK_TIMEOUT_MS = 12000;
3033

3134
private Form current;
3235
private Media media;
3336
private boolean browserLoaded;
37+
private boolean browserJsVerified;
38+
private String browserColor = "";
39+
private String browserReadyState = "";
40+
private boolean cefLoaded;
41+
private String displayImplementationClass = "";
42+
private String browserPeerClass = "";
43+
private boolean browserPeerReady;
3444
private boolean captureScheduled;
3545
private boolean captured;
3646

3747
@Override
3848
public void init(Object context) {
39-
super.init(context);
49+
CN.updateNetworkThreadCount(2);
50+
Toolbar.setGlobalToolbar(true);
4051
Display.getInstance().setProperty("BrowserComponent.useCEF", "true");
4152
}
4253

@@ -70,8 +81,7 @@ public void start() {
7081
browser.setPreferredW(320);
7182
browser.setPreferredH(240);
7283
browser.addWebEventListener(BrowserComponent.onLoad, evt -> {
73-
browserLoaded = true;
74-
maybeScheduleCapture(form);
84+
probeBrowser(browser, form);
7585
});
7686
browser.setPage("<html><body style='margin:0;background:#00ff00;'></body></html>", null);
7787

@@ -95,6 +105,17 @@ public void start() {
95105
current = form;
96106
form.show();
97107

108+
final UITimer[] browserProbe = new UITimer[1];
109+
browserProbe[0] = UITimer.timer(500, true, form, () -> {
110+
if (captured) {
111+
browserProbe[0].cancel();
112+
return;
113+
}
114+
if (probeBrowser(browser, form)) {
115+
browserProbe[0].cancel();
116+
}
117+
});
118+
98119
UITimer.timer(300, false, form, () -> {
99120
try {
100121
if (media != null) {
@@ -134,11 +155,11 @@ public void destroy() {
134155
}
135156

136157
private void maybeScheduleCapture(Form form) {
137-
if (captureScheduled || captured || !browserLoaded || media == null) {
158+
if (captureScheduled || captured || !browserPeerReady || media == null) {
138159
return;
139160
}
140161
captureScheduled = true;
141-
UITimer.timer(CAPTURE_DELAY_MS, false, form, () -> captureAndExit("browser-loaded"));
162+
UITimer.timer(CAPTURE_DELAY_MS, false, form, () -> captureAndExit("browser-peer-ready"));
142163
}
143164

144165
private void captureAndExit(String reason) {
@@ -147,7 +168,14 @@ private void captureAndExit(String reason) {
147168
}
148169
captured = true;
149170
writeStatus("captureReason=" + reason + "\n" +
171+
"cefLoaded=" + cefLoaded + "\n" +
172+
"displayImplementationClass=" + displayImplementationClass + "\n" +
173+
"browserPeerClass=" + browserPeerClass + "\n" +
174+
"browserPeerReady=" + browserPeerReady + "\n" +
150175
"browserLoaded=" + browserLoaded + "\n" +
176+
"browserJsVerified=" + browserJsVerified + "\n" +
177+
"browserReadyState=" + browserReadyState + "\n" +
178+
"browserColor=" + browserColor + "\n" +
151179
"mediaImplementation=" + System.getProperty("cn1.javase.mediaImplementation", "") + "\n" +
152180
"browserImplementation=" + System.getProperty("cn1.javase.implementation", "") + "\n");
153181
Display.getInstance().screenshot(img -> {
@@ -197,6 +225,68 @@ private void writeStatus(String text) {
197225
}
198226
}
199227

228+
private boolean probeBrowser(BrowserComponent browser, Form form) {
229+
inspectBrowserBackend(browser);
230+
try {
231+
browserReadyState = browser.executeAndReturnString("document.readyState");
232+
browserColor = browser.executeAndReturnString("window.getComputedStyle(document.body).backgroundColor");
233+
browserLoaded = browserReadyState != null && browserReadyState.length() > 0;
234+
browserJsVerified = browserColor != null && browserColor.indexOf("0, 255, 0") >= 0;
235+
if (browserLoaded || browserPeerReady) {
236+
maybeScheduleCapture(form);
237+
}
238+
return browserLoaded;
239+
} catch (RuntimeException ex) {
240+
browserReadyState = "error:" + ex.getMessage();
241+
browserColor = "";
242+
browserJsVerified = false;
243+
if (browserPeerReady) {
244+
maybeScheduleCapture(form);
245+
}
246+
return false;
247+
}
248+
}
249+
250+
private void inspectBrowserBackend(BrowserComponent browser) {
251+
cefLoaded = isCefLoaded();
252+
displayImplementationClass = getDisplayImplementationClass();
253+
browserPeerClass = getBrowserPeerClass(browser);
254+
browserPeerReady = browserPeerClass.length() > 0;
255+
}
256+
257+
private boolean isCefLoaded() {
258+
try {
259+
Class<?> cls = Class.forName("com.codename1.impl.javase.CN1Bootstrap");
260+
Method m = cls.getMethod("isCEFLoaded");
261+
Object out = m.invoke(null);
262+
return Boolean.TRUE.equals(out);
263+
} catch (Throwable ex) {
264+
return false;
265+
}
266+
}
267+
268+
private String getDisplayImplementationClass() {
269+
try {
270+
Method m = Display.class.getDeclaredMethod("getImplementation");
271+
m.setAccessible(true);
272+
Object impl = m.invoke(Display.getInstance());
273+
return impl == null ? "" : impl.getClass().getName();
274+
} catch (Throwable ex) {
275+
return "error:" + ex.getClass().getName();
276+
}
277+
}
278+
279+
private String getBrowserPeerClass(BrowserComponent browser) {
280+
try {
281+
Field f = BrowserComponent.class.getDeclaredField("internal");
282+
f.setAccessible(true);
283+
Object peer = f.get(browser);
284+
return peer == null ? "" : peer.getClass().getName();
285+
} catch (Throwable ex) {
286+
return "error:" + ex.getClass().getName();
287+
}
288+
}
289+
200290
private String getAppHomePath() {
201291
return FileSystemStorage.getInstance().getAppHomePath();
202292
}
Lines changed: 131 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,131 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<project xmlns="http://maven.apache.org/POM/4.0.0"
3+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
4+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
5+
<modelVersion>4.0.0</modelVersion>
6+
7+
<parent>
8+
<groupId>com.codenameone.tests</groupId>
9+
<artifactId>javase-cef-ffmpeg-smoke</artifactId>
10+
<version>8.0-SNAPSHOT</version>
11+
<relativePath>..</relativePath>
12+
</parent>
13+
14+
<groupId>com.codenameone.tests</groupId>
15+
<artifactId>javase-cef-ffmpeg-smoke-javase</artifactId>
16+
<version>8.0-SNAPSHOT</version>
17+
18+
<properties>
19+
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
20+
<maven.compiler.source>1.8</maven.compiler.source>
21+
<maven.compiler.target>1.8</maven.compiler.target>
22+
<codename1.platform>javase</codename1.platform>
23+
<codename1.projectPlatform>javase</codename1.projectPlatform>
24+
</properties>
25+
26+
<build>
27+
<plugins>
28+
<plugin>
29+
<groupId>com.codenameone</groupId>
30+
<artifactId>codenameone-maven-plugin</artifactId>
31+
<executions>
32+
<execution>
33+
<id>add-se-sources</id>
34+
<phase>generate-sources</phase>
35+
<goals>
36+
<goal>generate-javase-sources</goal>
37+
</goals>
38+
</execution>
39+
</executions>
40+
</plugin>
41+
</plugins>
42+
</build>
43+
44+
<dependencies>
45+
<dependency>
46+
<groupId>${project.groupId}</groupId>
47+
<artifactId>${cn1app.name}-common</artifactId>
48+
<version>${project.version}</version>
49+
</dependency>
50+
<dependency>
51+
<groupId>com.codenameone</groupId>
52+
<artifactId>codenameone-core</artifactId>
53+
<scope>provided</scope>
54+
</dependency>
55+
<dependency>
56+
<groupId>com.codenameone</groupId>
57+
<artifactId>codenameone-javase</artifactId>
58+
<scope>provided</scope>
59+
</dependency>
60+
</dependencies>
61+
62+
<profiles>
63+
<profile>
64+
<id>simulator</id>
65+
<properties>
66+
<codename1.platform>javase</codename1.platform>
67+
<exec.mainClass>com.codename1.impl.javase.Simulator</exec.mainClass>
68+
</properties>
69+
<dependencies>
70+
<dependency>
71+
<groupId>com.codenameone</groupId>
72+
<artifactId>codenameone-core</artifactId>
73+
<scope>compile</scope>
74+
</dependency>
75+
<dependency>
76+
<groupId>com.codenameone</groupId>
77+
<artifactId>codenameone-javase</artifactId>
78+
<scope>compile</scope>
79+
</dependency>
80+
</dependencies>
81+
<build>
82+
<plugins>
83+
<plugin>
84+
<groupId>com.codenameone</groupId>
85+
<artifactId>codenameone-maven-plugin</artifactId>
86+
<executions>
87+
<execution>
88+
<id>prepare-simulator-environment</id>
89+
<phase>initialize</phase>
90+
<goals>
91+
<goal>prepare-simulator-classpath</goal>
92+
</goals>
93+
</execution>
94+
</executions>
95+
</plugin>
96+
<plugin>
97+
<groupId>org.codehaus.mojo</groupId>
98+
<artifactId>exec-maven-plugin</artifactId>
99+
<configuration>
100+
<workingDirectory>${basedir}/../common</workingDirectory>
101+
<executable>java</executable>
102+
<longClasspath>true</longClasspath>
103+
<arguments>
104+
<argument>-Xmx1024M</argument>
105+
<argument>-Dcef.dir=${cef.dir}</argument>
106+
<argument>-Dffmpeg.dir=${ffmpeg.dir}</argument>
107+
<argument>-Dcn1.test.video=${cn1.test.video}</argument>
108+
<argument>-Dcodename1.designer.jar=${codename1.designer.jar}</argument>
109+
<argument>${codename1.exec.args.debug}</argument>
110+
<argument>${codename1.exec.args.runjdwp.transport}</argument>
111+
<argument>-classpath</argument>
112+
<classpath />
113+
<argument>${exec.mainClass}</argument>
114+
<argument>${codename1.mainClass}</argument>
115+
</arguments>
116+
</configuration>
117+
<executions>
118+
<execution>
119+
<id>run-in-simulator</id>
120+
<phase>verify</phase>
121+
<goals>
122+
<goal>exec</goal>
123+
</goals>
124+
</execution>
125+
</executions>
126+
</plugin>
127+
</plugins>
128+
</build>
129+
</profile>
130+
</profiles>
131+
</project>

0 commit comments

Comments
 (0)