summaryrefslogtreecommitdiff
path: root/core/java
diff options
context:
space:
mode:
authorJohn Reck <jreck@google.com>2011-08-12 14:20:11 -0700
committerAndroid (Google) Code Review <android-gerrit@google.com>2011-08-12 14:20:11 -0700
commit8b84ac955328d2c5175d29fcbbf615719f1c17ef (patch)
tree2eda73c29a477e1ab56c1fdfd49b65fad57751ad /core/java
parente1fec2408b41cdbc39003398c38537ef95af94ab (diff)
parent62e55fc77bb1f507f90f9fb9d88b595756f42af1 (diff)
Merge "Remove WebDriver"
Diffstat (limited to 'core/java')
-rw-r--r--core/java/android/webkit/webdriver/By.java252
-rw-r--r--core/java/android/webkit/webdriver/WebDriver.java843
-rw-r--r--core/java/android/webkit/webdriver/WebDriverException.java38
-rw-r--r--core/java/android/webkit/webdriver/WebElement.java388
-rw-r--r--core/java/android/webkit/webdriver/WebElementNotFoundException.java41
-rw-r--r--core/java/android/webkit/webdriver/WebElementStaleException.java42
-rw-r--r--core/java/android/webkit/webdriver/WebViewClient.java125
-rw-r--r--core/java/android/webkit/webdriver/WebchromeClientWrapper.java193
8 files changed, 0 insertions, 1922 deletions
diff --git a/core/java/android/webkit/webdriver/By.java b/core/java/android/webkit/webdriver/By.java
deleted file mode 100644
index fa4fe74dc158..000000000000
--- a/core/java/android/webkit/webdriver/By.java
+++ /dev/null
@@ -1,252 +0,0 @@
-/*
- * Copyright (C) 2011 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package android.webkit.webdriver;
-
-import java.util.List;
-
-/**
- * Mechanism to locate elements within the DOM of the page.
- * @hide
- */
-public abstract class By {
- public abstract WebElement findElement(WebElement element);
- public abstract List<WebElement> findElements(WebElement element);
-
- /**
- * Locates an element by its HTML id attribute.
- *
- * @param id The HTML id attribute to look for.
- * @return A By instance that locates elements by their HTML id attributes.
- */
- public static By id(final String id) {
- throwIfNull(id);
- return new By() {
- @Override
- public WebElement findElement(WebElement element) {
- return element.findElementById(id);
- }
-
- @Override
- public List<WebElement> findElements(WebElement element) {
- return element.findElementsById(id); // Yes, it happens a lot.
- }
-
- @Override
- public String toString() {
- return "By.id: " + id;
- }
- };
- }
-
- /**
- * Locates an element by the matching the exact text on the HTML link.
- *
- * @param linkText The exact text to match against.
- * @return A By instance that locates elements by the text displayed by
- * the link.
- */
- public static By linkText(final String linkText) {
- throwIfNull(linkText);
- return new By() {
- @Override
- public WebElement findElement(WebElement element) {
- return element.findElementByLinkText(linkText);
- }
-
- @Override
- public List<WebElement> findElements(WebElement element) {
- return element.findElementsByLinkText(linkText);
- }
-
- @Override
- public String toString() {
- return "By.linkText: " + linkText;
- }
- };
- }
-
- /**
- * Locates an element by matching partial part of the text displayed by an
- * HTML link.
- *
- * @param linkText The text that should be contained by the text displayed
- * on the link.
- * @return A By instance that locates elements that contain the given link
- * text.
- */
- public static By partialLinkText(final String linkText) {
- throwIfNull(linkText);
- return new By() {
- @Override
- public WebElement findElement(WebElement element) {
- return element.findElementByPartialLinkText(linkText);
- }
-
- @Override
- public List<WebElement> findElements(WebElement element) {
- return element.findElementsByPartialLinkText(linkText);
- }
-
- @Override
- public String toString() {
- return "By.partialLinkText: " + linkText;
- }
- };
- }
-
- /**
- * Locates an element by matching its HTML name attribute.
- *
- * @param name The value of the HTML name attribute.
- * @return A By instance that locates elements by the HTML name attribute.
- */
- public static By name(final String name) {
- throwIfNull(name);
- return new By() {
- @Override
- public WebElement findElement(WebElement element) {
- return element.findElementByName(name);
- }
-
- @Override
- public List<WebElement> findElements(WebElement element) {
- return element.findElementsByName(name);
- }
-
- @Override
- public String toString() {
- return "By.name: " + name;
- }
- };
- }
-
- /**
- * Locates an element by matching its class name.
- * @param className The class name
- * @return A By instance that locates elements by their class name attribute.
- */
- public static By className(final String className) {
- throwIfNull(className);
- return new By() {
- @Override
- public WebElement findElement(WebElement element) {
- return element.findElementByClassName(className);
- }
-
- @Override
- public List<WebElement> findElements(WebElement element) {
- return element.findElementsByClassName(className);
- }
-
- @Override
- public String toString() {
- return "By.className: " + className;
- }
- };
- }
-
- /**
- * Locates an element by matching its css property.
- *
- * @param css The css property.
- * @return A By instance that locates elements by their css property.
- */
- public static By css(final String css) {
- throwIfNull(css);
- return new By() {
- @Override
- public WebElement findElement(WebElement element) {
- return element.findElementByCss(css);
- }
-
- @Override
- public List<WebElement> findElements(WebElement element) {
- return element.findElementsByCss(css);
- }
-
- @Override
- public String toString() {
- return "By.css: " + css;
- }
- };
- }
-
- /**
- * Locates an element by matching its HTML tag name.
- *
- * @param tagName The HTML tag name to look for.
- * @return A By instance that locates elements using the name of the
- * HTML tag.
- */
- public static By tagName(final String tagName) {
- throwIfNull(tagName);
- return new By() {
- @Override
- public WebElement findElement(WebElement element) {
- return element.findElementByTagName(tagName);
- }
-
- @Override
- public List<WebElement> findElements(WebElement element) {
- return element.findElementsByTagName(tagName);
- }
-
- @Override
- public String toString() {
- return "By.tagName: " + tagName;
- }
- };
- }
-
- /**
- * Locates an element using an XPath expression.
- *
- * <p>When using XPath, be aware that this follows standard conventions: a
- * search prefixed with "//" will search the entire document, not just the
- * children of the current node. Use ".//" to limit your search to the
- * children of this {@link android.webkit.webdriver.WebElement}.
- *
- * @param xpath The XPath expression to use.
- * @return A By instance that locates elements using the given XPath.
- */
- public static By xpath(final String xpath) {
- throwIfNull(xpath);
- return new By() {
- @Override
- public WebElement findElement(WebElement element) {
- return element.findElementByXPath(xpath);
- }
-
- @Override
- public List<WebElement> findElements(WebElement element) {
- return element.findElementsByXPath(xpath);
- }
-
- @Override
- public String toString() {
- return "By.xpath: " + xpath;
- }
- };
- }
-
- private static void throwIfNull(String argument) {
- if (argument == null) {
- throw new IllegalArgumentException(
- "Cannot find elements with null locator.");
- }
- }
-}
diff --git a/core/java/android/webkit/webdriver/WebDriver.java b/core/java/android/webkit/webdriver/WebDriver.java
deleted file mode 100644
index 79e652308550..000000000000
--- a/core/java/android/webkit/webdriver/WebDriver.java
+++ /dev/null
@@ -1,843 +0,0 @@
-/*
- * Copyright (C) 2011 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package android.webkit.webdriver;
-
-import android.graphics.Point;
-import android.os.Handler;
-import android.os.Message;
-import android.os.SystemClock;
-import android.view.InputDevice;
-import android.view.KeyCharacterMap;
-import android.view.KeyEvent;
-import android.view.MotionEvent;
-import android.webkit.WebView;
-import android.webkit.WebViewCore;
-
-import com.google.android.collect.Lists;
-import com.google.android.collect.Maps;
-
-import com.android.internal.R;
-
-import org.json.JSONArray;
-import org.json.JSONException;
-import org.json.JSONObject;
-
-import java.io.BufferedReader;
-import java.io.IOException;
-import java.io.InputStream;
-import java.io.InputStreamReader;
-import java.util.Iterator;
-import java.util.List;
-import java.util.Map;
-
-/**
- * Drives a web application by controlling the WebView. This class
- * provides a DOM-like API allowing to get information about the page,
- * navigate, and interact with the web application. This is particularly useful
- * for testing a web application.
- *
- * <p/>{@link android.webkit.webdriver.WebDriver} should be created in the main
- * thread, and invoked from another thread. Here is a sample usage:
- *
- * public class WebDriverStubActivity extends Activity {
- * private WebDriver mDriver;
- *
- * public void onCreate(Bundle savedInstanceState) {
- * super.onCreate(savedInstanceState);
- * WebView view = new WebView(this);
- * mDriver = new WebDriver(view);
- * setContentView(view);
- * }
- *
- *
- * public WebDriver getDriver() {
- * return mDriver;
- * }
- *}
- *
- * public class WebDriverTest extends
- * ActivityInstrumentationTestCase2<WebDriverStubActivity>{
- * private WebDriver mDriver;
- *
- * public WebDriverTest() {
- * super(WebDriverStubActivity.class);
- * }
- *
- * protected void setUp() throws Exception {
- * super.setUp();
- * mDriver = getActivity().getDriver();
- * }
- *
- * public void testGoogle() {
- * mDriver.get("http://google.com");
- * WebElement searchBox = mDriver.findElement(By.name("q"));
- * q.sendKeys("Cheese!");
- * q.submit();
- * assertTrue(mDriver.findElements(By.partialLinkText("Cheese")).size() > 0);
- * }
- *}
- *
- * @hide
- */
-public class WebDriver {
- // Timeout for page load in milliseconds.
- private static final int LOADING_TIMEOUT = 30000;
- // Timeout for executing JavaScript in the WebView in milliseconds.
- private static final int JS_EXECUTION_TIMEOUT = 10000;
- // Timeout for the MotionEvent to be completely handled
- private static final int MOTION_EVENT_TIMEOUT = 1000;
- // Timeout for detecting a new page load
- private static final int PAGE_STARTED_LOADING = 500;
- // Timeout for handling KeyEvents
- private static final int KEY_EVENT_TIMEOUT = 2000;
-
- // Commands posted to the handler
- private static final int CMD_GET_URL = 1;
- private static final int CMD_EXECUTE_SCRIPT = 2;
- private static final int CMD_SEND_TOUCH = 3;
- private static final int CMD_SEND_KEYS = 4;
- private static final int CMD_NAV_REFRESH = 5;
- private static final int CMD_NAV_BACK = 6;
- private static final int CMD_NAV_FORWARD = 7;
- private static final int CMD_SEND_KEYCODE = 8;
- private static final int CMD_MOVE_CURSOR_RIGHTMOST_POS = 9;
- private static final int CMD_MESSAGE_RELAY_ECHO = 10;
-
- private static final String ELEMENT_KEY = "ELEMENT";
- private static final String STATUS = "status";
- private static final String VALUE = "value";
-
- private static final long MAIN_THREAD = Thread.currentThread().getId();
-
- // This is updated by a callabck from JavaScript when the result is ready.
- private String mJsResult;
-
- // Used for synchronization
- private final Object mSyncObject;
- private final Object mSyncPageLoad;
-
- // Updated when the command is done executing in the main thread.
- private volatile boolean mCommandDone;
- // Used by WebViewClientWrapper.onPageStarted() to notify that
- // a page started loading.
- private volatile boolean mPageStartedLoading;
- // Used by WebChromeClientWrapper.onProgressChanged to notify when
- // a page finished loading.
- private volatile boolean mPageFinishedLoading;
- private WebView mWebView;
- private Navigation mNavigation;
- // This WebElement represents the object document.documentElement
- private WebElement mDocumentElement;
-
-
- // This Handler runs in the main UI thread.
- private final Handler mHandler = new Handler() {
- @Override
- public void handleMessage(Message msg) {
- switch (msg.what) {
- case CMD_GET_URL:
- final String url = (String) msg.obj;
- mWebView.loadUrl(url);
- break;
- case CMD_EXECUTE_SCRIPT:
- mWebView.loadUrl("javascript:" + (String) msg.obj);
- break;
- case CMD_MESSAGE_RELAY_ECHO:
- notifyCommandDone();
- break;
- case CMD_SEND_TOUCH:
- touchScreen((Point) msg.obj);
- notifyCommandDone();
- break;
- case CMD_SEND_KEYS:
- dispatchKeys((CharSequence[]) msg.obj);
- notifyCommandDone();
- break;
- case CMD_NAV_REFRESH:
- mWebView.reload();
- break;
- case CMD_NAV_BACK:
- mWebView.goBack();
- break;
- case CMD_NAV_FORWARD:
- mWebView.goForward();
- break;
- case CMD_SEND_KEYCODE:
- dispatchKeyCodes((int[]) msg.obj);
- notifyCommandDone();
- break;
- case CMD_MOVE_CURSOR_RIGHTMOST_POS:
- moveCursorToLeftMostPos((String) msg.obj);
- notifyCommandDone();
- break;
- }
- }
- };
-
- /**
- * Error codes from the WebDriver wire protocol
- * http://code.google.com/p/selenium/wiki/JsonWireProtocol#Response_Status_Codes
- */
- private enum ErrorCode {
- SUCCESS(0),
- NO_SUCH_ELEMENT(7),
- NO_SUCH_FRAME(8),
- UNKNOWN_COMMAND(9),
- UNSUPPORTED_OPERATION(9), // Alias
- STALE_ELEMENT_REFERENCE(10),
- ELEMENT_NOT_VISISBLE(11),
- INVALID_ELEMENT_STATE(12),
- UNKNOWN_ERROR(13),
- ELEMENT_NOT_SELECTABLE(15),
- XPATH_LOOKUP_ERROR(19),
- NO_SUCH_WINDOW(23),
- INVALID_COOKIE_DOMAIN(24),
- UNABLE_TO_SET_COOKIE(25),
- MODAL_DIALOG_OPENED(26),
- MODAL_DIALOG_OPEN(27),
- SCRIPT_TIMEOUT(28);
-
- private final int mCode;
- private static ErrorCode[] values = ErrorCode.values();
-
- ErrorCode(int code) {
- this.mCode = code;
- }
-
- public int getCode() {
- return mCode;
- }
-
- public static ErrorCode get(final int intValue) {
- for (int i = 0; i < values.length; i++) {
- if (values[i].getCode() == intValue) {
- return values[i];
- }
- }
- return UNKNOWN_ERROR;
- }
- }
-
- public WebDriver(WebView webview) {
- this.mWebView = webview;
- mWebView.requestFocus();
- if (mWebView == null) {
- throw new IllegalArgumentException("WebView cannot be null");
- }
- if (!mWebView.getSettings().getJavaScriptEnabled()) {
- throw new RuntimeException("Javascript is disabled in the WebView. "
- + "Enable it to use WebDriver");
- }
- shouldRunInMainThread(true);
-
- mSyncObject = new Object();
- mSyncPageLoad = new Object();
- this.mWebView = webview;
- WebChromeClientWrapper chromeWrapper = new WebChromeClientWrapper(
- webview.getWebChromeClient(), this);
- mWebView.setWebChromeClient(chromeWrapper);
- WebViewClientWrapper viewWrapper = new WebViewClientWrapper(
- webview.getWebViewClient(), this);
- mWebView.setWebViewClient(viewWrapper);
- mWebView.addJavascriptInterface(new JavascriptResultReady(),
- "webdriver");
- mDocumentElement = new WebElement(this, "");
- mNavigation = new Navigation();
- }
-
- /**
- * @return The title of the current page, null if not set.
- */
- public String getTitle() {
- return mWebView.getTitle();
- }
-
- /**
- * Loads a URL in the WebView. This function is blocking and will return
- * when the page has finished loading.
- *
- * @param url The URL to load.
- */
- public void get(String url) {
- mNavigation.to(url);
- }
-
- /**
- * @return The source page of the currently loaded page in WebView.
- */
- public String getPageSource() {
- return (String) executeScript("return new XMLSerializer()."
- + "serializeToString(document);");
- }
-
- /**
- * Find the first {@link android.webkit.webdriver.WebElement} using the
- * given method.
- *
- * @param by The locating mechanism to use.
- * @return The first matching element on the current context.
- * @throws {@link android.webkit.webdriver.WebElementNotFoundException} if
- * no matching element was found.
- */
- public WebElement findElement(By by) {
- checkNotNull(mDocumentElement, "Load a page using WebDriver.get() "
- + "before looking for elements.");
- return by.findElement(mDocumentElement);
- }
-
- /**
- * Finds all {@link android.webkit.webdriver.WebElement} within the page
- * using the given method.
- *
- * @param by The locating mechanism to use.
- * @return A list of all {@link android.webkit.webdriver.WebElement} found,
- * or an empty list if nothing matches.
- */
- public List<WebElement> findElements(By by) {
- checkNotNull(mDocumentElement, "Load a page using WebDriver.get() "
- + "before looking for elements.");
- return by.findElements(mDocumentElement);
- }
-
- /**
- * Clears the WebView's state and closes associated views.
- */
- public void quit() {
- mWebView.clearCache(true);
- mWebView.clearFormData();
- mWebView.clearHistory();
- mWebView.clearSslPreferences();
- mWebView.clearView();
- mWebView.removeAllViewsInLayout();
- }
-
- /**
- * Executes javascript in the context of the main frame.
- *
- * If the script has a return value the following happens:
- * <ul>
- * <li>For an HTML element, this method returns a WebElement</li>
- * <li>For a decimal, a Double is returned</li>
- * <li>For non-decimal number, a Long is returned</li>
- * <li>For a boolean, a Boolean is returned</li>
- * <li>For all other cases, a String is returned</li>
- * <li>For an array, this returns a List<Object> with each object
- * following the rules above.</li>
- * <li>For an object literal this returns a Map<String, Object>. Note that
- * Object literals keys can only be Strings. Non Strings keys will
- * be filtered out.</li>
- * </ul>
- *
- * <p> Arguments must be a number, a boolean, a string a WebElement or
- * a list of any combination of the above. The arguments will be made
- * available to the javascript via the "arguments" magic variable,
- * as if the function was called via "Function.apply".
- *
- * @param script The JavaScript to execute.
- * @param args The arguments to the script. Can be any of a number, boolean,
- * string, WebElement or a List of those.
- * @return A Boolean, Long, Double, String, WebElement, List or null.
- */
- public Object executeScript(final String script, final Object... args) {
- String scriptArgs = "[" + convertToJsArgs(args) + "]";
- String injectScriptJs = getResourceAsString(R.raw.execute_script_android);
- return executeRawJavascript("(" + injectScriptJs +
- ")(" + escapeAndQuote(script) + ", " + scriptArgs + ", true)");
- }
-
- public Navigation navigate() {
- return mNavigation;
- }
-
-
- /**
- * @hide
- */
- public class Navigation {
- /* package */ Navigation () {}
-
- public void back() {
- navigate(CMD_NAV_BACK, null);
- }
-
- public void forward() {
- navigate(CMD_NAV_FORWARD, null);
- }
-
- public void to(String url) {
- navigate(CMD_GET_URL, url);
- }
-
- public void refresh() {
- navigate(CMD_NAV_REFRESH, null);
- }
-
- private void navigate(int command, String url) {
- synchronized (mSyncPageLoad) {
- mPageFinishedLoading = false;
- Message msg = mHandler.obtainMessage(command);
- msg.obj = url;
- mHandler.sendMessage(msg);
- waitForPageLoad();
- }
- }
- }
-
- /**
- * Converts the arguments passed to a JavaScript friendly format.
- *
- * @param args The arguments to convert.
- * @return Comma separated Strings containing the arguments.
- */
- /* package */ String convertToJsArgs(final Object... args) {
- StringBuilder toReturn = new StringBuilder();
- int length = args.length;
- for (int i = 0; i < length; i++) {
- toReturn.append((i > 0) ? "," : "");
- if (args[i] instanceof List<?>) {
- toReturn.append("[");
- List<Object> aList = (List<Object>) args[i];
- for (int j = 0 ; j < aList.size(); j++) {
- String comma = ((j == 0) ? "" : ",");
- toReturn.append(comma + convertToJsArgs(aList.get(j)));
- }
- toReturn.append("]");
- } else if (args[i] instanceof Map<?, ?>) {
- Map<Object, Object> aMap = (Map<Object, Object>) args[i];
- String toAdd = "{";
- for (Object key: aMap.keySet()) {
- toAdd += key + ":"
- + convertToJsArgs(aMap.get(key)) + ",";
- }
- toReturn.append(toAdd.substring(0, toAdd.length() -1) + "}");
- } else if (args[i] instanceof WebElement) {
- // WebElement are represented in JavaScript by Objects as
- // follow: {ELEMENT:"id"} where "id" refers to the id
- // of the HTML element in the javascript cache that can
- // be accessed throught bot.inject.cache.getCache_()
- toReturn.append("{\"" + ELEMENT_KEY + "\":\""
- + ((WebElement) args[i]).getId() + "\"}");
- } else if (args[i] instanceof Number || args[i] instanceof Boolean) {
- toReturn.append(String.valueOf(args[i]));
- } else if (args[i] instanceof String) {
- toReturn.append(escapeAndQuote((String) args[i]));
- } else {
- throw new IllegalArgumentException(
- "Javascript arguments can be "
- + "a Number, a Boolean, a String, a WebElement, "
- + "or a List or a Map of those. Got: "
- + ((args[i] == null) ? "null" : args[i].getClass()
- + ", value: " + args[i].toString()));
- }
- }
- return toReturn.toString();
- }
-
- /* package */ Object executeRawJavascript(final String script) {
- if (mWebView.getUrl() == null) {
- throw new WebDriverException("Cannot operate on a blank page. "
- + "Load a page using WebDriver.get().");
- }
- String result = executeCommand(CMD_EXECUTE_SCRIPT,
- "if (!window.webdriver || !window.webdriver.resultReady) {" +
- " return;" +
- "}" +
- "window.webdriver.resultReady(" + script + ")",
- JS_EXECUTION_TIMEOUT);
- if (result == null || "undefined".equals(result)) {
- return null;
- }
- try {
- JSONObject json = new JSONObject(result);
- throwIfError(json);
- Object value = json.get(VALUE);
- return convertJsonToJavaObject(value);
- } catch (JSONException e) {
- throw new RuntimeException("Failed to parse JavaScript result: "
- + result.toString(), e);
- }
- }
-
- /* package */ String getResourceAsString(final int resourceId) {
- InputStream is = mWebView.getResources().openRawResource(resourceId);
- BufferedReader br = new BufferedReader(new InputStreamReader(is));
- StringBuilder sb = new StringBuilder();
- String line = null;
- try {
- while ((line = br.readLine()) != null) {
- sb.append(line);
- }
- br.close();
- is.close();
- } catch (IOException e) {
- throw new RuntimeException("Failed to open JavaScript resource.", e);
- }
- return sb.toString();
- }
-
- /* package */ void sendTouchScreen(Point coords) {
- // Reset state
- resetPageLoadState();
- executeCommand(CMD_SEND_TOUCH, coords,LOADING_TIMEOUT);
- // Wait for the events to be fully handled
- waitForMessageRelay(MOTION_EVENT_TIMEOUT);
-
- // If a page started loading, block until page finishes loading
- waitForPageLoadIfNeeded();
- }
-
- /* package */ void resetPageLoadState() {
- synchronized (mSyncPageLoad) {
- mPageStartedLoading = false;
- mPageFinishedLoading = false;
- }
- }
-
- /* package */ void waitForPageLoadIfNeeded() {
- synchronized (mSyncPageLoad) {
- Long end = System.currentTimeMillis() + PAGE_STARTED_LOADING;
- // Wait PAGE_STARTED_LOADING milliseconds to see if we detect a
- // page load.
- while (!mPageStartedLoading && (System.currentTimeMillis() <= end)) {
- try {
- // This is notified by WebChromeClientWrapper#onProgressChanged
- // when the page finished loading.
- mSyncPageLoad.wait(PAGE_STARTED_LOADING);
- } catch (InterruptedException e) {
- new RuntimeException(e);
- }
- }
- if (mPageStartedLoading) {
- waitForPageLoad();
- }
- }
- }
-
- private void touchScreen(Point coords) {
- // Convert to screen coords
- // screen = JS x zoom - offset
- float zoom = mWebView.getScale();
- float xOffset = mWebView.getX();
- float yOffset = mWebView.getY();
- Point screenCoords = new Point( (int)(coords.x*zoom - xOffset),
- (int)(coords.y*zoom - yOffset));
-
- long downTime = SystemClock.uptimeMillis();
- MotionEvent down = MotionEvent.obtain(downTime,
- SystemClock.uptimeMillis(), MotionEvent.ACTION_DOWN, screenCoords.x,
- screenCoords.y, 0);
- down.setSource(InputDevice.SOURCE_TOUCHSCREEN);
- MotionEvent up = MotionEvent.obtain(downTime,
- SystemClock.uptimeMillis(), MotionEvent.ACTION_UP, screenCoords.x,
- screenCoords.y, 0);
- up.setSource(InputDevice.SOURCE_TOUCHSCREEN);
- // Dispatch the events to WebView
- mWebView.dispatchTouchEvent(down);
- mWebView.dispatchTouchEvent(up);
- }
-
- /* package */ void notifyPageStartedLoading() {
- synchronized (mSyncPageLoad) {
- mPageStartedLoading = true;
- mSyncPageLoad.notify();
- }
- }
-
- /* package */ void notifyPageFinishedLoading() {
- synchronized (mSyncPageLoad) {
- mPageFinishedLoading = true;
- mSyncPageLoad.notify();
- }
- }
-
- /**
- *
- * @param keys The first element of the CharSequence should be the
- * existing value in the text input, or the empty string if none.
- */
- /* package */ void sendKeys(CharSequence[] keys) {
- executeCommand(CMD_SEND_KEYS, keys, KEY_EVENT_TIMEOUT);
- // Wait for all KeyEvents to be handled
- waitForMessageRelay(KEY_EVENT_TIMEOUT);
- }
-
- /* package */ void sendKeyCodes(int[] keycodes) {
- executeCommand(CMD_SEND_KEYCODE, keycodes, KEY_EVENT_TIMEOUT);
- // Wait for all KeyEvents to be handled
- waitForMessageRelay(KEY_EVENT_TIMEOUT);
- }
-
- /* package */ void moveCursorToRightMostPosition(String value) {
- executeCommand(CMD_MOVE_CURSOR_RIGHTMOST_POS, value, KEY_EVENT_TIMEOUT);
- waitForMessageRelay(KEY_EVENT_TIMEOUT);
- }
-
- private void moveCursorToLeftMostPos(String value) {
- // If there is text, move the cursor to the rightmost position
- if (value != null && !value.equals("")) {
- long downTime = SystemClock.uptimeMillis();
- KeyEvent down = new KeyEvent(downTime, SystemClock.uptimeMillis(),
- KeyEvent.ACTION_DOWN, KeyEvent.KEYCODE_DPAD_RIGHT, 0);
- KeyEvent up = new KeyEvent(downTime, SystemClock.uptimeMillis(),
- KeyEvent.ACTION_UP, KeyEvent.KEYCODE_DPAD_RIGHT,
- value.length());
- mWebView.dispatchKeyEvent(down);
- mWebView.dispatchKeyEvent(up);
- }
- }
-
- private void dispatchKeyCodes(int[] keycodes) {
- for (int i = 0; i < keycodes.length; i++) {
- KeyEvent down = new KeyEvent(KeyEvent.ACTION_DOWN, keycodes[i]);
- KeyEvent up = new KeyEvent(KeyEvent.ACTION_UP, keycodes[i]);
- mWebView.dispatchKeyEvent(down);
- mWebView.dispatchKeyEvent(up);
- }
- }
-
- private void dispatchKeys(CharSequence[] keys) {
- KeyCharacterMap chararcterMap = KeyCharacterMap.load(
- KeyCharacterMap.VIRTUAL_KEYBOARD);
- for (int i = 0; i < keys.length; i++) {
- CharSequence s = keys[i];
- for (int j = 0; j < s.length(); j++) {
- KeyEvent[] events =
- chararcterMap.getEvents(new char[]{s.charAt(j)});
- for (KeyEvent e : events) {
- mWebView.dispatchKeyEvent(e);
- }
- }
- }
- }
-
- private void waitForMessageRelay(long timeout) {
- synchronized (mSyncObject) {
- mCommandDone = false;
- }
- Message msg = Message.obtain();
- msg.what = WebViewCore.EventHub.MESSAGE_RELAY;
- Message echo = mHandler.obtainMessage(CMD_MESSAGE_RELAY_ECHO);
- msg.obj = echo;
-
- mWebView.getWebViewCore().sendMessage(msg);
- synchronized (mSyncObject) {
- long end = System.currentTimeMillis() + timeout;
- while (!mCommandDone && (System.currentTimeMillis() <= end)) {
- try {
- // This is notifed by the mHandler when it receives the
- // MESSAGE_RELAY back
- mSyncObject.wait(timeout);
- } catch (InterruptedException e) {
- throw new RuntimeException(e);
- }
- }
- }
- }
-
- private void waitForPageLoad() {
- long endLoad = System.currentTimeMillis() + LOADING_TIMEOUT;
- while (!mPageFinishedLoading
- && (System.currentTimeMillis() <= endLoad)) {
- try {
- mSyncPageLoad.wait(LOADING_TIMEOUT);
- } catch (InterruptedException e) {
- throw new RuntimeException();
- }
- }
- }
-
- /**
- * Wraps the given string into quotes and escape existing quotes
- * and backslashes.
- * "foo" -> "\"foo\""
- * "foo\"" -> "\"foo\\\"\""
- * "fo\o" -> "\"fo\\o\""
- *
- * @param toWrap The String to wrap in quotes
- * @return a String wrapping the original String in quotes
- */
- private static String escapeAndQuote(final String toWrap) {
- StringBuilder toReturn = new StringBuilder("\"");
- for (int i = 0; i < toWrap.length(); i++) {
- char c = toWrap.charAt(i);
- if (c == '\"') {
- toReturn.append("\\\"");
- } else if (c == '\\') {
- toReturn.append("\\\\");
- } else {
- toReturn.append(c);
- }
- }
- toReturn.append("\"");
- return toReturn.toString();
- }
-
- private Object convertJsonToJavaObject(final Object toConvert) {
- try {
- if (toConvert == null
- || toConvert.equals(null)
- || "undefined".equals(toConvert)
- || "null".equals(toConvert)) {
- return null;
- } else if (toConvert instanceof Boolean) {
- return toConvert;
- } else if (toConvert instanceof Double
- || toConvert instanceof Float) {
- return Double.valueOf(String.valueOf(toConvert));
- } else if (toConvert instanceof Integer
- || toConvert instanceof Long) {
- return Long.valueOf(String.valueOf(toConvert));
- } else if (toConvert instanceof JSONArray) { // List
- return convertJsonArrayToList((JSONArray) toConvert);
- } else if (toConvert instanceof JSONObject) { // Map or WebElment
- JSONObject map = (JSONObject) toConvert;
- if (map.opt(ELEMENT_KEY) != null) { // WebElement
- return new WebElement(this, (String) map.get(ELEMENT_KEY));
- } else { // Map
- return convertJsonObjectToMap(map);
- }
- } else {
- return toConvert.toString();
- }
- } catch (JSONException e) {
- throw new RuntimeException("Failed to parse JavaScript result: "
- + toConvert.toString(), e);
- }
- }
-
- private List<Object> convertJsonArrayToList(final JSONArray json) {
- List<Object> toReturn = Lists.newArrayList();
- for (int i = 0; i < json.length(); i++) {
- try {
- toReturn.add(convertJsonToJavaObject(json.get(i)));
- } catch (JSONException e) {
- throw new RuntimeException("Failed to parse JSON: "
- + json.toString(), e);
- }
- }
- return toReturn;
- }
-
- private Map<Object, Object> convertJsonObjectToMap(final JSONObject json) {
- Map<Object, Object> toReturn = Maps.newHashMap();
- for (Iterator it = json.keys(); it.hasNext();) {
- String key = (String) it.next();
- try {
- Object value = json.get(key);
- toReturn.put(convertJsonToJavaObject(key),
- convertJsonToJavaObject(value));
- } catch (JSONException e) {
- throw new RuntimeException("Failed to parse JSON:"
- + json.toString(), e);
- }
- }
- return toReturn;
- }
-
- private void throwIfError(final JSONObject jsonObject) {
- ErrorCode status;
- String errorMsg;
- try {
- status = ErrorCode.get((Integer) jsonObject.get(STATUS));
- errorMsg = String.valueOf(jsonObject.get(VALUE));
- } catch (JSONException e) {
- throw new RuntimeException("Failed to parse JSON Object: "
- + jsonObject, e);
- }
- switch (status) {
- case SUCCESS:
- return;
- case NO_SUCH_ELEMENT:
- throw new WebElementNotFoundException("Could not find "
- + "WebElement.");
- case STALE_ELEMENT_REFERENCE:
- throw new WebElementStaleException("WebElement is stale.");
- default:
- throw new WebDriverException("Error: " + errorMsg);
- }
- }
-
- private void shouldRunInMainThread(boolean value) {
- assert (value == (MAIN_THREAD == Thread.currentThread().getId()));
- }
-
- /**
- * Interface called from JavaScript when the result is ready.
- */
- private class JavascriptResultReady {
-
- /**
- * A callback from JavaScript to Java that passes the result as a
- * parameter. This method is available from the WebView's
- * JavaScript DOM as window.webdriver.resultReady().
- *
- * @param result The result that should be sent to Java from Javascript.
- */
- public void resultReady(final String result) {
- synchronized (mSyncObject) {
- mJsResult = result;
- mCommandDone = true;
- mSyncObject.notify();
- }
- }
- }
-
- /* package */ void notifyCommandDone() {
- synchronized (mSyncObject) {
- mCommandDone = true;
- mSyncObject.notify();
- }
- }
-
- /**
- * Executes the given command by posting a message to mHandler. This thread
- * will block until the command which runs in the main thread is done.
- *
- * @param command The command to run.
- * @param arg The argument for that command.
- * @param timeout A timeout in milliseconds.
- */
- private String executeCommand(int command, final Object arg, long timeout) {
- shouldRunInMainThread(false);
- synchronized (mSyncObject) {
- mCommandDone = false;
- Message msg = mHandler.obtainMessage(command);
- msg.obj = arg;
- mHandler.sendMessage(msg);
-
- long end = System.currentTimeMillis() + timeout;
- while (!mCommandDone) {
- if (System.currentTimeMillis() >= end) {
- throw new RuntimeException("Timeout executing command: "
- + command);
- }
- try {
- mSyncObject.wait(timeout);
- } catch (InterruptedException e) {
- throw new RuntimeException(e);
- }
- }
- }
- return mJsResult;
- }
-
- private void checkNotNull(Object obj, String errosMsg) {
- if (obj == null) {
- throw new NullPointerException(errosMsg);
- }
- }
-}
diff --git a/core/java/android/webkit/webdriver/WebDriverException.java b/core/java/android/webkit/webdriver/WebDriverException.java
deleted file mode 100644
index 1a579c297481..000000000000
--- a/core/java/android/webkit/webdriver/WebDriverException.java
+++ /dev/null
@@ -1,38 +0,0 @@
-/*
- * Copyright (C) 2011 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package android.webkit.webdriver;
-
-/**
- * @hide
- */
-public class WebDriverException extends RuntimeException {
- public WebDriverException() {
- super();
- }
-
- public WebDriverException(String reason) {
- super(reason);
- }
-
- public WebDriverException(String reason, Throwable cause) {
- super(reason, cause);
- }
-
- public WebDriverException(Throwable cause) {
- super(cause);
- }
-}
diff --git a/core/java/android/webkit/webdriver/WebElement.java b/core/java/android/webkit/webdriver/WebElement.java
deleted file mode 100644
index 02c1595238ad..000000000000
--- a/core/java/android/webkit/webdriver/WebElement.java
+++ /dev/null
@@ -1,388 +0,0 @@
-/*
- * Copyright (C) 2011 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package android.webkit.webdriver;
-
-import android.graphics.Point;
-import android.view.KeyEvent;
-
-import com.android.internal.R;
-
-import java.util.List;
-import java.util.Map;
-
-/**
- * Represents an HTML element. Typically most interactions with a web page
- * will be performed through this class.
- *
- * @hide
- */
-public class WebElement {
- private final String mId;
- private final WebDriver mDriver;
-
- private static final String LOCATOR_ID = "id";
- private static final String LOCATOR_LINK_TEXT = "linkText";
- private static final String LOCATOR_PARTIAL_LINK_TEXT = "partialLinkText";
- private static final String LOCATOR_NAME = "name";
- private static final String LOCATOR_CLASS_NAME = "className";
- private static final String LOCATOR_CSS = "css";
- private static final String LOCATOR_TAG_NAME = "tagName";
- private static final String LOCATOR_XPATH = "xpath";
-
- /**
- * Package constructor to prevent clients from creating a new WebElement
- * instance.
- *
- * <p> A WebElement represents an HTML element on the page.
- * The corresponding HTML element is stored in a JS cache in the page
- * that can be accessed through JavaScript using "bot.inject.cache".
- *
- * @param driver The WebDriver instance to use.
- * @param id The index of the HTML element in the JavaSctipt cache.
- * document.documentElement object.
- */
- /* package */ WebElement(final WebDriver driver, final String id) {
- this.mId = id;
- this.mDriver = driver;
- }
-
- /**
- * Finds the first {@link android.webkit.webdriver.WebElement} using the
- * given method.
- *
- * @param by The locating mechanism to use.
- * @return The first matching element on the current context.
- */
- public WebElement findElement(final By by) {
- return by.findElement(this);
- }
-
- /**
- * Finds all {@link android.webkit.webdriver.WebElement} within the page
- * using the given method.
- *
- * @param by The locating mechanism to use.
- * @return A list of all {@link android.webkit.webdriver.WebElement} found,
- * or an empty list if nothing matches.
- */
- public List<WebElement> findElements(final By by) {
- return by.findElements(this);
- }
-
- /**
- * Gets the visisble (i.e. not hidden by CSS) innerText of this element,
- * inlcuding sub-elements.
- *
- * @return the innerText of this element.
- * @throws {@link android.webkit.webdriver.WebElementStaleException} if this
- * element is stale, i.e. not on the current DOM.
- */
- public String getText() {
- String getText = mDriver.getResourceAsString(R.raw.get_text_android);
- return (String) executeAtom(getText, this);
- }
-
- /**
- * Gets the value of an HTML attribute for this element or the value of the
- * property with the same name if the attribute is not present. If neither
- * is set, null is returned.
- *
- * @param attribute the HTML attribute.
- * @return the value of that attribute or the value of the property with the
- * same name if the attribute is not set, or null if neither are set. For
- * boolean attribute values this will return the string "true" or "false".
- */
- public String getAttribute(String attribute) {
- String getAttribute = mDriver.getResourceAsString(
- R.raw.get_attribute_value_android);
- return (String) executeAtom(getAttribute, this, attribute);
- }
-
- /**
- * @return the tag name of this element.
- */
- public String getTagName() {
- return (String) mDriver.executeScript("return arguments[0].tagName;",
- this);
- }
-
- /**
- * @return true if this element is enabled, false otherwise.
- */
- public boolean isEnabled() {
- String isEnabled = mDriver.getResourceAsString(
- R.raw.is_enabled_android);
- return (Boolean) executeAtom(isEnabled, this);
- }
-
- /**
- * Determines whether this element is selected or not. This applies to input
- * elements such as checkboxes, options in a select, and radio buttons.
- *
- * @return True if this element is selected, false otherwise.
- */
- public boolean isSelected() {
- String isSelected = mDriver.getResourceAsString(
- R.raw.is_selected_android);
- return (Boolean) executeAtom(isSelected, this);
- }
-
- /**
- * Selects an element on the page. This works for selecting checkboxes,
- * options in a select, and radio buttons.
- */
- public void setSelected() {
- String setSelected = mDriver.getResourceAsString(
- R.raw.set_selected_android);
- executeAtom(setSelected, this);
- }
-
- /**
- * This toggles the checkboxe state from selected to not selected, or
- * from not selected to selected.
- *
- * @return True if the toggled element is selected, false otherwise.
- */
- public boolean toggle() {
- String toggle = mDriver.getResourceAsString(R.raw.toggle_android);
- return (Boolean) executeAtom(toggle, this);
- }
-
- /**
- * Sends the KeyEvents for the given sequence of characters to the
- * WebElement to simulate typing. The KeyEvents are generated using the
- * device's {@link android.view.KeyCharacterMap.VIRTUAL_KEYBOARD}.
- *
- * @param keys The keys to send to this WebElement
- */
- public void sendKeys(CharSequence... keys) {
- if (keys == null || keys.length == 0) {
- return;
- }
- click();
- mDriver.moveCursorToRightMostPosition(getAttribute("value"));
- mDriver.sendKeys(keys);
- }
-
- /**
- * Use this to send one of the key code constants defined in
- * {@link android.view.KeyEvent}
- *
- * @param keys
- */
- public void sendKeyCodes(int... keys) {
- if (keys == null || keys.length == 0) {
- return;
- }
- click();
- mDriver.moveCursorToRightMostPosition(getAttribute("value"));
- mDriver.sendKeyCodes(keys);
- }
-
- /**
- * Sends a touch event to the center coordinates of this WebElement.
- */
- public void click() {
- Point topLeft = getLocation();
- Point size = getSize();
- int jsX = topLeft.x + size.x/2;
- int jsY = topLeft.y + size.y/2;
- Point center = new Point(jsX, jsY);
- mDriver.sendTouchScreen(center);
- }
-
- /**
- * Submits the form containing this WebElement.
- */
- public void submit() {
- mDriver.resetPageLoadState();
- String submit = mDriver.getResourceAsString(R.raw.submit_android);
- executeAtom(submit, this);
- mDriver.waitForPageLoadIfNeeded();
- }
-
- /**
- * Clears the text value if this is a text entry element. Does nothing
- * otherwise.
- */
- public void clear() {
- String value = getAttribute("value");
- if (value == null || value.equals("")) {
- return;
- }
- int length = value.length();
- int[] keys = new int[length];
- for (int i = 0; i < length; i++) {
- keys[i] = KeyEvent.KEYCODE_DEL;
- }
- sendKeyCodes(keys);
- }
-
- /**
- * @return the value of the given CSS property if found, null otherwise.
- */
- public String getCssValue(String cssProperty) {
- String getCssProp = mDriver.getResourceAsString(
- R.raw.get_value_of_css_property_android);
- return (String) executeAtom(getCssProp, this, cssProperty);
- }
-
- /**
- * Gets the width and height of the rendered element.
- *
- * @return a {@link android.graphics.Point}, where Point.x represents the
- * width, and Point.y represents the height of the element.
- */
- public Point getSize() {
- String getSize = mDriver.getResourceAsString(R.raw.get_size_android);
- Map<String, Long> map = (Map<String, Long>) executeAtom(getSize, this);
- return new Point(map.get("width").intValue(),
- map.get("height").intValue());
- }
-
- /**
- * Gets the location of the top left corner of this element on the screen.
- * If the element is not visisble, this will scroll to get the element into
- * the visisble screen.
- *
- * @return a {@link android.graphics.Point} containing the x and y
- * coordinates of the top left corner of this element.
- */
- public Point getLocation() {
- String getLocation = mDriver.getResourceAsString(
- R.raw.get_top_left_coordinates_android);
- Map<String,Long> map = (Map<String, Long>) executeAtom(getLocation,
- this);
- return new Point(map.get("x").intValue(), map.get("y").intValue());
- }
-
- /**
- * @return True if the WebElement is displayed on the screen,
- * false otherwise.
- */
- public boolean isDisplayed() {
- String isDisplayed = mDriver.getResourceAsString(
- R.raw.is_displayed_android);
- return (Boolean) executeAtom(isDisplayed, this);
- }
-
- /*package*/ String getId() {
- return mId;
- }
-
- /* package */ WebElement findElementById(final String locator) {
- return findElement(LOCATOR_ID, locator);
- }
-
- /* package */ WebElement findElementByLinkText(final String linkText) {
- return findElement(LOCATOR_LINK_TEXT, linkText);
- }
-
- /* package */ WebElement findElementByPartialLinkText(
- final String linkText) {
- return findElement(LOCATOR_PARTIAL_LINK_TEXT, linkText);
- }
-
- /* package */ WebElement findElementByName(final String name) {
- return findElement(LOCATOR_NAME, name);
- }
-
- /* package */ WebElement findElementByClassName(final String className) {
- return findElement(LOCATOR_CLASS_NAME, className);
- }
-
- /* package */ WebElement findElementByCss(final String css) {
- return findElement(LOCATOR_CSS, css);
- }
-
- /* package */ WebElement findElementByTagName(final String tagName) {
- return findElement(LOCATOR_TAG_NAME, tagName);
- }
-
- /* package */ WebElement findElementByXPath(final String xpath) {
- return findElement(LOCATOR_XPATH, xpath);
- }
-
- /* package */ List<WebElement> findElementsById(final String locator) {
- return findElements(LOCATOR_ID, locator);
- }
-
- /* package */ List<WebElement> findElementsByLinkText(final String linkText) {
- return findElements(LOCATOR_LINK_TEXT, linkText);
- }
-
- /* package */ List<WebElement> findElementsByPartialLinkText(
- final String linkText) {
- return findElements(LOCATOR_PARTIAL_LINK_TEXT, linkText);
- }
-
- /* package */ List<WebElement> findElementsByName(final String name) {
- return findElements(LOCATOR_NAME, name);
- }
-
- /* package */ List<WebElement> findElementsByClassName(final String className) {
- return findElements(LOCATOR_CLASS_NAME, className);
- }
-
- /* package */ List<WebElement> findElementsByCss(final String css) {
- return findElements(LOCATOR_CSS, css);
- }
-
- /* package */ List<WebElement> findElementsByTagName(final String tagName) {
- return findElements(LOCATOR_TAG_NAME, tagName);
- }
-
- /* package */ List<WebElement> findElementsByXPath(final String xpath) {
- return findElements(LOCATOR_XPATH, xpath);
- }
-
- private Object executeAtom(final String atom, final Object... args) {
- String scriptArgs = mDriver.convertToJsArgs(args);
- return mDriver.executeRawJavascript("(" +
- atom + ")(" + scriptArgs + ")");
- }
-
- private List<WebElement> findElements(String strategy, String locator) {
- String findElements = mDriver.getResourceAsString(
- R.raw.find_elements_android);
- if (mId.equals("")) {
- return (List<WebElement>) executeAtom(findElements,
- strategy, locator);
- } else {
- return (List<WebElement>) executeAtom(findElements,
- strategy, locator, this);
- }
- }
-
- private WebElement findElement(String strategy, String locator) {
- String findElement = mDriver.getResourceAsString(
- R.raw.find_element_android);
- WebElement el;
- if (mId.equals("")) {
- el = (WebElement) executeAtom(findElement,
- strategy, locator);
- } else {
- el = (WebElement) executeAtom(findElement,
- strategy, locator, this);
- }
- if (el == null) {
- throw new WebElementNotFoundException("Could not find element "
- + "with " + strategy + ": " + locator);
- }
- return el;
- }
-}
diff --git a/core/java/android/webkit/webdriver/WebElementNotFoundException.java b/core/java/android/webkit/webdriver/WebElementNotFoundException.java
deleted file mode 100644
index e66d279f0a04..000000000000
--- a/core/java/android/webkit/webdriver/WebElementNotFoundException.java
+++ /dev/null
@@ -1,41 +0,0 @@
-/*
- * Copyright (C) 2011 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package android.webkit.webdriver;
-
-/**
- * Thrown when a {@link android.webkit.webdriver.WebElement} is not found in the
- * DOM of the page.
- * @hide
- */
-public class WebElementNotFoundException extends RuntimeException {
-
- public WebElementNotFoundException() {
- super();
- }
-
- public WebElementNotFoundException(String reason) {
- super(reason);
- }
-
- public WebElementNotFoundException(String reason, Throwable cause) {
- super(reason, cause);
- }
-
- public WebElementNotFoundException(Throwable cause) {
- super(cause);
- }
-}
diff --git a/core/java/android/webkit/webdriver/WebElementStaleException.java b/core/java/android/webkit/webdriver/WebElementStaleException.java
deleted file mode 100644
index c59e7945b4fa..000000000000
--- a/core/java/android/webkit/webdriver/WebElementStaleException.java
+++ /dev/null
@@ -1,42 +0,0 @@
-/*
- * Copyright (C) 2011 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package android.webkit.webdriver;
-
-/**
- * Thrown when trying to access a {@link android.webkit.webdriver.WebElement}
- * that is stale. This mean that the {@link android.webkit.webdriver.WebElement}
- * is no longer present on the DOM of the page.
- * @hide
- */
-public class WebElementStaleException extends RuntimeException {
-
- public WebElementStaleException() {
- super();
- }
-
- public WebElementStaleException(String reason) {
- super(reason);
- }
-
- public WebElementStaleException(String reason, Throwable cause) {
- super(reason, cause);
- }
-
- public WebElementStaleException(Throwable cause) {
- super(cause);
- }
-}
diff --git a/core/java/android/webkit/webdriver/WebViewClient.java b/core/java/android/webkit/webdriver/WebViewClient.java
deleted file mode 100644
index c582b24f4953..000000000000
--- a/core/java/android/webkit/webdriver/WebViewClient.java
+++ /dev/null
@@ -1,125 +0,0 @@
-/*
- * Copyright (C) 2011 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package android.webkit.webdriver;
-
-import android.graphics.Bitmap;
-import android.net.http.SslError;
-import android.os.Message;
-import android.view.KeyEvent;
-import android.webkit.HttpAuthHandler;
-import android.webkit.SslErrorHandler;
-import android.webkit.WebResourceResponse;
-import android.webkit.WebView;
-import android.webkit.WebViewClient;
-
-/* package */ class WebViewClientWrapper extends WebViewClient {
- private final WebViewClient mDelegate;
- private final WebDriver mDriver;
-
- public WebViewClientWrapper(WebViewClient delegate, WebDriver driver) {
- if (delegate == null) {
- mDelegate = new WebViewClient();
- } else {
- mDelegate = delegate;
- }
- this.mDriver = driver;
- }
-
- @Override
- public boolean shouldOverrideUrlLoading(WebView view, String url) {
- return mDelegate.shouldOverrideUrlLoading(view, url);
- }
-
- @Override
- public void onPageStarted(WebView view, String url, Bitmap favicon) {
- mDriver.notifyPageStartedLoading();
- mDelegate.onPageStarted(view, url, favicon);
- }
-
- @Override
- public void onPageFinished(WebView view, String url) {
- mDelegate.onPageFinished(view, url);
- }
-
- @Override
- public void onLoadResource(WebView view, String url) {
- mDelegate.onLoadResource(view, url);
- }
-
- @Override
- public WebResourceResponse shouldInterceptRequest(WebView view,
- String url) {
- return mDelegate.shouldInterceptRequest(view, url);
- }
-
- @Override
- public void onTooManyRedirects(WebView view, Message cancelMsg,
- Message continueMsg) {
- mDelegate.onTooManyRedirects(view, cancelMsg, continueMsg);
- }
-
- @Override
- public void onReceivedError(WebView view, int errorCode, String description,
- String failingUrl) {
- mDelegate.onReceivedError(view, errorCode, description, failingUrl);
- }
-
- @Override
- public void onFormResubmission(WebView view, Message dontResend,
- Message resend) {
- mDelegate.onFormResubmission(view, dontResend, resend);
- }
-
- @Override
- public void doUpdateVisitedHistory(WebView view, String url,
- boolean isReload) {
- mDelegate.doUpdateVisitedHistory(view, url, isReload);
- }
-
- @Override
- public void onReceivedSslError(WebView view, SslErrorHandler handler,
- SslError error) {
- mDelegate.onReceivedSslError(view, handler, error);
- }
-
- @Override
- public void onReceivedHttpAuthRequest(WebView view, HttpAuthHandler handler,
- String host, String realm) {
- mDelegate.onReceivedHttpAuthRequest(view, handler, host, realm);
- }
-
- @Override
- public boolean shouldOverrideKeyEvent(WebView view, KeyEvent event) {
- return mDelegate.shouldOverrideKeyEvent(view, event);
- }
-
- @Override
- public void onUnhandledKeyEvent(WebView view, KeyEvent event) {
- mDelegate.onUnhandledKeyEvent(view, event);
- }
-
- @Override
- public void onScaleChanged(WebView view, float oldScale, float newScale) {
- mDelegate.onScaleChanged(view, oldScale, newScale);
- }
-
- @Override
- public void onReceivedLoginRequest(WebView view, String realm,
- String account, String args) {
- mDelegate.onReceivedLoginRequest(view, realm, account, args);
- }
-}
diff --git a/core/java/android/webkit/webdriver/WebchromeClientWrapper.java b/core/java/android/webkit/webdriver/WebchromeClientWrapper.java
deleted file mode 100644
index a9e5d19b605d..000000000000
--- a/core/java/android/webkit/webdriver/WebchromeClientWrapper.java
+++ /dev/null
@@ -1,193 +0,0 @@
-/*
- * Copyright (C) 2011 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package android.webkit.webdriver;
-
-import android.graphics.Bitmap;
-import android.net.Uri;
-import android.os.Message;
-import android.view.View;
-import android.webkit.ConsoleMessage;
-import android.webkit.GeolocationPermissions;
-import android.webkit.JsPromptResult;
-import android.webkit.JsResult;
-import android.webkit.ValueCallback;
-import android.webkit.WebChromeClient;
-import android.webkit.WebStorage;
-import android.webkit.WebView;
-
-/* package */ class WebChromeClientWrapper extends WebChromeClient {
-
- private final WebChromeClient mDelegate;
- private final WebDriver mDriver;
-
- public WebChromeClientWrapper(WebChromeClient delegate, WebDriver driver) {
- if (delegate == null) {
- this.mDelegate = new WebChromeClient();
- } else {
- this.mDelegate = delegate;
- }
- this.mDriver = driver;
- }
-
- @Override
- public void onProgressChanged(WebView view, int newProgress) {
- if (newProgress == 100) {
- mDriver.notifyPageFinishedLoading();
- }
- mDelegate.onProgressChanged(view, newProgress);
- }
-
- @Override
- public void onReceivedTitle(WebView view, String title) {
- mDelegate.onReceivedTitle(view, title);
- }
-
- @Override
- public void onReceivedIcon(WebView view, Bitmap icon) {
- mDelegate.onReceivedIcon(view, icon);
- }
-
- @Override
- public void onReceivedTouchIconUrl(WebView view, String url,
- boolean precomposed) {
- mDelegate.onReceivedTouchIconUrl(view, url, precomposed);
- }
-
- @Override
- public void onShowCustomView(View view,
- CustomViewCallback callback) {
- mDelegate.onShowCustomView(view, callback);
- }
-
- @Override
- public void onHideCustomView() {
- mDelegate.onHideCustomView();
- }
-
- @Override
- public boolean onCreateWindow(WebView view, boolean dialog,
- boolean userGesture, Message resultMsg) {
- return mDelegate.onCreateWindow(view, dialog, userGesture, resultMsg);
- }
-
- @Override
- public void onRequestFocus(WebView view) {
- mDelegate.onRequestFocus(view);
- }
-
- @Override
- public void onCloseWindow(WebView window) {
- mDelegate.onCloseWindow(window);
- }
-
- @Override
- public boolean onJsAlert(WebView view, String url, String message,
- JsResult result) {
- return mDelegate.onJsAlert(view, url, message, result);
- }
-
- @Override
- public boolean onJsConfirm(WebView view, String url, String message,
- JsResult result) {
- return mDelegate.onJsConfirm(view, url, message, result);
- }
-
- @Override
- public boolean onJsPrompt(WebView view, String url, String message,
- String defaultValue, JsPromptResult result) {
- return mDelegate.onJsPrompt(view, url, message, defaultValue, result);
- }
-
- @Override
- public boolean onJsBeforeUnload(WebView view, String url, String message,
- JsResult result) {
- return mDelegate.onJsBeforeUnload(view, url, message, result);
- }
-
- @Override
- public void onExceededDatabaseQuota(String url, String databaseIdentifier,
- long currentQuota, long estimatedSize, long totalUsedQuota,
- WebStorage.QuotaUpdater quotaUpdater) {
- mDelegate.onExceededDatabaseQuota(url, databaseIdentifier, currentQuota,
- estimatedSize, totalUsedQuota, quotaUpdater);
- }
-
- @Override
- public void onReachedMaxAppCacheSize(long spaceNeeded, long totalUsedQuota,
- WebStorage.QuotaUpdater quotaUpdater) {
- mDelegate.onReachedMaxAppCacheSize(spaceNeeded, totalUsedQuota,
- quotaUpdater);
- }
-
- @Override
- public void onGeolocationPermissionsShowPrompt(String origin,
- GeolocationPermissions.Callback callback) {
- mDelegate.onGeolocationPermissionsShowPrompt(origin, callback);
- }
-
- @Override
- public void onGeolocationPermissionsHidePrompt() {
- mDelegate.onGeolocationPermissionsHidePrompt();
- }
-
- @Override
- public boolean onJsTimeout() {
- return mDelegate.onJsTimeout();
- }
-
- @Override
- public void onConsoleMessage(String message, int lineNumber,
- String sourceID) {
- mDelegate.onConsoleMessage(message, lineNumber, sourceID);
- }
-
- @Override
- public boolean onConsoleMessage(ConsoleMessage consoleMessage) {
- return mDelegate.onConsoleMessage(consoleMessage);
- }
-
- @Override
- public Bitmap getDefaultVideoPoster() {
- return mDelegate.getDefaultVideoPoster();
- }
-
- @Override
- public View getVideoLoadingProgressView() {
- return mDelegate.getVideoLoadingProgressView();
- }
-
- @Override
- public void getVisitedHistory(ValueCallback<String[]> callback) {
- mDelegate.getVisitedHistory(callback);
- }
-
- @Override
- public void openFileChooser(ValueCallback<Uri> uploadFile,
- String acceptType) {
- mDelegate.openFileChooser(uploadFile, acceptType);
- }
-
- @Override
- public void setInstallableWebApp() {
- mDelegate.setInstallableWebApp();
- }
-
- @Override
- public void setupAutoFill(Message msg) {
- mDelegate.setupAutoFill(msg);
- }
-}