From eeb8bd16c91bdc4ccd2b1adece2a9107fbb72174 Mon Sep 17 00:00:00 2001 From: Yury Semikhatsky Date: Fri, 6 Nov 2020 14:42:46 -0800 Subject: [PATCH] chore: remove browser-specific APIs (#73) --- .../playwright/tools/ApiGenerator.java | 22 ++- .../com/microsoft/playwright/CDPSession.java | 52 ------- .../microsoft/playwright/ChromiumBrowser.java | 79 ---------- .../playwright/ChromiumBrowserContext.java | 50 ------- .../playwright/ChromiumCoverage.java | 141 ------------------ .../microsoft/playwright/FirefoxBrowser.java | 26 ---- .../java/com/microsoft/playwright/Page.java | 6 - .../microsoft/playwright/WebKitBrowser.java | 26 ---- .../microsoft/playwright/impl/PageImpl.java | 5 - 9 files changed, 21 insertions(+), 386 deletions(-) delete mode 100644 playwright/src/main/java/com/microsoft/playwright/CDPSession.java delete mode 100644 playwright/src/main/java/com/microsoft/playwright/ChromiumBrowser.java delete mode 100644 playwright/src/main/java/com/microsoft/playwright/ChromiumBrowserContext.java delete mode 100644 playwright/src/main/java/com/microsoft/playwright/ChromiumCoverage.java delete mode 100644 playwright/src/main/java/com/microsoft/playwright/FirefoxBrowser.java delete mode 100644 playwright/src/main/java/com/microsoft/playwright/WebKitBrowser.java diff --git a/api-generator/src/main/java/com/microsoft/playwright/tools/ApiGenerator.java b/api-generator/src/main/java/com/microsoft/playwright/tools/ApiGenerator.java index 82f54b6f..b4626dc8 100644 --- a/api-generator/src/main/java/com/microsoft/playwright/tools/ApiGenerator.java +++ b/api-generator/src/main/java/com/microsoft/playwright/tools/ApiGenerator.java @@ -273,6 +273,8 @@ class Method extends Element { // No connect for now. customSignature.put("BrowserType.connect", new String[0]); customSignature.put("BrowserType.launchServer", new String[0]); + // We don't expose Chromium-specific APIs at the moment. + customSignature.put("Page.coverage", new String[0]); customSignature.put("BrowserContext.route", new String[]{ "void route(String url, Consumer handler);", "void route(Pattern url, Consumer handler);", @@ -419,6 +421,11 @@ class Method extends Element { }); } + private static Set skipJavadoc = new HashSet<>(asList( + "Page.waitForEvent.optionsOrPredicate", + "Page.frame.options" + )); + Method(TypeDefinition parent, JsonObject jsonElement) { super(parent, jsonElement); returnType = new TypeRef(this, jsonElement.get("type")); @@ -494,6 +501,9 @@ class Method extends Element { if (comment.isEmpty()) { continue; } + if (skipJavadoc.contains(p.jsonPath)) { + continue; + } sections.add("@param " + p.name() + " " + comment); } } @@ -1006,6 +1016,16 @@ class Enum extends TypeDefinition { } public class ApiGenerator { + private static Set skipList = new HashSet<>(Arrays.asList( + "BrowserServer", + "ChromiumBrowser", + "ChromiumBrowserContext", + "ChromiumCoverage", + "CDPSession", + "FirefoxBrowser", + "WebKitBrowser" + )); + ApiGenerator(Reader reader) throws IOException { JsonObject api = new Gson().fromJson(reader, JsonObject.class); File cwd = FileSystems.getDefault().getPath(".").toFile(); @@ -1013,7 +1033,7 @@ public class ApiGenerator { System.out.println("Writing files to: " + dir.getCanonicalPath()); for (Map.Entry entry: api.entrySet()) { String name = entry.getKey(); - if ("BrowserServer".equals(name)) { + if (skipList.contains(name)) { continue; } List lines = new ArrayList<>(); diff --git a/playwright/src/main/java/com/microsoft/playwright/CDPSession.java b/playwright/src/main/java/com/microsoft/playwright/CDPSession.java deleted file mode 100644 index b792591a..00000000 --- a/playwright/src/main/java/com/microsoft/playwright/CDPSession.java +++ /dev/null @@ -1,52 +0,0 @@ -/* - * Copyright (c) Microsoft Corporation. - * - * Licensed 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 com.microsoft.playwright; - -import java.util.*; - -/** - * The {@code CDPSession} instances are used to talk raw Chrome Devtools Protocol: - *

- * protocol methods can be called with {@code session.send} method. - *

- * protocol events can be subscribed to with {@code session.on} method. - *

- * Useful links: - *

- * Documentation on DevTools Protocol can be found here: DevTools Protocol Viewer. - *

- * Getting Started with DevTools Protocol: https://github.com/aslushnikov/getting-started-with-cdp/blob/master/README.md - *

- */ -public interface CDPSession { - /** - * Detaches the CDPSession from the target. Once detached, the CDPSession object won't emit any events and can't be used - *

- * to send messages. - */ - void detach(); - default Object send(String method) { - return send(method, null); - } - /** - * - * @param method protocol method name - * @param params Optional method parameters - */ - Object send(String method, Object params); -} - diff --git a/playwright/src/main/java/com/microsoft/playwright/ChromiumBrowser.java b/playwright/src/main/java/com/microsoft/playwright/ChromiumBrowser.java deleted file mode 100644 index 7c6de753..00000000 --- a/playwright/src/main/java/com/microsoft/playwright/ChromiumBrowser.java +++ /dev/null @@ -1,79 +0,0 @@ -/* - * Copyright (c) Microsoft Corporation. - * - * Licensed 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 com.microsoft.playwright; - -import java.nio.file.Path; -import java.util.*; - -/** - * Chromium-specific features including Tracing, service worker support, etc. - *

- * You can use {@code chromiumBrowser.startTracing} and {@code chromiumBrowser.stopTracing} to create a trace file which can be opened in Chrome DevTools or timeline viewer. - *

- */ -public interface ChromiumBrowser extends Browser { - class StartTracingOptions { - /** - * A path to write the trace file to. - */ - public Path path; - /** - * captures screenshots in the trace. - */ - public Boolean screenshots; - /** - * specify custom categories to use instead of default. - */ - public List categories; - - public StartTracingOptions withPath(Path path) { - this.path = path; - return this; - } - public StartTracingOptions withScreenshots(Boolean screenshots) { - this.screenshots = screenshots; - return this; - } - public StartTracingOptions withCategories(List categories) { - this.categories = categories; - return this; - } - } - /** - * - * @return Promise that resolves to the newly created browser - * session. - */ - CDPSession newBrowserCDPSession(); - default void startTracing(Page page) { - startTracing(page, null); - } - default void startTracing() { - startTracing(null); - } - /** - * Only one trace can be active at a time per browser. - * @param page Optional, if specified, tracing includes screenshots of the given page. - */ - void startTracing(Page page, StartTracingOptions options); - /** - * - * @return Promise which resolves to buffer with trace data. - */ - byte[] stopTracing(); -} - diff --git a/playwright/src/main/java/com/microsoft/playwright/ChromiumBrowserContext.java b/playwright/src/main/java/com/microsoft/playwright/ChromiumBrowserContext.java deleted file mode 100644 index b3bb70c5..00000000 --- a/playwright/src/main/java/com/microsoft/playwright/ChromiumBrowserContext.java +++ /dev/null @@ -1,50 +0,0 @@ -/* - * Copyright (c) Microsoft Corporation. - * - * Licensed 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 com.microsoft.playwright; - -import java.util.*; - -/** - * Chromium-specific features including background pages, service worker support, etc. - *

- */ -public interface ChromiumBrowserContext extends BrowserContext { - enum EventType { - BACKGROUNDPAGE, - SERVICEWORKER, - } - - void addListener(EventType type, Listener listener); - void removeListener(EventType type, Listener listener); - /** - * - * @return All existing background pages in the context. - */ - List backgroundPages(); - /** - * - * @param page Page to create new session for. - * @return Promise that resolves to the newly created session. - */ - CDPSession newCDPSession(Page page); - /** - * - * @return All existing service workers in the context. - */ - List serviceWorkers(); -} - diff --git a/playwright/src/main/java/com/microsoft/playwright/ChromiumCoverage.java b/playwright/src/main/java/com/microsoft/playwright/ChromiumCoverage.java deleted file mode 100644 index b7268b99..00000000 --- a/playwright/src/main/java/com/microsoft/playwright/ChromiumCoverage.java +++ /dev/null @@ -1,141 +0,0 @@ -/* - * Copyright (c) Microsoft Corporation. - * - * Licensed 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 com.microsoft.playwright; - -import java.util.*; - -/** - * Coverage gathers information about parts of JavaScript and CSS that were used by the page. - */ -public interface ChromiumCoverage { - class StartCSSCoverageOptions { - /** - * Whether to reset coverage on every navigation. Defaults to {@code true}. - */ - public Boolean resetOnNavigation; - - public StartCSSCoverageOptions withResetOnNavigation(Boolean resetOnNavigation) { - this.resetOnNavigation = resetOnNavigation; - return this; - } - } - class StartJSCoverageOptions { - /** - * Whether to reset coverage on every navigation. Defaults to {@code true}. - */ - public Boolean resetOnNavigation; - /** - * Whether anonymous scripts generated by the page should be reported. Defaults to {@code false}. - */ - public Boolean reportAnonymousScripts; - - public StartJSCoverageOptions withResetOnNavigation(Boolean resetOnNavigation) { - this.resetOnNavigation = resetOnNavigation; - return this; - } - public StartJSCoverageOptions withReportAnonymousScripts(Boolean reportAnonymousScripts) { - this.reportAnonymousScripts = reportAnonymousScripts; - return this; - } - } - class ChromiumCoverageStopCSSCoverage { - /** - * StyleSheet URL - */ - private String url; - /** - * StyleSheet content, if available. - */ - private String text; - /** - * StyleSheet ranges that were used. Ranges are sorted and non-overlapping. - */ - private List ranges; - - public String url() { - return this.url; - } - public String text() { - return this.text; - } - public List ranges() { - return this.ranges; - } - } - class ChromiumCoverageStopJSCoverage { - /** - * Script URL - */ - private String url; - /** - * Script ID - */ - private String scriptId; - /** - * Script content, if applicable. - */ - private String source; - /** - * V8-specific coverage format. - */ - private List functions; - - public String url() { - return this.url; - } - public String scriptId() { - return this.scriptId; - } - public String source() { - return this.source; - } - public List functions() { - return this.functions; - } - } - default void startCSSCoverage() { - startCSSCoverage(null); - } - /** - * - * @param options Set of configurable options for coverage - * @return Promise that resolves when coverage is started - */ - void startCSSCoverage(StartCSSCoverageOptions options); - default void startJSCoverage() { - startJSCoverage(null); - } - /** - * NOTE Anonymous scripts are ones that don't have an associated url. These are scripts that are dynamically created on the page using {@code eval} or {@code new Function}. If {@code reportAnonymousScripts} is set to {@code true}, anonymous scripts will have {@code __playwright_evaluation_script__} as their URL. - * @param options Set of configurable options for coverage - * @return Promise that resolves when coverage is started - */ - void startJSCoverage(StartJSCoverageOptions options); - /** - * NOTE CSS Coverage doesn't include dynamically injected style tags without sourceURLs. - * @return Promise that resolves to the array of coverage reports for all stylesheets - */ - ChromiumCoverageStopCSSCoverage stopCSSCoverage(); - /** - * NOTE JavaScript Coverage doesn't include anonymous scripts by default. However, scripts with sourceURLs are - *

- * reported. - * @return Promise that resolves to the array of coverage reports for all scripts - */ - ChromiumCoverageStopJSCoverage stopJSCoverage(); -} - diff --git a/playwright/src/main/java/com/microsoft/playwright/FirefoxBrowser.java b/playwright/src/main/java/com/microsoft/playwright/FirefoxBrowser.java deleted file mode 100644 index d63a808c..00000000 --- a/playwright/src/main/java/com/microsoft/playwright/FirefoxBrowser.java +++ /dev/null @@ -1,26 +0,0 @@ -/* - * Copyright (c) Microsoft Corporation. - * - * Licensed 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 com.microsoft.playwright; - -import java.util.*; - -/** - * Firefox browser instance does not expose Firefox-specific features. - */ -public interface FirefoxBrowser extends Browser { -} - diff --git a/playwright/src/main/java/com/microsoft/playwright/Page.java b/playwright/src/main/java/com/microsoft/playwright/Page.java index 9e8effac..c7eb345a 100644 --- a/playwright/src/main/java/com/microsoft/playwright/Page.java +++ b/playwright/src/main/java/com/microsoft/playwright/Page.java @@ -1503,7 +1503,6 @@ public interface Page { * *

* Returns frame matching the specified criteria. Either {@code name} or {@code url} must be specified. - * @param options Frame name or other frame lookup options. * @return frame matching the criteria. Returns {@code null} if no frame matches. */ Frame frameByUrl(Predicate predicate); @@ -1976,7 +1975,6 @@ public interface Page { *

* is fired. * @param event Event name, same one would pass into {@code page.on(event)}. - * @param optionsOrPredicate Either a predicate that receives an event or an options object. * @return Promise which resolves to the event data value. */ Deferred> waitForEvent(EventType event, WaitForEventOptions options); @@ -2082,10 +2080,6 @@ public interface Page { */ List workers(); Accessibility accessibility(); - /** - * Browser-specific Coverage implementation, only available for Chromium atm. See ChromiumCoverage for more details. - */ - ChromiumCoverage coverage(); Keyboard keyboard(); Mouse mouse(); Touchscreen touchscreen(); diff --git a/playwright/src/main/java/com/microsoft/playwright/WebKitBrowser.java b/playwright/src/main/java/com/microsoft/playwright/WebKitBrowser.java deleted file mode 100644 index e3fc5385..00000000 --- a/playwright/src/main/java/com/microsoft/playwright/WebKitBrowser.java +++ /dev/null @@ -1,26 +0,0 @@ -/* - * Copyright (c) Microsoft Corporation. - * - * Licensed 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 com.microsoft.playwright; - -import java.util.*; - -/** - * WebKit browser instance does not expose WebKit-specific features. - */ -public interface WebKitBrowser extends Browser { -} - diff --git a/playwright/src/main/java/com/microsoft/playwright/impl/PageImpl.java b/playwright/src/main/java/com/microsoft/playwright/impl/PageImpl.java index 5035af69..f55487a9 100644 --- a/playwright/src/main/java/com/microsoft/playwright/impl/PageImpl.java +++ b/playwright/src/main/java/com/microsoft/playwright/impl/PageImpl.java @@ -287,11 +287,6 @@ public class PageImpl extends ChannelOwner implements Page { return browserContext; } - @Override - public ChromiumCoverage coverage() { - return null; - } - @Override public void dblclick(String selector, DblclickOptions options) { mainFrame.dblclick(selector, convertViaJson(options, Frame.DblclickOptions.class));