Skip to content

Commit 08b5b6a

Browse files
Update java/src/org/openqa/selenium/bidi/browsingcontext/DownloadEnded.java
Co-authored-by: qodo-merge-pro[bot] <151058649+qodo-merge-pro[bot]@users.noreply.github.com>
1 parent 8b155ab commit 08b5b6a

File tree

1 file changed

+12
-46
lines changed

1 file changed

+12
-46
lines changed

java/src/org/openqa/selenium/bidi/browsingcontext/DownloadEnded.java

Lines changed: 12 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -28,54 +28,20 @@ public DownloadEnded(NavigationInfo downloadParams) {
2828
}
2929

3030
public static DownloadEnded fromJson(JsonInput input) {
31-
String browsingContextId = null;
32-
String navigationId = null;
33-
long timestamp = 0;
34-
String url = null;
35-
String status = null;
36-
String filepath = null;
37-
38-
input.beginObject();
39-
while (input.hasNext()) {
40-
switch (input.nextName()) {
41-
case "context":
42-
browsingContextId = input.read(String.class);
43-
break;
44-
case "navigation":
45-
navigationId = input.read(String.class);
46-
break;
47-
case "timestamp":
48-
timestamp = input.read(Long.class);
49-
break;
50-
case "url":
51-
url = input.read(String.class);
52-
break;
53-
case "status":
54-
status = input.read(String.class);
55-
break;
56-
case "filepath":
57-
filepath = input.read(String.class);
58-
break;
59-
default:
60-
input.skipValue();
61-
break;
31+
Map<String, Object> jsonMap = input.read(Map.class);
32+
String status = (String) jsonMap.get("status");
33+
34+
try (StringReader reader = new StringReader(new Json().toJson(jsonMap));
35+
JsonInput jsonInput = new Json().newInput(reader)) {
36+
if ("canceled".equals(status)) {
37+
return new DownloadEnded(DownloadCanceled.fromJson(jsonInput));
38+
} else if ("complete".equals(status)) {
39+
return new DownloadEnded(DownloadCompleted.fromJson(jsonInput));
40+
} else {
41+
throw new IllegalArgumentException(
42+
"status must be either 'canceled' or 'complete', but got: " + status);
6243
}
6344
}
64-
input.endObject();
65-
66-
// Create the appropriate object based on status
67-
if ("canceled".equals(status)) {
68-
DownloadCanceled canceled =
69-
new DownloadCanceled(browsingContextId, navigationId, timestamp, url, status);
70-
return new DownloadEnded(canceled);
71-
} else if ("complete".equals(status)) {
72-
DownloadCompleted completed =
73-
new DownloadCompleted(browsingContextId, navigationId, timestamp, url, status, filepath);
74-
return new DownloadEnded(completed);
75-
} else {
76-
throw new IllegalArgumentException(
77-
"status must be either 'canceled' or 'complete', but got: " + status);
78-
}
7945
}
8046

8147
public NavigationInfo getDownloadParams() {

0 commit comments

Comments
 (0)