Skip to content

Commit abd81d0

Browse files
authored
[bid] [java] Add BiDi Input module release command (#13362)
1 parent 2cd2720 commit abd81d0

File tree

5 files changed

+188
-2
lines changed

5 files changed

+188
-2
lines changed
Lines changed: 107 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,107 @@
1+
<!-- The code here is taken from WPT BiDi Tests repo https://github.com/web-platform-tests/wpt/blob/master/webdriver/tests/support/html/test_actions.html-->
2+
<!-- Giving thanks to the folks contributing to https://github.com/web-platform-tests/wpt/tree/master/webdriver/tests/bidi Thank you! -->
3+
<!doctype html>
4+
<meta charset=utf-8>
5+
<html>
6+
<head>
7+
8+
<title>Test Actions</title>
9+
<p> This HTML page is taken from <a href="https://github.com/web-platform-tests/wpt/blob/master/webdriver/tests/support/html/test_actions.html">WPT BiDi Tests.</a> Thank you so much folks at <a href="https://github.com/web-platform-tests/wpt/"> web-platform-tests </a> for your contribution!</p>
10+
11+
<style>
12+
div { padding: 0; margin: 0; }
13+
#trackPointer { position: fixed; }
14+
#resultContainer { width: 600px; height: 60px; }
15+
.area { width: 100px; height: 50px; background-color: #ccc; }
16+
.block { width: 5px; height: 5px; border: solid 1px red; }
17+
.box { display: flex;}
18+
#dragArea { position: relative; }
19+
#dragTarget { position: absolute; top:22px; left:47px;}
20+
</style>
21+
<script>
22+
"use strict";
23+
var els = {};
24+
var allEvents = { events: [] };
25+
function displayMessage(message) {
26+
document.getElementById("events").innerHTML = "<p>" + message + "</p>";
27+
}
28+
29+
function appendMessage(message) {
30+
document.getElementById("events").innerHTML += "<p>" + message + "</p>";
31+
}
32+
33+
/**
34+
* Escape |key| if it's in a surrogate-half character range.
35+
*
36+
* Example: given "\ud83d" return "U+d83d".
37+
*
38+
* Otherwise JSON.stringify will convert it to U+FFFD (REPLACEMENT CHARACTER)
39+
* when returning a value from executeScript, for example.
40+
*/
41+
function escapeSurrogateHalf(key) {
42+
if (typeof key !== "undefined" && key.length === 1) {
43+
var charCode = key.charCodeAt(0);
44+
var highSurrogate = charCode >= 0xD800 && charCode <= 0xDBFF;
45+
var surrogate = highSurrogate || (charCode >= 0xDC00 && charCode <= 0xDFFF);
46+
if (surrogate) {
47+
key = "U+" + charCode.toString(16);
48+
}
49+
}
50+
return key;
51+
}
52+
53+
function recordKeyboardEvent(event) {
54+
var key = escapeSurrogateHalf(event.key);
55+
allEvents.events.push({
56+
"code": event.code,
57+
"key": key,
58+
"which": event.which,
59+
"location": event.location,
60+
"ctrl": event.ctrlKey,
61+
"meta": event.metaKey,
62+
"shift": event.shiftKey,
63+
"repeat": event.repeat,
64+
"type": event.type
65+
});
66+
appendMessage(event.type + " " +
67+
"code: " + event.code + ", " +
68+
"key: " + key + ", " +
69+
"which: " + event.which + ", " +
70+
"keyCode: " + event.keyCode);
71+
}
72+
73+
74+
function resetEvents() {
75+
allEvents.events.length = 0;
76+
displayMessage("");
77+
}
78+
79+
function drop(moveHandler) {
80+
return function (event) {
81+
els.dragArea.removeEventListener("mousemove", moveHandler);
82+
els.dragTarget.style.backgroundColor = "yellow";
83+
els.dragTarget.addEventListener("mousedown", grab);
84+
recordPointerEvent(event);
85+
};
86+
}
87+
88+
89+
document.addEventListener("DOMContentLoaded", function() {
90+
var keyReporter = document.getElementById("keys");
91+
keyReporter.addEventListener("keyup", recordKeyboardEvent);
92+
keyReporter.addEventListener("keypress", recordKeyboardEvent);
93+
keyReporter.addEventListener("keydown", recordKeyboardEvent);
94+
});
95+
</script>
96+
</head>
97+
<body>
98+
<div>
99+
<h2>KeyReporter</h2>
100+
<input type="text" id="keys" size="80">
101+
</div>
102+
<div id="resultContainer">
103+
<h2>Events</h2>
104+
<div id="events"></div>
105+
</div>
106+
</body>
107+
</html>

java/src/org/openqa/selenium/bidi/Input.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,4 +80,8 @@ public void perform(String browsingContext, Collection<Sequence> actions) {
8080
"context", browsingContext,
8181
"actions", encodedActions)));
8282
}
83+
84+
public void release(String browsingContext) {
85+
bidi.send(new Command<>("input.releaseActions", Map.of("context", browsingContext)));
86+
}
8387
}

java/test/org/openqa/selenium/bidi/input/CombinedInputActionsTest.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,6 @@
3535
import java.util.ArrayList;
3636
import java.util.List;
3737
import java.util.Optional;
38-
3938
import org.junit.jupiter.api.BeforeEach;
4039
import org.junit.jupiter.api.Test;
4140
import org.openqa.selenium.By;

java/test/org/openqa/selenium/bidi/input/DefaultMouseTest.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,6 @@
3434
import java.util.ArrayList;
3535
import java.util.List;
3636
import java.util.Optional;
37-
3837
import org.junit.jupiter.api.BeforeEach;
3938
import org.junit.jupiter.api.Test;
4039
import org.openqa.selenium.By;
Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
// Licensed to the Software Freedom Conservancy (SFC) under one
2+
// or more contributor license agreements. See the NOTICE file
3+
// distributed with this work for additional information
4+
// regarding copyright ownership. The SFC licenses this file
5+
// to you under the Apache License, Version 2.0 (the
6+
// "License"); you may not use this file except in compliance
7+
// with the License. You may obtain a copy of the License at
8+
//
9+
// http://www.apache.org/licenses/LICENSE-2.0
10+
//
11+
// Unless required by applicable law or agreed to in writing,
12+
// software distributed under the License is distributed on an
13+
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14+
// KIND, either express or implied. See the License for the
15+
// specific language governing permissions and limitations
16+
// under the License.
17+
18+
package org.openqa.selenium.bidi.input;
19+
20+
import static org.assertj.core.api.Assertions.assertThat;
21+
import static org.openqa.selenium.testing.drivers.Browser.EDGE;
22+
import static org.openqa.selenium.testing.drivers.Browser.IE;
23+
import static org.openqa.selenium.testing.drivers.Browser.SAFARI;
24+
25+
import java.util.List;
26+
import java.util.Map;
27+
import org.junit.jupiter.api.BeforeEach;
28+
import org.junit.jupiter.api.Test;
29+
import org.openqa.selenium.By;
30+
import org.openqa.selenium.JavascriptExecutor;
31+
import org.openqa.selenium.WebElement;
32+
import org.openqa.selenium.bidi.Input;
33+
import org.openqa.selenium.environment.webserver.AppServer;
34+
import org.openqa.selenium.environment.webserver.NettyAppServer;
35+
import org.openqa.selenium.interactions.Actions;
36+
import org.openqa.selenium.testing.JupiterTestBase;
37+
import org.openqa.selenium.testing.NotYetImplemented;
38+
39+
public class ReleaseCommandTest extends JupiterTestBase {
40+
private Input input;
41+
42+
private String windowHandle;
43+
44+
private AppServer server;
45+
46+
@BeforeEach
47+
public void setUp() {
48+
windowHandle = driver.getWindowHandle();
49+
input = new Input(driver);
50+
server = new NettyAppServer();
51+
server.start();
52+
}
53+
54+
@Test
55+
@NotYetImplemented(SAFARI)
56+
@NotYetImplemented(IE)
57+
@NotYetImplemented(EDGE)
58+
public void testReleaseInBrowsingContext() {
59+
driver.get(server.whereIs("/bidi/release_action.html"));
60+
61+
WebElement inputTextBox = driver.findElement(By.id("keys"));
62+
63+
Actions sendLowercase =
64+
new Actions(driver).keyDown(inputTextBox, "a").keyDown(inputTextBox, "b");
65+
66+
input.perform(windowHandle, sendLowercase.getSequences());
67+
((JavascriptExecutor) driver).executeScript("resetEvents()");
68+
69+
input.release(windowHandle);
70+
71+
List<Map<String, Object>> events =
72+
(List<Map<String, Object>>)
73+
((JavascriptExecutor) driver).executeScript("return allEvents.events");
74+
assertThat(events.get(0).get("code")).isEqualTo("KeyB");
75+
assertThat(events.get(1).get("code")).isEqualTo("KeyA");
76+
}
77+
}

0 commit comments

Comments
 (0)