-
-
Notifications
You must be signed in to change notification settings - Fork 8.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Scaffolding for implementing the W3C Actions APIs.
Try and do this with minimal impact on the existing classes, other than adding the implementation. This allows us to make the switch to the new API lighter and easier to rollback without losing everything if we discover we've Made A Terrible Mistake somewhere in our implementation.
- Loading branch information
Showing
15 changed files
with
669 additions
and
3 deletions.
There are no files selected for viewing
This file contains 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 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
29 changes: 29 additions & 0 deletions
29
java/client/src/org/openqa/selenium/interactions/Encodable.java
This file contains 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,29 @@ | ||
// 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.interactions; | ||
|
||
import java.util.Map; | ||
|
||
/** | ||
* This interface allows a custom {@link Interaction} to be JSON encoded for the W3C wire format. It | ||
* should not normally be exposed or used by user-facing APIs. Instead, these should traffic in the | ||
* {@link Interaction} interface. | ||
*/ | ||
public interface Encodable { | ||
Map<String, Object> encode(); | ||
} |
26 changes: 26 additions & 0 deletions
26
java/client/src/org/openqa/selenium/interactions/InputSource.java
This file contains 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,26 @@ | ||
// 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.interactions; | ||
|
||
/** | ||
* Models an <a href="https://www.w3.org/TR/webdriver/#dfn-input-source">input source</a> as defined | ||
* and used by the W3C WebDriver spec. | ||
*/ | ||
public interface InputSource { | ||
SourceType getInputType(); | ||
} |
43 changes: 43 additions & 0 deletions
43
java/client/src/org/openqa/selenium/interactions/Interaction.java
This file contains 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,43 @@ | ||
// 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.interactions; | ||
|
||
/** | ||
* Used as the basis of {@link Sequence}s for the W3C WebDriver spec | ||
* <a href="https://www.w3.org/TR/webdriver/#actions">Action commands</a>. | ||
*/ | ||
public abstract class Interaction { | ||
|
||
private final InputSource source; | ||
|
||
protected Interaction(InputSource source) { | ||
// Avoiding a guava dependency. | ||
if (source == null) { | ||
throw new NullPointerException("Input source must not be null"); | ||
} | ||
this.source = source; | ||
} | ||
|
||
protected boolean isValidFor(SourceType sourceType) { | ||
return source.getInputType() == sourceType; | ||
} | ||
|
||
public InputSource getSource() { | ||
return source; | ||
} | ||
} |
29 changes: 29 additions & 0 deletions
29
java/client/src/org/openqa/selenium/interactions/Interactive.java
This file contains 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,29 @@ | ||
// 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.interactions; | ||
|
||
import java.util.Collection; | ||
|
||
/** | ||
* Indicates that a class can be used with the W3C WebDriver | ||
* <a href="https://www.w3.org/TR/webdriver/#actions">Actions commands</a>. | ||
*/ | ||
public interface Interactive { | ||
void perform(Collection<Sequence> actions); | ||
void resetInputState(); | ||
} |
30 changes: 30 additions & 0 deletions
30
java/client/src/org/openqa/selenium/interactions/IsInteraction.java
This file contains 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,30 @@ | ||
// 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.interactions; | ||
|
||
import org.openqa.selenium.Beta; | ||
|
||
import java.util.List; | ||
|
||
/** | ||
* Interface to help us transition code to The New World | ||
*/ | ||
@Beta | ||
public interface IsInteraction { | ||
List<Interaction> asInteractions(PointerInput mouse, KeyInput keyboard); | ||
} |
81 changes: 81 additions & 0 deletions
81
java/client/src/org/openqa/selenium/interactions/KeyInput.java
This file contains 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,81 @@ | ||
// 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.interactions; | ||
|
||
import java.util.HashMap; | ||
import java.util.Map; | ||
import java.util.Optional; | ||
import java.util.UUID; | ||
|
||
/** | ||
* Models a <a href="https://www.w3.org/TR/webdriver/#dfn-key-input-source">key input source</a>. | ||
*/ | ||
public class KeyInput implements InputSource, Encodable { | ||
|
||
private final String name; | ||
|
||
public KeyInput(Optional<String> name) { | ||
this.name = name.orElse(UUID.randomUUID().toString()); | ||
} | ||
|
||
@Override | ||
public SourceType getInputType() { | ||
return SourceType.KEY; | ||
} | ||
|
||
public Interaction createKeyDown(int codePoint) { | ||
return new TypingInteraction(this, "keyDown", codePoint); | ||
} | ||
|
||
public Interaction createKeyUp(int codePoint) { | ||
return new TypingInteraction(this, "keyUp", codePoint); | ||
} | ||
|
||
@Override | ||
public Map<String, Object> encode() { | ||
Map<String, Object> toReturn = new HashMap<>(); | ||
|
||
toReturn.put("type", "key"); | ||
toReturn.put("id", name); | ||
|
||
return toReturn; | ||
} | ||
|
||
private static class TypingInteraction extends Interaction implements Encodable { | ||
|
||
private final String type; | ||
private final String value; | ||
|
||
TypingInteraction(InputSource source, String type, int codePoint) { | ||
super(source); | ||
|
||
this.type = type; | ||
this.value = new StringBuilder().appendCodePoint(codePoint).toString(); | ||
} | ||
|
||
@Override | ||
public Map<String, Object> encode() { | ||
HashMap<String, Object> toReturn = new HashMap<>(); | ||
|
||
toReturn.put("type", type); | ||
toReturn.put("value", value); | ||
|
||
return toReturn; | ||
} | ||
} | ||
} |
59 changes: 59 additions & 0 deletions
59
java/client/src/org/openqa/selenium/interactions/Pause.java
This file contains 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,59 @@ | ||
// 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.interactions; | ||
|
||
import java.time.Duration; | ||
import java.util.HashMap; | ||
import java.util.Map; | ||
|
||
/** | ||
* Indicates that a given {@link InputSource} should pause for a given duration. | ||
*/ | ||
public class Pause extends Interaction implements Encodable { | ||
|
||
private final Duration duration; | ||
|
||
/** | ||
* @param duration If 0, this means "wait until all other actions in the tick have been | ||
* evaluated". Must be greater than 0. | ||
*/ | ||
// TODO(simons): Reduce visibility? | ||
public Pause(InputSource device, Duration duration) { | ||
super(device); | ||
|
||
if (duration.isNegative()) { | ||
throw new IllegalStateException("Duration must be set to 0 or more: " + duration); | ||
} | ||
this.duration = duration; | ||
} | ||
|
||
@Override | ||
protected boolean isValidFor(SourceType sourceType) { | ||
return true; | ||
} | ||
|
||
@Override | ||
public Map<String, Object> encode() { | ||
Map<String, Object> toReturn = new HashMap<>(); | ||
|
||
toReturn.put("type", "pause"); | ||
toReturn.put("duration", duration.toMillis()); | ||
|
||
return toReturn; | ||
} | ||
} |
Oops, something went wrong.