Skip to content

Commit 8d5c21b

Browse files
committed
Refactor chrome laucher; Add tests
1 parent 0b0ce55 commit 8d5c21b

File tree

17 files changed

+1206
-191
lines changed

17 files changed

+1206
-191
lines changed

cdtp-java-client/Makefile

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,13 @@ MVN=mvn
33

44
SONAR_HOST=http://localhost:9999
55

6+
SONAR_COVERAGE_EXCLUSIONS="**/com/github/kklisura/cdtp/protocol/**/*,**/com/github/kklisura/cdtp/App.java"
7+
68
sonar-analysis:
79
# Running sonar analysis
8-
$(MVN) clean test && $(MVN) sonar:sonar -Dsonar.host.url=$(SONAR_HOST) \
10+
$(MVN) clean test && \
11+
$(MVN) org.jacoco:jacoco-maven-plugin:restore-instrumented-classes
12+
$(MVN) sonar:sonar -Dsonar.host.url=$(SONAR_HOST) \
913
-Dsonar.tests="src/test" \
10-
-Dsonar.exclusions="**/com/github/kklisura/cdtp/protocol/**/*" \
11-
-Dsonar.coverage.exclusions="**/com/github/kklisura/cdtp/protocol/**/*"
14+
-Dsonar.exclusions="$(SONAR_COVERAGE_EXCLUSIONS)" \
15+
-Dsonar.coverage.exclusions="$(SONAR_COVERAGE_EXCLUSIONS)"

cdtp-java-client/THIRD-PARTY.txt

Lines changed: 9 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
11

2-
Lists of 77 third-party dependencies.
3-
(Public Domain) Backport of JSR 166 (backport-util-concurrent:backport-util-concurrent:3.1 - http://backport-jsr166.sourceforge.net/)
2+
Lists of 37 third-party dependencies.
3+
(ASF 2.0) Code Generation Library (cglib:cglib-nodep:2.2.2 - http://cglib.sourceforge.net/)
44
(Eclipse Public License v1.0) (GNU Lesser General Public License) Logback Classic Module (ch.qos.logback:logback-classic:1.2.3 - http://logback.qos.ch/logback-classic)
55
(Eclipse Public License v1.0) (GNU Lesser General Public License) Logback Core Module (ch.qos.logback:logback-core:1.2.3 - http://logback.qos.ch/logback-core)
6-
(The Apache Software License, Version 2.0) classworlds (classworlds:classworlds:1.1-alpha-2 - http://classworlds.codehaus.org/)
76
(The Apache Software License, Version 2.0) Jackson-annotations (com.fasterxml.jackson.core:jackson-annotations:2.9.3 - http://github.com/FasterXML/jackson)
87
(The Apache Software License, Version 2.0) Jackson-core (com.fasterxml.jackson.core:jackson-core:2.9.3 - https://github.com/FasterXML/jackson-core)
98
(The Apache Software License, Version 2.0) jackson-databind (com.fasterxml.jackson.core:jackson-databind:2.9.3 - http://github.com/FasterXML/jackson)
@@ -12,44 +11,9 @@ Lists of 77 third-party dependencies.
1211
(The Apache Software License, Version 2.0) OkHttp Web Sockets (com.squareup.okhttp:okhttp-ws:2.7.5 - https://github.com/square/okhttp/okhttp-ws)
1312
(The Apache Software License, Version 2.0) Okio (com.squareup.okio:okio:1.6.0 - https://github.com/square/okio/okio)
1413
(The Apache Software License, Version 2.0) JSON library from Android SDK (com.vaadin.external.google:android-json:0.0.20131108.vaadin1 - http://developer.android.com/sdk)
15-
(The Apache Software License, Version 2.0) commons-beanutils (commons-beanutils:commons-beanutils:1.7.0 - no url defined)
16-
(The Apache Software License, Version 2.0) Codec (commons-codec:commons-codec:1.2 - no url defined)
17-
(The Apache Software License, Version 2.0) Collections (commons-collections:commons-collections:3.2 - http://jakarta.apache.org/commons/collections/)
18-
(The Apache Software License, Version 2.0) commons-digester (commons-digester:commons-digester:1.6 - no url defined)
19-
(The Apache Software License, Version 2.0) HttpClient (commons-httpclient:commons-httpclient:3.1 - http://jakarta.apache.org/httpcomponents/httpclient-3.x/)
20-
(The Apache Software License, Version 2.0) Commons Lang (commons-lang:commons-lang:2.4 - http://commons.apache.org/lang/)
21-
(The Apache Software License, Version 2.0) Logging (commons-logging:commons-logging:1.0.4 - http://jakarta.apache.org/commons/logging/)
22-
(The Apache Software License, Version 2.0) Validator (commons-validator:commons-validator:1.2.0 - http://jakarta.apache.org/commons/${pom.artifactId.substring(8)}/)
2314
(Dual license consisting of the CDDL v1.1 and GPL v2) WebSocket server API (javax.websocket:javax.websocket-api:1.1 - http://websocket-spec.java.net)
2415
(Eclipse Public License v1.0) JUnit (junit:junit:4.12 - http://junit.org)
25-
(The Apache Software License, Version 2.0) Maven Artifact (org.apache.maven:maven-artifact:2.2.1 - http://maven.apache.org/maven-artifact)
26-
(The Apache Software License, Version 2.0) Maven Artifact Manager (org.apache.maven:maven-artifact-manager:2.2.1 - http://maven.apache.org/maven-artifact-manager)
27-
(The Apache Software License, Version 2.0) Maven Model (org.apache.maven:maven-model:2.2.1 - http://maven.apache.org/maven-model)
28-
(The Apache Software License, Version 2.0) Maven Plugin API (org.apache.maven:maven-plugin-api:2.2.1 - http://maven.apache.org/maven-plugin-api)
29-
(The Apache Software License, Version 2.0) Maven Plugin Registry Model (org.apache.maven:maven-plugin-registry:2.2.1 - http://maven.apache.org/maven-plugin-registry)
30-
(The Apache Software License, Version 2.0) Maven Profile Model (org.apache.maven:maven-profile:2.2.1 - http://maven.apache.org/maven-profile)
31-
(The Apache Software License, Version 2.0) Maven Project Builder (org.apache.maven:maven-project:2.2.1 - http://maven.apache.org/maven-project)
32-
(The Apache Software License, Version 2.0) Maven Repository Metadata Model (org.apache.maven:maven-repository-metadata:2.2.1 - http://maven.apache.org/maven-repository-metadata)
33-
(The Apache Software License, Version 2.0) Maven Local Settings Model (org.apache.maven:maven-settings:2.2.1 - http://maven.apache.org/maven-settings)
34-
(The Apache Software License, Version 2.0) Doxia :: Core (org.apache.maven.doxia:doxia-core:1.1.2 - http://maven.apache.org/doxia/doxia/doxia-core)
35-
(The Apache Software License, Version 2.0) Doxia Sitetools :: Decoration Model (org.apache.maven.doxia:doxia-decoration-model:1.1.2 - http://maven.apache.org/doxia/doxia-sitetools/doxia-decoration-model)
36-
(The Apache Software License, Version 2.0) Doxia :: Logging API (org.apache.maven.doxia:doxia-logging-api:1.1 - http://maven.apache.org/doxia/doxia/doxia-logging-api)
37-
(The Apache Software License, Version 2.0) Doxia :: FML Module (org.apache.maven.doxia:doxia-module-fml:1.1.2 - http://maven.apache.org/doxia/doxia/doxia-modules/doxia-module-fml)
38-
(The Apache Software License, Version 2.0) Doxia :: XHTML Module (org.apache.maven.doxia:doxia-module-xhtml:1.1.2 - http://maven.apache.org/doxia/doxia/doxia-modules/doxia-module-xhtml)
39-
(The Apache Software License, Version 2.0) Doxia :: Sink API (org.apache.maven.doxia:doxia-sink-api:1.1 - http://maven.apache.org/doxia/doxia/doxia-sink-api)
40-
(The Apache Software License, Version 2.0) Doxia Sitetools :: Site Renderer Component (org.apache.maven.doxia:doxia-site-renderer:1.1.2 - http://maven.apache.org/doxia/doxia-sitetools/doxia-site-renderer)
41-
(The Apache Software License, Version 2.0) Maven Reporting API (org.apache.maven.reporting:maven-reporting-api:2.2.1 - http://maven.apache.org/maven-reporting/maven-reporting-api)
42-
(The Apache Software License, Version 2.0) Maven Reporting Implementation (org.apache.maven.reporting:maven-reporting-impl:2.1 - http://maven.apache.org/shared/maven-reporting-impl/)
43-
(The Apache Software License, Version 2.0) Maven File Management API (org.apache.maven.shared:file-management:1.2.1 - http://maven.apache.org/shared/file-management/)
44-
(The Apache Software License, Version 2.0) Maven Shared I/O API (org.apache.maven.shared:maven-shared-io:1.1 - http://maven.apache.org/shared/maven-shared-io/)
45-
(The Apache Software License, Version 2.0) Maven Wagon API (org.apache.maven.wagon:wagon-provider-api:1.0-beta-6 - http://maven.apache.org/wagon/wagon-provider-api)
46-
(The Apache Software License, Version 2.0) Apache Velocity (org.apache.velocity:velocity:1.5 - http://velocity.apache.org/engine/releases/velocity-1.5/)
4716
(Bouncy Castle Licence) Bouncy Castle Provider (org.bouncycastle:bcprov-jdk15on:1.50 - http://www.bouncycastle.org/java.html)
48-
(The Apache Software License, Version 2.0) Default Plexus Container (org.codehaus.plexus:plexus-container-default:1.0-alpha-9-stable-1 - no url defined)
49-
(The Apache Software License, Version 2.0) Plexus I18N Component (org.codehaus.plexus:plexus-i18n:1.0-beta-7 - http://plexus.codehaus.org/plexus-components/plexus-i18n)
50-
(The Apache Software License, Version 2.0) Plexus Interpolation API (org.codehaus.plexus:plexus-interpolation:1.11 - http://plexus.codehaus.org/plexus-components/plexus-interpolation)
51-
(The Apache Software License, Version 2.0) Plexus Common Utilities (org.codehaus.plexus:plexus-utils:3.0.22 - http://plexus.codehaus.org/plexus-utils)
52-
(The Apache Software License, Version 2.0) Plexus Velocity Component (org.codehaus.plexus:plexus-velocity:1.1.7 - http://plexus.codehaus.org/plexus-components/plexus-velocity)
5317
(The Apache Software License, Version 2.0) EasyMock (org.easymock:easymock:3.4 - http://easymock.org/easymock)
5418
(Dual license consisting of the CDDL v1.1 and GPL v2) grizzly-framework (org.glassfish.grizzly:grizzly-framework:2.3.25 - http://grizzly.java.net/grizzly-framework)
5519
(Dual license consisting of the CDDL v1.1 and GPL v2) grizzly-http (org.glassfish.grizzly:grizzly-http:2.3.25 - http://grizzly.java.net/grizzly-http)
@@ -61,19 +25,15 @@ Lists of 77 third-party dependencies.
6125
(Dual license consisting of the CDDL v1.1 and GPL v2) Tyrus Server (org.glassfish.tyrus:tyrus-server:1.13.1 - https://tyrus.java.net/tyrus-server)
6226
(Dual license consisting of the CDDL v1.1 and GPL v2) Tyrus Container SPI (org.glassfish.tyrus:tyrus-spi:1.13.1 - https://tyrus.java.net/tyrus-spi)
6327
(BSD 3-Clause License) Hamcrest Core (org.hamcrest:hamcrest-core:1.3 - https://github.com/hamcrest/JavaHamcrest/hamcrest-core)
64-
(Eclipse Public License v1.0) JaCoCo :: Maven Plugin (org.jacoco:jacoco-maven-plugin:0.8.0 - http://jacoco-maven-plugin)
6528
(Eclipse Public License v1.0) JaCoCo :: Agent (org.jacoco:org.jacoco.agent:0.8.0 - http://org.jacoco.agent)
66-
(Eclipse Public License v1.0) JaCoCo :: Core (org.jacoco:org.jacoco.core:0.8.0 - http://org.jacoco.core)
67-
(Eclipse Public License v1.0) JaCoCo :: Report (org.jacoco:org.jacoco.report:0.8.0 - http://org.jacoco.report)
6829
(LGPL 2.1) (MPL 1.1) (The Apache Software License, Version 2.0) Javassist (org.javassist:javassist:3.22.0-GA - http://www.javassist.org/)
6930
(The Apache Software License, Version 2.0) Objenesis (org.objenesis:objenesis:2.2 - http://objenesis.org)
70-
(BSD 3-Clause License) ASM Core (org.ow2.asm:asm:6.0 - http://asm.objectweb.org/asm/)
71-
(BSD 3-Clause License) ASM Analysis (org.ow2.asm:asm-analysis:6.0 - http://asm.objectweb.org/asm-analysis/)
72-
(BSD 3-Clause License) ASM Commons (org.ow2.asm:asm-commons:6.0 - http://asm.objectweb.org/asm-commons/)
73-
(BSD 3-Clause License) ASM Tree (org.ow2.asm:asm-tree:6.0 - http://asm.objectweb.org/asm-tree/)
74-
(BSD 3-Clause License) ASM Util (org.ow2.asm:asm-util:6.0 - http://asm.objectweb.org/asm-util/)
31+
(The Apache Software License, Version 2.0) powermock-api-easymock (org.powermock:powermock-api-easymock:1.6.6 - http://www.powermock.org/powermock-api/powermock-api-easymock)
32+
(The Apache Software License, Version 2.0) powermock-api-support (org.powermock:powermock-api-support:1.6.6 - http://www.powermock.org/powermock-api/powermock-api-support)
33+
(The Apache Software License, Version 2.0) powermock-core (org.powermock:powermock-core:1.6.6 - http://www.powermock.org)
34+
(The Apache Software License, Version 2.0) powermock-module-junit4 (org.powermock:powermock-module-junit4:1.6.6 - http://www.powermock.org)
35+
(The Apache Software License, Version 2.0) powermock-module-junit4-common (org.powermock:powermock-module-junit4-common:1.6.6 - http://www.powermock.org/powermock-modules/powermock-module-junit4-common)
36+
(The Apache Software License, Version 2.0) powermock-module-test-easymock-junit4 (org.powermock:powermock-module-test-easymock-junit4:1.6.6 - http://www.powermock.org/powermock-modules-test/powermock-modules-easymock-test/powermock-module-test-easymock-junit4)
37+
(The Apache Software License, Version 2.0) powermock-reflect (org.powermock:powermock-reflect:1.6.6 - http://www.powermock.org/powermock-reflect)
7538
(The Apache Software License, Version 2.0) JSONassert (org.skyscreamer:jsonassert:1.5.0 - https://github.com/skyscreamer/JSONassert)
7639
(MIT License) SLF4J API Module (org.slf4j:slf4j-api:1.7.25 - http://www.slf4j.org)
77-
(The Apache Software License, Version 1.1) oro (oro:oro:2.0.8 - no url defined)
78-
(The Apache Software License, Version 2.0) Xerces2 Java Parser (xerces:xercesImpl:2.8.1 - http://xerces.apache.org/xerces2-j/)
79-
(The Apache Software License, Version 2.0) XML Commons External Components XML APIs (xml-apis:xml-apis:1.0.b2 - http://xml.apache.org/commons/#external)

cdtp-java-client/pom.xml

Lines changed: 36 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@
4646
<junit.version>4.12</junit.version>
4747
<jacoco.version>0.8.0</jacoco.version>
4848
<easy.mock.version>3.4</easy.mock.version>
49+
<powermock.version>1.6.6</powermock.version>
4950
<jsonassert.version>1.5.0</jsonassert.version>
5051
<mockwebserver.version>2.7.5</mockwebserver.version>
5152
</properties>
@@ -82,7 +83,6 @@
8283
<groupId>ch.qos.logback</groupId>
8384
<artifactId>logback-classic</artifactId>
8485
<version>${logback.version}</version>
85-
<scope>test</scope>
8686
</dependency>
8787

8888
<dependency>
@@ -119,6 +119,18 @@
119119
<version>${easy.mock.version}</version>
120120
<scope>test</scope>
121121
</dependency>
122+
<dependency>
123+
<groupId>org.powermock</groupId>
124+
<artifactId>powermock-module-junit4</artifactId>
125+
<version>${powermock.version}</version>
126+
<scope>test</scope>
127+
</dependency>
128+
<dependency>
129+
<groupId>org.powermock</groupId>
130+
<artifactId>powermock-module-test-easymock-junit4</artifactId>
131+
<version>${powermock.version}</version>
132+
<scope>test</scope>
133+
</dependency>
122134
<dependency>
123135
<groupId>org.glassfish.tyrus</groupId>
124136
<artifactId>tyrus-server</artifactId>
@@ -133,9 +145,10 @@
133145
</dependency>
134146
<dependency>
135147
<groupId>org.jacoco</groupId>
136-
<artifactId>jacoco-maven-plugin</artifactId>
137-
<version>${jacoco.version}</version>
148+
<artifactId>org.jacoco.agent</artifactId>
149+
<classifier>runtime</classifier>
138150
<scope>test</scope>
151+
<version>${jacoco.version}</version>
139152
</dependency>
140153
</dependencies>
141154

@@ -196,22 +209,36 @@
196209
</licenseMerges>
197210
</configuration>
198211
</plugin>
212+
<plugin>
213+
<groupId>org.apache.maven.plugins</groupId>
214+
<artifactId>maven-surefire-plugin</artifactId>
215+
<version>2.20.1</version>
216+
<configuration>
217+
<systemPropertyVariables>
218+
<jacoco-agent.destfile>target/jacoco.exec</jacoco-agent.destfile>
219+
</systemPropertyVariables>
220+
</configuration>
221+
</plugin>
199222
<plugin>
200223
<groupId>org.jacoco</groupId>
201224
<artifactId>jacoco-maven-plugin</artifactId>
202225
<version>${jacoco.version}</version>
203226
<executions>
204227
<execution>
205-
<id>pre-unit-test</id>
228+
<id>default-instrument</id>
229+
<goals>
230+
<goal>instrument</goal>
231+
</goals>
232+
</execution>
233+
<execution>
234+
<id>default-restore-instrumented-classes</id>
206235
<goals>
207-
<goal>prepare-agent</goal>
236+
<goal>restore-instrumented-classes</goal>
208237
</goals>
209-
<configuration>
210-
</configuration>
238+
<phase>post-integration-test</phase>
211239
</execution>
212240
<execution>
213-
<id>post-unit-test</id>
214-
<phase>test</phase>
241+
<id>default-report</id>
215242
<goals>
216243
<goal>report</goal>
217244
</goals>

cdtp-java-client/src/license/THIRD-PARTY.properties

Lines changed: 0 additions & 27 deletions
This file was deleted.

cdtp-java-client/src/main/java/com/github/kklisura/cdtp/App.java

Lines changed: 27 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -21,41 +21,47 @@
2121
*/
2222

2323
import com.github.kklisura.cdtp.launch.ChromeLauncher;
24-
import com.github.kklisura.cdtp.protocol.events.network.RequestWillBeSent;
25-
import com.github.kklisura.cdtp.protocol.support.types.EventHandler;
24+
import com.github.kklisura.cdtp.protocol.commands.Network;
25+
import com.github.kklisura.cdtp.protocol.commands.Page;
2626
import com.github.kklisura.cdtp.services.ChromeDevToolsService;
2727
import com.github.kklisura.cdtp.services.ChromeService;
2828
import com.github.kklisura.cdtp.services.types.ChromeTab;
29+
import java.util.concurrent.CountDownLatch;
2930

3031
/** Hello world! */
3132
public class App {
3233
public static void main(String[] args) throws Exception {
33-
ChromeLauncher chromeLauncher = new ChromeLauncher();
34+
// Create chrome launcher
35+
try (final ChromeLauncher chromeLauncher = new ChromeLauncher()) {
3436

35-
final ChromeService chromeService = chromeLauncher.launch(false);
36-
final ChromeTab tab = chromeService.createTab();
37+
// Launch chrome either as headless (true) or no.
38+
final ChromeService chromeService = chromeLauncher.launch(true);
3739

38-
try (ChromeDevToolsService cdtpService = chromeService.createDevToolsService(tab)) {
40+
// Create empty tab (about:blank)
41+
final ChromeTab tab = chromeService.createTab();
3942

40-
cdtpService
41-
.getNetwork()
42-
.onRequestWillBeSent(
43-
new EventHandler<RequestWillBeSent>() {
44-
@Override
45-
public void onEvent(RequestWillBeSent event) {
46-
System.out.println(event.getRequest().getUrl());
47-
}
48-
});
43+
// Get dev tools service to this tab
44+
try (ChromeDevToolsService devToolsService = chromeService.createDevToolsService(tab)) {
45+
final Network network = devToolsService.getNetwork();
46+
final Page page = devToolsService.getPage();
4947

50-
cdtpService.getNetwork().enable();
48+
network.onRequestWillBeSent(event -> System.out.println(event.getRequest().getUrl()));
49+
network.enable();
5150

52-
cdtpService.getPage().navigate("http://github.com");
51+
page.navigate("http://klix.ba");
5352

54-
Thread.sleep(10000);
55-
}
53+
CountDownLatch countDownLatch = new CountDownLatch(1);
54+
55+
network.onLoadingFinished(
56+
event -> {
57+
System.out.println("Finished");
58+
countDownLatch.countDown();
59+
});
5660

57-
chromeService.closeTab(tab);
61+
countDownLatch.await();
62+
}
5863

59-
chromeLauncher.close();
64+
chromeService.closeTab(tab);
65+
}
6066
}
6167
}

0 commit comments

Comments
 (0)