Skip to content

Commit 04c0159

Browse files
committed
update proxyType values to match w3c spec
1 parent e586190 commit 04c0159

File tree

5 files changed

+29
-50
lines changed

5 files changed

+29
-50
lines changed

dotnet/src/webdriver/Proxy.cs

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -27,16 +27,12 @@ namespace OpenQA.Selenium
2727
/// <summary>
2828
/// Describes the kind of proxy.
2929
/// </summary>
30-
/// <remarks>
31-
/// Keep these in sync with the Firefox preferences numbers:
32-
/// http://kb.mozillazine.org/Network.proxy.type
33-
/// </remarks>
3430
public enum ProxyKind
3531
{
3632
/// <summary>
37-
/// Direct connection, no proxy (default on Windows).
33+
/// Direct connection, no proxy.
3834
/// </summary>
39-
Direct = 0,
35+
Direct,
4036

4137
/// <summary>
4238
/// Manual proxy settings (e.g., for httpProxy).
@@ -51,15 +47,15 @@ public enum ProxyKind
5147
/// <summary>
5248
/// Use proxy automatic detection.
5349
/// </summary>
54-
AutoDetect = 4,
50+
AutoDetect,
5551

5652
/// <summary>
57-
/// Use the system values for proxy settings (default on Linux).
53+
/// Use the system values for proxy settings.
5854
/// </summary>
5955
System,
6056

6157
/// <summary>
62-
/// No proxy type is specified.
58+
/// No proxy type is specified. This must be changed before use
6359
/// </summary>
6460
Unspecified
6561
}
@@ -488,7 +484,10 @@ internal Dictionary<string, object> ToLegacyCapability()
488484
private Dictionary<string, object> AsDictionary(bool isSpecCompliant)
489485
{
490486
Dictionary<string, object> serializedDictionary = null;
491-
if (this.proxyKind != ProxyKind.Unspecified)
487+
if (this.proxyKind == ProxyKind.Unspecified) {
488+
throw new InvalidOperationException("proxyKind must be set before use");
489+
}
490+
else
492491
{
493492
serializedDictionary = new Dictionary<string, object>();
494493
if (this.proxyKind == ProxyKind.ProxyAutoConfigure)

java/src/org/openqa/selenium/Proxy.java

Lines changed: 8 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -36,19 +36,12 @@
3636
public class Proxy {
3737

3838
public enum ProxyType {
39-
// Keep these in sync with the Firefox preferences numbers:
40-
// http://kb.mozillazine.org/Network.proxy.type
41-
42-
DIRECT("direct"), // Direct connection, no proxy (default on Windows)
39+
DIRECT("direct"), // Direct connection, no proxy
4340
MANUAL("manual"), // Manual proxy settings (e.g. for httpProxy)
4441
PAC("pac"), // Proxy auto-configuration from URL
45-
46-
RESERVED_1("reserved_1"), // Never used (but reserved in Firefox)
47-
4842
AUTODETECT("autodetect"), // Proxy auto-detection (presumably with WPAD)
49-
SYSTEM("system"), // Use system settings (default on Linux)
50-
51-
UNSPECIFIED("unspecified");
43+
SYSTEM("system"), // Use system settings
44+
UNSPECIFIED("unspecified"); // This must be changed before using
5245

5346
private final String type;
5447

@@ -127,7 +120,9 @@ public Proxy(Map<String, ?> raw) {
127120
public Map<String, Object> toJson() {
128121
Map<String, Object> m = new HashMap<>();
129122

130-
if (proxyType != ProxyType.UNSPECIFIED) {
123+
if (proxyType == ProxyType.UNSPECIFIED) {
124+
throw new IllegalStateException("proxyType must be specified before use");
125+
} else {
131126
m.put(PROXY_TYPE, proxyType.toString());
132127
}
133128
if (ftpProxy != null) {
@@ -165,7 +160,7 @@ public Map<String, Object> toJson() {
165160

166161
/**
167162
* Gets the {@link ProxyType}. This can signal if set to use a direct connection (without proxy),
168-
* manually set proxy settings, auto-configured proxy settings, or whether to use the default
163+
* manually set proxy settings, autoconfigured proxy settings, or whether to use the default
169164
* system proxy settings. It defaults to {@link ProxyType#UNSPECIFIED}.
170165
*
171166
* @return the proxy type employed
@@ -198,7 +193,7 @@ public boolean isAutodetect() {
198193
/**
199194
* Specifies whether to autodetect proxy settings.
200195
*
201-
* @param autodetect set to true to use proxy auto detection, false to leave proxy settings
196+
* @param autodetect set to true to use proxy auto-detection, false to leave proxy settings
202197
* unspecified
203198
* @return reference to self
204199
*/
@@ -455,7 +450,6 @@ public String toString() {
455450
builder.append("pac: ").append(getProxyAutoconfigUrl());
456451
break;
457452

458-
case RESERVED_1:
459453
case UNSPECIFIED:
460454
break;
461455
}

py/selenium/webdriver/common/proxy.py

Lines changed: 9 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -17,28 +17,17 @@
1717
"""The Proxy implementation."""
1818

1919

20-
class ProxyTypeFactory:
21-
"""Factory for proxy types."""
22-
23-
@staticmethod
24-
def make(ff_value, string):
25-
return {"ff_value": ff_value, "string": string}
26-
27-
2820
class ProxyType:
2921
"""Set of possible types of proxy.
3022
31-
Each proxy type has 2 properties: 'ff_value' is value of Firefox
3223
profile preference, 'string' is id of proxy type.
3324
"""
3425

35-
DIRECT = ProxyTypeFactory.make(0, "DIRECT") # Direct connection, no proxy (default on Windows).
36-
MANUAL = ProxyTypeFactory.make(1, "MANUAL") # Manual proxy settings (e.g., for httpProxy).
37-
PAC = ProxyTypeFactory.make(2, "PAC") # Proxy autoconfiguration from URL.
38-
RESERVED_1 = ProxyTypeFactory.make(3, "RESERVED1") # Never used.
39-
AUTODETECT = ProxyTypeFactory.make(4, "AUTODETECT") # Proxy autodetection (presumably with WPAD).
40-
SYSTEM = ProxyTypeFactory.make(5, "SYSTEM") # Use system settings (default on Linux).
41-
UNSPECIFIED = ProxyTypeFactory.make(6, "UNSPECIFIED") # Not initialized (for internal use).
26+
DIRECT = "DIRECT" # Direct connection, no proxy
27+
MANUAL = "MANUAL" # Manual proxy settings (e.g., for httpProxy).
28+
PAC = "PAC" # Proxy autoconfiguration from URL.
29+
AUTODETECT = "AUTODETECT" # Proxy auto-detection (presumably with WPAD).
30+
SYSTEM = "SYSTEM" # Use system settings
4231

4332
@classmethod
4433
def load(cls, value):
@@ -72,7 +61,7 @@ class Proxy:
7261
"""Proxy contains information about proxy type and necessary proxy
7362
settings."""
7463

75-
proxyType = ProxyType.UNSPECIFIED
64+
proxyType = None
7665
autodetect = False
7766
ftpProxy = ""
7867
httpProxy = ""
@@ -281,12 +270,14 @@ def proxy_type(self, value) -> None:
281270
self.proxyType = value
282271

283272
def _verify_proxy_type_compatibility(self, compatible_proxy):
284-
if self.proxyType not in (ProxyType.UNSPECIFIED, compatible_proxy):
273+
if self.proxyType not in (None, compatible_proxy):
285274
raise ValueError(
286275
f"Specified proxy type ({compatible_proxy}) not compatible with current setting ({self.proxyType})"
287276
)
288277

289278
def to_capabilities(self):
279+
if not self.proxyType:
280+
raise ValueError("proxyType must be specified before use")
290281
proxy_caps = {"proxyType": self.proxyType["string"].lower()}
291282
proxies = [
292283
"autodetect",

rb/lib/selenium/webdriver/common/proxy.rb

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,11 +21,11 @@ module Selenium
2121
module WebDriver
2222
class Proxy
2323
TYPES = {
24-
direct: 'DIRECT', # Direct connection, no proxy (default on Windows).
24+
direct: 'DIRECT', # Direct connection, no proxy.
2525
manual: 'MANUAL', # Manual proxy settings (e.g., for httpProxy).
2626
pac: 'PAC', # Proxy autoconfiguration from URL.
27-
auto_detect: 'AUTODETECT', # Proxy autodetection (presumably with WPAD).
28-
system: 'SYSTEM' # Use system settings (default on Linux).
27+
auto_detect: 'AUTODETECT', # Proxy auto-detection (presumably with WPAD).
28+
system: 'SYSTEM' # Use system settings.
2929
}.freeze
3030

3131
ALLOWED = {type: 'proxyType',
@@ -44,7 +44,6 @@ class Proxy
4444

4545
def self.json_create(data)
4646
data['proxyType'] = data['proxyType'].downcase.to_sym
47-
return if data['proxyType'] == :unspecified
4847

4948
proxy = new
5049

rb/spec/unit/selenium/webdriver/proxy_spec.rb

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -118,10 +118,6 @@ module WebDriver
118118

119119
expect(proxy).to eq(other)
120120
end
121-
122-
it 'deserializes to nil if proxyType is UNSPECIFIED' do
123-
expect(described_class.json_create('proxyType' => 'UNSPECIFIED')).to be_nil
124-
end
125121
end
126122
end # WebDriver
127123
end # Selenium

0 commit comments

Comments
 (0)