Skip to content

Commit 8629dc6

Browse files
committed
Mobile - Network Connection implementation for Java and Python.
Browser Connection is no more adding simple Android Driver wrapper for RWD (I tire of typing out webdriver.Remote(desired_capabilities=webdriver.DesiredCapabilities.ANDROID) ) :)
1 parent 2294fbb commit 8629dc6

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

42 files changed

+418
-425
lines changed

common/src/web/html5/offline.html

-1
This file was deleted.

java/client/src/org/openqa/selenium/build.desc

+1
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,7 @@ java_library(name = "webdriver-api",
7777
"internal/SocketLock.java",
7878
"internal/WrapsDriver.java",
7979
"internal/WrapsElement.java",
80+
"mobile/*.java",
8081
],
8182
deps = [
8283
":base",

java/client/src/org/openqa/selenium/html5/BrowserConnection.java

-36
This file was deleted.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,127 @@
1+
/*
2+
Copyright 2014 Software Freedom Conservancy
3+
4+
Licensed under the Apache License, Version 2.0 (the "License");
5+
you may not use this file except in compliance with the License.
6+
You may obtain a copy of the License at
7+
8+
http://www.apache.org/licenses/LICENSE-2.0
9+
10+
Unless required by applicable law or agreed to in writing, software
11+
distributed under the License is distributed on an "AS IS" BASIS,
12+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
See the License for the specific language governing permissions and
14+
limitations under the License.
15+
*/
16+
17+
package org.openqa.selenium.mobile;
18+
19+
20+
/**
21+
* Control a device's network connection
22+
* <p>
23+
* Example usage:
24+
*
25+
* <pre>
26+
* NetworkConnection mobileDriver = (NetworkConnection) driver;
27+
* if (mobileDriver.getNetworkConnection() != ConnectionType.AIRPLANE_MODE) {
28+
* // enabling Airplane mode
29+
* mobileDriver.setNetworkConnection(ConnectionType.AIRPLANE_MODE);
30+
* }
31+
* </pre>
32+
*/
33+
public interface NetworkConnection {
34+
35+
/**
36+
* ConnectionType is a bitmask to represent a device's network connection
37+
* Data | WIFI | Airplane
38+
* 0 0 1 == 1
39+
* 1 1 0 == 6
40+
* 1 0 0 == 4
41+
* 0 1 0 == 2
42+
* 0 0 0 == 0
43+
*
44+
* Giving "Data" the first bit positions in order to give room for the future of enabling
45+
* specific types of data (Edge / 2G, 3G, 4G, LTE, etc) if the device allows it.
46+
*/
47+
public class ConnectionType {
48+
public static final ConnectionType WIFI = new ConnectionType(2);
49+
public static final ConnectionType DATA = new ConnectionType(4);
50+
public static final ConnectionType AIRPLANE_MODE = new ConnectionType(1);
51+
public static final ConnectionType ALL = new ConnectionType(6);
52+
public static final ConnectionType NONE = new ConnectionType(0);
53+
54+
/*
55+
Future for Network Data types. With a new constructor accepting this enum.
56+
public enum DataType {
57+
_2G, _3G, _4G, LTE
58+
59+
}
60+
*/
61+
62+
private int mask = 0;
63+
64+
public ConnectionType(Boolean wifi, Boolean data, Boolean airplaneMode) {
65+
if (wifi) {
66+
mask += WIFI.mask;
67+
}
68+
if (data) {
69+
mask += DATA.mask;
70+
}
71+
if (airplaneMode) {
72+
mask += AIRPLANE_MODE.mask;
73+
}
74+
}
75+
76+
public ConnectionType(int mask) {
77+
// must be a positive number
78+
this.mask = Math.max(mask, 0);
79+
}
80+
81+
public Boolean isAirplaneMode() {
82+
return mask % 2 == 1;
83+
}
84+
85+
public Boolean isWifiEnabled() {
86+
// shift right 1 bit, check last bit
87+
return (mask / 2) % 2 == 1;
88+
}
89+
90+
public Boolean isDataEnabled() {
91+
// shift right 2 bits, check if any bits set
92+
return (mask / 4) > 0;
93+
}
94+
95+
@Override
96+
public boolean equals(Object type) {
97+
return type instanceof ConnectionType && this.mask == ((ConnectionType)type).mask;
98+
}
99+
100+
@Override
101+
public String toString() {
102+
return Integer.toString(mask);
103+
}
104+
105+
}
106+
107+
/**
108+
* Query the driver for the Airplane Mode setting state
109+
*
110+
* @return ConnectionType indicating if the device is in Airplane Mode
111+
* @see org.openqa.selenium.mobile.NetworkConnection.ConnectionType
112+
*/
113+
public ConnectionType getNetworkConnection();
114+
115+
/**
116+
* Set the Connection type
117+
* Not all connection type combinations are valid for an individual type of device
118+
* and the remote endpoint will make a best effort to set the type as requested
119+
*
120+
* @param type ConnectionType of what the network connection should be
121+
*
122+
* @return @ConnectionType of what the device's network connection is
123+
* @see org.openqa.selenium.mobile.NetworkConnection.ConnectionType
124+
*/
125+
public ConnectionType setNetworkConnection(ConnectionType type);
126+
127+
}

java/client/src/org/openqa/selenium/remote/BaseAugmenter.java

+4-4
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
Copyright 2007-2010 Selenium committers
2+
Copyright 2007-2014 Software Freedom Conservancy
33
44
Licensed under the Apache License, Version 2.0 (the "License");
55
you may not use this file except in compliance with the License.
@@ -19,9 +19,9 @@
1919
import static org.openqa.selenium.remote.CapabilityType.HAS_TOUCHSCREEN;
2020
import static org.openqa.selenium.remote.CapabilityType.ROTATABLE;
2121
import static org.openqa.selenium.remote.CapabilityType.SUPPORTS_APPLICATION_CACHE;
22-
import static org.openqa.selenium.remote.CapabilityType.SUPPORTS_BROWSER_CONNECTION;
2322
import static org.openqa.selenium.remote.CapabilityType.SUPPORTS_FINDING_BY_CSS;
2423
import static org.openqa.selenium.remote.CapabilityType.SUPPORTS_LOCATION_CONTEXT;
24+
import static org.openqa.selenium.remote.CapabilityType.SUPPORTS_NETWORK_CONNECTION;
2525
import static org.openqa.selenium.remote.CapabilityType.SUPPORTS_SQL_DATABASE;
2626
import static org.openqa.selenium.remote.CapabilityType.SUPPORTS_WEB_STORAGE;
2727
import static org.openqa.selenium.remote.CapabilityType.TAKES_SCREENSHOT;
@@ -31,10 +31,10 @@
3131
import org.openqa.selenium.WebDriver;
3232
import org.openqa.selenium.WebElement;
3333
import org.openqa.selenium.remote.html5.AddApplicationCache;
34-
import org.openqa.selenium.remote.html5.AddBrowserConnection;
3534
import org.openqa.selenium.remote.html5.AddDatabaseStorage;
3635
import org.openqa.selenium.remote.html5.AddLocationContext;
3736
import org.openqa.selenium.remote.html5.AddWebStorage;
37+
import org.openqa.selenium.remote.mobile.AddNetworkConnection;
3838

3939
import java.util.Map;
4040

@@ -55,7 +55,7 @@ public BaseAugmenter() {
5555
addDriverAugmentation(SUPPORTS_SQL_DATABASE, new AddDatabaseStorage());
5656
addDriverAugmentation(SUPPORTS_LOCATION_CONTEXT, new AddLocationContext());
5757
addDriverAugmentation(SUPPORTS_APPLICATION_CACHE, new AddApplicationCache());
58-
addDriverAugmentation(SUPPORTS_BROWSER_CONNECTION, new AddBrowserConnection());
58+
addDriverAugmentation(SUPPORTS_NETWORK_CONNECTION, new AddNetworkConnection());
5959
addDriverAugmentation(SUPPORTS_WEB_STORAGE, new AddWebStorage());
6060
addDriverAugmentation(ROTATABLE, new AddRotatable());
6161
addDriverAugmentation(HAS_TOUCHSCREEN, new AddRemoteTouchScreen());

java/client/src/org/openqa/selenium/remote/CapabilityType.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
Copyright 2007-2010 Selenium committers
2+
Copyright 2007-2014 Software Freedom Conservancy
33
44
Licensed under the Apache License, Version 2.0 (the "License");
55
you may not use this file except in compliance with the License.
@@ -29,7 +29,7 @@ public interface CapabilityType {
2929
String SUPPORTS_SQL_DATABASE = "databaseEnabled";
3030
String SUPPORTS_LOCATION_CONTEXT = "locationContextEnabled";
3131
String SUPPORTS_APPLICATION_CACHE = "applicationCacheEnabled";
32-
String SUPPORTS_BROWSER_CONNECTION = "browserConnectionEnabled";
32+
String SUPPORTS_NETWORK_CONNECTION = "networkConnectionEnabled";
3333
String SUPPORTS_FINDING_BY_CSS = "cssSelectorsEnabled";
3434
String PROXY = "proxy";
3535
String SUPPORTS_WEB_STORAGE = "webStorageEnabled";

java/client/src/org/openqa/selenium/remote/DriverCommand.java

+5-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
Copyright 2007-2011 Selenium committers
2+
Copyright 2007-2014 Software Freedom Conservancy
33
44
Licensed under the Apache License, Version 2.0 (the "License");
55
you may not use this file except in compliance with the License.
@@ -164,4 +164,8 @@ public interface DriverCommand {
164164
// Logging API
165165
String GET_AVAILABLE_LOG_TYPES = "getAvailableLogTypes";
166166
String GET_LOG = "getLog";
167+
168+
// Mobile API
169+
String GET_NETWORK_CONNECTION = "getNetworkConnection";
170+
String SET_NETWORK_CONNECTION = "setNetworkConnection";
167171
}

java/client/src/org/openqa/selenium/remote/HttpCommandExecutor.java

+6-3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
Copyright 2007-2011 Selenium committers
2+
Copyright 2007-2014 Software Freedom Conservancy
33
44
Licensed under the Apache License, Version 2.0 (the "License");
55
you may not use this file except in compliance with the License.
@@ -193,8 +193,6 @@ public HttpCommandExecutor(Map<String, CommandInfo> additionalCommands, URL addr
193193
.put(GET_LOCATION, get("/session/:sessionId/location"))
194194
.put(SET_LOCATION, post("/session/:sessionId/location"))
195195
.put(GET_APP_CACHE_STATUS, get("/session/:sessionId/application_cache/status"))
196-
.put(IS_BROWSER_ONLINE, get("/session/:sessionId/browser_connection"))
197-
.put(SET_BROWSER_ONLINE, post("/session/:sessionId/browser_connection"))
198196

199197
.put(SWITCH_TO_CONTEXT, post("/session/:sessionId/context"))
200198
.put(GET_CURRENT_CONTEXT_HANDLE, get("/session/:sessionId/context"))
@@ -250,6 +248,11 @@ public HttpCommandExecutor(Map<String, CommandInfo> additionalCommands, URL addr
250248
.put(GET_LOG, post("/session/:sessionId/log"))
251249
.put(GET_AVAILABLE_LOG_TYPES, get("/session/:sessionId/log/types"))
252250

251+
// Mobile Spec
252+
// https://code.google.com/p/selenium/source/browse/spec-draft.md?repo=mobile
253+
.put(GET_NETWORK_CONNECTION, get("/session/:sessionId/network_connection"))
254+
.put(SET_NETWORK_CONNECTION, post("/session/:sessionId/network_connection"))
255+
253256
.put(STATUS, get("/status"));
254257

255258
nameToUrl = builder.build();

java/client/src/org/openqa/selenium/remote/RemoteWebDriver.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
Copyright 2007-2012 Selenium committers
2+
Copyright 2007-2014 Software Freedom Conservancy
33
44
Licensed under the Apache License, Version 2.0 (the "License");
55
you may not use this file except in compliance with the License.

java/client/src/org/openqa/selenium/remote/build.desc

+2-2
Original file line numberDiff line numberDiff line change
@@ -59,10 +59,10 @@ java_library(name = "augmenter",
5959
"InterfaceImplementation.java",
6060
"JdkAugmenter.java",
6161
"html5/AddApplicationCache.java",
62-
"html5/AddBrowserConnection.java",
6362
"html5/AddDatabaseStorage.java",
6463
"html5/AddLocationContext.java",
6564
"html5/AddWebStorage.java",
65+
"mobile/AddNetworkConnection.java",
6666
],
6767
deps = [
6868
":api",
@@ -90,7 +90,6 @@ java_library(name = "remote",
9090
"RemoteTouchScreen.java",
9191
"UselessFileDetector.java",
9292
"html5/RemoteApplicationCache.java",
93-
"html5/RemoteBrowserConnection.java",
9493
"html5/RemoteDatabaseStorage.java",
9594
"html5/RemoteLocalStorage.java",
9695
"html5/RemoteLocationContext.java",
@@ -100,6 +99,7 @@ java_library(name = "remote",
10099
"internal/JsonToWebElementConverter.java",
101100
"internal/HttpClientFactory.java",
102101
"internal/WebElementToJsonConverter.java",
102+
"mobile/RemoteNetworkConnection.java",
103103
],
104104
deps = [
105105
":common",

java/client/src/org/openqa/selenium/remote/html5/RemoteBrowserConnection.java

-30
This file was deleted.

java/client/src/org/openqa/selenium/remote/html5/AddBrowserConnection.java renamed to java/client/src/org/openqa/selenium/remote/mobile/AddNetworkConnection.java

+7-7
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
Copyright 2007-2010 Selenium committers
2+
Copyright 2014 Software Freedom Conservancy
33
44
Licensed under the Apache License, Version 2.0 (the "License");
55
you may not use this file except in compliance with the License.
@@ -14,24 +14,24 @@
1414
limitations under the License.
1515
*/
1616

17-
package org.openqa.selenium.remote.html5;
17+
package org.openqa.selenium.remote.mobile;
1818

1919
import com.google.common.base.Throwables;
2020

2121
import org.openqa.selenium.WebDriverException;
22-
import org.openqa.selenium.html5.BrowserConnection;
22+
import org.openqa.selenium.mobile.NetworkConnection;
2323
import org.openqa.selenium.remote.AugmenterProvider;
2424
import org.openqa.selenium.remote.ExecuteMethod;
2525
import org.openqa.selenium.remote.InterfaceImplementation;
2626

2727
import java.lang.reflect.InvocationTargetException;
2828
import java.lang.reflect.Method;
2929

30-
public class AddBrowserConnection implements AugmenterProvider {
30+
public class AddNetworkConnection implements AugmenterProvider {
3131

3232
@Override
3333
public Class<?> getDescribedInterface() {
34-
return BrowserConnection.class;
34+
return NetworkConnection.class;
3535
}
3636

3737
@Override
@@ -40,8 +40,8 @@ public InterfaceImplementation getImplementation(Object value) {
4040

4141
@Override
4242
public Object invoke(ExecuteMethod executeMethod, Object self, Method method,
43-
Object... args) {
44-
BrowserConnection connection = new RemoteBrowserConnection(executeMethod);
43+
Object... args) {
44+
NetworkConnection connection = new RemoteNetworkConnection(executeMethod);
4545
try {
4646
return method.invoke(connection, args);
4747
} catch (IllegalAccessException e) {

0 commit comments

Comments
 (0)