Skip to content

Commit

Permalink
update all of the AugmenterProvider interfaces and implementations to…
Browse files Browse the repository at this point in the history
… have the same conventions. Complete JavaDocs in interface, ImmutableMap.of for all maps, Require.nonNull in all interface implementations, etc
  • Loading branch information
titusfortner committed Sep 23, 2021
1 parent 53cbfaf commit d706012
Show file tree
Hide file tree
Showing 26 changed files with 82 additions and 47 deletions.
2 changes: 1 addition & 1 deletion java/src/org/openqa/selenium/chrome/AddHasCdp.java
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ public class AddHasCdp extends org.openqa.selenium.chromium.AddHasCdp {
@Override
public Map<String, CommandInfo> getAdditionalCommands() {
return ImmutableMap.of(
EXECUTE_CDP, new CommandInfo("session/:sessionId/goog//cdp/execute", HttpMethod.POST));
EXECUTE_CDP, new CommandInfo("session/:sessionId/goog/cdp/execute", HttpMethod.POST));
}

@Override
Expand Down
18 changes: 12 additions & 6 deletions java/src/org/openqa/selenium/chromium/AddHasCasting.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@

import com.google.common.collect.ImmutableMap;
import org.openqa.selenium.Capabilities;
import org.openqa.selenium.internal.Require;
import org.openqa.selenium.remote.AdditionalHttpCommands;
import org.openqa.selenium.remote.AugmenterProvider;
import org.openqa.selenium.remote.CommandInfo;
Expand Down Expand Up @@ -51,24 +52,29 @@ public Class<HasCasting> getDescribedInterface() {
public HasCasting getImplementation(Capabilities capabilities, ExecuteMethod executeMethod) {
return new HasCasting() {
@Override public ArrayList<Map<String, String>> getCastSinks() {
return (ArrayList<Map<String, String>>) executeMethod.execute(ChromiumDriverCommand.GET_CAST_SINKS, null);
return (ArrayList<Map<String, String>>) executeMethod.execute(GET_CAST_SINKS, null);
}

@Override public void selectCastSink(String deviceName) {
executeMethod.execute(ChromiumDriverCommand.SET_CAST_SINK_TO_USE, ImmutableMap.of("sinkName", deviceName));
Require.nonNull("Device Name", deviceName);

executeMethod.execute(SET_CAST_SINK_TO_USE, ImmutableMap.of("sinkName", deviceName));
}

@Override public void startTabMirroring(String deviceName) {
executeMethod.execute(ChromiumDriverCommand.START_CAST_TAB_MIRRORING, ImmutableMap.of("sinkName", deviceName));
Require.nonNull("Device Name", deviceName);

executeMethod.execute(START_CAST_TAB_MIRRORING, ImmutableMap.of("sinkName", deviceName));
}

@Override public String getCastIssueMessage() {
Object response = executeMethod.execute(ChromiumDriverCommand.GET_CAST_ISSUE_MESSAGE, null);
return response.toString();
return executeMethod.execute(GET_CAST_ISSUE_MESSAGE, null).toString();
}

@Override public void stopCasting(String deviceName) {
executeMethod.execute(ChromiumDriverCommand.STOP_CASTING, ImmutableMap.of("sinkName", deviceName));
Require.nonNull("Device Name", deviceName);

executeMethod.execute(STOP_CASTING, ImmutableMap.of("sinkName", deviceName));
}
};
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import com.google.auto.service.AutoService;
import com.google.common.collect.ImmutableMap;
import org.openqa.selenium.Capabilities;
import org.openqa.selenium.internal.Require;
import org.openqa.selenium.remote.AdditionalHttpCommands;
import org.openqa.selenium.remote.AugmenterProvider;
import org.openqa.selenium.remote.CommandInfo;
Expand Down Expand Up @@ -80,6 +81,8 @@ public ChromiumNetworkConditions getNetworkConditions() {

@Override
public void setNetworkConditions(ChromiumNetworkConditions networkConditions) {
Require.nonNull("Network Conditions", networkConditions);

Map<String, Object> conditions = ImmutableMap.of(ChromiumNetworkConditions.OFFLINE, networkConditions.getOffline(),
ChromiumNetworkConditions.LATENCY, networkConditions.getLatency().toMillis(),
ChromiumNetworkConditions.DOWNLOAD_THROUGHPUT, networkConditions.getDownloadThroughput(),
Expand Down
3 changes: 1 addition & 2 deletions java/src/org/openqa/selenium/chromium/ChromiumDriver.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@

package org.openqa.selenium.chromium;

import com.google.common.collect.ImmutableMap;
import org.openqa.selenium.BuildInfo;
import org.openqa.selenium.Capabilities;
import org.openqa.selenium.Credentials;
Expand Down Expand Up @@ -207,6 +206,7 @@ public void launchApp(String id) {
launch.launchApp(id);
}

@Override
public Map<String, Object> executeCdpCommand(String commandName, Map<String, Object> parameters) {
return cdp.executeCdpCommand(commandName, parameters);
}
Expand Down Expand Up @@ -253,7 +253,6 @@ public ChromiumNetworkConditions getNetworkConditions() {

@Override
public void setNetworkConditions(ChromiumNetworkConditions networkConditions) {
Require.nonNull("Network Conditions", networkConditions);
this.networkConditions.setNetworkConditions(networkConditions);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,11 @@

import com.google.common.collect.ImmutableMap;
import org.openqa.selenium.remote.CommandInfo;
import org.openqa.selenium.remote.http.HttpMethod;
import org.openqa.selenium.remote.service.DriverCommandExecutor;
import org.openqa.selenium.remote.service.DriverService;

import java.util.HashMap;
import java.util.Map;

import static java.util.Collections.unmodifiableMap;

/**
* {@link DriverCommandExecutor} that understands ChromiumDriver specific commands.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,48 +52,54 @@ public void setOffline(Boolean offline) {
}

/**
* The current simulated latency of the connection.
*
* @return
* @return amount of latency, typically a Duration of milliseconds.
*/
public Duration getLatency() {
return latency;
}

/**
* Sets the simulated latency of the connection.
*
* @param latency
* @param latency amount of latency, typically a Duration of millisceonds.
*/
public void setLatency(Duration latency) {
this.latency = latency;
}

/**
* The current throughput of the network connection in kb/second for downloading.
*
* @return
* @return the current download throughput in kb/second.
*/
public Number getDownloadThroughput() {
return downloadThroughput;
}

/**
* ets the throughput of the network connection in kb/second for downloading.
*
* @param downloadThroughput
* @param downloadThroughput thoughput in kb/second
*/
public void setDownloadThroughput(Number downloadThroughput) {
this.downloadThroughput = downloadThroughput;
}

/**
* The current throughput of the network connection in kb/second for uploading.
*
* @return
* @return the current upload throughput in kb/second.
*/
public Number getUploadThroughput() {
return uploadThroughput;
}

/**
* ets the throughput of the network connection in kb/second for uploading.
*
* @param uploadThroughput
* @param uploadThroughput thoughput in kb/second
*/
public void setUploadThroughput(Number uploadThroughput) {
this.uploadThroughput = uploadThroughput;
Expand Down
2 changes: 1 addition & 1 deletion java/src/org/openqa/selenium/chromium/HasCasting.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
import java.util.Map;

/**
* Used by classes to indicate that they can install and uninstall browser extensions on the fly.
* Used by classes to indicate that they can cast devices to available sink targets.
*/
@Beta
public interface HasCasting {
Expand Down
7 changes: 3 additions & 4 deletions java/src/org/openqa/selenium/chromium/HasCdp.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,17 +19,16 @@

import org.openqa.selenium.Beta;

import java.util.ArrayList;
import java.util.Map;

/**
* Used by classes to indicate that they can install and uninstall browser extensions on the fly.
* Used by classes to indicate that they can execute Command DevTools commands.
*/
@Beta
public interface HasCdp {

/**
* Execute a Chrome Devtools Protocol command and get returned result. The
* Execute a Chrome DevTools Protocol command and get returned result. The
* command and command args should follow
* <a href="https://chromedevtools.github.io/devtools-protocol/">chrome
* devtools protocol domains/commands</a>.
Expand All @@ -38,7 +37,7 @@ public interface HasCdp {
*
* @param commandName the command to execute with Chrome Dev Tools.
* @param parameters any information needed to execute the Dev Tools command.
* @return
* @return the name and value of the response.
*/
public Map<String, Object> executeCdpCommand(String commandName, Map<String, Object> parameters);
}
3 changes: 3 additions & 0 deletions java/src/org/openqa/selenium/chromium/HasLaunchApp.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@

import org.openqa.selenium.Beta;

/**
* Used by classes to indicate that they can launch a Chromium app.
*/
@Beta
public interface HasLaunchApp {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
import org.openqa.selenium.Beta;

/**
* Used by classes to indicate that they can install and uninstall browser extensions on the fly.
* Used by classes to indicate that they can simulate different network conditions.
*/
@Beta
public interface HasNetworkConditions {
Expand All @@ -40,6 +40,9 @@ public interface HasNetworkConditions {
*/
void setNetworkConditions(ChromiumNetworkConditions networkConditions);

/**
* Resets the network conditions to the default settings.
*/
void deleteNetworkConditions();

}
7 changes: 4 additions & 3 deletions java/src/org/openqa/selenium/chromium/HasPermissions.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,15 @@

import org.openqa.selenium.Beta;

import java.util.Map;

/**
* Used by classes to indicate that they can adjust permissions compatible items.
*/
@Beta
public interface HasPermissions {

/**
*
* @param name what permission to set.
* @param name what item to set the permission on.
* @param value what to set the permission to.
*/
public void setPermission(String name, String value);
Expand Down
2 changes: 1 addition & 1 deletion java/src/org/openqa/selenium/edge/AddHasCdp.java
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
public class AddHasCdp extends org.openqa.selenium.chromium.AddHasCdp {

private static final Map<String, CommandInfo> COMMANDS = ImmutableMap.of(
EXECUTE_CDP, new CommandInfo("session/:sessionId/ms//cdp/execute", HttpMethod.POST));
EXECUTE_CDP, new CommandInfo("session/:sessionId/ms/cdp/execute", HttpMethod.POST));

@Override
public Map<String, CommandInfo> getAdditionalCommands() {
Expand Down
3 changes: 3 additions & 0 deletions java/src/org/openqa/selenium/firefox/AddHasContext.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import com.google.auto.service.AutoService;
import com.google.common.collect.ImmutableMap;
import org.openqa.selenium.Capabilities;
import org.openqa.selenium.internal.Require;
import org.openqa.selenium.remote.AdditionalHttpCommands;
import org.openqa.selenium.remote.AugmenterProvider;
import org.openqa.selenium.remote.CommandInfo;
Expand Down Expand Up @@ -59,6 +60,8 @@ public HasContext getImplementation(Capabilities capabilities, ExecuteMethod exe
return new HasContext() {
@Override
public void setContext(FirefoxCommandContext context) {
Require.nonNull("Firefox Command Context", context);

executeMethod.execute(
CONTEXT,
ImmutableMap.of(CONTEXT, context));
Expand Down
10 changes: 7 additions & 3 deletions java/src/org/openqa/selenium/firefox/AddHasExtensions.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import com.google.auto.service.AutoService;
import com.google.common.collect.ImmutableMap;
import org.openqa.selenium.Capabilities;
import org.openqa.selenium.internal.Require;
import org.openqa.selenium.remote.AdditionalHttpCommands;
import org.openqa.selenium.remote.AugmenterProvider;
import org.openqa.selenium.remote.CommandInfo;
Expand All @@ -40,7 +41,7 @@ public class AddHasExtensions implements AugmenterProvider<HasExtensions>, Addit
public static final String UNINSTALL_EXTENSION = "uninstallExtension";

private static final Map<String, CommandInfo> COMMANDS = ImmutableMap.of(
INSTALL_EXTENSION, new CommandInfo("/session/:sessionId/moz/addon/install",HttpMethod.POST),
INSTALL_EXTENSION, new CommandInfo("/session/:sessionId/moz/addon/install", HttpMethod.POST),
UNINSTALL_EXTENSION, new CommandInfo("/session/:sessionId/moz/addon/uninstall", HttpMethod.POST));

@Override
Expand All @@ -63,15 +64,18 @@ public HasExtensions getImplementation(Capabilities capabilities, ExecuteMethod
return new HasExtensions() {
@Override
public String installExtension(Path path) {
Require.nonNull("Extension Path", path);

return (String) executeMethod.execute(
INSTALL_EXTENSION,
ImmutableMap.of("path", path.toAbsolutePath().toString(), "temporary", false));

}

@Override
public void uninstallExtension(String extensionId) {
executeMethod.execute(UNINSTALL_EXTENSION, singletonMap("id", extensionId));
Require.nonNull("Extension ID", extensionId);

executeMethod.execute(UNINSTALL_EXTENSION, ImmutableMap.of("id", extensionId));
}
};
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import com.google.common.collect.ImmutableMap;
import org.openqa.selenium.Capabilities;
import org.openqa.selenium.OutputType;
import org.openqa.selenium.internal.Require;
import org.openqa.selenium.remote.AdditionalHttpCommands;
import org.openqa.selenium.remote.AugmenterProvider;
import org.openqa.selenium.remote.CommandInfo;
Expand Down Expand Up @@ -60,6 +61,8 @@ public HasFullPageScreenshot getImplementation(Capabilities capabilities, Execut
return new HasFullPageScreenshot() {
@Override
public <X> X getFullPageScreenshotAs(OutputType<X> outputType) {
Require.nonNull("Output Type", outputType);

Object result = executeMethod.execute(FULL_PAGE_SCREENSHOT, null);

if (result instanceof String) {
Expand Down
2 changes: 0 additions & 2 deletions java/src/org/openqa/selenium/firefox/FirefoxDriver.java
Original file line number Diff line number Diff line change
Expand Up @@ -265,13 +265,11 @@ private static boolean isLegacy(Capabilities desiredCapabilities) {

@Override
public String installExtension(Path path) {
Require.nonNull("Path", path);
return extensions.installExtension(path);
}

@Override
public void uninstallExtension(String extensionId) {
Require.nonNull("Extension ID", extensionId);
extensions.uninstallExtension(extensionId);
}

Expand Down
2 changes: 1 addition & 1 deletion java/src/org/openqa/selenium/firefox/HasContext.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
import org.openqa.selenium.Beta;

/**
* Used by classes to indicate that they can install and uninstall browser extensions on the fly.
* Used by classes to indicate that they can change the context commands operate in.
*/
@Beta
public interface HasContext {
Expand Down
1 change: 1 addition & 0 deletions java/src/org/openqa/selenium/firefox/HasExtensions.java
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ public interface HasExtensions {

/**
* Uninstall the extension by the given identifier.
* This value can be found in the extension's manifest, and typically ends with "@mozilla.org".
*
* @param extensionId The unique extension identifier returned by {{@link #installExtension(Path)}}
*/
Expand Down
2 changes: 1 addition & 1 deletion java/src/org/openqa/selenium/safari/AddHasDebugger.java
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ public HasDebugger getImplementation(Capabilities capabilities, ExecuteMethod ex
return new HasDebugger() {
@Override
public void attachDebugger() {
executeMethod.execute(ATTACH_DEBUGGER, singletonMap(ATTACH_DEBUGGER, null));
executeMethod.execute(ATTACH_DEBUGGER, ImmutableMap.of(ATTACH_DEBUGGER, null));
}
};
}
Expand Down
4 changes: 2 additions & 2 deletions java/src/org/openqa/selenium/safari/AddHasPermissions.java
Original file line number Diff line number Diff line change
Expand Up @@ -61,12 +61,12 @@ public HasPermissions getImplementation(Capabilities capabilities, ExecuteMethod
return new HasPermissions() {
@Override
public void setPermissions(String permission, Boolean value) {
executeMethod.execute(SET_PERMISSIONS, singletonMap("permissions", singletonMap(permission, value)));
executeMethod.execute(SET_PERMISSIONS, ImmutableMap.of("permissions", ImmutableMap.of(permission, value)));
}

@Override
public Map<String, Boolean> getPermissions() {
Map<String, Object> results = (Map<String, Object>) executeMethod.execute(GET_PERMISSIONS, singletonMap("permissions", null));
Map<String, Object> results = (Map<String, Object>) executeMethod.execute(GET_PERMISSIONS, ImmutableMap.of("permissions", null));
return (Map<String, Boolean>) results.get("permissions");
}
};
Expand Down
Loading

0 comments on commit d706012

Please sign in to comment.