chore(generator): use case-sensitive event names from upstream (#257)

This commit is contained in:
Yury Semikhatsky 2021-02-04 11:55:36 -08:00 committed by GitHub
parent f99d6643cd
commit eebb223bc3
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
10 changed files with 39 additions and 82 deletions

View File

@ -723,7 +723,7 @@ public interface ElementHandle extends JSHandle {
* @param selector A selector to query for. See [working with selectors](./selectors.md) for more details.
* @param expression JavaScript expression to be evaluated in the browser context. If it looks like a function declaration, it is interpreted
* as a function. Otherwise, evaluated as an expression.
* @param arg Optional argument to pass to {@code expression}
* @param arg Optional argument to pass to {@code expression}.
*/
Object evalOnSelector(String selector, String expression, Object arg);
default Object evalOnSelectorAll(String selector, String expression) {
@ -742,7 +742,7 @@ public interface ElementHandle extends JSHandle {
* @param selector A selector to query for. See [working with selectors](./selectors.md) for more details.
* @param expression JavaScript expression to be evaluated in the browser context. If it looks like a function declaration, it is interpreted
* as a function. Otherwise, evaluated as an expression.
* @param arg Optional argument to pass to {@code expression}
* @param arg Optional argument to pass to {@code expression}.
*/
Object evalOnSelectorAll(String selector, String expression, Object arg);
default void fill(String value) {

View File

@ -20,7 +20,7 @@ import java.nio.file.Path;
import java.util.*;
/**
* {@code FileChooser} objects are dispatched by the page in the [{@code event: Page.filechooser}] event.
* {@code FileChooser} objects are dispatched by the page in the [{@code event: Page.fileChooser}] event.
*/
public interface FileChooser {
class FilePayload {

View File

@ -26,10 +26,10 @@ import java.util.regex.Pattern;
* [{@code method: Frame.childFrames}] methods.
*
* <p> {@code Frame} object's lifecycle is controlled by three events, dispatched on the page object:
* - [{@code event: Page.frameattached}] - fired when the frame gets attached to the page. A Frame can be attached to the page
* - [{@code event: Page.frameAttached}] - fired when the frame gets attached to the page. A Frame can be attached to the page
* only once.
* - [{@code event: Page.framenavigated}] - fired when the frame commits navigation to a different URL.
* - [{@code event: Page.framedetached}] - fired when the frame gets detached from the page. A Frame can be detached from the
* - [{@code event: Page.frameNavigated}] - fired when the frame commits navigation to a different URL.
* - [{@code event: Page.frameDetached}] - fired when the frame gets detached from the page. A Frame can be detached from the
* page only once.
*/
public interface Frame {
@ -983,7 +983,7 @@ public interface Frame {
* @param selector A selector to query for. See [working with selectors](./selectors.md) for more details.
* @param expression JavaScript expression to be evaluated in the browser context. If it looks like a function declaration, it is interpreted
* as a function. Otherwise, evaluated as an expression.
* @param arg Optional argument to pass to {@code expression}
* @param arg Optional argument to pass to {@code expression}.
*/
Object evalOnSelector(String selector, String expression, Object arg);
default Object evalOnSelectorAll(String selector, String expression) {
@ -1002,7 +1002,7 @@ public interface Frame {
* @param selector A selector to query for. See [working with selectors](./selectors.md) for more details.
* @param expression JavaScript expression to be evaluated in the browser context. If it looks like a function declaration, it is interpreted
* as a function. Otherwise, evaluated as an expression.
* @param arg Optional argument to pass to {@code expression}
* @param arg Optional argument to pass to {@code expression}.
*/
Object evalOnSelectorAll(String selector, String expression, Object arg);
default Object evaluate(String expression) {
@ -1025,7 +1025,7 @@ public interface Frame {
*
* @param expression JavaScript expression to be evaluated in the browser context. If it looks like a function declaration, it is interpreted
* as a function. Otherwise, evaluated as an expression.
* @param arg Optional argument to pass to {@code expression}
* @param arg Optional argument to pass to {@code expression}.
*/
Object evaluate(String expression, Object arg);
default JSHandle evaluateHandle(String expression) {
@ -1047,7 +1047,7 @@ public interface Frame {
*
* @param expression JavaScript expression to be evaluated in the browser context. If it looks like a function declaration, it is interpreted
* as a function. Otherwise, evaluated as an expression.
* @param arg Optional argument to pass to {@code expression}
* @param arg Optional argument to pass to {@code expression}.
*/
JSHandle evaluateHandle(String expression, Object arg);
default void fill(String selector, String value) {
@ -1459,7 +1459,7 @@ public interface Frame {
*
* @param expression JavaScript expression to be evaluated in the browser context. If it looks like a function declaration, it is interpreted
* as a function. Otherwise, evaluated as an expression.
* @param arg Optional argument to pass to {@code expression}
* @param arg Optional argument to pass to {@code expression}.
*/
JSHandle waitForFunction(String expression, Object arg, WaitForFunctionOptions options);
default void waitForLoadState(LoadState state) {

View File

@ -51,7 +51,7 @@ public interface JSHandle {
*
* @param expression JavaScript expression to be evaluated in the browser context. If it looks like a function declaration, it is interpreted
* as a function. Otherwise, evaluated as an expression.
* @param arg Optional argument to pass to {@code expression}
* @param arg Optional argument to pass to {@code expression}.
*/
Object evaluate(String expression, Object arg);
default JSHandle evaluateHandle(String expression) {
@ -72,7 +72,7 @@ public interface JSHandle {
*
* @param expression JavaScript expression to be evaluated in the browser context. If it looks like a function declaration, it is interpreted
* as a function. Otherwise, evaluated as an expression.
* @param arg Optional argument to pass to {@code expression}
* @param arg Optional argument to pass to {@code expression}.
*/
JSHandle evaluateHandle(String expression, Object arg);
/**

View File

@ -1664,7 +1664,7 @@ public interface Page extends AutoCloseable {
* @param selector A selector to query for. See [working with selectors](./selectors.md) for more details.
* @param expression JavaScript expression to be evaluated in the browser context. If it looks like a function declaration, it is interpreted
* as a function. Otherwise, evaluated as an expression.
* @param arg Optional argument to pass to {@code expression}
* @param arg Optional argument to pass to {@code expression}.
*/
Object evalOnSelector(String selector, String expression, Object arg);
default Object evalOnSelectorAll(String selector, String expression) {
@ -1681,7 +1681,7 @@ public interface Page extends AutoCloseable {
* @param selector A selector to query for. See [working with selectors](./selectors.md) for more details.
* @param expression JavaScript expression to be evaluated in the browser context. If it looks like a function declaration, it is interpreted
* as a function. Otherwise, evaluated as an expression.
* @param arg Optional argument to pass to {@code expression}
* @param arg Optional argument to pass to {@code expression}.
*/
Object evalOnSelectorAll(String selector, String expression, Object arg);
default Object evaluate(String expression) {
@ -1707,7 +1707,7 @@ public interface Page extends AutoCloseable {
*
* @param expression JavaScript expression to be evaluated in the browser context. If it looks like a function declaration, it is interpreted
* as a function. Otherwise, evaluated as an expression.
* @param arg Optional argument to pass to {@code expression}
* @param arg Optional argument to pass to {@code expression}.
*/
Object evaluate(String expression, Object arg);
default JSHandle evaluateHandle(String expression) {
@ -1729,7 +1729,7 @@ public interface Page extends AutoCloseable {
*
* @param expression JavaScript expression to be evaluated in the browser context. If it looks like a function declaration, it is interpreted
* as a function. Otherwise, evaluated as an expression.
* @param arg Optional argument to pass to {@code expression}
* @param arg Optional argument to pass to {@code expression}.
*/
JSHandle evaluateHandle(String expression, Object arg);
default void exposeBinding(String name, Binding callback) {
@ -2365,7 +2365,7 @@ public interface Page extends AutoCloseable {
*
* @param expression JavaScript expression to be evaluated in the browser context. If it looks like a function declaration, it is interpreted
* as a function. Otherwise, evaluated as an expression.
* @param arg Optional argument to pass to {@code expression}
* @param arg Optional argument to pass to {@code expression}.
*/
JSHandle waitForFunction(String expression, Object arg, WaitForFunctionOptions options);
default void waitForLoadState(Frame.LoadState state) {

View File

@ -22,10 +22,10 @@ import java.util.*;
* Whenever the page sends a request for a network resource the following sequence of events are emitted by {@code Page}:
* - [{@code event: Page.request}] emitted when the request is issued by the page.
* - [{@code event: Page.response}] emitted when/if the response status and headers are received for the request.
* - [{@code event: Page.requestfinished}] emitted when the response body is downloaded and the request is complete.
* - [{@code event: Page.requestFinished}] emitted when the response body is downloaded and the request is complete.
*
* <p> If request fails at some point, then instead of {@code 'requestfinished'} event (and possibly instead of 'response' event),
* the [{@code event: Page.requestfailed}] event is emitted.
* the [{@code event: Page.requestFailed}] event is emitted.
*
* <p> <strong>NOTE:</strong> HTTP Error responses, such as 404 or 503, are still successful responses from HTTP standpoint, so request will
* complete with {@code 'requestfinished'} event.

View File

@ -55,7 +55,7 @@ public interface Worker {
*
* @param expression JavaScript expression to be evaluated in the browser context. If it looks like a function declaration, it is interpreted
* as a function. Otherwise, evaluated as an expression.
* @param arg Optional argument to pass to {@code expression}
* @param arg Optional argument to pass to {@code expression}.
*/
Object evaluate(String expression, Object arg);
default JSHandle evaluateHandle(String expression) {
@ -72,7 +72,7 @@ public interface Worker {
*
* @param expression JavaScript expression to be evaluated in the browser context. If it looks like a function declaration, it is interpreted
* as a function. Otherwise, evaluated as an expression.
* @param arg Optional argument to pass to {@code expression}
* @param arg Optional argument to pass to {@code expression}.
*/
JSHandle evaluateHandle(String expression, Object arg);
String url();

View File

@ -1 +1 @@
1.9.0-next-1612400196000
1.9.0-next-1612463649000

View File

@ -382,41 +382,6 @@ abstract class TypeDefinition extends Element {
}
class Event extends Element {
private static Map<String, String> eventNames = new HashMap<>();
static {
eventNames.put("Browser.disconnected", "Disconnected");
eventNames.put("BrowserContext.close", "Close");
eventNames.put("BrowserContext.page", "Page");
eventNames.put("Page.close", "Close");
eventNames.put("Page.console", "Console");
eventNames.put("Page.crash", "Crash");
eventNames.put("Page.dialog", "Dialog");
eventNames.put("Page.domcontentloaded", "DOMContentLoaded");
eventNames.put("Page.download", "Download");
eventNames.put("Page.filechooser", "FileChooser");
eventNames.put("Page.frameattached", "FrameAttached");
eventNames.put("Page.framedetached", "FrameDetached");
eventNames.put("Page.framenavigated", "FrameNavigated");
eventNames.put("Page.load", "Load");
eventNames.put("Page.pageerror", "PageError");
eventNames.put("Page.popup", "Popup");
eventNames.put("Page.request", "Request");
eventNames.put("Page.requestfailed", "RequestFailed");
eventNames.put("Page.requestfinished", "RequestFinished");
eventNames.put("Page.response", "Response");
eventNames.put("Page.websocket", "WebSocket");
eventNames.put("Page.worker", "Worker");
eventNames.put("WebSocket.close", "Close");
eventNames.put("WebSocket.framereceived", "FrameReceived");
eventNames.put("WebSocket.framesent", "FrameSent");
eventNames.put("WebSocket.socketerror", "SocketError");
eventNames.put("Worker.close", "Close");
}
private static Set<String> waitForEvents = new HashSet<>();
static {
waitForEvents.add("BrowserContext.page");
@ -424,22 +389,22 @@ class Event extends Element {
waitForEvents.add("Page.close");
waitForEvents.add("Page.console");
waitForEvents.add("Page.download");
waitForEvents.add("Page.filechooser");
waitForEvents.add("Page.frameattached");
waitForEvents.add("Page.framedetached");
waitForEvents.add("Page.framenavigated");
waitForEvents.add("Page.pageerror");
waitForEvents.add("Page.fileChooser");
waitForEvents.add("Page.frameAttached");
waitForEvents.add("Page.frameDetached");
waitForEvents.add("Page.frameNavigated");
waitForEvents.add("Page.pageError");
waitForEvents.add("Page.popup");
waitForEvents.add("Page.request");
waitForEvents.add("Page.requestfailed");
waitForEvents.add("Page.requestfinished");
waitForEvents.add("Page.requestFailed");
waitForEvents.add("Page.requestFinished");
waitForEvents.add("Page.response");
waitForEvents.add("Page.websocket");
waitForEvents.add("Page.webSocket");
waitForEvents.add("Page.worker");
waitForEvents.add("WebSocket.framereceived");
waitForEvents.add("WebSocket.framesent");
waitForEvents.add("WebSocket.socketerror");
waitForEvents.add("WebSocket.frameReceived");
waitForEvents.add("WebSocket.frameSent");
waitForEvents.add("WebSocket.socketError");
waitForEvents.add("Worker.close");
}
@ -452,16 +417,8 @@ class Event extends Element {
}
void writeListenerMethods(List<String> output, String offset) {
if (!eventNames.containsKey(jsonPath)) {
throw new RuntimeException("Unknown event: " + jsonPath);
}
String name = eventNames.get(jsonPath);
String paramType = type.toJava();
// TODO: remove once fixed upstream
if (paramType.equals("void")) {
paramType = parent.jsonName;
}
String listenerType = "Consumer<" + paramType + ">";
String name = toTitle(jsonName);
String listenerType = "Consumer<" + type.toJava() + ">";
output.add(offset + "void on" + name + "(" + listenerType + " handler);");
output.add(offset + "void off" + name + "(" + listenerType + " handler);");
}
@ -470,7 +427,7 @@ class Event extends Element {
if (!waitForEvents.contains(jsonPath)) {
return;
}
String name = eventNames.get(jsonPath);
String name = toTitle(jsonName);
String methodName = "waitFor" + name;
// Skip events for which there is waitFor* method in the upstream API, that method will generate the code.
if (Method.waitForMethods.contains(parent.jsonPath + "." + methodName)) {

View File

@ -130,8 +130,8 @@ class Types {
// Return structures
add("ConsoleMessage.location", "Object", "Location");
add("ElementHandle.boundingBox", "Object|null", "BoundingBox", new Empty());
add("WebSocket.framereceived", "Object", "FrameData", new Empty());
add("WebSocket.framesent", "Object", "FrameData", new Empty());
add("WebSocket.frameReceived", "Object", "FrameData", new Empty());
add("WebSocket.frameSent", "Object", "FrameData", new Empty());
// Custom options
add("Page.pdf.options.margin.top", "float|string", "String");