- 
          
- 
                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
          
     Merged
      
      
    
      
        
          +291
        
        
          −0
        
        
          
        
      
    
  
  
     Merged
                    Changes from all commits
      Commits
    
    
            Show all changes
          
          
            16 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 44f6e99
              
                Merge branch 'trunk' into download_end
              
              
                Delta456 e7d996f
              
                Merge branch 'trunk' into download_end
              
              
                Delta456 785e958
              
                use single imports
              
              
                Delta456 f52ccb4
              
                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
    
  
  
    
              
      
      Oops, something went wrong.
        
    
  
  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.
  
    
  
    
Uh oh!
There was an error while loading. Please reload this page.