Skip to content

Commit

Permalink
Merge branch 'trunk' into dotnet-logfile-overwite
Browse files Browse the repository at this point in the history
  • Loading branch information
diemol authored May 15, 2024
2 parents 8e0574f + d556c8e commit 5365389
Show file tree
Hide file tree
Showing 23 changed files with 103 additions and 67 deletions.
1 change: 0 additions & 1 deletion MODULE.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,6 @@ maven.install(
"org.junit.platform:junit-platform-commons:1.10.2",
"org.junit.platform:junit-platform-engine:1.10.2",
"org.mockito:mockito-core:5.11.0",
"org.mockito:mockito-inline:5.2.0",
"org.redisson:redisson:3.29.0",
"org.slf4j:slf4j-api:2.0.13",
"org.slf4j:slf4j-jdk14:2.0.13",
Expand Down
34 changes: 17 additions & 17 deletions common/repositories.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -123,10 +123,10 @@ js_library(

pkg_archive(
name = "mac_edge",
url = "https://msedge.sf.dl.delivery.mp.microsoft.com/filestreamingservice/files/e6f7f9ba-499c-44cb-9c19-28daeaa82dc6/MicrosoftEdge-124.0.2478.80.pkg",
sha256 = "fc667b0401c05bbe0e4d337cc593641e2b653107fafd363b401cd32baa8a4f53",
url = "https://msedge.sf.dl.delivery.mp.microsoft.com/filestreamingservice/files/f12b802a-7a08-47df-b40e-04570cf4e133/MicrosoftEdge-124.0.2478.97.pkg",
sha256 = "a1c9df556e158a2564e3f8238082ea724ea4a2585b4b543376d0f0e4bc389749",
move = {
"MicrosoftEdge-124.0.2478.80.pkg/Payload/Microsoft Edge.app": "Edge.app",
"MicrosoftEdge-124.0.2478.97.pkg/Payload/Microsoft Edge.app": "Edge.app",
},
build_file_content = """
load("@aspect_rules_js//js:defs.bzl", "js_library")
Expand All @@ -143,8 +143,8 @@ js_library(

deb_archive(
name = "linux_edge",
url = "https://packages.microsoft.com/repos/edge/pool/main/m/microsoft-edge-stable/microsoft-edge-stable_124.0.2478.80-1_amd64.deb",
sha256 = "a7eb75d95730c520eec998f755fcc427a9b4ac6a150bbb267b21e8383b6dc105",
url = "https://packages.microsoft.com/repos/edge/pool/main/m/microsoft-edge-stable/microsoft-edge-stable_124.0.2478.97-1_amd64.deb",
sha256 = "85d0ad1d63847b3dd54f0f214d18a2b54462bb43291536e773ad1b8b29bbf799",
build_file_content = """
load("@aspect_rules_js//js:defs.bzl", "js_library")
package(default_visibility = ["//visibility:public"])
Expand All @@ -165,8 +165,8 @@ js_library(

http_archive(
name = "linux_edgedriver",
url = "https://msedgedriver.azureedge.net/124.0.2478.80/edgedriver_linux64.zip",
sha256 = "4c9192c8e42ac1e1d779784ba95a0b28807cc75ae1be07be740f40bc20410670",
url = "https://msedgedriver.azureedge.net/124.0.2478.97/edgedriver_linux64.zip",
sha256 = "b8c2b6c20c1669240ef601939a3097f3b704d062215ee5bd98cb6415f5a7c907",
build_file_content = """
load("@aspect_rules_js//js:defs.bzl", "js_library")
package(default_visibility = ["//visibility:public"])
Expand All @@ -182,8 +182,8 @@ js_library(

http_archive(
name = "mac_edgedriver",
url = "https://msedgedriver.azureedge.net/124.0.2478.80/edgedriver_mac64.zip",
sha256 = "f8d8b0eaacb884196e5f368a64cad246a86e5a92941b0d37c5d7aa8ebb0fec1f",
url = "https://msedgedriver.azureedge.net/124.0.2478.97/edgedriver_mac64.zip",
sha256 = "8c70da916d7a040a90949a6dcb9c4bf9717d5d7daffeb7a4ca9304327c3ad199",
build_file_content = """
load("@aspect_rules_js//js:defs.bzl", "js_library")
package(default_visibility = ["//visibility:public"])
Expand All @@ -199,8 +199,8 @@ js_library(

http_archive(
name = "linux_chrome",
url = "https://storage.googleapis.com/chrome-for-testing-public/124.0.6367.155/linux64/chrome-linux64.zip",
sha256 = "0761489e320bb56a29f53c051abea0a26418afcef62af2fa9bf1d4768a78d005",
url = "https://storage.googleapis.com/chrome-for-testing-public/124.0.6367.207/linux64/chrome-linux64.zip",
sha256 = "22ac5d13b0bcbe1e7a454714421ab2448f8f8568ad3954cb4a87750bd70336c2",
build_file_content = """
load("@aspect_rules_js//js:defs.bzl", "js_library")
package(default_visibility = ["//visibility:public"])
Expand All @@ -221,8 +221,8 @@ js_library(

http_archive(
name = "mac_chrome",
url = "https://storage.googleapis.com/chrome-for-testing-public/124.0.6367.155/mac-x64/chrome-mac-x64.zip",
sha256 = "30456654c6699f2b8b6378a08d82caff439da1834213cb65e3536e669fc0e7ad",
url = "https://storage.googleapis.com/chrome-for-testing-public/124.0.6367.207/mac-x64/chrome-mac-x64.zip",
sha256 = "67d8b832c49c0afc96f2b3f3480acae270293f097c162ef2805cead51694b870",
strip_prefix = "chrome-mac-x64",
patch_cmds = [
"mv 'Google Chrome for Testing.app' Chrome.app",
Expand All @@ -243,8 +243,8 @@ js_library(

http_archive(
name = "linux_chromedriver",
url = "https://storage.googleapis.com/chrome-for-testing-public/124.0.6367.155/linux64/chromedriver-linux64.zip",
sha256 = "7ae76046edce32e4c14de5fcceb9ba4a18268dcb0d87368160400fff89f54899",
url = "https://storage.googleapis.com/chrome-for-testing-public/124.0.6367.207/linux64/chromedriver-linux64.zip",
sha256 = "c428b34691e071e9eddc3fed3012be0ad5e2c2d4dd1fad5f8dad6ef10c840820",
strip_prefix = "chromedriver-linux64",
build_file_content = """
load("@aspect_rules_js//js:defs.bzl", "js_library")
Expand All @@ -261,8 +261,8 @@ js_library(

http_archive(
name = "mac_chromedriver",
url = "https://storage.googleapis.com/chrome-for-testing-public/124.0.6367.155/mac-x64/chromedriver-mac-x64.zip",
sha256 = "e0c6700f68e08ceac14ed923c56d171fe9597cff308fb67a7a0ecbc05ce208f5",
url = "https://storage.googleapis.com/chrome-for-testing-public/124.0.6367.207/mac-x64/chromedriver-mac-x64.zip",
sha256 = "d34e7cda39e5024564a85b329599d359f1e1e53264cfe9bd5bc4025d829eadfa",
strip_prefix = "chromedriver-mac-x64",
build_file_content = """
load("@aspect_rules_js//js:defs.bzl", "js_library")
Expand Down
16 changes: 2 additions & 14 deletions java/maven_install.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"__AUTOGENERATED_FILE_DO_NOT_MODIFY_THIS_FILE_MANUALLY": "THERE_IS_NO_DATA_ONLY_ZUUL",
"__INPUT_ARTIFACTS_HASH": 1731569326,
"__RESOLVED_ARTIFACTS_HASH": -177292306,
"__INPUT_ARTIFACTS_HASH": 804245233,
"__RESOLVED_ARTIFACTS_HASH": 375527245,
"conflict_resolution": {
"com.google.code.gson:gson:2.8.9": "com.google.code.gson:gson:2.10.1",
"com.google.errorprone:error_prone_annotations:2.3.2": "com.google.errorprone:error_prone_annotations:2.26.1",
Expand Down Expand Up @@ -710,13 +710,6 @@
},
"version": "5.11.0"
},
"org.mockito:mockito-inline": {
"shasums": {
"jar": "ee52e1c299a632184fba274a9370993e09140429f5e516e6c5570fd6574b297f",
"sources": "ee52e1c299a632184fba274a9370993e09140429f5e516e6c5570fd6574b297f"
},
"version": "5.2.0"
},
"org.objenesis:objenesis": {
"shasums": {
"jar": "02dfd0b0439a5591e35b708ed2f5474eb0948f53abf74637e959b8e4ef69bfeb",
Expand Down Expand Up @@ -1114,9 +1107,6 @@
"net.bytebuddy:byte-buddy-agent",
"org.objenesis:objenesis"
],
"org.mockito:mockito-inline": [
"org.mockito:mockito-core"
],
"org.ow2.asm:asm-analysis": [
"org.ow2.asm:asm-tree"
],
Expand Down Expand Up @@ -3153,8 +3143,6 @@
"org.junit.platform:junit-platform-reporting:jar:sources",
"org.mockito:mockito-core",
"org.mockito:mockito-core:jar:sources",
"org.mockito:mockito-inline",
"org.mockito:mockito-inline:jar:sources",
"org.objenesis:objenesis",
"org.objenesis:objenesis:jar:sources",
"org.opentest4j:opentest4j",
Expand Down
7 changes: 4 additions & 3 deletions java/src/org/openqa/selenium/Cookie.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import java.util.Date;
import java.util.Map;
import java.util.Objects;
import java.util.TimeZone;
import java.util.TreeMap;

public class Cookie implements Serializable {
Expand Down Expand Up @@ -255,12 +256,12 @@ public Map<String, Object> toJson() {

@Override
public String toString() {
SimpleDateFormat sdf = new SimpleDateFormat("EEE, dd MMM yyyy HH:mm:ss z");
sdf.setTimeZone(TimeZone.getTimeZone("GMT"));
return name
+ "="
+ value
+ (expiry == null
? ""
: "; expires=" + new SimpleDateFormat("EEE, dd MMM yyyy hh:mm:ss z").format(expiry))
+ (expiry == null ? "" : "; expires=" + sdf.format(expiry))
+ ("".equals(path) ? "" : "; path=" + path)
+ (domain == null ? "" : "; domain=" + domain)
+ (isSecure ? ";secure;" : "")
Expand Down
2 changes: 1 addition & 1 deletion java/src/org/openqa/selenium/bidi/network/FetchError.java
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ private FetchError(BaseParameters baseParameters, String errorText) {

public static FetchError fromJsonMap(Map<String, Object> jsonMap) {
try (StringReader baseParameterReader = new StringReader(JSON.toJson(jsonMap));
JsonInput baseParamsInput = JSON.newInput(baseParameterReader); ) {
JsonInput baseParamsInput = JSON.newInput(baseParameterReader)) {
String errorText = JSON.toJson(jsonMap.get("errorText"));
return new FetchError(BaseParameters.fromJson(baseParamsInput), errorText);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ public interface EvaluateResult {

String getRealmId();

public enum Type {
enum Type {
SUCCESS("success"),
EXCEPTION("exception");

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ public class SerializationOptions {
public enum IncludeShadowTree {
NONE,
OPEN,
ALL;
ALL
}

private Optional<Long> maxDomDepth = Optional.empty();
Expand Down
17 changes: 10 additions & 7 deletions java/src/org/openqa/selenium/devtools/Connection.java
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@
import java.util.concurrent.locks.Lock;
import java.util.concurrent.locks.ReadWriteLock;
import java.util.concurrent.locks.ReentrantReadWriteLock;
import java.util.function.BiConsumer;
import java.util.function.Consumer;
import java.util.logging.Level;
import java.util.logging.Logger;
Expand Down Expand Up @@ -70,11 +71,12 @@ public class Connection implements Closeable {
return thread;
});
private static final AtomicLong NEXT_ID = new AtomicLong(1L);
private static final AtomicLong NEXT_SEQUENCE = new AtomicLong(1L);
private WebSocket socket;
private final Map<Long, Consumer<Either<Throwable, JsonInput>>> methodCallbacks =
new ConcurrentHashMap<>();
private final ReadWriteLock callbacksLock = new ReentrantReadWriteLock(true);
private final Map<Event<?>, List<Consumer<?>>> eventCallbacks = new HashMap<>();
private final Map<Event<?>, List<BiConsumer<Long, ?>>> eventCallbacks = new HashMap<>();
private HttpClient client;
private final String url;
private final AtomicBoolean isClosed;
Expand Down Expand Up @@ -196,7 +198,7 @@ public <X> X sendAndWait(SessionID sessionId, Command<X> command, Duration timeo
}
}

public <X> void addListener(Event<X> event, Consumer<X> handler) {
public <X> void addListener(Event<X> event, BiConsumer<Long, X> handler) {
Require.nonNull("Event to listen for", event);
Require.nonNull("Handler to call", handler);

Expand Down Expand Up @@ -230,10 +232,11 @@ private class Listener implements WebSocket.Listener {

@Override
public void onText(CharSequence data) {
long sequence = NEXT_SEQUENCE.getAndIncrement();
EXECUTOR.execute(
() -> {
try {
handle(data);
handle(sequence, data);
} catch (Throwable t) {
LOG.log(Level.WARNING, "Unable to process: " + data, t);
throw new DevToolsException(t);
Expand All @@ -242,7 +245,7 @@ public void onText(CharSequence data) {
}
}

private void handle(CharSequence data) {
private void handle(long sequence, CharSequence data) {
// It's kind of gross to decode the data twice, but this lets us get started on something
// that feels nice to users.
// TODO: decode once, and once only
Expand Down Expand Up @@ -335,14 +338,14 @@ private void handle(CharSequence data) {
return;
}

for (Consumer<?> action : event.getValue()) {
for (BiConsumer<Long, ?> action : event.getValue()) {
@SuppressWarnings("unchecked")
Consumer<Object> obj = (Consumer<Object>) action;
BiConsumer<Long, Object> obj = (BiConsumer<Long, Object>) action;
LOG.log(
getDebugLogLevel(),
"Calling callback for {0} using {1} being passed {2}",
new Object[] {event.getKey(), obj, params});
obj.accept(params);
obj.accept(sequence, params);
}
}
});
Expand Down
24 changes: 24 additions & 0 deletions java/src/org/openqa/selenium/devtools/DevTools.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.TimeoutException;
import java.util.function.BiConsumer;
import java.util.function.Consumer;
import java.util.function.Function;
import java.util.logging.Level;
Expand Down Expand Up @@ -89,10 +90,33 @@ public <X> X send(Command<X> command) {
return connection.sendAndWait(cdpSession, command, timeout);
}

/**
* Register a handler to the given event.
*
* @param event the event to listen to
* @param handler the handler to register
* @param <X> type of the data generated by the event
*/
public <X> void addListener(Event<X> event, Consumer<X> handler) {
Require.nonNull("Event to listen for", event);
Require.nonNull("Handler to call", handler);

connection.addListener(event, (sequence, x) -> handler.accept(x));
}

/**
* Register a handler to the given event, this handler will receive a sequence number to
* determinate the order of the data generated by the event. The sequence number might have gaps
* when other events are raised in between.
*
* @param event the event to listen to
* @param handler the handler to register
* @param <X> type of the data generated by the event
*/
public <X> void addListener(Event<X> event, BiConsumer<Long, X> handler) {
Require.nonNull("Event to listen for", event);
Require.nonNull("Handler to call", handler);

connection.addListener(event, handler);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -316,25 +316,25 @@ public boolean isReady() {
private String uriKey(SessionId id) {
Require.nonNull("Session ID", id);

return "session:" + id.toString() + ":uri";
return "session:" + id + ":uri";
}

private String capabilitiesKey(SessionId id) {
Require.nonNull("Session ID", id);

return "session:" + id.toString() + ":capabilities";
return "session:" + id + ":capabilities";
}

private String startKey(SessionId id) {
Require.nonNull("Session ID", id);

return "session:" + id.toString() + ":start";
return "session:" + id + ":start";
}

private String stereotypeKey(SessionId id) {
Require.nonNull("Session ID", id);

return "session:" + id.toString() + ":stereotype";
return "session:" + id + ":stereotype";
}

private void setCommonSpanAttributes(Span span) {
Expand Down
10 changes: 7 additions & 3 deletions java/src/org/openqa/selenium/io/CircularOutputStream.java
Original file line number Diff line number Diff line change
Expand Up @@ -85,19 +85,23 @@ public void close() {
}

@Override
public synchronized String toString() {
public String toString() {
return toString(Charset.defaultCharset());
}

public synchronized String toString(Charset encoding) {
int size = filled ? buffer.length : end;
byte[] toReturn = new byte[size];

// Handle the partially filled array as a special case
if (!filled) {
System.arraycopy(buffer, 0, toReturn, 0, end);
return new String(toReturn, Charset.defaultCharset());
return new String(toReturn, encoding);
}

int n = buffer.length - end;
System.arraycopy(buffer, end, toReturn, 0, n);
System.arraycopy(buffer, 0, toReturn, n, end);
return new String(toReturn, Charset.defaultCharset());
return new String(toReturn, encoding);
}
}
2 changes: 1 addition & 1 deletion java/src/org/openqa/selenium/json/JsonInput.java
Original file line number Diff line number Diff line change
Expand Up @@ -246,7 +246,7 @@ public Number nextNumber() {
}
return number.longValue();
} catch (NumberFormatException e) {
throw new JsonException("Unable to parse to a number: " + builder.toString() + ". " + input);
throw new JsonException("Unable to parse to a number: " + builder + ". " + input);
}
}

Expand Down
3 changes: 2 additions & 1 deletion java/src/org/openqa/selenium/manager/SeleniumManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@

import java.io.IOException;
import java.io.InputStream;
import java.nio.charset.StandardCharsets;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
Expand Down Expand Up @@ -141,7 +142,7 @@ private static Result runCommand(Path binary, List<String> arguments) {
process.shutdown();
}
code = process.exitValue();
output = process.getOutput();
output = process.getOutput(StandardCharsets.UTF_8);
} catch (Exception e) {
throw new WebDriverException("Failed to run command: " + arguments, e);
}
Expand Down
Loading

0 comments on commit 5365389

Please sign in to comment.