-
-
Notifications
You must be signed in to change notification settings - Fork 8.6k
[java][BiDi] implement browsingContext.downloadEnd
event
#16347
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
Delta456
wants to merge
12
commits into
SeleniumHQ:trunk
Choose a base branch
from
Delta456:download_end
base: trunk
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
173391f
[java][BiDi] implement `browsingContext.downloadEnd`
Delta456 8b155ab
fmt
Delta456 08b5b6a
Update java/src/org/openqa/selenium/bidi/browsingcontext/DownloadEnde…
Delta456 f8b4a45
add imports
Delta456 97887a7
rename
Delta456 b8af810
revert old test (was accidental)
Delta456 cca9625
use consts and util.objects
Delta456 4696e57
Merge branch 'trunk' into download_end
Delta456 ffe6504
Merge branch 'trunk' into download_end
Delta456 de7731d
Merge branch 'trunk' into download_end
Delta456 98a98b0
Merge branch 'trunk' into download_end
Delta456 1be7708
Merge branch 'trunk' into download_end
Delta456 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
84 changes: 84 additions & 0 deletions
84
java/src/org/openqa/selenium/bidi/browsingcontext/DownloadCanceled.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
// Licensed to the Software Freedom Conservancy (SFC) under one | ||
// or more contributor license agreements. See the NOTICE file | ||
// distributed with this work for additional information | ||
// regarding copyright ownership. The SFC licenses this file | ||
// to you under the Apache License, Version 2.0 (the | ||
// "License"); you may not use this file except in compliance | ||
// with the License. You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, | ||
// software distributed under the License is distributed on an | ||
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
// KIND, either express or implied. See the License for the | ||
// specific language governing permissions and limitations | ||
// under the License. | ||
|
||
package org.openqa.selenium.bidi.browsingcontext; | ||
|
||
import static java.util.Objects.requireNonNullElse; | ||
|
||
import org.openqa.selenium.json.JsonInput; | ||
|
||
public class DownloadCanceled extends NavigationInfo { | ||
|
||
private final String status; | ||
|
||
private static final String CANCELED = "canceled"; | ||
|
||
DownloadCanceled( | ||
String browsingContextId, String navigationId, long timestamp, String url, String status) { | ||
super(browsingContextId, navigationId, timestamp, url); | ||
this.status = requireNonNullElse(status, CANCELED); | ||
} | ||
|
||
public static DownloadCanceled fromJson(JsonInput input) { | ||
String browsingContextId = null; | ||
String navigationId = null; | ||
long timestamp = 0; | ||
String url = null; | ||
String status = CANCELED; | ||
|
||
input.beginObject(); | ||
while (input.hasNext()) { | ||
switch (input.nextName()) { | ||
case "context": | ||
browsingContextId = input.read(String.class); | ||
break; | ||
|
||
case "navigation": | ||
navigationId = input.read(String.class); | ||
break; | ||
|
||
case "timestamp": | ||
timestamp = input.read(Long.class); | ||
break; | ||
|
||
case "url": | ||
url = input.read(String.class); | ||
break; | ||
|
||
case "status": | ||
status = input.read(String.class); | ||
if (!CANCELED.equals(status)) { | ||
throw new IllegalArgumentException( | ||
"Expected status '" + CANCELED + "' , but got: " + status); | ||
} | ||
break; | ||
|
||
default: | ||
input.skipValue(); | ||
break; | ||
} | ||
} | ||
|
||
input.endObject(); | ||
|
||
return new DownloadCanceled(browsingContextId, navigationId, timestamp, url, status); | ||
} | ||
|
||
public String getStatus() { | ||
return status; | ||
} | ||
} |
100 changes: 100 additions & 0 deletions
100
java/src/org/openqa/selenium/bidi/browsingcontext/DownloadCompleted.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,100 @@ | ||
// Licensed to the Software Freedom Conservancy (SFC) under one | ||
// or more contributor license agreements. See the NOTICE file | ||
// distributed with this work for additional information | ||
// regarding copyright ownership. The SFC licenses this file | ||
// to you under the Apache License, Version 2.0 (the | ||
// "License"); you may not use this file except in compliance | ||
// with the License. You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, | ||
// software distributed under the License is distributed on an | ||
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
// KIND, either express or implied. See the License for the | ||
// specific language governing permissions and limitations | ||
// under the License. | ||
|
||
package org.openqa.selenium.bidi.browsingcontext; | ||
|
||
import static java.util.Objects.requireNonNullElse; | ||
|
||
import org.openqa.selenium.json.JsonInput; | ||
|
||
public class DownloadCompleted extends NavigationInfo { | ||
|
||
private final String status; | ||
private final String filepath; | ||
|
||
private static final String COMPLETE = "complete"; | ||
|
||
DownloadCompleted( | ||
String browsingContextId, | ||
String navigationId, | ||
long timestamp, | ||
String url, | ||
String status, | ||
String filepath) { | ||
super(browsingContextId, navigationId, timestamp, url); | ||
this.status = requireNonNullElse(status, COMPLETE); | ||
this.filepath = filepath; | ||
} | ||
|
||
public static DownloadCompleted fromJson(JsonInput input) { | ||
String browsingContextId = null; | ||
String navigationId = null; | ||
long timestamp = 0; | ||
String url = null; | ||
String status = COMPLETE; | ||
String filepath = null; | ||
|
||
input.beginObject(); | ||
while (input.hasNext()) { | ||
switch (input.nextName()) { | ||
case "context": | ||
browsingContextId = input.read(String.class); | ||
break; | ||
|
||
case "navigation": | ||
navigationId = input.read(String.class); | ||
break; | ||
|
||
case "timestamp": | ||
timestamp = input.read(Long.class); | ||
break; | ||
|
||
case "url": | ||
url = input.read(String.class); | ||
break; | ||
|
||
case "status": | ||
status = input.read(String.class); | ||
if (!COMPLETE.equals(status)) { | ||
throw new IllegalArgumentException( | ||
"Expected status '" + COMPLETE + "' , but got: " + status); | ||
} | ||
break; | ||
|
||
case "filepath": | ||
filepath = input.read(String.class); | ||
break; | ||
|
||
default: | ||
input.skipValue(); | ||
break; | ||
} | ||
} | ||
|
||
input.endObject(); | ||
|
||
return new DownloadCompleted(browsingContextId, navigationId, timestamp, url, status, filepath); | ||
} | ||
|
||
public String getStatus() { | ||
return status; | ||
} | ||
|
||
public String getFilepath() { | ||
return filepath; | ||
} | ||
} |
64 changes: 64 additions & 0 deletions
64
java/src/org/openqa/selenium/bidi/browsingcontext/DownloadEnded.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
// Licensed to the Software Freedom Conservancy (SFC) under one | ||
// or more contributor license agreements. See the NOTICE file | ||
// distributed with this work for additional information | ||
// regarding copyright ownership. The SFC licenses this file | ||
// to you under the Apache License, Version 2.0 (the | ||
// "License"); you may not use this file except in compliance | ||
// with the License. You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, | ||
// software distributed under the License is distributed on an | ||
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
// KIND, either express or implied. See the License for the | ||
// specific language governing permissions and limitations | ||
// under the License. | ||
|
||
package org.openqa.selenium.bidi.browsingcontext; | ||
|
||
import java.io.StringReader; | ||
import java.util.Map; | ||
import org.openqa.selenium.json.Json; | ||
import org.openqa.selenium.json.JsonInput; | ||
|
||
public class DownloadEnded { | ||
|
||
private static final String CANCELED = "canceled"; | ||
private static final String COMPLETE = "complete"; | ||
|
||
private final NavigationInfo downloadParams; | ||
|
||
public DownloadEnded(NavigationInfo downloadParams) { | ||
this.downloadParams = downloadParams; | ||
} | ||
|
||
public static DownloadEnded fromJson(JsonInput input) { | ||
Map<String, Object> jsonMap = input.read(Map.class); | ||
String status = (String) jsonMap.get("status"); | ||
|
||
try (StringReader reader = new StringReader(new Json().toJson(jsonMap)); | ||
JsonInput jsonInput = new Json().newInput(reader)) { | ||
if (CANCELED.equals(status)) { | ||
return new DownloadEnded(DownloadCanceled.fromJson(jsonInput)); | ||
} else if (COMPLETE.equals(status)) { | ||
return new DownloadEnded(DownloadCompleted.fromJson(jsonInput)); | ||
} else { | ||
throw new IllegalArgumentException( | ||
"status must be either '" + CANCELED + "' or '" + COMPLETE + "', but got: " + status); | ||
} | ||
} | ||
} | ||
|
||
public NavigationInfo getDownloadParams() { | ||
return downloadParams; | ||
} | ||
|
||
public boolean isCanceled() { | ||
return downloadParams instanceof DownloadCanceled; | ||
} | ||
|
||
public boolean isCompleted() { | ||
return downloadParams instanceof DownloadCompleted; | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should we use word "canceled" or "cancelled"?
Both are correct, while "canceled" American English, and "cancelled" is British English.
I've checked that in Selenium Java code,
Status.CANCELLED
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've actually had this same discussion about this word a few times in my career :)
Unlike "color/colour", "canceled" is pretty commonly used in both American/British English, but more common in American.
Across our entire codebase, the American spelling is the winner:
However, if we exclude 3rd party code we have vendored, British spelling has a slight edge:
So, I'd call it a draw.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The spec uses
canceled
, which is a hardcore value for checking downloads.