am a222a71e: am 40198166: am 28179d62: Merge "Some Assorted WebKit Test Fixes" into froyo

Merge commit 'a222a71e181949e154e3d57fb704b5a4283f2f80' into gingerbread-plus-aosp

* commit 'a222a71e181949e154e3d57fb704b5a4283f2f80':
  Some Assorted WebKit Test Fixes
diff --git a/tests/appsecurity-tests/Android.mk b/tests/appsecurity-tests/Android.mk
index a0f7f41..4ec9922 100644
--- a/tests/appsecurity-tests/Android.mk
+++ b/tests/appsecurity-tests/Android.mk
@@ -23,7 +23,7 @@
 
 LOCAL_MODULE := CtsAppSecurityTests
 
-LOCAL_JAVA_LIBRARIES := hosttestlib ddmlib junit
+LOCAL_JAVA_LIBRARIES := hosttestlib ddmlib-prebuilt junit
 
 include $(BUILD_HOST_JAVA_LIBRARY)
 
diff --git a/tests/appsecurity-tests/src/com/android/cts/appsecurity/AppSecurityTests.java b/tests/appsecurity-tests/src/com/android/cts/appsecurity/AppSecurityTests.java
index 2833fa4..db25260 100644
--- a/tests/appsecurity-tests/src/com/android/cts/appsecurity/AppSecurityTests.java
+++ b/tests/appsecurity-tests/src/com/android/cts/appsecurity/AppSecurityTests.java
@@ -18,10 +18,15 @@
 
 import java.io.File;
 import java.io.IOException;
+import java.util.Map;
 
 import junit.framework.Test;
 
+import com.android.ddmlib.AdbCommandRejectedException;
+import com.android.ddmlib.InstallException;
 import com.android.ddmlib.Log;
+import com.android.ddmlib.ShellCommandUnresponsiveException;
+import com.android.ddmlib.TimeoutException;
 import com.android.ddmlib.testrunner.ITestRunListener;
 import com.android.ddmlib.testrunner.RemoteAndroidTestRunner;
 import com.android.ddmlib.testrunner.TestIdentifier;
@@ -78,7 +83,7 @@
      * Test that an app that declares the same shared uid as an existing app, cannot be installed
      * if it is signed with a different certificate.
      */
-    public void testSharedUidDifferentCerts() throws IOException {
+    public void testSharedUidDifferentCerts() throws InstallException {
         Log.i(LOG_TAG, "installing apks with shared uid, but different certs");
         try {
             // cleanup test apps that might be installed from previous partial test run
@@ -104,7 +109,7 @@
      * Test that an app update cannot be installed over an existing app if it has a different
      * certificate.
      */
-    public void testAppUpgradeDifferentCerts() throws IOException {
+    public void testAppUpgradeDifferentCerts() throws InstallException {
         Log.i(LOG_TAG, "installing app upgrade with different certs");
         try {
             // cleanup test app that might be installed from previous partial test run
@@ -127,7 +132,8 @@
     /**
      * Test that an app cannot access another app's private data.
      */
-    public void testAppFailAccessPrivateData() throws IOException {
+    public void testAppFailAccessPrivateData() throws InstallException, TimeoutException,
+            AdbCommandRejectedException, ShellCommandUnresponsiveException, IOException {
         Log.i(LOG_TAG, "installing app that attempts to access another app's private data");
         try {
             // cleanup test app that might be installed from previous partial test run
@@ -155,7 +161,8 @@
     /**
      * Test that an app cannot instrument another app that is signed with different certificate.
      */
-    public void testInstrumentationDiffCert() throws IOException {
+    public void testInstrumentationDiffCert() throws InstallException, TimeoutException,
+            AdbCommandRejectedException, ShellCommandUnresponsiveException, IOException {
         Log.i(LOG_TAG, "installing app that attempts to instrument another app");
         try {
             // cleanup test app that might be installed from previous partial test run
@@ -186,7 +193,8 @@
      * Test that an app cannot use a signature-enforced permission if it is signed with a different
      * certificate than the app that declared the permission.
      */
-    public void testPermissionDiffCert() throws IOException {
+    public void testPermissionDiffCert() throws InstallException, TimeoutException,
+            AdbCommandRejectedException, ShellCommandUnresponsiveException, IOException {
         Log.i(LOG_TAG, "installing app that attempts to use permission of another app");
         try {
             // cleanup test app that might be installed from previous partial test run
@@ -225,9 +233,15 @@
      *
      * @param pkgName Android application package for tests
      * @return <code>true</code> if all tests passed.
-     * @throws IOException if connection to device was lost
+     * @throws TimeoutException in case of a timeout on the connection.
+     * @throws AdbCommandRejectedException if adb rejects the command
+     * @throws ShellCommandUnresponsiveException if the device did not output any test result for
+     * a period longer than the max time to output.
+     * @throws IOException if connection to device was lost.
      */
-    private boolean runDeviceTests(String pkgName) throws IOException {
+    private boolean runDeviceTests(String pkgName)
+            throws TimeoutException, AdbCommandRejectedException,
+            ShellCommandUnresponsiveException, IOException {
         CollectingTestRunListener listener = doRunTests(pkgName);
         return listener.didAllTestsPass();
     }
@@ -236,9 +250,15 @@
      * Helper method to run tests and return the listener that collected the results.
      * @param pkgName Android application package for tests
      * @return the {@link CollectingTestRunListener}
-     * @throws IOException if connection to device was lost
+     * @throws TimeoutException in case of a timeout on the connection.
+     * @throws AdbCommandRejectedException if adb rejects the command
+     * @throws ShellCommandUnresponsiveException if the device did not output any test result for
+     * a period longer than the max time to output.
+     * @throws IOException if connection to device was lost.
      */
-    private CollectingTestRunListener doRunTests(String pkgName) throws IOException {
+    private CollectingTestRunListener doRunTests(String pkgName)
+            throws TimeoutException, AdbCommandRejectedException,
+            ShellCommandUnresponsiveException, IOException {
         RemoteAndroidTestRunner testRunner = new RemoteAndroidTestRunner(pkgName, getDevice());
         CollectingTestRunListener listener = new CollectingTestRunListener();
         testRunner.run(listener);
@@ -261,7 +281,7 @@
             mAllTestsPassed = false;
         }
 
-        public void testRunEnded(long elapsedTime) {
+        public void testRunEnded(long elapsedTime, Map<String, String> resultBundle) {
             // ignore
         }
 
diff --git a/tests/tests/widget/src/android/widget/cts/ArrayAdapterTest.java b/tests/tests/widget/src/android/widget/cts/ArrayAdapterTest.java
index a268cba..4541e9d 100644
--- a/tests/tests/widget/src/android/widget/cts/ArrayAdapterTest.java
+++ b/tests/tests/widget/src/android/widget/cts/ArrayAdapterTest.java
@@ -526,6 +526,94 @@
         assertEquals(2, mockDataSetObserver.getCalledOnChangedCount());
     }
 
+    /**
+     * insert multiple items via add, notify data changed
+     * check count and content
+     */
+    @TestTargets({
+        @TestTargetNew(
+            level = TestLevel.COMPLETE,
+            method = "add",
+            args = {Object.class}
+        )
+    })
+    public void testAdd() {
+        mArrayAdapter.setNotifyOnChange(true);
+        final MockDataSetObserver mockDataSetObserver = new MockDataSetObserver();
+        mArrayAdapter.registerDataSetObserver(mockDataSetObserver);
+
+        mArrayAdapter.clear();
+        assertEquals(mArrayAdapter.getCount(), 0);
+
+        mArrayAdapter.add("testing");
+        mArrayAdapter.add("android");
+        assertEquals(mArrayAdapter.getCount(), 2);
+        assertEquals(mArrayAdapter.getItem(0), "testing");
+        assertEquals(mArrayAdapter.getItem(1), "android");
+    }
+
+    /**
+     * insert multiple items via addAll, notify data changed
+     * check count and content
+     */
+    @TestTargets({
+        @TestTargetNew(
+            level = TestLevel.COMPLETE,
+            method = "addAll",
+            args = {java.util.Collection.class}
+        )
+    })
+    public void testAddAllCollection() {
+        mArrayAdapter.setNotifyOnChange(true);
+        final MockDataSetObserver mockDataSetObserver = new MockDataSetObserver();
+        mArrayAdapter.registerDataSetObserver(mockDataSetObserver);
+
+        List<String> list = new ArrayList<String>();
+        list.add("");
+        list.add("hello");
+        list.add("android");
+        list.add("!");
+
+        mArrayAdapter.clear();
+        assertEquals(mArrayAdapter.getCount(), 0);
+
+        mArrayAdapter.addAll(list);
+        assertEquals(mArrayAdapter.getCount(), list.size());
+
+        assertEquals(mArrayAdapter.getItem(0), list.get(0));
+        assertEquals(mArrayAdapter.getItem(1), list.get(1));
+        assertEquals(mArrayAdapter.getItem(2), list.get(2));
+        assertEquals(mArrayAdapter.getItem(3), list.get(3));
+    }
+
+    /**
+     * insert multiple items via addAll, notify data changed
+     * check count and content
+     */
+    @TestTargets({
+        @TestTargetNew(
+            level = TestLevel.COMPLETE,
+            method = "addAll",
+            args = {Object[].class}
+        )
+    })
+    public void testAddAllParams() {
+        mArrayAdapter.setNotifyOnChange(true);
+        final MockDataSetObserver mockDataSetObserver = new MockDataSetObserver();
+        mArrayAdapter.registerDataSetObserver(mockDataSetObserver);
+
+        mArrayAdapter.clear();
+        assertEquals(mArrayAdapter.getCount(), 0);
+
+        mArrayAdapter.addAll("this", "is", "a", "unit", "test");
+        assertEquals(mArrayAdapter.getCount(), 5);
+        assertEquals(mArrayAdapter.getItem(0), "this");
+        assertEquals(mArrayAdapter.getItem(1), "is");
+        assertEquals(mArrayAdapter.getItem(2), "a");
+        assertEquals(mArrayAdapter.getItem(3), "unit");
+        assertEquals(mArrayAdapter.getItem(4), "test");
+    }
+
     private static class MockDataSetObserver extends DataSetObserver {
 
         private int mCalledOnChangedCount;
diff --git a/tools/host/src/Android.mk b/tools/host/src/Android.mk
index df43dc8..47a9cb8 100644
--- a/tools/host/src/Android.mk
+++ b/tools/host/src/Android.mk
@@ -21,7 +21,7 @@
 
 LOCAL_JAR_MANIFEST := ../etc/manifest.txt
 LOCAL_JAVA_LIBRARIES := \
-    ddmlib junit hosttestlib
+    ddmlib-prebuilt junit hosttestlib
 
 LOCAL_MODULE := cts
 
diff --git a/tools/host/src/com/android/cts/DeviceManager.java b/tools/host/src/com/android/cts/DeviceManager.java
index 528036e..80e05d5 100644
--- a/tools/host/src/com/android/cts/DeviceManager.java
+++ b/tools/host/src/com/android/cts/DeviceManager.java
@@ -16,8 +16,10 @@
 
 package com.android.cts;
 
+import com.android.ddmlib.AdbCommandRejectedException;
 import com.android.ddmlib.AndroidDebugBridge;
 import com.android.ddmlib.IDevice;
+import com.android.ddmlib.TimeoutException;
 import com.android.ddmlib.AndroidDebugBridge.IDeviceChangeListener;
 
 import java.io.IOException;
@@ -230,6 +232,10 @@
                 mSemaphore.release();
             } catch (IOException e) {
                 // FIXME: handle failed connection to device.
+            } catch (TimeoutException e) {
+                // FIXME: handle failed connection to device.
+            } catch (AdbCommandRejectedException e) {
+                // FIXME: handle failed connection to device.
             }
         }
     }
diff --git a/tools/host/src/com/android/cts/ReferenceAppTestPackage.java b/tools/host/src/com/android/cts/ReferenceAppTestPackage.java
index 2b70b86..6b91ab4 100644
--- a/tools/host/src/com/android/cts/ReferenceAppTestPackage.java
+++ b/tools/host/src/com/android/cts/ReferenceAppTestPackage.java
@@ -16,8 +16,10 @@
 
 package com.android.cts;
 
+import com.android.ddmlib.AdbCommandRejectedException;
 import com.android.ddmlib.MultiLineReceiver;
 import com.android.ddmlib.RawImage;
+import com.android.ddmlib.TimeoutException;
 import com.android.ddmlib.log.LogReceiver.ILogListener;
 import com.android.ddmlib.log.LogReceiver.LogEntry;
 
@@ -199,6 +201,10 @@
                     }
                 } catch (IOException e) {
                     Log.e("Error taking snapshot! " + cmdArgs, e);
+                } catch (TimeoutException e) {
+                    Log.e("Error taking snapshot! " + cmdArgs, e);
+                } catch (AdbCommandRejectedException e) {
+                    Log.e("Error taking snapshot! " + cmdArgs, e);
                 }
             }
         });
diff --git a/tools/host/src/com/android/cts/TestDevice.java b/tools/host/src/com/android/cts/TestDevice.java
index 65ff969..5fd00b4 100644
--- a/tools/host/src/com/android/cts/TestDevice.java
+++ b/tools/host/src/com/android/cts/TestDevice.java
@@ -16,6 +16,7 @@
 
 package com.android.cts;
 
+import com.android.ddmlib.AdbCommandRejectedException;
 import com.android.ddmlib.Client;
 import com.android.ddmlib.ClientData;
 import com.android.ddmlib.IDevice;
@@ -23,13 +24,16 @@
 import com.android.ddmlib.MultiLineReceiver;
 import com.android.ddmlib.NullOutputReceiver;
 import com.android.ddmlib.RawImage;
+import com.android.ddmlib.ShellCommandUnresponsiveException;
+import com.android.ddmlib.SyncException;
 import com.android.ddmlib.SyncService;
 import com.android.ddmlib.SyncService.ISyncProgressMonitor;
-import com.android.ddmlib.SyncService.SyncResult;
+import com.android.ddmlib.TimeoutException;
 import com.android.ddmlib.log.LogReceiver;
 import com.android.ddmlib.log.LogReceiver.ILogListener;
 
 import java.io.BufferedReader;
+import java.io.FileNotFoundException;
 import java.io.IOException;
 import java.io.InputStream;
 import java.io.InputStreamReader;
@@ -101,6 +105,8 @@
             try {
                 mDevice.runLogService("main", logReceiver);
             } catch (IOException e) {
+            } catch (TimeoutException e) {
+            } catch (AdbCommandRejectedException e) {
             }
         }
 
@@ -136,6 +142,10 @@
             mSyncService = mDevice.getSyncService();
         } catch (IOException e) {
             // FIXME: handle failed connection.
+        } catch (TimeoutException e) {
+            // FIXME: handle failed connection.
+        } catch (AdbCommandRejectedException e) {
+            // FIXME: handle failed connection.
         }
         mBatchModeResultParser = null;
         mUninstallObserver = new PackageActionObserver(ACTION_UNINSTALL);
@@ -922,10 +932,16 @@
      * @param remotePath The remote path.
      */
     public void pushFile(String localPath, String remotePath) {
-        SyncResult result = mSyncService.pushFile(localPath, remotePath,
-                new PushMonitor());
-        if (result.getCode() != SyncService.RESULT_OK) {
-            Log.e("Uploading file failed: " + result.getMessage(), null);
+        try {
+            mSyncService.pushFile(localPath, remotePath, new PushMonitor());
+        } catch (TimeoutException e) {
+            Log.e("Uploading file failed: timeout", null);
+        } catch (SyncException e) {
+            Log.e("Uploading file failed: " + e.getMessage(), null);
+        } catch (FileNotFoundException e) {
+            Log.e("Uploading file failed: " + e.getMessage(), null);
+        } catch (IOException e) {
+            Log.e("Uploading file failed: " + e.getMessage(), null);
         }
     }
 
@@ -1670,6 +1686,12 @@
                     mDevice.executeShellCommand(cmd, receiver);
                 } catch (IOException e) {
                     Log.e("", e);
+                } catch (TimeoutException e) {
+                    Log.e("", e);
+                } catch (AdbCommandRejectedException e) {
+                    Log.e("", e);
+                } catch (ShellCommandUnresponsiveException e) {
+                    Log.e("", e);
                 }
             }
         }.start();
@@ -1887,8 +1909,11 @@
      *
      * @return the screenshot
      * @throws IOException
+     * @throws AdbCommandRejectedException
+     * @throws TimeoutException
      */
-    public RawImage getScreenshot() throws IOException {
+    public RawImage getScreenshot() throws IOException, TimeoutException,
+            AdbCommandRejectedException {
         return mDevice.getScreenshot();
     }
 }
diff --git a/tools/utils/startcts b/tools/utils/startcts
index 59ca6aa..a4c97f8 100755
--- a/tools/utils/startcts
+++ b/tools/utils/startcts
@@ -49,7 +49,7 @@
 checkDir ${CTS_ROOT} "Error: Cannot locate CTS in \"${CTS_DIR}\". Please check your configuration in $0"
 checkDir ${SDK_ROOT} "Error: Cannot locate SDK installation in \"${SDK_ROOT}\". Please check your configuration in $0"
 
-DDM_LIB=${SDK_ROOT}/tools/lib/ddmlib.jar
+DDM_LIB=${CTS_ROOT}/tools/ddmlib-prebuilt.jar
 CTS_LIB=${CTS_ROOT}/tools/cts.jar
 JUNIT_LIB=${CTS_ROOT}/tools/junit.jar
 HOSTTEST_LIB=${CTS_ROOT}/tools/hosttestlib.jar