├── CONTRIBUTING.md ├── LICENSE ├── README.md ├── java └── com │ └── google │ └── devtoolsdriver │ ├── devtools │ ├── Console.java │ ├── DOM.java │ ├── DevtoolsCommand.java │ ├── DevtoolsDebugger.java │ ├── DevtoolsDomain.java │ ├── DevtoolsErrorException.java │ ├── DevtoolsEvent.java │ ├── DevtoolsMessage.java │ ├── DevtoolsObject.java │ ├── DevtoolsResult.java │ ├── IdGenerator.java │ ├── Network.java │ ├── ObjectWrapper.java │ ├── Page.java │ ├── Runtime.java │ └── Timeline.java │ ├── examples │ └── ExampleMobileSafariWebTest.java │ ├── safari │ ├── ConfigProfiles.java │ ├── InspectorMessenger.java │ ├── SafariBrowser.java │ ├── SafariBrowserLauncher.java │ └── profiles │ │ ├── BUILD │ │ ├── cert_profile_template.mobileconfig │ │ └── http_proxy_template.mobileconfig │ ├── util │ └── JavaxJson.java │ └── webdriver │ ├── Browser.java │ ├── BrowserException.java │ ├── BrowserLauncher.java │ ├── JsAtoms.java │ └── PageId.java ├── javatests └── com │ └── google │ └── devtoolsdriver │ ├── devtools │ ├── CommandGenerationTest.java │ ├── DevtoolsDebuggerTest.java │ ├── DevtoolsObjectTest.java │ └── MessageFromJsonTest.java │ ├── safari │ ├── FakeScheduledExecutorService.java │ └── InspectorMessengerTest.java │ └── webdriver │ └── JsAtomsTest.java ├── pom.xml └── third_party ├── ios_driver ├── LICENSE └── org │ └── uiautomation │ └── ios │ ├── HostInfo.java │ ├── IOSServer.java │ ├── IOSServerConfiguration.java │ ├── IOSServerManager.java │ ├── SafariDriver.java │ ├── ServerSideSession.java │ ├── WebDriverMain.java │ ├── command │ ├── AddCookieHandler.java │ ├── AlertHandler.java │ ├── BackHandler.java │ ├── ClearHandler.java │ ├── ClickHandler.java │ ├── CommandHandler.java │ ├── CssPropertyHandler.java │ ├── DeleteAllCookiesHandler.java │ ├── DeleteCookieByNameHandler.java │ ├── ExecuteAsyncScriptHandler.java │ ├── ExecuteScriptHandler.java │ ├── FindElementHandler.java │ ├── FindElementsHandler.java │ ├── ForwardHandler.java │ ├── GetAttributeHandler.java │ ├── GetCapabilitiesHandler.java │ ├── GetConfigurationHandler.java │ ├── GetCookiesHandler.java │ ├── GetCurrentContextHandler.java │ ├── GetElementSizeHandler.java │ ├── GetHandler.java │ ├── GetLocationHandler.java │ ├── GetPageSizeHandler.java │ ├── GetPageSourceHandler.java │ ├── GetSessionsHandler.java │ ├── GetTagNameHandler.java │ ├── GetTextHandler.java │ ├── GetTitleHandler.java │ ├── GetURL.java │ ├── GetWindowHandlesHandler.java │ ├── IsDisplayedHandler.java │ ├── IsEnabledHandler.java │ ├── IsEqualHandler.java │ ├── IsSelectedHandler.java │ ├── LogHandler.java │ ├── LogTypesHandler.java │ ├── MoveToHandler.java │ ├── NewSessionHandler.java │ ├── QuitSessionHandler.java │ ├── RefreshHandler.java │ ├── ServerStatusHandler.java │ ├── SetConfigurationHandler.java │ ├── SetCurrentContextHandler.java │ ├── SetFrameHandler.java │ ├── SetImplicitWaitTimeoutHandler.java │ ├── SetScriptTimeoutHandler.java │ ├── SetTimeoutHandler.java │ ├── SetValueHandler.java │ ├── SubmitHandler.java │ ├── TakeScreenshotHandler.java │ ├── ToCSSSelectorConverter.java │ └── configuration │ │ ├── CommandConfigurationStore.java │ │ └── DriverConfigurationStore.java │ ├── drivers │ └── RemoteIOSWebDriver.java │ ├── logging │ ├── IOSLogManager.java │ ├── Log.java │ ├── PerformanceListener.java │ └── WebDriverLog.java │ ├── servlet │ ├── CommandConfiguration.java │ ├── DriverBasedServlet.java │ ├── DriverConfiguration.java │ ├── IOSServlet.java │ ├── WebDriverLikeCommand.java │ └── WebDriverLikeRequest.java │ └── wkrdp │ ├── DOMContext.java │ ├── WebInspectorHelper.java │ ├── events │ ├── ChildIframeInserted.java │ ├── ChildNodeRemoved.java │ ├── Event.java │ ├── EventFactory.java │ ├── EventHistory.java │ └── NodeEvent.java │ └── model │ ├── NodeId.java │ ├── RemoteObject.java │ ├── RemoteObjectArray.java │ ├── RemoteObjectIterator.java │ └── RemoteWebElement.java └── jsatoms ├── LICENSE ├── back_ios.js ├── clear_ios.js ├── forward_ios.js ├── get_effective_style_ios.js ├── get_interactable_size_ios.js ├── get_location_ios.js ├── get_size_ios.js ├── get_visible_text_ios.js ├── is_enabled_ios.js ├── is_selected_ios.js ├── is_shown_ios.js ├── move_mouse_ios.js ├── stringify_ios.js ├── submit_ios.js ├── tap_ios.js ├── type_ios.js ├── xpath_ios.js └── xpaths_ios.js /CONTRIBUTING.md: -------------------------------------------------------------------------------- 1 | # How to Contribute 2 | 3 | We'd love to accept your patches and contributions to this project. There are 4 | just a few small guidelines you need to follow. 5 | 6 | ## Contributor License Agreement 7 | 8 | Contributions to this project must be accompanied by a Contributor License 9 | Agreement. You (or your employer) retain the copyright to your contribution, 10 | this simply gives us permission to use and redistribute your contributions as 11 | part of the project. Head over to to see 12 | your current agreements on file or to sign a new one. 13 | 14 | You generally only need to submit a CLA once, so if you've already submitted one 15 | (even if it was for a different project), you probably don't need to do it 16 | again. 17 | 18 | ## Code reviews 19 | 20 | All submissions, including submissions by project members, require review. We 21 | use GitHub pull requests for this purpose. Consult 22 | [GitHub Help](https://help.github.com/articles/about-pull-requests/) for more 23 | information on using pull requests. 24 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # DevTools Driver 2 | 3 | DevTools Driver is a Java framework for creating a WebDriver server 4 | implementation for any browser that supports the [DevTools Remote Debugging 5 | Protocol](https://chromedevtools.github.io/devtools-protocol/), including any 6 | browser based on the WebKit or Blink browser engines. Implementations for such 7 | browsers can be created simply by providing a few relatively simple hook 8 | methods, and the framework handles the rest, largely through JavaScript 9 | injection of [browser automation 10 | atoms](https://github.com/SeleniumHQ/selenium/wiki/Automation-Atoms) over 11 | DevTools. 12 | 13 | This project includes a WebDriver implementation for Mobile Safari on iOS. This 14 | implementation, which works for both iOS simulators and real devices, uses the 15 | [iOS Device Control library](https://github.com/google/ios-device-control) to 16 | control devices. An example of a web test controlling a remote Mobile Safari 17 | Devtools Driver can be found in [ExampleMobileSafariWebTest.java](src/com/google/devtoolsdriver/examples/ExampleMobileSafariWebTest.java). 18 | 19 | ## Installation 20 | 21 | 1. Before assembling a runnable jar for a Selenium server, the iOS Device 22 | Control dependency has to be installed. This can be done by following the 23 | steps outlined [here](https://github.com/google/ios-device-control). 24 | 25 | 2. The library must then be installed into the local Maven repository: 26 | 27 | ```console 28 | git clone https://github.com/google/ios-device-control.git 29 | cd ios-device-control/ 30 | mvn install 31 | ``` 32 | 33 | 3. A runnable jar of a Mobile Safari capable Selenium server can be assembled 34 | (along with the example provided) by running: 35 | 36 | ```console 37 | git clone https://github.com/google/devtools-driver 38 | cd devtools-driver/ 39 | mvn assembly:assembly 40 | ``` 41 | 42 | 4. Run the assembled jar found at 43 | target/SafariDriverServer-jar-with-dependencies.jar on a Mac: 44 | 45 | ```console 46 | # The -simulator flag indicates that all requested WebDriver instances will be of an iOS Simulator. Omit it for real devices 47 | java -jar SafariDriverServer-jar-with-dependencies.jar -simulator 48 | ``` 49 | 50 | ## License 51 | 52 | DevTools Driver is licensed under the open-source [Apache 2.0 license](LICENSE) 53 | 54 | ## Contributing 55 | 56 | Please [see the guidelines for contributing](CONTRIBUTING.md) before creating 57 | pull requests 58 | -------------------------------------------------------------------------------- /java/com/google/devtoolsdriver/devtools/Console.java: -------------------------------------------------------------------------------- 1 | // Copyright 2017 Google Inc. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | package com.google.devtoolsdriver.devtools; 16 | 17 | import static com.google.devtoolsdriver.devtools.DevtoolsDomain.CONSOLE; 18 | 19 | /** 20 | * Factory for messages in the devtools Console domain. For a specification of this domain's 21 | * methods, see the debugging protocol 23 | * viewer. Note that not all the domain's methods have been implemented yet. 24 | */ 25 | public final class Console { 26 | private static DevtoolsCommand command(String methodSuffix) { 27 | return new DevtoolsCommand.NoOptionals(CONSOLE.methodName(methodSuffix)); 28 | } 29 | 30 | public static DevtoolsCommand enable() { 31 | return command("enable"); 32 | } 33 | 34 | public static DevtoolsCommand disable() { 35 | return command("disable"); 36 | } 37 | 38 | public static DevtoolsCommand clearMessages() { 39 | return command("clearMessages"); 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /java/com/google/devtoolsdriver/devtools/DevtoolsCommand.java: -------------------------------------------------------------------------------- 1 | // Copyright 2017 Google Inc. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | package com.google.devtoolsdriver.devtools; 16 | 17 | import com.google.common.base.MoreObjects; 18 | import java.util.List; 19 | import java.util.Objects; 20 | import javax.json.Json; 21 | import javax.json.JsonObject; 22 | import javax.json.JsonObjectBuilder; 23 | 24 | /** A command message in the Devtools protocol. */ 25 | public abstract class DevtoolsCommand extends ObjectWrapper 26 | implements DevtoolsMessage { 27 | private final String method; 28 | 29 | private DevtoolsCommand(String method, JsonObject object) { 30 | super(object); 31 | this.method = method; 32 | } 33 | 34 | @Override 35 | public final String method() { 36 | return method; 37 | } 38 | 39 | @Override 40 | public final JsonObject params() { 41 | return object; 42 | } 43 | 44 | @Override 45 | public final boolean equals(Object other) { 46 | if (other == this) { 47 | return true; 48 | } 49 | if (other instanceof DevtoolsCommand) { 50 | DevtoolsCommand that = (DevtoolsCommand) other; 51 | return method().equals(that.method()) && object.equals(that.object); 52 | } 53 | return false; 54 | } 55 | 56 | @Override 57 | public final int hashCode() { 58 | return Objects.hash(method(), object); 59 | } 60 | 61 | @Override 62 | public final String toString() { 63 | return MoreObjects.toStringHelper(DevtoolsCommand.class) 64 | .add("method", method()) 65 | .add("params", params()) 66 | .toString(); 67 | } 68 | 69 | /** 70 | * Convert this JSON command to a JsonObject message that can be sent to a remote debugger. The 71 | * returned messages will have the specified id in its 'id' field. 72 | */ 73 | final JsonObject toJson(int id) { 74 | JsonObjectBuilder builder = Json.createObjectBuilder().add("method", method()); 75 | if (!object.isEmpty()) { 76 | builder.add("params", object); 77 | } 78 | builder.add("id", id); 79 | return builder.build(); 80 | } 81 | 82 | /** A devtools command with no optional parameters */ 83 | static final class NoOptionals extends DevtoolsCommand { 84 | NoOptionals(String method) { 85 | super(method, Json.createObjectBuilder().build()); 86 | } 87 | 88 | NoOptionals(String method, JsonObject params) { 89 | super(method, params); 90 | } 91 | 92 | @Override 93 | NoOptionals create(JsonObject params) { 94 | return new NoOptionals(method(), params); 95 | } 96 | } 97 | 98 | /** A devtools command with publicly exposed functions for adding optional parameters */ 99 | abstract static class WithOptionals extends DevtoolsCommand { 100 | WithOptionals(String method) { 101 | super(method, Json.createObjectBuilder().build()); 102 | } 103 | 104 | WithOptionals(String method, JsonObject params) { 105 | super(method, params); 106 | } 107 | 108 | /* 109 | * The with methods will always call the create method, which will be overrided to 110 | * return a new instance of an object of type T. This makes the below suppressions safe 111 | * to add. 112 | */ 113 | @SuppressWarnings("unchecked") 114 | @Override 115 | final C with(String name, boolean value) { 116 | return (C) super.with(name, value); 117 | } 118 | 119 | @SuppressWarnings("unchecked") 120 | @Override 121 | final C with(String name, long value) { 122 | return (C) super.with(name, value); 123 | } 124 | 125 | @SuppressWarnings("unchecked") 126 | @Override 127 | final C with(String name, double value) { 128 | return (C) super.with(name, value); 129 | } 130 | 131 | @SuppressWarnings("unchecked") 132 | @Override 133 | final C with(String name, String value) { 134 | return (C) super.with(name, value); 135 | } 136 | 137 | @SuppressWarnings("unchecked") 138 | @Override 139 | final C with(String name, DevtoolsObject value) { 140 | return (C) super.with(name, value); 141 | } 142 | 143 | @SuppressWarnings("unchecked") 144 | @Override 145 | final C withNumberArray(String name, List numberList) { 146 | return (C) super.withNumberArray(name, numberList); 147 | } 148 | 149 | @SuppressWarnings("unchecked") 150 | @Override 151 | final C withStringArray(String name, List stringList) { 152 | return (C) super.withStringArray(name, stringList); 153 | } 154 | 155 | @SuppressWarnings("unchecked") 156 | @Override 157 | final C withObjectArray(String name, List objectList) { 158 | return (C) super.withObjectArray(name, objectList); 159 | } 160 | 161 | @Override 162 | abstract C create(JsonObject object); 163 | } 164 | } 165 | -------------------------------------------------------------------------------- /java/com/google/devtoolsdriver/devtools/DevtoolsDomain.java: -------------------------------------------------------------------------------- 1 | // Copyright 2017 Google Inc. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | package com.google.devtoolsdriver.devtools; 16 | 17 | /** An enumeration and utility for generating qualified names of methods in the devtools protocol */ 18 | enum DevtoolsDomain { 19 | CONSOLE("Console"), 20 | DOM("DOM"), 21 | NETWORK("Network"), 22 | PAGE("Page"), 23 | RUNTIME("Runtime"), 24 | TIMELINE("Timeline"); 25 | 26 | private final String name; 27 | 28 | private DevtoolsDomain(String name) { 29 | this.name = name; 30 | } 31 | 32 | String methodName(String methodSuffix) { 33 | return name + "." + methodSuffix; 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /java/com/google/devtoolsdriver/devtools/DevtoolsErrorException.java: -------------------------------------------------------------------------------- 1 | // Copyright 2017 Google Inc. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | package com.google.devtoolsdriver.devtools; 16 | 17 | import javax.json.JsonObject; 18 | 19 | /** Indicates a devtools command caused an error when executed by the debugger. */ 20 | public final class DevtoolsErrorException extends Exception { 21 | private final DevtoolsCommand command; 22 | private final JsonObject response; 23 | 24 | DevtoolsErrorException(DevtoolsCommand command, JsonObject response) { 25 | super(String.format("Devtools command %s caused an error: %s", command, response)); 26 | this.command = command; 27 | this.response = response; 28 | } 29 | 30 | public DevtoolsCommand command() { 31 | return command; 32 | } 33 | 34 | public JsonObject response() { 35 | return response; 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /java/com/google/devtoolsdriver/devtools/DevtoolsEvent.java: -------------------------------------------------------------------------------- 1 | // Copyright 2017 Google Inc. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | package com.google.devtoolsdriver.devtools; 16 | 17 | import com.google.auto.value.AutoValue; 18 | import com.google.common.base.Optional; 19 | import com.google.devtoolsdriver.util.JavaxJson; 20 | import javax.json.JsonObject; 21 | 22 | /** An event message in the Devtools protocol. */ 23 | @AutoValue 24 | public abstract class DevtoolsEvent implements DevtoolsMessage { 25 | public static DevtoolsEvent fromJson(JsonObject json) { 26 | String method = json.getString("method"); 27 | Optional params = Optional.fromNullable(json.getJsonObject("params")); 28 | return new AutoValue_DevtoolsEvent(method, params.or(JavaxJson.EMPTY_OBJECT)); 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /java/com/google/devtoolsdriver/devtools/DevtoolsMessage.java: -------------------------------------------------------------------------------- 1 | // Copyright 2017 Google Inc. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | package com.google.devtoolsdriver.devtools; 16 | 17 | import javax.json.JsonObject; 18 | 19 | /** A message (command or event) in the Devtools protocol. */ 20 | interface DevtoolsMessage { 21 | /* The fully qualified Domain.methodName method name of this message */ 22 | String method(); 23 | 24 | /* The Json parameters of this message */ 25 | JsonObject params(); 26 | } 27 | -------------------------------------------------------------------------------- /java/com/google/devtoolsdriver/devtools/DevtoolsObject.java: -------------------------------------------------------------------------------- 1 | // Copyright 2017 Google Inc. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | package com.google.devtoolsdriver.devtools; 16 | 17 | import com.google.common.base.MoreObjects; 18 | import java.util.List; 19 | import java.util.Objects; 20 | import javax.json.Json; 21 | import javax.json.JsonObject; 22 | 23 | /** A Devtool-defined object (JSON object with defined schema) to be used in Devtools commands. */ 24 | public abstract class DevtoolsObject extends ObjectWrapper { 25 | private DevtoolsObject(JsonObject object) { 26 | super(object); 27 | } 28 | 29 | /** Get the json properties of this object. */ 30 | public final JsonObject properties() { 31 | return object; 32 | } 33 | 34 | @Override 35 | public final boolean equals(Object other) { 36 | if (other == this) { 37 | return true; 38 | } 39 | if (other instanceof DevtoolsObject) { 40 | DevtoolsObject that = (DevtoolsObject) other; 41 | return object.equals(that.object); 42 | } 43 | return false; 44 | } 45 | 46 | @Override 47 | public final int hashCode() { 48 | return Objects.hashCode(object); 49 | } 50 | 51 | @Override 52 | public final String toString() { 53 | return MoreObjects.toStringHelper(DevtoolsObject.class) 54 | .add("properties", properties()) 55 | .toString(); 56 | } 57 | 58 | /** A Devtools type with no optional field */ 59 | static final class NoOptionals extends DevtoolsObject { 60 | NoOptionals() { 61 | super(Json.createObjectBuilder().build()); 62 | } 63 | 64 | NoOptionals(JsonObject properties) { 65 | super(properties); 66 | } 67 | 68 | @Override 69 | NoOptionals create(JsonObject object) { 70 | return new NoOptionals(object); 71 | } 72 | } 73 | 74 | /** Abstract type for a Devtools type with optional fields */ 75 | abstract static class WithOptionals extends DevtoolsObject { 76 | WithOptionals() { 77 | super(Json.createObjectBuilder().build()); 78 | } 79 | 80 | WithOptionals(JsonObject properties) { 81 | super(properties); 82 | } 83 | 84 | /* 85 | * The with methods will always call the create method, which will be overrided to 86 | * return a new instance of an object of type T. This makes the below suppressions safe 87 | * to add. 88 | */ 89 | @SuppressWarnings("unchecked") 90 | @Override 91 | final T with(String name, boolean value) { 92 | return (T) super.with(name, value); 93 | } 94 | 95 | @SuppressWarnings("unchecked") 96 | @Override 97 | final T with(String name, long value) { 98 | return (T) super.with(name, value); 99 | } 100 | 101 | @SuppressWarnings("unchecked") 102 | @Override 103 | final T with(String name, String value) { 104 | return (T) super.with(name, value); 105 | } 106 | 107 | @SuppressWarnings("unchecked") 108 | @Override 109 | final T with(String name, DevtoolsObject value) { 110 | return (T) super.with(name, value); 111 | } 112 | 113 | @SuppressWarnings("unchecked") 114 | @Override 115 | final T with(String name, double value) { 116 | return (T) super.with(name, value); 117 | } 118 | 119 | @SuppressWarnings("unchecked") 120 | @Override 121 | final T withNumberArray(String name, List numberList) { 122 | return (T) super.withNumberArray(name, numberList); 123 | } 124 | 125 | @SuppressWarnings("unchecked") 126 | @Override 127 | final T withStringArray(String name, List stringList) { 128 | return (T) super.withStringArray(name, stringList); 129 | } 130 | 131 | @SuppressWarnings("unchecked") 132 | @Override 133 | final T withObjectArray(String name, List objectList) { 134 | return (T) super.withObjectArray(name, objectList); 135 | } 136 | 137 | @Override 138 | abstract T create(JsonObject object); 139 | } 140 | } 141 | -------------------------------------------------------------------------------- /java/com/google/devtoolsdriver/devtools/DevtoolsResult.java: -------------------------------------------------------------------------------- 1 | // Copyright 2017 Google Inc. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | package com.google.devtoolsdriver.devtools; 16 | 17 | import com.google.auto.value.AutoValue; 18 | import javax.json.JsonObject; 19 | 20 | /** A command result in the Devtools protocol. */ 21 | @AutoValue 22 | public abstract class DevtoolsResult { 23 | static DevtoolsResult fromJson(JsonObject response) { 24 | JsonObject result = response.getJsonObject("result"); 25 | return new AutoValue_DevtoolsResult(result); 26 | } 27 | 28 | /** Get the JSON result */ 29 | public abstract JsonObject json(); 30 | } 31 | -------------------------------------------------------------------------------- /java/com/google/devtoolsdriver/devtools/IdGenerator.java: -------------------------------------------------------------------------------- 1 | // Copyright 2017 Google Inc. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | package com.google.devtoolsdriver.devtools; 16 | 17 | /** 18 | * An IdGenerator is a utility used during message generation to assign a unique id to a message. 19 | */ 20 | interface IdGenerator { 21 | /** Return the next unique integer id. */ 22 | int nextId(); 23 | } 24 | -------------------------------------------------------------------------------- /java/com/google/devtoolsdriver/devtools/ObjectWrapper.java: -------------------------------------------------------------------------------- 1 | // Copyright 2017 Google Inc. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | package com.google.devtoolsdriver.devtools; 16 | 17 | import com.google.devtoolsdriver.util.JavaxJson; 18 | import java.util.List; 19 | import javax.json.Json; 20 | import javax.json.JsonArrayBuilder; 21 | import javax.json.JsonObject; 22 | import javax.json.JsonObjectBuilder; 23 | 24 | /** A fluent base for all Devtools objects */ 25 | abstract class ObjectWrapper { 26 | final JsonObject object; 27 | 28 | ObjectWrapper(JsonObject object) { 29 | this.object = object; 30 | } 31 | 32 | T with(String name, boolean value) { 33 | return create(toObjectBuilder().add(name, value)); 34 | } 35 | 36 | T with(String name, long value) { 37 | return create(toObjectBuilder().add(name, value)); 38 | } 39 | 40 | T with(String name, double value) { 41 | return create(toObjectBuilder().add(name, value)); 42 | } 43 | 44 | T with(String name, String value) { 45 | return create(toObjectBuilder().add(name, value)); 46 | } 47 | 48 | T with(String name, DevtoolsObject value) { 49 | return create(toObjectBuilder().add(name, value.object)); 50 | } 51 | 52 | T withNumberArray(String name, List numList) { 53 | JsonArrayBuilder arrayBuilder = Json.createArrayBuilder(); 54 | for (long l : numList) { 55 | arrayBuilder.add(l); 56 | } 57 | return create(toObjectBuilder().add(name, arrayBuilder)); 58 | } 59 | 60 | T withStringArray(String name, List stringList) { 61 | JsonArrayBuilder arrayBuilder = Json.createArrayBuilder(); 62 | for (String s : stringList) { 63 | arrayBuilder.add(s); 64 | } 65 | return create(toObjectBuilder().add(name, arrayBuilder)); 66 | } 67 | 68 | T withObjectArray(String name, List objectList) { 69 | JsonArrayBuilder arrayBuilder = Json.createArrayBuilder(); 70 | for (DevtoolsObject t : objectList) { 71 | arrayBuilder.add(t.object); 72 | } 73 | return create(toObjectBuilder().add(name, arrayBuilder)); 74 | } 75 | 76 | /** Create a new instance of the DevtoolsObject subclass, using parameters */ 77 | abstract T create(JsonObject params); 78 | 79 | private T create(JsonObjectBuilder builder) { 80 | return create(builder.build()); 81 | } 82 | 83 | private JsonObjectBuilder toObjectBuilder() { 84 | return JavaxJson.toBuilder(object); 85 | } 86 | } 87 | -------------------------------------------------------------------------------- /java/com/google/devtoolsdriver/devtools/Timeline.java: -------------------------------------------------------------------------------- 1 | // Copyright 2017 Google Inc. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | package com.google.devtoolsdriver.devtools; 16 | 17 | import static com.google.devtoolsdriver.devtools.DevtoolsDomain.TIMELINE; 18 | 19 | /** 20 | * Factory for messages in the formerly used devtools Timeline domain. Since stable version 1.1, 21 | * this domain has been deprecated. This class still exists to maintain support for legacy clients. 22 | */ 23 | public final class Timeline { 24 | private static DevtoolsCommand command(String methodSuffix) { 25 | return new DevtoolsCommand.NoOptionals(TIMELINE.methodName(methodSuffix)); 26 | } 27 | 28 | public static DevtoolsCommand start() { 29 | return command("start"); 30 | } 31 | 32 | public static DevtoolsCommand stop() { 33 | return command("stop"); 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /java/com/google/devtoolsdriver/examples/ExampleMobileSafariWebTest.java: -------------------------------------------------------------------------------- 1 | // Copyright 2017 Google Inc. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | package com.google.devtoolsdriver.examples; 16 | 17 | import com.google.iosdevicecontrol.util.FluentLogger; 18 | import java.net.URL; 19 | import java.nio.file.Files; 20 | import java.nio.file.Path; 21 | import org.openqa.selenium.By; 22 | import org.openqa.selenium.NoSuchElementException; 23 | import org.openqa.selenium.OutputType; 24 | import org.openqa.selenium.TakesScreenshot; 25 | import org.openqa.selenium.WebDriver; 26 | import org.openqa.selenium.WebElement; 27 | import org.openqa.selenium.remote.DesiredCapabilities; 28 | import org.openqa.selenium.remote.RemoteWebDriver; 29 | 30 | /** 31 | * This class contains an example use case of the DevTools Driver library for automating iOS devices 32 | * running on a Selenium server. 33 | */ 34 | public class ExampleMobileSafariWebTest { 35 | private static final FluentLogger logger = FluentLogger.forEnclosingClass(); 36 | 37 | private static WebDriver driver; 38 | 39 | public static void main(String[] args) throws Exception { 40 | // Create a DesiredCapabilities object to request specific devices from the WebDriver server. 41 | // A udid can be optionally specified, otherwise an arbitrary device is chosen. 42 | DesiredCapabilities caps = new DesiredCapabilities(); 43 | // caps.setCapability("uuid", udid); 44 | // Start a WebDriver session. The local machine has to be running the SafariDriverServer, or 45 | // change localhost below to an IP running the SafariDriverServer. 46 | driver = new RemoteWebDriver(new URL("http://localhost:5555/wd/hub"), caps); 47 | // Connect to a URL 48 | driver.get("http://www.google.com"); 49 | 50 | // Interact with the web page. In this example use case, the Webdriver API is used to find 51 | // specific elements, test a google search and take a screenshot. 52 | driver.findElement(By.id("hplogo")); 53 | 54 | // Google New York 55 | WebElement mobileSearchBox = driver.findElement(By.id("lst-ib")); 56 | mobileSearchBox.sendKeys("New York"); 57 | WebElement searchBox; 58 | try { 59 | searchBox = driver.findElement(By.id("tsbb")); 60 | } catch (NoSuchElementException e) { 61 | searchBox = driver.findElement(By.name("btnG")); 62 | } 63 | searchBox.click(); 64 | 65 | takeScreenshot(); 66 | driver.navigate().refresh(); 67 | takeScreenshot(); 68 | 69 | // Quit the WebDriver instance on completion of the test. 70 | driver.quit(); 71 | driver = null; 72 | } 73 | 74 | private static void takeScreenshot() throws Exception { 75 | byte[] screenshotBytes = ((TakesScreenshot) driver).getScreenshotAs(OutputType.BYTES); 76 | Path screenshotPath = Files.createTempFile("screenshot", ".png"); 77 | Files.write(screenshotPath, screenshotBytes); 78 | logger.atInfo().log("Screenshot written to: %s", screenshotPath); 79 | } 80 | } 81 | -------------------------------------------------------------------------------- /java/com/google/devtoolsdriver/safari/ConfigProfiles.java: -------------------------------------------------------------------------------- 1 | // Copyright 2017 Google Inc. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | package com.google.devtoolsdriver.safari; 16 | 17 | import static com.google.common.base.Preconditions.checkState; 18 | import static java.nio.charset.StandardCharsets.UTF_8; 19 | 20 | import com.dd.plist.NSArray; 21 | import com.dd.plist.NSData; 22 | import com.dd.plist.NSDictionary; 23 | import com.dd.plist.NSObject; 24 | import com.google.common.io.Resources; 25 | import com.google.common.net.HostAndPort; 26 | import com.google.iosdevicecontrol.IosDeviceException; 27 | import com.google.iosdevicecontrol.real.RealDevice; 28 | import com.google.iosdevicecontrol.util.PlistParser; 29 | import java.io.IOException; 30 | import java.nio.file.Files; 31 | import java.nio.file.Path; 32 | import java.util.Map; 33 | 34 | /** ProfileEditorUtils provides utilities for editing real device configuration profiles. */ 35 | final class ConfigProfiles { 36 | private static final String PROFILES_ROOT = "com/google/devtoolsdriver/safari/profiles/"; 37 | private static final String PROXY_PROFILE_PATH = 38 | PROFILES_ROOT + "http_proxy_template.mobileconfig"; 39 | private static final String CERT_PROFILE_PATH = 40 | PROFILES_ROOT + "cert_profile_template.mobileconfig"; 41 | private static final String PROXY_PROFILE_ID = "com.google.devtoolsdriver.safari.http_proxy"; 42 | private static final String CERT_PROFILE_ID = "com.google.devtoolsdriver.safari.https_cert"; 43 | 44 | /** Installs a profile to communicate with a specified HTTP/S proxy and port. */ 45 | static void installProxyProfile(RealDevice device, HostAndPort hostAndPort) 46 | throws IosDeviceException { 47 | checkState(hostAndPort.hasPort()); 48 | NSDictionary replacementDict = new NSDictionary(); 49 | replacementDict.put("ProxyServer", hostAndPort.getHost()); 50 | replacementDict.put("ProxyServerPort", hostAndPort.getPort()); 51 | ConfigProfiles.installProfile(device, PROXY_PROFILE_PATH, replacementDict); 52 | } 53 | 54 | /** Installs a profile to set up an HTTPS certificate on the device. */ 55 | static void installCertProfile(RealDevice device, String certName, String certContentBase64) 56 | throws IosDeviceException { 57 | NSDictionary replacementDict = new NSDictionary(); 58 | replacementDict.put("PayloadCertificateFileName", certName + ".cer"); 59 | try { 60 | replacementDict.put("PayloadContent", new NSData(certContentBase64)); 61 | } catch (IOException e) { 62 | throw new IosDeviceException(device, e); 63 | } 64 | replacementDict.put("PayloadDisplayName", certName); 65 | ConfigProfiles.installProfile(device, CERT_PROFILE_PATH, replacementDict); 66 | } 67 | 68 | private static void installProfile(RealDevice device, String profilePath, NSDictionary newPayload) 69 | throws IosDeviceException { 70 | try { 71 | String templateXml = Resources.toString(Resources.getResource(profilePath), UTF_8); 72 | NSDictionary plistDict = (NSDictionary) PlistParser.fromXml(templateXml); 73 | NSArray plistArray = (NSArray) plistDict.get("PayloadContent"); 74 | NSDictionary plistInnerDict = (NSDictionary) plistArray.objectAtIndex(0); 75 | for (Map.Entry entry : newPayload.entrySet()) { 76 | plistInnerDict.put(entry.getKey(), entry.getValue()); 77 | } 78 | String plist = plistDict.toXMLPropertyList(); 79 | 80 | Path configFile = Files.createTempFile("modified_profile", ".mobileconfig"); 81 | Files.write(configFile, plist.getBytes(UTF_8)); 82 | device.installProfile(configFile.toAbsolutePath()); 83 | } catch (IOException e) { 84 | throw new IosDeviceException(device, e); 85 | } 86 | } 87 | 88 | static void removeProxyProfile(RealDevice device) throws IosDeviceException { 89 | removeProfile(device, PROXY_PROFILE_ID); 90 | } 91 | 92 | static void removeCertProfile(RealDevice device) throws IosDeviceException { 93 | removeProfile(device, CERT_PROFILE_ID); 94 | } 95 | 96 | private static void removeProfile(RealDevice device, String profileId) throws IosDeviceException { 97 | boolean profileInstalled = 98 | device.listConfigurationProfiles().stream().anyMatch(p -> p.identifier().equals(profileId)); 99 | if (profileInstalled) { 100 | device.removeProfile(profileId); 101 | } 102 | } 103 | 104 | private ConfigProfiles() {} 105 | } 106 | -------------------------------------------------------------------------------- /java/com/google/devtoolsdriver/safari/profiles/BUILD: -------------------------------------------------------------------------------- 1 | licenses(["notice"]) # Apache License 2.0 2 | 3 | filegroup( 4 | name = "opensource_files", 5 | srcs = glob(["*"]), 6 | visibility = ["//third_party/java_src/devtoolsdriver/opensource:__pkg__"], 7 | ) 8 | -------------------------------------------------------------------------------- /java/com/google/devtoolsdriver/safari/profiles/cert_profile_template.mobileconfig: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | PayloadContent 6 | 7 | 8 | PayloadCertificateFileName 9 | PLACEHOLDER 10 | PayloadContent 11 | 12 | PLACEHOLDER 13 | 14 | PayloadDescription 15 | Adds a CA root certificate 16 | PayloadDisplayName 17 | PLACEHOLDER 18 | PayloadIdentifier 19 | com.apple.security.root.5051B0E0-F165-429F-9435-6B76B8889E5B 20 | PayloadType 21 | com.apple.security.root 22 | PayloadUUID 23 | 5051B0E0-F165-429F-9435-6B76B8889E5B 24 | PayloadVersion 25 | 1 26 | 27 | 28 | PayloadDisplayName 29 | HTTPS Certificate Profile 30 | PayloadIdentifier 31 | com.google.devtoolsdriver.safari.https_cert 32 | PayloadRemovalDisallowed 33 | 34 | PayloadType 35 | Configuration 36 | PayloadUUID 37 | E2174BFF-F292-4C26-959C-D4E07DC2BF8A 38 | PayloadVersion 39 | 1 40 | 41 | 42 | -------------------------------------------------------------------------------- /java/com/google/devtoolsdriver/safari/profiles/http_proxy_template.mobileconfig: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | PayloadContent 6 | 7 | 8 | PayloadDescription 9 | Global HTTP Proxy 10 | PayloadDisplayName 11 | Global HTTP Proxy 12 | PayloadIdentifier 13 | com.apple.proxy.http.global.CF237754-A774-4832-A507-E944FB58A670 14 | PayloadType 15 | com.apple.proxy.http.global 16 | PayloadUUID 17 | CF237754-A774-4832-A507-E944FB58A670 18 | PayloadVersion 19 | 1 20 | ProxyCaptiveLoginAllowed 21 | 22 | ProxyServer 23 | HOSTNAME 24 | ProxyServerPort 25 | 0 26 | ProxyType 27 | Manual 28 | 29 | 30 | PayloadDisplayName 31 | HTTP Proxy Settings 32 | PayloadIdentifier 33 | com.google.devtoolsdriver.safari.http_proxy 34 | PayloadRemovalDisallowed 35 | 36 | PayloadType 37 | Configuration 38 | PayloadUUID 39 | B6F9E2AA-0514-4AF4-ACA0-60F7872A4F5F 40 | PayloadVersion 41 | 1 42 | 43 | 44 | -------------------------------------------------------------------------------- /java/com/google/devtoolsdriver/webdriver/Browser.java: -------------------------------------------------------------------------------- 1 | // Copyright 2017 Google Inc. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | package com.google.devtoolsdriver.webdriver; 16 | 17 | import com.google.common.collect.ImmutableList; 18 | import com.google.devtoolsdriver.devtools.DevtoolsCommand; 19 | import com.google.devtoolsdriver.devtools.DevtoolsEvent; 20 | import com.google.devtoolsdriver.devtools.DevtoolsResult; 21 | import java.time.Duration; 22 | import java.util.function.Consumer; 23 | 24 | /** 25 | * An strategy to interact with a browser for the purpose of providing a WebDriver implementation. 26 | */ 27 | public interface Browser extends AutoCloseable { 28 | /** Returns the id of the currently active page in the browser. */ 29 | PageId activePage(); 30 | 31 | /** Returns a list of {@link PageId} for every open page. */ 32 | ImmutableList listPages() throws BrowserException; 33 | 34 | /** 35 | * Switches the browser to the specified pageId; a noop if {@code pageId} identifies the page that 36 | * is already active. Returns whether the specified page differed from the active page. 37 | */ 38 | boolean switchTo(PageId pageId) throws BrowserException; 39 | 40 | /** Send a devtools command to the browser. */ 41 | DevtoolsResult sendCommand(DevtoolsCommand command, Duration timeout) throws BrowserException; 42 | 43 | /** Set a listener for devtools events */ 44 | void addEventListener(Consumer listener); 45 | 46 | /** Takes a screenshot in PNG format and returns it as a byte array. */ 47 | byte[] takeScreenshot() throws BrowserException; 48 | 49 | /** Returns the WebDriver "browserName" capability for this browser. */ 50 | String browserName(); 51 | 52 | /** Returns the WebDriver "platformName" capability for this browser. */ 53 | String platformName(); 54 | 55 | @Override 56 | void close() throws BrowserException; 57 | } 58 | -------------------------------------------------------------------------------- /java/com/google/devtoolsdriver/webdriver/BrowserException.java: -------------------------------------------------------------------------------- 1 | // Copyright 2017 Google Inc. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | package com.google.devtoolsdriver.webdriver; 16 | 17 | /** Wrapper for all of the exceptions thrown by {@link Browser} */ 18 | public class BrowserException extends Exception { 19 | 20 | public BrowserException(String message, Throwable cause) { 21 | super(message, cause); 22 | } 23 | 24 | public BrowserException(String message) { 25 | super(message); 26 | } 27 | 28 | public BrowserException(Throwable cause) { 29 | super(cause); 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /java/com/google/devtoolsdriver/webdriver/BrowserLauncher.java: -------------------------------------------------------------------------------- 1 | // Copyright 2017 Google Inc. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | package com.google.devtoolsdriver.webdriver; 16 | 17 | import org.openqa.selenium.remote.DesiredCapabilities; 18 | 19 | /** A tool for launching browser instances. */ 20 | public interface BrowserLauncher { 21 | /** Launch a new browser instance. */ 22 | Browser launch(DesiredCapabilities caps) throws BrowserException; 23 | } 24 | -------------------------------------------------------------------------------- /java/com/google/devtoolsdriver/webdriver/PageId.java: -------------------------------------------------------------------------------- 1 | // Copyright 2017 Google Inc. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | package com.google.devtoolsdriver.webdriver; 16 | 17 | import com.google.auto.value.AutoValue; 18 | 19 | /** A unique id of a page in the browser. */ 20 | @AutoValue 21 | public abstract class PageId { 22 | /** Creates a browser pageId. */ 23 | public static PageId of(String asString) { 24 | return new AutoValue_PageId(asString); 25 | } 26 | 27 | /** PageId id. */ 28 | public abstract String asString(); 29 | } 30 | -------------------------------------------------------------------------------- /javatests/com/google/devtoolsdriver/devtools/DevtoolsObjectTest.java: -------------------------------------------------------------------------------- 1 | // Copyright 2017 Google Inc. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | package com.google.devtoolsdriver.devtools; 16 | 17 | import static com.google.common.truth.Truth.assertThat; 18 | 19 | import org.junit.Test; 20 | import org.junit.runner.RunWith; 21 | import org.junit.runners.JUnit4; 22 | 23 | @RunWith(JUnit4.class) 24 | public class DevtoolsObjectTest { 25 | @Test 26 | public void testEqualsAndHashCode() { 27 | DevtoolsObject first = Runtime.callArgument().withValue("val").withObjectId("567"); 28 | DevtoolsObject firstEqual = Runtime.callArgument().withValue("val").withObjectId("567"); 29 | DevtoolsObject firstNotEqual = Runtime.callArgument().withValue("val").withObjectId("568"); 30 | 31 | assertThat(first).isEqualTo(firstEqual); 32 | assertThat(first).isNotEqualTo(firstNotEqual); 33 | 34 | assertThat(first.hashCode()).isEqualTo(firstEqual.hashCode()); 35 | assertThat(first.hashCode()).isNotEqualTo(firstNotEqual.hashCode()); 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /javatests/com/google/devtoolsdriver/devtools/MessageFromJsonTest.java: -------------------------------------------------------------------------------- 1 | // Copyright 2017 Google Inc. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | package com.google.devtoolsdriver.devtools; 16 | 17 | import static com.google.common.truth.Truth.assertThat; 18 | 19 | import com.google.devtoolsdriver.util.JavaxJson; 20 | import org.junit.Test; 21 | import org.junit.runner.RunWith; 22 | import org.junit.runners.JUnit4; 23 | 24 | /* A remote message is a message created by the browser, as opposed to the devtools client */ 25 | @RunWith(JUnit4.class) 26 | public class MessageFromJsonTest { 27 | @Test 28 | public void testEventFromJson() { 29 | String paramsText = 30 | "{\"scriptId\":\"69\"," 31 | + "\"url\":\"https://docs.oracle.com/javaee/7/api/script.js\"," 32 | + "\"startLine\":0,\"startColumn\":0,\"endLine\":31,\"endColumn\":0," 33 | + "\"executionContextId\":3," 34 | + "\"hash\":\"0FDEBE32DE7C1F965D844FA75116EE9B72483064\"," 35 | + "\"isContentScript\":false,\"isInternalScript\":false,\"isLiveEdit\":false," 36 | + "\"sourceMapURL\":\"\",\"hasSourceURL\":false," 37 | + "\"deprecatedCommentWasUsed\":false}"; 38 | String eventText = "{\"method\":\"Debugger.scriptParsed\", \"params\":" + paramsText + "}"; 39 | DevtoolsEvent event = DevtoolsEvent.fromJson(JavaxJson.parseObject(eventText)); 40 | assertThat(event.method()).isEqualTo("Debugger.scriptParsed"); 41 | assertThat(event.params()).isEqualTo(JavaxJson.parseObject(paramsText)); 42 | } 43 | 44 | @Test 45 | public void testEventWithNoParamsFromJson() { 46 | String eventText = "{\"method\":\"Console.messagesCleared\"}"; 47 | DevtoolsEvent event = DevtoolsEvent.fromJson(JavaxJson.parseObject(eventText)); 48 | assertThat(event.method()).isEqualTo("Console.messagesCleared"); 49 | assertThat(event.params()).isEqualTo(JavaxJson.EMPTY_OBJECT); 50 | } 51 | 52 | @Test 53 | public void testResultFromJson() { 54 | String resultText = "{\"value\": \"Hello world!\"}"; 55 | String messageText = "{\"id\": 38, \"result\": " + resultText + "}"; 56 | DevtoolsResult result = DevtoolsResult.fromJson(JavaxJson.parseObject(messageText)); 57 | assertThat(result.json()).isEqualTo(JavaxJson.parseObject(resultText)); 58 | } 59 | } 60 | -------------------------------------------------------------------------------- /javatests/com/google/devtoolsdriver/webdriver/JsAtomsTest.java: -------------------------------------------------------------------------------- 1 | // Copyright 2017 Google Inc. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | package com.google.devtoolsdriver.webdriver; 16 | 17 | import static com.google.common.truth.Truth.assertThat; 18 | 19 | import com.google.devtoolsdriver.webdriver.JsAtoms.JsFunction; 20 | import java.util.Arrays; 21 | import org.junit.Test; 22 | import org.junit.runner.RunWith; 23 | import org.junit.runners.JUnit4; 24 | 25 | /** Unit tests for {@link JsAtoms}. */ 26 | @RunWith(JUnit4.class) 27 | public class JsAtomsTest { 28 | @Test 29 | public void testAllAtomFunctions() { 30 | for (JsFunction function : JsFunction.values()) { 31 | assertThat(function.call(fakeArgs(function))).isNotNull(); 32 | } 33 | } 34 | 35 | private static String[] fakeArgs(JsFunction function) { 36 | String[] fakeArgs = new String[function.numArgs()]; 37 | Arrays.fill(fakeArgs, "arg"); 38 | return fakeArgs; 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /third_party/ios_driver/org/uiautomation/ios/HostInfo.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2012-2013 eBay Software Foundation and ios-driver committers 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except 5 | * in compliance with the License. You may obtain a copy of the License at 6 | * 7 | * http://www.apache.org/licenses/LICENSE-2.0 8 | * 9 | * Unless required by applicable law or agreed to in writing, software distributed under the License 10 | * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express 11 | * or implied. See the License for the specific language governing permissions and limitations under 12 | * the License. 13 | */ 14 | 15 | package org.uiautomation.ios; 16 | 17 | final class HostInfo { 18 | private static final String OS_NAME = System.getProperty("os.name"); 19 | private static final String OS_ARCH = System.getProperty("os.arch"); 20 | private static final String OS_VERSION = System.getProperty("os.version"); 21 | private static final String OS_INFO = OS_NAME + " " + OS_VERSION + " (" + OS_ARCH + ')'; 22 | private static final String JAVA_VERSION = System.getProperty("java.version"); 23 | 24 | static String osInfo() { 25 | return OS_INFO; 26 | } 27 | 28 | static String javaVersion() { 29 | return JAVA_VERSION; 30 | } 31 | 32 | private HostInfo() {} 33 | } 34 | -------------------------------------------------------------------------------- /third_party/ios_driver/org/uiautomation/ios/IOSServerConfiguration.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2012-2013 eBay Software Foundation and ios-driver committers 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except 5 | * in compliance with the License. You may obtain a copy of the License at 6 | * 7 | * http://www.apache.org/licenses/LICENSE-2.0 8 | * 9 | * Unless required by applicable law or agreed to in writing, software distributed under the License 10 | * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express 11 | * or implied. See the License for the specific language governing permissions and limitations under 12 | * the License. 13 | */ 14 | 15 | package org.uiautomation.ios; 16 | 17 | import com.beust.jcommander.Parameter; 18 | 19 | /** 20 | * Class IOSServerConfiguration Configures with the given configurable arguments: -port # 21 | * Start server in port with value . Default port = 5555. 22 | */ 23 | public abstract class IOSServerConfiguration { 24 | @Parameter(description = "port the server will listen on.", names = "-port") 25 | private int port = 5555; 26 | 27 | /** 28 | * *********************************************************************************************** 29 | * ****** DO NOT DELETE THIS METHOD. IF YOU DELETE IT, JCOMMANDER CANNOT SET THE PORT FLAG! ****** 30 | * *********************************************************************************************** 31 | */ 32 | public void setPort(int port) { 33 | this.port = port; 34 | } 35 | 36 | public int getPort() { 37 | return port; 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /third_party/ios_driver/org/uiautomation/ios/IOSServerManager.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2012-2013 eBay Software Foundation and ios-driver committers 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except 5 | * in compliance with the License. You may obtain a copy of the License at 6 | * 7 | * http://www.apache.org/licenses/LICENSE-2.0 8 | * 9 | * Unless required by applicable law or agreed to in writing, software distributed under the License 10 | * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express 11 | * or implied. See the License for the specific language governing permissions and limitations under 12 | * the License. 13 | */ 14 | package org.uiautomation.ios; 15 | 16 | import com.google.common.collect.Sets; 17 | import com.google.devtoolsdriver.webdriver.BrowserLauncher; 18 | import java.io.File; 19 | import java.util.Set; 20 | import java.util.logging.FileHandler; 21 | import java.util.logging.LogManager; 22 | import java.util.logging.Logger; 23 | import org.openqa.selenium.WebDriverException; 24 | import org.openqa.selenium.remote.DesiredCapabilities; 25 | import org.uiautomation.ios.ServerSideSession.SessionState; 26 | 27 | /** Manages the ios-driver server sessions. */ 28 | public final class IOSServerManager { 29 | private static final Logger log = Logger.getLogger(IOSServerManager.class.getName()); 30 | 31 | private final Set sessions = Sets.newConcurrentHashSet(); 32 | private final Set stoppedSessionIds = Sets.newConcurrentHashSet(); 33 | private final BrowserLauncher launcher; 34 | private final Object lock = new Object(); 35 | private State state = State.stopped; 36 | 37 | /** State of the server. */ 38 | public enum State { 39 | starting, 40 | running, 41 | stopping, 42 | stopped; 43 | } 44 | 45 | IOSServerManager(BrowserLauncher launcher) { 46 | // force stop session if running for too long 47 | setState(State.starting); 48 | this.launcher = launcher; 49 | 50 | // setup logging 51 | String loggingConfigFile = System.getProperty("java.util.logging.config.file"); 52 | if (loggingConfigFile != null) { 53 | if (!new File(loggingConfigFile).exists()) { 54 | System.err.println( 55 | "logging file not found: " + new File(loggingConfigFile).getAbsolutePath()); 56 | loggingConfigFile = null; // to revert to builtin one 57 | } 58 | } 59 | if (loggingConfigFile == null) { 60 | // do not use builtin ios-logging.properties if -Djava.util.logging.config.file set 61 | // or if skipLoggingConfiguration is set to true 62 | try { 63 | LogManager.getLogManager() 64 | .readConfiguration( 65 | IOSServerManager.class.getResourceAsStream("/ios-logging.properties")); 66 | } catch (Exception e) { 67 | System.err.println("Cannot configure logger."); 68 | } 69 | } 70 | 71 | setState(State.running); 72 | } 73 | 74 | public void stop() { 75 | for (java.util.logging.Handler h : log.getHandlers()) { 76 | if (h instanceof FileHandler) { 77 | ((FileHandler) h).close(); 78 | } 79 | } 80 | for (ServerSideSession session : sessions) { 81 | session.stop(); 82 | } 83 | sessions.clear(); 84 | } 85 | 86 | public ServerSideSession createSession(DesiredCapabilities cap) { 87 | if (getState() != State.running) { 88 | return null; 89 | } 90 | ServerSideSession session = new ServerSideSession(this, cap, launcher); 91 | sessions.add(session); 92 | return session; 93 | } 94 | 95 | void registerSessionHasStop(ServerSideSession session) { 96 | stoppedSessionIds.add(session.getSessionId()); 97 | sessions.remove(session); 98 | } 99 | 100 | public Set getSessions() { 101 | return sessions; 102 | } 103 | 104 | public ServerSideSession getSession(String sessionId) { 105 | // first, check if the session stopped already 106 | if (stoppedSessionIds.contains(sessionId)) { 107 | throw newSessionStoppedException(sessionId); 108 | } 109 | 110 | // check if the session is in the process of stopping 111 | for (ServerSideSession session : sessions) { 112 | if (session.getSessionId().equals(sessionId)) { 113 | if (session.getSessionState() == SessionState.STOPPED) { 114 | throw newSessionStoppedException(sessionId); 115 | } else { 116 | return session; 117 | } 118 | } 119 | } 120 | 121 | throw new WebDriverException("Cannot find session " + sessionId + " on the server."); 122 | } 123 | 124 | private static WebDriverException newSessionStoppedException(String sessionId) { 125 | return new WebDriverException(String.format("Session %s stopped", sessionId)); 126 | } 127 | 128 | public void stopGracefully() throws InterruptedException { 129 | // refuse further requests 130 | setState(State.stopping); 131 | // wait for requests to be processed 132 | while (getSessions().size() != 0) { 133 | Thread.sleep(250); 134 | } 135 | // stops 136 | stop(); 137 | setState(State.stopped); 138 | } 139 | 140 | private void setState(State state) { 141 | synchronized (lock) { 142 | this.state = state; 143 | } 144 | } 145 | 146 | private State getState() { 147 | synchronized (lock) { 148 | return this.state; 149 | } 150 | } 151 | } 152 | -------------------------------------------------------------------------------- /third_party/ios_driver/org/uiautomation/ios/SafariDriver.java: -------------------------------------------------------------------------------- 1 | // Copyright 2017 Google Inc. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | package org.uiautomation.ios; 16 | 17 | import com.beust.jcommander.JCommander; 18 | import com.beust.jcommander.Parameter; 19 | import com.google.devtoolsdriver.safari.SafariBrowserLauncher; 20 | import com.google.iosdevicecontrol.real.RealDeviceHost; 21 | import java.nio.file.Paths; 22 | import java.util.ArrayList; 23 | import java.util.Collections; 24 | import java.util.HashSet; 25 | import java.util.List; 26 | import java.util.Set; 27 | 28 | /** Runner class for a webdriver for Safari */ 29 | public final class SafariDriver { 30 | public static void main(String[] args) throws Exception { 31 | WebDriverMain.getTmpIOSFolder(); // Ensures logging directory exists. 32 | SafariIOSServerConfiguration options = new SafariIOSServerConfiguration(); 33 | new JCommander(options).parse(args); 34 | 35 | SafariBrowserLauncher launcher; 36 | if (options.getIsSimulator()) { 37 | launcher = SafariBrowserLauncher.onSimulator(true); 38 | } else { 39 | RealDeviceHost.Configuration hostConf = RealDeviceHost.withDeveloperDiskImagesFromXcode(); 40 | if (!options.supervisionCert.isEmpty() && !options.supervisionKey.isEmpty()) { 41 | hostConf = 42 | hostConf.withSupervisionIdentity( 43 | Paths.get(options.supervisionCert), Paths.get(options.supervisionKey)); 44 | } else if (options.supervisionCert.isEmpty() != options.supervisionKey.isEmpty()) { 45 | throw new IllegalArgumentException("Supervision cert passed without key, or vice-versa"); 46 | } 47 | launcher = SafariBrowserLauncher.onRealDevice(hostConf.initialize()); 48 | } 49 | 50 | WebDriverMain.run(options, launcher); 51 | } 52 | 53 | private static class SafariIOSServerConfiguration extends IOSServerConfiguration { 54 | @Parameter(description = "supported real device uuid to whitelist.", names = "-uuid") 55 | private final List uuidWhitelist = new ArrayList<>(); 56 | 57 | @Parameter( 58 | description = "optional set true to run against simulator, defaults to real device", 59 | names = "-simulator" 60 | ) 61 | private boolean isSimulator = false; 62 | 63 | @Parameter( 64 | description = "path to the supervision certificate for real devices.", 65 | names = "-supervision_cert" 66 | ) 67 | private String supervisionCert = ""; 68 | 69 | @Parameter( 70 | description = "path to the supervision private key for real devices.", 71 | names = "-supervision_key" 72 | ) 73 | private String supervisionKey = ""; 74 | 75 | private SafariIOSServerConfiguration() {} 76 | 77 | public Set getUuidWhitelist() { 78 | return Collections.unmodifiableSet(new HashSet<>(uuidWhitelist)); 79 | } 80 | 81 | boolean getIsSimulator() { 82 | return isSimulator; 83 | } 84 | 85 | public String getSupervisionCert() { 86 | return supervisionCert; 87 | } 88 | 89 | public String getSupervisionKey() { 90 | return supervisionKey; 91 | } 92 | } 93 | 94 | private SafariDriver() {} 95 | } 96 | -------------------------------------------------------------------------------- /third_party/ios_driver/org/uiautomation/ios/ServerSideSession.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2012-2013 eBay Software Foundation and ios-driver committers 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except 5 | * in compliance with the License. You may obtain a copy of the License at 6 | * 7 | * http://www.apache.org/licenses/LICENSE-2.0 8 | * 9 | * Unless required by applicable law or agreed to in writing, software distributed under the License 10 | * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express 11 | * or implied. See the License for the specific language governing permissions and limitations under 12 | * the License. 13 | */ 14 | package org.uiautomation.ios; 15 | 16 | import static com.google.common.base.Preconditions.checkNotNull; 17 | import static org.openqa.selenium.remote.CapabilityType.LOGGING_PREFS; 18 | 19 | import com.google.devtoolsdriver.webdriver.BrowserLauncher; 20 | import java.util.UUID; 21 | import java.util.logging.Level; 22 | import java.util.logging.Logger; 23 | import javax.annotation.concurrent.GuardedBy; 24 | import org.openqa.selenium.SessionNotCreatedException; 25 | import org.openqa.selenium.logging.LoggingPreferences; 26 | import org.openqa.selenium.remote.DesiredCapabilities; 27 | import org.uiautomation.ios.command.configuration.DriverConfigurationStore; 28 | import org.uiautomation.ios.drivers.RemoteIOSWebDriver; 29 | import org.uiautomation.ios.logging.IOSLogManager; 30 | import org.uiautomation.ios.servlet.CommandConfiguration; 31 | import org.uiautomation.ios.servlet.DriverConfiguration; 32 | import org.uiautomation.ios.servlet.WebDriverLikeCommand; 33 | 34 | /** A WebDriver session. */ 35 | public final class ServerSideSession { 36 | /** State of a session. */ 37 | enum SessionState { 38 | CREATED, 39 | RUNNING, 40 | STOPPED 41 | } 42 | 43 | private static final Logger log = Logger.getLogger(ServerSideSession.class.getName()); 44 | 45 | private final String sessionId; 46 | private final IOSServerManager server; 47 | private final DesiredCapabilities capabilities; 48 | private final RemoteIOSWebDriver driver; 49 | private final DriverConfiguration configuration; 50 | private final IOSLogManager logManager; 51 | 52 | @GuardedBy("this") 53 | private SessionState state = SessionState.CREATED; 54 | 55 | ServerSideSession( 56 | IOSServerManager server, DesiredCapabilities desiredCapabilities, BrowserLauncher launcher) { 57 | sessionId = UUID.randomUUID().toString(); 58 | this.server = checkNotNull(server); 59 | this.capabilities = checkNotNull(desiredCapabilities); 60 | 61 | logManager = createLogManager(desiredCapabilities); 62 | driver = new RemoteIOSWebDriver(this, launcher); 63 | configuration = new DriverConfigurationStore(); 64 | } 65 | 66 | private static IOSLogManager createLogManager(DesiredCapabilities caps) { 67 | LoggingPreferences loggingPrefs = (LoggingPreferences) caps.getCapability(LOGGING_PREFS); 68 | if (loggingPrefs == null) { 69 | loggingPrefs = new LoggingPreferences(); 70 | } 71 | try { 72 | return new IOSLogManager(loggingPrefs); 73 | } catch (Exception ex) { 74 | log.log(Level.SEVERE, "log manager error", ex); 75 | throw new SessionNotCreatedException("Cannot create logManager", ex); 76 | } 77 | } 78 | 79 | public String getSessionId() { 80 | return sessionId; 81 | } 82 | 83 | public synchronized SessionState getSessionState() { 84 | return state; 85 | } 86 | 87 | public DesiredCapabilities getCapabilities() { 88 | return capabilities; 89 | } 90 | 91 | public CommandConfiguration configure(WebDriverLikeCommand command) { 92 | return configuration.configure(command); 93 | } 94 | 95 | public RemoteIOSWebDriver getWebDriver() { 96 | return driver; 97 | } 98 | 99 | public synchronized void start() { 100 | driver.start(); 101 | state = SessionState.RUNNING; 102 | } 103 | 104 | public synchronized void stop() { 105 | if (state != SessionState.STOPPED) { 106 | state = SessionState.STOPPED; 107 | server.registerSessionHasStop(this); 108 | driver.close(); 109 | } 110 | } 111 | 112 | public IOSLogManager getLogManager() { 113 | return logManager; 114 | } 115 | 116 | @Override 117 | public String toString() { 118 | return sessionId; 119 | } 120 | } 121 | -------------------------------------------------------------------------------- /third_party/ios_driver/org/uiautomation/ios/WebDriverMain.java: -------------------------------------------------------------------------------- 1 | // Copyright 2017 Google Inc. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | package org.uiautomation.ios; 16 | 17 | import com.google.devtoolsdriver.webdriver.BrowserLauncher; 18 | import java.io.File; 19 | import java.util.logging.Level; 20 | import java.util.logging.Logger; 21 | 22 | /** Runner class for a webdriver for a generic browser */ 23 | final class WebDriverMain { 24 | private static final Logger log = Logger.getLogger(WebDriverMain.class.getName()); 25 | 26 | /** Start a webdriver server for the browser specified by factory. */ 27 | static void run(IOSServerConfiguration options, BrowserLauncher launcher) { 28 | final IOSServer server = new IOSServer(options, launcher); 29 | Runtime.getRuntime() 30 | .addShutdownHook( 31 | new Thread() { 32 | @Override 33 | public void run() { 34 | try { 35 | server.stopGracefully(); 36 | } catch (Exception e) { 37 | log.log(Level.SEVERE, "error in shutdown hook", e); 38 | } 39 | } 40 | }); 41 | 42 | try { 43 | server.start(); 44 | } catch (Exception e) { 45 | log.log(Level.SEVERE, "cannot start ios-driver server.", e); 46 | Runtime.getRuntime().exit(1); 47 | } 48 | } 49 | 50 | static File getTmpIOSFolder() { 51 | File f = new File(System.getProperty("java.io.tmpdir") + "/.ios-driver/"); 52 | f.mkdirs(); 53 | return f; 54 | } 55 | 56 | private WebDriverMain() {} 57 | } 58 | -------------------------------------------------------------------------------- /third_party/ios_driver/org/uiautomation/ios/command/AddCookieHandler.java: -------------------------------------------------------------------------------- 1 | // Copyright 2017 Google Inc. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | package org.uiautomation.ios.command; 16 | 17 | import java.net.URL; 18 | import java.time.Instant; 19 | import java.time.OffsetDateTime; 20 | import java.time.ZoneOffset; 21 | import javax.json.JsonObject; 22 | import org.openqa.selenium.remote.Response; 23 | import org.uiautomation.ios.IOSServerManager; 24 | import org.uiautomation.ios.servlet.WebDriverLikeRequest; 25 | 26 | /** 27 | * Handles adding cookies. 28 | */ 29 | public class AddCookieHandler extends CommandHandler { 30 | public AddCookieHandler(IOSServerManager driver, WebDriverLikeRequest request) { 31 | super(driver, request); 32 | } 33 | 34 | @Override 35 | public Response handle() throws Exception { 36 | JsonObject payload = getRequest().getPayload(); 37 | JsonObject cookie = payload.getJsonObject("cookie"); 38 | 39 | String name = cookie.getString("name", ""); 40 | String value = cookie.getString("value", ""); 41 | String path = cookie.getString("path", "/"); 42 | String domain; 43 | if (cookie.containsKey("domain")) { 44 | domain = cookie.getString("domain"); 45 | } else { 46 | URL url = new URL(getWebDriver().getCurrentUrl()); 47 | domain = url.getHost(); 48 | } 49 | boolean secure = cookie.getBoolean("secure", false); 50 | boolean httpOnly = cookie.getBoolean("httpOnly", false); 51 | Instant expiry = 52 | cookie.containsKey("expiry") 53 | ? Instant.ofEpochSecond(cookie.getJsonNumber("expiry").longValueExact()) 54 | : OffsetDateTime.now(ZoneOffset.UTC).plusYears(20).toInstant(); 55 | 56 | getWebDriver().addCookie(name, value, path, domain, secure, httpOnly, expiry); 57 | Response res = new Response(); 58 | res.setSessionId(getSession().getSessionId()); 59 | res.setStatus(0); 60 | return res; 61 | } 62 | } 63 | -------------------------------------------------------------------------------- /third_party/ios_driver/org/uiautomation/ios/command/AlertHandler.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2012-2013 eBay Software Foundation and ios-driver committers 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except 5 | * in compliance with the License. You may obtain a copy of the License at 6 | * 7 | * http://www.apache.org/licenses/LICENSE-2.0 8 | * 9 | * Unless required by applicable law or agreed to in writing, software distributed under the License 10 | * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express 11 | * or implied. See the License for the specific language governing permissions and limitations under 12 | * the License. 13 | */ 14 | 15 | package org.uiautomation.ios.command; 16 | 17 | import org.openqa.selenium.remote.ErrorCodes; 18 | import org.openqa.selenium.remote.Response; 19 | import org.uiautomation.ios.IOSServerManager; 20 | import org.uiautomation.ios.servlet.WebDriverLikeRequest; 21 | 22 | /** 23 | * Handles WebDriver alert commands. 24 | */ 25 | public class AlertHandler extends CommandHandler { 26 | public AlertHandler(IOSServerManager driver, WebDriverLikeRequest request) { 27 | super(driver, request); 28 | } 29 | 30 | @Override 31 | public Response handle() throws Exception { 32 | // We don't have any way currently of dealing with alert dialogs with pure JS, so we respond to 33 | // every alert command with the "no alert present" error code. 34 | Response response = new Response(); 35 | response.setSessionId(getSession().getSessionId()); 36 | response.setStatus(ErrorCodes.NO_ALERT_PRESENT); 37 | response.setValue(new ErrorCodes().toState(ErrorCodes.NO_ALERT_PRESENT)); 38 | return response; 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /third_party/ios_driver/org/uiautomation/ios/command/BackHandler.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2012-2013 eBay Software Foundation and ios-driver committers 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except 5 | * in compliance with the License. You may obtain a copy of the License at 6 | * 7 | * http://www.apache.org/licenses/LICENSE-2.0 8 | * 9 | * Unless required by applicable law or agreed to in writing, software distributed under the License 10 | * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express 11 | * or implied. See the License for the specific language governing permissions and limitations under 12 | * the License. 13 | */ 14 | package org.uiautomation.ios.command; 15 | 16 | import org.json.JSONObject; 17 | import org.openqa.selenium.remote.Response; 18 | import org.uiautomation.ios.IOSServerManager; 19 | import org.uiautomation.ios.servlet.WebDriverLikeRequest; 20 | 21 | public class BackHandler extends CommandHandler { 22 | public BackHandler(IOSServerManager driver, WebDriverLikeRequest request) { 23 | super(driver, request); 24 | } 25 | 26 | @Override 27 | public Response handle() throws Exception { 28 | getWebDriver().back(); 29 | getWebDriver().getContext().newContext(); 30 | getWebDriver().waitForPageToLoad(); 31 | Response resp = new Response(); 32 | resp.setSessionId(getSession().getSessionId()); 33 | resp.setStatus(0); 34 | resp.setValue(new JSONObject()); 35 | return resp; 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /third_party/ios_driver/org/uiautomation/ios/command/ClearHandler.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2012-2013 eBay Software Foundation and ios-driver committers 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except 5 | * in compliance with the License. You may obtain a copy of the License at 6 | * 7 | * http://www.apache.org/licenses/LICENSE-2.0 8 | * 9 | * Unless required by applicable law or agreed to in writing, software distributed under the License 10 | * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express 11 | * or implied. See the License for the specific language governing permissions and limitations under 12 | * the License. 13 | */ 14 | package org.uiautomation.ios.command; 15 | 16 | import org.json.JSONObject; 17 | import org.openqa.selenium.remote.Response; 18 | import org.uiautomation.ios.IOSServerManager; 19 | import org.uiautomation.ios.servlet.WebDriverLikeRequest; 20 | import org.uiautomation.ios.wkrdp.model.RemoteWebElement; 21 | 22 | public class ClearHandler extends CommandHandler { 23 | public ClearHandler(IOSServerManager driver, WebDriverLikeRequest request) { 24 | super(driver, request); 25 | } 26 | 27 | @Override 28 | public Response handle() throws Exception { 29 | String ref = getRequest().getVariableValue(":reference"); 30 | RemoteWebElement element = getWebDriver().createElement(ref); 31 | element.clear(); 32 | Response resp = new Response(); 33 | resp.setSessionId(getSession().getSessionId()); 34 | resp.setStatus(0); 35 | resp.setValue(new JSONObject()); 36 | return resp; 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /third_party/ios_driver/org/uiautomation/ios/command/ClickHandler.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2012-2013 eBay Software Foundation and ios-driver committers 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except 5 | * in compliance with the License. You may obtain a copy of the License at 6 | * 7 | * http://www.apache.org/licenses/LICENSE-2.0 8 | * 9 | * Unless required by applicable law or agreed to in writing, software distributed under the License 10 | * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express 11 | * or implied. See the License for the specific language governing permissions and limitations under 12 | * the License. 13 | */ 14 | package org.uiautomation.ios.command; 15 | 16 | import org.json.JSONObject; 17 | import org.openqa.selenium.remote.Response; 18 | import org.uiautomation.ios.IOSServerManager; 19 | import org.uiautomation.ios.servlet.WebDriverLikeRequest; 20 | import org.uiautomation.ios.wkrdp.model.RemoteWebElement; 21 | 22 | public class ClickHandler extends CommandHandler { 23 | public ClickHandler(IOSServerManager driver, WebDriverLikeRequest request) { 24 | super(driver, request); 25 | } 26 | 27 | @Override 28 | public Response handle() throws Exception { 29 | String reference = getRequest().getVariableValue(":reference"); 30 | RemoteWebElement element = getWebDriver().createElement(reference); 31 | element.click(); 32 | 33 | Response resp = new Response(); 34 | resp.setSessionId(getSession().getSessionId()); 35 | resp.setStatus(0); 36 | resp.setValue(new JSONObject()); 37 | return resp; 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /third_party/ios_driver/org/uiautomation/ios/command/CommandHandler.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2012-2013 eBay Software Foundation and ios-driver committers 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except 5 | * in compliance with the License. You may obtain a copy of the License at 6 | * 7 | * http://www.apache.org/licenses/LICENSE-2.0 8 | * 9 | * Unless required by applicable law or agreed to in writing, software distributed under the License 10 | * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express 11 | * or implied. See the License for the specific language governing permissions and limitations under 12 | * the License. 13 | */ 14 | 15 | package org.uiautomation.ios.command; 16 | 17 | import org.openqa.selenium.remote.Response; 18 | import org.uiautomation.ios.IOSServerManager; 19 | import org.uiautomation.ios.ServerSideSession; 20 | import org.uiautomation.ios.drivers.RemoteIOSWebDriver; 21 | import org.uiautomation.ios.servlet.CommandConfiguration; 22 | import org.uiautomation.ios.servlet.WebDriverLikeRequest; 23 | 24 | /** Handles a WebDriver request. */ 25 | public abstract class CommandHandler { 26 | private final IOSServerManager server; 27 | private final ServerSideSession session; 28 | private final WebDriverLikeRequest request; 29 | 30 | CommandHandler(IOSServerManager server, WebDriverLikeRequest request) { 31 | this.server = server; 32 | this.request = request; 33 | 34 | if (request.hasVariable(":sessionId")) { 35 | session = server.getSession(request.getSession()); 36 | } else { 37 | session = null; 38 | } 39 | } 40 | 41 | public abstract Response handle() throws Exception; 42 | 43 | final RemoteIOSWebDriver getWebDriver() { 44 | return getSession().getWebDriver(); 45 | } 46 | 47 | final ServerSideSession getSession() { 48 | return session; 49 | } 50 | 51 | final IOSServerManager getServer() { 52 | return server; 53 | } 54 | 55 | final WebDriverLikeRequest getRequest() { 56 | return request; 57 | } 58 | 59 | final void waitForPageToLoad() { 60 | getWebDriver().waitForPageToLoad(); 61 | } 62 | 63 | @SuppressWarnings("unchecked") 64 | final T getConf(String key, T defaultValue) { 65 | CommandConfiguration conf = getSession().configure(getRequest().getGenericCommand()); 66 | T res = (T) conf.get(key); 67 | return res != null ? res : defaultValue; 68 | } 69 | 70 | final Response createResponse(Object value) { 71 | Response r = new Response(); 72 | r.setSessionId(getSession().getSessionId()); 73 | r.setStatus(0); 74 | r.setValue(value); 75 | return r; 76 | } 77 | } 78 | -------------------------------------------------------------------------------- /third_party/ios_driver/org/uiautomation/ios/command/CssPropertyHandler.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2012-2013 eBay Software Foundation and ios-driver committers 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except 5 | * in compliance with the License. You may obtain a copy of the License at 6 | * 7 | * http://www.apache.org/licenses/LICENSE-2.0 8 | * 9 | * Unless required by applicable law or agreed to in writing, software distributed under the License 10 | * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express 11 | * or implied. See the License for the specific language governing permissions and limitations under 12 | * the License. 13 | */ 14 | package org.uiautomation.ios.command; 15 | 16 | import org.openqa.selenium.remote.Response; 17 | import org.uiautomation.ios.IOSServerManager; 18 | import org.uiautomation.ios.servlet.WebDriverLikeRequest; 19 | import org.uiautomation.ios.wkrdp.model.RemoteWebElement; 20 | 21 | public class CssPropertyHandler extends CommandHandler { 22 | public CssPropertyHandler(IOSServerManager driver, WebDriverLikeRequest request) { 23 | super(driver, request); 24 | } 25 | 26 | @Override 27 | public Response handle() throws Exception { 28 | String propertyName = getRequest().getVariableValue(":name"); 29 | String ref = getRequest().getVariableValue(":reference"); 30 | RemoteWebElement element = getWebDriver().createElement(ref); 31 | Object value = element.getCssValue(propertyName); 32 | Response res = new Response(); 33 | res.setSessionId(getSession().getSessionId()); 34 | res.setStatus(0); 35 | res.setValue(value); 36 | return res; 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /third_party/ios_driver/org/uiautomation/ios/command/DeleteAllCookiesHandler.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2012-2013 eBay Software Foundation and ios-driver committers 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except 5 | * in compliance with the License. You may obtain a copy of the License at 6 | * 7 | * http://www.apache.org/licenses/LICENSE-2.0 8 | * 9 | * Unless required by applicable law or agreed to in writing, software distributed under the License 10 | * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express 11 | * or implied. See the License for the specific language governing permissions and limitations under 12 | * the License. 13 | */ 14 | 15 | package org.uiautomation.ios.command; 16 | 17 | import org.json.JSONObject; 18 | import org.openqa.selenium.Cookie; 19 | import org.openqa.selenium.remote.Response; 20 | import org.uiautomation.ios.IOSServerManager; 21 | import org.uiautomation.ios.servlet.WebDriverLikeRequest; 22 | import java.util.List; 23 | 24 | public class DeleteAllCookiesHandler extends CommandHandler { 25 | public DeleteAllCookiesHandler(IOSServerManager driver, WebDriverLikeRequest request) { 26 | super(driver, request); 27 | } 28 | 29 | @Override 30 | public Response handle() throws Exception { 31 | String url = getWebDriver().getCurrentUrl(); 32 | List cookies = getWebDriver().getCookies(); 33 | for (Cookie c : cookies) { 34 | getWebDriver().deleteCookie(c.getName(), url); 35 | } 36 | 37 | Response res = new Response(); 38 | res.setSessionId(getSession().getSessionId()); 39 | res.setStatus(0); 40 | res.setValue(new JSONObject()); 41 | return res; 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /third_party/ios_driver/org/uiautomation/ios/command/DeleteCookieByNameHandler.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2012-2013 eBay Software Foundation and ios-driver committers 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except 5 | * in compliance with the License. You may obtain a copy of the License at 6 | * 7 | * http://www.apache.org/licenses/LICENSE-2.0 8 | * 9 | * Unless required by applicable law or agreed to in writing, software distributed under the License 10 | * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express 11 | * or implied. See the License for the specific language governing permissions and limitations under 12 | * the License. 13 | */ 14 | 15 | package org.uiautomation.ios.command; 16 | 17 | import org.json.JSONObject; 18 | import org.openqa.selenium.remote.Response; 19 | import org.uiautomation.ios.IOSServerManager; 20 | import org.uiautomation.ios.servlet.WebDriverLikeRequest; 21 | 22 | public class DeleteCookieByNameHandler extends CommandHandler { 23 | public DeleteCookieByNameHandler(IOSServerManager driver, WebDriverLikeRequest request) { 24 | super(driver, request); 25 | } 26 | 27 | @Override 28 | public Response handle() throws Exception { 29 | String name = getRequest().getVariableValue(":name"); 30 | String url = getWebDriver().getCurrentUrl(); 31 | getWebDriver().deleteCookie(name, url); 32 | 33 | Response res = new Response(); 34 | res.setSessionId(getSession().getSessionId()); 35 | res.setStatus(0); 36 | res.setValue(new JSONObject()); 37 | return res; 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /third_party/ios_driver/org/uiautomation/ios/command/ExecuteAsyncScriptHandler.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2012-2013 eBay Software Foundation and ios-driver committers 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except 5 | * in compliance with the License. You may obtain a copy of the License at 6 | * 7 | * http://www.apache.org/licenses/LICENSE-2.0 8 | * 9 | * Unless required by applicable law or agreed to in writing, software distributed under the License 10 | * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express 11 | * or implied. See the License for the specific language governing permissions and limitations under 12 | * the License. 13 | */ 14 | package org.uiautomation.ios.command; 15 | 16 | import java.util.ArrayList; 17 | import java.util.Collection; 18 | import java.util.List; 19 | import javax.json.JsonArray; 20 | import org.json.JSONObject; 21 | import org.openqa.selenium.remote.Response; 22 | import org.uiautomation.ios.IOSServerManager; 23 | import org.uiautomation.ios.servlet.WebDriverLikeRequest; 24 | import org.uiautomation.ios.wkrdp.model.RemoteObject; 25 | import org.uiautomation.ios.wkrdp.model.RemoteWebElement; 26 | 27 | public class ExecuteAsyncScriptHandler extends CommandHandler { 28 | public ExecuteAsyncScriptHandler(IOSServerManager driver, WebDriverLikeRequest request) { 29 | super(driver, request); 30 | } 31 | 32 | @Override 33 | public Response handle() throws Exception { 34 | String script = getRequest().getPayload().getString("script"); 35 | JsonArray args = getRequest().getPayload().getJsonArray("args"); 36 | Object res = getWebDriver().executeAsyncScript(script, args); 37 | 38 | Response resp = new Response(); 39 | resp.setSessionId(getSession().getSessionId()); 40 | resp.setStatus(0); 41 | 42 | if (res instanceof RemoteObject) { 43 | RemoteObject ro = (RemoteObject) res; 44 | RemoteWebElement rwe = ro.getWebElement(); 45 | JSONObject jo = new JSONObject().put("ELEMENT", rwe.getReference()); 46 | resp.setValue(jo); 47 | } else if (res instanceof Integer) { 48 | resp.setValue(res); 49 | } else if (res instanceof Boolean) { 50 | resp.setValue(res); 51 | } else if (res instanceof Collection) { 52 | List rwes = new ArrayList<>(); 53 | 54 | @SuppressWarnings("unchecked") 55 | Collection all = (Collection) res; 56 | for (Object ro : all) { 57 | if (ro instanceof RemoteObject) { 58 | JSONObject 59 | jo = 60 | new JSONObject() 61 | .put("ELEMENT", "" + ((RemoteObject) ro).getWebElement().getNodeId().getId()); 62 | rwes.add(jo); 63 | } else { 64 | rwes.add(ro); 65 | } 66 | } 67 | 68 | resp.setValue(rwes); 69 | } else { 70 | resp.setValue(res); 71 | } 72 | 73 | return resp; 74 | } 75 | } 76 | -------------------------------------------------------------------------------- /third_party/ios_driver/org/uiautomation/ios/command/ExecuteScriptHandler.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2012-2013 eBay Software Foundation and ios-driver committers 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except 5 | * in compliance with the License. You may obtain a copy of the License at 6 | * 7 | * http://www.apache.org/licenses/LICENSE-2.0 8 | * 9 | * Unless required by applicable law or agreed to in writing, software distributed under the License 10 | * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express 11 | * or implied. See the License for the specific language governing permissions and limitations under 12 | * the License. 13 | */ 14 | package org.uiautomation.ios.command; 15 | 16 | import java.util.ArrayList; 17 | import java.util.Collection; 18 | import java.util.List; 19 | import javax.json.JsonArray; 20 | import org.json.JSONObject; 21 | import org.openqa.selenium.remote.Response; 22 | import org.uiautomation.ios.IOSServerManager; 23 | import org.uiautomation.ios.servlet.WebDriverLikeRequest; 24 | import org.uiautomation.ios.wkrdp.model.RemoteObject; 25 | import org.uiautomation.ios.wkrdp.model.RemoteWebElement; 26 | 27 | public class ExecuteScriptHandler extends CommandHandler { 28 | public ExecuteScriptHandler(IOSServerManager driver, WebDriverLikeRequest request) { 29 | super(driver, request); 30 | } 31 | 32 | @Override 33 | public Response handle() throws Exception { 34 | String script = getRequest().getPayload().getString("script"); 35 | JsonArray args = getRequest().getPayload().getJsonArray("args"); 36 | Object res = getWebDriver().executeScript(script, args); 37 | 38 | Response resp = new Response(); 39 | resp.setSessionId(getSession().getSessionId()); 40 | resp.setStatus(0); 41 | 42 | if (res instanceof RemoteObject) { 43 | RemoteObject ro = (RemoteObject) res; 44 | RemoteWebElement rwe = ro.getWebElement(); 45 | JSONObject jo = new JSONObject().put("ELEMENT", rwe.getReference()); 46 | resp.setValue(jo); 47 | } else if (res instanceof Integer) { 48 | resp.setValue(res); 49 | } else if (res instanceof Boolean) { 50 | resp.setValue(res); 51 | } else if (res instanceof Collection) { 52 | List rwes = new ArrayList<>(); 53 | 54 | @SuppressWarnings("unchecked") 55 | Collection all = (Collection) res; 56 | for (Object ro : all) { 57 | if (ro instanceof RemoteObject) { 58 | JSONObject 59 | jo = 60 | new JSONObject() 61 | .put("ELEMENT", "" + ((RemoteObject) ro).getWebElement().getNodeId().getId()); 62 | rwes.add(jo); 63 | } else { 64 | rwes.add(ro); 65 | } 66 | } 67 | 68 | resp.setValue(rwes); 69 | } else { 70 | resp.setValue(res); 71 | } 72 | 73 | return resp; 74 | } 75 | } 76 | -------------------------------------------------------------------------------- /third_party/ios_driver/org/uiautomation/ios/command/FindElementHandler.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2012-2013 eBay Software Foundation and ios-driver committers 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except 5 | * in compliance with the License. You may obtain a copy of the License at 6 | * 7 | * http://www.apache.org/licenses/LICENSE-2.0 8 | * 9 | * Unless required by applicable law or agreed to in writing, software distributed under the License 10 | * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express 11 | * or implied. See the License for the specific language governing permissions and limitations under 12 | * the License. 13 | */ 14 | package org.uiautomation.ios.command; 15 | 16 | import javax.json.JsonObject; 17 | import org.json.JSONObject; 18 | import org.openqa.selenium.NoSuchElementException; 19 | import org.openqa.selenium.remote.Response; 20 | import org.uiautomation.ios.IOSServerManager; 21 | import org.uiautomation.ios.servlet.WebDriverLikeRequest; 22 | import org.uiautomation.ios.wkrdp.model.RemoteWebElement; 23 | 24 | public class FindElementHandler extends CommandHandler { 25 | public FindElementHandler(IOSServerManager driver, WebDriverLikeRequest request) { 26 | super(driver, request); 27 | } 28 | 29 | @Override 30 | public Response handle() throws Exception { 31 | waitForPageToLoad(); 32 | 33 | int implicitWait = getConf("implicit_wait", 0); 34 | long deadline = System.currentTimeMillis() + implicitWait; 35 | RemoteWebElement rwe = null; 36 | do { 37 | try { 38 | rwe = findElement(); 39 | break; 40 | } catch (NoSuchElementException e) { 41 | // Ignore and try again. 42 | } 43 | } while (System.currentTimeMillis() < deadline); 44 | 45 | if (rwe == null) { 46 | throw new NoSuchElementException( 47 | "No element found for " + getRequest().getPayload() + " after waiting for " + implicitWait 48 | + " ms."); 49 | } else { 50 | JSONObject res = new JSONObject(); 51 | res.put("ELEMENT", rwe.getReference()); 52 | Response resp = new Response(); 53 | resp.setSessionId(getSession().getSessionId()); 54 | resp.setStatus(0); 55 | resp.setValue(res); 56 | return resp; 57 | } 58 | } 59 | 60 | private RemoteWebElement findElement() throws Exception { 61 | JsonObject payload = getRequest().getPayload(); 62 | String type = payload.getString("using"); 63 | String value = payload.getString("value"); 64 | 65 | RemoteWebElement element = null; 66 | 67 | if (getRequest().hasVariable(":reference")) { 68 | String reference = getRequest().getVariableValue(":reference"); 69 | element = getWebDriver().createElement(reference); 70 | } else { 71 | element = getWebDriver().getDocument(); 72 | } 73 | RemoteWebElement rwe; 74 | if ("link text".equals(type)) { 75 | rwe = element.findElementByLinkText(value, false); 76 | } else if ("partial link text".equals(type)) { 77 | rwe = element.findElementByLinkText(value, true); 78 | } else if ("xpath".equals(type)) { 79 | rwe = element.findElementByXpath(value); 80 | } else { 81 | String cssSelector = ToCSSSelectorConverter.convertToCSSSelector(type, value); 82 | rwe = element.findElementByCSSSelector(cssSelector); 83 | } 84 | return rwe; 85 | } 86 | } 87 | -------------------------------------------------------------------------------- /third_party/ios_driver/org/uiautomation/ios/command/FindElementsHandler.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2012-2013 eBay Software Foundation and ios-driver committers 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except 5 | * in compliance with the License. You may obtain a copy of the License at 6 | * 7 | * http://www.apache.org/licenses/LICENSE-2.0 8 | * 9 | * Unless required by applicable law or agreed to in writing, software distributed under the License 10 | * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express 11 | * or implied. See the License for the specific language governing permissions and limitations under 12 | * the License. 13 | */ 14 | package org.uiautomation.ios.command; 15 | 16 | import java.util.ArrayList; 17 | import java.util.List; 18 | import javax.json.JsonObject; 19 | import org.openqa.selenium.NoSuchElementException; 20 | import org.openqa.selenium.remote.Response; 21 | import org.uiautomation.ios.IOSServerManager; 22 | import org.uiautomation.ios.servlet.WebDriverLikeRequest; 23 | import org.uiautomation.ios.wkrdp.model.RemoteWebElement; 24 | 25 | public class FindElementsHandler extends CommandHandler { 26 | public FindElementsHandler(IOSServerManager driver, WebDriverLikeRequest request) { 27 | super(driver, request); 28 | } 29 | 30 | @Override 31 | public Response handle() throws Exception { 32 | waitForPageToLoad(); 33 | 34 | int implicitWait = getConf("implicit_wait", 0); 35 | long deadline = System.currentTimeMillis() + implicitWait; 36 | List elements = null; 37 | do { 38 | try { 39 | elements = findElements(); 40 | if (elements.size() != 0) { 41 | break; 42 | } 43 | } catch (NoSuchElementException e) { 44 | // Ignore and try again. 45 | } 46 | } while (System.currentTimeMillis() < deadline); 47 | 48 | List list = new ArrayList<>(); 49 | for (RemoteWebElement el : elements) { 50 | com.google.gson.JsonObject jsonObject = new com.google.gson.JsonObject(); 51 | jsonObject.addProperty("ELEMENT", el.getReference()); 52 | list.add(jsonObject); 53 | } 54 | 55 | Response resp = new Response(); 56 | resp.setSessionId(getSession().getSessionId()); 57 | resp.setStatus(0); 58 | resp.setValue(list); 59 | return resp; 60 | } 61 | 62 | private List findElements() throws Exception { 63 | JsonObject payload = getRequest().getPayload(); 64 | String type = payload.getString("using"); 65 | String value = payload.getString("value"); 66 | 67 | RemoteWebElement element = null; 68 | 69 | if (getRequest().hasVariable(":reference")) { 70 | String ref = getRequest().getVariableValue(":reference"); 71 | element = getWebDriver().createElement(ref); 72 | } else { 73 | element = getWebDriver().getDocument(); 74 | } 75 | 76 | List res; 77 | if ("link text".equals(type)) { 78 | res = element.findElementsByLinkText(value, false); 79 | } else if ("partial link text".equals(type)) { 80 | res = element.findElementsByLinkText(value, true); 81 | } else if ("xpath".equals(type)) { 82 | res = element.findElementsByXpath(value); 83 | } else { 84 | String cssSelector = ToCSSSelectorConverter.convertToCSSSelector(type, value); 85 | res = element.findElementsByCSSSelector(cssSelector); 86 | } 87 | return res; 88 | } 89 | } 90 | -------------------------------------------------------------------------------- /third_party/ios_driver/org/uiautomation/ios/command/ForwardHandler.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2012-2013 eBay Software Foundation and ios-driver committers 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except 5 | * in compliance with the License. You may obtain a copy of the License at 6 | * 7 | * http://www.apache.org/licenses/LICENSE-2.0 8 | * 9 | * Unless required by applicable law or agreed to in writing, software distributed under the License 10 | * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express 11 | * or implied. See the License for the specific language governing permissions and limitations under 12 | * the License. 13 | */ 14 | package org.uiautomation.ios.command; 15 | 16 | import org.json.JSONObject; 17 | import org.openqa.selenium.remote.Response; 18 | import org.uiautomation.ios.IOSServerManager; 19 | import org.uiautomation.ios.servlet.WebDriverLikeRequest; 20 | 21 | public class ForwardHandler extends CommandHandler { 22 | public ForwardHandler(IOSServerManager driver, WebDriverLikeRequest request) { 23 | super(driver, request); 24 | } 25 | 26 | @Override 27 | public Response handle() throws Exception { 28 | getWebDriver().getContext().newContext(); 29 | getWebDriver().forward(); 30 | 31 | Response res = new Response(); 32 | res.setSessionId(getSession().getSessionId()); 33 | res.setStatus(0); 34 | res.setValue(new JSONObject()); 35 | return res; 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /third_party/ios_driver/org/uiautomation/ios/command/GetAttributeHandler.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2012-2013 eBay Software Foundation and ios-driver committers 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except 5 | * in compliance with the License. You may obtain a copy of the License at 6 | * 7 | * http://www.apache.org/licenses/LICENSE-2.0 8 | * 9 | * Unless required by applicable law or agreed to in writing, software distributed under the License 10 | * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express 11 | * or implied. See the License for the specific language governing permissions and limitations under 12 | * the License. 13 | */ 14 | package org.uiautomation.ios.command; 15 | 16 | import org.openqa.selenium.remote.Response; 17 | import org.uiautomation.ios.IOSServerManager; 18 | import org.uiautomation.ios.servlet.WebDriverLikeRequest; 19 | import org.uiautomation.ios.wkrdp.model.RemoteWebElement; 20 | 21 | public class GetAttributeHandler extends CommandHandler { 22 | public GetAttributeHandler(IOSServerManager driver, WebDriverLikeRequest request) { 23 | super(driver, request); 24 | } 25 | 26 | @Override 27 | public Response handle() throws Exception { 28 | String attributeName = getRequest().getVariableValue(":name"); 29 | String ref = getRequest().getVariableValue(":reference"); 30 | RemoteWebElement element = getWebDriver().createElement(ref); 31 | Object value = element.getAttribute(attributeName); 32 | Response res = new Response(); 33 | res.setSessionId(getSession().getSessionId()); 34 | res.setStatus(0); 35 | res.setValue(value); 36 | return res; 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /third_party/ios_driver/org/uiautomation/ios/command/GetCapabilitiesHandler.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2012-2013 eBay Software Foundation and ios-driver committers 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except 5 | * in compliance with the License. You may obtain a copy of the License at 6 | * 7 | * http://www.apache.org/licenses/LICENSE-2.0 8 | * 9 | * Unless required by applicable law or agreed to in writing, software distributed under the License 10 | * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express 11 | * or implied. See the License for the specific language governing permissions and limitations under 12 | * the License. 13 | */ 14 | package org.uiautomation.ios.command; 15 | 16 | import org.openqa.selenium.remote.Response; 17 | import org.uiautomation.ios.IOSServerManager; 18 | import org.uiautomation.ios.servlet.WebDriverLikeRequest; 19 | 20 | /** Handler to return the browser capabilities. */ 21 | public class GetCapabilitiesHandler extends CommandHandler { 22 | public GetCapabilitiesHandler(IOSServerManager driver, WebDriverLikeRequest request) { 23 | super(driver, request); 24 | } 25 | 26 | @Override 27 | public synchronized Response handle() throws Exception { 28 | Response r = new Response(); 29 | r.setSessionId(getSession().getSessionId()); 30 | r.setValue(getWebDriver().capabilities()); 31 | r.setStatus(0); 32 | return r; 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /third_party/ios_driver/org/uiautomation/ios/command/GetConfigurationHandler.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2012-2013 eBay Software Foundation and ios-driver committers 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except 5 | * in compliance with the License. You may obtain a copy of the License at 6 | * 7 | * http://www.apache.org/licenses/LICENSE-2.0 8 | * 9 | * Unless required by applicable law or agreed to in writing, software distributed under the License 10 | * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express 11 | * or implied. See the License for the specific language governing permissions and limitations under 12 | * the License. 13 | */ 14 | package org.uiautomation.ios.command; 15 | 16 | import org.json.JSONObject; 17 | import org.openqa.selenium.remote.Response; 18 | import org.uiautomation.ios.IOSServerManager; 19 | import org.uiautomation.ios.servlet.CommandConfiguration; 20 | import org.uiautomation.ios.servlet.WebDriverLikeCommand; 21 | import org.uiautomation.ios.servlet.WebDriverLikeRequest; 22 | import java.util.Map; 23 | 24 | public class GetConfigurationHandler extends CommandHandler { 25 | public GetConfigurationHandler(IOSServerManager driver, WebDriverLikeRequest request) { 26 | super(driver, request); 27 | } 28 | 29 | @Override 30 | public Response handle() throws Exception { 31 | String name = getRequest().getVariableValue(":command"); 32 | WebDriverLikeCommand command = WebDriverLikeCommand.valueOf(name); 33 | 34 | CommandConfiguration conf = getSession().configure(command); 35 | 36 | JSONObject res = new JSONObject(); 37 | Map m = conf.getAll(); 38 | for (String key : m.keySet()) { 39 | res.put(key, m.get(key)); 40 | } 41 | 42 | Response resp = new Response(); 43 | resp.setSessionId(getSession().getSessionId()); 44 | resp.setStatus(0); 45 | resp.setValue(res); 46 | return resp; 47 | } 48 | } 49 | -------------------------------------------------------------------------------- /third_party/ios_driver/org/uiautomation/ios/command/GetCookiesHandler.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2012-2013 eBay Software Foundation and ios-driver committers 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except 5 | * in compliance with the License. You may obtain a copy of the License at 6 | * 7 | * http://www.apache.org/licenses/LICENSE-2.0 8 | * 9 | * Unless required by applicable law or agreed to in writing, software distributed under the License 10 | * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express 11 | * or implied. See the License for the specific language governing permissions and limitations under 12 | * the License. 13 | */ 14 | 15 | package org.uiautomation.ios.command; 16 | 17 | import org.openqa.selenium.Cookie; 18 | import org.openqa.selenium.remote.Response; 19 | import org.uiautomation.ios.IOSServerManager; 20 | import org.uiautomation.ios.servlet.WebDriverLikeRequest; 21 | import java.util.List; 22 | 23 | public class GetCookiesHandler extends CommandHandler { 24 | public GetCookiesHandler(IOSServerManager driver, WebDriverLikeRequest request) { 25 | super(driver, request); 26 | } 27 | 28 | @Override 29 | public Response handle() throws Exception { 30 | 31 | List cookies = getWebDriver().getCookies(); 32 | Response res = new Response(); 33 | res.setSessionId(getSession().getSessionId()); 34 | res.setStatus(0); 35 | res.setValue(cookies); 36 | return res; 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /third_party/ios_driver/org/uiautomation/ios/command/GetCurrentContextHandler.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2012-2013 eBay Software Foundation and ios-driver committers 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except 5 | * in compliance with the License. You may obtain a copy of the License at 6 | * 7 | * http://www.apache.org/licenses/LICENSE-2.0 8 | * 9 | * Unless required by applicable law or agreed to in writing, software distributed under the License 10 | * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express 11 | * or implied. See the License for the specific language governing permissions and limitations under 12 | * the License. 13 | */ 14 | package org.uiautomation.ios.command; 15 | 16 | import org.openqa.selenium.remote.Response; 17 | import org.uiautomation.ios.IOSServerManager; 18 | import org.uiautomation.ios.servlet.WebDriverLikeRequest; 19 | 20 | /** Handler to get the current context (window handle). */ 21 | public class GetCurrentContextHandler extends CommandHandler { 22 | public GetCurrentContextHandler(IOSServerManager driver, WebDriverLikeRequest request) { 23 | super(driver, request); 24 | } 25 | 26 | @Override 27 | public Response handle() throws Exception { 28 | String value = getWebDriver().getCurrentPageId().asString(); 29 | 30 | Response resp = new Response(); 31 | resp.setSessionId(getSession().getSessionId()); 32 | resp.setStatus(0); 33 | resp.setValue(value); 34 | return resp; 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /third_party/ios_driver/org/uiautomation/ios/command/GetElementSizeHandler.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2014 eBay Software Foundation and ios-driver committers 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except 5 | * in compliance with the License. You may obtain a copy of the License at 6 | * 7 | * http://www.apache.org/licenses/LICENSE-2.0 8 | * 9 | * Unless required by applicable law or agreed to in writing, software distributed under the License 10 | * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express 11 | * or implied. See the License for the specific language governing permissions and limitations under 12 | * the License. 13 | */ 14 | 15 | package org.uiautomation.ios.command; 16 | 17 | import org.openqa.selenium.Dimension; 18 | import org.openqa.selenium.remote.Response; 19 | import org.uiautomation.ios.IOSServerManager; 20 | import org.uiautomation.ios.servlet.WebDriverLikeRequest; 21 | import org.uiautomation.ios.wkrdp.model.RemoteWebElement; 22 | 23 | public class GetElementSizeHandler extends CommandHandler { 24 | public GetElementSizeHandler(IOSServerManager driver, WebDriverLikeRequest request) { 25 | super(driver, request); 26 | } 27 | 28 | @Override 29 | public Response handle() throws Exception { 30 | String ref = getRequest().getVariableValue(":reference"); 31 | RemoteWebElement element = getWebDriver().createElement(ref); 32 | Dimension size = element.getSize(); 33 | Response res = new Response(); 34 | res.setSessionId(getSession().getSessionId()); 35 | res.setStatus(0); 36 | res.setValue(size); 37 | return res; 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /third_party/ios_driver/org/uiautomation/ios/command/GetHandler.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2012-2013 eBay Software Foundation and ios-driver committers 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except 5 | * in compliance with the License. You may obtain a copy of the License at 6 | * 7 | * http://www.apache.org/licenses/LICENSE-2.0 8 | * 9 | * Unless required by applicable law or agreed to in writing, software distributed under the License 10 | * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express 11 | * or implied. See the License for the specific language governing permissions and limitations under 12 | * the License. 13 | */ 14 | package org.uiautomation.ios.command; 15 | 16 | import org.json.JSONObject; 17 | import org.openqa.selenium.remote.Response; 18 | import org.uiautomation.ios.IOSServerManager; 19 | import org.uiautomation.ios.servlet.WebDriverLikeRequest; 20 | 21 | /** 22 | * Handler to navigate to a specified url. 23 | */ 24 | public class GetHandler extends CommandHandler { 25 | public GetHandler(IOSServerManager driver, WebDriverLikeRequest request) { 26 | super(driver, request); 27 | } 28 | 29 | @Override 30 | public Response handle() throws Exception { 31 | String url = getRequest().getPayload().getString("url"); 32 | getWebDriver().get(url); 33 | Response res = new Response(); 34 | res.setSessionId(getSession().getSessionId()); 35 | res.setStatus(0); 36 | res.setValue(new JSONObject()); 37 | return res; 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /third_party/ios_driver/org/uiautomation/ios/command/GetLocationHandler.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2012-2013 eBay Software Foundation and ios-driver committers 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except 5 | * in compliance with the License. You may obtain a copy of the License at 6 | * 7 | * http://www.apache.org/licenses/LICENSE-2.0 8 | * 9 | * Unless required by applicable law or agreed to in writing, software distributed under the License 10 | * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express 11 | * or implied. See the License for the specific language governing permissions and limitations under 12 | * the License. 13 | */ 14 | 15 | package org.uiautomation.ios.command; 16 | 17 | import org.openqa.selenium.Point; 18 | import org.openqa.selenium.remote.Response; 19 | import org.uiautomation.ios.IOSServerManager; 20 | import org.uiautomation.ios.servlet.WebDriverLikeRequest; 21 | import org.uiautomation.ios.wkrdp.model.RemoteWebElement; 22 | 23 | public class GetLocationHandler extends CommandHandler { 24 | public GetLocationHandler(IOSServerManager driver, WebDriverLikeRequest request) { 25 | super(driver, request); 26 | } 27 | 28 | @Override 29 | public Response handle() throws Exception { 30 | String ref = getRequest().getVariableValue(":reference"); 31 | RemoteWebElement element = getWebDriver().createElement(ref); 32 | Point location = element.getLocation(); 33 | Response res = new Response(); 34 | res.setSessionId(getSession().getSessionId()); 35 | res.setStatus(0); 36 | res.setValue(location); 37 | return res; 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /third_party/ios_driver/org/uiautomation/ios/command/GetPageSizeHandler.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2012-2013 eBay Software Foundation and ios-driver committers 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except 5 | * in compliance with the License. You may obtain a copy of the License at 6 | * 7 | * http://www.apache.org/licenses/LICENSE-2.0 8 | * 9 | * Unless required by applicable law or agreed to in writing, software distributed under the License 10 | * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express 11 | * or implied. See the License for the specific language governing permissions and limitations under 12 | * the License. 13 | */ 14 | 15 | package org.uiautomation.ios.command; 16 | 17 | import org.openqa.selenium.remote.Response; 18 | import org.uiautomation.ios.IOSServerManager; 19 | import org.uiautomation.ios.servlet.WebDriverLikeRequest; 20 | 21 | public class GetPageSizeHandler extends CommandHandler { 22 | public GetPageSizeHandler(IOSServerManager driver, WebDriverLikeRequest request) { 23 | super(driver, request); 24 | } 25 | 26 | @Override 27 | public Response handle() throws Exception { 28 | Response res = new Response(); 29 | res.setSessionId(getSession().getSessionId()); 30 | res.setStatus(0); 31 | res.setValue(getWebDriver().getSize()); 32 | return res; 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /third_party/ios_driver/org/uiautomation/ios/command/GetPageSourceHandler.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2012-2013 eBay Software Foundation and ios-driver committers 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except 5 | * in compliance with the License. You may obtain a copy of the License at 6 | * 7 | * http://www.apache.org/licenses/LICENSE-2.0 8 | * 9 | * Unless required by applicable law or agreed to in writing, software distributed under the License 10 | * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express 11 | * or implied. See the License for the specific language governing permissions and limitations under 12 | * the License. 13 | */ 14 | 15 | package org.uiautomation.ios.command; 16 | 17 | import org.openqa.selenium.remote.Response; 18 | import org.uiautomation.ios.IOSServerManager; 19 | import org.uiautomation.ios.servlet.WebDriverLikeRequest; 20 | 21 | public class GetPageSourceHandler extends CommandHandler { 22 | public GetPageSourceHandler(IOSServerManager driver, WebDriverLikeRequest request) { 23 | super(driver, request); 24 | } 25 | 26 | @Override 27 | public Response handle() throws Exception { 28 | Response res = new Response(); 29 | res.setSessionId(getSession().getSessionId()); 30 | res.setStatus(0); 31 | res.setValue(getWebDriver().getPageSource()); 32 | return res; 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /third_party/ios_driver/org/uiautomation/ios/command/GetSessionsHandler.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2012-2013 eBay Software Foundation and ios-driver committers 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except 5 | * in compliance with the License. You may obtain a copy of the License at 6 | * 7 | * http://www.apache.org/licenses/LICENSE-2.0 8 | * 9 | * Unless required by applicable law or agreed to in writing, software distributed under the License 10 | * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express 11 | * or implied. See the License for the specific language governing permissions and limitations under 12 | * the License. 13 | */ 14 | 15 | package org.uiautomation.ios.command; 16 | 17 | import org.json.JSONArray; 18 | import org.json.JSONObject; 19 | import org.openqa.selenium.remote.DesiredCapabilities; 20 | import org.openqa.selenium.remote.Response; 21 | import org.uiautomation.ios.IOSServerManager; 22 | import org.uiautomation.ios.ServerSideSession; 23 | import org.uiautomation.ios.servlet.WebDriverLikeRequest; 24 | 25 | public class GetSessionsHandler extends CommandHandler { 26 | public GetSessionsHandler(IOSServerManager driver, WebDriverLikeRequest request) { 27 | super(driver, request); 28 | } 29 | 30 | @Override 31 | public Response handle() throws Exception { 32 | JSONArray res = new JSONArray(); 33 | for (ServerSideSession s : getServer().getSessions()) { 34 | JSONObject session = new JSONObject(); 35 | session.put("id", s.getSessionId()); 36 | session.put("capabilities", new DesiredCapabilities()); 37 | res.put(session); 38 | } 39 | 40 | Response resp = new Response(); 41 | resp.setSessionId("dummy one"); 42 | resp.setStatus(0); 43 | resp.setValue(res.toString()); 44 | return resp; 45 | } 46 | } 47 | -------------------------------------------------------------------------------- /third_party/ios_driver/org/uiautomation/ios/command/GetTagNameHandler.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2012-2013 eBay Software Foundation and ios-driver committers 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except 5 | * in compliance with the License. You may obtain a copy of the License at 6 | * 7 | * http://www.apache.org/licenses/LICENSE-2.0 8 | * 9 | * Unless required by applicable law or agreed to in writing, software distributed under the License 10 | * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express 11 | * or implied. See the License for the specific language governing permissions and limitations under 12 | * the License. 13 | */ 14 | package org.uiautomation.ios.command; 15 | 16 | import org.openqa.selenium.remote.Response; 17 | import org.uiautomation.ios.IOSServerManager; 18 | import org.uiautomation.ios.servlet.WebDriverLikeRequest; 19 | import org.uiautomation.ios.wkrdp.model.RemoteWebElement; 20 | 21 | public class GetTagNameHandler extends CommandHandler { 22 | public GetTagNameHandler(IOSServerManager driver, WebDriverLikeRequest request) { 23 | super(driver, request); 24 | } 25 | 26 | @Override 27 | public Response handle() throws Exception { 28 | String ref = getRequest().getVariableValue(":reference"); 29 | RemoteWebElement element = getWebDriver().createElement(ref); 30 | String value = element.getTagName(); 31 | Response res = new Response(); 32 | res.setSessionId(getSession().getSessionId()); 33 | res.setStatus(0); 34 | res.setValue(value); 35 | return res; 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /third_party/ios_driver/org/uiautomation/ios/command/GetTextHandler.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2012-2013 eBay Software Foundation and ios-driver committers 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except 5 | * in compliance with the License. You may obtain a copy of the License at 6 | * 7 | * http://www.apache.org/licenses/LICENSE-2.0 8 | * 9 | * Unless required by applicable law or agreed to in writing, software distributed under the License 10 | * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express 11 | * or implied. See the License for the specific language governing permissions and limitations under 12 | * the License. 13 | */ 14 | package org.uiautomation.ios.command; 15 | 16 | import org.openqa.selenium.remote.Response; 17 | import org.uiautomation.ios.IOSServerManager; 18 | import org.uiautomation.ios.servlet.WebDriverLikeRequest; 19 | import org.uiautomation.ios.wkrdp.model.RemoteWebElement; 20 | 21 | public class GetTextHandler extends CommandHandler { 22 | public GetTextHandler(IOSServerManager driver, WebDriverLikeRequest request) { 23 | super(driver, request); 24 | } 25 | 26 | @Override 27 | public Response handle() throws Exception { 28 | String ref = getRequest().getVariableValue(":reference"); 29 | RemoteWebElement element = getWebDriver().createElement(ref); 30 | String text = element.getText(); 31 | Response res = new Response(); 32 | res.setSessionId(getSession().getSessionId()); 33 | res.setStatus(0); 34 | res.setValue(text); 35 | return res; 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /third_party/ios_driver/org/uiautomation/ios/command/GetTitleHandler.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2012-2013 eBay Software Foundation and ios-driver committers 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except 5 | * in compliance with the License. You may obtain a copy of the License at 6 | * 7 | * http://www.apache.org/licenses/LICENSE-2.0 8 | * 9 | * Unless required by applicable law or agreed to in writing, software distributed under the License 10 | * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express 11 | * or implied. See the License for the specific language governing permissions and limitations under 12 | * the License. 13 | */ 14 | package org.uiautomation.ios.command; 15 | 16 | import org.openqa.selenium.remote.Response; 17 | import org.uiautomation.ios.IOSServerManager; 18 | import org.uiautomation.ios.servlet.WebDriverLikeRequest; 19 | 20 | public class GetTitleHandler extends CommandHandler { 21 | public GetTitleHandler(IOSServerManager driver, WebDriverLikeRequest request) { 22 | super(driver, request); 23 | } 24 | 25 | @Override 26 | public Response handle() throws Exception { 27 | waitForPageToLoad(); 28 | String title = getWebDriver().getTitle(); 29 | Response res = new Response(); 30 | res.setSessionId(getSession().getSessionId()); 31 | res.setStatus(0); 32 | res.setValue(title); 33 | return res; 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /third_party/ios_driver/org/uiautomation/ios/command/GetURL.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2012-2013 eBay Software Foundation and ios-driver committers 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except 5 | * in compliance with the License. You may obtain a copy of the License at 6 | * 7 | * http://www.apache.org/licenses/LICENSE-2.0 8 | * 9 | * Unless required by applicable law or agreed to in writing, software distributed under the License 10 | * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express 11 | * or implied. See the License for the specific language governing permissions and limitations under 12 | * the License. 13 | */ 14 | package org.uiautomation.ios.command; 15 | 16 | import org.openqa.selenium.remote.Response; 17 | import org.uiautomation.ios.IOSServerManager; 18 | import org.uiautomation.ios.servlet.WebDriverLikeRequest; 19 | 20 | public class GetURL extends CommandHandler { 21 | public GetURL(IOSServerManager driver, WebDriverLikeRequest request) { 22 | super(driver, request); 23 | } 24 | 25 | @Override 26 | public Response handle() throws Exception { 27 | String url = getWebDriver().getCurrentUrl(); 28 | Response res = new Response(); 29 | res.setSessionId(getSession().getSessionId()); 30 | res.setStatus(0); 31 | res.setValue(url); 32 | return res; 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /third_party/ios_driver/org/uiautomation/ios/command/GetWindowHandlesHandler.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2012-2013 eBay Software Foundation and ios-driver committers 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except 5 | * in compliance with the License. You may obtain a copy of the License at 6 | * 7 | * http://www.apache.org/licenses/LICENSE-2.0 8 | * 9 | * Unless required by applicable law or agreed to in writing, software distributed under the License 10 | * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express 11 | * or implied. See the License for the specific language governing permissions and limitations under 12 | * the License. 13 | */ 14 | package org.uiautomation.ios.command; 15 | 16 | import com.google.devtoolsdriver.webdriver.PageId; 17 | import java.util.HashSet; 18 | import java.util.Set; 19 | import org.openqa.selenium.remote.Response; 20 | import org.uiautomation.ios.IOSServerManager; 21 | import org.uiautomation.ios.servlet.WebDriverLikeRequest; 22 | 23 | /** Handler to retrieve all the window handles. */ 24 | public class GetWindowHandlesHandler extends CommandHandler { 25 | public GetWindowHandlesHandler(IOSServerManager driver, WebDriverLikeRequest request) { 26 | super(driver, request); 27 | } 28 | 29 | @Override 30 | public Response handle() throws Exception { 31 | Set handles = new HashSet<>(); 32 | for (PageId pageId : getWebDriver().listPages()) { 33 | handles.add(pageId.asString()); 34 | } 35 | 36 | Response resp = new Response(); 37 | resp.setSessionId(getSession().getSessionId()); 38 | resp.setStatus(0); 39 | resp.setValue(handles); 40 | return resp; 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /third_party/ios_driver/org/uiautomation/ios/command/IsDisplayedHandler.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2012-2013 eBay Software Foundation and ios-driver committers 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except 5 | * in compliance with the License. You may obtain a copy of the License at 6 | * 7 | * http://www.apache.org/licenses/LICENSE-2.0 8 | * 9 | * Unless required by applicable law or agreed to in writing, software distributed under the License 10 | * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express 11 | * or implied. See the License for the specific language governing permissions and limitations under 12 | * the License. 13 | */ 14 | package org.uiautomation.ios.command; 15 | 16 | import org.openqa.selenium.remote.Response; 17 | import org.uiautomation.ios.IOSServerManager; 18 | import org.uiautomation.ios.servlet.WebDriverLikeRequest; 19 | import org.uiautomation.ios.wkrdp.model.RemoteWebElement; 20 | 21 | public class IsDisplayedHandler extends CommandHandler { 22 | public IsDisplayedHandler(IOSServerManager driver, WebDriverLikeRequest request) { 23 | super(driver, request); 24 | } 25 | 26 | @Override 27 | public Response handle() throws Exception { 28 | String reference = getRequest().getVariableValue(":reference"); 29 | RemoteWebElement element = getWebDriver().createElement(reference); 30 | boolean isDisplayed = element.isDisplayed(); 31 | Response res = new Response(); 32 | res.setSessionId(getSession().getSessionId()); 33 | res.setStatus(0); 34 | res.setValue(isDisplayed); 35 | return res; 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /third_party/ios_driver/org/uiautomation/ios/command/IsEnabledHandler.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2012-2013 eBay Software Foundation and ios-driver committers 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except 5 | * in compliance with the License. You may obtain a copy of the License at 6 | * 7 | * http://www.apache.org/licenses/LICENSE-2.0 8 | * 9 | * Unless required by applicable law or agreed to in writing, software distributed under the License 10 | * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express 11 | * or implied. See the License for the specific language governing permissions and limitations under 12 | * the License. 13 | */ 14 | package org.uiautomation.ios.command; 15 | 16 | import org.openqa.selenium.remote.Response; 17 | import org.uiautomation.ios.IOSServerManager; 18 | import org.uiautomation.ios.servlet.WebDriverLikeRequest; 19 | import org.uiautomation.ios.wkrdp.model.RemoteWebElement; 20 | 21 | public class IsEnabledHandler extends CommandHandler { 22 | public IsEnabledHandler(IOSServerManager driver, WebDriverLikeRequest request) { 23 | super(driver, request); 24 | } 25 | 26 | @Override 27 | public Response handle() throws Exception { 28 | String ref = getRequest().getVariableValue(":reference"); 29 | RemoteWebElement element = getWebDriver().createElement(ref); 30 | boolean isEnabled = element.isEnabled(); 31 | Response res = new Response(); 32 | res.setSessionId(getSession().getSessionId()); 33 | res.setStatus(0); 34 | res.setValue(isEnabled); 35 | return res; 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /third_party/ios_driver/org/uiautomation/ios/command/IsEqualHandler.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2012-2013 eBay Software Foundation and ios-driver committers 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except 5 | * in compliance with the License. You may obtain a copy of the License at 6 | * 7 | * http://www.apache.org/licenses/LICENSE-2.0 8 | * 9 | * Unless required by applicable law or agreed to in writing, software distributed under the License 10 | * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express 11 | * or implied. See the License for the specific language governing permissions and limitations under 12 | * the License. 13 | */ 14 | package org.uiautomation.ios.command; 15 | 16 | import org.openqa.selenium.remote.Response; 17 | import org.uiautomation.ios.IOSServerManager; 18 | import org.uiautomation.ios.servlet.WebDriverLikeRequest; 19 | 20 | public class IsEqualHandler extends CommandHandler { 21 | public IsEqualHandler(IOSServerManager driver, WebDriverLikeRequest request) { 22 | super(driver, request); 23 | } 24 | 25 | @Override 26 | public Response handle() throws Exception { 27 | int id = Integer.parseInt(getRequest().getVariableValue(":reference")); 28 | int other = Integer.parseInt(getRequest().getVariableValue(":other")); 29 | boolean equal = equal(id, other); 30 | Response res = new Response(); 31 | res.setSessionId(getSession().getSessionId()); 32 | res.setStatus(0); 33 | res.setValue(equal); 34 | return res; 35 | } 36 | 37 | private boolean equal(int id, int other) throws Exception { 38 | if (id == other) { 39 | return true; 40 | } 41 | return id == other; 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /third_party/ios_driver/org/uiautomation/ios/command/IsSelectedHandler.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2012-2013 eBay Software Foundation and ios-driver committers 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except 5 | * in compliance with the License. You may obtain a copy of the License at 6 | * 7 | * http://www.apache.org/licenses/LICENSE-2.0 8 | * 9 | * Unless required by applicable law or agreed to in writing, software distributed under the License 10 | * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express 11 | * or implied. See the License for the specific language governing permissions and limitations under 12 | * the License. 13 | */ 14 | 15 | package org.uiautomation.ios.command; 16 | 17 | import org.openqa.selenium.remote.Response; 18 | import org.uiautomation.ios.IOSServerManager; 19 | import org.uiautomation.ios.servlet.WebDriverLikeRequest; 20 | import org.uiautomation.ios.wkrdp.model.RemoteWebElement; 21 | 22 | public class IsSelectedHandler extends CommandHandler { 23 | public IsSelectedHandler(IOSServerManager driver, WebDriverLikeRequest request) { 24 | super(driver, request); 25 | } 26 | 27 | @Override 28 | public Response handle() throws Exception { 29 | String ref = getRequest().getVariableValue(":reference"); 30 | RemoteWebElement element = getWebDriver().createElement(ref); 31 | boolean isSelected = element.isSelected(); 32 | Response res = new Response(); 33 | res.setSessionId(getSession().getSessionId()); 34 | res.setStatus(0); 35 | res.setValue(isSelected); 36 | return res; 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /third_party/ios_driver/org/uiautomation/ios/command/LogHandler.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2012-2013 eBay Software Foundation and ios-driver committers 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except 5 | * in compliance with the License. You may obtain a copy of the License at 6 | * 7 | * http://www.apache.org/licenses/LICENSE-2.0 8 | * 9 | * Unless required by applicable law or agreed to in writing, software distributed under the License 10 | * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express 11 | * or implied. See the License for the specific language governing permissions and limitations under 12 | * the License. 13 | */ 14 | package org.uiautomation.ios.command; 15 | 16 | import java.util.List; 17 | import javax.json.JsonObject; 18 | import org.openqa.selenium.logging.LogEntry; 19 | import org.openqa.selenium.remote.Response; 20 | import org.uiautomation.ios.IOSServerManager; 21 | import org.uiautomation.ios.ServerSideSession; 22 | import org.uiautomation.ios.servlet.WebDriverLikeRequest; 23 | 24 | public class LogHandler extends CommandHandler { 25 | public LogHandler(IOSServerManager driver, WebDriverLikeRequest request) { 26 | super(driver, request); 27 | } 28 | 29 | @Override 30 | public Response handle() throws Exception { 31 | ServerSideSession session = getSession(); 32 | JsonObject payload = getRequest().getPayload(); 33 | String type = payload.getString("type"); 34 | List entries = session.getLogManager().getLog(type); 35 | return createResponse(entries); 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /third_party/ios_driver/org/uiautomation/ios/command/LogTypesHandler.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2012-2013 eBay Software Foundation and ios-driver committers 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except 5 | * in compliance with the License. You may obtain a copy of the License at 6 | * 7 | * http://www.apache.org/licenses/LICENSE-2.0 8 | * 9 | * Unless required by applicable law or agreed to in writing, software distributed under the License 10 | * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express 11 | * or implied. See the License for the specific language governing permissions and limitations under 12 | * the License. 13 | */ 14 | package org.uiautomation.ios.command; 15 | 16 | import org.openqa.selenium.remote.Response; 17 | import org.uiautomation.ios.IOSServerManager; 18 | import org.uiautomation.ios.ServerSideSession; 19 | import org.uiautomation.ios.servlet.WebDriverLikeRequest; 20 | import java.util.Set; 21 | 22 | public class LogTypesHandler extends CommandHandler{ 23 | public LogTypesHandler(IOSServerManager driver, WebDriverLikeRequest request) { 24 | super(driver, request); 25 | } 26 | 27 | @Override 28 | public Response handle() throws Exception { 29 | ServerSideSession session = getSession(); 30 | Set types = session.getLogManager().getTypes(); 31 | return createResponse(types); 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /third_party/ios_driver/org/uiautomation/ios/command/MoveToHandler.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2012-2013 eBay Software Foundation and ios-driver committers 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except 5 | * in compliance with the License. You may obtain a copy of the License at 6 | * 7 | * http://www.apache.org/licenses/LICENSE-2.0 8 | * 9 | * Unless required by applicable law or agreed to in writing, software distributed under the License 10 | * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express 11 | * or implied. See the License for the specific language governing permissions and limitations under 12 | * the License. 13 | */ 14 | package org.uiautomation.ios.command; 15 | 16 | import org.json.JSONObject; 17 | import org.openqa.selenium.remote.Response; 18 | import org.uiautomation.ios.IOSServerManager; 19 | import org.uiautomation.ios.servlet.WebDriverLikeRequest; 20 | import org.uiautomation.ios.wkrdp.model.RemoteWebElement; 21 | 22 | /** Handles the WebDriver /moveto command. */ 23 | public class MoveToHandler extends CommandHandler { 24 | public MoveToHandler(IOSServerManager driver, WebDriverLikeRequest request) { 25 | super(driver, request); 26 | } 27 | 28 | @Override 29 | public Response handle() throws Exception { 30 | String reference = getRequest().getPayload().getString("element"); 31 | RemoteWebElement element = getWebDriver().createElement(reference); 32 | element.moveTo(); 33 | 34 | Response resp = new Response(); 35 | resp.setSessionId(getSession().getSessionId()); 36 | resp.setStatus(0); 37 | resp.setValue(new JSONObject()); 38 | return resp; 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /third_party/ios_driver/org/uiautomation/ios/command/NewSessionHandler.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2012-2013 eBay Software Foundation and ios-driver committers 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except 5 | * in compliance with the License. You may obtain a copy of the License at 6 | * 7 | * http://www.apache.org/licenses/LICENSE-2.0 8 | * 9 | * Unless required by applicable law or agreed to in writing, software distributed under the License 10 | * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express 11 | * or implied. See the License for the specific language governing permissions and limitations under 12 | * the License. 13 | */ 14 | package org.uiautomation.ios.command; 15 | 16 | import com.google.iosdevicecontrol.util.FluentLogger; 17 | import com.google.devtoolsdriver.util.JavaxJson; 18 | import javax.json.JsonObject; 19 | import org.openqa.selenium.SessionNotCreatedException; 20 | import org.openqa.selenium.WebDriverException; 21 | import org.openqa.selenium.remote.DesiredCapabilities; 22 | import org.openqa.selenium.remote.Response; 23 | import org.uiautomation.ios.IOSServerManager; 24 | import org.uiautomation.ios.ServerSideSession; 25 | import org.uiautomation.ios.servlet.WebDriverLikeRequest; 26 | 27 | /** Handles new session requests. */ 28 | public final class NewSessionHandler extends CommandHandler { 29 | private static final FluentLogger logger = FluentLogger.forEnclosingClass(); 30 | 31 | public NewSessionHandler(IOSServerManager driver, WebDriverLikeRequest request) { 32 | super(driver, request); 33 | } 34 | 35 | @Override 36 | public Response handle() throws Exception { 37 | ServerSideSession session = null; 38 | try { 39 | JsonObject capsJson = getRequest().getPayload().getJsonObject("desiredCapabilities"); 40 | session = safeStart(new DesiredCapabilities(JavaxJson.toJavaMap(capsJson))); 41 | if (session == null) { 42 | throw new SessionNotCreatedException("Failed to start session."); 43 | } 44 | 45 | Response r = new Response(); 46 | r.setSessionId(session.getSessionId()); 47 | r.setValue(session.getWebDriver().capabilities()); 48 | r.setStatus(0); 49 | return r; 50 | } catch (Exception e) { 51 | logger.atSevere().withCause(e).log(); 52 | if (session != null) { 53 | session.stop(); 54 | } 55 | if (e instanceof WebDriverException) { 56 | throw e; 57 | } else { 58 | throw new SessionNotCreatedException(e.getMessage(), e); 59 | } 60 | } 61 | } 62 | 63 | private ServerSideSession safeStart(DesiredCapabilities cap) { 64 | ServerSideSession session = null; 65 | try { 66 | // init session 67 | session = getServer().createSession(cap); 68 | if (session == null) { 69 | throw new SessionNotCreatedException( 70 | "The server is currently shutting down and doesn't accept new tests."); 71 | } 72 | 73 | // start session 74 | session.start(); 75 | return session; 76 | } catch (Exception e) { 77 | // TODO(user): Clean this up to meet logging best practices (should not log and throw). 78 | logger.atSevere().withCause(e).log("Error starting the session"); 79 | if (session != null) { 80 | session.stop(); 81 | } 82 | throw new SessionNotCreatedException(e.getMessage(), e); 83 | } 84 | } 85 | } 86 | -------------------------------------------------------------------------------- /third_party/ios_driver/org/uiautomation/ios/command/QuitSessionHandler.java: -------------------------------------------------------------------------------- 1 | // Copyright 2017 Google Inc. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | package org.uiautomation.ios.command; 16 | 17 | import org.json.JSONObject; 18 | import org.openqa.selenium.remote.Response; 19 | import org.uiautomation.ios.IOSServerManager; 20 | import org.uiautomation.ios.servlet.WebDriverLikeRequest; 21 | 22 | public class QuitSessionHandler extends CommandHandler{ 23 | public QuitSessionHandler(IOSServerManager driver, WebDriverLikeRequest request) { 24 | super(driver, request); 25 | } 26 | 27 | @Override 28 | public Response handle() throws Exception { 29 | getSession().stop(); 30 | return createResponse(new JSONObject()); 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /third_party/ios_driver/org/uiautomation/ios/command/RefreshHandler.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2012-2013 eBay Software Foundation and ios-driver committers 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except 5 | * in compliance with the License. You may obtain a copy of the License at 6 | * 7 | * http://www.apache.org/licenses/LICENSE-2.0 8 | * 9 | * Unless required by applicable law or agreed to in writing, software distributed under the License 10 | * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express 11 | * or implied. See the License for the specific language governing permissions and limitations under 12 | * the License. 13 | */ 14 | package org.uiautomation.ios.command; 15 | 16 | import org.json.JSONObject; 17 | import org.openqa.selenium.remote.Response; 18 | import org.uiautomation.ios.IOSServerManager; 19 | import org.uiautomation.ios.servlet.WebDriverLikeRequest; 20 | 21 | public class RefreshHandler extends CommandHandler { 22 | public RefreshHandler(IOSServerManager driver, WebDriverLikeRequest request) { 23 | super(driver, request); 24 | } 25 | 26 | @Override 27 | public Response handle() throws Exception { 28 | getWebDriver().getContext().newContext(); 29 | getWebDriver().refresh(); 30 | // needed to add this waitForLoadEvent() as waitForPageToLoad() is empty currently 31 | getWebDriver().getContext().waitForLoadEvent(); 32 | getWebDriver().waitForPageToLoad(); 33 | Response res = new Response(); 34 | res.setSessionId(getSession().getSessionId()); 35 | res.setStatus(0); 36 | res.setValue(new JSONObject()); 37 | return res; 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /third_party/ios_driver/org/uiautomation/ios/command/ServerStatusHandler.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2012-2013 eBay Software Foundation and ios-driver committers 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except 5 | * in compliance with the License. You may obtain a copy of the License at 6 | * 7 | * http://www.apache.org/licenses/LICENSE-2.0 8 | * 9 | * Unless required by applicable law or agreed to in writing, software distributed under the License 10 | * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express 11 | * or implied. See the License for the specific language governing permissions and limitations under 12 | * the License. 13 | */ 14 | 15 | package org.uiautomation.ios.command; 16 | 17 | import java.util.Set; 18 | import org.json.JSONException; 19 | import org.json.JSONObject; 20 | import org.openqa.selenium.WebDriverException; 21 | import org.openqa.selenium.remote.Response; 22 | import org.uiautomation.ios.IOSServerManager; 23 | import org.uiautomation.ios.ServerSideSession; 24 | import org.uiautomation.ios.servlet.WebDriverLikeRequest; 25 | 26 | public class ServerStatusHandler extends CommandHandler { 27 | public ServerStatusHandler(IOSServerManager driver, WebDriverLikeRequest request) { 28 | super(driver, request); 29 | } 30 | 31 | @Override 32 | public Response handle() throws Exception { 33 | JSONObject res = generateStatus(); 34 | 35 | Set sessions = getServer().getSessions(); 36 | Response resp = new Response(); 37 | 38 | resp.setStatus(0); 39 | resp.setValue(res); 40 | if (sessions.size() == 0) { 41 | resp.setSessionId(null); 42 | } else if (sessions.size() == 1) { 43 | resp.setSessionId(sessions.iterator().next().getSessionId()); 44 | } else { 45 | throw new WebDriverException("NI multi sessions per server."); 46 | } 47 | return resp; 48 | } 49 | 50 | public static JSONObject generateStatus() throws JSONException { 51 | JSONObject res = new JSONObject(); 52 | res.put("state", "success"); 53 | res.put( 54 | "os", 55 | new JSONObject() 56 | .put("name", System.getProperty("os.name")) 57 | .put("arch", System.getProperty("os.arch")) 58 | .put("version", System.getProperty("os.version"))); 59 | 60 | res.put("java", new JSONObject().put("version", System.getProperty("java.version"))); 61 | return res; 62 | } 63 | } 64 | -------------------------------------------------------------------------------- /third_party/ios_driver/org/uiautomation/ios/command/SetConfigurationHandler.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2012-2013 eBay Software Foundation and ios-driver committers 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except 5 | * in compliance with the License. You may obtain a copy of the License at 6 | * 7 | * http://www.apache.org/licenses/LICENSE-2.0 8 | * 9 | * Unless required by applicable law or agreed to in writing, software distributed under the License 10 | * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express 11 | * or implied. See the License for the specific language governing permissions and limitations under 12 | * the License. 13 | */ 14 | package org.uiautomation.ios.command; 15 | 16 | import com.google.devtoolsdriver.util.JavaxJson; 17 | import java.util.Iterator; 18 | import org.json.JSONObject; 19 | import org.openqa.selenium.remote.Response; 20 | import org.uiautomation.ios.IOSServerManager; 21 | import org.uiautomation.ios.servlet.WebDriverLikeCommand; 22 | import org.uiautomation.ios.servlet.WebDriverLikeRequest; 23 | 24 | public class SetConfigurationHandler extends CommandHandler { 25 | 26 | public SetConfigurationHandler(IOSServerManager driver, WebDriverLikeRequest request) { 27 | super(driver, request); 28 | } 29 | 30 | @Override 31 | public Response handle() throws Exception { 32 | WebDriverLikeCommand command = 33 | WebDriverLikeCommand.valueOf(getRequest().getVariableValue(":command")); 34 | JSONObject payload = JavaxJson.toOrgJson(getRequest().getPayload()); 35 | 36 | @SuppressWarnings("unchecked") 37 | Iterator iter = payload.keys(); 38 | while (iter.hasNext()) { 39 | String key = iter.next(); 40 | Object value = payload.opt(key); 41 | getSession().configure(command).set(key, value); 42 | } 43 | 44 | Response resp = new Response(); 45 | resp.setSessionId(getSession().getSessionId()); 46 | resp.setStatus(0); 47 | resp.setValue(new JSONObject()); 48 | return resp; 49 | 50 | } 51 | } 52 | -------------------------------------------------------------------------------- /third_party/ios_driver/org/uiautomation/ios/command/SetCurrentContextHandler.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2012-2013 eBay Software Foundation and ios-driver committers 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except 5 | * in compliance with the License. You may obtain a copy of the License at 6 | * 7 | * http://www.apache.org/licenses/LICENSE-2.0 8 | * 9 | * Unless required by applicable law or agreed to in writing, software distributed under the License 10 | * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express 11 | * or implied. See the License for the specific language governing permissions and limitations under 12 | * the License. 13 | */ 14 | 15 | package org.uiautomation.ios.command; 16 | 17 | import com.google.devtoolsdriver.webdriver.PageId; 18 | import org.json.JSONObject; 19 | import org.openqa.selenium.remote.Response; 20 | import org.uiautomation.ios.IOSServerManager; 21 | import org.uiautomation.ios.servlet.WebDriverLikeRequest; 22 | 23 | /** Handler to set the current context (window handle). */ 24 | public class SetCurrentContextHandler extends CommandHandler { 25 | public SetCurrentContextHandler(IOSServerManager driver, WebDriverLikeRequest request) { 26 | super(driver, request); 27 | } 28 | 29 | @Override 30 | public Response handle() throws Exception { 31 | String context = getRequest().getPayload().getString("name"); 32 | getWebDriver().switchTo(PageId.of(context)); 33 | 34 | Response resp = new Response(); 35 | resp.setSessionId(getSession().getSessionId()); 36 | resp.setStatus(0); 37 | resp.setValue(new JSONObject()); 38 | return resp; 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /third_party/ios_driver/org/uiautomation/ios/command/SetFrameHandler.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2012-2013 eBay Software Foundation and ios-driver committers 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except 5 | * in compliance with the License. You may obtain a copy of the License at 6 | * 7 | * http://www.apache.org/licenses/LICENSE-2.0 8 | * 9 | * Unless required by applicable law or agreed to in writing, software distributed under the License 10 | * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express 11 | * or implied. See the License for the specific language governing permissions and limitations under 12 | * the License. 13 | */ 14 | package org.uiautomation.ios.command; 15 | 16 | import java.util.List; 17 | import javax.json.JsonNumber; 18 | import javax.json.JsonObject; 19 | import javax.json.JsonString; 20 | import javax.json.JsonValue; 21 | import org.json.JSONObject; 22 | import org.openqa.selenium.NoSuchElementException; 23 | import org.openqa.selenium.NoSuchFrameException; 24 | import org.openqa.selenium.UnsupportedCommandException; 25 | import org.openqa.selenium.remote.Response; 26 | import org.uiautomation.ios.IOSServerManager; 27 | import org.uiautomation.ios.servlet.WebDriverLikeRequest; 28 | import org.uiautomation.ios.wkrdp.model.RemoteWebElement; 29 | 30 | public class SetFrameHandler extends CommandHandler { 31 | public SetFrameHandler(IOSServerManager driver, WebDriverLikeRequest request) { 32 | super(driver, request); 33 | } 34 | 35 | // NoSuchWindow - If the currently selected window has been closed. 36 | // NoSuchFrame - If the frame specified by id cannot be found. 37 | @Override 38 | public Response handle() throws Exception { 39 | JsonValue p = getRequest().getPayload().get("id"); 40 | 41 | if (JsonValue.NULL.equals(p)) { 42 | getWebDriver().getContext().setCurrentFrame(null, null, null); 43 | } else { 44 | RemoteWebElement iframe; 45 | switch (p.getValueType()) { 46 | case NUMBER: 47 | iframe = getIframe(((JsonNumber) p).intValue()); 48 | break; 49 | case OBJECT: 50 | String id = ((JsonObject) p).getString("ELEMENT"); 51 | iframe = getWebDriver().createElement(id); 52 | break; 53 | case STRING: 54 | iframe = getIframe(((JsonString) p).getString()); 55 | break; 56 | default: 57 | throw new UnsupportedCommandException("cannot select frame by " + p.getClass()); 58 | } 59 | RemoteWebElement document = iframe.getContentDocument(); 60 | RemoteWebElement window = iframe.getContentWindow(); 61 | getWebDriver().getContext().setCurrentFrame(iframe, document, window); 62 | } 63 | 64 | Response res = new Response(); 65 | res.setSessionId(getSession().getSessionId()); 66 | res.setStatus(0); 67 | res.setValue(new JSONObject()); 68 | return res; 69 | } 70 | 71 | private RemoteWebElement getIframe(Integer index) throws Exception { 72 | List iframes = getWebDriver().findElementsByCssSelector( 73 | "iframe,frame"); 74 | try { 75 | return iframes.get(index); 76 | } catch (IndexOutOfBoundsException i) { 77 | throw new NoSuchFrameException( 78 | "detected " + iframes.size() + " frames. Cannot get index = " + index); 79 | } 80 | } 81 | 82 | private RemoteWebElement getIframe(String id) throws Exception { 83 | RemoteWebElement currentDocument = getWebDriver().getDocument(); 84 | 85 | String 86 | selector = 87 | "iframe[name='" + id + "'],iframe[id='" + id + "'],frame[name='" + id + "'],frame[id='" + id 88 | + "']"; 89 | try { 90 | RemoteWebElement frame = currentDocument.findElementByCSSSelector(selector); 91 | return frame; 92 | } catch (NoSuchElementException e) { 93 | throw new NoSuchFrameException(e.getMessage(), e); 94 | } 95 | } 96 | } 97 | -------------------------------------------------------------------------------- /third_party/ios_driver/org/uiautomation/ios/command/SetImplicitWaitTimeoutHandler.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2012-2013 eBay Software Foundation and ios-driver committers 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except 5 | * in compliance with the License. You may obtain a copy of the License at 6 | * 7 | * http://www.apache.org/licenses/LICENSE-2.0 8 | * 9 | * Unless required by applicable law or agreed to in writing, software distributed under the License 10 | * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express 11 | * or implied. See the License for the specific language governing permissions and limitations under 12 | * the License. 13 | */ 14 | 15 | package org.uiautomation.ios.command; 16 | 17 | import java.util.ArrayList; 18 | import java.util.List; 19 | import org.json.JSONObject; 20 | import org.openqa.selenium.remote.Response; 21 | import org.uiautomation.ios.IOSServerManager; 22 | import org.uiautomation.ios.servlet.WebDriverLikeCommand; 23 | import org.uiautomation.ios.servlet.WebDriverLikeRequest; 24 | 25 | public class SetImplicitWaitTimeoutHandler extends CommandHandler { 26 | public static int timeout = 0; 27 | 28 | private static final List impacted = new ArrayList<>(); 29 | 30 | public SetImplicitWaitTimeoutHandler(IOSServerManager driver, WebDriverLikeRequest request) { 31 | super(driver, request); 32 | impacted.add(WebDriverLikeCommand.ELEMENT); 33 | impacted.add(WebDriverLikeCommand.ELEMENT_ROOT); 34 | impacted.add(WebDriverLikeCommand.ELEMENTS); 35 | impacted.add(WebDriverLikeCommand.ELEMENTS_ROOT); 36 | } 37 | 38 | @Override 39 | public Response handle() throws Exception { 40 | timeout = getRequest().getPayload().getInt("ms"); 41 | for (WebDriverLikeCommand command : impacted) { 42 | getSession().configure(command).set("implicit_wait", timeout); 43 | } 44 | 45 | Response res = new Response(); 46 | res.setSessionId(getSession().getSessionId()); 47 | res.setStatus(0); 48 | res.setValue(new JSONObject()); 49 | return res; 50 | } 51 | } 52 | -------------------------------------------------------------------------------- /third_party/ios_driver/org/uiautomation/ios/command/SetScriptTimeoutHandler.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2012-2013 eBay Software Foundation and ios-driver committers 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except 5 | * in compliance with the License. You may obtain a copy of the License at 6 | * 7 | * http://www.apache.org/licenses/LICENSE-2.0 8 | * 9 | * Unless required by applicable law or agreed to in writing, software distributed under the License 10 | * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express 11 | * or implied. See the License for the specific language governing permissions and limitations under 12 | * the License. 13 | */ 14 | 15 | package org.uiautomation.ios.command; 16 | 17 | import java.util.ArrayList; 18 | import java.util.List; 19 | import org.json.JSONObject; 20 | import org.openqa.selenium.remote.Response; 21 | import org.uiautomation.ios.IOSServerManager; 22 | import org.uiautomation.ios.servlet.WebDriverLikeCommand; 23 | import org.uiautomation.ios.servlet.WebDriverLikeRequest; 24 | 25 | public class SetScriptTimeoutHandler extends CommandHandler { 26 | public static int timeout = 0; 27 | 28 | private static final List impacted = new ArrayList<>(); 29 | 30 | public SetScriptTimeoutHandler(IOSServerManager driver, WebDriverLikeRequest request) { 31 | super(driver, request); 32 | impacted.add(WebDriverLikeCommand.ELEMENT); 33 | impacted.add(WebDriverLikeCommand.ELEMENT_ROOT); 34 | impacted.add(WebDriverLikeCommand.ELEMENTS); 35 | impacted.add(WebDriverLikeCommand.ELEMENTS_ROOT); 36 | } 37 | 38 | @Override 39 | public Response handle() throws Exception { 40 | timeout = getRequest().getPayload().getInt("ms"); 41 | for (WebDriverLikeCommand command : impacted) { 42 | getSession().configure(command).set("script", timeout); 43 | } 44 | 45 | Response res = new Response(); 46 | res.setSessionId(getSession().getSessionId()); 47 | res.setStatus(0); 48 | res.setValue(new JSONObject()); 49 | return res; 50 | } 51 | } 52 | -------------------------------------------------------------------------------- /third_party/ios_driver/org/uiautomation/ios/command/SetTimeoutHandler.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2012-2013 eBay Software Foundation and ios-driver committers 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except 5 | * in compliance with the License. You may obtain a copy of the License at 6 | * 7 | * http://www.apache.org/licenses/LICENSE-2.0 8 | * 9 | * Unless required by applicable law or agreed to in writing, software distributed under the License 10 | * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express 11 | * or implied. See the License for the specific language governing permissions and limitations under 12 | * the License. 13 | */ 14 | package org.uiautomation.ios.command; 15 | 16 | import javax.json.JsonObject; 17 | import org.json.JSONObject; 18 | import org.openqa.selenium.UnsupportedCommandException; 19 | import org.openqa.selenium.remote.Response; 20 | import org.uiautomation.ios.IOSServerManager; 21 | import org.uiautomation.ios.servlet.WebDriverLikeCommand; 22 | import org.uiautomation.ios.servlet.WebDriverLikeRequest; 23 | 24 | public class SetTimeoutHandler extends CommandHandler { 25 | public SetTimeoutHandler(IOSServerManager driver, WebDriverLikeRequest request) { 26 | super(driver, request); 27 | } 28 | 29 | /** 30 | * type - {string} The type of operation to set the timeout for. Valid values are: "script" for 31 | * script timeouts, "implicit" for modifying the implicit wait timeout and "page load" for setting 32 | * a page load timeout. 33 | */ 34 | @Override 35 | public Response handle() throws Exception { 36 | JsonObject payload = getRequest().getPayload(); 37 | String type = payload.getString("type", ""); 38 | final WebDriverLikeCommand command; 39 | if ("page load".equals(type)) { 40 | command = WebDriverLikeCommand.URL; 41 | } else if ("script".equals(type)) { 42 | command = WebDriverLikeCommand.EXECUTE_SCRIPT; 43 | } else { 44 | throw new UnsupportedCommandException("set timeout for " + payload); 45 | } 46 | 47 | long timeout = payload.getJsonNumber("ms").longValue(); 48 | getSession().configure(command).set(type, timeout); 49 | 50 | Response res = new Response(); 51 | res.setSessionId(getSession().getSessionId()); 52 | res.setStatus(0); 53 | res.setValue(new JSONObject()); 54 | return res; 55 | } 56 | } 57 | -------------------------------------------------------------------------------- /third_party/ios_driver/org/uiautomation/ios/command/SetValueHandler.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2012-2013 eBay Software Foundation and ios-driver committers 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except 5 | * in compliance with the License. You may obtain a copy of the License at 6 | * 7 | * http://www.apache.org/licenses/LICENSE-2.0 8 | * 9 | * Unless required by applicable law or agreed to in writing, software distributed under the License 10 | * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express 11 | * or implied. See the License for the specific language governing permissions and limitations under 12 | * the License. 13 | */ 14 | package org.uiautomation.ios.command; 15 | 16 | import com.google.devtoolsdriver.util.JavaxJson; 17 | import javax.json.JsonArray; 18 | import javax.json.JsonValue; 19 | import org.json.JSONObject; 20 | import org.openqa.selenium.remote.Response; 21 | import org.uiautomation.ios.IOSServerManager; 22 | import org.uiautomation.ios.servlet.WebDriverLikeRequest; 23 | import org.uiautomation.ios.wkrdp.model.RemoteWebElement; 24 | 25 | public class SetValueHandler extends CommandHandler { 26 | public SetValueHandler(IOSServerManager driver, WebDriverLikeRequest request) { 27 | super(driver, request); 28 | } 29 | 30 | @Override 31 | public Response handle() throws Exception { 32 | String ref = getRequest().getVariableValue(":reference"); 33 | RemoteWebElement element = getWebDriver().createElement(ref); 34 | JsonArray array = getRequest().getPayload().getJsonArray("value"); 35 | 36 | String value = ""; 37 | for (JsonValue jsonValue : array) { 38 | value += JavaxJson.toJavaObject(jsonValue); 39 | } 40 | element.setValueAtoms(value); 41 | 42 | Response res = new Response(); 43 | res.setSessionId(getSession().getSessionId()); 44 | res.setStatus(0); 45 | res.setValue(new JSONObject()); 46 | return res; 47 | } 48 | } 49 | -------------------------------------------------------------------------------- /third_party/ios_driver/org/uiautomation/ios/command/SubmitHandler.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2012-2013 eBay Software Foundation and ios-driver committers 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except 5 | * in compliance with the License. You may obtain a copy of the License at 6 | * 7 | * http://www.apache.org/licenses/LICENSE-2.0 8 | * 9 | * Unless required by applicable law or agreed to in writing, software distributed under the License 10 | * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express 11 | * or implied. See the License for the specific language governing permissions and limitations under 12 | * the License. 13 | */ 14 | package org.uiautomation.ios.command; 15 | 16 | import org.json.JSONObject; 17 | import org.openqa.selenium.remote.Response; 18 | import org.uiautomation.ios.IOSServerManager; 19 | import org.uiautomation.ios.servlet.WebDriverLikeRequest; 20 | import org.uiautomation.ios.wkrdp.model.RemoteWebElement; 21 | 22 | public class SubmitHandler extends CommandHandler { 23 | public SubmitHandler(IOSServerManager driver, WebDriverLikeRequest request) { 24 | super(driver, request); 25 | } 26 | 27 | @Override 28 | public Response handle() throws Exception { 29 | String ref = getRequest().getVariableValue(":reference"); 30 | RemoteWebElement element = getWebDriver().createElement(ref); 31 | element.submit(); 32 | Response res = new Response(); 33 | res.setSessionId(getSession().getSessionId()); 34 | res.setStatus(0); 35 | res.setValue(new JSONObject()); 36 | return res; 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /third_party/ios_driver/org/uiautomation/ios/command/TakeScreenshotHandler.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2012-2013 eBay Software Foundation and ios-driver committers 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except 5 | * in compliance with the License. You may obtain a copy of the License at 6 | * 7 | * http://www.apache.org/licenses/LICENSE-2.0 8 | * 9 | * Unless required by applicable law or agreed to in writing, software distributed under the License 10 | * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express 11 | * or implied. See the License for the specific language governing permissions and limitations under 12 | * the License. 13 | */ 14 | 15 | package org.uiautomation.ios.command; 16 | 17 | import com.google.common.io.BaseEncoding; 18 | import org.openqa.selenium.remote.Response; 19 | import org.uiautomation.ios.IOSServerManager; 20 | import org.uiautomation.ios.servlet.WebDriverLikeRequest; 21 | 22 | public class TakeScreenshotHandler extends CommandHandler { 23 | public TakeScreenshotHandler(IOSServerManager driver, WebDriverLikeRequest request) { 24 | super(driver, request); 25 | } 26 | 27 | @Override 28 | public Response handle() throws Exception { 29 | return createResponse(BaseEncoding.base64().encode(getWebDriver().takeScreenshot())); 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /third_party/ios_driver/org/uiautomation/ios/command/ToCSSSelectorConverter.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2012-2013 eBay Software Foundation and ios-driver committers 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except 5 | * in compliance with the License. You may obtain a copy of the License at 6 | * 7 | * http://www.apache.org/licenses/LICENSE-2.0 8 | * 9 | * Unless required by applicable law or agreed to in writing, software distributed under the License 10 | * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express 11 | * or implied. See the License for the specific language governing permissions and limitations under 12 | * the License. 13 | */ 14 | package org.uiautomation.ios.command; 15 | 16 | import org.openqa.selenium.InvalidSelectorException; 17 | import org.openqa.selenium.WebDriverException; 18 | 19 | public class ToCSSSelectorConverter { 20 | 21 | public static String convertToCSSSelector(String type, String value) { 22 | if ("css selector".equals(type)) { 23 | return value; 24 | } 25 | if ("id".equals(type)) { 26 | // return "#" + value; // doesn't work for id starting with an int. 27 | return "[id='" + value + "']"; 28 | } 29 | if ("tag name".equals(type)) { 30 | return value; 31 | } 32 | if ("class name".equals(type)) { 33 | // detect composite class name 34 | if (isCompoundName(value)) { 35 | throw new InvalidSelectorException("Compound class names aren't allowed"); 36 | } 37 | return "." + value; 38 | } 39 | if ("class name".equals(type)) { 40 | return "." + value; 41 | } 42 | if ("name".equals(type)) { 43 | return "[name='" + value + "']"; 44 | } 45 | throw new WebDriverException("NI , selector type " + type); 46 | } 47 | 48 | private static boolean isCompoundName(String value) { 49 | return value != null && value.split(" ").length != 1; 50 | } 51 | } 52 | -------------------------------------------------------------------------------- /third_party/ios_driver/org/uiautomation/ios/command/configuration/CommandConfigurationStore.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2012-2013 eBay Software Foundation and ios-driver committers 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except 5 | * in compliance with the License. You may obtain a copy of the License at 6 | * 7 | * http://www.apache.org/licenses/LICENSE-2.0 8 | * 9 | * Unless required by applicable law or agreed to in writing, software distributed under the License 10 | * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express 11 | * or implied. See the License for the specific language governing permissions and limitations under 12 | * the License. 13 | */ 14 | package org.uiautomation.ios.command.configuration; 15 | 16 | import org.json.JSONException; 17 | import org.json.JSONObject; 18 | import org.uiautomation.ios.servlet.CommandConfiguration; 19 | import java.util.HashMap; 20 | import java.util.Iterator; 21 | import java.util.Map; 22 | import java.util.logging.Level; 23 | import java.util.logging.Logger; 24 | 25 | public class CommandConfigurationStore implements CommandConfiguration { 26 | 27 | private final JSONObject config = new JSONObject(); 28 | private static final Logger log = Logger.getLogger(CommandConfiguration.class.getName()); 29 | 30 | @Override 31 | public void set(String key, Object value) { 32 | try { 33 | config.put(key, value); 34 | } catch (JSONException e) { 35 | log.log(Level.SEVERE,"format error",e); 36 | } 37 | 38 | } 39 | 40 | @Override 41 | public Object get(String key) { 42 | Object res = config.opt(key); 43 | return res; 44 | } 45 | 46 | @Override 47 | public Map getAll() { 48 | Map res = new HashMap(); 49 | Iterator iter = config.keys(); 50 | while (iter.hasNext()) { 51 | String key = iter.next(); 52 | Object value = config.opt(key); 53 | res.put(key, value); 54 | } 55 | return res; 56 | } 57 | 58 | @Override 59 | public Object opt(String key, Object defaultValue) { 60 | Object res = get(key); 61 | if (res == null) { 62 | res = defaultValue; 63 | } 64 | return res; 65 | } 66 | 67 | } 68 | -------------------------------------------------------------------------------- /third_party/ios_driver/org/uiautomation/ios/command/configuration/DriverConfigurationStore.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2012-2013 eBay Software Foundation and ios-driver committers 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except 5 | * in compliance with the License. You may obtain a copy of the License at 6 | * 7 | * http://www.apache.org/licenses/LICENSE-2.0 8 | * 9 | * Unless required by applicable law or agreed to in writing, software distributed under the License 10 | * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express 11 | * or implied. See the License for the specific language governing permissions and limitations under 12 | * the License. 13 | */ 14 | package org.uiautomation.ios.command.configuration; 15 | 16 | import java.util.HashMap; 17 | import java.util.Map; 18 | import org.uiautomation.ios.servlet.CommandConfiguration; 19 | import org.uiautomation.ios.servlet.DriverConfiguration; 20 | import org.uiautomation.ios.servlet.WebDriverLikeCommand; 21 | 22 | public class DriverConfigurationStore implements DriverConfiguration { 23 | private final Map configurations = new HashMap<>(); 24 | 25 | @Override 26 | public CommandConfiguration configure(WebDriverLikeCommand command) { 27 | CommandConfiguration config = configurations.get(command); 28 | if (config == null) { 29 | config = new CommandConfigurationStore(); 30 | configurations.put(command, config); 31 | } 32 | return config; 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /third_party/ios_driver/org/uiautomation/ios/logging/IOSLogManager.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2013 ios-driver committers. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except 5 | * in compliance with the License. You may obtain a copy of the License at 6 | * 7 | * http://www.apache.org/licenses/LICENSE-2.0 8 | * 9 | * Unless required by applicable law or agreed to in writing, software distributed under the License 10 | * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express 11 | * or implied. See the License for the specific language governing permissions and limitations under 12 | * the License. 13 | */ 14 | package org.uiautomation.ios.logging; 15 | 16 | import com.google.common.base.Optional; 17 | 18 | import org.openqa.selenium.logging.LogEntry; 19 | import org.openqa.selenium.logging.LogType; 20 | import org.openqa.selenium.logging.LoggingPreferences; 21 | 22 | import java.util.Collections; 23 | import java.util.HashMap; 24 | import java.util.List; 25 | import java.util.Map; 26 | import java.util.Set; 27 | import java.util.logging.Level; 28 | 29 | /* 30 | * Maps and stores WebDriver logs to their log type and registers listeners. 31 | */ 32 | public class IOSLogManager { 33 | private final Map logs = new HashMap<>(); 34 | 35 | public IOSLogManager(LoggingPreferences prefs) { 36 | Level perfLevel = prefs.getLevel(LogType.PERFORMANCE); 37 | if (perfLevel.intValue() < Level.OFF.intValue()) { 38 | logs.put(LogType.PERFORMANCE, new WebDriverLog(LogType.PERFORMANCE, perfLevel)); 39 | } 40 | } 41 | 42 | public Optional performanceListener() { 43 | Log log = logs.get(LogType.PERFORMANCE); 44 | return log == null 45 | ? Optional.absent() 46 | : Optional.of(new PerformanceListener(log)); 47 | } 48 | 49 | public Set getTypes() { 50 | return logs.keySet(); 51 | } 52 | 53 | public List getLog(String type) { 54 | WebDriverLog log = (WebDriverLog) logs.get(type); 55 | return (log == null ? (Collections.emptyList()) : log.getAndClearEntries()); 56 | } 57 | } 58 | -------------------------------------------------------------------------------- /third_party/ios_driver/org/uiautomation/ios/logging/Log.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2013 ios-driver committers. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except 5 | * in compliance with the License. You may obtain a copy of the License at 6 | * 7 | * http://www.apache.org/licenses/LICENSE-2.0 8 | * 9 | * Unless required by applicable law or agreed to in writing, software distributed under the License 10 | * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express 11 | * or implied. See the License for the specific language governing permissions and limitations under 12 | * the License. 13 | */ 14 | package org.uiautomation.ios.logging; 15 | 16 | import java.util.logging.Level; 17 | 18 | /* 19 | * Log Interface 20 | */ 21 | public interface Log { 22 | 23 | public void addEntry(Level level, String message); 24 | 25 | public void addEntryTimestamped(long timestamp, Level level, String message); 26 | 27 | } 28 | -------------------------------------------------------------------------------- /third_party/ios_driver/org/uiautomation/ios/logging/PerformanceListener.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2013 ios-driver committers. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except 5 | * in compliance with the License. You may obtain a copy of the License at 6 | * 7 | * http://www.apache.org/licenses/LICENSE-2.0 8 | * 9 | * Unless required by applicable law or agreed to in writing, software distributed under the License 10 | * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express 11 | * or implied. See the License for the specific language governing permissions and limitations under 12 | * the License. 13 | */ 14 | package org.uiautomation.ios.logging; 15 | 16 | import static com.google.common.base.Preconditions.checkNotNull; 17 | 18 | import com.google.devtoolsdriver.devtools.DevtoolsEvent; 19 | import java.util.function.Consumer; 20 | import java.util.logging.Level; 21 | import javax.json.Json; 22 | import javax.json.JsonObject; 23 | 24 | /** 25 | * A listener class that enables and logs Network and Timeline messages from DevTools. 26 | */ 27 | public class PerformanceListener implements Consumer { 28 | private static final String[] DOMAINS = new String[] {"Network.", "Page.", "Timeline."}; 29 | 30 | private final Log log; 31 | 32 | public PerformanceListener(Log log) { 33 | this.log = checkNotNull(log); 34 | } 35 | 36 | private boolean shouldLog(DevtoolsEvent event) { 37 | for (String domain : DOMAINS) { 38 | if (event.method().startsWith(domain)) { 39 | return true; 40 | } 41 | } 42 | return false; 43 | } 44 | 45 | @Override 46 | public void accept(DevtoolsEvent event) { 47 | if (!shouldLog(event)) { 48 | return; 49 | } 50 | // The remote performance log clients expect the events to be formatted in 51 | // the following specific JSON format. 52 | // See: https://sites.google.com/a/chromium.org/chromedriver/logging/performance-log 53 | JsonObject messageJson = 54 | Json.createObjectBuilder() 55 | .add("method", event.method()) 56 | .add("params", event.params()) 57 | .build(); 58 | JsonObject eventJson = 59 | Json.createObjectBuilder() 60 | .add("message", messageJson.toString()) 61 | .build(); 62 | log.addEntry(Level.INFO, eventJson.toString()); 63 | } 64 | } 65 | -------------------------------------------------------------------------------- /third_party/ios_driver/org/uiautomation/ios/logging/WebDriverLog.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2013 ios-driver committers. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except 5 | * in compliance with the License. You may obtain a copy of the License at 6 | * 7 | * http://www.apache.org/licenses/LICENSE-2.0 8 | * 9 | * Unless required by applicable law or agreed to in writing, software distributed under the License 10 | * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express 11 | * or implied. See the License for the specific language governing permissions and limitations under 12 | * the License. 13 | */ 14 | package org.uiautomation.ios.logging; 15 | 16 | import org.openqa.selenium.logging.LogEntry; 17 | 18 | import java.util.ArrayList; 19 | import java.util.List; 20 | import java.util.logging.Level; 21 | 22 | /* 23 | * Stores an Array of LogEntry from Webdriver Logging API. LogEntries are of a specific 24 | * type and have a minimum level. 25 | */ 26 | public class WebDriverLog implements Log { 27 | 28 | private final List logEntries = new ArrayList(); 29 | 30 | private final Level minLogLevel; 31 | private final String type; 32 | 33 | public WebDriverLog(String type, Level minLogLevel) { 34 | this.type = type; 35 | this.minLogLevel = minLogLevel; 36 | } 37 | 38 | public String getType() { 39 | return type; 40 | } 41 | 42 | @Override 43 | public void addEntry(Level level, String message) { 44 | addEntryTimestamped(System.currentTimeMillis(), level, message); 45 | } 46 | 47 | @Override 48 | public void addEntryTimestamped(long timestamp, Level level, String message) { 49 | if (level.intValue() >= minLogLevel.intValue()) { 50 | logEntries.add(new LogEntry(level, timestamp, message)); 51 | } 52 | } 53 | 54 | public List getAndClearEntries() { 55 | List ret = new ArrayList(logEntries); 56 | logEntries.clear(); 57 | return ret; 58 | } 59 | 60 | } 61 | -------------------------------------------------------------------------------- /third_party/ios_driver/org/uiautomation/ios/servlet/CommandConfiguration.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2012-2013 eBay Software Foundation and ios-driver committers 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except 5 | * in compliance with the License. You may obtain a copy of the License at 6 | * 7 | * http://www.apache.org/licenses/LICENSE-2.0 8 | * 9 | * Unless required by applicable law or agreed to in writing, software distributed under the License 10 | * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express 11 | * or implied. See the License for the specific language governing permissions and limitations under 12 | * the License. 13 | */ 14 | 15 | package org.uiautomation.ios.servlet; 16 | 17 | import java.util.Map; 18 | 19 | public interface CommandConfiguration { 20 | void set(String key, Object value); 21 | 22 | Object get(String key); 23 | 24 | Map getAll(); 25 | 26 | Object opt(String key, Object defaultValue); 27 | } 28 | -------------------------------------------------------------------------------- /third_party/ios_driver/org/uiautomation/ios/servlet/DriverBasedServlet.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2012-2013 eBay Software Foundation and ios-driver committers 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except 5 | * in compliance with the License. You may obtain a copy of the License at 6 | * 7 | * http://www.apache.org/licenses/LICENSE-2.0 8 | * 9 | * Unless required by applicable law or agreed to in writing, software distributed under the License 10 | * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express 11 | * or implied. See the License for the specific language governing permissions and limitations under 12 | * the License. 13 | */ 14 | package org.uiautomation.ios.servlet; 15 | 16 | import javax.servlet.http.HttpServlet; 17 | import org.uiautomation.ios.IOSServer; 18 | import org.uiautomation.ios.IOSServerManager; 19 | 20 | @SuppressWarnings("serial") 21 | public abstract class DriverBasedServlet extends HttpServlet { 22 | private IOSServerManager driver; 23 | 24 | public synchronized IOSServerManager getDriver() { 25 | if (driver == null) { 26 | driver = (IOSServerManager) getServletContext().getAttribute(IOSServer.DRIVER); 27 | } 28 | return driver; 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /third_party/ios_driver/org/uiautomation/ios/servlet/DriverConfiguration.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2012-2013 eBay Software Foundation and ios-driver committers 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except 5 | * in compliance with the License. You may obtain a copy of the License at 6 | * 7 | * http://www.apache.org/licenses/LICENSE-2.0 8 | * 9 | * Unless required by applicable law or agreed to in writing, software distributed under the License 10 | * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express 11 | * or implied. See the License for the specific language governing permissions and limitations under 12 | * the License. 13 | */ 14 | 15 | package org.uiautomation.ios.servlet; 16 | 17 | public interface DriverConfiguration { 18 | CommandConfiguration configure(WebDriverLikeCommand command); 19 | } 20 | -------------------------------------------------------------------------------- /third_party/ios_driver/org/uiautomation/ios/servlet/WebDriverLikeRequest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2012-2013 eBay Software Foundation and ios-driver committers 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except 5 | * in compliance with the License. You may obtain a copy of the License at 6 | * 7 | * http://www.apache.org/licenses/LICENSE-2.0 8 | * 9 | * Unless required by applicable law or agreed to in writing, software distributed under the License 10 | * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express 11 | * or implied. See the License for the specific language governing permissions and limitations under 12 | * the License. 13 | */ 14 | package org.uiautomation.ios.servlet; 15 | 16 | import static java.nio.charset.StandardCharsets.UTF_8; 17 | 18 | import com.google.common.io.ByteStreams; 19 | import com.google.devtoolsdriver.util.JavaxJson; 20 | import java.io.IOException; 21 | import javax.json.JsonObject; 22 | import javax.servlet.http.HttpServletRequest; 23 | 24 | public class WebDriverLikeRequest { 25 | private final String method; 26 | private final String path; 27 | private final JsonObject payload; 28 | 29 | WebDriverLikeRequest(HttpServletRequest request) throws IOException { 30 | method = request.getMethod(); 31 | path = request.getPathInfo(); 32 | payload = readPayloadFromRequest(request); 33 | } 34 | 35 | private static JsonObject readPayloadFromRequest(HttpServletRequest request) throws IOException { 36 | byte[] payloadBytes = ByteStreams.toByteArray(request.getInputStream()); 37 | return payloadBytes.length == 0 38 | ? JavaxJson.EMPTY_OBJECT 39 | : JavaxJson.parseObject(new String(payloadBytes, UTF_8)); 40 | } 41 | 42 | @Override 43 | public String toString() { 44 | String res = method + ":" + path; 45 | if (!payload.isEmpty()) { 46 | res += "\n\tbody:" + payload; 47 | } 48 | return res; 49 | } 50 | 51 | public JsonObject getPayload() { 52 | return payload; 53 | } 54 | 55 | public WebDriverLikeCommand getGenericCommand() { 56 | return WebDriverLikeCommand.getCommand(method, path); 57 | } 58 | 59 | public String getVariableValue(String variable) { 60 | WebDriverLikeCommand genericCommand = getGenericCommand(); 61 | int i = genericCommand.getIndex(variable); 62 | String[] pieces = path.split("/"); 63 | return pieces[i]; 64 | } 65 | 66 | public boolean hasVariable(String variable) { 67 | WebDriverLikeCommand genericCommand = getGenericCommand(); 68 | boolean ok = genericCommand.path().contains(variable); 69 | return ok; 70 | } 71 | 72 | public String getSession() { 73 | return getVariableValue(":sessionId"); 74 | } 75 | 76 | public boolean hasSession() { 77 | return hasVariable(":sessionId"); 78 | } 79 | } 80 | -------------------------------------------------------------------------------- /third_party/ios_driver/org/uiautomation/ios/wkrdp/events/ChildIframeInserted.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2012-2013 eBay Software Foundation and ios-driver committers 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except 5 | * in compliance with the License. You may obtain a copy of the License at 6 | * 7 | * http://www.apache.org/licenses/LICENSE-2.0 8 | * 9 | * Unless required by applicable law or agreed to in writing, software distributed under the License 10 | * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express 11 | * or implied. See the License for the specific language governing permissions and limitations under 12 | * the License. 13 | */ 14 | package org.uiautomation.ios.wkrdp.events; 15 | 16 | import org.json.JSONException; 17 | import org.json.JSONObject; 18 | import org.uiautomation.ios.wkrdp.model.NodeId; 19 | 20 | public final class ChildIframeInserted extends NodeEvent { 21 | private final NodeId contentDocument; 22 | 23 | public ChildIframeInserted(JSONObject message) throws JSONException { 24 | super(message); 25 | JSONObject params = message.optJSONObject("params").getJSONObject("node"); 26 | JSONObject json = params.getJSONObject("contentDocument"); 27 | contentDocument = new NodeId(json.getInt("nodeId")); 28 | } 29 | 30 | public NodeId getContentDocument() { 31 | return contentDocument; 32 | } 33 | 34 | @Override 35 | public int hashCode() { 36 | final int prime = 31; 37 | int result = super.hashCode(); 38 | result = prime * result + ((contentDocument == null) ? 0 : contentDocument.hashCode()); 39 | return result; 40 | } 41 | 42 | @Override 43 | public boolean equals(Object obj) { 44 | if (this == obj) { 45 | return true; 46 | } 47 | if (!super.equals(obj)) { 48 | return false; 49 | } 50 | if (getClass() != obj.getClass()) { 51 | return false; 52 | } 53 | ChildIframeInserted other = (ChildIframeInserted) obj; 54 | if (contentDocument == null) { 55 | if (other.contentDocument != null) { 56 | return false; 57 | } 58 | } else if (!contentDocument.equals(other.contentDocument)) { 59 | return false; 60 | } 61 | return true; 62 | } 63 | } 64 | -------------------------------------------------------------------------------- /third_party/ios_driver/org/uiautomation/ios/wkrdp/events/ChildNodeRemoved.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2012-2013 eBay Software Foundation and ios-driver committers 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except 5 | * in compliance with the License. You may obtain a copy of the License at 6 | * 7 | * http://www.apache.org/licenses/LICENSE-2.0 8 | * 9 | * Unless required by applicable law or agreed to in writing, software distributed under the License 10 | * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express 11 | * or implied. See the License for the specific language governing permissions and limitations under 12 | * the License. 13 | */ 14 | package org.uiautomation.ios.wkrdp.events; 15 | 16 | import org.json.JSONException; 17 | import org.json.JSONObject; 18 | 19 | public class ChildNodeRemoved extends NodeEvent { 20 | public ChildNodeRemoved(JSONObject message) throws JSONException { 21 | super(message); 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /third_party/ios_driver/org/uiautomation/ios/wkrdp/events/Event.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2012-2013 eBay Software Foundation and ios-driver committers 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except 5 | * in compliance with the License. You may obtain a copy of the License at 6 | * 7 | * http://www.apache.org/licenses/LICENSE-2.0 8 | * 9 | * Unless required by applicable law or agreed to in writing, software distributed under the License 10 | * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express 11 | * or implied. See the License for the specific language governing permissions and limitations under 12 | * the License. 13 | */ 14 | package org.uiautomation.ios.wkrdp.events; 15 | 16 | import org.json.JSONObject; 17 | 18 | public class Event { 19 | private final JSONObject raw; 20 | private final long timestamp; 21 | 22 | public Event(JSONObject raw) { 23 | this.raw = raw; 24 | timestamp = System.currentTimeMillis(); 25 | } 26 | 27 | public final long getAge() { 28 | return System.currentTimeMillis() - timestamp; 29 | } 30 | 31 | @Override 32 | public String toString() { 33 | return raw.optString("method") + " " + raw; 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /third_party/ios_driver/org/uiautomation/ios/wkrdp/events/EventFactory.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2012-2013 eBay Software Foundation and ios-driver committers 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except 5 | * in compliance with the License. You may obtain a copy of the License at 6 | * 7 | * http://www.apache.org/licenses/LICENSE-2.0 8 | * 9 | * Unless required by applicable law or agreed to in writing, software distributed under the License 10 | * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express 11 | * or implied. See the License for the specific language governing permissions and limitations under 12 | * the License. 13 | */ 14 | package org.uiautomation.ios.wkrdp.events; 15 | 16 | import com.google.devtoolsdriver.devtools.DevtoolsEvent; 17 | import com.google.devtoolsdriver.util.JavaxJson; 18 | import java.lang.reflect.Constructor; 19 | import javax.json.Json; 20 | import javax.json.JsonObject; 21 | import org.json.JSONObject; 22 | import org.openqa.selenium.WebDriverException; 23 | 24 | public class EventFactory { 25 | private static final String NODE_REMOVED = "DOM.childNodeRemoved"; 26 | private static final String NODE_INSERTED = "DOM.childNodeInserted"; 27 | 28 | public static Event createEvent(DevtoolsEvent event) { 29 | JsonObject obj = 30 | Json.createObjectBuilder() 31 | .add("method", event.method()) 32 | .add("params", event.params()) 33 | .build(); 34 | try { 35 | return createObject(JavaxJson.toOrgJson(obj)); 36 | } catch (Exception e) { 37 | throw new WebDriverException( 38 | "Error creating an event generated by the webview: " + event, e); 39 | } 40 | } 41 | 42 | private static Event createObject(JSONObject message) throws Exception { 43 | Class clazz = getAssociatedEvent(message); 44 | 45 | Class[] parameterTypes = new Class[] {JSONObject.class}; 46 | Object[] parameters = new JSONObject[] {message}; 47 | 48 | Constructor constructor = clazz.getConstructor(parameterTypes); 49 | return constructor.newInstance(parameters); 50 | } 51 | 52 | private static Class getAssociatedEvent(JSONObject message) { 53 | String method = message.optString("method"); 54 | 55 | if (NODE_REMOVED.equals(method)) { 56 | return ChildNodeRemoved.class; 57 | } 58 | 59 | if (isFrameOrIFrame(message)) { 60 | return ChildIframeInserted.class; 61 | } 62 | 63 | return Event.class; 64 | } 65 | 66 | private static boolean isFrameOrIFrame(JSONObject message) { 67 | String method = message.optString("method"); 68 | JSONObject params = message.optJSONObject("params"); 69 | 70 | if (NODE_INSERTED.equals(method) 71 | && params != null 72 | && "IFRAME".equals(params.optJSONObject("node").optString("nodeName"))) { 73 | return true; 74 | } 75 | if (NODE_INSERTED.equals(method) 76 | && params != null 77 | && "FRAME".equals(params.optJSONObject("node").optString("nodeName"))) { 78 | return true; 79 | } 80 | return false; 81 | } 82 | } 83 | -------------------------------------------------------------------------------- /third_party/ios_driver/org/uiautomation/ios/wkrdp/events/EventHistory.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2012-2013 eBay Software Foundation and ios-driver committers 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except 5 | * in compliance with the License. You may obtain a copy of the License at 6 | * 7 | * http://www.apache.org/licenses/LICENSE-2.0 8 | * 9 | * Unless required by applicable law or agreed to in writing, software distributed under the License 10 | * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express 11 | * or implied. See the License for the specific language governing permissions and limitations under 12 | * the License. 13 | */ 14 | package org.uiautomation.ios.wkrdp.events; 15 | 16 | import java.util.ArrayList; 17 | import java.util.List; 18 | import java.util.concurrent.CopyOnWriteArrayList; 19 | import java.util.logging.Logger; 20 | import org.uiautomation.ios.wkrdp.model.NodeId; 21 | 22 | public class EventHistory { 23 | private static final Logger log = Logger.getLogger(EventHistory.class.getName()); 24 | 25 | private static final long MAX_AGE = 10 * 1000; 26 | 27 | private final List events = new CopyOnWriteArrayList<>(); 28 | 29 | public EventHistory() {} 30 | 31 | public void add(Event e) { 32 | if (events.size() >= 50) { 33 | removeOldEvents(); 34 | } 35 | events.add(e); 36 | } 37 | 38 | public void removeEvent(Event e) { 39 | events.remove(e); 40 | } 41 | 42 | private void removeOldEvents() { 43 | int removed = 0; 44 | for (Event e : events) { 45 | if (e.getAge() > MAX_AGE) { 46 | if (events.remove(e)) { 47 | removed++; 48 | } 49 | } 50 | } 51 | if (removed == 0) { 52 | log.warning("events history is growing too fast."); 53 | } 54 | } 55 | 56 | public List getInsertedFrames(NodeId parent) { 57 | List res = new ArrayList<>(); 58 | for (Event e : events) { 59 | if (e instanceof ChildIframeInserted 60 | && ((ChildIframeInserted) e).getParent().equals(parent)) { 61 | res.add((ChildIframeInserted) e); 62 | } 63 | } 64 | return res; 65 | } 66 | } 67 | -------------------------------------------------------------------------------- /third_party/ios_driver/org/uiautomation/ios/wkrdp/events/NodeEvent.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2012-2013 eBay Software Foundation and ios-driver committers 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except 5 | * in compliance with the License. You may obtain a copy of the License at 6 | * 7 | * http://www.apache.org/licenses/LICENSE-2.0 8 | * 9 | * Unless required by applicable law or agreed to in writing, software distributed under the License 10 | * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express 11 | * or implied. See the License for the specific language governing permissions and limitations under 12 | * the License. 13 | */ 14 | 15 | package org.uiautomation.ios.wkrdp.events; 16 | 17 | import java.util.logging.Logger; 18 | import org.json.JSONException; 19 | import org.json.JSONObject; 20 | import org.uiautomation.ios.wkrdp.model.NodeId; 21 | 22 | abstract class NodeEvent extends Event { 23 | private static final Logger log = Logger.getLogger(ChildNodeRemoved.class.getName()); 24 | 25 | private final NodeId node; 26 | private final NodeId parent; 27 | 28 | NodeEvent(JSONObject message) throws JSONException { 29 | super(message); 30 | JSONObject params = message.optJSONObject("params"); 31 | if (params == null) { 32 | log.severe("Cannot parse " + message); 33 | } 34 | int parentNodeId = params.getInt("parentNodeId"); 35 | 36 | if (params.has("node")) { 37 | params = params.getJSONObject("node"); 38 | } 39 | int nodeId = params.getInt("nodeId"); 40 | 41 | this.node = new NodeId(nodeId); 42 | this.parent = new NodeId(parentNodeId); 43 | } 44 | 45 | public final NodeId getNode() { 46 | return node; 47 | } 48 | 49 | public final NodeId getParent() { 50 | return parent; 51 | } 52 | 53 | @Override 54 | public final String toString() { 55 | return "id:" + node + ", parent:" + parent; 56 | } 57 | 58 | @Override 59 | public int hashCode() { 60 | final int prime = 31; 61 | int result = 1; 62 | result = prime * result + ((node == null) ? 0 : node.hashCode()); 63 | result = prime * result + ((parent == null) ? 0 : parent.hashCode()); 64 | return result; 65 | } 66 | 67 | @Override 68 | public boolean equals(Object obj) { 69 | if (this == obj) { 70 | return true; 71 | } 72 | if (obj == null) { 73 | return false; 74 | } 75 | if (getClass() != obj.getClass()) { 76 | return false; 77 | } 78 | NodeEvent other = (NodeEvent) obj; 79 | if (node == null) { 80 | if (other.node != null) { 81 | return false; 82 | } 83 | } else if (!node.equals(other.node)) { 84 | return false; 85 | } 86 | if (parent == null) { 87 | if (other.parent != null) { 88 | return false; 89 | } 90 | } else if (!parent.equals(other.parent)) { 91 | return false; 92 | } 93 | return true; 94 | } 95 | } 96 | -------------------------------------------------------------------------------- /third_party/ios_driver/org/uiautomation/ios/wkrdp/model/NodeId.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2012-2013 eBay Software Foundation and ios-driver committers 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except 5 | * in compliance with the License. You may obtain a copy of the License at 6 | * 7 | * http://www.apache.org/licenses/LICENSE-2.0 8 | * 9 | * Unless required by applicable law or agreed to in writing, software distributed under the License 10 | * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express 11 | * or implied. See the License for the specific language governing permissions and limitations under 12 | * the License. 13 | */ 14 | package org.uiautomation.ios.wkrdp.model; 15 | 16 | /** Id of a node on a page. */ 17 | public final class NodeId { 18 | private final int id; 19 | 20 | public NodeId(int id) { 21 | this.id = id; 22 | } 23 | 24 | public int getId() { 25 | return id; 26 | } 27 | 28 | @Override 29 | public String toString() { 30 | return "" + id; 31 | } 32 | 33 | @Override 34 | public int hashCode() { 35 | final int prime = 31; 36 | int result = 1; 37 | result = prime * result + id; 38 | return result; 39 | } 40 | 41 | @Override 42 | public boolean equals(Object obj) { 43 | if (this == obj) { 44 | return true; 45 | } 46 | if (obj == null) { 47 | return false; 48 | } 49 | if (getClass() != obj.getClass()) { 50 | return false; 51 | } 52 | NodeId other = (NodeId) obj; 53 | if (id != other.id) { 54 | return false; 55 | } 56 | return true; 57 | } 58 | 59 | public boolean exist() { 60 | return id > 0; 61 | } 62 | } 63 | -------------------------------------------------------------------------------- /third_party/ios_driver/org/uiautomation/ios/wkrdp/model/RemoteObject.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2012-2013 eBay Software Foundation and ios-driver committers 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except 5 | * in compliance with the License. You may obtain a copy of the License at 6 | * 7 | * http://www.apache.org/licenses/LICENSE-2.0 8 | * 9 | * Unless required by applicable law or agreed to in writing, software distributed under the License 10 | * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express 11 | * or implied. See the License for the specific language governing permissions and limitations under 12 | * the License. 13 | */ 14 | package org.uiautomation.ios.wkrdp.model; 15 | 16 | import com.google.common.collect.ImmutableList; 17 | import com.google.devtoolsdriver.devtools.DOM; 18 | import com.google.devtoolsdriver.devtools.DevtoolsCommand; 19 | import com.google.devtoolsdriver.devtools.Runtime; 20 | import com.google.devtoolsdriver.webdriver.JsAtoms; 21 | import javax.json.JsonObject; 22 | import org.json.JSONException; 23 | import org.uiautomation.ios.wkrdp.WebInspectorHelper; 24 | 25 | /** A remote object on a webpage. */ 26 | public final class RemoteObject { 27 | private final String objectId; 28 | private final WebInspectorHelper inspector; 29 | 30 | public RemoteObject(String objectId, WebInspectorHelper inspector) { 31 | this.inspector = inspector; 32 | this.objectId = objectId; 33 | } 34 | 35 | public String getId() { 36 | return objectId; 37 | } 38 | 39 | public RemoteWebElement getWebElement() throws JSONException, Exception { 40 | JsonObject result = inspector.sendCommand(DOM.requestNode(objectId)); 41 | int id = result.getInt("nodeId"); 42 | NodeId nodeId = new NodeId(id); 43 | return new RemoteWebElement(nodeId, this, inspector); 44 | } 45 | 46 | @Override 47 | public String toString() { 48 | return objectId; 49 | } 50 | 51 | public T call(String function) { 52 | String f = "(function(arg) { var res = this" + function + "; return res;})"; 53 | DevtoolsCommand cmd = 54 | Runtime.callFunctionOn(getId(), f) 55 | .withReturnByValue(false) 56 | .withArguments(ImmutableList.of(Runtime.callArgument().withValue(""))); 57 | JsonObject response = inspector.sendCommand(cmd); 58 | return inspector.cast(response); 59 | } 60 | 61 | public String stringify() { 62 | String f = "(function() { var res = " + JsAtoms.stringify("this") + "; return res;})"; 63 | DevtoolsCommand cmd = Runtime.callFunctionOn(getId(), f).withReturnByValue(false); 64 | JsonObject response = inspector.sendCommand(cmd); 65 | return inspector.cast(response); 66 | } 67 | } 68 | -------------------------------------------------------------------------------- /third_party/ios_driver/org/uiautomation/ios/wkrdp/model/RemoteObjectArray.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2012-2013 eBay Software Foundation and ios-driver committers 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except 5 | * in compliance with the License. You may obtain a copy of the License at 6 | * 7 | * http://www.apache.org/licenses/LICENSE-2.0 8 | * 9 | * Unless required by applicable law or agreed to in writing, software distributed under the License 10 | * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express 11 | * or implied. See the License for the specific language governing permissions and limitations under 12 | * the License. 13 | */ 14 | package org.uiautomation.ios.wkrdp.model; 15 | 16 | import java.util.Iterator; 17 | 18 | public class RemoteObjectArray implements Iterable { 19 | 20 | private final RemoteObject remoteArray; 21 | private final int size; 22 | 23 | public RemoteObjectArray(RemoteObject remoteArray) { 24 | this.remoteArray = remoteArray; 25 | try { 26 | this.size = ((Number) remoteArray.call(".length")).intValue(); 27 | } catch (Exception e) { 28 | throw new RuntimeException("Error finding array size " + e.getMessage(), e); 29 | } 30 | } 31 | 32 | @Override 33 | public Iterator iterator() { 34 | return new RemoteObjectIterator(remoteArray, size); 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /third_party/ios_driver/org/uiautomation/ios/wkrdp/model/RemoteObjectIterator.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2012-2013 eBay Software Foundation and ios-driver committers 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except 5 | * in compliance with the License. You may obtain a copy of the License at 6 | * 7 | * http://www.apache.org/licenses/LICENSE-2.0 8 | * 9 | * Unless required by applicable law or agreed to in writing, software distributed under the License 10 | * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express 11 | * or implied. See the License for the specific language governing permissions and limitations under 12 | * the License. 13 | */ 14 | package org.uiautomation.ios.wkrdp.model; 15 | 16 | import java.util.Iterator; 17 | import java.util.logging.Level; 18 | import java.util.logging.Logger; 19 | 20 | /** An iterator over webpage objects. */ 21 | public final class RemoteObjectIterator implements Iterator { 22 | private static final Logger log = Logger.getLogger(RemoteObjectIterator.class.getName()); 23 | 24 | private final RemoteObject underlyingObject; 25 | private final int size; 26 | 27 | private int index = 0; 28 | 29 | RemoteObjectIterator(RemoteObject uro, int size) { 30 | this.underlyingObject = uro; 31 | this.size = size; 32 | } 33 | 34 | @Override 35 | public boolean hasNext() { 36 | return index < size; 37 | } 38 | 39 | @Override 40 | public Object next() { 41 | Object res; 42 | try { 43 | res = underlyingObject.call("[" + index + "]"); 44 | index++; 45 | return res; 46 | } catch (Exception e) { 47 | log.log(Level.SEVERE, "error", e); 48 | } 49 | return null; 50 | } 51 | 52 | @Override 53 | public void remove() { 54 | throw new IllegalAccessError("NI"); 55 | } 56 | } 57 | -------------------------------------------------------------------------------- /third_party/jsatoms/back_ios.js: -------------------------------------------------------------------------------- 1 | function(){return(function(){var b=String.prototype.trim?function(a){return a.trim()}:function(a){return a.replace(/^[\s\xa0]+|[\s\xa0]+$/g,"")};function f(a){return-1!=g.indexOf(a)} 2 | function h(a,c){var k=0;a=b(String(a)).split(".");c=b(String(c)).split(".");for(var v=Math.max(a.length,c.length),p=0;0==k&&pc?1:0};var g;a:{var m=this.navigator;if(m){var n=m.userAgent;if(n){g=n;break a}}g=""};function q(){return(f("Chrome")||f("CriOS"))&&!f("Edge")};function r(){return f("iPhone")&&!f("iPod")&&!f("iPad")};function t(a,c){var k=u;Object.prototype.hasOwnProperty.call(k,a)||(k[a]=c(a))};var w="",x=/WebKit\/(\S+)/.exec(g);x&&(w=x?x[1]:"");var y=w,u={};function z(a){t(a,function(){return 0<=h(y,a)})};var A=f("Firefox"),B=r()||f("iPod"),C=f("iPad"),D=f("Android")&&!(q()||f("Firefox")||f("Opera")||f("Silk")),E=q(),F=f("Safari")&&!(q()||f("Coast")||f("Opera")||f("Edge")||f("Silk")||f("Android"))&&!(r()||f("iPad")||f("iPod"));/* 3 | 4 | Copyright 2014 Software Freedom Conservancy 5 | 6 | Licensed under the Apache License, Version 2.0 (the "License"); 7 | you may not use this file except in compliance with the License. 8 | You may obtain a copy of the License at 9 | 10 | http://www.apache.org/licenses/LICENSE-2.0 11 | 12 | Unless required by applicable law or agreed to in writing, software 13 | distributed under the License is distributed on an "AS IS" BASIS, 14 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | See the License for the specific language governing permissions and 16 | limitations under the License. 17 | */ 18 | var G=window;function H(a,c){this.code=a;this.a=I[a]||"unknown error";this.message=c||"";a=this.a.replace(/((?:^|\s+)[a-z])/g,function(a){return a.toUpperCase().replace(/^[\s\xa0]+/g,"")});c=a.length-5;if(0>c||a.indexOf("Error",c)!=c)a+="Error";this.name=a;a=Error(this.message);a.name=this.name;this.stack=a.stack||""} 19 | (function(){var a=Error;function c(){}c.prototype=a.prototype;H.b=a.prototype;H.prototype=new c;H.prototype.constructor=H;H.a=function(c,v,p){for(var e=Array(arguments.length-2),d=2;d=a)throw new H(13,"number of pages must be positive");if(null!==c&&a>c)throw new H(13,"number of pages must be less than the length of the browser history");G.history.go(-a)}var Q=["_"],R=this;Q[0]in R||!R.execScript||R.execScript("var "+Q[0]);for(var S;Q.length&&(S=Q.shift());)Q.length||void 0===P?R[S]&&R[S]!==Object.prototype[S]?R=R[S]:R=R[S]={}:R[S]=P;;return this._.apply(null,arguments);}).apply({navigator:typeof window!="undefined"?window.navigator:null},arguments);} 22 | -------------------------------------------------------------------------------- /third_party/jsatoms/forward_ios.js: -------------------------------------------------------------------------------- 1 | function(){return(function(){var b=String.prototype.trim?function(a){return a.trim()}:function(a){return a.replace(/^[\s\xa0]+|[\s\xa0]+$/g,"")};function f(a){return-1!=h.indexOf(a)} 2 | function k(a,c){var g=0;a=b(String(a)).split(".");c=b(String(c)).split(".");for(var v=Math.max(a.length,c.length),p=0;0==g&&pc?1:0};var h;a:{var m=this.navigator;if(m){var n=m.userAgent;if(n){h=n;break a}}h=""};function q(){return(f("Chrome")||f("CriOS"))&&!f("Edge")};function r(){return f("iPhone")&&!f("iPod")&&!f("iPad")};function t(a,c){var g=u;return Object.prototype.hasOwnProperty.call(g,a)?g[a]:g[a]=c(a)};var w="",x=/WebKit\/(\S+)/.exec(h);x&&(w=x?x[1]:"");var y=w,u={};function z(a){return t(a,function(){return 0<=k(y,a)})};var A=f("Firefox"),B=r()||f("iPod"),C=f("iPad"),D=f("Android")&&!(q()||f("Firefox")||f("Opera")||f("Silk")),E=q(),F=f("Safari")&&!(q()||f("Coast")||f("Opera")||f("Edge")||f("Silk")||f("Android"))&&!(r()||f("iPad")||f("iPod"));/* 3 | 4 | Copyright 2014 Software Freedom Conservancy 5 | 6 | Licensed under the Apache License, Version 2.0 (the "License"); 7 | you may not use this file except in compliance with the License. 8 | You may obtain a copy of the License at 9 | 10 | http://www.apache.org/licenses/LICENSE-2.0 11 | 12 | Unless required by applicable law or agreed to in writing, software 13 | distributed under the License is distributed on an "AS IS" BASIS, 14 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | See the License for the specific language governing permissions and 16 | limitations under the License. 17 | */ 18 | var G=window;function H(a,c){this.code=a;this.a=I[a]||"unknown error";this.message=c||"";a=this.a.replace(/((?:^|\s+)[a-z])/g,function(a){return a.toUpperCase().replace(/^[\s\xa0]+/g,"")});c=a.length-5;if(0>c||a.indexOf("Error",c)!=c)a+="Error";this.name=a;a=Error(this.message);a.name=this.name;this.stack=a.stack||""} 19 | (function(){var a=Error;function c(){}c.prototype=a.prototype;H.b=a.prototype;H.prototype=new c;H.prototype.constructor=H;H.a=function(c,v,p){for(var e=Array(arguments.length-2),d=2;d=a)throw new H(13,"number of pages must be positive");if(null!==c&&a>c)throw new H(13,"number of pages must be less than the length of the browser history");G.history.go(a)}var R=["_"],S=this;R[0]in S||!S.execScript||S.execScript("var "+R[0]);for(var T;R.length&&(T=R.shift());)R.length||void 0===Q?S[T]&&S[T]!==Object.prototype[T]?S=S[T]:S=S[T]={}:S[T]=Q;;return this._.apply(null,arguments);}).apply({navigator:typeof window!="undefined"?window.navigator:null},arguments);} 22 | -------------------------------------------------------------------------------- /third_party/jsatoms/stringify_ios.js: -------------------------------------------------------------------------------- 1 | function(){return(function(){function d(a){var b=typeof a;if("object"==b)if(a){if(a instanceof Array)return"array";if(a instanceof Object)return b;var c=Object.prototype.toString.call(a);if("[object Window]"==c)return"object";if("[object Array]"==c||"number"==typeof a.length&&"undefined"!=typeof a.splice&&"undefined"!=typeof a.propertyIsEnumerable&&!a.propertyIsEnumerable("splice"))return"array";if("[object Function]"==c||"undefined"!=typeof a.call&&"undefined"!=typeof a.propertyIsEnumerable&&!a.propertyIsEnumerable("call"))return"function"}else return"null"; 2 | else if("function"==b&&"undefined"==typeof a.call)return"object";return b};function h(a){this.a=a} 3 | function l(a,b,c){if(null==b)c.push("null");else{if("object"==typeof b){if("array"==d(b)){var g=b;b=g.length;c.push("[");for(var f="",e=0;eb?1:0};var t;a:{var w=this.navigator;if(w){var x=w.userAgent;if(x){t=x;break a}}t=""};function y(){return(r("Chrome")||r("CriOS"))&&!r("Edge")};function z(){return r("iPhone")&&!r("iPod")&&!r("iPad")};var A=r("Firefox"),B=z()||r("iPod"),C=r("iPad"),D=r("Android")&&!(y()||r("Firefox")||r("Opera")||r("Silk")),E=y(),F=r("Safari")&&!(y()||r("Coast")||r("Opera")||r("Edge")||r("Silk")||r("Android"))&&!(z()||r("iPad")||r("iPod"));function G(a){return(a=a.exec(t))?a[1]:""}var H=function(){if(A)return G(/Firefox\/([0-9.]+)/);if(E)return z()||r("iPad")||r("iPod")?G(/CriOS\/([0-9.]+)/):G(/Chrome\/([0-9.]+)/);if(F&&!(z()||r("iPad")||r("iPod")))return G(/Version\/([0-9.]+)/);if(B||C){var a=/Version\/(\S+).*Mobile\/(\S+)/.exec(t);if(a)return a[1]+"."+a[2]}else if(D)return(a=G(/Android\s+([0-9.]+)/))?a:G(/Version\/([0-9.]+)/);return""}();/* 7 | 8 | Copyright 2014 Software Freedom Conservancy 9 | 10 | Licensed under the Apache License, Version 2.0 (the "License"); 11 | you may not use this file except in compliance with the License. 12 | You may obtain a copy of the License at 13 | 14 | http://www.apache.org/licenses/LICENSE-2.0 15 | 16 | Unless required by applicable law or agreed to in writing, software 17 | distributed under the License is distributed on an "AS IS" BASIS, 18 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 19 | See the License for the specific language governing permissions and 20 | limitations under the License. 21 | */ 22 | function I(a){D?u(J,a):u(H,a)}var K;if(D){var L=/Android\s+([0-9\.]+)/.exec(t);K=L?L[1]:"0"}else K="0";var J=K;D&&I(2.3);D&&I(4);F&&I(6);function M(a,b){var c=[];l(new h(b),a,c);return c.join("")}var N=["_"],O=this;N[0]in O||!O.execScript||O.execScript("var "+N[0]);for(var P;N.length&&(P=N.shift());){var Q;if(Q=!N.length)Q=void 0!==M;Q?O[P]=M:O[P]&&O[P]!==Object.prototype[P]?O=O[P]:O=O[P]={}};;return this._.apply(null,arguments);}).apply({navigator:typeof window!="undefined"?window.navigator:null},arguments);} 23 | --------------------------------------------------------------------------------