Skip to content

Commit

Permalink
[java] Formatting files.
Browse files Browse the repository at this point in the history
  • Loading branch information
diemol committed Jun 5, 2023
1 parent aaf6c27 commit 3c2313f
Show file tree
Hide file tree
Showing 12 changed files with 68 additions and 78 deletions.
75 changes: 37 additions & 38 deletions java/src/org/openqa/selenium/bidi/BrowsingContextInspector.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,13 @@

package org.openqa.selenium.bidi;

import java.io.StringReader;
import java.util.Collections;
import java.util.HashSet;
import java.util.Map;
import java.util.Set;
import java.util.function.Consumer;
import java.util.function.Function;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.bidi.browsingcontext.BrowsingContextInfo;
import org.openqa.selenium.bidi.browsingcontext.NavigationInfo;
Expand All @@ -26,14 +33,6 @@
import org.openqa.selenium.json.Json;
import org.openqa.selenium.json.JsonInput;

import java.io.StringReader;
import java.util.Collections;
import java.util.HashSet;
import java.util.Map;
import java.util.Set;
import java.util.function.Consumer;
import java.util.function.Function;

public class BrowsingContextInspector implements AutoCloseable {

private static final Json JSON = new Json();
Expand All @@ -43,48 +42,48 @@ public class BrowsingContextInspector implements AutoCloseable {
private final BiDi bidi;

private final Function<Map<String, Object>, BrowsingContextInfo> browsingContextInfoMapper =
params -> {
try (
StringReader reader = new StringReader(JSON.toJson(params));
JsonInput input = JSON.newInput(reader)) {
return input.read(BrowsingContextInfo.class);
}
};
params -> {
try (StringReader reader = new StringReader(JSON.toJson(params));
JsonInput input = JSON.newInput(reader)) {
return input.read(BrowsingContextInfo.class);
}
};

private final Function<Map<String, Object>, NavigationInfo> navigationInfoMapper =
params -> {
try (
StringReader reader = new StringReader(JSON.toJson(params));
JsonInput input = JSON.newInput(reader)) {
return input.read(NavigationInfo.class);
}
};
params -> {
try (StringReader reader = new StringReader(JSON.toJson(params));
JsonInput input = JSON.newInput(reader)) {
return input.read(NavigationInfo.class);
}
};

private final Event<BrowsingContextInfo> browsingContextCreated =
new Event<>("browsingContext.contextCreated", browsingContextInfoMapper);
new Event<>("browsingContext.contextCreated", browsingContextInfoMapper);

private final Event<BrowsingContextInfo> browsingContextDestroyed =
new Event<>("browsingContext.contextDestroyed", browsingContextInfoMapper);
new Event<>("browsingContext.contextDestroyed", browsingContextInfoMapper);

private final Event<UserPromptClosed> userPromptClosed =
new Event<>("browsingContext.userPromptClosed", params -> {
try (
StringReader reader = new StringReader(JSON.toJson(params));
JsonInput input = JSON.newInput(reader)) {
return input.read(UserPromptClosed.class);
}
});
new Event<>(
"browsingContext.userPromptClosed",
params -> {
try (StringReader reader = new StringReader(JSON.toJson(params));
JsonInput input = JSON.newInput(reader)) {
return input.read(UserPromptClosed.class);
}
});

private final Set<Event<NavigationInfo>> navigationEventSet = new HashSet<>();

private final Event<UserPromptOpened> userPromptOpened =
new Event<>("browsingContext.userPromptOpened", params -> {
try (
StringReader reader = new StringReader(JSON.toJson(params));
JsonInput input = JSON.newInput(reader)) {
return input.read(UserPromptOpened.class);
}
});
new Event<>(
"browsingContext.userPromptOpened",
params -> {
try (StringReader reader = new StringReader(JSON.toJson(params));
JsonInput input = JSON.newInput(reader)) {
return input.read(UserPromptOpened.class);
}
});

public BrowsingContextInspector(WebDriver driver) {
this(new HashSet<>(), driver);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,9 @@

import static java.util.Collections.unmodifiableMap;

import org.openqa.selenium.json.JsonInput;

import java.util.Map;
import java.util.TreeMap;
import org.openqa.selenium.json.JsonInput;

public class NavigationInfo {

Expand All @@ -34,7 +33,8 @@ public class NavigationInfo {

private final String url;

private NavigationInfo(String browsingContextId, String navigationId, long timestamp, String url) {
private NavigationInfo(
String browsingContextId, String navigationId, long timestamp, String url) {
this.browsingContextId = browsingContextId;
this.navigationId = navigationId;
this.timestamp = timestamp;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,10 @@

import static java.util.Collections.unmodifiableMap;

import org.openqa.selenium.json.JsonInput;

import java.util.Map;
import java.util.Optional;
import java.util.TreeMap;
import org.openqa.selenium.json.JsonInput;

public class UserPromptClosed {

Expand All @@ -39,7 +38,6 @@ private UserPromptClosed(String browsingContextId, boolean accepted, Optional<St
this.userText = userText;
}


public static UserPromptClosed fromJson(JsonInput input) {
String browsingContextId = null;
boolean accepted = false;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,9 @@

import static java.util.Collections.unmodifiableMap;

import org.openqa.selenium.json.JsonInput;

import java.util.Map;
import java.util.TreeMap;
import org.openqa.selenium.json.JsonInput;

public class UserPromptOpened {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -465,8 +465,9 @@ protected OutputStream getLogOutput(String logProperty) {
}

if (logLocation == null) {
LOG.info("Driver logs no longer sent to console by default; " +
"https://www.selenium.dev/documentation/webdriver/drivers/service/#setting-log-output");
LOG.info(
"Driver logs no longer sent to console by default; "
+ "https://www.selenium.dev/documentation/webdriver/drivers/service/#setting-log-output");
return ByteStreams.nullOutputStream();
}

Expand Down
2 changes: 1 addition & 1 deletion java/test/org/openqa/selenium/ReferrerTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ class ReferrerTest {
public static void shouldTestBeRunAtAll() {
assumeThat(Boolean.getBoolean("selenium.skiptest")).isFalse();
}

@BeforeAll
public static void readContents() throws IOException {
page1 = new String(Files.readAllBytes(locate("common/src/web/proxy" + PAGE_1)));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,10 @@
import static org.assertj.core.api.AssertionsForClassTypes.assertThat;
import static org.openqa.selenium.testing.Safely.safelyCall;

import java.util.concurrent.CompletableFuture;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.TimeoutException;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
Expand All @@ -30,11 +34,6 @@
import org.openqa.selenium.firefox.FirefoxDriver;
import org.openqa.selenium.firefox.FirefoxOptions;

import java.util.concurrent.CompletableFuture;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.TimeoutException;

class BrowsingContextInspectorTest {

private AppServer server;
Expand All @@ -53,7 +52,7 @@ public void setUp() {

@Test
void canListenToWindowBrowsingContextCreatedEvent()
throws ExecutionException, InterruptedException, TimeoutException {
throws ExecutionException, InterruptedException, TimeoutException {
try (BrowsingContextInspector inspector = new BrowsingContextInspector(driver)) {
CompletableFuture<BrowsingContextInfo> future = new CompletableFuture<>();

Expand All @@ -73,7 +72,7 @@ void canListenToWindowBrowsingContextCreatedEvent()

@Test
void canListenToTabBrowsingContextCreatedEvent()
throws ExecutionException, InterruptedException, TimeoutException {
throws ExecutionException, InterruptedException, TimeoutException {
try (BrowsingContextInspector inspector = new BrowsingContextInspector(driver)) {
CompletableFuture<BrowsingContextInfo> future = new CompletableFuture<>();
inspector.onBrowsingContextCreated(future::complete);
Expand All @@ -92,7 +91,7 @@ void canListenToTabBrowsingContextCreatedEvent()

@Test
void canListenToDomContentLoadedEvent()
throws ExecutionException, InterruptedException, TimeoutException {
throws ExecutionException, InterruptedException, TimeoutException {
try (BrowsingContextInspector inspector = new BrowsingContextInspector(driver)) {
CompletableFuture<NavigationInfo> future = new CompletableFuture<>();
inspector.onDomContentLoaded(future::complete);
Expand All @@ -108,7 +107,7 @@ void canListenToDomContentLoadedEvent()

@Test
void canListenToBrowsingContextLoadedEvent()
throws ExecutionException, InterruptedException, TimeoutException {
throws ExecutionException, InterruptedException, TimeoutException {
try (BrowsingContextInspector inspector = new BrowsingContextInspector(driver)) {
CompletableFuture<NavigationInfo> future = new CompletableFuture<>();
inspector.onBrowsingContextLoaded(future::complete);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,10 @@
import static org.assertj.core.api.Assumptions.assumeThat;
import static org.openqa.selenium.testing.drivers.Browser.CHROME;

import com.google.common.collect.ImmutableMap;
import com.google.common.util.concurrent.Uninterruptibles;
import java.time.Duration;
import java.util.List;
import java.util.Map;

import org.assertj.core.api.Assumptions;
import org.junit.jupiter.api.Test;
import org.openqa.selenium.Capabilities;
Expand All @@ -47,7 +45,6 @@
import org.openqa.selenium.testing.Ignore;
import org.openqa.selenium.testing.JupiterTestBase;
import org.openqa.selenium.testing.NoDriverBeforeTest;
import org.openqa.selenium.testing.drivers.Browser;

class ChromeDriverFunctionalTest extends JupiterTestBase {

Expand Down Expand Up @@ -87,7 +84,7 @@ public void driverOverridesDefaultClientConfig() {
localDriver =
new ChromeDriver(
ChromeDriverService.createDefaultService(),
(ChromeOptions) CHROME.getCapabilities(),
(ChromeOptions) CHROME.getCapabilities(),
clientConfig);
})
.isInstanceOf(SessionNotCreatedException.class);
Expand All @@ -96,7 +93,8 @@ public void driverOverridesDefaultClientConfig() {
@Test
void builderWithClientConfigThrowsException() {
ClientConfig clientConfig = ClientConfig.defaultConfig().readTimeout(Duration.ofMinutes(1));
RemoteWebDriverBuilder builder = ChromeDriver.builder().oneOf(CHROME.getCapabilities()).config(clientConfig);
RemoteWebDriverBuilder builder =
ChromeDriver.builder().oneOf(CHROME.getCapabilities()).config(clientConfig);

assertThatExceptionOfType(IllegalArgumentException.class)
.isThrownBy(builder::build)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,13 @@

package org.openqa.selenium.chrome;

import static org.assertj.core.api.Assertions.assertThat;
import static org.openqa.selenium.remote.CapabilityType.ACCEPT_INSECURE_CERTS;

import com.google.common.collect.ImmutableMap;
import java.io.IOException;
import java.nio.file.Files;
import java.util.Base64;
import org.junit.jupiter.api.AfterAll;
import org.junit.jupiter.api.Test;
import org.openqa.selenium.By;
Expand All @@ -27,13 +33,6 @@
import org.openqa.selenium.testing.NoDriverBeforeTest;
import org.openqa.selenium.testing.drivers.Browser;

import java.io.IOException;
import java.nio.file.Files;
import java.util.Base64;

import static org.assertj.core.api.Assertions.assertThat;
import static org.openqa.selenium.remote.CapabilityType.ACCEPT_INSECURE_CERTS;

class ChromeOptionsFunctionalTest extends JupiterTestBase {

private static final String EXT_PATH = "common/extensions/webextensions-selenium-example.crx";
Expand Down Expand Up @@ -107,6 +106,7 @@ public void canAddExtensionFromStringEncodedInBase64() throws IOException {

private ChromeOptions createChromeOptionsForExtensions() {
ChromeOptions options = (ChromeOptions) Browser.CHROME.getCapabilities();
return options.setExperimentalOption("prefs", ImmutableMap.of("extensions.ui.developer_mode", true));
return options.setExperimentalOption(
"prefs", ImmutableMap.of("extensions.ui.developer_mode", true));
}
}
3 changes: 2 additions & 1 deletion java/test/org/openqa/selenium/testing/JupiterTestBase.java
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,8 @@ public void removeDriver() {
public String toLocalUrl(String url) {
try {
URL original = new URL(url);
return new URL(original.getProtocol(), "localhost", original.getPort(), original.getFile()).toString();
return new URL(original.getProtocol(), "localhost", original.getPort(), original.getFile())
.toString();
} catch (MalformedURLException e) {
throw new RuntimeException(e);
}
Expand Down
5 changes: 1 addition & 4 deletions java/test/org/openqa/selenium/testing/drivers/Browser.java
Original file line number Diff line number Diff line change
Expand Up @@ -52,10 +52,7 @@ public Capabilities getCapabilities() {
}

options.addArguments(
"disable-infobars",
"disable-breakpad",
"disable-dev-shm-usage",
"no-sandbox");
"disable-infobars", "disable-breakpad", "disable-dev-shm-usage", "no-sandbox");

Map<String, Object> prefs = new HashMap<>();
prefs.put("exit_type", "None");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,6 @@
import static org.junit.jupiter.api.Assertions.assertThrows;

import java.net.MalformedURLException;
import java.net.URI;
import java.net.URL;
import java.security.spec.PKCS8EncodedKeySpec;
import java.util.Arrays;
import java.util.Base64;
Expand Down

0 comments on commit 3c2313f

Please sign in to comment.