summaryrefslogtreecommitdiffstats
path: root/core/tests
diff options
context:
space:
mode:
Diffstat (limited to 'core/tests')
-rw-r--r--core/tests/ConnectivityManagerTest/AndroidManifest.xml14
-rw-r--r--core/tests/ConnectivityManagerTest/src/com/android/connectivitymanagertest/AccessPointParserHelper.java2
-rw-r--r--core/tests/ConnectivityManagerTest/src/com/android/connectivitymanagertest/ConnectivityManagerTestBase.java (renamed from core/tests/ConnectivityManagerTest/src/com/android/connectivitymanagertest/ConnectivityManagerTestActivity.java)160
-rw-r--r--core/tests/ConnectivityManagerTest/src/com/android/connectivitymanagertest/ConnectivityManagerUnitTestRunner.java2
-rw-r--r--core/tests/ConnectivityManagerTest/src/com/android/connectivitymanagertest/NetworkState.java33
-rw-r--r--core/tests/ConnectivityManagerTest/src/com/android/connectivitymanagertest/functional/ConnectivityManagerMobileTest.java317
-rw-r--r--core/tests/ConnectivityManagerTest/src/com/android/connectivitymanagertest/functional/WifiAssociationTest.java33
-rw-r--r--core/tests/ConnectivityManagerTest/src/com/android/connectivitymanagertest/functional/WifiConnectionTest.java64
-rw-r--r--core/tests/ConnectivityManagerTest/src/com/android/connectivitymanagertest/stress/WifiApStress.java38
-rw-r--r--core/tests/ConnectivityManagerTest/src/com/android/connectivitymanagertest/stress/WifiStressTest.java81
-rw-r--r--core/tests/ConnectivityManagerTest/src/com/android/connectivitymanagertest/unit/WifiClientTest.java6
-rw-r--r--core/tests/ConnectivityManagerTest/src/com/android/connectivitymanagertest/unit/WifiSoftAPTest.java8
-rw-r--r--core/tests/bandwidthtests/src/com/android/bandwidthtest/BandwidthTest.java56
-rw-r--r--core/tests/benchmarks/src/android/os/StrictModeBenchmark.java (renamed from core/tests/coretests/src/android/webkit/AccessibilityInjectorTestActivity.java)28
-rw-r--r--core/tests/coretests/Android.mk2
-rw-r--r--core/tests/coretests/AndroidManifest.xml6
-rw-r--r--core/tests/coretests/apks/version_nosys/Android.mk9
-rw-r--r--core/tests/coretests/apks/version_nosys/AndroidManifest.xml27
-rw-r--r--core/tests/coretests/apks/version_nosys/res/values/strings.xml6
-rw-r--r--core/tests/coretests/apks/version_nosys/src/com/android/frameworks/coretests/version_test/NullProvider.java39
-rw-r--r--core/tests/coretests/src/android/animation/AnimatorSetEventsTest.java4
-rw-r--r--core/tests/coretests/src/android/animation/EventsTest.java160
-rw-r--r--core/tests/coretests/src/android/database/MatrixCursorTest.java50
-rw-r--r--core/tests/coretests/src/android/hardware/display/VirtualDisplayTest.java500
-rw-r--r--core/tests/coretests/src/android/net/LinkPropertiesTest.java263
-rw-r--r--core/tests/coretests/src/android/webkit/AccessibilityInjectorTest.java1809
-rw-r--r--core/tests/coretests/src/android/webkit/UrlInterceptRegistryTest.java88
-rw-r--r--core/tests/coretests/src/android/webkit/WebkitTest.java59
-rw-r--r--core/tests/coretests/src/android/webkit/ZoomManagerTest.java128
29 files changed, 1309 insertions, 2683 deletions
diff --git a/core/tests/ConnectivityManagerTest/AndroidManifest.xml b/core/tests/ConnectivityManagerTest/AndroidManifest.xml
index 54881d5..1649268 100644
--- a/core/tests/ConnectivityManagerTest/AndroidManifest.xml
+++ b/core/tests/ConnectivityManagerTest/AndroidManifest.xml
@@ -16,21 +16,13 @@
<!-- package name must be unique so suffix with "tests" so package loader doesn't ignore us -->
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
- package="com.android.connectivitymanagertest"
- android:sharedUserId="android.uid.system">
+ package="com.android.connectivitymanagertest">
<!-- We add an application tag here just so that we can indicate that
this package needs to link against the android.test library,
which is needed when building test cases. -->
<application>
<uses-library android:name="android.test.runner" />
- <activity android:name="ConnectivityManagerTestActivity"
- android:label="@string/app_name">
- <intent-filter>
- <action android:name="android.intent.action.MAIN" />
- <category android:name="android.intent.category.LAUNCHER" />
- </intent-filter>
- </activity>
</application>
<!--
@@ -80,10 +72,14 @@
<uses-permission android:name="android.permission.CHANGE_WIFI_STATE" />
<uses-permission android:name="android.permission.WRITE_SETTINGS" />
<uses-permission android:name="android.permission.WRITE_SECURE_SETTINGS" />
+ <!-- This permission is added for API call setAirplaneMode() in ConnectivityManager -->
+ <uses-permission android:name="android.permission.CONNECTIVITY_INTERNAL" />
<uses-permission android:name="android.permission.WAKE_LOCK" />
<uses-permission android:name="android.permission.DEVICE_POWER" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.INTERACT_ACROSS_USERS_FULL" />
<uses-permission android:name="android.permission.INTERACT_ACROSS_USERS" />
<uses-permission android:name="android.permission.INJECT_EVENTS" />
+ <uses-permission android:name="android.permission.DEVICE_POWER" />
+
</manifest>
diff --git a/core/tests/ConnectivityManagerTest/src/com/android/connectivitymanagertest/AccessPointParserHelper.java b/core/tests/ConnectivityManagerTest/src/com/android/connectivitymanagertest/AccessPointParserHelper.java
index 0461c0b..b942eb6 100644
--- a/core/tests/ConnectivityManagerTest/src/com/android/connectivitymanagertest/AccessPointParserHelper.java
+++ b/core/tests/ConnectivityManagerTest/src/com/android/connectivitymanagertest/AccessPointParserHelper.java
@@ -32,13 +32,11 @@ import android.net.wifi.WifiEnterpriseConfig;
import android.net.LinkAddress;
import android.net.LinkProperties;
import android.net.RouteInfo;
-import android.util.Log;
import java.io.InputStream;
import java.net.InetAddress;
import java.net.UnknownHostException;
import java.util.ArrayList;
-import java.util.HashMap;
import java.util.List;
diff --git a/core/tests/ConnectivityManagerTest/src/com/android/connectivitymanagertest/ConnectivityManagerTestActivity.java b/core/tests/ConnectivityManagerTest/src/com/android/connectivitymanagertest/ConnectivityManagerTestBase.java
index 463e999..30eda75 100644
--- a/core/tests/ConnectivityManagerTest/src/com/android/connectivitymanagertest/ConnectivityManagerTestActivity.java
+++ b/core/tests/ConnectivityManagerTest/src/com/android/connectivitymanagertest/ConnectivityManagerTestBase.java
@@ -16,7 +16,7 @@
package com.android.connectivitymanagertest;
-import android.app.Activity;
+import android.app.KeyguardManager;
import android.content.Context;
import android.content.BroadcastReceiver;
import android.content.Intent;
@@ -26,21 +26,14 @@ import android.net.NetworkInfo;
import android.net.NetworkInfo.State;
import android.net.wifi.WifiConfiguration;
import android.net.wifi.WifiManager;
-import android.net.wifi.WifiInfo;
-import android.net.wifi.ScanResult;
import android.net.wifi.WifiConfiguration.KeyMgmt;
-import android.os.Bundle;
import android.os.Handler;
-import android.os.IPowerManager;
import android.os.Message;
import android.os.PowerManager;
-import android.os.ServiceManager;
import android.os.SystemClock;
-import android.os.UserHandle;
-import android.provider.Settings;
+import android.test.InstrumentationTestCase;
import android.util.Log;
import android.view.KeyEvent;
-import android.widget.LinearLayout;
import com.android.internal.util.AsyncChannel;
@@ -52,13 +45,17 @@ import java.util.List;
/**
- * An activity registered with connectivity manager broadcast
- * provides network connectivity information and
- * can be used to set device states: Cellular, Wifi, Airplane mode.
+ * Base InstrumentationTestCase for Connectivity Manager (CM) test suite
+ *
+ * It registers connectivity manager broadcast and WiFi broadcast to provide
+ * network connectivity information, also provides a set of utility functions
+ * to modify and verify connectivity states.
+ *
+ * A CM test case should extend this base class.
*/
-public class ConnectivityManagerTestActivity extends Activity {
+public class ConnectivityManagerTestBase extends InstrumentationTestCase {
- public static final String LOG_TAG = "ConnectivityManagerTestActivity";
+ public static final String LOG_TAG = "ConnectivityManagerTestBase";
public static final int WAIT_FOR_SCAN_RESULT = 10 * 1000; //10 seconds
public static final int WIFI_SCAN_TIMEOUT = 50 * 1000; // 50 seconds
public static final int SHORT_TIMEOUT = 5 * 1000; // 5 seconds
@@ -94,14 +91,9 @@ public class ConnectivityManagerTestActivity extends Activity {
private Context mContext;
public boolean scanResultAvailable = false;
- /*
- * Control Wifi States
- */
+ /* Control Wifi States */
public WifiManager mWifiManager;
-
- /*
- * Verify connectivity state
- */
+ /* Verify connectivity state */
public static final int NUM_NETWORK_TYPES = ConnectivityManager.MAX_NETWORK_TYPE + 1;
NetworkState[] connectivityState = new NetworkState[NUM_NETWORK_TYPES];
@@ -208,26 +200,28 @@ public class ConnectivityManagerTestActivity extends Activity {
}
}
- public ConnectivityManagerTestActivity() {
+ @Override
+ public void setUp() throws Exception {
mState = State.UNKNOWN;
scanResultAvailable = false;
- }
+ mContext = getInstrumentation().getContext();
- @Override
- protected void onCreate(Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
- log("onCreate, inst=" + Integer.toHexString(hashCode()));
+ // Get an instance of ConnectivityManager
+ mCM = (ConnectivityManager)mContext.getSystemService(Context.CONNECTIVITY_SERVICE);
+ // Get an instance of WifiManager
+ mWifiManager =(WifiManager)mContext.getSystemService(Context.WIFI_SERVICE);
- // Create a simple layout
- LinearLayout contentView = new LinearLayout(this);
- contentView.setOrientation(LinearLayout.VERTICAL);
- setContentView(contentView);
- setTitle("ConnectivityManagerTestActivity");
+ if (mWifiManager.isWifiApEnabled()) {
+ // if soft AP is enabled, disable it
+ mWifiManager.setWifiApEnabled(null, false);
+ log("Disable soft ap");
+ }
+ initializeNetworkStates();
// register a connectivity receiver for CONNECTIVITY_ACTION;
mConnectivityReceiver = new ConnectivityReceiver();
- registerReceiver(mConnectivityReceiver,
+ mContext.registerReceiver(mConnectivityReceiver,
new IntentFilter(ConnectivityManager.CONNECTIVITY_ACTION));
mWifiReceiver = new WifiReceiver();
@@ -238,28 +232,15 @@ public class ConnectivityManagerTestActivity extends Activity {
mIntentFilter.addAction(WifiManager.SUPPLICANT_CONNECTION_CHANGE_ACTION);
mIntentFilter.addAction(WifiManager.WIFI_AP_STATE_CHANGED_ACTION);
mIntentFilter.addAction(ConnectivityManager.ACTION_TETHER_STATE_CHANGED);
- registerReceiver(mWifiReceiver, mIntentFilter);
-
- // Get an instance of ConnectivityManager
- mCM = (ConnectivityManager)getSystemService(Context.CONNECTIVITY_SERVICE);
- // Get an instance of WifiManager
- mWifiManager =(WifiManager)getSystemService(Context.WIFI_SERVICE);
- mContext = this;
+ mContext.registerReceiver(mWifiReceiver, mIntentFilter);
- if (mWifiManager.isWifiApEnabled()) {
- // if soft AP is enabled, disable it
- mWifiManager.setWifiApEnabled(null, false);
- log("Disable soft ap");
- }
-
- initializeNetworkStates();
log("Clear Wifi before we start the test.");
removeConfiguredNetworksAndDisableWifi();
mWifiRegexs = mCM.getTetherableWifiRegexs();
}
public List<WifiConfiguration> loadNetworkConfigurations() throws Exception {
- InputStream in = getAssets().open(ACCESS_POINT_FILE);
+ InputStream in = mContext.getAssets().open(ACCESS_POINT_FILE);
mParseHelper = new AccessPointParserHelper(in);
return mParseHelper.getNetworkConfigurations();
}
@@ -277,6 +258,12 @@ public class ConnectivityManagerTestActivity extends Activity {
public void recordNetworkState(int networkType, State networkState) {
log("record network state for network " + networkType +
", state is " + networkState);
+ if (connectivityState == null) {
+ log("ConnectivityState is null");
+ }
+ if (connectivityState[networkType] == null) {
+ log("connectivityState[networkType] is null");
+ }
connectivityState[networkType].recordState(networkState);
}
@@ -503,7 +490,7 @@ public class ConnectivityManagerTestActivity extends Activity {
public void turnScreenOff() {
log("Turn screen off");
PowerManager pm =
- (PowerManager) getSystemService(Context.POWER_SERVICE);
+ (PowerManager) mContext.getSystemService(Context.POWER_SERVICE);
pm.goToSleep(SystemClock.uptimeMillis());
}
@@ -511,8 +498,13 @@ public class ConnectivityManagerTestActivity extends Activity {
public void turnScreenOn() {
log("Turn screen on");
PowerManager pm =
- (PowerManager) getSystemService(Context.POWER_SERVICE);
+ (PowerManager) mContext.getSystemService(Context.POWER_SERVICE);
pm.wakeUp(SystemClock.uptimeMillis());
+ // disable lock screen
+ KeyguardManager km = (KeyguardManager) mContext.getSystemService(Context.KEYGUARD_SERVICE);
+ if (km.inKeyguardRestrictedInputMode()) {
+ sendKeys(KeyEvent.KEYCODE_MENU);
+ }
}
/**
@@ -607,7 +599,12 @@ public class ConnectivityManagerTestActivity extends Activity {
mWifiManager.setWifiEnabled(true);
sleep(SHORT_TIMEOUT);
}
+
List<WifiConfiguration> wifiConfigList = mWifiManager.getConfiguredNetworks();
+ if (wifiConfigList == null) {
+ log("no configuration list is null");
+ return true;
+ }
log("size of wifiConfigList: " + wifiConfigList.size());
for (WifiConfiguration wifiConfig: wifiConfigList) {
log("remove wifi configuration: " + wifiConfig.networkId);
@@ -651,75 +648,20 @@ public class ConnectivityManagerTestActivity extends Activity {
} catch (InterruptedException e) {}
}
- /**
- * Set airplane mode
- */
- public void setAirplaneMode(Context context, boolean enableAM) {
- //set the airplane mode
- Settings.Global.putInt(context.getContentResolver(), Settings.Global.AIRPLANE_MODE_ON,
- enableAM ? 1 : 0);
- // Post the intent
- Intent intent = new Intent(Intent.ACTION_AIRPLANE_MODE_CHANGED);
- intent.putExtra("state", enableAM);
- context.sendBroadcastAsUser(intent, UserHandle.ALL);
- }
-
protected static String convertToQuotedString(String string) {
return "\"" + string + "\"";
}
@Override
- protected void onDestroy() {
- super.onDestroy();
-
+ public void tearDown() throws Exception{
//Unregister receiver
if (mConnectivityReceiver != null) {
- unregisterReceiver(mConnectivityReceiver);
+ mContext.unregisterReceiver(mConnectivityReceiver);
}
if (mWifiReceiver != null) {
- unregisterReceiver(mWifiReceiver);
- }
- log("onDestroy, inst=" + Integer.toHexString(hashCode()));
- }
-
- @Override
- public void onStart() {
- super.onStart();
- mContext = this;
- Bundle bundle = this.getIntent().getExtras();
- if (bundle != null){
- mPowerSsid = bundle.getString("power_ssid");
- }
- }
- //A thread to set the device into airplane mode then turn on wifi.
- Thread setDeviceWifiAndAirplaneThread = new Thread(new Runnable() {
- public void run() {
- setAirplaneMode(mContext, true);
- connectToWifi(mPowerSsid);
- }
- });
-
- //A thread to set the device into wifi
- Thread setDeviceInWifiOnlyThread = new Thread(new Runnable() {
- public void run() {
- connectToWifi(mPowerSsid);
- }
- });
-
- @Override
- public boolean onKeyDown(int keyCode, KeyEvent event) {
- switch (keyCode) {
- //This is a tricky way for the scripted monkey to
- //set the device in wifi and wifi in airplane mode.
- case KeyEvent.KEYCODE_1:
- setDeviceWifiAndAirplaneThread.start();
- break;
-
- case KeyEvent.KEYCODE_2:
- setDeviceInWifiOnlyThread.start();
- break;
+ mContext.unregisterReceiver(mWifiReceiver);
}
- return super.onKeyDown(keyCode, event);
+ super.tearDown();
}
private void log(String message) {
diff --git a/core/tests/ConnectivityManagerTest/src/com/android/connectivitymanagertest/ConnectivityManagerUnitTestRunner.java b/core/tests/ConnectivityManagerTest/src/com/android/connectivitymanagertest/ConnectivityManagerUnitTestRunner.java
index 3a78f26..0e57a00 100644
--- a/core/tests/ConnectivityManagerTest/src/com/android/connectivitymanagertest/ConnectivityManagerUnitTestRunner.java
+++ b/core/tests/ConnectivityManagerTest/src/com/android/connectivitymanagertest/ConnectivityManagerUnitTestRunner.java
@@ -16,10 +16,8 @@
package com.android.connectivitymanagertest;
-import android.os.Bundle;
import android.test.InstrumentationTestRunner;
import android.test.InstrumentationTestSuite;
-import android.util.Log;
import com.android.connectivitymanagertest.unit.WifiClientTest;
import com.android.connectivitymanagertest.unit.WifiSoftAPTest;
diff --git a/core/tests/ConnectivityManagerTest/src/com/android/connectivitymanagertest/NetworkState.java b/core/tests/ConnectivityManagerTest/src/com/android/connectivitymanagertest/NetworkState.java
index 5a4a2d0..9d97ac5 100644
--- a/core/tests/ConnectivityManagerTest/src/com/android/connectivitymanagertest/NetworkState.java
+++ b/core/tests/ConnectivityManagerTest/src/com/android/connectivitymanagertest/NetworkState.java
@@ -101,9 +101,10 @@ public class NetworkState {
}
/*
- * Transition from CONNECTED -> DISCONNECTED:
- * CONNECTED->DISCONNECTING->DISCONNECTED
- * return false if any state transition is not valid and save a message in mReason
+ * Verifies state transition from CONNECTED->...-> DISCONNECTED.
+ *
+ * returns false if initial state or target state is not correct, or if there is
+ * any transition from DISCONNECTING/DISCONNECTED -> CONNECTED.
*/
public boolean transitToDisconnection () {
mReason = "states: " + printStates();
@@ -120,13 +121,13 @@ public class NetworkState {
for (int i = 1; i < mStateDepository.size() - 1; i++) {
State preState = mStateDepository.get(i-1);
State curState = mStateDepository.get(i);
- if ((preState == State.CONNECTED) && ((curState == State.DISCONNECTING) ||
+ if (preState == curState) {
+ continue;
+ } else if ((preState == State.CONNECTED) && ((curState == State.DISCONNECTING) ||
(curState == State.DISCONNECTED))) {
continue;
} else if ((preState == State.DISCONNECTING) && (curState == State.DISCONNECTED)) {
continue;
- } else if ((preState == State.DISCONNECTED) && (curState == State.DISCONNECTED)) {
- continue;
} else {
mReason += " Transition state from " + preState.toString() + " to " +
curState.toString() + " is not valid.";
@@ -136,7 +137,12 @@ public class NetworkState {
return true;
}
- // DISCONNECTED->CONNECTING->CONNECTED
+ /*
+ * Verifies state transition from DISCONNECTED->...-> CONNECTED.
+ *
+ * returns false if initial state or target state is not correct, or if there is
+ * any transition from CONNECED -> DISCONNECTED.
+ */
public boolean transitToConnection() {
mReason = "states: " + printStates();
if (mStateDepository.get(0) != State.DISCONNECTED) {
@@ -152,14 +158,15 @@ public class NetworkState {
for (int i = 1; i < mStateDepository.size(); i++) {
State preState = mStateDepository.get(i-1);
State curState = mStateDepository.get(i);
- if ((preState == State.DISCONNECTED) && ((curState == State.CONNECTING) ||
- (curState == State.CONNECTED) || (curState == State.DISCONNECTED))) {
+ if (preState == curState) {
continue;
- } else if ((preState == State.CONNECTING) && (curState == State.CONNECTED)) {
- continue;
- } else if ((preState == State.CONNECTED) && (curState == State.CONNECTED)) {
+ }
+ if ((preState == State.DISCONNECTED) && ((curState == State.CONNECTING) ||
+ (curState == State.CONNECTED))) {
continue;
- } else {
+ } else if ((preState == State.CONNECTING) && (curState == State.CONNECTED)) {
+ continue;
+ } else {
mReason += " Transition state from " + preState.toString() + " to " +
curState.toString() + " is not valid.";
return false;
diff --git a/core/tests/ConnectivityManagerTest/src/com/android/connectivitymanagertest/functional/ConnectivityManagerMobileTest.java b/core/tests/ConnectivityManagerTest/src/com/android/connectivitymanagertest/functional/ConnectivityManagerMobileTest.java
index 3111489..05462b4 100644
--- a/core/tests/ConnectivityManagerTest/src/com/android/connectivitymanagertest/functional/ConnectivityManagerMobileTest.java
+++ b/core/tests/ConnectivityManagerTest/src/com/android/connectivitymanagertest/functional/ConnectivityManagerMobileTest.java
@@ -24,31 +24,24 @@ import android.net.wifi.WifiManager;
import android.os.PowerManager;
import android.os.PowerManager.WakeLock;
import android.provider.Settings;
-import android.test.ActivityInstrumentationTestCase2;
import android.test.suitebuilder.annotation.LargeTest;
import android.util.Log;
-import com.android.connectivitymanagertest.ConnectivityManagerTestActivity;
+import com.android.connectivitymanagertest.ConnectivityManagerTestBase;
import com.android.connectivitymanagertest.ConnectivityManagerTestRunner;
import com.android.connectivitymanagertest.NetworkState;
public class ConnectivityManagerMobileTest extends
- ActivityInstrumentationTestCase2<ConnectivityManagerTestActivity> {
- private static final String LOG_TAG = "ConnectivityManagerMobileTest";
+ ConnectivityManagerTestBase {
+ private static final String TAG = "ConnectivityManagerMobileTest";
private String mTestAccessPoint;
- private ConnectivityManagerTestActivity cmActivity;
private WakeLock wl;
private boolean mWifiOnlyFlag;
- public ConnectivityManagerMobileTest() {
- super(ConnectivityManagerTestActivity.class);
- }
-
@Override
public void setUp() throws Exception {
super.setUp();
- cmActivity = getActivity();
ConnectivityManagerTestRunner mRunner =
(ConnectivityManagerTestRunner)getInstrumentation();
mTestAccessPoint = mRunner.mTestSsid;
@@ -62,12 +55,12 @@ public class ConnectivityManagerMobileTest extends
if (Settings.Global.getInt(getInstrumentation().getContext().getContentResolver(),
Settings.Global.AIRPLANE_MODE_ON) == 1) {
log("airplane is not disabled, disable it.");
- cmActivity.setAirplaneMode(getInstrumentation().getContext(), false);
+ mCM.setAirplaneMode(false);
}
if (!mWifiOnlyFlag) {
- if (!cmActivity.waitForNetworkState(ConnectivityManager.TYPE_MOBILE, State.CONNECTED,
- ConnectivityManagerTestActivity.LONG_TIMEOUT)) {
+ if (!waitForNetworkState(ConnectivityManager.TYPE_MOBILE,
+ State.CONNECTED, LONG_TIMEOUT)) {
// Note: When the test fails in setUp(), tearDown is not called. In that case,
// the activity is destroyed which blocks the next test at "getActivity()".
// tearDown() is called here to avoid that situation.
@@ -79,29 +72,22 @@ public class ConnectivityManagerMobileTest extends
@Override
public void tearDown() throws Exception {
- cmActivity.finish();
- log("tear down ConnectivityManagerTestActivity");
wl.release();
- cmActivity.removeConfiguredNetworksAndDisableWifi();
- // if airplane mode is set, disable it.
- if (Settings.Global.getInt(getInstrumentation().getContext().getContentResolver(),
- Settings.Global.AIRPLANE_MODE_ON) == 1) {
- log("disable airplane mode if it is enabled");
- cmActivity.setAirplaneMode(getInstrumentation().getContext(), false);
- }
+ removeConfiguredNetworksAndDisableWifi();
+ mCM.setAirplaneMode(false);
super.tearDown();
}
// help function to verify 3G connection
public void verifyCellularConnection() {
- NetworkInfo extraNetInfo = cmActivity.mCM.getActiveNetworkInfo();
+ NetworkInfo extraNetInfo = mCM.getActiveNetworkInfo();
assertEquals("network type is not MOBILE", ConnectivityManager.TYPE_MOBILE,
extraNetInfo.getType());
assertTrue("not connected to cellular network", extraNetInfo.isConnected());
}
private void log(String message) {
- Log.v(LOG_TAG, message);
+ Log.v(TAG, message);
}
private void sleep(long sleeptime) {
@@ -115,46 +101,46 @@ public class ConnectivityManagerMobileTest extends
@LargeTest
public void test3GToWifiNotification() {
if (mWifiOnlyFlag) {
- Log.v(LOG_TAG, this.getName() + " is excluded for wifi-only test");
+ Log.v(TAG, this.getName() + " is excluded for wifi-only test");
return;
}
// Enable Wi-Fi to avoid initial UNKNOWN state
- cmActivity.enableWifi();
- sleep(2 * ConnectivityManagerTestActivity.SHORT_TIMEOUT);
+ enableWifi();
+ sleep(2 * SHORT_TIMEOUT);
// Wi-Fi is disabled
- cmActivity.disableWifi();
+ disableWifi();
- assertTrue(cmActivity.waitForNetworkState(ConnectivityManager.TYPE_WIFI,
- State.DISCONNECTED, ConnectivityManagerTestActivity.LONG_TIMEOUT));
- assertTrue(cmActivity.waitForNetworkState(ConnectivityManager.TYPE_MOBILE,
- State.CONNECTED, ConnectivityManagerTestActivity.LONG_TIMEOUT));
+ assertTrue(waitForNetworkState(ConnectivityManager.TYPE_WIFI,
+ State.DISCONNECTED, LONG_TIMEOUT));
+ assertTrue(waitForNetworkState(ConnectivityManager.TYPE_MOBILE,
+ State.CONNECTED, LONG_TIMEOUT));
// Wait for 10 seconds for broadcasts to be sent out
sleep(10 * 1000);
// As Wifi stays in DISCONNETED, Mobile statys in CONNECTED,
// the connectivity manager will not broadcast any network connectivity event for Wifi
- NetworkInfo networkInfo = cmActivity.mCM.getNetworkInfo(ConnectivityManager.TYPE_MOBILE);
- cmActivity.setStateTransitionCriteria(ConnectivityManager.TYPE_MOBILE,
+ NetworkInfo networkInfo = mCM.getNetworkInfo(ConnectivityManager.TYPE_MOBILE);
+ setStateTransitionCriteria(ConnectivityManager.TYPE_MOBILE,
networkInfo.getState(), NetworkState.DO_NOTHING, State.CONNECTED);
- networkInfo = cmActivity.mCM.getNetworkInfo(ConnectivityManager.TYPE_WIFI);
- cmActivity.setStateTransitionCriteria(ConnectivityManager.TYPE_WIFI, networkInfo.getState(),
+ networkInfo = mCM.getNetworkInfo(ConnectivityManager.TYPE_WIFI);
+ setStateTransitionCriteria(ConnectivityManager.TYPE_WIFI, networkInfo.getState(),
NetworkState.DO_NOTHING, State.DISCONNECTED);
// Eanble Wifi without associating with any AP
- cmActivity.enableWifi();
- sleep(2 * ConnectivityManagerTestActivity.SHORT_TIMEOUT);
+ enableWifi();
+ sleep(2 * SHORT_TIMEOUT);
// validate state and broadcast
- if (!cmActivity.validateNetworkStates(ConnectivityManager.TYPE_WIFI)) {
+ if (!validateNetworkStates(ConnectivityManager.TYPE_WIFI)) {
log("the state for WIFI is changed");
log("reason: " +
- cmActivity.getTransitionFailureReason(ConnectivityManager.TYPE_WIFI));
+ getTransitionFailureReason(ConnectivityManager.TYPE_WIFI));
assertTrue("state validation fail", false);
}
- if (!cmActivity.validateNetworkStates(ConnectivityManager.TYPE_MOBILE)) {
+ if (!validateNetworkStates(ConnectivityManager.TYPE_MOBILE)) {
log("the state for MOBILE is changed");
log("reason: " +
- cmActivity.getTransitionFailureReason(ConnectivityManager.TYPE_MOBILE));
+ getTransitionFailureReason(ConnectivityManager.TYPE_MOBILE));
assertTrue("state validation fail", false);
}
// Verify that the device is still connected to MOBILE
@@ -168,40 +154,39 @@ public class ConnectivityManagerMobileTest extends
NetworkInfo networkInfo;
if (!mWifiOnlyFlag) {
//Prepare for connectivity verification
- networkInfo = cmActivity.mCM.getNetworkInfo(ConnectivityManager.TYPE_MOBILE);
- cmActivity.setStateTransitionCriteria(ConnectivityManager.TYPE_MOBILE,
+ networkInfo = mCM.getNetworkInfo(ConnectivityManager.TYPE_MOBILE);
+ setStateTransitionCriteria(ConnectivityManager.TYPE_MOBILE,
networkInfo.getState(), NetworkState.TO_DISCONNECTION, State.DISCONNECTED);
}
- networkInfo = cmActivity.mCM.getNetworkInfo(ConnectivityManager.TYPE_WIFI);
- cmActivity.setStateTransitionCriteria(ConnectivityManager.TYPE_WIFI, networkInfo.getState(),
+ networkInfo = mCM.getNetworkInfo(ConnectivityManager.TYPE_WIFI);
+ setStateTransitionCriteria(ConnectivityManager.TYPE_WIFI, networkInfo.getState(),
NetworkState.TO_CONNECTION, State.CONNECTED);
// Enable Wifi and connect to a test access point
assertTrue("failed to connect to " + mTestAccessPoint,
- cmActivity.connectToWifi(mTestAccessPoint));
+ connectToWifi(mTestAccessPoint));
- assertTrue(cmActivity.waitForWifiState(WifiManager.WIFI_STATE_ENABLED,
- ConnectivityManagerTestActivity.LONG_TIMEOUT));
+ assertTrue(waitForWifiState(WifiManager.WIFI_STATE_ENABLED, LONG_TIMEOUT));
log("wifi state is enabled");
- assertTrue(cmActivity.waitForNetworkState(ConnectivityManager.TYPE_WIFI, State.CONNECTED,
- ConnectivityManagerTestActivity.WIFI_CONNECTION_TIMEOUT));
+ assertTrue(waitForNetworkState(ConnectivityManager.TYPE_WIFI, State.CONNECTED,
+ WIFI_CONNECTION_TIMEOUT));
if (!mWifiOnlyFlag) {
- assertTrue(cmActivity.waitForNetworkState(ConnectivityManager.TYPE_MOBILE,
- State.DISCONNECTED, ConnectivityManagerTestActivity.LONG_TIMEOUT));
+ assertTrue(waitForNetworkState(ConnectivityManager.TYPE_MOBILE,
+ State.DISCONNECTED, LONG_TIMEOUT));
}
// validate states
- if (!cmActivity.validateNetworkStates(ConnectivityManager.TYPE_WIFI)) {
+ if (!validateNetworkStates(ConnectivityManager.TYPE_WIFI)) {
log("Wifi state transition validation failed.");
log("reason: " +
- cmActivity.getTransitionFailureReason(ConnectivityManager.TYPE_WIFI));
+ getTransitionFailureReason(ConnectivityManager.TYPE_WIFI));
assertTrue(false);
}
if (!mWifiOnlyFlag) {
- if (!cmActivity.validateNetworkStates(ConnectivityManager.TYPE_MOBILE)) {
+ if (!validateNetworkStates(ConnectivityManager.TYPE_MOBILE)) {
log("Mobile state transition validation failed.");
log("reason: " +
- cmActivity.getTransitionFailureReason(ConnectivityManager.TYPE_MOBILE));
+ getTransitionFailureReason(ConnectivityManager.TYPE_MOBILE));
assertTrue(false);
}
}
@@ -213,61 +198,59 @@ public class ConnectivityManagerMobileTest extends
assertNotNull("SSID is null", mTestAccessPoint);
// Connect to mTestAccessPoint
assertTrue("failed to connect to " + mTestAccessPoint,
- cmActivity.connectToWifi(mTestAccessPoint));
- assertTrue(cmActivity.waitForWifiState(WifiManager.WIFI_STATE_ENABLED,
- ConnectivityManagerTestActivity.LONG_TIMEOUT));
- assertTrue(cmActivity.waitForNetworkState(ConnectivityManager.TYPE_WIFI, State.CONNECTED,
- ConnectivityManagerTestActivity.WIFI_CONNECTION_TIMEOUT));
+ connectToWifi(mTestAccessPoint));
+ assertTrue(waitForWifiState(WifiManager.WIFI_STATE_ENABLED, LONG_TIMEOUT));
+ assertTrue(waitForNetworkState(ConnectivityManager.TYPE_WIFI, State.CONNECTED,
+ WIFI_CONNECTION_TIMEOUT));
- sleep(ConnectivityManagerTestActivity.SHORT_TIMEOUT);
+ sleep(SHORT_TIMEOUT);
// Disable Wifi
log("Disable Wifi");
- if (!cmActivity.disableWifi()) {
+ if (!disableWifi()) {
log("disable Wifi failed");
return;
}
// Wait for the Wifi state to be DISABLED
- assertTrue(cmActivity.waitForWifiState(WifiManager.WIFI_STATE_DISABLED,
- ConnectivityManagerTestActivity.LONG_TIMEOUT));
- assertTrue(cmActivity.waitForNetworkState(ConnectivityManager.TYPE_WIFI,
- State.DISCONNECTED, ConnectivityManagerTestActivity.LONG_TIMEOUT));
+ assertTrue(waitForWifiState(WifiManager.WIFI_STATE_DISABLED, LONG_TIMEOUT));
+ assertTrue(waitForNetworkState(ConnectivityManager.TYPE_WIFI,
+ State.DISCONNECTED, LONG_TIMEOUT));
if (!mWifiOnlyFlag) {
- assertTrue(cmActivity.waitForNetworkState(ConnectivityManager.TYPE_MOBILE,
- State.CONNECTED, ConnectivityManagerTestActivity.LONG_TIMEOUT));
+ assertTrue(waitForNetworkState(ConnectivityManager.TYPE_MOBILE,
+ State.CONNECTED, LONG_TIMEOUT));
}
NetworkInfo networkInfo;
if (!mWifiOnlyFlag) {
//Prepare for connectivity state verification
- networkInfo = cmActivity.mCM.getNetworkInfo(ConnectivityManager.TYPE_MOBILE);
- cmActivity.setStateTransitionCriteria(ConnectivityManager.TYPE_MOBILE,
+ networkInfo = mCM.getNetworkInfo(ConnectivityManager.TYPE_MOBILE);
+ setStateTransitionCriteria(ConnectivityManager.TYPE_MOBILE,
networkInfo.getState(), NetworkState.DO_NOTHING,
State.DISCONNECTED);
}
- networkInfo = cmActivity.mCM.getNetworkInfo(ConnectivityManager.TYPE_WIFI);
- cmActivity.setStateTransitionCriteria(ConnectivityManager.TYPE_WIFI, networkInfo.getState(),
+ networkInfo = mCM.getNetworkInfo(ConnectivityManager.TYPE_WIFI);
+ setStateTransitionCriteria(ConnectivityManager.TYPE_WIFI, networkInfo.getState(),
NetworkState.TO_CONNECTION, State.CONNECTED);
// wait for 2 minutes before restart wifi
- sleep(ConnectivityManagerTestActivity.WIFI_STOP_START_INTERVAL);
+ sleep(WIFI_STOP_START_INTERVAL);
// Enable Wifi again
log("Enable Wifi again");
- cmActivity.enableWifi();
+ enableWifi();
// Wait for Wifi to be connected and mobile to be disconnected
- assertTrue(cmActivity.waitForNetworkState(ConnectivityManager.TYPE_WIFI, State.CONNECTED,
- ConnectivityManagerTestActivity.WIFI_CONNECTION_TIMEOUT));
+ assertTrue(waitForNetworkState(ConnectivityManager.TYPE_WIFI, State.CONNECTED,
+ WIFI_CONNECTION_TIMEOUT));
if (!mWifiOnlyFlag) {
- assertTrue(cmActivity.waitForNetworkState(ConnectivityManager.TYPE_MOBILE,
- State.DISCONNECTED, ConnectivityManagerTestActivity.LONG_TIMEOUT));
+ assertTrue(waitForNetworkState(ConnectivityManager.TYPE_MOBILE,
+ State.DISCONNECTED, LONG_TIMEOUT));
}
// validate wifi states
- if (!cmActivity.validateNetworkStates(ConnectivityManager.TYPE_WIFI)) {
+ if (!validateNetworkStates(ConnectivityManager.TYPE_WIFI)) {
log("Wifi state transition validation failed.");
log("reason: " +
- cmActivity.getTransitionFailureReason(ConnectivityManager.TYPE_WIFI));
+ getTransitionFailureReason(ConnectivityManager.TYPE_WIFI));
assertTrue(false);
}
}
@@ -279,48 +262,48 @@ public class ConnectivityManagerMobileTest extends
// connect to Wifi
assertTrue("failed to connect to " + mTestAccessPoint,
- cmActivity.connectToWifi(mTestAccessPoint));
+ connectToWifi(mTestAccessPoint));
- assertTrue(cmActivity.waitForNetworkState(ConnectivityManager.TYPE_WIFI, State.CONNECTED,
- ConnectivityManagerTestActivity.WIFI_CONNECTION_TIMEOUT));
+ assertTrue(waitForNetworkState(ConnectivityManager.TYPE_WIFI, State.CONNECTED,
+ WIFI_CONNECTION_TIMEOUT));
// Wait for a few seconds to avoid the state that both Mobile and Wifi is connected
- sleep(ConnectivityManagerTestActivity.SHORT_TIMEOUT);
+ sleep(SHORT_TIMEOUT);
NetworkInfo networkInfo;
if (!mWifiOnlyFlag) {
- networkInfo = cmActivity.mCM.getNetworkInfo(ConnectivityManager.TYPE_MOBILE);
- cmActivity.setStateTransitionCriteria(ConnectivityManager.TYPE_MOBILE,
+ networkInfo = mCM.getNetworkInfo(ConnectivityManager.TYPE_MOBILE);
+ setStateTransitionCriteria(ConnectivityManager.TYPE_MOBILE,
networkInfo.getState(),
NetworkState.TO_CONNECTION,
State.CONNECTED);
}
- networkInfo = cmActivity.mCM.getNetworkInfo(ConnectivityManager.TYPE_WIFI);
- cmActivity.setStateTransitionCriteria(ConnectivityManager.TYPE_WIFI, networkInfo.getState(),
+ networkInfo = mCM.getNetworkInfo(ConnectivityManager.TYPE_WIFI);
+ setStateTransitionCriteria(ConnectivityManager.TYPE_WIFI, networkInfo.getState(),
NetworkState.TO_DISCONNECTION, State.DISCONNECTED);
// clear Wifi
- cmActivity.removeConfiguredNetworksAndDisableWifi();
+ removeConfiguredNetworksAndDisableWifi();
- assertTrue(cmActivity.waitForNetworkState(ConnectivityManager.TYPE_WIFI, State.DISCONNECTED,
- ConnectivityManagerTestActivity.LONG_TIMEOUT));
+ assertTrue(waitForNetworkState(ConnectivityManager.TYPE_WIFI,
+ State.DISCONNECTED, LONG_TIMEOUT));
if (!mWifiOnlyFlag) {
- assertTrue(cmActivity.waitForNetworkState(ConnectivityManager.TYPE_MOBILE,
- State.CONNECTED, ConnectivityManagerTestActivity.LONG_TIMEOUT));
+ assertTrue(waitForNetworkState(ConnectivityManager.TYPE_MOBILE,
+ State.CONNECTED, LONG_TIMEOUT));
}
// validate states
- if (!cmActivity.validateNetworkStates(ConnectivityManager.TYPE_WIFI)) {
+ if (!validateNetworkStates(ConnectivityManager.TYPE_WIFI)) {
log("Wifi state transition validation failed.");
log("reason: " +
- cmActivity.getTransitionFailureReason(ConnectivityManager.TYPE_WIFI));
+ getTransitionFailureReason(ConnectivityManager.TYPE_WIFI));
assertTrue(false);
}
if (!mWifiOnlyFlag) {
- if (!cmActivity.validateNetworkStates(ConnectivityManager.TYPE_MOBILE)) {
+ if (!validateNetworkStates(ConnectivityManager.TYPE_MOBILE)) {
log("Mobile state transition validation failed.");
log("reason: " +
- cmActivity.getTransitionFailureReason(ConnectivityManager.TYPE_MOBILE));
+ getTransitionFailureReason(ConnectivityManager.TYPE_MOBILE));
assertTrue(false);
}
}
@@ -330,62 +313,62 @@ public class ConnectivityManagerMobileTest extends
@LargeTest
public void testDataConnectionWith3GToAmTo3G() {
if (mWifiOnlyFlag) {
- Log.v(LOG_TAG, this.getName() + " is excluded for wifi-only test");
+ Log.v(TAG, this.getName() + " is excluded for wifi-only test");
return;
}
//Prepare for state verification
- NetworkInfo networkInfo = cmActivity.mCM.getNetworkInfo(ConnectivityManager.TYPE_MOBILE);
- cmActivity.setStateTransitionCriteria(ConnectivityManager.TYPE_MOBILE,
+ NetworkInfo networkInfo = mCM.getNetworkInfo(ConnectivityManager.TYPE_MOBILE);
+ setStateTransitionCriteria(ConnectivityManager.TYPE_MOBILE,
networkInfo.getState(),
NetworkState.TO_DISCONNECTION,
State.DISCONNECTED);
- networkInfo = cmActivity.mCM.getNetworkInfo(ConnectivityManager.TYPE_WIFI);
+ networkInfo = mCM.getNetworkInfo(ConnectivityManager.TYPE_WIFI);
assertEquals(State.DISCONNECTED, networkInfo.getState());
// Enable airplane mode
log("Enable airplane mode");
- cmActivity.setAirplaneMode(getInstrumentation().getContext(), true);
- sleep(ConnectivityManagerTestActivity.SHORT_TIMEOUT);
+ mCM.setAirplaneMode(true);
+ sleep(SHORT_TIMEOUT);
- networkInfo = cmActivity.mCM.getNetworkInfo(ConnectivityManager.TYPE_WIFI);
+ networkInfo = mCM.getNetworkInfo(ConnectivityManager.TYPE_WIFI);
assertEquals(State.DISCONNECTED, networkInfo.getState());
// wait until mobile is turn off
- assertTrue(cmActivity.waitForNetworkState(ConnectivityManager.TYPE_MOBILE,
- State.DISCONNECTED, ConnectivityManagerTestActivity.LONG_TIMEOUT));
- if (!cmActivity.validateNetworkStates(ConnectivityManager.TYPE_MOBILE)) {
+ assertTrue(waitForNetworkState(ConnectivityManager.TYPE_MOBILE,
+ State.DISCONNECTED, LONG_TIMEOUT));
+ if (!validateNetworkStates(ConnectivityManager.TYPE_MOBILE)) {
log("Mobile state transition validation failed.");
log("reason: " +
- cmActivity.getTransitionFailureReason(ConnectivityManager.TYPE_MOBILE));
+ getTransitionFailureReason(ConnectivityManager.TYPE_MOBILE));
assertTrue(false);
}
// reset state recorder
- networkInfo = cmActivity.mCM.getNetworkInfo(ConnectivityManager.TYPE_MOBILE);
- cmActivity.setStateTransitionCriteria(ConnectivityManager.TYPE_MOBILE,
+ networkInfo = mCM.getNetworkInfo(ConnectivityManager.TYPE_MOBILE);
+ setStateTransitionCriteria(ConnectivityManager.TYPE_MOBILE,
networkInfo.getState(),
NetworkState.TO_CONNECTION,
State.CONNECTED);
- networkInfo = cmActivity.mCM.getNetworkInfo(ConnectivityManager.TYPE_WIFI);
- cmActivity.setStateTransitionCriteria(ConnectivityManager.TYPE_WIFI, networkInfo.getState(),
+ networkInfo = mCM.getNetworkInfo(ConnectivityManager.TYPE_WIFI);
+ setStateTransitionCriteria(ConnectivityManager.TYPE_WIFI, networkInfo.getState(),
NetworkState.DO_NOTHING, State.DISCONNECTED);
// disable airplane mode
- cmActivity.setAirplaneMode(getInstrumentation().getContext(), false);
+ mCM.setAirplaneMode(false);
- assertTrue(cmActivity.waitForNetworkState(ConnectivityManager.TYPE_MOBILE, State.CONNECTED,
- ConnectivityManagerTestActivity.LONG_TIMEOUT));
+ assertTrue(waitForNetworkState(ConnectivityManager.TYPE_MOBILE,
+ State.CONNECTED, LONG_TIMEOUT));
// Validate the state transition
- if (!cmActivity.validateNetworkStates(ConnectivityManager.TYPE_MOBILE)) {
+ if (!validateNetworkStates(ConnectivityManager.TYPE_MOBILE)) {
log("Mobile state transition validation failed.");
log("reason: " +
- cmActivity.getTransitionFailureReason(ConnectivityManager.TYPE_MOBILE));
+ getTransitionFailureReason(ConnectivityManager.TYPE_MOBILE));
assertTrue(false);
}
- if (!cmActivity.validateNetworkStates(ConnectivityManager.TYPE_WIFI)) {
+ if (!validateNetworkStates(ConnectivityManager.TYPE_WIFI)) {
log("Wifi state transition validation failed.");
log("reason: " +
- cmActivity.getTransitionFailureReason(ConnectivityManager.TYPE_WIFI));
+ getTransitionFailureReason(ConnectivityManager.TYPE_WIFI));
assertTrue(false);
}
}
@@ -394,107 +377,107 @@ public class ConnectivityManagerMobileTest extends
@LargeTest
public void testDataConnectionOverAMWithWifi() {
if (mWifiOnlyFlag) {
- Log.v(LOG_TAG, this.getName() + " is excluded for wifi-only test");
+ Log.v(TAG, this.getName() + " is excluded for wifi-only test");
return;
}
assertNotNull("SSID is null", mTestAccessPoint);
// Eanble airplane mode
log("Enable airplane mode");
- cmActivity.setAirplaneMode(getInstrumentation().getContext(), true);
+ mCM.setAirplaneMode(true);
NetworkInfo networkInfo;
if (!mWifiOnlyFlag) {
- assertTrue(cmActivity.waitForNetworkState(ConnectivityManager.TYPE_MOBILE,
- State.DISCONNECTED, ConnectivityManagerTestActivity.LONG_TIMEOUT));
- networkInfo = cmActivity.mCM.getNetworkInfo(ConnectivityManager.TYPE_MOBILE);
- cmActivity.setStateTransitionCriteria(ConnectivityManager.TYPE_MOBILE,
+ assertTrue(waitForNetworkState(ConnectivityManager.TYPE_MOBILE,
+ State.DISCONNECTED, LONG_TIMEOUT));
+ networkInfo = mCM.getNetworkInfo(ConnectivityManager.TYPE_MOBILE);
+ setStateTransitionCriteria(ConnectivityManager.TYPE_MOBILE,
networkInfo.getState(),
NetworkState.DO_NOTHING,
State.DISCONNECTED);
}
- networkInfo = cmActivity.mCM.getNetworkInfo(ConnectivityManager.TYPE_WIFI);
- cmActivity.setStateTransitionCriteria(ConnectivityManager.TYPE_WIFI, networkInfo.getState(),
+ networkInfo = mCM.getNetworkInfo(ConnectivityManager.TYPE_WIFI);
+ setStateTransitionCriteria(ConnectivityManager.TYPE_WIFI, networkInfo.getState(),
NetworkState.TO_CONNECTION, State.CONNECTED);
// Connect to Wifi
assertTrue("failed to connect to " + mTestAccessPoint,
- cmActivity.connectToWifi(mTestAccessPoint));
- assertTrue(cmActivity.waitForNetworkState(ConnectivityManager.TYPE_WIFI, State.CONNECTED,
- ConnectivityManagerTestActivity.WIFI_CONNECTION_TIMEOUT));
+ connectToWifi(mTestAccessPoint));
+ assertTrue(waitForNetworkState(ConnectivityManager.TYPE_WIFI, State.CONNECTED,
+ WIFI_CONNECTION_TIMEOUT));
// validate state and broadcast
- if (!cmActivity.validateNetworkStates(ConnectivityManager.TYPE_WIFI)) {
+ if (!validateNetworkStates(ConnectivityManager.TYPE_WIFI)) {
log("state validate for Wifi failed");
log("reason: " +
- cmActivity.getTransitionFailureReason(ConnectivityManager.TYPE_WIFI));
+ getTransitionFailureReason(ConnectivityManager.TYPE_WIFI));
assertTrue("State validation failed", false);
}
if (!mWifiOnlyFlag) {
- if (!cmActivity.validateNetworkStates(ConnectivityManager.TYPE_MOBILE)) {
+ if (!validateNetworkStates(ConnectivityManager.TYPE_MOBILE)) {
log("state validation for Mobile failed");
log("reason: " +
- cmActivity.getTransitionFailureReason(ConnectivityManager.TYPE_MOBILE));
+ getTransitionFailureReason(ConnectivityManager.TYPE_MOBILE));
assertTrue("state validation failed", false);
}
}
- cmActivity.setAirplaneMode(getInstrumentation().getContext(), false);
+ mCM.setAirplaneMode(false);
}
// Test case 7: test connectivity while transit from Wifi->AM->Wifi
@LargeTest
public void testDataConnectionWithWifiToAMToWifi () {
if (mWifiOnlyFlag) {
- Log.v(LOG_TAG, this.getName() + " is excluded for wifi-only test");
+ Log.v(TAG, this.getName() + " is excluded for wifi-only test");
return;
}
// Connect to mTestAccessPoint
assertNotNull("SSID is null", mTestAccessPoint);
// Connect to Wifi
assertTrue("failed to connect to " + mTestAccessPoint,
- cmActivity.connectToWifi(mTestAccessPoint));
+ connectToWifi(mTestAccessPoint));
- assertTrue(cmActivity.waitForNetworkState(ConnectivityManager.TYPE_WIFI, State.CONNECTED,
- ConnectivityManagerTestActivity.WIFI_CONNECTION_TIMEOUT));
+ assertTrue(waitForNetworkState(ConnectivityManager.TYPE_WIFI, State.CONNECTED,
+ WIFI_CONNECTION_TIMEOUT));
try {
- Thread.sleep(ConnectivityManagerTestActivity.SHORT_TIMEOUT);
+ Thread.sleep(SHORT_TIMEOUT);
} catch (Exception e) {
log("exception: " + e.toString());
}
// Enable airplane mode without clearing Wifi
- cmActivity.setAirplaneMode(getInstrumentation().getContext(), true);
+ mCM.setAirplaneMode(true);
- assertTrue(cmActivity.waitForNetworkState(ConnectivityManager.TYPE_WIFI, State.DISCONNECTED,
- ConnectivityManagerTestActivity.LONG_TIMEOUT));
+ assertTrue(waitForNetworkState(ConnectivityManager.TYPE_WIFI,
+ State.DISCONNECTED, LONG_TIMEOUT));
try {
- Thread.sleep(ConnectivityManagerTestActivity.SHORT_TIMEOUT);
+ Thread.sleep(SHORT_TIMEOUT);
} catch (Exception e) {
log("exception: " + e.toString());
}
// Prepare for state validation
- NetworkInfo networkInfo = cmActivity.mCM.getNetworkInfo(ConnectivityManager.TYPE_WIFI);
+ NetworkInfo networkInfo = mCM.getNetworkInfo(ConnectivityManager.TYPE_WIFI);
assertEquals(State.DISCONNECTED, networkInfo.getState());
- cmActivity.setStateTransitionCriteria(ConnectivityManager.TYPE_WIFI,
+ setStateTransitionCriteria(ConnectivityManager.TYPE_WIFI,
networkInfo.getState(), NetworkState.TO_CONNECTION, State.CONNECTED);
// Disable airplane mode
- cmActivity.setAirplaneMode(getInstrumentation().getContext(), false);
+ mCM.setAirplaneMode(false);
- assertTrue(cmActivity.waitForNetworkState(ConnectivityManager.TYPE_WIFI, State.CONNECTED,
- ConnectivityManagerTestActivity.WIFI_CONNECTION_TIMEOUT));
+ assertTrue(waitForNetworkState(ConnectivityManager.TYPE_WIFI, State.CONNECTED,
+ WIFI_CONNECTION_TIMEOUT));
if (!mWifiOnlyFlag) {
- assertTrue(cmActivity.waitForNetworkState(ConnectivityManager.TYPE_MOBILE,
- State.DISCONNECTED, ConnectivityManagerTestActivity.LONG_TIMEOUT));
+ assertTrue(waitForNetworkState(ConnectivityManager.TYPE_MOBILE,
+ State.DISCONNECTED, LONG_TIMEOUT));
}
// validate the state transition
- if (!cmActivity.validateNetworkStates(ConnectivityManager.TYPE_WIFI)) {
+ if (!validateNetworkStates(ConnectivityManager.TYPE_WIFI)) {
log("Wifi state transition validation failed.");
log("reason: " +
- cmActivity.getTransitionFailureReason(ConnectivityManager.TYPE_WIFI));
+ getTransitionFailureReason(ConnectivityManager.TYPE_WIFI));
assertTrue(false);
}
}
@@ -505,35 +488,33 @@ public class ConnectivityManagerMobileTest extends
assertNotNull("SSID is null", mTestAccessPoint);
//Connect to mTestAccessPoint
assertTrue("failed to connect to " + mTestAccessPoint,
- cmActivity.connectToWifi(mTestAccessPoint));
- assertTrue(cmActivity.waitForWifiState(WifiManager.WIFI_STATE_ENABLED,
- ConnectivityManagerTestActivity.LONG_TIMEOUT));
- assertTrue(cmActivity.waitForNetworkState(ConnectivityManager.TYPE_WIFI, State.CONNECTED,
- ConnectivityManagerTestActivity.WIFI_CONNECTION_TIMEOUT));
+ connectToWifi(mTestAccessPoint));
+ assertTrue(waitForWifiState(WifiManager.WIFI_STATE_ENABLED, LONG_TIMEOUT));
+ assertTrue(waitForNetworkState(ConnectivityManager.TYPE_WIFI, State.CONNECTED,
+ WIFI_CONNECTION_TIMEOUT));
assertNotNull("Not associated with any AP",
- cmActivity.mWifiManager.getConnectionInfo().getBSSID());
+ mWifiManager.getConnectionInfo().getBSSID());
try {
- Thread.sleep(ConnectivityManagerTestActivity.SHORT_TIMEOUT);
+ Thread.sleep(SHORT_TIMEOUT);
} catch (Exception e) {
log("exception: " + e.toString());
}
// Disconnect from the current AP
log("disconnect from the AP");
- if (!cmActivity.disconnectAP()) {
+ if (!disconnectAP()) {
log("failed to disconnect from " + mTestAccessPoint);
}
// Verify the connectivity state for Wifi is DISCONNECTED
- assertTrue(cmActivity.waitForNetworkState(ConnectivityManager.TYPE_WIFI, State.DISCONNECTED,
- ConnectivityManagerTestActivity.LONG_TIMEOUT));
+ assertTrue(waitForNetworkState(ConnectivityManager.TYPE_WIFI,
+ State.DISCONNECTED, LONG_TIMEOUT));
- if (!cmActivity.disableWifi()) {
+ if (!disableWifi()) {
log("disable Wifi failed");
return;
}
- assertTrue(cmActivity.waitForWifiState(WifiManager.WIFI_STATE_DISABLED,
- ConnectivityManagerTestActivity.LONG_TIMEOUT));
+ assertTrue(waitForWifiState(WifiManager.WIFI_STATE_DISABLED, LONG_TIMEOUT));
}
}
diff --git a/core/tests/ConnectivityManagerTest/src/com/android/connectivitymanagertest/functional/WifiAssociationTest.java b/core/tests/ConnectivityManagerTest/src/com/android/connectivitymanagertest/functional/WifiAssociationTest.java
index f12e62e..183f2a9 100644
--- a/core/tests/ConnectivityManagerTest/src/com/android/connectivitymanagertest/functional/WifiAssociationTest.java
+++ b/core/tests/ConnectivityManagerTest/src/com/android/connectivitymanagertest/functional/WifiAssociationTest.java
@@ -16,7 +16,7 @@
package com.android.connectivitymanagertest.functional;
-import com.android.connectivitymanagertest.ConnectivityManagerTestActivity;
+import com.android.connectivitymanagertest.ConnectivityManagerTestBase;
import com.android.connectivitymanagertest.WifiAssociationTestRunner;
import android.content.Context;
@@ -32,7 +32,6 @@ import android.net.wifi.WifiManager;
import android.net.ConnectivityManager;
import android.net.NetworkInfo.State;
import android.test.suitebuilder.annotation.LargeTest;
-import android.test.ActivityInstrumentationTestCase2;
import android.util.Log;
/**
@@ -43,30 +42,22 @@ import android.util.Log;
* -w com.android.connectivitymanagertest/.WifiAssociationTestRunner"
*/
public class WifiAssociationTest
- extends ActivityInstrumentationTestCase2<ConnectivityManagerTestActivity> {
+ extends ConnectivityManagerTestBase {
private static final String TAG = "WifiAssociationTest";
- private ConnectivityManagerTestActivity mAct;
private String mSsid = null;
private String mPassword = null;
private String mSecurityType = null;
private String mFrequencyBand = null;
private int mBand;
- private WifiManager mWifiManager = null;
enum SECURITY_TYPE {
OPEN, WEP64, WEP128, WPA_TKIP, WPA2_AES
- };
-
- public WifiAssociationTest() {
- super(ConnectivityManagerTestActivity.class);
}
@Override
public void setUp() throws Exception {
super.setUp();
WifiAssociationTestRunner mRunner = (WifiAssociationTestRunner)getInstrumentation();
- mWifiManager = (WifiManager) mRunner.getContext().getSystemService(Context.WIFI_SERVICE);
- mAct = getActivity();
Bundle arguments = mRunner.getArguments();
mSecurityType = arguments.getString("security-type");
mSsid = arguments.getString("ssid");
@@ -77,17 +68,15 @@ public class WifiAssociationTest
assertNotNull("Ssid is empty", mSsid);
validateFrequencyBand();
// enable Wifi and verify wpa_supplicant is started
- assertTrue("enable Wifi failed", mAct.enableWifi());
- sleep(2 * ConnectivityManagerTestActivity.SHORT_TIMEOUT,
- "interrupted while waiting for WPA_SUPPLICANT to start");
- WifiInfo mConnection = mAct.mWifiManager.getConnectionInfo();
+ assertTrue("enable Wifi failed", enableWifi());
+ sleep(2 * SHORT_TIMEOUT, "interrupted while waiting for WPA_SUPPLICANT to start");
+ WifiInfo mConnection = mWifiManager.getConnectionInfo();
assertNotNull(mConnection);
- assertTrue("wpa_supplicant is not started ", mAct.mWifiManager.pingSupplicant());
+ assertTrue("wpa_supplicant is not started ", mWifiManager.pingSupplicant());
}
@Override
public void tearDown() throws Exception {
- log("tearDown()");
super.tearDown();
}
@@ -107,16 +96,16 @@ public class WifiAssociationTest
private void connectToWifi(WifiConfiguration config) {
// step 1: connect to the test access point
assertTrue("failed to associate with " + config.SSID,
- mAct.connectToWifiWithConfiguration(config));
+ connectToWifiWithConfiguration(config));
// step 2: verify Wifi state and network state;
assertTrue("failed to connect with " + config.SSID,
- mAct.waitForNetworkState(ConnectivityManager.TYPE_WIFI,
- State.CONNECTED, ConnectivityManagerTestActivity.WIFI_CONNECTION_TIMEOUT));
+ waitForNetworkState(ConnectivityManager.TYPE_WIFI,
+ State.CONNECTED, WIFI_CONNECTION_TIMEOUT));
// step 3: verify the current connected network is the given SSID
- assertNotNull("Wifi connection returns null", mAct.mWifiManager.getConnectionInfo());
- assertTrue(config.SSID.contains(mAct.mWifiManager.getConnectionInfo().getSSID()));
+ assertNotNull("Wifi connection returns null", mWifiManager.getConnectionInfo());
+ assertTrue(config.SSID.contains(mWifiManager.getConnectionInfo().getSSID()));
}
private void sleep(long sometime, String errorMsg) {
diff --git a/core/tests/ConnectivityManagerTest/src/com/android/connectivitymanagertest/functional/WifiConnectionTest.java b/core/tests/ConnectivityManagerTest/src/com/android/connectivitymanagertest/functional/WifiConnectionTest.java
index de0298e..ad73ee1 100644
--- a/core/tests/ConnectivityManagerTest/src/com/android/connectivitymanagertest/functional/WifiConnectionTest.java
+++ b/core/tests/ConnectivityManagerTest/src/com/android/connectivitymanagertest/functional/WifiConnectionTest.java
@@ -16,35 +16,19 @@
package com.android.connectivitymanagertest.functional;
-import com.android.connectivitymanagertest.ConnectivityManagerTestActivity;
+import com.android.connectivitymanagertest.ConnectivityManagerTestBase;
import com.android.connectivitymanagertest.ConnectivityManagerTestRunner;
-import android.R;
-import android.app.Activity;
-import android.content.ContentResolver;
-import android.content.Intent;
import android.content.Context;
-import android.content.res.Resources;
import android.net.wifi.WifiConfiguration;
-import android.net.wifi.WifiConfiguration.KeyMgmt;
-import android.net.wifi.WifiConfiguration.Status;
import android.net.wifi.WifiInfo;
import android.net.wifi.WifiManager;
import android.net.ConnectivityManager;
-import android.net.DhcpInfo;
-import android.net.NetworkInfo;
import android.net.NetworkInfo.State;
-import android.os.Handler;
-import android.os.Message;
-import android.provider.Settings;
import android.test.suitebuilder.annotation.LargeTest;
-import android.test.ActivityInstrumentationTestCase2;
import android.util.Log;
-import com.android.internal.util.AsyncChannel;
-
import java.util.ArrayList;
-import java.util.HashSet;
import java.util.List;
import java.util.Set;
@@ -56,39 +40,25 @@ import java.util.Set;
* -w com.android.connectivitymanagertest/.ConnectivityManagerTestRunner
*/
public class WifiConnectionTest
- extends ActivityInstrumentationTestCase2<ConnectivityManagerTestActivity> {
+ extends ConnectivityManagerTestBase {
private static final String TAG = "WifiConnectionTest";
private static final boolean DEBUG = false;
private List<WifiConfiguration> networks = new ArrayList<WifiConfiguration>();
- private ConnectivityManagerTestActivity mAct;
- private ConnectivityManagerTestRunner mRunner;
- private WifiManager mWifiManager = null;
- private Set<WifiConfiguration> enabledNetworks = null;
-
- public WifiConnectionTest() {
- super(ConnectivityManagerTestActivity.class);
- }
@Override
public void setUp() throws Exception {
super.setUp();
- mRunner = ((ConnectivityManagerTestRunner)getInstrumentation());
- mWifiManager = (WifiManager) mRunner.getContext().getSystemService(Context.WIFI_SERVICE);
-
- mAct = getActivity();
-
- networks = mAct.loadNetworkConfigurations();
+ networks = loadNetworkConfigurations();
if (DEBUG) {
printNetworkConfigurations();
}
// enable Wifi and verify wpa_supplicant is started
- assertTrue("enable Wifi failed", mAct.enableWifi());
- sleep(2 * ConnectivityManagerTestActivity.SHORT_TIMEOUT,
- "interrupted while waiting for WPA_SUPPLICANT to start");
- WifiInfo mConnection = mAct.mWifiManager.getConnectionInfo();
+ assertTrue("enable Wifi failed", enableWifi());
+ sleep(2 * SHORT_TIMEOUT, "interrupted while waiting for WPA_SUPPLICANT to start");
+ WifiInfo mConnection = mWifiManager.getConnectionInfo();
assertNotNull(mConnection);
- assertTrue("wpa_supplicant is not started ", mAct.mWifiManager.pingSupplicant());
+ assertTrue("wpa_supplicant is not started ", mWifiManager.pingSupplicant());
}
private void printNetworkConfigurations() {
@@ -101,8 +71,7 @@ public class WifiConnectionTest
@Override
public void tearDown() throws Exception {
- log("tearDown()");
- mAct.removeConfiguredNetworksAndDisableWifi();
+ removeConfiguredNetworksAndDisableWifi();
super.tearDown();
}
@@ -114,20 +83,20 @@ public class WifiConnectionTest
private void connectToWifi(WifiConfiguration config) {
// step 1: connect to the test access point
assertTrue("failed to connect to " + config.SSID,
- mAct.connectToWifiWithConfiguration(config));
+ connectToWifiWithConfiguration(config));
// step 2: verify Wifi state and network state;
- assertTrue(mAct.waitForNetworkState(ConnectivityManager.TYPE_WIFI,
- State.CONNECTED, ConnectivityManagerTestActivity.WIFI_CONNECTION_TIMEOUT));
+ assertTrue(waitForNetworkState(ConnectivityManager.TYPE_WIFI,
+ State.CONNECTED, WIFI_CONNECTION_TIMEOUT));
// step 3: verify the current connected network is the given SSID
- assertNotNull("Wifi connection returns null", mAct.mWifiManager.getConnectionInfo());
+ assertNotNull("Wifi connection returns null", mWifiManager.getConnectionInfo());
if (DEBUG) {
log("config.SSID = " + config.SSID);
- log("mAct.mWifiManager.getConnectionInfo.getSSID()" +
- mAct.mWifiManager.getConnectionInfo().getSSID());
+ log("mWifiManager.getConnectionInfo.getSSID()" +
+ mWifiManager.getConnectionInfo().getSSID());
}
- assertTrue(config.SSID.contains(mAct.mWifiManager.getConnectionInfo().getSSID()));
+ assertTrue(config.SSID.contains(mWifiManager.getConnectionInfo().getSSID()));
}
private void sleep(long sometime, String errorMsg) {
@@ -149,8 +118,7 @@ public class WifiConnectionTest
log("-- START Wi-Fi connection test to : " + ssid + " --");
connectToWifi(networks.get(i));
// wait for 2 minutes between wifi stop and start
- sleep(ConnectivityManagerTestActivity.WIFI_STOP_START_INTERVAL,
- "interruped while connected to wifi");
+ sleep(WIFI_STOP_START_INTERVAL, "interruped while connected to wifi");
log("-- END Wi-Fi connection test to " + ssid + " -- ");
}
}
diff --git a/core/tests/ConnectivityManagerTest/src/com/android/connectivitymanagertest/stress/WifiApStress.java b/core/tests/ConnectivityManagerTest/src/com/android/connectivitymanagertest/stress/WifiApStress.java
index 60595fb..790ca38 100644
--- a/core/tests/ConnectivityManagerTest/src/com/android/connectivitymanagertest/stress/WifiApStress.java
+++ b/core/tests/ConnectivityManagerTest/src/com/android/connectivitymanagertest/stress/WifiApStress.java
@@ -18,19 +18,13 @@ package com.android.connectivitymanagertest.stress;
import com.android.connectivitymanagertest.ConnectivityManagerStressTestRunner;
-import com.android.connectivitymanagertest.ConnectivityManagerTestActivity;
+import com.android.connectivitymanagertest.ConnectivityManagerTestBase;
-import android.content.Context;
import android.net.wifi.WifiConfiguration;
import android.net.wifi.WifiConfiguration.KeyMgmt;
import android.net.wifi.WifiConfiguration.AuthAlgorithm;
import android.net.wifi.WifiManager;
import android.os.Environment;
-import android.os.IPowerManager;
-import android.os.PowerManager;
-import android.os.ServiceManager;
-import android.os.SystemClock;
-import android.test.ActivityInstrumentationTestCase2;
import android.test.suitebuilder.annotation.LargeTest;
import android.util.Log;
@@ -42,30 +36,24 @@ import java.io.FileWriter;
* Stress the wifi driver as access point.
*/
public class WifiApStress
- extends ActivityInstrumentationTestCase2<ConnectivityManagerTestActivity> {
+ extends ConnectivityManagerTestBase {
private final static String TAG = "WifiApStress";
private static String NETWORK_ID = "AndroidAPTest";
private static String PASSWD = "androidwifi";
private final static String OUTPUT_FILE = "WifiStressTestOutput.txt";
- private ConnectivityManagerTestActivity mAct;
private int iterations;
private BufferedWriter mOutputWriter = null;
private int mLastIteration = 0;
private boolean mWifiOnlyFlag;
- public WifiApStress() {
- super(ConnectivityManagerTestActivity.class);
- }
-
@Override
public void setUp() throws Exception {
super.setUp();
- mAct = getActivity();
ConnectivityManagerStressTestRunner mRunner =
(ConnectivityManagerStressTestRunner)getInstrumentation();
iterations = mRunner.mSoftapIterations;
mWifiOnlyFlag = mRunner.mWifiOnlyFlag;
- mAct.turnScreenOn();
+ turnScreenOn();
}
@Override
@@ -92,30 +80,28 @@ public class WifiApStress
config.preSharedKey = PASSWD;
// If Wifi is enabled, disable it
- if (mAct.mWifiManager.isWifiEnabled()) {
- mAct.disableWifi();
+ if (mWifiManager.isWifiEnabled()) {
+ disableWifi();
}
int i;
for (i = 0; i < iterations; i++) {
Log.v(TAG, "iteration: " + i);
mLastIteration = i;
// enable Wifi tethering
- assertTrue(mAct.mWifiManager.setWifiApEnabled(config, true));
+ assertTrue(mWifiManager.setWifiApEnabled(config, true));
// Wait for wifi ap state to be ENABLED
- assertTrue(mAct.waitForWifiAPState(WifiManager.WIFI_AP_STATE_ENABLED,
- 2 * ConnectivityManagerTestActivity.LONG_TIMEOUT));
+ assertTrue(waitForWifiAPState(WifiManager.WIFI_AP_STATE_ENABLED, 2 * LONG_TIMEOUT));
// Wait for wifi tethering result
- assertEquals(ConnectivityManagerTestActivity.SUCCESS,
- mAct.waitForTetherStateChange(2*ConnectivityManagerTestActivity.SHORT_TIMEOUT));
+ assertEquals(SUCCESS, waitForTetherStateChange(2 * SHORT_TIMEOUT));
// Allow the wifi tethering to be enabled for 10 seconds
try {
- Thread.sleep(2 * ConnectivityManagerTestActivity.SHORT_TIMEOUT);
+ Thread.sleep(2 * SHORT_TIMEOUT);
} catch (Exception e) {
fail("thread in sleep is interrupted");
}
- assertTrue("no uplink data connection after Wi-Fi tethering", mAct.pingTest(null));
+ assertTrue("no uplink data connection after Wi-Fi tethering", pingTest(null));
// Disable soft AP
- assertTrue(mAct.mWifiManager.setWifiApEnabled(config, false));
+ assertTrue(mWifiManager.setWifiApEnabled(config, false));
// Wait for 30 seconds until Wi-Fi tethering is stopped
try {
Thread.sleep(30 * 1000);
@@ -123,7 +109,7 @@ public class WifiApStress
} catch (Exception e) {
fail("thread in sleep is interrupted");
}
- assertFalse("Wi-Fi AP disable failed", mAct.mWifiManager.isWifiApEnabled());
+ assertFalse("Wi-Fi AP disable failed", mWifiManager.isWifiApEnabled());
}
if (i == iterations) {
mLastIteration = iterations;
diff --git a/core/tests/ConnectivityManagerTest/src/com/android/connectivitymanagertest/stress/WifiStressTest.java b/core/tests/ConnectivityManagerTest/src/com/android/connectivitymanagertest/stress/WifiStressTest.java
index e3c7cc4..04ce4b7 100644
--- a/core/tests/ConnectivityManagerTest/src/com/android/connectivitymanagertest/stress/WifiStressTest.java
+++ b/core/tests/ConnectivityManagerTest/src/com/android/connectivitymanagertest/stress/WifiStressTest.java
@@ -29,12 +29,11 @@ import android.os.Environment;
import android.os.PowerManager;
import android.provider.Settings;
import android.view.KeyEvent;
-import android.test.ActivityInstrumentationTestCase2;
import android.test.suitebuilder.annotation.LargeTest;
import android.util.Log;
import com.android.connectivitymanagertest.ConnectivityManagerStressTestRunner;
-import com.android.connectivitymanagertest.ConnectivityManagerTestActivity;
+import com.android.connectivitymanagertest.ConnectivityManagerTestBase;
import java.io.BufferedWriter;
import java.io.File;
@@ -50,7 +49,7 @@ import java.util.List;
* -w com.android.connectivitymanagertest/.ConnectivityManagerStressTestRunner
*/
public class WifiStressTest
- extends ActivityInstrumentationTestCase2<ConnectivityManagerTestActivity> {
+ extends ConnectivityManagerTestBase {
private final static String TAG = "WifiStressTest";
/**
@@ -67,7 +66,6 @@ public class WifiStressTest
private final static long WIFI_SHUTDOWN_DELAY = 2 * 60 * 1000;
private final static String OUTPUT_FILE = "WifiStressTestOutput.txt";
- private ConnectivityManagerTestActivity mAct;
private int mReconnectIterations;
private int mWifiSleepTime;
private int mScanIterations;
@@ -77,15 +75,10 @@ public class WifiStressTest
private BufferedWriter mOutputWriter = null;
private boolean mWifiOnlyFlag;
- public WifiStressTest() {
- super(ConnectivityManagerTestActivity.class);
- }
-
@Override
public void setUp() throws Exception {
super.setUp();
- mAct = getActivity();
mRunner = (ConnectivityManagerStressTestRunner) getInstrumentation();
mReconnectIterations = mRunner.mReconnectIterations;
mSsid = mRunner.mReconnectSsid;
@@ -98,15 +91,14 @@ public class WifiStressTest
mPassword, mScanIterations, mWifiSleepTime));
mOutputWriter = new BufferedWriter(new FileWriter(new File(
Environment.getExternalStorageDirectory(), OUTPUT_FILE), true));
- mAct.turnScreenOn();
- if (!mAct.mWifiManager.isWifiEnabled()) {
+ turnScreenOn();
+ if (!mWifiManager.isWifiEnabled()) {
log("Enable wi-fi before stress tests.");
- if (!mAct.enableWifi()) {
+ if (!enableWifi()) {
tearDown();
fail("enable wifi failed.");
}
- sleep(ConnectivityManagerTestActivity.SHORT_TIMEOUT,
- "Interruped while waiting for wifi on");
+ sleep(SHORT_TIMEOUT, "Interruped while waiting for wifi on");
}
}
@@ -166,33 +158,32 @@ public class WifiStressTest
writeOutput(String.format("ssid appear %d out of %d scan iterations",
ssidAppearInScanResultsCount, i));
long startTime = System.currentTimeMillis();
- mAct.scanResultAvailable = false;
- assertTrue("start scan failed", mAct.mWifiManager.startScan());
+ scanResultAvailable = false;
+ assertTrue("start scan failed", mWifiManager.startScan());
while (true) {
if ((System.currentTimeMillis() - startTime) >
- ConnectivityManagerTestActivity.WIFI_SCAN_TIMEOUT) {
- fail("Wifi scanning takes more than " +
- ConnectivityManagerTestActivity.WIFI_SCAN_TIMEOUT + " ms");
+ WIFI_SCAN_TIMEOUT) {
+ fail("Wifi scanning takes more than " + WIFI_SCAN_TIMEOUT + " ms");
}
- synchronized(mAct) {
+ synchronized(this) {
try {
- mAct.wait(ConnectivityManagerTestActivity.WAIT_FOR_SCAN_RESULT);
+ wait(WAIT_FOR_SCAN_RESULT);
} catch (InterruptedException e) {
e.printStackTrace();
}
- if (mAct.scanResultAvailable) {
+ if (scanResultAvailable) {
long scanTime = (System.currentTimeMillis() - startTime);
scanTimeSum += scanTime;
break;
}
}
}
- if ((mAct.mWifiManager.getScanResults() == null) ||
- (mAct.mWifiManager.getScanResults().size() <= 0)) {
+ if ((mWifiManager.getScanResults() == null) ||
+ (mWifiManager.getScanResults().size() <= 0)) {
fail("Scan results are empty ");
}
- List<ScanResult> netList = mAct.mWifiManager.getScanResults();
+ List<ScanResult> netList = mWifiManager.getScanResults();
if (netList != null) {
log("size of scan result list: " + netList.size());
for (int s = 0; s < netList.size(); s++) {
@@ -244,13 +235,13 @@ public class WifiStressTest
config.proxySettings = ProxySettings.NONE;
assertTrue("Failed to connect to Wi-Fi network: " + mSsid,
- mAct.connectToWifiWithConfiguration(config));
- assertTrue(mAct.waitForWifiState(WifiManager.WIFI_STATE_ENABLED,
- ConnectivityManagerTestActivity.SHORT_TIMEOUT));
- assertTrue(mAct.waitForNetworkState(ConnectivityManager.TYPE_WIFI, State.CONNECTED,
- ConnectivityManagerTestActivity.WIFI_CONNECTION_TIMEOUT));
+ connectToWifiWithConfiguration(config));
+ assertTrue(waitForWifiState(WifiManager.WIFI_STATE_ENABLED,
+ SHORT_TIMEOUT));
+ assertTrue(waitForNetworkState(ConnectivityManager.TYPE_WIFI, State.CONNECTED,
+ WIFI_CONNECTION_TIMEOUT));
// Run ping test to verify the data connection
- assertTrue("Wi-Fi is connected, but no data connection.", mAct.pingTest(null));
+ assertTrue("Wi-Fi is connected, but no data connection.", pingTest(null));
int i;
long sum = 0;
@@ -263,33 +254,33 @@ public class WifiStressTest
writeOutput(String.format("iteration %d out of %d",
i, mReconnectIterations));
log("iteration: " + i);
- mAct.turnScreenOff();
+ turnScreenOff();
PowerManager pm =
(PowerManager)mRunner.getContext().getSystemService(Context.POWER_SERVICE);
assertFalse(pm.isScreenOn());
sleep(WIFI_IDLE_MS + WIFI_SHUTDOWN_DELAY, "Interruped while wait for wifi to be idle");
assertTrue("Wait for Wi-Fi to idle timeout",
- mAct.waitForNetworkState(ConnectivityManager.TYPE_WIFI, State.DISCONNECTED,
- 6 * ConnectivityManagerTestActivity.SHORT_TIMEOUT));
+ waitForNetworkState(ConnectivityManager.TYPE_WIFI, State.DISCONNECTED,
+ 6 * SHORT_TIMEOUT));
if (!mWifiOnlyFlag) {
// use long timeout as the pppd startup may take several retries.
assertTrue("Wait for cellular connection timeout",
- mAct.waitForNetworkState(ConnectivityManager.TYPE_MOBILE, State.CONNECTED,
- 2 * ConnectivityManagerTestActivity.LONG_TIMEOUT));
+ waitForNetworkState(ConnectivityManager.TYPE_MOBILE, State.CONNECTED,
+ 2 * LONG_TIMEOUT));
}
sleep(mWifiSleepTime, "Interrupted while device is in sleep mode");
// Verify the wi-fi is still off and data connection is on
assertEquals("Wi-Fi is reconnected", State.DISCONNECTED,
- mAct.mCM.getNetworkInfo(ConnectivityManager.TYPE_WIFI).getState());
+ mCM.getNetworkInfo(ConnectivityManager.TYPE_WIFI).getState());
if (!mWifiOnlyFlag) {
assertEquals("Cellular connection is down", State.CONNECTED,
- mAct.mCM.getNetworkInfo(ConnectivityManager.TYPE_MOBILE).getState());
- assertTrue("Mobile is connected, but no data connection.", mAct.pingTest(null));
+ mCM.getNetworkInfo(ConnectivityManager.TYPE_MOBILE).getState());
+ assertTrue("Mobile is connected, but no data connection.", pingTest(null));
}
// Turn screen on again
- mAct.turnScreenOn();
+ turnScreenOn();
// Wait for 2 seconds for the lock screen
sleep(2 * 1000, "wait 2 seconds for lock screen");
// Disable lock screen by inject menu key event
@@ -298,16 +289,16 @@ public class WifiStressTest
// Measure the time for Wi-Fi to get connected
long startTime = System.currentTimeMillis();
assertTrue("Wait for Wi-Fi enable timeout after wake up",
- mAct.waitForWifiState(WifiManager.WIFI_STATE_ENABLED,
- ConnectivityManagerTestActivity.SHORT_TIMEOUT));
+ waitForWifiState(WifiManager.WIFI_STATE_ENABLED,
+ SHORT_TIMEOUT));
assertTrue("Wait for Wi-Fi connection timeout after wake up",
- mAct.waitForNetworkState(ConnectivityManager.TYPE_WIFI, State.CONNECTED,
- ConnectivityManagerTestActivity.WIFI_CONNECTION_TIMEOUT));
+ waitForNetworkState(ConnectivityManager.TYPE_WIFI, State.CONNECTED,
+ WIFI_CONNECTION_TIMEOUT));
long connectionTime = System.currentTimeMillis() - startTime;
sum += connectionTime;
log("average reconnection time is: " + sum/(i+1));
- assertTrue("Reconnect to Wi-Fi network, but no data connection.", mAct.pingTest(null));
+ assertTrue("Reconnect to Wi-Fi network, but no data connection.", pingTest(null));
}
if (i == mReconnectIterations) {
writeOutput(String.format("iteration %d out of %d",
diff --git a/core/tests/ConnectivityManagerTest/src/com/android/connectivitymanagertest/unit/WifiClientTest.java b/core/tests/ConnectivityManagerTest/src/com/android/connectivitymanagertest/unit/WifiClientTest.java
index e44023b..7a9bc78 100644
--- a/core/tests/ConnectivityManagerTest/src/com/android/connectivitymanagertest/unit/WifiClientTest.java
+++ b/core/tests/ConnectivityManagerTest/src/com/android/connectivitymanagertest/unit/WifiClientTest.java
@@ -20,9 +20,6 @@ import android.content.BroadcastReceiver;
import android.content.Intent;
import android.content.IntentFilter;
import android.content.Context;
-import android.app.Instrumentation;
-import android.os.Handler;
-import android.os.Message;
import android.net.NetworkInfo;
import android.net.wifi.WifiManager;
import android.net.wifi.WifiConfiguration;
@@ -33,11 +30,8 @@ import android.net.wifi.SupplicantState;
import android.test.suitebuilder.annotation.LargeTest;
import android.test.AndroidTestCase;
-import java.util.ArrayList;
import java.util.List;
-import android.util.Log;
-
/**
* Test wifi client
*/
diff --git a/core/tests/ConnectivityManagerTest/src/com/android/connectivitymanagertest/unit/WifiSoftAPTest.java b/core/tests/ConnectivityManagerTest/src/com/android/connectivitymanagertest/unit/WifiSoftAPTest.java
index 3f43e48..f202862 100644
--- a/core/tests/ConnectivityManagerTest/src/com/android/connectivitymanagertest/unit/WifiSoftAPTest.java
+++ b/core/tests/ConnectivityManagerTest/src/com/android/connectivitymanagertest/unit/WifiSoftAPTest.java
@@ -16,13 +16,7 @@
package com.android.connectivitymanagertest.unit;
-import android.content.BroadcastReceiver;
-import android.content.Intent;
import android.content.Context;
-import android.app.Instrumentation;
-import android.os.Handler;
-import android.os.Message;
-import android.net.ConnectivityManager;
import android.net.wifi.WifiManager;
import android.net.wifi.WifiConfiguration;
import android.net.wifi.WifiConfiguration.KeyMgmt;
@@ -30,8 +24,6 @@ import android.net.wifi.WifiConfiguration.KeyMgmt;
import android.test.suitebuilder.annotation.LargeTest;
import android.test.AndroidTestCase;
-import java.util.ArrayList;
-
import android.util.Log;
/**
diff --git a/core/tests/bandwidthtests/src/com/android/bandwidthtest/BandwidthTest.java b/core/tests/bandwidthtests/src/com/android/bandwidthtest/BandwidthTest.java
index 76b702e..4a58f88 100644
--- a/core/tests/bandwidthtests/src/com/android/bandwidthtest/BandwidthTest.java
+++ b/core/tests/bandwidthtests/src/com/android/bandwidthtest/BandwidthTest.java
@@ -36,8 +36,6 @@ import com.android.bandwidthtest.util.BandwidthTestUtil;
import com.android.bandwidthtest.util.ConnectionUtil;
import java.io.File;
-import java.util.HashMap;
-import java.util.Map;
/**
* Test that downloads files from a test server and reports the bandwidth metrics collected.
@@ -131,8 +129,8 @@ public class BandwidthTest extends InstrumentationTestCase {
results.putString("device_id", mDeviceId);
results.putString("timestamp", ts);
results.putInt("size", FILE_SIZE);
- AddStatsToResults(PROF_LABEL, prof_stats, results);
- AddStatsToResults(PROC_LABEL, proc_stats, results);
+ addStatsToResults(PROF_LABEL, prof_stats, results, mUid);
+ addStatsToResults(PROC_LABEL, proc_stats, results, mUid);
getInstrumentation().sendStatus(INSTRUMENTATION_IN_PROGRESS, results);
// Clean up.
@@ -185,8 +183,8 @@ public class BandwidthTest extends InstrumentationTestCase {
results.putString("device_id", mDeviceId);
results.putString("timestamp", ts);
results.putInt("size", FILE_SIZE);
- AddStatsToResults(PROF_LABEL, prof_stats, results);
- AddStatsToResults(PROC_LABEL, proc_stats, results);
+ addStatsToResults(PROF_LABEL, prof_stats, results, mUid);
+ addStatsToResults(PROC_LABEL, proc_stats, results, mUid);
getInstrumentation().sendStatus(INSTRUMENTATION_IN_PROGRESS, results);
// Clean up.
@@ -242,8 +240,9 @@ public class BandwidthTest extends InstrumentationTestCase {
results.putString("device_id", mDeviceId);
results.putString("timestamp", ts);
results.putInt("size", FILE_SIZE);
- AddStatsToResults(PROF_LABEL, prof_stats, results);
- AddStatsToResults(PROC_LABEL, proc_stats, results);
+ addStatsToResults(PROF_LABEL, prof_stats, results, mUid);
+ // remember to use download manager uid for proc stats
+ addStatsToResults(PROC_LABEL, proc_stats, results, downloadManagerUid);
getInstrumentation().sendStatus(INSTRUMENTATION_IN_PROGRESS, results);
// Clean up.
@@ -302,46 +301,35 @@ public class BandwidthTest extends InstrumentationTestCase {
* @param label to attach to this given stats.
* @param stats {@link NetworkStats} to add.
* @param results {@link Bundle} to be added to.
+ * @param uid for which to report the results.
*/
- public void AddStatsToResults(String label, NetworkStats stats, Bundle results){
+ public void addStatsToResults(String label, NetworkStats stats, Bundle results, int uid){
if (results == null || results.isEmpty()) {
Log.e(LOG_TAG, "Empty bundle provided.");
return;
}
- // Merge stats across all sets.
- Map<Integer, Entry> totalStats = new HashMap<Integer, Entry>();
+ Entry totalStats = null;
for (int i = 0; i < stats.size(); ++i) {
Entry statsEntry = stats.getValues(i, null);
// We are only interested in the all inclusive stats.
if (statsEntry.tag != 0) {
continue;
}
- Entry mapEntry = null;
- if (totalStats.containsKey(statsEntry.uid)) {
- mapEntry = totalStats.get(statsEntry.uid);
- switch (statsEntry.set) {
- case NetworkStats.SET_ALL:
- mapEntry.rxBytes = statsEntry.rxBytes;
- mapEntry.txBytes = statsEntry.txBytes;
- break;
- case NetworkStats.SET_DEFAULT:
- case NetworkStats.SET_FOREGROUND:
- mapEntry.rxBytes += statsEntry.rxBytes;
- mapEntry.txBytes += statsEntry.txBytes;
- break;
- default:
- Log.w(LOG_TAG, "Invalid state found in NetworkStats.");
- }
+ // skip stats for other uids
+ if (statsEntry.uid != uid) {
+ continue;
+ }
+ if (totalStats == null || statsEntry.set == NetworkStats.SET_ALL) {
+ totalStats = statsEntry;
} else {
- totalStats.put(statsEntry.uid, statsEntry);
+ totalStats.rxBytes += statsEntry.rxBytes;
+ totalStats.txBytes += statsEntry.txBytes;
}
}
- // Ouput merged stats to bundle.
- for (Entry entry : totalStats.values()) {
- results.putInt(label + "uid", entry.uid);
- results.putLong(label + "tx", entry.txBytes);
- results.putLong(label + "rx", entry.rxBytes);
- }
+ // Output merged stats to bundle.
+ results.putInt(label + "uid", totalStats.uid);
+ results.putLong(label + "tx", totalStats.txBytes);
+ results.putLong(label + "rx", totalStats.rxBytes);
}
/**
diff --git a/core/tests/coretests/src/android/webkit/AccessibilityInjectorTestActivity.java b/core/tests/benchmarks/src/android/os/StrictModeBenchmark.java
index 3842df7..41af3820 100644
--- a/core/tests/coretests/src/android/webkit/AccessibilityInjectorTestActivity.java
+++ b/core/tests/benchmarks/src/android/os/StrictModeBenchmark.java
@@ -1,5 +1,5 @@
/*
- * Copyright (C) 2011 The Android Open Source Project
+ * Copyright (C) 2013 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.
@@ -14,25 +14,21 @@
* limitations under the License.
*/
-package android.webkit;
+package android.os;
-import com.android.frameworks.coretests.R;
+import android.os.StrictMode.ThreadPolicy;
-import android.app.Activity;
-import android.os.Bundle;
+import com.google.caliper.SimpleBenchmark;
-public class AccessibilityInjectorTestActivity extends Activity {
+public class StrictModeBenchmark extends SimpleBenchmark {
- private WebView mWebView;
+ private ThreadPolicy mOff = new ThreadPolicy.Builder().build();
+ private ThreadPolicy mOn = new ThreadPolicy.Builder().detectAll().build();
- @Override
- public void onCreate(Bundle icicle) {
- super.onCreate(icicle);
- setContentView(R.layout.accessibility_injector_test);
- mWebView = (WebView) findViewById(R.id.webview);
- }
-
- public WebView getWebView() {
- return mWebView;
+ public void timeToggleThreadPolicy(int reps) {
+ for (int i = 0; i < reps; i++) {
+ StrictMode.setThreadPolicy(mOn);
+ StrictMode.setThreadPolicy(mOff);
+ }
}
}
diff --git a/core/tests/coretests/Android.mk b/core/tests/coretests/Android.mk
index 22fa7fc..be55444 100644
--- a/core/tests/coretests/Android.mk
+++ b/core/tests/coretests/Android.mk
@@ -22,7 +22,7 @@ LOCAL_SRC_FILES := \
$(call all-java-files-under, EnabledTestApp/src)
LOCAL_DX_FLAGS := --core-library
-LOCAL_STATIC_JAVA_LIBRARIES := core-tests android-common frameworks-core-util-lib mockwebserver guava littlemock
+LOCAL_STATIC_JAVA_LIBRARIES := core-tests-support android-common frameworks-core-util-lib mockwebserver guava littlemock
LOCAL_JAVA_LIBRARIES := android.test.runner conscrypt telephony-common
LOCAL_PACKAGE_NAME := FrameworksCoreTests
diff --git a/core/tests/coretests/AndroidManifest.xml b/core/tests/coretests/AndroidManifest.xml
index f8b26bc..a2cc40c 100644
--- a/core/tests/coretests/AndroidManifest.xml
+++ b/core/tests/coretests/AndroidManifest.xml
@@ -94,7 +94,7 @@
<uses-permission android:name="android.permission.MOVE_PACKAGE" />
<uses-permission android:name="android.permission.PACKAGE_VERIFICATION_AGENT" />
- <!--os storage test permissions -->
+ <!-- os storage test permissions -->
<uses-permission android:name="android.permission.MOUNT_UNMOUNT_FILESYSTEMS" />
<uses-permission android:name="android.permission.ASEC_ACCESS" />
<uses-permission android:name="android.permission.ASEC_CREATE" />
@@ -103,6 +103,10 @@
<uses-permission android:name="android.permission.ASEC_RENAME" />
<uses-permission android:name="android.permission.SHUTDOWN" />
+ <!-- virtual display test permissions -->
+ <uses-permission android:name="android.permission.CAPTURE_VIDEO_OUTPUT" />
+ <uses-permission android:name="android.permission.CAPTURE_SECURE_VIDEO_OUTPUT" />
+
<!-- accessibility test permissions -->
<uses-permission android:name="android.permission.RETRIEVE_WINDOW_CONTENT" />
diff --git a/core/tests/coretests/apks/version_nosys/Android.mk b/core/tests/coretests/apks/version_nosys/Android.mk
new file mode 100644
index 0000000..bbc8e12
--- /dev/null
+++ b/core/tests/coretests/apks/version_nosys/Android.mk
@@ -0,0 +1,9 @@
+LOCAL_PATH:= $(call my-dir)
+
+include $(CLEAR_VARS)
+LOCAL_SRC_FILES := $(call all-subdir-java-files)
+LOCAL_PACKAGE_NAME := version_1_nosys
+LOCAL_AAPT_FLAGS := --version-code 1 --version-name 1.0
+LOCAL_CERTIFICATE := $(LOCAL_PATH)/../../certs/unit_test
+include $(FrameworkCoreTests_BUILD_PACKAGE)
+
diff --git a/core/tests/coretests/apks/version_nosys/AndroidManifest.xml b/core/tests/coretests/apks/version_nosys/AndroidManifest.xml
new file mode 100644
index 0000000..46aac38
--- /dev/null
+++ b/core/tests/coretests/apks/version_nosys/AndroidManifest.xml
@@ -0,0 +1,27 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!-- Copyright (C) 2012 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.
+-->
+<manifest xmlns:android="http://schemas.android.com/apk/res/android"
+ package="com.android.frameworks.coretests.version_test">
+
+ <!-- Do not ask for this system permission -->
+<!-- <uses-permission android:name="android.permission.ACCESS_CACHE_FILESYSTEM" />
+-->
+ <!-- Which permission it uses is not important as long as it's a normal
+ permission -->
+ <uses-permission android:name="android.permission.VIBRATE" />
+
+ <application android:hasCode="false"/>
+</manifest>
diff --git a/core/tests/coretests/apks/version_nosys/res/values/strings.xml b/core/tests/coretests/apks/version_nosys/res/values/strings.xml
new file mode 100644
index 0000000..3b8b3b1
--- /dev/null
+++ b/core/tests/coretests/apks/version_nosys/res/values/strings.xml
@@ -0,0 +1,6 @@
+<?xml version="1.0" encoding="utf-8"?>
+
+<!-- Just need this dummy file to have something to build. -->
+<resources xmlns:xliff="urn:oasis:names:tc:xliff:document:1.2">
+ <string name="dummy">dummy</string>
+</resources>
diff --git a/core/tests/coretests/apks/version_nosys/src/com/android/frameworks/coretests/version_test/NullProvider.java b/core/tests/coretests/apks/version_nosys/src/com/android/frameworks/coretests/version_test/NullProvider.java
new file mode 100644
index 0000000..f5742f0
--- /dev/null
+++ b/core/tests/coretests/apks/version_nosys/src/com/android/frameworks/coretests/version_test/NullProvider.java
@@ -0,0 +1,39 @@
+package com.android.frameworks.coretests.version_test;
+
+import android.content.ContentProvider;
+import android.content.ContentValues;
+import android.database.Cursor;
+import android.net.Uri;
+
+public class NullProvider extends ContentProvider {
+ @Override
+ public boolean onCreate() {
+ return true;
+ }
+
+ @Override
+ public Cursor query(Uri uri, String[] projection, String selection, String[] selectionArgs,
+ String sortOrder) {
+ return null;
+ }
+
+ @Override
+ public Uri insert(Uri uri, ContentValues values) {
+ return null;
+ }
+
+ @Override
+ public int delete(Uri uri, String selection, String[] selectionArgs) {
+ return 0;
+ }
+
+ @Override
+ public int update(Uri uri, ContentValues values, String selection, String[] selectionArgs) {
+ return 0;
+ }
+
+ @Override
+ public String getType(Uri uri) {
+ return "text/plain";
+ }
+}
diff --git a/core/tests/coretests/src/android/animation/AnimatorSetEventsTest.java b/core/tests/coretests/src/android/animation/AnimatorSetEventsTest.java
index d415e4e..7eb32ee 100644
--- a/core/tests/coretests/src/android/animation/AnimatorSetEventsTest.java
+++ b/core/tests/coretests/src/android/animation/AnimatorSetEventsTest.java
@@ -37,14 +37,12 @@ public class AnimatorSetEventsTest extends EventsTest {
button = (Button) getActivity().findViewById(R.id.animatingButton);
mAnimator = new AnimatorSet();
((AnimatorSet)mAnimator).playSequentially(xAnim, yAnim);
-
super.setUp();
}
@Override
protected long getTimeout() {
- return (xAnim.getDuration() + yAnim.getDuration()) +
- (xAnim.getStartDelay() + yAnim.getStartDelay()) +
+ return (2 * mAnimator.getDuration()) + (2 * mAnimator.getStartDelay()) +
ANIM_DELAY + FUTURE_RELEASE_DELAY;
}
diff --git a/core/tests/coretests/src/android/animation/EventsTest.java b/core/tests/coretests/src/android/animation/EventsTest.java
index 8df711b..28cfe3d 100644
--- a/core/tests/coretests/src/android/animation/EventsTest.java
+++ b/core/tests/coretests/src/android/animation/EventsTest.java
@@ -22,6 +22,7 @@ import android.test.suitebuilder.annotation.MediumTest;
import android.test.suitebuilder.annotation.SmallTest;
import java.util.concurrent.TimeUnit;
+import java.util.concurrent.TimeoutException;
/**
* Tests for the various lifecycle events of Animators. This abstract class is subclassed by
@@ -42,12 +43,15 @@ public abstract class EventsTest
protected static final int ANIM_DELAY = 100;
protected static final int ANIM_MID_DURATION = ANIM_DURATION / 2;
protected static final int ANIM_MID_DELAY = ANIM_DELAY / 2;
+ protected static final int ANIM_PAUSE_DURATION = ANIM_DELAY;
+ protected static final int ANIM_PAUSE_DELAY = ANIM_DELAY / 2;
protected static final int FUTURE_RELEASE_DELAY = 50;
+ protected static final int ANIM_FULL_DURATION_SLOP = 100;
private boolean mStarted; // tracks whether we've received the onAnimationStart() callback
protected boolean mRunning; // tracks whether we've started the animator
- private boolean mCanceled; // trackes whether we've canceled the animator
- protected Animator.AnimatorListener mFutureListener; // mechanism for delaying the end of the test
+ private boolean mCanceled; // tracks whether we've canceled the animator
+ protected Animator.AnimatorListener mFutureListener; // mechanism for delaying end of the test
protected FutureWaiter mFuture; // Mechanism for waiting for the UI test to complete
private Animator.AnimatorListener mListener; // Listener that handles/tests the events
@@ -104,6 +108,48 @@ public abstract class EventsTest
};
/**
+ * Pauses the given animator. Used to delay pausing until some later time (after the
+ * animator has started playing).
+ */
+ static class Pauser implements Runnable {
+ Animator mAnim;
+ FutureWaiter mFuture;
+ public Pauser(Animator anim, FutureWaiter future) {
+ mAnim = anim;
+ mFuture = future;
+ }
+ @Override
+ public void run() {
+ try {
+ mAnim.pause();
+ } catch (junit.framework.AssertionFailedError e) {
+ mFuture.setException(new RuntimeException(e));
+ }
+ }
+ };
+
+ /**
+ * Resumes the given animator. Used to delay resuming until some later time (after the
+ * animator has paused for some duration).
+ */
+ static class Resumer implements Runnable {
+ Animator mAnim;
+ FutureWaiter mFuture;
+ public Resumer(Animator anim, FutureWaiter future) {
+ mAnim = anim;
+ mFuture = future;
+ }
+ @Override
+ public void run() {
+ try {
+ mAnim.resume();
+ } catch (junit.framework.AssertionFailedError e) {
+ mFuture.setException(new RuntimeException(e));
+ }
+ }
+ };
+
+ /**
* Releases the given Future object when the listener's end() event is called. Specifically,
* it releases it after some further delay, to give the test time to do other things right
* after an animation ends.
@@ -555,4 +601,114 @@ public abstract class EventsTest
mFuture.get(getTimeout(), TimeUnit.MILLISECONDS);
}
+ /**
+ * Verify that pausing and resuming an animator ends within
+ * the appropriate timeout duration.
+ */
+ @MediumTest
+ public void testPauseResume() throws Exception {
+ mFutureListener = new FutureReleaseListener(mFuture);
+ getActivity().runOnUiThread(new Runnable() {
+ @Override
+ public void run() {
+ try {
+ Handler handler = new Handler();
+ mAnimator.addListener(mFutureListener);
+ mRunning = true;
+ mAnimator.start();
+ handler.postDelayed(new Pauser(mAnimator, mFuture), ANIM_PAUSE_DELAY);
+ handler.postDelayed(new Resumer(mAnimator, mFuture),
+ ANIM_PAUSE_DELAY + ANIM_PAUSE_DURATION);
+ } catch (junit.framework.AssertionFailedError e) {
+ mFuture.setException(new RuntimeException(e));
+ }
+ }
+ });
+ mFuture.get(getTimeout() + ANIM_PAUSE_DURATION, TimeUnit.MILLISECONDS);
+ }
+
+ /**
+ * Verify that pausing and resuming a startDelayed animator ends within
+ * the appropriate timeout duration.
+ */
+ @MediumTest
+ public void testPauseResumeDelayed() throws Exception {
+ mAnimator.setStartDelay(ANIM_DELAY);
+ mFutureListener = new FutureReleaseListener(mFuture);
+ getActivity().runOnUiThread(new Runnable() {
+ @Override
+ public void run() {
+ try {
+ Handler handler = new Handler();
+ mAnimator.addListener(mFutureListener);
+ mRunning = true;
+ mAnimator.start();
+ handler.postDelayed(new Pauser(mAnimator, mFuture), ANIM_PAUSE_DELAY);
+ handler.postDelayed(new Resumer(mAnimator, mFuture),
+ ANIM_PAUSE_DELAY + ANIM_PAUSE_DURATION);
+ } catch (junit.framework.AssertionFailedError e) {
+ mFuture.setException(new RuntimeException(e));
+ }
+ }
+ });
+ mFuture.get(getTimeout() + ANIM_PAUSE_DURATION + ANIM_FULL_DURATION_SLOP,
+ TimeUnit.MILLISECONDS);
+ }
+
+ /**
+ * Verify that pausing an animator without resuming it causes a timeout.
+ */
+ @MediumTest
+ public void testPauseTimeout() throws Exception {
+ mFutureListener = new FutureReleaseListener(mFuture);
+ getActivity().runOnUiThread(new Runnable() {
+ @Override
+ public void run() {
+ try {
+ Handler handler = new Handler();
+ mAnimator.addListener(mFutureListener);
+ mRunning = true;
+ mAnimator.start();
+ handler.postDelayed(new Pauser(mAnimator, mFuture), ANIM_PAUSE_DELAY);
+ } catch (junit.framework.AssertionFailedError e) {
+ mFuture.setException(new RuntimeException(e));
+ }
+ }
+ });
+ try {
+ mFuture.get(getTimeout() + ANIM_PAUSE_DURATION + ANIM_FULL_DURATION_SLOP,
+ TimeUnit.MILLISECONDS);
+ } catch (TimeoutException e) {
+ // Expected behavior, swallow the exception
+ }
+ }
+
+ /**
+ * Verify that pausing a startDelayed animator without resuming it causes a timeout.
+ */
+ @MediumTest
+ public void testPauseTimeoutDelayed() throws Exception {
+ mAnimator.setStartDelay(ANIM_DELAY);
+ mFutureListener = new FutureReleaseListener(mFuture);
+ getActivity().runOnUiThread(new Runnable() {
+ @Override
+ public void run() {
+ try {
+ Handler handler = new Handler();
+ mAnimator.addListener(mFutureListener);
+ mRunning = true;
+ mAnimator.start();
+ handler.postDelayed(new Pauser(mAnimator, mFuture), ANIM_PAUSE_DELAY);
+ } catch (junit.framework.AssertionFailedError e) {
+ mFuture.setException(new RuntimeException(e));
+ }
+ }
+ });
+ try {
+ mFuture.get(getTimeout() + ANIM_PAUSE_DURATION + ANIM_FULL_DURATION_SLOP,
+ TimeUnit.MILLISECONDS);
+ } catch (TimeoutException e) {
+ // Expected behavior, swallow the exception
+ }
+ }
}
diff --git a/core/tests/coretests/src/android/database/MatrixCursorTest.java b/core/tests/coretests/src/android/database/MatrixCursorTest.java
index cdab638..aa805dc 100644
--- a/core/tests/coretests/src/android/database/MatrixCursorTest.java
+++ b/core/tests/coretests/src/android/database/MatrixCursorTest.java
@@ -128,6 +128,56 @@ public class MatrixCursorTest extends TestCase {
} catch (IllegalArgumentException e) { /* expected */ }
}
+ public void testRowBuilderOffer() {
+ MatrixCursor cursor = newMatrixCursor();
+
+ cursor.newRow()
+ .add("float", 4.2f)
+ .add("string", "foobar")
+ .add("blob", new byte[] {(byte) 0xaa, (byte) 0x55})
+ .add("lolwat", "kittens");
+
+ cursor.newRow();
+
+ cursor.newRow()
+ .add("string", "zero")
+ .add("string", "one")
+ .add("string", "two")
+ .add("lolwat", "kittens");
+
+ assertTrue(cursor.moveToFirst());
+ assertEquals("foobar", cursor.getString(0));
+ assertEquals(null, cursor.getString(1));
+ assertEquals(0, cursor.getShort(1));
+ assertEquals(0, cursor.getInt(2));
+ assertEquals(0, cursor.getLong(3));
+ assertEquals(4.2f, cursor.getFloat(4));
+ assertEquals(0.0d, cursor.getDouble(5));
+ MoreAsserts.assertEquals(new byte[] {(byte) 0xaa, (byte) 0x55}, cursor.getBlob(6));
+
+ assertTrue(cursor.moveToNext());
+ assertEquals(null, cursor.getString(0));
+ assertEquals(0, cursor.getShort(1));
+ assertEquals(0, cursor.getInt(2));
+ assertEquals(0, cursor.getLong(3));
+ assertEquals(0.0f, cursor.getFloat(4));
+ assertEquals(0.0d, cursor.getDouble(5));
+ assertEquals(null, cursor.getBlob(6));
+
+ assertTrue(cursor.moveToNext());
+ assertEquals("two", cursor.getString(0));
+ assertEquals(0, cursor.getShort(1));
+ assertEquals(0, cursor.getInt(2));
+ assertEquals(0, cursor.getLong(3));
+ assertEquals(0.0f, cursor.getFloat(4));
+ assertEquals(0.0d, cursor.getDouble(5));
+ assertEquals(null, cursor.getBlob(6));
+
+ assertTrue(cursor.isLast());
+ assertFalse(cursor.moveToNext());
+ assertTrue(cursor.isAfterLast());
+ }
+
static class NonIterableArrayList<T> extends ArrayList<T> {
NonIterableArrayList() {}
diff --git a/core/tests/coretests/src/android/hardware/display/VirtualDisplayTest.java b/core/tests/coretests/src/android/hardware/display/VirtualDisplayTest.java
new file mode 100644
index 0000000..a2e9ae8
--- /dev/null
+++ b/core/tests/coretests/src/android/hardware/display/VirtualDisplayTest.java
@@ -0,0 +1,500 @@
+/*
+ * Copyright (C) 2013 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.hardware.display;
+
+import android.app.Presentation;
+import android.content.Context;
+import android.graphics.Color;
+import android.graphics.PixelFormat;
+import android.graphics.Point;
+import android.graphics.drawable.ColorDrawable;
+import android.hardware.display.DisplayManager;
+import android.hardware.display.VirtualDisplay;
+import android.media.Image;
+import android.media.ImageReader;
+import android.os.Bundle;
+import android.os.Handler;
+import android.os.Looper;
+import android.os.SystemClock;
+import android.test.AndroidTestCase;
+import android.util.DisplayMetrics;
+import android.util.Log;
+import android.view.Display;
+import android.view.Surface;
+import android.view.ViewGroup.LayoutParams;
+import android.view.WindowManager;
+import android.widget.ImageView;
+
+import java.nio.ByteBuffer;
+import java.util.concurrent.locks.Lock;
+import java.util.concurrent.locks.ReentrantLock;
+
+/**
+ * Tests that applications can create virtual displays and present content on them.
+ *
+ * Contains additional tests that cannot be included in CTS because they require
+ * system permissions. See also the CTS version of VirtualDisplayTest.
+ */
+public class VirtualDisplayTest extends AndroidTestCase {
+ private static final String TAG = "VirtualDisplayTest";
+
+ private static final String NAME = TAG;
+ private static final int WIDTH = 720;
+ private static final int HEIGHT = 480;
+ private static final int DENSITY = DisplayMetrics.DENSITY_MEDIUM;
+ private static final int TIMEOUT = 10000;
+
+ // Colors that we use as a signal to determine whether some desired content was
+ // drawn. The colors themselves doesn't matter but we choose them to have with distinct
+ // values for each color channel so as to detect possible RGBA vs. BGRA buffer format issues.
+ // We should only observe RGBA buffers but some graphics drivers might incorrectly
+ // deliver BGRA buffers to virtual displays instead.
+ private static final int BLUEISH = 0xff1122ee;
+ private static final int GREENISH = 0xff33dd44;
+
+ private DisplayManager mDisplayManager;
+ private Handler mHandler;
+ private final Lock mImageReaderLock = new ReentrantLock(true /*fair*/);
+ private ImageReader mImageReader;
+ private Surface mSurface;
+ private ImageListener mImageListener;
+
+ @Override
+ protected void setUp() throws Exception {
+ super.setUp();
+
+ mDisplayManager = (DisplayManager)mContext.getSystemService(Context.DISPLAY_SERVICE);
+ mHandler = new Handler(Looper.getMainLooper());
+ mImageListener = new ImageListener();
+
+ mImageReaderLock.lock();
+ try {
+ mImageReader = ImageReader.newInstance(WIDTH, HEIGHT, PixelFormat.RGBA_8888, 2);
+ mImageReader.setOnImageAvailableListener(mImageListener, mHandler);
+ mSurface = mImageReader.getSurface();
+ } finally {
+ mImageReaderLock.unlock();
+ }
+ }
+
+ @Override
+ protected void tearDown() throws Exception {
+ super.tearDown();
+
+ mImageReaderLock.lock();
+ try {
+ mImageReader.close();
+ mImageReader = null;
+ mSurface = null;
+ } finally {
+ mImageReaderLock.unlock();
+ }
+ }
+
+ /**
+ * Ensures that an application can create a private virtual display and show
+ * its own windows on it.
+ */
+ public void testPrivateVirtualDisplay() throws Exception {
+ VirtualDisplay virtualDisplay = mDisplayManager.createVirtualDisplay(NAME,
+ WIDTH, HEIGHT, DENSITY, mSurface, 0);
+ assertNotNull("virtual display must not be null", virtualDisplay);
+
+ Display display = virtualDisplay.getDisplay();
+ try {
+ assertDisplayRegistered(display, Display.FLAG_PRIVATE);
+
+ // Show a private presentation on the display.
+ assertDisplayCanShowPresentation("private presentation window",
+ display, BLUEISH,
+ WindowManager.LayoutParams.TYPE_PRIVATE_PRESENTATION, 0);
+ } finally {
+ virtualDisplay.release();
+ }
+ assertDisplayUnregistered(display);
+ }
+
+ /**
+ * Ensures that an application can create a private presentation virtual display and show
+ * its own windows on it.
+ */
+ public void testPrivatePresentationVirtualDisplay() throws Exception {
+ VirtualDisplay virtualDisplay = mDisplayManager.createVirtualDisplay(NAME,
+ WIDTH, HEIGHT, DENSITY, mSurface,
+ DisplayManager.VIRTUAL_DISPLAY_FLAG_PRESENTATION);
+ assertNotNull("virtual display must not be null", virtualDisplay);
+
+ Display display = virtualDisplay.getDisplay();
+ try {
+ assertDisplayRegistered(display, Display.FLAG_PRIVATE | Display.FLAG_PRESENTATION);
+
+ // Show a private presentation on the display.
+ assertDisplayCanShowPresentation("private presentation window",
+ display, BLUEISH,
+ WindowManager.LayoutParams.TYPE_PRIVATE_PRESENTATION, 0);
+ } finally {
+ virtualDisplay.release();
+ }
+ assertDisplayUnregistered(display);
+ }
+
+ /**
+ * Ensures that an application can create a public virtual display and show
+ * its own windows on it. This test requires the CAPTURE_VIDEO_OUTPUT permission.
+ *
+ * Because this test does not have an activity token, we use the TOAST window
+ * type to create the window. Another choice might be SYSTEM_ALERT_WINDOW but
+ * that requires a permission.
+ */
+ public void testPublicPresentationVirtualDisplay() throws Exception {
+ VirtualDisplay virtualDisplay = mDisplayManager.createVirtualDisplay(NAME,
+ WIDTH, HEIGHT, DENSITY, mSurface,
+ DisplayManager.VIRTUAL_DISPLAY_FLAG_PUBLIC
+ | DisplayManager.VIRTUAL_DISPLAY_FLAG_PRESENTATION);
+ assertNotNull("virtual display must not be null", virtualDisplay);
+
+ Display display = virtualDisplay.getDisplay();
+ try {
+ assertDisplayRegistered(display, Display.FLAG_PRESENTATION);
+
+ // Mirroring case.
+ // Show a window on the default display. It should be mirrored to the
+ // virtual display automatically.
+ Display defaultDisplay = mDisplayManager.getDisplay(Display.DEFAULT_DISPLAY);
+ assertDisplayCanShowPresentation("mirrored window",
+ defaultDisplay, GREENISH,
+ WindowManager.LayoutParams.TYPE_TOAST, 0);
+
+ // Mirroring case with secure window (but display is not secure).
+ // Show a window on the default display. It should be replaced with black on
+ // the virtual display.
+ assertDisplayCanShowPresentation("mirrored secure window on non-secure display",
+ defaultDisplay, Color.BLACK,
+ WindowManager.LayoutParams.TYPE_TOAST,
+ WindowManager.LayoutParams.FLAG_SECURE);
+
+ // Presentation case.
+ // Show a normal presentation on the display.
+ assertDisplayCanShowPresentation("presentation window",
+ display, BLUEISH,
+ WindowManager.LayoutParams.TYPE_TOAST, 0);
+
+ // Presentation case with secure window (but display is not secure).
+ // Show a normal presentation on the display. It should be replaced with black.
+ assertDisplayCanShowPresentation("secure presentation window on non-secure display",
+ display, Color.BLACK,
+ WindowManager.LayoutParams.TYPE_TOAST,
+ WindowManager.LayoutParams.FLAG_SECURE);
+ } finally {
+ virtualDisplay.release();
+ }
+ assertDisplayUnregistered(display);
+ }
+
+ /**
+ * Ensures that an application can create a secure public virtual display and show
+ * its own windows on it. This test requires the CAPTURE_SECURE_VIDEO_OUTPUT permission.
+ *
+ * Because this test does not have an activity token, we use the TOAST window
+ * type to create the window. Another choice might be SYSTEM_ALERT_WINDOW but
+ * that requires a permission.
+ */
+ public void testSecurePublicPresentationVirtualDisplay() throws Exception {
+ VirtualDisplay virtualDisplay = mDisplayManager.createVirtualDisplay(NAME,
+ WIDTH, HEIGHT, DENSITY, mSurface,
+ DisplayManager.VIRTUAL_DISPLAY_FLAG_SECURE
+ | DisplayManager.VIRTUAL_DISPLAY_FLAG_PUBLIC
+ | DisplayManager.VIRTUAL_DISPLAY_FLAG_PRESENTATION);
+ assertNotNull("virtual display must not be null", virtualDisplay);
+
+ Display display = virtualDisplay.getDisplay();
+ try {
+ assertDisplayRegistered(display, Display.FLAG_PRESENTATION | Display.FLAG_SECURE);
+
+ // Mirroring case with secure window (and display is secure).
+ // Show a window on the default display. It should be mirrored to the
+ // virtual display automatically.
+ Display defaultDisplay = mDisplayManager.getDisplay(Display.DEFAULT_DISPLAY);
+ assertDisplayCanShowPresentation("mirrored secure window on secure display",
+ defaultDisplay, GREENISH,
+ WindowManager.LayoutParams.TYPE_TOAST,
+ WindowManager.LayoutParams.FLAG_SECURE);
+
+ // Presentation case with secure window (and display is secure).
+ // Show a normal presentation on the display.
+ assertDisplayCanShowPresentation("secure presentation window on secure display",
+ display, BLUEISH,
+ WindowManager.LayoutParams.TYPE_TOAST,
+ WindowManager.LayoutParams.FLAG_SECURE);
+ } finally {
+ virtualDisplay.release();
+ }
+ assertDisplayUnregistered(display);
+ }
+
+ private void assertDisplayRegistered(Display display, int flags) {
+ assertNotNull("display object must not be null", display);
+ assertTrue("display must be valid", display.isValid());
+ assertTrue("display id must be unique",
+ display.getDisplayId() != Display.DEFAULT_DISPLAY);
+ assertEquals("display must have correct flags", flags, display.getFlags());
+ assertEquals("display name must match supplied name", NAME, display.getName());
+ Point size = new Point();
+ display.getSize(size);
+ assertEquals("display width must match supplied width", WIDTH, size.x);
+ assertEquals("display height must match supplied height", HEIGHT, size.y);
+ assertEquals("display rotation must be 0",
+ Surface.ROTATION_0, display.getRotation());
+ assertNotNull("display must be registered",
+ findDisplay(mDisplayManager.getDisplays(), NAME));
+
+ if ((flags & Display.FLAG_PRESENTATION) != 0) {
+ assertNotNull("display must be registered as a presentation display",
+ findDisplay(mDisplayManager.getDisplays(
+ DisplayManager.DISPLAY_CATEGORY_PRESENTATION), NAME));
+ } else {
+ assertNull("display must not be registered as a presentation display",
+ findDisplay(mDisplayManager.getDisplays(
+ DisplayManager.DISPLAY_CATEGORY_PRESENTATION), NAME));
+ }
+ }
+
+ private void assertDisplayUnregistered(Display display) {
+ assertNull("display must no longer be registered after being removed",
+ findDisplay(mDisplayManager.getDisplays(), NAME));
+ assertFalse("display must no longer be valid", display.isValid());
+ }
+
+ private void assertDisplayCanShowPresentation(String message, final Display display,
+ final int color, final int windowType, final int windowFlags) {
+ // At this point, we should not have seen any blue.
+ assertTrue(message + ": display should not show content before window is shown",
+ mImageListener.getColor() != color);
+
+ final TestPresentation[] presentation = new TestPresentation[1];
+ try {
+ // Show the presentation.
+ runOnUiThread(new Runnable() {
+ @Override
+ public void run() {
+ presentation[0] = new TestPresentation(getContext(), display,
+ color, windowType, windowFlags);
+ presentation[0].show();
+ }
+ });
+
+ // Wait for the blue to be seen.
+ assertTrue(message + ": display should show content after window is shown",
+ mImageListener.waitForColor(color, TIMEOUT));
+ } finally {
+ if (presentation[0] != null) {
+ runOnUiThread(new Runnable() {
+ @Override
+ public void run() {
+ presentation[0].dismiss();
+ }
+ });
+ }
+ }
+ }
+
+ private void runOnUiThread(Runnable runnable) {
+ Runnable waiter = new Runnable() {
+ @Override
+ public void run() {
+ synchronized (this) {
+ notifyAll();
+ }
+ }
+ };
+ synchronized (waiter) {
+ mHandler.post(runnable);
+ mHandler.post(waiter);
+ try {
+ waiter.wait(TIMEOUT);
+ } catch (InterruptedException ex) {
+ }
+ }
+ }
+
+ private Display findDisplay(Display[] displays, String name) {
+ for (int i = 0; i < displays.length; i++) {
+ if (displays[i].getName().equals(name)) {
+ return displays[i];
+ }
+ }
+ return null;
+ }
+
+ private final class TestPresentation extends Presentation {
+ private final int mColor;
+ private final int mWindowType;
+ private final int mWindowFlags;
+
+ public TestPresentation(Context context, Display display,
+ int color, int windowType, int windowFlags) {
+ super(context, display);
+ mColor = color;
+ mWindowType = windowType;
+ mWindowFlags = windowFlags;
+ }
+
+ @Override
+ protected void onCreate(Bundle savedInstanceState) {
+ super.onCreate(savedInstanceState);
+
+ setTitle(TAG);
+ getWindow().setType(mWindowType);
+ getWindow().addFlags(mWindowFlags);
+
+ // Create a solid color image to use as the content of the presentation.
+ ImageView view = new ImageView(getContext());
+ view.setImageDrawable(new ColorDrawable(mColor));
+ view.setLayoutParams(new LayoutParams(
+ LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT));
+ setContentView(view);
+ }
+ }
+
+ /**
+ * Watches for an image with a large amount of some particular solid color to be shown.
+ */
+ private final class ImageListener
+ implements ImageReader.OnImageAvailableListener {
+ private int mColor = -1;
+
+ public int getColor() {
+ synchronized (this) {
+ return mColor;
+ }
+ }
+
+ public boolean waitForColor(int color, long timeoutMillis) {
+ long timeoutTime = SystemClock.uptimeMillis() + timeoutMillis;
+ synchronized (this) {
+ while (mColor != color) {
+ long now = SystemClock.uptimeMillis();
+ if (now >= timeoutTime) {
+ return false;
+ }
+ try {
+ wait(timeoutTime - now);
+ } catch (InterruptedException ex) {
+ }
+ }
+ return true;
+ }
+ }
+
+ @Override
+ public void onImageAvailable(ImageReader reader) {
+ mImageReaderLock.lock();
+ try {
+ if (reader != mImageReader) {
+ return;
+ }
+
+ Log.d(TAG, "New image available from virtual display.");
+
+ // Get the latest buffer.
+ Image image = reader.acquireLatestImage();
+ if (image != null) {
+ try {
+ // Scan for colors.
+ int color = scanImage(image);
+ synchronized (this) {
+ if (mColor != color) {
+ mColor = color;
+ notifyAll();
+ }
+ }
+ } finally {
+ image.close();
+ }
+ }
+ } finally {
+ mImageReaderLock.unlock();
+ }
+ }
+
+ private int scanImage(Image image) {
+ final Image.Plane plane = image.getPlanes()[0];
+ final ByteBuffer buffer = plane.getBuffer();
+ final int width = image.getWidth();
+ final int height = image.getHeight();
+ final int pixelStride = plane.getPixelStride();
+ final int rowStride = plane.getRowStride();
+ final int rowPadding = rowStride - pixelStride * width;
+
+ Log.d(TAG, "- Scanning image: width=" + width + ", height=" + height
+ + ", pixelStride=" + pixelStride + ", rowStride=" + rowStride);
+
+ int offset = 0;
+ int blackPixels = 0;
+ int bluePixels = 0;
+ int greenPixels = 0;
+ int otherPixels = 0;
+ for (int y = 0; y < height; y++) {
+ for (int x = 0; x < width; x++) {
+ int pixel = 0;
+ pixel |= (buffer.get(offset) & 0xff) << 16; // R
+ pixel |= (buffer.get(offset + 1) & 0xff) << 8; // G
+ pixel |= (buffer.get(offset + 2) & 0xff); // B
+ pixel |= (buffer.get(offset + 3) & 0xff) << 24; // A
+ if (pixel == Color.BLACK || pixel == 0) {
+ blackPixels += 1;
+ } else if (pixel == BLUEISH) {
+ bluePixels += 1;
+ } else if (pixel == GREENISH) {
+ greenPixels += 1;
+ } else {
+ otherPixels += 1;
+ if (otherPixels < 10) {
+ Log.d(TAG, "- Found unexpected color: " + Integer.toHexString(pixel));
+ }
+ }
+ offset += pixelStride;
+ }
+ offset += rowPadding;
+ }
+
+ // Return a color if it represents more than one quarter of the pixels.
+ // We use this threshold in case the display is being letterboxed when
+ // mirroring so there might be large black bars on the sides, which is normal.
+ Log.d(TAG, "- Pixels: " + blackPixels + " black, "
+ + bluePixels + " blue, "
+ + greenPixels + " green, "
+ + otherPixels + " other");
+ final int threshold = width * height / 4;
+ if (bluePixels > threshold) {
+ Log.d(TAG, "- Reporting blue.");
+ return BLUEISH;
+ }
+ if (greenPixels > threshold) {
+ Log.d(TAG, "- Reporting green.");
+ return GREENISH;
+ }
+ if (blackPixels > threshold) {
+ Log.d(TAG, "- Reporting black.");
+ return Color.BLACK;
+ }
+ Log.d(TAG, "- Reporting other.");
+ return -1;
+ }
+ }
+}
+
diff --git a/core/tests/coretests/src/android/net/LinkPropertiesTest.java b/core/tests/coretests/src/android/net/LinkPropertiesTest.java
index d6a7ee2..e63f6b0 100644
--- a/core/tests/coretests/src/android/net/LinkPropertiesTest.java
+++ b/core/tests/coretests/src/android/net/LinkPropertiesTest.java
@@ -25,13 +25,18 @@ import java.net.InetAddress;
import java.util.ArrayList;
public class LinkPropertiesTest extends TestCase {
- private static String ADDRV4 = "75.208.6.1";
- private static String ADDRV6 = "2001:0db8:85a3:0000:0000:8a2e:0370:7334";
- private static String DNS1 = "75.208.7.1";
- private static String DNS2 = "69.78.7.1";
- private static String GATEWAY1 = "75.208.8.1";
- private static String GATEWAY2 = "69.78.8.1";
+ private static InetAddress ADDRV4 = NetworkUtils.numericToInetAddress("75.208.6.1");
+ private static InetAddress ADDRV6 = NetworkUtils.numericToInetAddress(
+ "2001:0db8:85a3:0000:0000:8a2e:0370:7334");
+ private static InetAddress DNS1 = NetworkUtils.numericToInetAddress("75.208.7.1");
+ private static InetAddress DNS2 = NetworkUtils.numericToInetAddress("69.78.7.1");
+ private static InetAddress GATEWAY1 = NetworkUtils.numericToInetAddress("75.208.8.1");
+ private static InetAddress GATEWAY2 = NetworkUtils.numericToInetAddress("69.78.8.1");
private static String NAME = "qmi0";
+ private static int MTU = 1500;
+
+ private static LinkAddress LINKADDRV4 = new LinkAddress(ADDRV4, 32);
+ private static LinkAddress LINKADDRV6 = new LinkAddress(ADDRV6, 128);
public void assertLinkPropertiesEqual(LinkProperties source, LinkProperties target) {
// Check implementation of equals(), element by element.
@@ -53,6 +58,9 @@ public class LinkPropertiesTest extends TestCase {
assertTrue(source.isIdenticalStackedLinks(target));
assertTrue(target.isIdenticalStackedLinks(source));
+ assertTrue(source.isIdenticalMtu(target));
+ assertTrue(target.isIdenticalMtu(source));
+
// Check result of equals().
assertTrue(source.equals(target));
assertTrue(target.equals(source));
@@ -76,43 +84,40 @@ public class LinkPropertiesTest extends TestCase {
LinkProperties source = new LinkProperties();
source.setInterfaceName(NAME);
// set 2 link addresses
- source.addLinkAddress(new LinkAddress(
- NetworkUtils.numericToInetAddress(ADDRV4), 32));
- source.addLinkAddress(new LinkAddress(
- NetworkUtils.numericToInetAddress(ADDRV6), 128));
+ source.addLinkAddress(LINKADDRV4);
+ source.addLinkAddress(LINKADDRV6);
// set 2 dnses
- source.addDns(NetworkUtils.numericToInetAddress(DNS1));
- source.addDns(NetworkUtils.numericToInetAddress(DNS2));
+ source.addDns(DNS1);
+ source.addDns(DNS2);
// set 2 gateways
- source.addRoute(new RouteInfo(NetworkUtils.numericToInetAddress(GATEWAY1)));
- source.addRoute(new RouteInfo(NetworkUtils.numericToInetAddress(GATEWAY2)));
+ source.addRoute(new RouteInfo(GATEWAY1));
+ source.addRoute(new RouteInfo(GATEWAY2));
+ source.setMtu(MTU);
LinkProperties target = new LinkProperties();
// All fields are same
target.setInterfaceName(NAME);
- target.addLinkAddress(new LinkAddress(
- NetworkUtils.numericToInetAddress(ADDRV4), 32));
- target.addLinkAddress(new LinkAddress(
- NetworkUtils.numericToInetAddress(ADDRV6), 128));
- target.addDns(NetworkUtils.numericToInetAddress(DNS1));
- target.addDns(NetworkUtils.numericToInetAddress(DNS2));
- target.addRoute(new RouteInfo(NetworkUtils.numericToInetAddress(GATEWAY1)));
- target.addRoute(new RouteInfo(NetworkUtils.numericToInetAddress(GATEWAY2)));
+ target.addLinkAddress(LINKADDRV4);
+ target.addLinkAddress(LINKADDRV6);
+ target.addDns(DNS1);
+ target.addDns(DNS2);
+ target.addRoute(new RouteInfo(GATEWAY1));
+ target.addRoute(new RouteInfo(GATEWAY2));
+ target.setMtu(MTU);
assertLinkPropertiesEqual(source, target);
target.clear();
// change Interface Name
target.setInterfaceName("qmi1");
- target.addLinkAddress(new LinkAddress(
- NetworkUtils.numericToInetAddress(ADDRV4), 32));
- target.addLinkAddress(new LinkAddress(
- NetworkUtils.numericToInetAddress(ADDRV6), 128));
- target.addDns(NetworkUtils.numericToInetAddress(DNS1));
- target.addDns(NetworkUtils.numericToInetAddress(DNS2));
- target.addRoute(new RouteInfo(NetworkUtils.numericToInetAddress(GATEWAY1)));
- target.addRoute(new RouteInfo(NetworkUtils.numericToInetAddress(GATEWAY2)));
+ target.addLinkAddress(LINKADDRV4);
+ target.addLinkAddress(LINKADDRV6);
+ target.addDns(DNS1);
+ target.addDns(DNS2);
+ target.addRoute(new RouteInfo(GATEWAY1));
+ target.addRoute(new RouteInfo(GATEWAY2));
+ target.setMtu(MTU);
assertFalse(source.equals(target));
target.clear();
@@ -120,38 +125,48 @@ public class LinkPropertiesTest extends TestCase {
// change link addresses
target.addLinkAddress(new LinkAddress(
NetworkUtils.numericToInetAddress("75.208.6.2"), 32));
- target.addLinkAddress(new LinkAddress(
- NetworkUtils.numericToInetAddress(ADDRV6), 128));
- target.addDns(NetworkUtils.numericToInetAddress(DNS1));
- target.addDns(NetworkUtils.numericToInetAddress(DNS2));
- target.addRoute(new RouteInfo(NetworkUtils.numericToInetAddress(GATEWAY1)));
- target.addRoute(new RouteInfo(NetworkUtils.numericToInetAddress(GATEWAY2)));
+ target.addLinkAddress(LINKADDRV6);
+ target.addDns(DNS1);
+ target.addDns(DNS2);
+ target.addRoute(new RouteInfo(GATEWAY1));
+ target.addRoute(new RouteInfo(GATEWAY2));
+ target.setMtu(MTU);
assertFalse(source.equals(target));
target.clear();
target.setInterfaceName(NAME);
- target.addLinkAddress(new LinkAddress(
- NetworkUtils.numericToInetAddress(ADDRV4), 32));
- target.addLinkAddress(new LinkAddress(
- NetworkUtils.numericToInetAddress(ADDRV6), 128));
+ target.addLinkAddress(LINKADDRV4);
+ target.addLinkAddress(LINKADDRV6);
// change dnses
target.addDns(NetworkUtils.numericToInetAddress("75.208.7.2"));
- target.addDns(NetworkUtils.numericToInetAddress(DNS2));
- target.addRoute(new RouteInfo(NetworkUtils.numericToInetAddress(GATEWAY1)));
- target.addRoute(new RouteInfo(NetworkUtils.numericToInetAddress(GATEWAY2)));
+ target.addDns(DNS2);
+ target.addRoute(new RouteInfo(GATEWAY1));
+ target.addRoute(new RouteInfo(GATEWAY2));
+ target.setMtu(MTU);
assertFalse(source.equals(target));
target.clear();
target.setInterfaceName(NAME);
- target.addLinkAddress(new LinkAddress(
- NetworkUtils.numericToInetAddress(ADDRV4), 32));
- target.addLinkAddress(new LinkAddress(
- NetworkUtils.numericToInetAddress(ADDRV6), 128));
- target.addDns(NetworkUtils.numericToInetAddress(DNS1));
- target.addDns(NetworkUtils.numericToInetAddress(DNS2));
+ target.addLinkAddress(LINKADDRV4);
+ target.addLinkAddress(LINKADDRV6);
+ target.addDns(DNS1);
+ target.addDns(DNS2);
// change gateway
target.addRoute(new RouteInfo(NetworkUtils.numericToInetAddress("75.208.8.2")));
- target.addRoute(new RouteInfo(NetworkUtils.numericToInetAddress(GATEWAY2)));
+ target.addRoute(new RouteInfo(GATEWAY2));
+ target.setMtu(MTU);
+ assertFalse(source.equals(target));
+
+ target.clear();
+ target.setInterfaceName(NAME);
+ target.addLinkAddress(LINKADDRV4);
+ target.addLinkAddress(LINKADDRV6);
+ target.addDns(DNS1);
+ target.addDns(DNS2);
+ target.addRoute(new RouteInfo(GATEWAY1));
+ target.addRoute(new RouteInfo(GATEWAY2));
+ // change mtu
+ target.setMtu(1440);
assertFalse(source.equals(target));
} catch (Exception e) {
@@ -166,28 +181,26 @@ public class LinkPropertiesTest extends TestCase {
LinkProperties source = new LinkProperties();
source.setInterfaceName(NAME);
// set 2 link addresses
- source.addLinkAddress(new LinkAddress(
- NetworkUtils.numericToInetAddress(ADDRV4), 32));
- source.addLinkAddress(new LinkAddress(
- NetworkUtils.numericToInetAddress(ADDRV6), 128));
+ source.addLinkAddress(LINKADDRV4);
+ source.addLinkAddress(LINKADDRV6);
// set 2 dnses
- source.addDns(NetworkUtils.numericToInetAddress(DNS1));
- source.addDns(NetworkUtils.numericToInetAddress(DNS2));
+ source.addDns(DNS1);
+ source.addDns(DNS2);
// set 2 gateways
- source.addRoute(new RouteInfo(NetworkUtils.numericToInetAddress(GATEWAY1)));
- source.addRoute(new RouteInfo(NetworkUtils.numericToInetAddress(GATEWAY2)));
+ source.addRoute(new RouteInfo(GATEWAY1));
+ source.addRoute(new RouteInfo(GATEWAY2));
+ source.setMtu(MTU);
LinkProperties target = new LinkProperties();
// Exchange order
target.setInterfaceName(NAME);
- target.addLinkAddress(new LinkAddress(
- NetworkUtils.numericToInetAddress(ADDRV6), 128));
- target.addLinkAddress(new LinkAddress(
- NetworkUtils.numericToInetAddress(ADDRV4), 32));
- target.addDns(NetworkUtils.numericToInetAddress(DNS2));
- target.addDns(NetworkUtils.numericToInetAddress(DNS1));
- target.addRoute(new RouteInfo(NetworkUtils.numericToInetAddress(GATEWAY2)));
- target.addRoute(new RouteInfo(NetworkUtils.numericToInetAddress(GATEWAY1)));
+ target.addLinkAddress(LINKADDRV6);
+ target.addLinkAddress(LINKADDRV4);
+ target.addDns(DNS2);
+ target.addDns(DNS1);
+ target.addRoute(new RouteInfo(GATEWAY2));
+ target.addRoute(new RouteInfo(GATEWAY1));
+ target.setMtu(MTU);
assertLinkPropertiesEqual(source, target);
} catch (Exception e) {
@@ -200,21 +213,15 @@ public class LinkPropertiesTest extends TestCase {
try {
LinkProperties source = new LinkProperties();
// set 3 link addresses, eg, [A, A, B]
- source.addLinkAddress(new LinkAddress(
- NetworkUtils.numericToInetAddress(ADDRV4), 32));
- source.addLinkAddress(new LinkAddress(
- NetworkUtils.numericToInetAddress(ADDRV4), 32));
- source.addLinkAddress(new LinkAddress(
- NetworkUtils.numericToInetAddress(ADDRV6), 128));
+ source.addLinkAddress(LINKADDRV4);
+ source.addLinkAddress(LINKADDRV4);
+ source.addLinkAddress(LINKADDRV6);
LinkProperties target = new LinkProperties();
// set 3 link addresses, eg, [A, B, B]
- target.addLinkAddress(new LinkAddress(
- NetworkUtils.numericToInetAddress(ADDRV4), 32));
- target.addLinkAddress(new LinkAddress(
- NetworkUtils.numericToInetAddress(ADDRV6), 128));
- target.addLinkAddress(new LinkAddress(
- NetworkUtils.numericToInetAddress(ADDRV6), 128));
+ target.addLinkAddress(LINKADDRV4);
+ target.addLinkAddress(LINKADDRV6);
+ target.addLinkAddress(LINKADDRV6);
assertLinkPropertiesEqual(source, target);
} catch (Exception e) {
@@ -232,7 +239,7 @@ public class LinkPropertiesTest extends TestCase {
public void testRouteInterfaces() {
LinkAddress prefix = new LinkAddress(
NetworkUtils.numericToInetAddress("2001:db8::"), 32);
- InetAddress address = NetworkUtils.numericToInetAddress(ADDRV6);
+ InetAddress address = ADDRV6;
// Add a route with no interface to a LinkProperties with no interface. No errors.
LinkProperties lp = new LinkProperties();
@@ -265,7 +272,7 @@ public class LinkPropertiesTest extends TestCase {
assertAllRoutesHaveInterface("wlan0", lp);
// Routes with null interfaces are converted to wlan0.
- r = RouteInfo.makeHostRoute(NetworkUtils.numericToInetAddress(ADDRV6), null);
+ r = RouteInfo.makeHostRoute(ADDRV6, null);
lp.addRoute(r);
assertEquals(3, lp.getRoutes().size());
assertAllRoutesHaveInterface("wlan0", lp);
@@ -273,28 +280,45 @@ public class LinkPropertiesTest extends TestCase {
// Check comparisons work.
LinkProperties lp2 = new LinkProperties(lp);
assertAllRoutesHaveInterface("wlan0", lp);
- assertEquals(0, lp.compareRoutes(lp2).added.size());
- assertEquals(0, lp.compareRoutes(lp2).removed.size());
+ assertEquals(0, lp.compareAllRoutes(lp2).added.size());
+ assertEquals(0, lp.compareAllRoutes(lp2).removed.size());
lp2.setInterfaceName("p2p0");
assertAllRoutesHaveInterface("p2p0", lp2);
- assertEquals(3, lp.compareRoutes(lp2).added.size());
- assertEquals(3, lp.compareRoutes(lp2).removed.size());
+ assertEquals(3, lp.compareAllRoutes(lp2).added.size());
+ assertEquals(3, lp.compareAllRoutes(lp2).removed.size());
}
@SmallTest
public void testStackedInterfaces() {
LinkProperties rmnet0 = new LinkProperties();
rmnet0.setInterfaceName("rmnet0");
+ rmnet0.addLinkAddress(LINKADDRV6);
LinkProperties clat4 = new LinkProperties();
clat4.setInterfaceName("clat4");
+ clat4.addLinkAddress(LINKADDRV4);
assertEquals(0, rmnet0.getStackedLinks().size());
+ assertEquals(1, rmnet0.getAddresses().size());
+ assertEquals(1, rmnet0.getLinkAddresses().size());
+ assertEquals(1, rmnet0.getAllAddresses().size());
+ assertEquals(1, rmnet0.getAllLinkAddresses().size());
+
rmnet0.addStackedLink(clat4);
assertEquals(1, rmnet0.getStackedLinks().size());
+ assertEquals(1, rmnet0.getAddresses().size());
+ assertEquals(1, rmnet0.getLinkAddresses().size());
+ assertEquals(2, rmnet0.getAllAddresses().size());
+ assertEquals(2, rmnet0.getAllLinkAddresses().size());
+
rmnet0.addStackedLink(clat4);
assertEquals(1, rmnet0.getStackedLinks().size());
+ assertEquals(1, rmnet0.getAddresses().size());
+ assertEquals(1, rmnet0.getLinkAddresses().size());
+ assertEquals(2, rmnet0.getAllAddresses().size());
+ assertEquals(2, rmnet0.getAllLinkAddresses().size());
+
assertEquals(0, clat4.getStackedLinks().size());
// Modify an item in the returned collection to see what happens.
@@ -306,5 +330,76 @@ public class LinkPropertiesTest extends TestCase {
for (LinkProperties link : rmnet0.getStackedLinks()) {
assertFalse("newname".equals(link.getInterfaceName()));
}
+
+ assertTrue(rmnet0.removeStackedLink(clat4));
+ assertEquals(0, rmnet0.getStackedLinks().size());
+ assertEquals(1, rmnet0.getAddresses().size());
+ assertEquals(1, rmnet0.getLinkAddresses().size());
+ assertEquals(1, rmnet0.getAllAddresses().size());
+ assertEquals(1, rmnet0.getAllLinkAddresses().size());
+
+ assertFalse(rmnet0.removeStackedLink(clat4));
+ }
+
+ @SmallTest
+ public void testAddressMethods() {
+ LinkProperties lp = new LinkProperties();
+
+ // No addresses.
+ assertFalse(lp.hasIPv4Address());
+ assertFalse(lp.hasIPv6Address());
+
+ // Addresses on stacked links don't count.
+ LinkProperties stacked = new LinkProperties();
+ stacked.setInterfaceName("stacked");
+ lp.addStackedLink(stacked);
+ stacked.addLinkAddress(LINKADDRV4);
+ stacked.addLinkAddress(LINKADDRV6);
+ assertTrue(stacked.hasIPv4Address());
+ assertTrue(stacked.hasIPv6Address());
+ assertFalse(lp.hasIPv4Address());
+ assertFalse(lp.hasIPv6Address());
+ lp.removeStackedLink(stacked);
+ assertFalse(lp.hasIPv4Address());
+ assertFalse(lp.hasIPv6Address());
+
+ // Addresses on the base link.
+ // Check the return values of hasIPvXAddress and ensure the add/remove methods return true
+ // iff something changes.
+ assertTrue(lp.addLinkAddress(LINKADDRV6));
+ assertFalse(lp.hasIPv4Address());
+ assertTrue(lp.hasIPv6Address());
+
+ assertTrue(lp.removeLinkAddress(LINKADDRV6));
+ assertTrue(lp.addLinkAddress(LINKADDRV4));
+ assertTrue(lp.hasIPv4Address());
+ assertFalse(lp.hasIPv6Address());
+
+ assertTrue(lp.addLinkAddress(LINKADDRV6));
+ assertTrue(lp.hasIPv4Address());
+ assertTrue(lp.hasIPv6Address());
+
+ // Adding an address twice has no effect.
+ // Removing an address that's not present has no effect.
+ assertFalse(lp.addLinkAddress(LINKADDRV4));
+ assertTrue(lp.hasIPv4Address());
+ assertTrue(lp.removeLinkAddress(LINKADDRV4));
+ assertFalse(lp.hasIPv4Address());
+ assertFalse(lp.removeLinkAddress(LINKADDRV4));
+ }
+
+ @SmallTest
+ public void testSetLinkAddresses() {
+ LinkProperties lp = new LinkProperties();
+ lp.addLinkAddress(LINKADDRV4);
+ lp.addLinkAddress(LINKADDRV6);
+
+ LinkProperties lp2 = new LinkProperties();
+ lp2.addLinkAddress(LINKADDRV6);
+
+ assertFalse(lp.equals(lp2));
+
+ lp2.setLinkAddresses(lp.getLinkAddresses());
+ assertTrue(lp.equals(lp));
}
}
diff --git a/core/tests/coretests/src/android/webkit/AccessibilityInjectorTest.java b/core/tests/coretests/src/android/webkit/AccessibilityInjectorTest.java
deleted file mode 100644
index 417a85f..0000000
--- a/core/tests/coretests/src/android/webkit/AccessibilityInjectorTest.java
+++ /dev/null
@@ -1,1809 +0,0 @@
-/*
- * Copyright (C) 2010 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;
-
-import android.accessibilityservice.AccessibilityService;
-import android.accessibilityservice.AccessibilityServiceInfo;
-import android.content.ComponentName;
-import android.content.ContentResolver;
-import android.content.Intent;
-import android.os.Handler;
-import android.os.Looper;
-import android.os.SystemClock;
-import android.provider.Settings;
-import android.test.ActivityInstrumentationTestCase2;
-import android.test.suitebuilder.annotation.LargeTest;
-import android.view.KeyEvent;
-import android.view.accessibility.AccessibilityEvent;
-import android.view.accessibility.AccessibilityManager;
-
-/**
- * This is a test for the behavior of the {@link AccessibilityInjector}
- * which is used by {@link WebView} to provide basic accessibility support
- * in case JavaScript is disabled.
- * </p>
- * Note: This test works against the generated {@link AccessibilityEvent}s
- * to so it also checks if the test for announcing navigation axis and
- * status messages as appropriate.
- */
-public class AccessibilityInjectorTest
- extends ActivityInstrumentationTestCase2<AccessibilityInjectorTestActivity> {
-
- /** The timeout to wait for the expected selection. */
- private static final long TIMEOUT_WAIT_FOR_SELECTION_STRING = 1000;
-
- /** The timeout to wait for accessibility and the mock service to be enabled. */
- private static final long TIMEOUT_ENABLE_ACCESSIBILITY_AND_MOCK_SERVICE = 1000;
-
- /** The count of tests to detect when to shut down the service. */
- private static final int TEST_CASE_COUNT = 19;
-
- /** The meta state for pressed left ALT. */
- private static final int META_STATE_ALT_LEFT_ON = KeyEvent.META_ALT_ON
- | KeyEvent.META_ALT_LEFT_ON;
-
- /** Prefix for the CSS style span appended by WebKit. */
- private static final String APPLE_SPAN_PREFIX = "<span class=\"Apple-style-span\"";
-
- /** Suffix for the CSS style span appended by WebKit. */
- private static final String APPLE_SPAN_SUFFIX = "</span>";
-
- /** The value for not specified selection string since null is a valid value. */
- private static final String SELECTION_STRING_UNKNOWN = "Unknown";
-
- /** Lock for locking the test. */
- private static final Object sTestLock = new Object();
-
- /** Key bindings used for testing. */
- private static final String TEST_KEY_DINDINGS =
- "0x13=0x01000100;" +
- "0x14=0x01010100;" +
- "0x15=0x04000000;" +
- "0x16=0x04000000;" +
- "0x200000013=0x03020701:0x03010201:0x03000101:0x03030001:0x03040001:0x03050001:0x03060001;" +
- "0x200000014=0x03010001:0x03020101:0x03070201:0x03030701:0x03040701:0x03050701:0x03060701;" +
- "0x200000015=0x03040301:0x03050401:0x03060501:0x03000601:0x03010601:0x03020601:0x03070601;" +
- "0x200000016=0x03050601:0x03040501:0x03030401:0x03020301:0x03070301:0x03010301:0x03000301;";
-
- /** Handle to the test for use by the mock service. */
- private static AccessibilityInjectorTest sInstance;
-
- /** Flag indicating if the accessibility service is ready to receive events. */
- private static boolean sIsAccessibilityServiceReady;
-
- /** The count of executed tests to detect when to toggle accessibility and the service. */
- private static int sExecutedTestCount;
-
- /** Worker thread with a handler to perform non test thread processing. */
- private Worker mWorker;
-
- /** Handle to the {@link WebView} to load data in. */
- private WebView mWebView;
-
- /** Used for caching the default bindings so they can be restored. */
- private static String sDefaultKeyBindings;
-
- /** The received selection string for assertion checking. */
- private static String sReceivedSelectionString = SELECTION_STRING_UNKNOWN;
-
- public AccessibilityInjectorTest() {
- super(AccessibilityInjectorTestActivity.class);
- }
-
- @Override
- protected void setUp() throws Exception {
- super.setUp();
- mWorker = new Worker();
- sInstance = this;
- if (sExecutedTestCount == 0) {
- // until JUnit4 comes to play with @BeforeTest
- disableAccessibilityAndMockAccessibilityService();
- enableAccessibilityAndMockAccessibilityService();
- injectTestWebContentKeyBindings();
- }
- }
-
- @Override
- protected void tearDown() throws Exception {
- if (mWorker != null) {
- mWorker.stop();
- }
- if (sExecutedTestCount == TEST_CASE_COUNT) {
- // until JUnit4 comes to play with @AfterTest
- disableAccessibilityAndMockAccessibilityService();
- restoreDefaultWebContentKeyBindings();
- }
- super.tearDown();
- }
-
- /**
- * Tests navigation by character.
- */
- @LargeTest
- public void testNavigationByCharacter() throws Exception {
- // a bit ugly but helps detect beginning and end of all tests so accessibility
- // and the mock service are not toggled on every test (expensive)
- sExecutedTestCount++;
-
- String html =
- "<html>" +
- "<head>" +
- "</head>" +
- "<body>" +
- "<p>" +
- "a<b>b</b>c" +
- "</p>" +
- "<p>" +
- "d" +
- "<p/>" +
- "e" +
- "</body>" +
- "</html>";
-
- WebView webView = loadHTML(html);
-
- // change navigation axis to word
- sendKeyEvent(webView, KeyEvent.KEYCODE_DPAD_DOWN, META_STATE_ALT_LEFT_ON);
- assertSelectionString("1"); // expect the word navigation axis
-
- // change navigation axis to character
- sendKeyEvent(webView, KeyEvent.KEYCODE_DPAD_DOWN, META_STATE_ALT_LEFT_ON);
- assertSelectionString("0"); // expect the character navigation axis
-
- // go to the first character
- sendKeyEvent(webView, KeyEvent.KEYCODE_DPAD_DOWN, 0);
- assertSelectionString("a");
-
- // go to the second character
- sendKeyEvent(webView, KeyEvent.KEYCODE_DPAD_DOWN, 0);
- assertSelectionString("<b>b</b>");
-
- // go to the third character
- sendKeyEvent(webView, KeyEvent.KEYCODE_DPAD_DOWN, 0);
- assertSelectionString("c");
-
- // go to the fourth character
- sendKeyEvent(webView, KeyEvent.KEYCODE_DPAD_DOWN, 0);
- assertSelectionString("d");
-
- // go to the fifth character
- sendKeyEvent(webView, KeyEvent.KEYCODE_DPAD_DOWN, 0);
- assertSelectionString("e");
-
- // try to go past the last character
- sendKeyEvent(webView, KeyEvent.KEYCODE_DPAD_DOWN, 0);
- assertSelectionString(null);
-
- // go to the fifth character (reverse)
- sendKeyEvent(webView, KeyEvent.KEYCODE_DPAD_UP, 0);
- assertSelectionString("e");
-
- // go to the fourth character (reverse)
- sendKeyEvent(webView, KeyEvent.KEYCODE_DPAD_UP, 0);
- assertSelectionString("d");
-
- // go to the third character
- sendKeyEvent(webView, KeyEvent.KEYCODE_DPAD_UP, 0);
- assertSelectionString("c");
-
- // go to the second character
- sendKeyEvent(webView, KeyEvent.KEYCODE_DPAD_UP, 0);
- assertSelectionString("<b>b</b>");
-
- // go to the first character
- sendKeyEvent(webView, KeyEvent.KEYCODE_DPAD_UP, 0);
- assertSelectionString("a");
-
- // try to go before the first character
- sendKeyEvent(webView, KeyEvent.KEYCODE_DPAD_UP, 0);
- assertSelectionString(null);
-
- // go to the first character
- sendKeyEvent(webView, KeyEvent.KEYCODE_DPAD_DOWN, 0);
- assertSelectionString("a");
-
- // go to the second character (reverse again)
- sendKeyEvent(webView, KeyEvent.KEYCODE_DPAD_DOWN, 0);
- assertSelectionString("<b>b</b>");
- }
-
- /**
- * Tests navigation by word.
- */
- @LargeTest
- public void testNavigationByWord() throws Exception {
- // a bit ugly but helps detect beginning and end of all tests so accessibility
- // and the mock service are not toggled on every test (expensive)
- sExecutedTestCount++;
-
- String html =
- "<html>" +
- "<head>" +
- "</head>" +
- "<body>" +
- "<p>" +
- "This is <b>a</b> sentence" +
- "</p>" +
- "<p>" +
- " scattered " +
- "<p/>" +
- " all over " +
- "</p>" +
- "<div>" +
- "<p>the place.</p>" +
- "</div>" +
- "</body>" +
- "</html>";
-
- WebView webView = loadHTML(html);
-
- // change navigation axis to word
- sendKeyEvent(webView, KeyEvent.KEYCODE_DPAD_DOWN, META_STATE_ALT_LEFT_ON);
- assertSelectionString("1"); // expect the word navigation axis
-
- // go to the first word
- sendKeyEvent(webView, KeyEvent.KEYCODE_DPAD_DOWN, 0);
- assertSelectionString("This");
-
- // go to the second word
- sendKeyEvent(webView, KeyEvent.KEYCODE_DPAD_DOWN, 0);
- assertSelectionString("is");
-
- // go to the third word
- sendKeyEvent(webView, KeyEvent.KEYCODE_DPAD_DOWN, 0);
- assertSelectionString("<b>a</b>");
-
- // go to the fourth word
- sendKeyEvent(webView, KeyEvent.KEYCODE_DPAD_DOWN, 0);
- assertSelectionString("sentence");
-
- // go to the fifth word
- sendKeyEvent(webView, KeyEvent.KEYCODE_DPAD_DOWN, 0);
- assertSelectionString("scattered");
-
- // go to the sixth word
- sendKeyEvent(webView, KeyEvent.KEYCODE_DPAD_DOWN, 0);
- assertSelectionString("all");
-
- // go to the seventh word
- sendKeyEvent(webView, KeyEvent.KEYCODE_DPAD_DOWN, 0);
- assertSelectionString("over");
-
- // go to the eight word
- sendKeyEvent(webView, KeyEvent.KEYCODE_DPAD_DOWN, 0);
- assertSelectionString("the");
-
- // go to the ninth word
- sendKeyEvent(webView, KeyEvent.KEYCODE_DPAD_DOWN, 0);
- assertSelectionString("place");
-
- // NOTE: WebKit selection returns the dot as a word
- sendKeyEvent(webView, KeyEvent.KEYCODE_DPAD_DOWN, 0);
- assertSelectionString(".");
-
- // try to go past the last word
- sendKeyEvent(webView, KeyEvent.KEYCODE_DPAD_DOWN, 0);
- assertSelectionString(null);
-
- // go to the last word (reverse)
- sendKeyEvent(webView, KeyEvent.KEYCODE_DPAD_UP, 0);
- assertSelectionString("place.");
-
- // go to the eight word
- sendKeyEvent(webView, KeyEvent.KEYCODE_DPAD_UP, 0);
- assertSelectionString("the");
-
- // go to the seventh word
- sendKeyEvent(webView, KeyEvent.KEYCODE_DPAD_UP, 0);
- assertSelectionString("over");
-
- // go to the sixth word
- sendKeyEvent(webView, KeyEvent.KEYCODE_DPAD_UP, 0);
- assertSelectionString("all");
-
- // go to the fifth word
- sendKeyEvent(webView, KeyEvent.KEYCODE_DPAD_UP, 0);
- assertSelectionString("scattered");
-
- // go to the fourth word
- sendKeyEvent(webView, KeyEvent.KEYCODE_DPAD_UP, 0);
- assertSelectionString("sentence");
-
- // go to the third word
- sendKeyEvent(webView, KeyEvent.KEYCODE_DPAD_UP, 0);
- assertSelectionString("<b>a</b>");
-
- // go to the second word
- sendKeyEvent(webView, KeyEvent.KEYCODE_DPAD_UP, 0);
- assertSelectionString("is");
-
- // go to the first word
- sendKeyEvent(webView, KeyEvent.KEYCODE_DPAD_UP, 0);
- assertSelectionString("This");
-
- // try to go before the first word
- sendKeyEvent(webView, KeyEvent.KEYCODE_DPAD_UP, 0);
- assertSelectionString(null);
-
- // go to the first word
- sendKeyEvent(webView, KeyEvent.KEYCODE_DPAD_DOWN, 0);
- assertSelectionString("This");
-
- // go to the second word (reverse again)
- sendKeyEvent(webView, KeyEvent.KEYCODE_DPAD_DOWN, 0);
- assertSelectionString("is");
- }
-
- /**
- * Tests navigation by sentence.
- */
- @LargeTest
- public void testNavigationBySentence() throws Exception {
- // a bit ugly but helps detect beginning and end of all tests so accessibility
- // and the mock service are not toggled on every test (expensive)
- sExecutedTestCount++;
-
- String html =
- "<html>" +
- "<head>" +
- "</head>" +
- "<body>" +
- "<div>" +
- "<p>" +
- "This is the first sentence of the first paragraph and has an <b>inline bold tag</b>." +
- "This is the second sentence of the first paragraph." +
- "</p>" +
- "<h1>This is a heading</h1>" +
- "<p>" +
- "This is the first sentence of the second paragraph." +
- "This is the second sentence of the second paragraph." +
- "</p>" +
- "</div>" +
- "</body>" +
- "</html>";
-
- WebView webView = loadHTML(html);
-
- // Sentence axis is the default
-
- // go to the first sentence
- sendKeyEvent(webView, KeyEvent.KEYCODE_DPAD_DOWN, 0);
- assertSelectionString("This is the first sentence of the first paragraph and has an "
- + "<b>inline bold tag</b>.");
-
- // go to the second sentence
- sendKeyEvent(webView, KeyEvent.KEYCODE_DPAD_DOWN, 0);
- assertSelectionString("This is the second sentence of the first paragraph.");
-
- // go to the third sentence
- sendKeyEvent(webView, KeyEvent.KEYCODE_DPAD_DOWN, 0);
- assertSelectionString("This is a heading");
-
- // go to the fourth sentence
- sendKeyEvent(webView, KeyEvent.KEYCODE_DPAD_DOWN, 0);
- assertSelectionString("This is the first sentence of the second paragraph.");
-
- // go to the fifth sentence
- sendKeyEvent(webView, KeyEvent.KEYCODE_DPAD_DOWN, 0);
- assertSelectionString("This is the second sentence of the second paragraph.");
-
- // try to go past the last sentence
- sendKeyEvent(webView, KeyEvent.KEYCODE_DPAD_DOWN, 0);
- assertSelectionString(null);
-
- // go to the fifth sentence
- sendKeyEvent(webView, KeyEvent.KEYCODE_DPAD_UP, 0);
- assertSelectionString("This is the second sentence of the second paragraph.");
-
- // go to the fourth sentence (reverse)
- sendKeyEvent(webView, KeyEvent.KEYCODE_DPAD_UP, 0);
- assertSelectionString("This is the first sentence of the second paragraph.");
-
- // go to the third sentence
- sendKeyEvent(webView, KeyEvent.KEYCODE_DPAD_UP, 0);
- assertSelectionString("This is a heading");
-
- // go to the second sentence
- sendKeyEvent(webView, KeyEvent.KEYCODE_DPAD_UP, 0);
- assertSelectionString("This is the second sentence of the first paragraph.");
-
- // go to the first sentence
- sendKeyEvent(webView, KeyEvent.KEYCODE_DPAD_UP, 0);
- assertSelectionString("This is the first sentence of the first paragraph and has an "
- + "<b>inline bold tag</b>.");
-
- // try to go before the first sentence
- sendKeyEvent(webView, KeyEvent.KEYCODE_DPAD_UP, 0);
- assertSelectionString(null);
-
- // go to the first sentence
- sendKeyEvent(webView, KeyEvent.KEYCODE_DPAD_DOWN, 0);
- assertSelectionString("This is the first sentence of the first paragraph and has an "
- + "<b>inline bold tag</b>.");
-
- // go to the second sentence (reverse again)
- sendKeyEvent(webView, KeyEvent.KEYCODE_DPAD_DOWN, 0);
- assertSelectionString("This is the second sentence of the first paragraph.");
- }
-
- /**
- * Tests navigation by heading.
- */
- @LargeTest
- public void testNavigationByHeading() throws Exception {
- // a bit ugly but helps detect beginning and end of all tests so accessibility
- // and the mock service are not toggled on every test (expensive)
- sExecutedTestCount++;
-
- String html =
- "<!DOCTYPE html>" +
- "<html>" +
- "<head>" +
- "</head>" +
- "<body>" +
- "<h1>Heading one</h1>" +
- "<p>" +
- "This is some text" +
- "</p>" +
- "<h2>Heading two</h2>" +
- "<p>" +
- "This is some text" +
- "</p>" +
- "<h3>Heading three</h3>" +
- "<p>" +
- "This is some text" +
- "</p>" +
- "<h4>Heading four</h4>" +
- "<p>" +
- "This is some text" +
- "</p>" +
- "<h5>Heading five</h5>" +
- "<p>" +
- "This is some text" +
- "</p>" +
- "<h6>Heading six</h6>" +
- "</body>" +
- "</html>";
-
- WebView webView = loadHTML(html);
-
- // change navigation axis to heading
- sendKeyEvent(webView, KeyEvent.KEYCODE_DPAD_RIGHT, META_STATE_ALT_LEFT_ON);
- assertSelectionString("3"); // expect the heading navigation axis
-
- // go to the first heading
- sendKeyEvent(webView, KeyEvent.KEYCODE_DPAD_DOWN, 0);
- assertSelectionString("<h1>Heading one</h1>");
-
- // go to the second heading
- sendKeyEvent(webView, KeyEvent.KEYCODE_DPAD_DOWN, 0);
- assertSelectionString("<h2>Heading two</h2>");
-
- // go to the third heading
- sendKeyEvent(webView, KeyEvent.KEYCODE_DPAD_DOWN, 0);
- assertSelectionString("<h3>Heading three</h3>");
-
- // go to the fourth heading
- sendKeyEvent(webView, KeyEvent.KEYCODE_DPAD_DOWN, 0);
- assertSelectionString("<h4>Heading four</h4>");
-
- // go to the fifth heading
- sendKeyEvent(webView, KeyEvent.KEYCODE_DPAD_DOWN, 0);
- assertSelectionString("<h5>Heading five</h5>");
-
- // go to the sixth heading
- sendKeyEvent(webView, KeyEvent.KEYCODE_DPAD_DOWN, 0);
- assertSelectionString("<h6>Heading six</h6>");
-
- // try to go past the last heading
- sendKeyEvent(webView, KeyEvent.KEYCODE_DPAD_DOWN, 0);
- assertSelectionString(null);
-
- // go to the fifth heading (reverse)
- sendKeyEvent(webView, KeyEvent.KEYCODE_DPAD_UP, 0);
- assertSelectionString("<h5>Heading five</h5>");
-
- // go to the fourth heading
- sendKeyEvent(webView, KeyEvent.KEYCODE_DPAD_UP, 0);
- assertSelectionString("<h4>Heading four</h4>");
-
- // go to the third heading
- sendKeyEvent(webView, KeyEvent.KEYCODE_DPAD_UP, 0);
- assertSelectionString("<h3>Heading three</h3>");
-
- // go to the second heading
- sendKeyEvent(webView, KeyEvent.KEYCODE_DPAD_UP, 0);
- assertSelectionString("<h2>Heading two</h2>");
-
- // go to the first heading
- sendKeyEvent(webView, KeyEvent.KEYCODE_DPAD_UP, 0);
- assertSelectionString("<h1>Heading one</h1>");
-
- // try to go before the first heading
- sendKeyEvent(webView, KeyEvent.KEYCODE_DPAD_UP, 0);
- assertSelectionString(null);
-
- // go to the second heading (reverse again)
- sendKeyEvent(webView, KeyEvent.KEYCODE_DPAD_DOWN, 0);
- assertSelectionString("<h2>Heading two</h2>");
- }
-
- /**
- * Tests navigation by sibling.
- */
- @LargeTest
- public void testNavigationBySibing() throws Exception {
- // a bit ugly but helps detect beginning and end of all tests so accessibility
- // and the mock service are not toggled on every test (expensive)
- sExecutedTestCount++;
-
- String html =
- "<!DOCTYPE html>" +
- "<html>" +
- "<head>" +
- "</head>" +
- "<body>" +
- "<h1>Heading one</h1>" +
- "<p>" +
- "This is some text" +
- "</p>" +
- "<div>" +
- "<button>Input</button>" +
- "</div>" +
- "</body>" +
- "</html>";
-
- WebView webView = loadHTML(html);
-
- // change navigation axis to heading
- sendKeyEvent(webView, KeyEvent.KEYCODE_DPAD_RIGHT, META_STATE_ALT_LEFT_ON);
- assertSelectionString("3"); // expect the heading navigation axis
-
- // change navigation axis to sibling
- sendKeyEvent(webView, KeyEvent.KEYCODE_DPAD_RIGHT, META_STATE_ALT_LEFT_ON);
- assertSelectionString("4"); // expect the sibling navigation axis
-
- // change navigation axis to parent/first child
- sendKeyEvent(webView, KeyEvent.KEYCODE_DPAD_RIGHT, META_STATE_ALT_LEFT_ON);
- assertSelectionString("5"); // expect the parent/first child navigation axis
-
- // go to the first child of the body
- sendKeyEvent(webView, KeyEvent.KEYCODE_DPAD_DOWN, 0);
- assertSelectionString("<h1>Heading one</h1>");
-
- // change navigation axis to sibling
- sendKeyEvent(webView, KeyEvent.KEYCODE_DPAD_LEFT, META_STATE_ALT_LEFT_ON);
- assertSelectionString("4"); // expect the sibling navigation axis
-
- // go to the next sibling
- sendKeyEvent(webView, KeyEvent.KEYCODE_DPAD_DOWN, 0);
- assertSelectionString("<p>This is some text</p>");
-
- // go to the next sibling
- sendKeyEvent(webView, KeyEvent.KEYCODE_DPAD_DOWN, 0);
- assertSelectionString("<div><button>Input</button></div>");
-
- // try to go past the last sibling
- sendKeyEvent(webView, KeyEvent.KEYCODE_DPAD_DOWN, 0);
- assertSelectionString(null);
-
- // go to the previous sibling (reverse)
- sendKeyEvent(webView, KeyEvent.KEYCODE_DPAD_UP, 0);
- assertSelectionString("<p>This is some text</p>");
-
- // go to the previous sibling
- sendKeyEvent(webView, KeyEvent.KEYCODE_DPAD_UP, 0);
- assertSelectionString("<h1>Heading one</h1>");
-
- // try to go before the previous sibling
- sendKeyEvent(webView, KeyEvent.KEYCODE_DPAD_UP, 0);
- assertSelectionString(null);
-
- // go to the next sibling (reverse again)
- sendKeyEvent(webView, KeyEvent.KEYCODE_DPAD_DOWN, 0);
- assertSelectionString("<p>This is some text</p>");
- }
-
- /**
- * Tests navigation by parent/first child.
- */
- @LargeTest
- public void testNavigationByParentFirstChild() throws Exception {
- // a bit ugly but helps detect beginning and end of all tests so accessibility
- // and the mock service are not toggled on every test (expensive)
- sExecutedTestCount++;
-
- String html =
- "<!DOCTYPE html>" +
- "<html>" +
- "<head>" +
- "</head>" +
- "<body>" +
- "<div>" +
- "<button>Input</button>" +
- "</div>" +
- "</body>" +
- "</html>";
-
- WebView webView = loadHTML(html);
-
- // change navigation axis to document
- sendKeyEvent(webView, KeyEvent.KEYCODE_DPAD_LEFT, META_STATE_ALT_LEFT_ON);
- assertSelectionString("6"); // expect the document navigation axis
-
- // change navigation axis to parent/first child
- sendKeyEvent(webView, KeyEvent.KEYCODE_DPAD_LEFT, META_STATE_ALT_LEFT_ON);
- assertSelectionString("5"); // expect the parent/first child navigation axis
-
- // go to the first child
- sendKeyEvent(webView, KeyEvent.KEYCODE_DPAD_DOWN, 0);
- assertSelectionString("<div><button>Input</button></div>");
-
- // go to the first child
- sendKeyEvent(webView, KeyEvent.KEYCODE_DPAD_DOWN, 0);
- assertSelectionString("<button>Input</button>");
-
- // try to go to the first child of a leaf element
- sendKeyEvent(webView, KeyEvent.KEYCODE_DPAD_DOWN, 0);
- assertSelectionString(null);
-
- // go to the parent (reverse)
- sendKeyEvent(webView, KeyEvent.KEYCODE_DPAD_UP, 0);
- assertSelectionString("<div><button>Input</button></div>");
-
- // go to the parent
- sendKeyEvent(webView, KeyEvent.KEYCODE_DPAD_UP, 0);
- assertSelectionString("<body><div><button>Input</button></div></body>");
-
- // try to go to the body parent
- sendKeyEvent(webView, KeyEvent.KEYCODE_DPAD_UP, 0);
- assertSelectionString(null);
-
- // go to the first child (reverse again)
- sendKeyEvent(webView, KeyEvent.KEYCODE_DPAD_DOWN, 0);
- assertSelectionString("<div><button>Input</button></div>");
- }
-
- /**
- * Tests navigation by document.
- */
- @LargeTest
- public void testNavigationByDocument() throws Exception {
- // a bit ugly but helps detect beginning and end of all tests so accessibility
- // and the mock service are not toggled on every test (expensive)
- sExecutedTestCount++;
-
- String html =
- "<!DOCTYPE html>" +
- "<html>" +
- "<head>" +
- "</head>" +
- "<body>" +
- "<button>Click</button>" +
- "</body>" +
- "</html>";
-
- WebView webView = loadHTML(html);
-
- // change navigation axis to document
- sendKeyEvent(webView, KeyEvent.KEYCODE_DPAD_LEFT, META_STATE_ALT_LEFT_ON);
- assertSelectionString("6"); // expect the document navigation axis
-
- // go to the bottom of the document
- sendKeyEvent(webView, KeyEvent.KEYCODE_DPAD_DOWN, 0);
- assertSelectionString("Click");
-
- // go to the top of the document (reverse)
- sendKeyEvent(webView, KeyEvent.KEYCODE_DPAD_UP, 0);
- assertSelectionString("<body><button>Click</button></body>");
-
- // go to the bottom of the document (reverse again)
- sendKeyEvent(webView, KeyEvent.KEYCODE_DPAD_DOWN, 0);
- assertSelectionString("Click");
- }
-
- /**
- * Tests the sync between the text navigation and navigation by DOM elements.
- */
- @LargeTest
- public void testSyncBetweenTextAndDomNodeNavigation() throws Exception {
- // a bit ugly but helps detect beginning and end of all tests so accessibility
- // and the mock service are not toggled on every test (expensive)
- sExecutedTestCount++;
-
- String html =
- "<!DOCTYPE html>" +
- "<html>" +
- "<head>" +
- "</head>" +
- "<body>" +
- "<p>" +
- "First" +
- "</p>" +
- "<button>Second</button>" +
- "<p>" +
- "Third" +
- "</p>" +
- "</body>" +
- "</html>";
-
- WebView webView = loadHTML(html);
-
- // change navigation axis to word
- sendKeyEvent(webView, KeyEvent.KEYCODE_DPAD_DOWN, META_STATE_ALT_LEFT_ON);
- assertSelectionString("1"); // expect the word navigation axis
-
- // go to the first word
- sendKeyEvent(webView, KeyEvent.KEYCODE_DPAD_DOWN, 0);
- assertSelectionString("First");
-
- // change navigation axis to heading
- sendKeyEvent(webView, KeyEvent.KEYCODE_DPAD_RIGHT, META_STATE_ALT_LEFT_ON);
- assertSelectionString("3"); // expect the heading navigation axis
-
- // change navigation axis to sibling
- sendKeyEvent(webView, KeyEvent.KEYCODE_DPAD_RIGHT, META_STATE_ALT_LEFT_ON);
- assertSelectionString("4"); // expect the sibling navigation axis
-
- // go to the next sibling
- sendKeyEvent(webView, KeyEvent.KEYCODE_DPAD_DOWN, 0);
- assertSelectionString("<button>Second</button>");
-
- // change navigation axis to character
- sendKeyEvent(webView, KeyEvent.KEYCODE_DPAD_UP, META_STATE_ALT_LEFT_ON);
- assertSelectionString("0"); // expect the character navigation axis
-
- // change navigation axis to word
- sendKeyEvent(webView, KeyEvent.KEYCODE_DPAD_UP, META_STATE_ALT_LEFT_ON);
- assertSelectionString("1"); // expect the word navigation axis
-
- // go to the next word
- sendKeyEvent(webView, KeyEvent.KEYCODE_DPAD_DOWN, 0);
- assertSelectionString("Third");
- }
-
- /**
- * Tests that the selection does not cross anchor boundaries. This is a
- * workaround for the asymmetric and inconsistent handling of text with
- * links by WebKit while traversing by sentence.
- */
- @LargeTest
- public void testEnforceSelectionDoesNotCrossAnchorBoundary1() throws Exception {
- // a bit ugly but helps detect beginning and end of all tests so accessibility
- // and the mock service are not toggled on every test (expensive)
- sExecutedTestCount++;
-
- String html =
- "<!DOCTYPE html>" +
- "<html>" +
- "<head>" +
- "</head>" +
- "<body>" +
- "<div>First</div>" +
- "<p>" +
- "<a href=\"\">Second</a> Third" +
- "</p>" +
- "</body>" +
- "</html>";
-
- WebView webView = loadHTML(html);
-
- // go to the first sentence
- sendKeyEvent(webView, KeyEvent.KEYCODE_DPAD_DOWN, 0);
- assertSelectionString("<div>First</div>");
-
- // go to the second sentence
- sendKeyEvent(webView, KeyEvent.KEYCODE_DPAD_DOWN, 0);
- assertSelectionString("<a href=\"\">Second</a>");
-
- // go to the third sentence
- sendKeyEvent(webView, KeyEvent.KEYCODE_DPAD_DOWN, 0);
- assertSelectionString("Third");
-
- // go to past the last sentence
- sendKeyEvent(webView, KeyEvent.KEYCODE_DPAD_DOWN, 0);
- assertSelectionString(null);
-
- // go to the third sentence
- sendKeyEvent(webView, KeyEvent.KEYCODE_DPAD_UP, 0);
- assertSelectionString("Third");
-
- // go to the second sentence
- sendKeyEvent(webView, KeyEvent.KEYCODE_DPAD_UP, 0);
- assertSelectionString("<a href=\"\">Second</a>");
-
- // go to the first sentence
- sendKeyEvent(webView, KeyEvent.KEYCODE_DPAD_UP, 0);
- assertSelectionString("First");
-
- // go to before the first sentence
- sendKeyEvent(webView, KeyEvent.KEYCODE_DPAD_UP, 0);
- assertSelectionString(null);
-
- // go to the first sentence
- sendKeyEvent(webView, KeyEvent.KEYCODE_DPAD_DOWN, 0);
- assertSelectionString("<div>First</div>");
- }
-
- /**
- * Tests that the selection does not cross anchor boundaries. This is a
- * workaround for the asymmetric and inconsistent handling of text with
- * links by WebKit while traversing by sentence.
- */
- @LargeTest
- public void testEnforceSelectionDoesNotCrossAnchorBoundary2() throws Exception {
- // a bit ugly but helps detect beginning and end of all tests so accessibility
- // and the mock service are not toggled on every test (expensive)
- sExecutedTestCount++;
-
- String html =
- "<!DOCTYPE html>" +
- "<html>" +
- "<head>" +
- "</head>" +
- "<body>" +
- "<div>First</div>" +
- "<a href=\"#\">Second</a>" +
- "&nbsp;" +
- "<a href=\"#\">Third</a>" +
- "</body>" +
- "</html>";
-
- WebView webView = loadHTML(html);
-
- // go to the first sentence
- sendKeyEvent(webView, KeyEvent.KEYCODE_DPAD_DOWN, 0);
- assertSelectionString("First");
-
- // go to the second sentence
- sendKeyEvent(webView, KeyEvent.KEYCODE_DPAD_DOWN, 0);
- assertSelectionString("<a href=\"#\">Second</a>");
-
- // go to the third sentence
- sendKeyEvent(webView, KeyEvent.KEYCODE_DPAD_DOWN, 0);
- assertSelectionString("&nbsp;");
-
- // go to the fourth sentence
- sendKeyEvent(webView, KeyEvent.KEYCODE_DPAD_DOWN, 0);
- assertSelectionString("<a href=\"#\">Third</a>");
-
- // go to past the last sentence
- sendKeyEvent(webView, KeyEvent.KEYCODE_DPAD_DOWN, 0);
- assertSelectionString(null);
-
- // go to the fourth sentence
- sendKeyEvent(webView, KeyEvent.KEYCODE_DPAD_UP, 0);
- assertSelectionString("<a href=\"#\">Third</a>");
-
- // go to the third sentence
- sendKeyEvent(webView, KeyEvent.KEYCODE_DPAD_UP, 0);
- assertSelectionString("&nbsp;");
-
- // go to the second sentence
- sendKeyEvent(webView, KeyEvent.KEYCODE_DPAD_UP, 0);
- assertSelectionString("<a href=\"#\">Second</a>");
-
- // go to the first sentence
- sendKeyEvent(webView, KeyEvent.KEYCODE_DPAD_UP, 0);
- assertSelectionString("First");
-
- // go to before the first sentence
- sendKeyEvent(webView, KeyEvent.KEYCODE_DPAD_UP, 0);
- assertSelectionString(null);
-
- // go to the first sentence
- sendKeyEvent(webView, KeyEvent.KEYCODE_DPAD_DOWN, 0);
- assertSelectionString("First");
- }
-
- /**
- * Tests that the selection does not cross anchor boundaries. This is a
- * workaround for the asymmetric and inconsistent handling of text with
- * links by WebKit while traversing by sentence.
- */
- @LargeTest
- public void testEnforceSelectionDoesNotCrossAnchorBoundary3() throws Exception {
- // a bit ugly but helps detect beginning and end of all tests so accessibility
- // and the mock service are not toggled on every test (expensive)
- sExecutedTestCount++;
-
- String html =
- "<!DOCTYPE html>" +
- "<html>" +
- "<head>" +
- "</head>" +
- "<body>" +
- "<div>" +
- "First" +
- "<div>" +
- "<div>" +
- "<a href=\"#\">Second</a>" +
- "</div>" +
- "<div>" +
- "Third" +
- "</div>" +
- "</body>" +
- "</html>";
-
- WebView webView = loadHTML(html);
-
- // go to the first sentence
- sendKeyEvent(webView, KeyEvent.KEYCODE_DPAD_DOWN, 0);
- assertSelectionString("First");
-
- // go to the second sentence
- sendKeyEvent(webView, KeyEvent.KEYCODE_DPAD_DOWN, 0);
- assertSelectionString("<a href=\"#\">Second</a>");
-
- // go to the third sentence
- sendKeyEvent(webView, KeyEvent.KEYCODE_DPAD_DOWN, 0);
- assertSelectionString("Third");
-
- // go to past the last sentence
- sendKeyEvent(webView, KeyEvent.KEYCODE_DPAD_DOWN, 0);
- assertSelectionString(null);
-
- // go to the third sentence
- sendKeyEvent(webView, KeyEvent.KEYCODE_DPAD_UP, 0);
- assertSelectionString("Third");
-
- // go to the second sentence
- sendKeyEvent(webView, KeyEvent.KEYCODE_DPAD_UP, 0);
- assertSelectionString("<a href=\"#\">Second</a>");
-
- // go to the first sentence
- sendKeyEvent(webView, KeyEvent.KEYCODE_DPAD_UP, 0);
- assertSelectionString("First");
-
- // go to before the first sentence
- sendKeyEvent(webView, KeyEvent.KEYCODE_DPAD_UP, 0);
- assertSelectionString(null);
-
- // go to the first sentence
- sendKeyEvent(webView, KeyEvent.KEYCODE_DPAD_DOWN, 0);
- assertSelectionString("First");
- }
-
- /**
- * Tests skipping of content with hidden visibility.
- */
- @LargeTest
- public void testSkipVisibilityHidden() throws Exception {
- // a bit ugly but helps detect beginning and end of all tests so accessibility
- // and the mock service are not toggled on every test (expensive)
- sExecutedTestCount++;
-
- String html =
- "<!DOCTYPE html>" +
- "<html>" +
- "<head>" +
- "</head>" +
- "<body>" +
- "<div>First </div>" +
- "<div style=\"visibility:hidden;\">Second</div>" +
- "<div> Third</div>" +
- "</body>" +
- "</html>";
-
- WebView webView = loadHTML(html);
-
- // change navigation axis to word
- sendKeyEvent(webView, KeyEvent.KEYCODE_DPAD_DOWN, META_STATE_ALT_LEFT_ON);
- assertSelectionString("1"); // expect the word navigation axis
-
- // go to the first word
- sendKeyEvent(webView, KeyEvent.KEYCODE_DPAD_DOWN, 0);
- assertSelectionString("First");
-
- // go to the third word (the second is invisible)
- sendKeyEvent(webView, KeyEvent.KEYCODE_DPAD_DOWN, 0);
- assertSelectionString("Third");
-
- // go to past the last sentence
- sendKeyEvent(webView, KeyEvent.KEYCODE_DPAD_DOWN, 0);
- assertSelectionString(null);
-
- // go to the third word (the second is invisible)
- sendKeyEvent(webView, KeyEvent.KEYCODE_DPAD_UP, 0);
- assertSelectionString("Third");
-
- // go to the first word
- sendKeyEvent(webView, KeyEvent.KEYCODE_DPAD_UP, 0);
- assertSelectionString("First");
-
- // go to before the first word
- sendKeyEvent(webView, KeyEvent.KEYCODE_DPAD_UP, 0);
- assertSelectionString(null);
-
- // go to the first word
- sendKeyEvent(webView, KeyEvent.KEYCODE_DPAD_DOWN, 0);
- assertSelectionString("First");
- }
-
- /**
- * Tests skipping of content with display none.
- */
- @LargeTest
- public void testSkipDisplayNone() throws Exception {
- // a bit ugly but helps detect beginning and end of all tests so accessibility
- // and the mock service are not toggled on every test (expensive)
- sExecutedTestCount++;
-
- String html =
- "<!DOCTYPE html>" +
- "<html>" +
- "<head>" +
- "</head>" +
- "<body>" +
- "<div>First</div>" +
- "<div style=\"display: none;\">Second</div>" +
- "<div>Third</div>" +
- "</body>" +
- "</html>";
-
- WebView webView = loadHTML(html);
-
- // change navigation axis to word
- sendKeyEvent(webView, KeyEvent.KEYCODE_DPAD_DOWN, META_STATE_ALT_LEFT_ON);
- assertSelectionString("1"); // expect the word navigation axis
-
- // go to the first word
- sendKeyEvent(webView, KeyEvent.KEYCODE_DPAD_DOWN, 0);
- assertSelectionString("First");
-
- // go to the third word (the second is invisible)
- sendKeyEvent(webView, KeyEvent.KEYCODE_DPAD_DOWN, 0);
- assertSelectionString("Third");
-
- // go to past the last sentence
- sendKeyEvent(webView, KeyEvent.KEYCODE_DPAD_DOWN, 0);
- assertSelectionString(null);
-
- // go to the third word (the second is invisible)
- sendKeyEvent(webView, KeyEvent.KEYCODE_DPAD_UP, 0);
- assertSelectionString("Third");
-
- // go to the first word
- sendKeyEvent(webView, KeyEvent.KEYCODE_DPAD_UP, 0);
- assertSelectionString("First");
-
- // go to before the first word
- sendKeyEvent(webView, KeyEvent.KEYCODE_DPAD_UP, 0);
- assertSelectionString(null);
-
- // go to the first word
- sendKeyEvent(webView, KeyEvent.KEYCODE_DPAD_DOWN, 0);
- assertSelectionString("First");
- }
-
- /**
- * Tests for the selection not getting stuck.
- *
- * Note: The selection always proceeds but if it can
- * be selecting the same content i.e. between the start
- * and end are contained the same text nodes.
- */
- @LargeTest
- public void testSelectionTextProceed() throws Exception {
- // a bit ugly but helps detect beginning and end of all tests so accessibility
- // and the mock service are not toggled on every test (expensive)
- sExecutedTestCount++;
-
- String html =
- "<!DOCTYPE html>" +
- "<html>" +
- "<head>" +
- "</head>" +
- "<body>" +
- "<a href=\"#\">First</a>" +
- "<span><a href=\"#\"><span>Second</span>&nbsp;<small>a</small></a>" +
- "</span>&nbsp;<a href=\"#\">Third</a>" +
- "</body>" +
- "</html>";
-
- WebView webView = loadHTML(html);
-
- // go to the first sentence
- sendKeyEvent(webView, KeyEvent.KEYCODE_DPAD_DOWN, 0);
- assertSelectionString("<a href=\"#\">First</a>");
-
- // go to the second sentence
- sendKeyEvent(webView, KeyEvent.KEYCODE_DPAD_DOWN, 0);
- assertSelectionString("<a href=\"#\"><span>Second&nbsp;<small>a</small></a>");
-
- // go to the third sentence
- sendKeyEvent(webView, KeyEvent.KEYCODE_DPAD_DOWN, 0);
- assertSelectionString("&nbsp;");
-
- // go to the fourth sentence
- sendKeyEvent(webView, KeyEvent.KEYCODE_DPAD_DOWN, 0);
- assertSelectionString("<a href=\"#\">Third</a>");
-
- // go to past the last sentence
- sendKeyEvent(webView, KeyEvent.KEYCODE_DPAD_DOWN, 0);
- assertSelectionString(null);
-
- // go to the third sentence
- sendKeyEvent(webView, KeyEvent.KEYCODE_DPAD_UP, 0);
- assertSelectionString("<a href=\"#\">Third</a>");
-
- // NOTE: Here we are a bit asymmetric around whitespace but we can live with it
- sendKeyEvent(webView, KeyEvent.KEYCODE_DPAD_UP, 0);
- assertSelectionString("&nbsp;");
-
- // go to the second sentence
- sendKeyEvent(webView, KeyEvent.KEYCODE_DPAD_UP, 0);
- assertSelectionString("<a href=\"#\"><span>Second&nbsp;<small>a</small></a>");
-
- // go to the first sentence
- sendKeyEvent(webView, KeyEvent.KEYCODE_DPAD_UP, 0);
- assertSelectionString("<a href=\"#\">First</a>");
-
- // go to before the first sentence
- sendKeyEvent(webView, KeyEvent.KEYCODE_DPAD_UP, 0);
- assertSelectionString(null);
-
- // go to the first sentence
- sendKeyEvent(webView, KeyEvent.KEYCODE_DPAD_DOWN, 0);
- assertSelectionString("<a href=\"#\">First</a>");
- }
-
- /**
- * Tests if input elements are selected rather skipped.
- */
- @LargeTest
- public void testSelectionOfInputElements() throws Exception {
- // a bit ugly but helps detect beginning and end of all tests so accessibility
- // and the mock service are not toggled on every test (expensive)
- sExecutedTestCount++;
-
- String html =
- "<!DOCTYPE html>" +
- "<html>" +
- "<head>" +
- "</head>" +
- "<body>" +
- "<p>" +
- "First" +
- "</p>" +
- "<input type=\"text\"/>" +
- "<p>" +
- "Second" +
- "</p>" +
- "</body>" +
- "</html>";
-
- WebView webView = loadHTML(html);
-
- // go to the first sentence
- sendKeyEvent(webView, KeyEvent.KEYCODE_DPAD_DOWN, 0);
- assertSelectionString("First");
-
- // go to the second sentence
- sendKeyEvent(webView, KeyEvent.KEYCODE_DPAD_DOWN, 0);
- assertSelectionString("<input type=\"text\">");
-
- // go to the third sentence
- sendKeyEvent(webView, KeyEvent.KEYCODE_DPAD_DOWN, 0);
- assertSelectionString("Second");
-
- // go to past the last sentence
- sendKeyEvent(webView, KeyEvent.KEYCODE_DPAD_DOWN, 0);
- assertSelectionString(null);
-
- // go to the third sentence
- sendKeyEvent(webView, KeyEvent.KEYCODE_DPAD_UP, 0);
- assertSelectionString("Second");
-
- // go to the second sentence
- sendKeyEvent(webView, KeyEvent.KEYCODE_DPAD_UP, 0);
- assertSelectionString("<input type=\"text\">");
-
- // go to the first sentence
- sendKeyEvent(webView, KeyEvent.KEYCODE_DPAD_UP, 0);
- assertSelectionString("First");
-
- // go to before the first sentence
- sendKeyEvent(webView, KeyEvent.KEYCODE_DPAD_UP, 0);
- assertSelectionString(null);
-
- // go to the first sentence
- sendKeyEvent(webView, KeyEvent.KEYCODE_DPAD_DOWN, 0);
- assertSelectionString("First");
- }
-
- /**
- * Tests traversing of input controls.
- */
- @LargeTest
- public void testSelectionOfInputElements2() throws Exception {
- // a bit ugly but helps detect beginning and end of all tests so accessibility
- // and the mock service are not toggled on every test (expensive)
- sExecutedTestCount++;
-
- String html =
- "<!DOCTYPE html>" +
- "<html>" +
- "<head>" +
- "</head>" +
- "<body>" +
- "<div>" +
- "First" +
- "<input type=\"text\"/>" +
- "<span>" +
- "<input type=\"text\"/>" +
- "</span>" +
- "<button type=\"button\">Click Me!</button>" +
- "<div>" +
- "<input type=\"submit\"/>" +
- "</div>" +
- "<p>" +
- "Second" +
- "</p>" +
- "</div>" +
- "</body>" +
- "</html>";
-
- WebView webView = loadHTML(html);
-
- // go to the first sentence
- sendKeyEvent(webView, KeyEvent.KEYCODE_DPAD_DOWN, 0);
- assertSelectionString("First");
-
- // go to the second sentence
- sendKeyEvent(webView, KeyEvent.KEYCODE_DPAD_DOWN, 0);
- assertSelectionString("<input type=\"text\">");
-
- // go to the third sentence
- sendKeyEvent(webView, KeyEvent.KEYCODE_DPAD_DOWN, 0);
- assertSelectionString("<input type=\"text\">");
-
- // go to the fourth sentence
- sendKeyEvent(webView, KeyEvent.KEYCODE_DPAD_DOWN, 0);
- assertSelectionString("<button type=\"button\">Click Me!</button>");
-
- // go to the fifth sentence
- sendKeyEvent(webView, KeyEvent.KEYCODE_DPAD_DOWN, 0);
- assertSelectionString("<input type=\"submit\">");
-
- // go to the sixth sentence
- sendKeyEvent(webView, KeyEvent.KEYCODE_DPAD_DOWN, 0);
- assertSelectionString("Second");
-
- // go to past the last sentence
- sendKeyEvent(webView, KeyEvent.KEYCODE_DPAD_DOWN, 0);
- assertSelectionString(null);
-
- // go to the sixth sentence
- sendKeyEvent(webView, KeyEvent.KEYCODE_DPAD_UP, 0);
- assertSelectionString("Second");
-
- // go to the fifth sentence
- sendKeyEvent(webView, KeyEvent.KEYCODE_DPAD_UP, 0);
- assertSelectionString("<input type=\"submit\">");
-
- // go to the fourth sentence
- sendKeyEvent(webView, KeyEvent.KEYCODE_DPAD_UP, 0);
- assertSelectionString("<button type=\"button\">Click Me!</button>");
-
- // go to the third sentence
- sendKeyEvent(webView, KeyEvent.KEYCODE_DPAD_UP, 0);
- assertSelectionString("<input type=\"text\">");
-
- // go to the second sentence
- sendKeyEvent(webView, KeyEvent.KEYCODE_DPAD_UP, 0);
- assertSelectionString("<input type=\"text\">");
-
- // go to the first sentence
- sendKeyEvent(webView, KeyEvent.KEYCODE_DPAD_UP, 0);
- assertSelectionString("First");
- }
-
- /**
- * Tests traversing of input controls.
- */
- @LargeTest
- public void testSelectionOfInputElements3() throws Exception {
- // a bit ugly but helps detect beginning and end of all tests so accessibility
- // and the mock service are not toggled on every test (expensive)
- sExecutedTestCount++;
-
- String html =
- "<!DOCTYPE html>" +
- "<html>" +
- "<head>" +
- "</head>" +
- "<body>" +
- "<input type=\"text\"/>" +
- "<button type=\"button\">Click Me!</button>" +
- "<select>" +
- "<option value=\"volvo\">Volvo</option>" +
- "<option value=\"saab\">Saab</option>" +
- "</select>" +
- "</body>" +
- "</html>";
-
- WebView webView = loadHTML(html);
-
- // go to the first sentence
- sendKeyEvent(webView, KeyEvent.KEYCODE_DPAD_DOWN, 0);
- assertSelectionString("<input type=\"text\">");
-
- // go to the second sentence
- sendKeyEvent(webView, KeyEvent.KEYCODE_DPAD_DOWN, 0);
- assertSelectionString("<button type=\"button\">Click Me!</button>");
-
- // go to the third sentence
- sendKeyEvent(webView, KeyEvent.KEYCODE_DPAD_DOWN, 0);
- assertSelectionString("<select><option value=\"volvo\">Volvo</option>" +
- "<option value=\"saab\">Saab</option></select>");
-
- // go to past the last sentence
- sendKeyEvent(webView, KeyEvent.KEYCODE_DPAD_DOWN, 0);
- assertSelectionString(null);
-
- // go to the third sentence
- sendKeyEvent(webView, KeyEvent.KEYCODE_DPAD_UP, 0);
- assertSelectionString("<select><option value=\"volvo\">Volvo</option>" +
- "<option value=\"saab\">Saab</option></select>");
-
- // go to the second sentence
- sendKeyEvent(webView, KeyEvent.KEYCODE_DPAD_UP, 0);
- assertSelectionString("<button type=\"button\">Click Me!</button>");
-
- // go to the first sentence
- sendKeyEvent(webView, KeyEvent.KEYCODE_DPAD_UP, 0);
- assertSelectionString("<input type=\"text\">");
-
- // go to before the first sentence
- sendKeyEvent(webView, KeyEvent.KEYCODE_DPAD_UP, 0);
- assertSelectionString(null);
-
- // go to the first sentence
- sendKeyEvent(webView, KeyEvent.KEYCODE_DPAD_DOWN, 0);
- assertSelectionString("<input type=\"text\">");
- }
-
- /**
- * Tests traversing of input controls.
- */
- @LargeTest
- public void testSelectionOfInputElements4() throws Exception {
- // a bit ugly but helps detect beginning and end of all tests so accessibility
- // and the mock service are not toggled on every test (expensive)
- sExecutedTestCount++;
-
- String html =
- "<!DOCTYPE html>" +
- "<html>" +
- "<head>" +
- "</head>" +
- "<body>" +
- "Start" +
- "<span>" +
- "<span>" +
- "<input type=\"submit\">" +
- "</span>" +
- "</span>" +
- "<input type=\"text\" size=\"30\">" +
- "<span>" +
- "<span>" +
- "<input type=\"submit\" size=\"30\">" +
- "</span>" +
- "</span>" +
- "End" +
- "</body>" +
- "</html>";
-
- WebView webView = loadHTML(html);
-
- // go to the first sentence
- sendKeyEvent(webView, KeyEvent.KEYCODE_DPAD_DOWN, 0);
- assertSelectionString("Start");
-
- // go to the second sentence
- sendKeyEvent(webView, KeyEvent.KEYCODE_DPAD_DOWN, 0);
- assertSelectionString("<input type=\"submit\">");
-
- // go to the third sentence
- sendKeyEvent(webView, KeyEvent.KEYCODE_DPAD_DOWN, 0);
- assertSelectionString("<input type=\"text\" size=\"30\">");
-
- // go to the fourth sentence
- sendKeyEvent(webView, KeyEvent.KEYCODE_DPAD_DOWN, 0);
- assertSelectionString("<input type=\"submit\" size=\"30\">");
-
- // go to the fifth sentence
- sendKeyEvent(webView, KeyEvent.KEYCODE_DPAD_DOWN, 0);
- assertSelectionString("End");
-
- // go to past the last sentence
- sendKeyEvent(webView, KeyEvent.KEYCODE_DPAD_DOWN, 0);
- assertSelectionString(null);
-
- // go to the fifth sentence
- sendKeyEvent(webView, KeyEvent.KEYCODE_DPAD_UP, 0);
- assertSelectionString("End");
-
- // go to the fourth sentence
- sendKeyEvent(webView, KeyEvent.KEYCODE_DPAD_UP, 0);
- assertSelectionString("<input type=\"submit\" size=\"30\">");
-
- // go to the third sentence
- sendKeyEvent(webView, KeyEvent.KEYCODE_DPAD_UP, 0);
- assertSelectionString("<input type=\"text\" size=\"30\">");
-
- // go to the second sentence
- sendKeyEvent(webView, KeyEvent.KEYCODE_DPAD_UP, 0);
- assertSelectionString("<input type=\"submit\">");
-
- // go to the first sentence
- sendKeyEvent(webView, KeyEvent.KEYCODE_DPAD_UP, 0);
- assertSelectionString("Start");
-
- // go to before the first sentence
- sendKeyEvent(webView, KeyEvent.KEYCODE_DPAD_UP, 0);
- assertSelectionString(null);
-
- // go to the first sentence
- sendKeyEvent(webView, KeyEvent.KEYCODE_DPAD_DOWN, 0);
- assertSelectionString("Start");
- }
-
- /**
- * Tests traversing of input controls.
- */
- @LargeTest
- public void testSelectionOfInputElements5() throws Exception {
- // a bit ugly but helps detect beginning and end of all tests so accessibility
- // and the mock service are not toggled on every test (expensive)
- sExecutedTestCount++;
-
- String html =
- "<!DOCTYPE html>" +
- "<html>" +
- "<head>" +
- "</head>" +
- "<body>" +
- "<div>" +
- "First" +
- "<input type=\"hidden\">" +
- "<input type=\"hidden\">" +
- "<input type=\"hidden\">" +
- "<input type=\"hidden\">" +
- "<input type=\"text\">" +
- "<span>" +
- "<span>" +
- "<input type=\"submit\">" +
- "</span>" +
- "</span>" +
- "</div>" +
- "</body>" +
- "Second" +
- "</html>";
-
- WebView webView = loadHTML(html);
-
- // go to the first sentence
- sendKeyEvent(webView, KeyEvent.KEYCODE_DPAD_DOWN, 0);
- assertSelectionString("First");
-
- // go to the second sentence
- sendKeyEvent(webView, KeyEvent.KEYCODE_DPAD_DOWN, 0);
- assertSelectionString("<input type=\"text\">");
-
- // go to the third sentence
- sendKeyEvent(webView, KeyEvent.KEYCODE_DPAD_DOWN, 0);
- assertSelectionString("<input type=\"submit\">");
-
- // go to the fourth sentence
- sendKeyEvent(webView, KeyEvent.KEYCODE_DPAD_DOWN, 0);
- assertSelectionString("Second");
-
- // go to past the last sentence
- sendKeyEvent(webView, KeyEvent.KEYCODE_DPAD_DOWN, 0);
- assertSelectionString(null);
-
- // go to the fourth sentence
- sendKeyEvent(webView, KeyEvent.KEYCODE_DPAD_UP, 0);
- assertSelectionString("Second");
-
- // go to the third sentence
- sendKeyEvent(webView, KeyEvent.KEYCODE_DPAD_UP, 0);
- assertSelectionString("<input type=\"submit\">");
-
- // go to the second sentence
- sendKeyEvent(webView, KeyEvent.KEYCODE_DPAD_UP, 0);
- assertSelectionString("<input type=\"text\">");
-
- // go to the first sentence
- sendKeyEvent(webView, KeyEvent.KEYCODE_DPAD_UP, 0);
- assertSelectionString("First");
-
- // go to before the first sentence
- sendKeyEvent(webView, KeyEvent.KEYCODE_DPAD_UP, 0);
- assertSelectionString(null);
-
- // go to the first sentence
- sendKeyEvent(webView, KeyEvent.KEYCODE_DPAD_DOWN, 0);
- assertSelectionString("First");
- }
-
- /**
- * Enable accessibility and the mock accessibility service.
- */
- private void enableAccessibilityAndMockAccessibilityService() {
- // make sure the manager is instantiated so the system initializes it
- AccessibilityManager.getInstance(getActivity());
-
- // enable accessibility and the mock accessibility service
- Settings.Secure.putInt(getActivity().getContentResolver(),
- Settings.Secure.ACCESSIBILITY_ENABLED, 1);
- String enabledServices = new ComponentName(getActivity().getPackageName(),
- MockAccessibilityService.class.getName()).flattenToShortString();
- Settings.Secure.putString(getActivity().getContentResolver(),
- Settings.Secure.ENABLED_ACCESSIBILITY_SERVICES, enabledServices);
-
- // poll within a timeout and let be interrupted in case of success
- long incrementStep = TIMEOUT_ENABLE_ACCESSIBILITY_AND_MOCK_SERVICE / 5;
- long start = SystemClock.uptimeMillis();
- while (SystemClock.uptimeMillis() - start < TIMEOUT_ENABLE_ACCESSIBILITY_AND_MOCK_SERVICE &&
- !sIsAccessibilityServiceReady) {
- synchronized (sTestLock) {
- try {
- sTestLock.wait(incrementStep);
- } catch (InterruptedException ie) {
- /* ignore */
- }
- }
- }
-
- if (!sIsAccessibilityServiceReady) {
- throw new IllegalStateException("MockAccessibilityService not ready. Did you add " +
- "tests and forgot to update AccessibilityInjectorTest#TEST_CASE_COUNT?");
- }
- }
-
- @Override
- protected void scrubClass(Class<?> testCaseClass) {
- /* do nothing - avoid superclass behavior */
- }
-
- /**
- * Strips the apple span appended by WebKit while generating
- * the selection markup.
- *
- * @param markup The markup.
- * @return Stripped from apple spans markup.
- */
- private static String stripAppleSpanFromMarkup(String markup) {
- StringBuilder stripped = new StringBuilder(markup);
- int prefixBegIdx = stripped.indexOf(APPLE_SPAN_PREFIX);
- while (prefixBegIdx >= 0) {
- int prefixEndIdx = stripped.indexOf(">", prefixBegIdx) + 1;
- stripped.replace(prefixBegIdx, prefixEndIdx, "");
- int suffixBegIdx = stripped.lastIndexOf(APPLE_SPAN_SUFFIX);
- int suffixEndIdx = suffixBegIdx + APPLE_SPAN_SUFFIX.length();
- stripped.replace(suffixBegIdx, suffixEndIdx, "");
- prefixBegIdx = stripped.indexOf(APPLE_SPAN_PREFIX);
- }
- return stripped.toString();
- }
-
- /**
- * Disables accessibility and the mock accessibility service.
- */
- private void disableAccessibilityAndMockAccessibilityService() {
- // disable accessibility and the mock accessibility service
- Settings.Secure.putInt(getActivity().getContentResolver(),
- Settings.Secure.ACCESSIBILITY_ENABLED, 0);
- Settings.Secure.putString(getActivity().getContentResolver(),
- Settings.Secure.ENABLED_ACCESSIBILITY_SERVICES, "");
- }
-
- /**
- * Asserts the next <code>expectedSelectionString</code> to be received.
- */
- private void assertSelectionString(String expectedSelectionString) {
- assertTrue("MockAccessibilityService not ready", sIsAccessibilityServiceReady);
-
- long incrementStep = TIMEOUT_WAIT_FOR_SELECTION_STRING / 5;
- long start = SystemClock.uptimeMillis();
- while (SystemClock.uptimeMillis() - start < TIMEOUT_WAIT_FOR_SELECTION_STRING &&
- sReceivedSelectionString == SELECTION_STRING_UNKNOWN) {
- synchronized (sTestLock) {
- try {
- sTestLock.wait(incrementStep);
- } catch (InterruptedException ie) {
- /* ignore */
- }
- }
- }
- try {
- if (sReceivedSelectionString == SELECTION_STRING_UNKNOWN) {
- fail("No selection string received. Expected: " + expectedSelectionString);
- }
- assertEquals(expectedSelectionString, sReceivedSelectionString);
- } finally {
- sReceivedSelectionString = SELECTION_STRING_UNKNOWN;
- }
- }
-
- /**
- * Sends a {@link KeyEvent} (up and down) to the {@link WebView}.
- *
- * @param keyCode The event key code.
- */
- private void sendKeyEvent(WebView webView, int keyCode, int metaState) {
- webView.onKeyDown(keyCode, new KeyEvent(0, 0, KeyEvent.ACTION_DOWN, keyCode, 1, metaState));
- webView.onKeyUp(keyCode, new KeyEvent(0, 0, KeyEvent.ACTION_UP, keyCode, 1, metaState));
- }
-
- /**
- * Loads HTML content in a {@link WebView}.
- *
- * @param html The HTML content;
- * @return The {@link WebView} view.
- */
- private WebView loadHTML(final String html) {
- mWorker.getHandler().post(new Runnable() {
- public void run() {
- if (mWebView == null) {
- mWebView = getActivity().getWebView();
- mWebView.setWebViewClient(new WebViewClient() {
- @Override
- public void onPageFinished(WebView view, String url) {
- mWorker.getHandler().post(new Runnable() {
- public void run() {
- synchronized (sTestLock) {
- sTestLock.notifyAll();
- }
- }
- });
- }
- });
- }
- mWebView.loadData(html, "text/html", null);
- }
- });
- synchronized (sTestLock) {
- try {
- sTestLock.wait();
- } catch (InterruptedException ie) {
- /* ignore */
- }
- }
- return mWebView;
- }
-
- /**
- * Injects web content key bindings used for testing. This is required
- * to ensure that this test will be agnostic to changes of the bindings.
- */
- private void injectTestWebContentKeyBindings() {
- ContentResolver contentResolver = getActivity().getContentResolver();
- sDefaultKeyBindings = Settings.Secure.getString(contentResolver,
- Settings.Secure.ACCESSIBILITY_WEB_CONTENT_KEY_BINDINGS);
- Settings.Secure.putString(contentResolver,
- Settings.Secure.ACCESSIBILITY_WEB_CONTENT_KEY_BINDINGS, TEST_KEY_DINDINGS);
- }
-
- /**
- * Restores the default web content key bindings.
- */
- private void restoreDefaultWebContentKeyBindings() {
- Settings.Secure.putString(getActivity().getContentResolver(),
- Settings.Secure.ACCESSIBILITY_WEB_CONTENT_KEY_BINDINGS,
- sDefaultKeyBindings);
- }
-
- /**
- * This is a worker thread responsible for creating the {@link WebView}.
- */
- private class Worker implements Runnable {
- private final Object mWorkerLock = new Object();
- private Handler mHandler;
-
- public Worker() {
- new Thread(this).start();
- synchronized (mWorkerLock) {
- while (mHandler == null) {
- try {
- mWorkerLock.wait();
- } catch (InterruptedException ex) {
- /* ignore */
- }
- }
- }
- }
-
- public void run() {
- synchronized (mWorkerLock) {
- Looper.prepare();
- mHandler = new Handler();
- mWorkerLock.notifyAll();
- }
- Looper.loop();
- }
-
- public Handler getHandler() {
- return mHandler;
- }
-
- public void stop() {
- mHandler.getLooper().quit();
- }
- }
-
- /**
- * Mock accessibility service to receive the accessibility events
- * with the current {@link WebView} selection.
- */
- public static class MockAccessibilityService extends AccessibilityService {
- private boolean mIsServiceInfoSet;
-
- @Override
- protected void onServiceConnected() {
- if (mIsServiceInfoSet) {
- return;
- }
- AccessibilityServiceInfo info = new AccessibilityServiceInfo();
- info.eventTypes = AccessibilityEvent.TYPE_VIEW_SELECTED;
- info.feedbackType = AccessibilityServiceInfo.FEEDBACK_GENERIC;
- setServiceInfo(info);
- mIsServiceInfoSet = true;
-
- sIsAccessibilityServiceReady = true;
-
- if (sInstance == null) {
- return;
- }
- synchronized (sTestLock) {
- sTestLock.notifyAll();
- }
- }
-
- @Override
- public void onAccessibilityEvent(AccessibilityEvent event) {
- if (sInstance == null) {
- return;
- }
- if (!event.getText().isEmpty()) {
- CharSequence text = event.getText().get(0);
- if (text != null) {
- sReceivedSelectionString = stripAppleSpanFromMarkup(text.toString());
- } else {
- sReceivedSelectionString = null;
- }
- }
- synchronized (sTestLock) {
- sTestLock.notifyAll();
- }
- }
-
- @Override
- public void onInterrupt() {
- /* do nothing */
- }
-
- @Override
- public boolean onUnbind(Intent intent) {
- sIsAccessibilityServiceReady = false;
- return false;
- }
- }
-}
diff --git a/core/tests/coretests/src/android/webkit/UrlInterceptRegistryTest.java b/core/tests/coretests/src/android/webkit/UrlInterceptRegistryTest.java
deleted file mode 100644
index 7504449..0000000
--- a/core/tests/coretests/src/android/webkit/UrlInterceptRegistryTest.java
+++ /dev/null
@@ -1,88 +0,0 @@
-/*
- * Copyright (C) 2009 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;
-
-import android.test.AndroidTestCase;
-import android.util.Log;
-import android.webkit.CacheManager.CacheResult;
-import android.webkit.PluginData;
-import android.webkit.UrlInterceptHandler;
-
-import java.util.LinkedList;
-import java.util.Map;
-
-public class UrlInterceptRegistryTest extends AndroidTestCase {
-
- /**
- * To run these tests: $ mmm
- * frameworks/base/tests/CoreTests/android && adb remount && adb
- * sync $ adb shell am instrument -w -e class \
- * android.webkit.UrlInterceptRegistryTest \
- * android.core/android.test.InstrumentationTestRunner
- */
-
- private static class MockUrlInterceptHandler implements UrlInterceptHandler {
- private PluginData mData;
- private String mUrl;
-
- public MockUrlInterceptHandler(PluginData data, String url) {
- mData = data;
- mUrl = url;
- }
-
- public CacheResult service(String url, Map<String, String> headers) {
- return null;
- }
-
- public PluginData getPluginData(String url,
- Map<String,
- String> headers) {
- if (mUrl.equals(url)) {
- return mData;
- }
-
- return null;
- }
- }
-
- public void testGetPluginData() {
- PluginData data = new PluginData(null, 0 , null, 200);
- String url = new String("url1");
- MockUrlInterceptHandler handler1 =
- new MockUrlInterceptHandler(data, url);
-
- data = new PluginData(null, 0 , null, 404);
- url = new String("url2");
- MockUrlInterceptHandler handler2 =
- new MockUrlInterceptHandler(data, url);
-
- assertTrue(UrlInterceptRegistry.registerHandler(handler1));
- assertTrue(UrlInterceptRegistry.registerHandler(handler2));
-
- data = UrlInterceptRegistry.getPluginData("url1", null);
- assertTrue(data != null);
- assertTrue(data.getStatusCode() == 200);
-
- data = UrlInterceptRegistry.getPluginData("url2", null);
- assertTrue(data != null);
- assertTrue(data.getStatusCode() == 404);
-
- assertTrue(UrlInterceptRegistry.unregisterHandler(handler1));
- assertTrue(UrlInterceptRegistry.unregisterHandler(handler2));
-
- }
-}
diff --git a/core/tests/coretests/src/android/webkit/WebkitTest.java b/core/tests/coretests/src/android/webkit/WebkitTest.java
deleted file mode 100644
index 4685e3c..0000000
--- a/core/tests/coretests/src/android/webkit/WebkitTest.java
+++ /dev/null
@@ -1,59 +0,0 @@
-/*
- * Copyright (C) 2006 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;
-
-import android.test.AndroidTestCase;
-import android.text.format.DateFormat;
-import android.test.suitebuilder.annotation.MediumTest;
-import android.util.Log;
-import android.webkit.DateSorter;
-
-import java.util.Calendar;
-import java.util.Date;
-
-public class WebkitTest extends AndroidTestCase {
-
- private static final String LOGTAG = WebkitTest.class.getName();
-
- @MediumTest
- public void testDateSorter() throws Exception {
- /**
- * Note: check the logging output manually to test
- * nothing automated yet, besides object creation
- */
- DateSorter dateSorter = new DateSorter(mContext);
- Date date = new Date();
-
- for (int i = 0; i < DateSorter.DAY_COUNT; i++) {
- Log.i(LOGTAG, "Boundary " + i + " " + dateSorter.getBoundary(i));
- Log.i(LOGTAG, "Label " + i + " " + dateSorter.getLabel(i));
- }
-
- Calendar c = Calendar.getInstance();
- long time = c.getTimeInMillis();
- int index;
- Log.i(LOGTAG, "now: " + dateSorter.getIndex(time));
- for (int i = 0; i < 20; i++) {
- time -= 8 * 60 * 60 * 1000; // 8 hours
- date.setTime(time);
- c.setTime(date);
- index = dateSorter.getIndex(time);
- Log.i(LOGTAG, "time: " + DateFormat.format("yyyy/MM/dd HH:mm:ss", c).toString() +
- " " + index + " " + dateSorter.getLabel(index));
- }
- }
-}
diff --git a/core/tests/coretests/src/android/webkit/ZoomManagerTest.java b/core/tests/coretests/src/android/webkit/ZoomManagerTest.java
deleted file mode 100644
index 7e0e0b2..0000000
--- a/core/tests/coretests/src/android/webkit/ZoomManagerTest.java
+++ /dev/null
@@ -1,128 +0,0 @@
-/*
- * Copyright (C) 2010 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;
-
-import android.test.AndroidTestCase;
-
-public class ZoomManagerTest extends AndroidTestCase {
-
- private ZoomManager zoomManager;
-
- @Override
- public void setUp() {
- WebView webView = new WebView(this.getContext());
- WebViewClassic webViewClassic = WebViewClassic.fromWebView(webView);
- CallbackProxy callbackProxy = new CallbackProxy(this.getContext(), webViewClassic);
- zoomManager = new ZoomManager(webViewClassic, callbackProxy);
-
- zoomManager.init(1.00f);
- }
-
- public void testInit() {
- testInit(0.01f);
- testInit(1.00f);
- testInit(1.25f);
- }
-
- private void testInit(float density) {
- zoomManager.init(density);
- actualScaleTest(density);
- defaultScaleTest(density);
- assertEquals(zoomManager.getDefaultMaxZoomScale(), zoomManager.getMaxZoomScale());
- assertEquals(zoomManager.getDefaultMinZoomScale(), zoomManager.getMinZoomScale());
- assertEquals(density, zoomManager.getTextWrapScale());
- }
-
- public void testUpdateDefaultZoomDensity() {
- // test the basic case where the actual values are equal to the defaults
- testUpdateDefaultZoomDensity(0.01f);
- testUpdateDefaultZoomDensity(1.00f);
- testUpdateDefaultZoomDensity(1.25f);
- }
-
- private void testUpdateDefaultZoomDensity(float density) {
- zoomManager.updateDefaultZoomDensity(density);
- defaultScaleTest(density);
- }
-
- public void testUpdateDefaultZoomDensityWithSmallMinZoom() {
- // test the case where the minZoomScale has changed to be < the default
- float newDefaultScale = 1.50f;
- float minZoomScale = ZoomManager.DEFAULT_MIN_ZOOM_SCALE_FACTOR * newDefaultScale;
- WebViewCore.ViewState minViewState = new WebViewCore.ViewState();
- minViewState.mMinScale = minZoomScale - 0.1f;
- zoomManager.updateZoomRange(minViewState, 0, 0);
- zoomManager.updateDefaultZoomDensity(newDefaultScale);
- defaultScaleTest(newDefaultScale);
- }
-
- public void testUpdateDefaultZoomDensityWithLargeMinZoom() {
- // test the case where the minZoomScale has changed to be > the default
- float newDefaultScale = 1.50f;
- float minZoomScale = ZoomManager.DEFAULT_MIN_ZOOM_SCALE_FACTOR * newDefaultScale;
- WebViewCore.ViewState minViewState = new WebViewCore.ViewState();
- minViewState.mMinScale = minZoomScale + 0.1f;
- zoomManager.updateZoomRange(minViewState, 0, 0);
- zoomManager.updateDefaultZoomDensity(newDefaultScale);
- defaultScaleTest(newDefaultScale);
- }
-
- public void testUpdateDefaultZoomDensityWithSmallMaxZoom() {
- // test the case where the maxZoomScale has changed to be < the default
- float newDefaultScale = 1.50f;
- float maxZoomScale = ZoomManager.DEFAULT_MAX_ZOOM_SCALE_FACTOR * newDefaultScale;
- WebViewCore.ViewState maxViewState = new WebViewCore.ViewState();
- maxViewState.mMaxScale = maxZoomScale - 0.1f;
- zoomManager.updateZoomRange(maxViewState, 0, 0);
- zoomManager.updateDefaultZoomDensity(newDefaultScale);
- defaultScaleTest(newDefaultScale);
- }
-
- public void testUpdateDefaultZoomDensityWithLargeMaxZoom() {
- // test the case where the maxZoomScale has changed to be > the default
- float newDefaultScale = 1.50f;
- float maxZoomScale = ZoomManager.DEFAULT_MAX_ZOOM_SCALE_FACTOR * newDefaultScale;
- WebViewCore.ViewState maxViewState = new WebViewCore.ViewState();
- maxViewState.mMaxScale = maxZoomScale + 0.1f;
- zoomManager.updateZoomRange(maxViewState, 0, 0);
- zoomManager.updateDefaultZoomDensity(newDefaultScale);
- defaultScaleTest(newDefaultScale);
- }
-
- public void testComputeScaleWithLimits() {
- final float maxScale = zoomManager.getMaxZoomScale();
- final float minScale = zoomManager.getMinZoomScale();
- assertTrue(maxScale > minScale);
- assertEquals(maxScale, zoomManager.computeScaleWithLimits(maxScale));
- assertEquals(maxScale, zoomManager.computeScaleWithLimits(maxScale + .01f));
- assertEquals(minScale, zoomManager.computeScaleWithLimits(minScale));
- assertEquals(minScale, zoomManager.computeScaleWithLimits(minScale - .01f));
- }
-
- private void actualScaleTest(float actualScale) {
- assertEquals(actualScale, zoomManager.getScale());
- assertEquals(1 / actualScale, zoomManager.getInvScale());
- }
-
- private void defaultScaleTest(float defaultScale) {
- final float maxDefault = ZoomManager.DEFAULT_MAX_ZOOM_SCALE_FACTOR * defaultScale;
- final float minDefault = ZoomManager.DEFAULT_MIN_ZOOM_SCALE_FACTOR * defaultScale;
- assertEquals(defaultScale, zoomManager.getDefaultScale());
- assertEquals(1 / defaultScale, zoomManager.getInvDefaultScale());
- assertEquals(maxDefault, zoomManager.getDefaultMaxZoomScale());
- assertEquals(minDefault, zoomManager.getDefaultMinZoomScale());
- }
-}