Skip to content

Commit

Permalink
DouniaBerrada: Android WebDriver is now as fast as desktop browsers! …
Browse files Browse the repository at this point in the history
…Moved Jetty from its own process to the ui process. There are no guarantee that this will work prior to froyo.

r11716
  • Loading branch information
Dounia Berrada committed Mar 18, 2011
1 parent aac8bd6 commit 923d8fd
Show file tree
Hide file tree
Showing 20 changed files with 594 additions and 711 deletions.
5 changes: 2 additions & 3 deletions android/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,7 @@ limitations under the License.
<action android:name="android.intent.action.MAIN" />
</intent-filter>
</activity>
<service android:name="org.openqa.selenium.android.server.JettyService"
android:process=":remote" />
<service android:enabled="true" android:name="org.openqa.selenium.android.server.JettyService"/>
</application>

<uses-permission android:name="android.permission.INTERNET" />
Expand All @@ -49,5 +48,5 @@ limitations under the License.
<uses-permission android:name="android.permission.SET_DEBUG_APP" />
<uses-permission android:name="android.permission.WRITE_SETTINGS" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.WRITE_APN_SETTINGS" />
<uses-permission android:name="android.permission.WRITE_APN_SETTINGS" />
</manifest>
239 changes: 239 additions & 0 deletions android/src/java/org/openqa/selenium/android/ActivityController.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,239 @@
/*
Copyright 2010 WebDriver committers
Copyright 2010 Google Inc.
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 org.openqa.selenium.android;

import java.util.Set;

import org.openqa.selenium.Cookie;
import org.openqa.selenium.ScreenOrientation;
import org.openqa.selenium.android.app.WebDriverActivity;

import android.util.Log;
import android.view.MotionEvent;

public class ActivityController {

private WebDriverActivity activity;
private static ActivityController instance;
private static Object syncObject = new Object();
private static volatile boolean done;
private static volatile String result;
private volatile boolean startedLoading;

private ActivityController() {}

public static ActivityController getInstance() {
synchronized (syncObject) {
if (instance == null) {
instance = new ActivityController();
}
return instance;
}
}

public void setActivity(WebDriverActivity ui) {
synchronized (syncObject) {
this.activity = ui;
}
}

public void waitUntilEditableAreaFocused() {
synchronized (syncObject) {
done = false;
while (!done) {
try {
syncObject.wait(AndroidDriver.FOCUS_TIMEOUT);
} catch (InterruptedException e) {
throw new RuntimeException(e);
}
}
}
}

public void notifyPageStartedLoading() {
synchronized(syncObject) {
startedLoading = true;
}
}

public void blockIfPageIsLoading() {
synchronized (syncObject) {
if (startedLoading) {
while (!done) {
try {
syncObject.wait(AndroidDriver.LOADING_TIMEOUT);
} catch (InterruptedException e) {
throw new RuntimeException(e);
}
}
}
}
}

public static void done () {
synchronized (syncObject) {
Logger.log(Log.DEBUG, "WD", "SHARED OBJECT NOTIFIED");
done = true;
syncObject.notify();
}
}

public void get(final String url) {
synchronized (syncObject) {
done = false;
activity.navigateTo(url);
while (!done) {
try {
syncObject.wait(AndroidDriver.LOADING_TIMEOUT);
} catch (InterruptedException e) {
throw new RuntimeException(e);
}
}
}
}

public String getCurrentUrl() {
synchronized (syncObject) {
return activity.getCurrentUrl();
}
}

public String getTitle() {
synchronized (syncObject) {
return activity.getPageTitle();
}
}

public String executeJavascript(final String script) {
synchronized (syncObject) {
done = false;
activity.injectScript(script);
while (!done) {
try {
syncObject.wait(AndroidDriver.LOADING_TIMEOUT);
} catch (InterruptedException e) {
throw new RuntimeException(e);
}
}
}
return result;
}

public static void updateResult(String updated) {
synchronized (syncObject) {
result = updated;
}
}

public void quit() {
synchronized(syncObject) {
activity.finish();
}
}

public Set<String> getAllWindowHandles() {
synchronized(syncObject) {
return activity.getAllWindowHandles();
}
}

public String getWindowHandle() {
synchronized(syncObject) {
return activity.getWindowHandle();
}
}

public void switchToWindow(final String name) {
synchronized(syncObject) {
activity.switchToWindow(name);
}
}

public void addCookie(final String name, final String value, final String path) {
synchronized(syncObject) {
activity.addCookie(name, value, path);
}
}

public void removeCookie(final String name) {
synchronized(syncObject) {
activity.removeCookie(name);
}
}

public void removeAllCookies() {
synchronized(syncObject) {
activity.removeAllCookies();
}
}

public Set<Cookie> getCookies() {
synchronized(syncObject) {
return activity.getCookies();
}
}

public Cookie getCookie(final String name) {
synchronized(syncObject) {
return activity.getCookie(name);
}
}

public byte[] takeScreenshot() {
synchronized(syncObject) {
return activity.takeScreenshot();
}
}

public ScreenOrientation getScreenOrientation() {
synchronized(syncObject) {
return activity.getScreenOrientation();
}
}

public void rotate(ScreenOrientation orientation) {
synchronized(syncObject) {
activity.rotate(orientation);
}
}

public void navigateBackOrForward(int direction) {
synchronized(syncObject) {
activity.navigateBackOrForward(direction);
}
}

public void refresh() {
synchronized(syncObject) {
activity.refresh();
}
}

public void sendMotionEvent(MotionEvent down, MotionEvent up) {
synchronized(syncObject) {
activity.sendMotionToScreen(down, up);
}
}

public void sendKeys(CharSequence[] inputKeys) {
synchronized(syncObject) {
activity.sendKeys(inputKeys);
}
}

}
Loading

0 comments on commit 923d8fd

Please sign in to comment.