Skip to content
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

[bidi][java] Add Permissions Module commands #15294

Merged
merged 7 commits into from
Mar 20, 2025

Conversation

pujagani
Copy link
Contributor

@pujagani pujagani commented Feb 17, 2025

User description

Thanks for contributing to Selenium!
A PR well described will help maintainers to quickly review and merge it

Before submitting your PR, please check our contributing guidelines.
Avoid large PRs, help reviewers by making them as simple and short as possible.

Motivation and Context

Add commands from extension module permissions as stated in the spec https://www.w3.org/TR/permissions/#automation-webdriver-bidi

Types of changes

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)

Checklist

  • I have read the contributing document.
  • My change requires a change to the documentation.
  • I have updated the documentation accordingly.
  • I have added tests to cover my changes.
  • All new and existing tests passed.

PR Type

Enhancement, Tests


Description

  • Added BiDi Permissions module to manage browser permissions.

  • Introduced PermissionState enum for permission states.

  • Implemented tests for setting and verifying permissions.

  • Updated Bazel build files to include new permissions module.


Changes walkthrough 📝

Relevant files
Enhancement
2 files
Permission.java
Introduced BiDi Permissions module for managing permissions.
+70/-0   
PermissionState.java
Added `PermissionState` enum for permission states.           
+46/-0   
Tests
1 files
PermissionsTest.java
Added tests for BiDi Permissions module functionality.     
+172/-0 
Configuration changes
5 files
BUILD.bazel
Updated Bazel build file to include permissions module.   
+1/-0     
BUILD.bazel
Added Bazel build file for permissions module.                     
+17/-0   
BUILD.bazel
Updated Bazel build file to export permissions module.     
+1/-0     
BUILD.bazel
Updated Bazel test suite to include permissions module.   
+1/-0     
BUILD.bazel
Added Bazel test suite for permissions module tests.         
+41/-0   

Need help?
  • Type /help how to ... in the comments thread for any questions about Qodo Merge usage.
  • Check out the documentation for more information.
  • @pujagani pujagani marked this pull request as ready for review March 19, 2025 11:35
    Copy link
    Contributor

    PR Reviewer Guide 🔍

    Here are some key observations to aid the review process:

    ⏱️ Estimated effort to review: 2 🔵🔵⚪⚪⚪
    🧪 PR contains tests
    🔒 No security concerns identified
    ⚡ Recommended focus areas for review

    Error Handling

    The setPermission method doesn't handle potential errors from the BiDi protocol. Consider adding error handling or documenting exceptions that might be thrown.

    public void setPermission(
        Map<String, String> permissionDescriptor, PermissionState state, String origin) {
      this.setPermission(permissionDescriptor, state, origin, null);
    }
    
    public void setPermission(
        Map<String, String> permissionDescriptor,
        PermissionState state,
        String origin,
        String userContext) {
      Require.nonNull("Permission descriptor", permissionDescriptor);
      Require.nonNull("Permission state", state);
      Require.nonNull("Origin", origin);
    
      Map<String, Object> params =
          new HashMap<>(
              Map.of(
                  "descriptor", permissionDescriptor,
                  "state", state.toString(),
                  "origin", origin));
    
      if (userContext != null) {
        params.put("userContext", userContext);
      }
    
      this.bidi.send(new Command<>("permissions.setPermission", params));
    }
    Null Return

    The findByName method can return null if no matching state is found. Consider throwing an IllegalArgumentException instead or documenting this behavior.

    public static PermissionState findByName(String name) {
      PermissionState result = null;
      for (PermissionState state : values()) {
        if (state.toString().equalsIgnoreCase(name)) {
          result = state;
          break;
        }
      }
      return result;
    }

    Copy link
    Contributor

    qodo-merge-pro bot commented Mar 19, 2025

    PR Code Suggestions ✨

    Explore these optional code suggestions:

    CategorySuggestion                                                                                                                                    Impact
    Possible issue
    Handle invalid permission states

    The findByName method can return null if no matching state is found. This could
    lead to NullPointerExceptions when the method is used. Consider throwing an
    IllegalArgumentException for invalid names or using Optional as the return type.

    java/src/org/openqa/selenium/bidi/permissions/PermissionState.java [36-45]

     public static PermissionState findByName(String name) {
    -  PermissionState result = null;
       for (PermissionState state : values()) {
         if (state.toString().equalsIgnoreCase(name)) {
    -      result = state;
    -      break;
    +      return state;
         }
       }
    -  return result;
    +  throw new IllegalArgumentException("No permission state found with name: " + name);
     }
    • Apply this suggestion
    Suggestion importance[1-10]: 8

    __

    Why: The suggestion addresses a potential null pointer exception by replacing the current implementation that returns null with one that throws a descriptive IllegalArgumentException. This is a significant improvement for error handling as it provides immediate feedback about invalid inputs rather than causing failures later in the execution flow.

    Medium
    • Update

    @pujagani pujagani merged commit 265df15 into SeleniumHQ:trunk Mar 20, 2025
    34 checks passed
    sandeepsuryaprasad pushed a commit to sandeepsuryaprasad/selenium that referenced this pull request Mar 23, 2025
    Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
    Projects
    None yet
    Development

    Successfully merging this pull request may close these issues.

    1 participant