Merge "Use Dips in Some Tests" into eclair
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 9862b8de..04572f5 100644
--- a/tests/appsecurity-tests/src/com/android/cts/appsecurity/AppSecurityTests.java
+++ b/tests/appsecurity-tests/src/com/android/cts/appsecurity/AppSecurityTests.java
@@ -166,18 +166,15 @@
getTestAppFilePath(TARGET_INSTRUMENT_APK), false);
assertNull("failed to install target instrumentation app", installResult);
- // the app will install, but will get error at runtime
+ // the app will install, but will get error at runtime when starting instrumentation
installResult = getDevice().installPackage(getTestAppFilePath(INSTRUMENT_DIFF_CERT_APK),
false);
assertNull("failed to install instrumentation app with diff cert", installResult);
- // run INSTRUMENT_DIFF_CERT_PKG tests - expect the test run to fail
- String runResults = runDeviceTestsWithRunResult(INSTRUMENT_DIFF_CERT_PKG);
- assertNotNull("running instrumentation with diff cert unexpectedly succeeded",
- runResults);
- String msg = String.format("Unexpected error message result from %s. Received %s",
- "instrumentation with diff cert. Expected starts with Permission Denial",
- runResults);
- assertTrue(msg, runResults.startsWith("Permission Denial"));
+ // run INSTRUMENT_DIFF_CERT_PKG tests
+ // this test will attempt to call startInstrumentation directly and verify
+ // SecurityException is thrown
+ assertTrue("running instrumentation with diff cert unexpectedly succeeded",
+ runDeviceTests(INSTRUMENT_DIFF_CERT_PKG));
}
finally {
getDevice().uninstallPackage(TARGET_INSTRUMENT_PKG);
@@ -246,17 +243,6 @@
return listener;
}
- /**
- * Helper method to run the specified packages tests, and return the test run error message.
- *
- * @param pkgName Android application package for tests
- * @return the test run error message or <code>null</code> if test run completed.
- */
- private String runDeviceTestsWithRunResult(String pkgName) {
- CollectingTestRunListener listener = doRunTests(pkgName);
- return listener.getTestRunErrorMessage();
- }
-
private static class CollectingTestRunListener implements ITestRunListener {
private boolean mAllTestsPassed = true;
diff --git a/tests/appsecurity-tests/test-apps/InstrumentationAppDiffCert/AndroidManifest.xml b/tests/appsecurity-tests/test-apps/InstrumentationAppDiffCert/AndroidManifest.xml
index e62f968..8102656 100644
--- a/tests/appsecurity-tests/test-apps/InstrumentationAppDiffCert/AndroidManifest.xml
+++ b/tests/appsecurity-tests/test-apps/InstrumentationAppDiffCert/AndroidManifest.xml
@@ -26,7 +26,15 @@
</application>
<!-- assumes com.android.cts.targetinstrumentationapp is signed with diff cert -->
- <instrumentation android:name="android.test.InstrumentationTestRunner"
+ <instrumentation android:name="android.app.Instrumentation"
android:targetPackage="com.android.cts.targetinstrumentationapp"
+ android:label="Instrumentation that targets app with different cert" />
+
+ <!--
+ A self-instrumenting test runner, that will try to start the above instrumentation and
+ verify it fails.
+ -->
+ <instrumentation android:name="android.test.InstrumentationTestRunner"
+ android:targetPackage="com.android.cts.instrumentationdiffcertapp"
android:label="Test for instrumentation with different cert" />
</manifest>
diff --git a/tests/appsecurity-tests/test-apps/InstrumentationAppDiffCert/src/com/android/cts/instrumentationdiffcertapp/InstrumentationFailToRunTest.java b/tests/appsecurity-tests/test-apps/InstrumentationAppDiffCert/src/com/android/cts/instrumentationdiffcertapp/InstrumentationFailToRunTest.java
index bd5de8c..9c320d9 100644
--- a/tests/appsecurity-tests/test-apps/InstrumentationAppDiffCert/src/com/android/cts/instrumentationdiffcertapp/InstrumentationFailToRunTest.java
+++ b/tests/appsecurity-tests/test-apps/InstrumentationAppDiffCert/src/com/android/cts/instrumentationdiffcertapp/InstrumentationFailToRunTest.java
@@ -16,17 +16,29 @@
package com.android.cts.instrumentationdiffcertapp;
-import junit.framework.TestCase;
+import android.app.Instrumentation;
+import android.content.ComponentName;
+import android.content.Context;
+import android.os.Bundle;
+import android.test.InstrumentationTestCase;
/**
- * Test that is expected not to run
+ * Test that a instrumentation targeting another app with a different cert fails.
*/
-public class InstrumentationFailToRunTest extends TestCase {
+public class InstrumentationFailToRunTest extends InstrumentationTestCase {
- /**
- * Test method that is expected not to run.
- */
public void testInstrumentationNotAllowed() {
- fail("instrumentating app with different cert should fail");
+ Context myContext = getInstrumentation().getContext();
+ // assumes android.app.Instrumentation has been defined in this app's AndroidManifest.xml
+ // as targeting an app with a different cert
+ ComponentName appDiffCertInstrumentation = new ComponentName(myContext,
+ Instrumentation.class);
+ try {
+ getInstrumentation().getContext().startInstrumentation(appDiffCertInstrumentation,
+ null, new Bundle());
+ fail("could launch instrumentation");
+ } catch (SecurityException e) {
+ // expected
+ }
}
}
diff --git a/tests/tests/app/src/android/app/cts/AlertDialog_BuilderTest.java b/tests/tests/app/src/android/app/cts/AlertDialog_BuilderTest.java
index 84c64a4..c56dc28 100644
--- a/tests/tests/app/src/android/app/cts/AlertDialog_BuilderTest.java
+++ b/tests/tests/app/src/android/app/cts/AlertDialog_BuilderTest.java
@@ -40,14 +40,10 @@
import android.widget.ArrayAdapter;
import android.widget.Button;
import android.widget.FrameLayout;
-import android.widget.LinearLayout;
import android.widget.ListAdapter;
import android.widget.ListView;
-import android.widget.TextView;
import android.widget.AdapterView.OnItemSelectedListener;
-import com.android.internal.R;
-
import dalvik.annotation.TestLevel;
import dalvik.annotation.TestTargetClass;
import dalvik.annotation.TestTargetNew;
@@ -58,12 +54,8 @@
private Context mContext;
private Instrumentation mInstrumentation;
private final CharSequence mTitle = "title";
- private final CharSequence mMessage = "message";
- private TextView mTitleView;
- private TextView mMessageView;
private Drawable mDrawable;
private AlertDialog mDialog;
- private LinearLayout mLinearLayout;
private Button mButton;
private boolean mResult;
private boolean mItemSelected;
@@ -119,14 +111,11 @@
super.setUp();
mBuilder = null;
mInstrumentation = getInstrumentation();
- mContext = (Context)getActivity();
- mTitleView = null;
- mMessageView = null;
+ mContext = getActivity();
mButton = null;
mView = null;
mListView = null;
mDialog = null;
- mLinearLayout = null;
mItemSelected = false;
mSelectedItem = null;
mSelectedItems = new ArrayList<Integer>();
@@ -138,30 +127,6 @@
@TestTargetNew(
level = TestLevel.COMPLETE,
- method = "setCustomTitle",
- args = {View.class}
- )
- public void testSetCustomTitle() throws Throwable {
- final String expectecTitle = "test";
- final TextView view = new TextView(mContext);
- view.setText(expectecTitle);
- runTestOnUiThread(new Runnable() {
- public void run() {
- mBuilder = new AlertDialog.Builder(mContext);
- mBuilder.setCustomTitle(view);
- mDialog = mBuilder.show();
- }
- });
- mInstrumentation.waitForIdleSync();
- final LinearLayout topPanel = (LinearLayout)mDialog.getWindow().findViewById(
- com.android.internal.R.id.topPanel);
- final TextView atv = (TextView)topPanel.getChildAt(2);
- final String title = (String)atv.getText();
- assertEquals(expectecTitle, title);
- }
-
- @TestTargetNew(
- level = TestLevel.COMPLETE,
method = "AlertDialog.Builder",
args = {Context.class}
)
@@ -171,87 +136,15 @@
@TestTargetNew(
level = TestLevel.COMPLETE,
- method = "setTitle",
- args = {int.class}
- )
- public void testSetTitleWithParamInt() throws Throwable {
- runTestOnUiThread(new Runnable() {
- public void run() {
- mBuilder = new AlertDialog.Builder(mContext);
- mBuilder.setTitle(R.string.am);
- mDialog = mBuilder.show();
- mTitleView = (TextView)mDialog.getWindow().findViewById(R.id.alertTitle);
- }
- });
- mInstrumentation.waitForIdleSync();
- assertEquals(mTitleView.getText(), mContext.getText(R.string.am));
- }
-
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- method = "setTitle",
- args = {CharSequence.class}
- )
- public void testSetTitleWithParamCharSequence() throws Throwable {
- runTestOnUiThread(new Runnable() {
- public void run() {
- mBuilder = new AlertDialog.Builder(mContext);
- mBuilder.setTitle(mTitle);
- mDialog = mBuilder.show();
- mTitleView = (TextView)mDialog.getWindow().findViewById(R.id.alertTitle);
- }
- });
- mInstrumentation.waitForIdleSync();
- assertEquals(mTitleView.getText(), mTitle);
- }
-
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- method = "setMessage",
- args = {int.class}
- )
- public void testSetMessageWithParamInt() throws Throwable {
- runTestOnUiThread(new Runnable() {
- public void run() {
- mBuilder = new AlertDialog.Builder(mContext);
- mBuilder.setMessage(R.string.am);
- mDialog = mBuilder.show();
- mMessageView = (TextView)mDialog.getWindow().findViewById(R.id.message);
- }
- });
- mInstrumentation.waitForIdleSync();
- assertEquals(mMessageView.getText(), mContext.getText(R.string.am));
- }
-
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- method = "setMessage",
- args = {CharSequence.class}
- )
- public void testSetMessageWithParamCharSequence() throws Throwable {
- runTestOnUiThread(new Runnable() {
- public void run() {
- mBuilder = new AlertDialog.Builder(mContext);
- mBuilder.setMessage(mMessage);
- mDialog = mBuilder.show();
- mMessageView = (TextView)mDialog.getWindow().findViewById(R.id.message);
- }
- });
- mInstrumentation.waitForIdleSync();
- assertEquals(mMessageView.getText(), mMessage);
- }
-
- @TestTargetNew(
- level = TestLevel.COMPLETE,
method = "setIcon",
args = {int.class}
)
public void testSetIconWithParamInt() throws Throwable {
runTestOnUiThread(new Runnable() {
public void run() {
- mDrawable = mContext.getResources().getDrawable(R.drawable.btn_check_on);
+ mDrawable = mContext.getResources().getDrawable(android.R.drawable.btn_default);
mBuilder = new AlertDialog.Builder(mContext);
- mBuilder.setIcon(R.drawable.btn_check_on);
+ mBuilder.setIcon(android.R.drawable.btn_default);
mDialog = mBuilder.show();
}
});
@@ -266,7 +159,7 @@
public void testSetIconWithParamDrawable() throws Throwable {
runTestOnUiThread(new Runnable() {
public void run() {
- mDrawable = mContext.getResources().getDrawable(R.drawable.btn_check_on);
+ mDrawable = mContext.getResources().getDrawable(android.R.drawable.btn_default);
mBuilder = new AlertDialog.Builder(mContext);
mBuilder.setIcon(mDrawable);
mDialog = mBuilder.show();
@@ -284,15 +177,15 @@
runTestOnUiThread(new Runnable() {
public void run() {
mBuilder = new AlertDialog.Builder(mContext);
- mBuilder.setPositiveButton(R.string.year, mOnClickListener);
+ mBuilder.setPositiveButton(android.R.string.yes, mOnClickListener);
mDialog = mBuilder.show();
- mButton = (Button)mDialog.getWindow().findViewById(R.id.button1);
+ mButton = mDialog.getButton(DialogInterface.BUTTON_POSITIVE);
mButton.performClick();
}
});
mInstrumentation.waitForIdleSync();
- assertEquals(mContext.getText(R.string.year), mButton.getText());
+ assertEquals(mContext.getText(android.R.string.yes), mButton.getText());
assertTrue(mResult);
}
@@ -305,14 +198,14 @@
runTestOnUiThread(new Runnable() {
public void run() {
mBuilder = new AlertDialog.Builder(mContext);
- mBuilder.setPositiveButton(R.string.year, mOnClickListener);
+ mBuilder.setPositiveButton(android.R.string.yes, mOnClickListener);
mDialog = mBuilder.show();
- mButton = (Button)mDialog.getWindow().findViewById(R.id.button1);
+ mButton = mDialog.getButton(DialogInterface.BUTTON_POSITIVE);
mButton.performClick();
}
});
mInstrumentation.waitForIdleSync();
- assertEquals(mContext.getText(R.string.year), mButton.getText());
+ assertEquals(mContext.getText(android.R.string.yes), mButton.getText());
assertTrue(mResult);
}
@@ -327,7 +220,7 @@
mBuilder = new AlertDialog.Builder(mContext);
mBuilder.setNegativeButton(mTitle, mOnClickListener);
mDialog = mBuilder.show();
- mButton = (Button)mDialog.getWindow().findViewById(R.id.button2);
+ mButton = mDialog.getButton(DialogInterface.BUTTON_NEGATIVE);
mButton.performClick();
}
});
@@ -347,7 +240,7 @@
mBuilder = new AlertDialog.Builder(mContext);
mBuilder.setNegativeButton(com.android.cts.stub.R.string.notify, mOnClickListener);
mDialog = mBuilder.show();
- mButton = (Button)mDialog.getWindow().findViewById(R.id.button2);
+ mButton = mDialog.getButton(DialogInterface.BUTTON_NEGATIVE);
mButton.performClick();
}
});
@@ -367,7 +260,7 @@
mBuilder = new AlertDialog.Builder(mContext);
mBuilder.setNeutralButton(com.android.cts.stub.R.string.notify, mOnClickListener);
mDialog = mBuilder.show();
- mButton = (Button)mDialog.getWindow().findViewById(R.id.button3);
+ mButton = mDialog.getButton(DialogInterface.BUTTON_NEUTRAL);
mButton.performClick();
}
});
@@ -387,7 +280,7 @@
mBuilder = new AlertDialog.Builder(mContext);
mBuilder.setNeutralButton(mTitle, mOnClickListener);
mDialog = mBuilder.show();
- mButton = (Button)mDialog.getWindow().findViewById(R.id.button3);
+ mButton = mDialog.getButton(DialogInterface.BUTTON_NEUTRAL);
mButton.performClick();
}
});
@@ -476,8 +369,7 @@
mBuilder = new AlertDialog.Builder(mContext);
mBuilder.setItems(com.android.cts.stub.R.array.difficultyLevel, mOnClickListener);
mDialog = mBuilder.show();
- mLinearLayout = (LinearLayout)mDialog.getWindow().findViewById(R.id.contentPanel);
- mListView = (ListView)mLinearLayout.getChildAt(0);
+ mListView = mDialog.getListView();
}
});
mInstrumentation.waitForIdleSync();
@@ -501,8 +393,7 @@
mBuilder = new AlertDialog.Builder(mContext);
mBuilder.setItems(expect, mOnClickListener);
mDialog = mBuilder.show();
- mLinearLayout = (LinearLayout)mDialog.getWindow().findViewById(R.id.contentPanel);
- mListView = (ListView)mLinearLayout.getChildAt(0);
+ mListView = mDialog.getListView();
}
});
mInstrumentation.waitForIdleSync();
@@ -521,8 +412,7 @@
mBuilder = new AlertDialog.Builder(mContext);
mBuilder.setAdapter(adapter, mOnClickListener);
mDialog = mBuilder.show();
- mLinearLayout = (LinearLayout)mDialog.getWindow().findViewById(R.id.contentPanel);
- mListView = (ListView)mLinearLayout.getChildAt(0);
+ mListView = mDialog.getListView();
}
});
mInstrumentation.waitForIdleSync();
@@ -544,8 +434,7 @@
mBuilder = new AlertDialog.Builder(mContext);
mBuilder.setCursor(c, mOnClickListener, People.NAME);
mDialog = mBuilder.show();
- mLinearLayout = (LinearLayout)mDialog.getWindow().findViewById(R.id.contentPanel);
- mListView = (ListView)mLinearLayout.getChildAt(0);
+ mListView = mDialog.getListView();
mListView.performItemClick(null, 0, 0);
}
});
@@ -571,8 +460,7 @@
mBuilder.setMultiChoiceItems(com.android.cts.stub.R.array.difficultyLevel, null,
mOnMultiChoiceClickListener);
mDialog = mBuilder.show();
- mLinearLayout = (LinearLayout)mDialog.getWindow().findViewById(R.id.contentPanel);
- mListView = (ListView)mLinearLayout.getChildAt(0);
+ mListView = mDialog.getListView();
mSelectedItem = (CharSequence)mListView.getSelectedItem();
mListView.performItemClick(null, 0, 0);
mListView.performItemClick(null, 1, 0);
@@ -599,8 +487,7 @@
mBuilder = new AlertDialog.Builder(mContext);
mBuilder.setMultiChoiceItems(items, null, mOnMultiChoiceClickListener);
mDialog = mBuilder.show();
- mLinearLayout = (LinearLayout)mDialog.getWindow().findViewById(R.id.contentPanel);
- mListView = (ListView)mLinearLayout.getChildAt(0);
+ mListView = mDialog.getListView();
mSelectedItem = (CharSequence)mListView.getSelectedItem();
mListView.performItemClick(null, 0, 0);
mListView.performItemClick(null, 1, 0);
@@ -629,8 +516,7 @@
mBuilder.setMultiChoiceItems(c, People.NAME, People.NAME,
mOnMultiChoiceClickListener);
mDialog = mBuilder.show();
- mLinearLayout = (LinearLayout)mDialog.getWindow().findViewById(R.id.contentPanel);
- mListView = (ListView)mLinearLayout.getChildAt(0);
+ mListView = mDialog.getListView();
mListView.performItemClick(null, 0, 0);
mListView.performItemClick(null, 1, 0);
}
@@ -657,8 +543,7 @@
mBuilder.setSingleChoiceItems(com.android.cts.stub.R.array.difficultyLevel, 0,
mOnClickListener);
mDialog = mBuilder.show();
- mLinearLayout = (LinearLayout)mDialog.getWindow().findViewById(R.id.contentPanel);
- mListView = (ListView)mLinearLayout.getChildAt(0);
+ mListView = mDialog.getListView();
mSelectedItem = (CharSequence)mListView.getSelectedItem();
mListView.performItemClick(null, 0, 0);
}
@@ -696,8 +581,7 @@
mBuilder = new AlertDialog.Builder(mContext);
mBuilder.setSingleChoiceItems(c, 0, People.NAME, mOnClickListener);
mDialog = mBuilder.show();
- mLinearLayout = (LinearLayout)mDialog.getWindow().findViewById(R.id.contentPanel);
- mListView = (ListView)mLinearLayout.getChildAt(0);
+ mListView = mDialog.getListView();
mListView.performItemClick(null, 0, 0);
}
});
@@ -721,8 +605,7 @@
mBuilder = new AlertDialog.Builder(mContext);
mBuilder.setSingleChoiceItems(items, 0, mOnClickListener);
mDialog = mBuilder.show();
- mLinearLayout = (LinearLayout)mDialog.getWindow().findViewById(R.id.contentPanel);
- mListView = (ListView)mLinearLayout.getChildAt(0);
+ mListView = mDialog.getListView();
mSelectedItem = (CharSequence)mListView.getSelectedItem();
mListView.performItemClick(null, 0, 0);
}
@@ -746,11 +629,10 @@
public void run() {
mBuilder = new AlertDialog.Builder(mContext);
mBuilder.setSingleChoiceItems(new ArrayAdapter<CharSequence>(mContext,
- R.layout.select_dialog_singlechoice, R.id.text1, items), 0,
+ android.R.layout.select_dialog_singlechoice, android.R.id.text1, items), 0,
mOnClickListener);
mDialog = mBuilder.show();
- mLinearLayout = (LinearLayout)mDialog.getWindow().findViewById(R.id.contentPanel);
- mListView = (ListView)mLinearLayout.getChildAt(0);
+ mListView = mDialog.getListView();
mSelectedItem = (CharSequence)mListView.getSelectedItem();
mListView.performItemClick(null, 0, 0);
}
@@ -773,8 +655,7 @@
mBuilder.setOnItemSelectedListener(mOnItemSelectedListener);
mBuilder.setItems(com.android.cts.stub.R.array.difficultyLevel, mOnClickListener);
mDialog = mBuilder.show();
- mLinearLayout = (LinearLayout)mDialog.getWindow().findViewById(R.id.contentPanel);
- mListView = (ListView)mLinearLayout.getChildAt(0);
+ mListView = mDialog.getListView();
mListView.pointToPosition(0, 0);
}
});
@@ -789,13 +670,13 @@
)
public void testSetView() throws Throwable {
final View view = new View(mContext);
+ view.setId(100);
runTestOnUiThread(new Runnable() {
public void run() {
mBuilder = new AlertDialog.Builder(mContext);
mBuilder.setView(view);
mDialog = mBuilder.show();
- mFrameLayout = (FrameLayout)mDialog.getWindow().findViewById(R.id.custom);
- mView = mFrameLayout.getChildAt(0);
+ mView = mDialog.getWindow().findViewById(100);
}
});
mInstrumentation.waitForIdleSync();
@@ -813,22 +694,18 @@
final int viewSpacingRight = 30;
final int viewSpacingBottom = 40;
final View view = new View(mContext);
+ view.setId(100);
runTestOnUiThread(new Runnable() {
public void run() {
mBuilder = new AlertDialog.Builder(mContext);
mBuilder.setView(view, viewSpacingLeft, viewSpacingTop, viewSpacingRight,
viewSpacingBottom);
mDialog = mBuilder.show();
- mFrameLayout = (FrameLayout)mDialog.getWindow().findViewById(R.id.custom);
- mView = mFrameLayout.getChildAt(0);
+ mView = mDialog.getWindow().findViewById(100);
}
});
mInstrumentation.waitForIdleSync();
assertEquals(view, mView);
- assertEquals(viewSpacingTop, mFrameLayout.getPaddingTop());
- assertEquals(viewSpacingLeft, mFrameLayout.getPaddingLeft());
- assertEquals(viewSpacingRight, mFrameLayout.getPaddingRight());
- assertEquals(viewSpacingBottom, mFrameLayout.getPaddingBottom());
}
@TestTargetNew(
diff --git a/tools/utils/buildCts.py b/tools/utils/buildCts.py
index 1f1967f..3465410 100755
--- a/tools/utils/buildCts.py
+++ b/tools/utils/buildCts.py
@@ -121,6 +121,7 @@
"""Generate the test description for the signature check."""
self.__LogGenerateDescription('android.tests.sigtest')
package = tools.TestPackage('SignatureTest', 'android.tests.sigtest')
+ package.AddAttribute('appNameSpace', 'android.tests.sigtest')
package.AddAttribute('signatureCheck', 'true')
package.AddAttribute('runner', '.InstrumentationRunner')
package.AddTest('android.tests.sigtest.SignatureTest.signatureTest')
@@ -132,6 +133,7 @@
"""Generate the test description for the reference app tests."""
self.__LogGenerateDescription('android.apidemos.cts')
package = tools.TestPackage('ApiDemosReferenceTest', 'android.apidemos.cts')
+ package.AddAttribute('appNameSpace', 'android.apidemos.cts')
package.AddAttribute('packageToTest', 'com.example.android.apis')
package.AddAttribute('apkToTestName', 'ApiDemos')
package.AddAttribute('runner', 'android.test.InstrumentationTestRunner')