1
0
mirror of synced 2026-08-05 23:16:54 +00:00

chore: use single definition of HTTPCredentials

This commit is contained in:
Yury Semikhatsky
2020-10-02 18:07:29 -07:00
parent 236d2ae8b6
commit 96b4bf57b2
8 changed files with 50 additions and 239 deletions
@@ -300,7 +300,6 @@ class Method extends Element {
static {
customSignature.put("Page.setViewportSize", "void setViewportSize(int width, int height);");
customSignature.put("BrowserContext.setHTTPCredentials", "void setHTTPCredentials(String username, String password);");
customSignature.put("ChromiumBrowserContext.setHTTPCredentials", "void setHTTPCredentials(String username, String password);");
}
Method(TypeDefinition parent, JsonObject jsonElement) {
@@ -419,11 +418,9 @@ class Field extends Element {
}
void writeBuilderMethod(List<String> output, String offset, String parentClass) {
if (name.equals("httpCredentials") && type.toJava().equals("HttpCredentials")) {
if (name.equals("httpCredentials")) {
output.add(offset + "public " + parentClass + " with" + toTitle(name) + "(String username, String password) {");
output.add(offset + " this." + name + " = new " + type.toJava() + "();");
output.add(offset + " this." + name + ".username = username;");
output.add(offset + " this." + name + ".password = password;");
output.add(offset + " this." + name + " = new " + type.toJava() + "(username, password);");
output.add(offset + " return this;");
} else if (type.isNestedClass) {
output.add(offset + "public " + type.toJava() + " set" + toTitle(name) + "() {");
@@ -536,6 +533,26 @@ class Interface extends TypeDefinition {
output.add(offset + "}");
break;
}
case "BrowserContext": {
output.add(offset + "class HTTPCredentials {");
output.add(offset + " private final String username;");
output.add(offset + " private final String password;");
output.add("");
output.add(offset + " public HTTPCredentials(String username, String password) {");
output.add(offset + " this.username = username;");
output.add(offset + " this.password = password;");
output.add(offset + " }");
output.add("");
output.add(offset + " public String username() {");
output.add(offset + " return username;");
output.add(offset + " }");
output.add("");
output.add(offset + " public String password() {");
output.add(offset + " return password;");
output.add(offset + " }");
output.add(offset + "}");
break;
}
default: return;
}
output.add("");
@@ -122,15 +122,10 @@ class Types {
add("WebKitBrowser.newPage.options.viewport", "null|Object", "Page.Viewport", new Empty());
// HTTP credentials.
add("Browser.newContext.options.httpCredentials", "Object", "HttpCredentials");
add("Browser.newPage.options.httpCredentials", "Object", "HttpCredentials");
add("BrowserType.launchPersistentContext.options.httpCredentials", "Object", "HttpCredentials");
add("ChromiumBrowser.newContext.options.httpCredentials", "Object", "HttpCredentials");
add("ChromiumBrowser.newPage.options.httpCredentials", "Object", "HttpCredentials");
add("FirefoxBrowser.newContext.options.httpCredentials", "Object", "HttpCredentials");
add("FirefoxBrowser.newPage.options.httpCredentials", "Object", "HttpCredentials");
add("WebKitBrowser.newContext.options.httpCredentials", "Object", "HttpCredentials");
add("WebKitBrowser.newPage.options.httpCredentials", "Object", "HttpCredentials");
add("Browser.newContext.options.httpCredentials", "Object", "BrowserContext.HTTPCredentials", new Empty());
add("Browser.newPage.options.httpCredentials", "Object", "BrowserContext.HTTPCredentials", new Empty());
add("BrowserType.launchPersistentContext.options.httpCredentials", "Object", "BrowserContext.HTTPCredentials", new Empty());
add("BrowserContext.setHTTPCredentials.httpCredentials", "null|Object", "HTTPCredentials", new Empty());
// EvaluationArgument
add("Page.$eval.arg", "EvaluationArgument", "Object");
@@ -266,9 +261,6 @@ class Types {
add("WebKitBrowser.newPage.options.geolocation.accuracy", "number", "double");
add("BrowserContext.setGeolocation.geolocation", "null|Object", "Geolocation");
add("ChromiumBrowserContext.setGeolocation.geolocation", "null|Object", "Geolocation");
add("BrowserContext.setHTTPCredentials.httpCredentials", "null|Object", "HTTPCredentials");
add("ChromiumBrowserContext.setHTTPCredentials.httpCredentials", "null|Object", "HTTPCredentials");
// Single field options
add("Keyboard.type.options", "Object", "int", new Empty());
@@ -46,25 +46,6 @@ public interface Browser {
return this;
}
}
public class HttpCredentials {
public String username;
public String password;
HttpCredentials() {
}
public NewContextOptions done() {
return NewContextOptions.this;
}
public HttpCredentials withUsername(String username) {
this.username = username;
return this;
}
public HttpCredentials withPassword(String password) {
this.password = password;
return this;
}
}
public class VideoSize {
public int width;
public int height;
@@ -99,7 +80,7 @@ public interface Browser {
public List<String> permissions;
public Map<String, String> extraHTTPHeaders;
public Boolean offline;
public HttpCredentials httpCredentials;
public BrowserContext.HTTPCredentials httpCredentials;
public ColorScheme colorScheme;
public Logger logger;
public String relativeArtifactsPath;
@@ -168,9 +149,7 @@ public interface Browser {
return this;
}
public NewContextOptions withHttpCredentials(String username, String password) {
this.httpCredentials = new HttpCredentials();
this.httpCredentials.username = username;
this.httpCredentials.password = password;
this.httpCredentials = new BrowserContext.HTTPCredentials(username, password);
return this;
}
public NewContextOptions withColorScheme(ColorScheme colorScheme) {
@@ -224,25 +203,6 @@ public interface Browser {
return this;
}
}
public class HttpCredentials {
public String username;
public String password;
HttpCredentials() {
}
public NewPageOptions done() {
return NewPageOptions.this;
}
public HttpCredentials withUsername(String username) {
this.username = username;
return this;
}
public HttpCredentials withPassword(String password) {
this.password = password;
return this;
}
}
public class VideoSize {
public int width;
public int height;
@@ -277,7 +237,7 @@ public interface Browser {
public List<String> permissions;
public Map<String, String> extraHTTPHeaders;
public Boolean offline;
public HttpCredentials httpCredentials;
public BrowserContext.HTTPCredentials httpCredentials;
public ColorScheme colorScheme;
public Logger logger;
public String relativeArtifactsPath;
@@ -346,9 +306,7 @@ public interface Browser {
return this;
}
public NewPageOptions withHttpCredentials(String username, String password) {
this.httpCredentials = new HttpCredentials();
this.httpCredentials.username = username;
this.httpCredentials.password = password;
this.httpCredentials = new BrowserContext.HTTPCredentials(username, password);
return this;
}
public NewPageOptions withColorScheme(ColorScheme colorScheme) {
@@ -20,6 +20,24 @@ import java.util.*;
import java.util.function.BiConsumer;
public interface BrowserContext {
class HTTPCredentials {
private final String username;
private final String password;
public HTTPCredentials(String username, String password) {
this.username = username;
this.password = password;
}
public String username() {
return username;
}
public String password() {
return password;
}
}
class GrantPermissionsOptions {
public String origin;
@@ -46,19 +64,6 @@ public interface BrowserContext {
return this;
}
}
class HTTPCredentials {
public String username;
public String password;
public HTTPCredentials withUsername(String username) {
this.username = username;
return this;
}
public HTTPCredentials withPassword(String password) {
this.password = password;
return this;
}
}
Deferred<Page> waitForPage();
void close();
void addCookies(List<Object> cookies);
@@ -215,25 +215,6 @@ public interface BrowserType {
return this;
}
}
public class HttpCredentials {
public String username;
public String password;
HttpCredentials() {
}
public LaunchPersistentContextOptions done() {
return LaunchPersistentContextOptions.this;
}
public HttpCredentials withUsername(String username) {
this.username = username;
return this;
}
public HttpCredentials withPassword(String password) {
this.password = password;
return this;
}
}
public class VideoSize {
public int width;
public int height;
@@ -284,7 +265,7 @@ public interface BrowserType {
public List<String> permissions;
public Map<String, String> extraHTTPHeaders;
public Boolean offline;
public HttpCredentials httpCredentials;
public BrowserContext.HTTPCredentials httpCredentials;
public ColorScheme colorScheme;
public String relativeArtifactsPath;
public Boolean recordVideos;
@@ -416,9 +397,7 @@ public interface BrowserType {
return this;
}
public LaunchPersistentContextOptions withHttpCredentials(String username, String password) {
this.httpCredentials = new HttpCredentials();
this.httpCredentials.username = username;
this.httpCredentials.password = password;
this.httpCredentials = new BrowserContext.HTTPCredentials(username, password);
return this;
}
public LaunchPersistentContextOptions withColorScheme(ColorScheme colorScheme) {
@@ -1,65 +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.impl;
import java.util.LinkedHashMap;
public class BrowserNewContextOptions {
public Boolean noDefaultViewport;
public static class Viewport {
// TODO: int is preferred here
public int width;
public int height;
}
public Viewport viewport;
public Boolean ignoreHTTPSErrors;
public Boolean javaScriptEnabled;
public Boolean bypassCSP;
public String userAgent;
public String locale;
public String timezoneId;
public static class Geolocation {
// TODO: can we use int somehow?
public Double longitude;
public Double latitude;
public Double accuracy;
};
public Geolocation geolocation;
public String[] permissions;
public LinkedHashMap<String, String> extraHTTPHeaders;
public Boolean offline;
public static class HttpCredentials {
public String username;
public String password;
}
public HttpCredentials httpCredentials;
public Integer deviceScaleFactor;
public Boolean isMobile;
public Boolean hasTouch;
public enum ColorScheme {
// TODO: noPreference => no-preference
dark, light, noPreference
}
public ColorScheme colorScheme;
public Boolean acceptDownloads;
public Boolean _recordVideos;
public static class _VideoSize {
public int width;
public int height;
}
public _VideoSize _videoSize;
}
@@ -1,47 +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.impl;
import com.google.gson.JsonObject;
import java.util.LinkedHashMap;
public class BrowserTypeLaunchOptions {
public String executablePath;
public String[] args;
public Boolean ignoreAllDefaultArgs;
public String[] ignoreDefaultArgs;
public Boolean handleSIGINT;
public Boolean handleSIGTERM;
public Boolean handleSIGHUP;
public Integer timeout;
public LinkedHashMap<String, String> env;
public Boolean headless;
public Boolean devtools;
public static class Proxy {
String server;
String bypass;
String username;
String password;
}
public Proxy proxy;
public String downloadsPath;
public String _videosPath;
public JsonObject firefoxUserPrefs;
public Boolean chromiumSandbox;
public Integer slowMo;
}
@@ -1,28 +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.impl;
public class NavigateOptions {
Integer timeout;
enum WaitUntil {
load,
domcontentloaded,
networkidle
}
WaitUntil waitUntil = WaitUntil.load;
String referer;
}