summaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorRomain Guy <romainguy@android.com>2009-12-04 11:50:22 -0800
committerRomain Guy <romainguy@android.com>2009-12-04 11:50:22 -0800
commitf32b488bd205ae2b026f47ee898073fd4815da90 (patch)
treedbc39eb9fddef70854c0065eb4d88abbc8d44c36 /tests
parent8280c2b15f6875b2d387c05df23d264864eb9cd5 (diff)
downloadframeworks_base-f32b488bd205ae2b026f47ee898073fd4815da90.zip
frameworks_base-f32b488bd205ae2b026f47ee898073fd4815da90.tar.gz
frameworks_base-f32b488bd205ae2b026f47ee898073fd4815da90.tar.bz2
Add new unit test for RadioGroup/RadioButton.
Also fix the AutoCompleteTextViewCallbacks test.
Diffstat (limited to 'tests')
-rw-r--r--tests/FrameworkTest/AndroidManifest.xml8
-rw-r--r--tests/FrameworkTest/res/layout/radiogroup_checkedchild.xml44
-rw-r--r--tests/FrameworkTest/src/com/android/frameworktest/radiogroup/RadioGroupActivity.java31
-rw-r--r--tests/FrameworkTest/tests/src/android/widget/AutoCompleteTextViewCallbacks.java37
-rw-r--r--tests/FrameworkTest/tests/src/com/android/frameworktest/radiogroup/RadioGroupPreCheckedTest.java63
5 files changed, 175 insertions, 8 deletions
diff --git a/tests/FrameworkTest/AndroidManifest.xml b/tests/FrameworkTest/AndroidManifest.xml
index 4e4ebff..a906149 100644
--- a/tests/FrameworkTest/AndroidManifest.xml
+++ b/tests/FrameworkTest/AndroidManifest.xml
@@ -955,6 +955,14 @@
<action android:name="android.accessibilityservice.AccessibilityService" />
</intent-filter>
</service>
+
+ <activity android:name=".radiogroup.RadioGroupActivity" android:label="RadioGroupActivity">
+ <intent-filter>
+ <action android:name="android.intent.action.MAIN" />
+ <category android:name="android.intent.category.FRAMEWORK_INSTRUMENTATION_TEST" />
+ </intent-filter>
+ </activity>
+
</application>
diff --git a/tests/FrameworkTest/res/layout/radiogroup_checkedchild.xml b/tests/FrameworkTest/res/layout/radiogroup_checkedchild.xml
new file mode 100644
index 0000000..7724729
--- /dev/null
+++ b/tests/FrameworkTest/res/layout/radiogroup_checkedchild.xml
@@ -0,0 +1,44 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!-- 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.
+-->
+
+<RadioGroup xmlns:android="http://schemas.android.com/apk/res/android"
+ android:id="@+id/group"
+ android:layout_width="wrap_content"
+ android:layout_height="wrap_content">
+
+ <RadioButton
+ android:id="@+id/value_one"
+ android:layout_width="fill_parent"
+ android:layout_height="fill_parent"
+ android:textColor="#555555"
+ android:checked="true"
+ android:text="@string/visibility_1_view_1" />
+
+ <RadioButton
+ android:id="@+id/value_two"
+ android:layout_width="fill_parent"
+ android:layout_height="fill_parent"
+ android:textColor="#555555"
+ android:text="@string/visibility_1_view_2" />
+
+ <RadioButton
+ android:id="@+id/value_three"
+ android:layout_width="fill_parent"
+ android:layout_height="fill_parent"
+ android:textColor="#555555"
+ android:text="@string/visibility_1_view_3" />
+
+</RadioGroup>
diff --git a/tests/FrameworkTest/src/com/android/frameworktest/radiogroup/RadioGroupActivity.java b/tests/FrameworkTest/src/com/android/frameworktest/radiogroup/RadioGroupActivity.java
new file mode 100644
index 0000000..ac9e870
--- /dev/null
+++ b/tests/FrameworkTest/src/com/android/frameworktest/radiogroup/RadioGroupActivity.java
@@ -0,0 +1,31 @@
+/*
+ * 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 com.android.frameworktest.radiogroup;
+
+import com.android.frameworktest.R;
+
+import android.app.Activity;
+import android.os.Bundle;
+
+public class RadioGroupActivity extends Activity {
+ @Override
+ protected void onCreate(Bundle savedInstanceState) {
+ super.onCreate(savedInstanceState);
+ setContentView(R.layout.radiogroup_checkedchild);
+ }
+}
diff --git a/tests/FrameworkTest/tests/src/android/widget/AutoCompleteTextViewCallbacks.java b/tests/FrameworkTest/tests/src/android/widget/AutoCompleteTextViewCallbacks.java
index 29000dd..1b81c98 100644
--- a/tests/FrameworkTest/tests/src/android/widget/AutoCompleteTextViewCallbacks.java
+++ b/tests/FrameworkTest/tests/src/android/widget/AutoCompleteTextViewCallbacks.java
@@ -42,6 +42,7 @@ public class AutoCompleteTextViewCallbacks
textView.requestFocus();
instrumentation.waitForIdleSync();
sendKeys("A");
+ instrumentation.waitForIdleSync();
// give UI time to settle
Thread.sleep(WAIT_TIME);
@@ -58,7 +59,7 @@ public class AutoCompleteTextViewCallbacks
/** Test that arrow-down into the popup calls the onSelected callback. */
@FlakyTest(tolerance=3)
public void testPopupEnterSelection() throws Exception {
- AutoCompleteTextViewSimple theActivity = getActivity();
+ final AutoCompleteTextViewSimple theActivity = getActivity();
AutoCompleteTextView textView = theActivity.getTextView();
final Instrumentation instrumentation = getInstrumentation();
@@ -67,9 +68,15 @@ public class AutoCompleteTextViewCallbacks
instrumentation.waitForIdleSync();
sendKeys("A");
- // prepare to move down into the popup
- theActivity.resetItemListeners();
+ textView.post(new Runnable() {
+ public void run() {
+ // prepare to move down into the popup
+ theActivity.resetItemListeners();
+ }
+ });
+
sendKeys("DPAD_DOWN");
+ instrumentation.waitForIdleSync();
// give UI time to settle
Thread.sleep(WAIT_TIME);
@@ -79,9 +86,15 @@ public class AutoCompleteTextViewCallbacks
assertEquals("onItemSelected position", 0, theActivity.mItemSelectedPosition);
assertFalse("onNothingSelected should not be called", theActivity.mNothingSelectedCalled);
- // try one more time - should move from 0 to 1
- theActivity.resetItemListeners();
+ textView.post(new Runnable() {
+ public void run() {
+ // try one more time - should move from 0 to 1
+ theActivity.resetItemListeners();
+ }
+ });
+
sendKeys("DPAD_DOWN");
+ instrumentation.waitForIdleSync();
// give UI time to settle
Thread.sleep(WAIT_TIME);
@@ -95,7 +108,7 @@ public class AutoCompleteTextViewCallbacks
/** Test that arrow-up out of the popup calls the onNothingSelected callback */
@FlakyTest(tolerance=3)
public void testPopupLeaveSelection() {
- AutoCompleteTextViewSimple theActivity = getActivity();
+ final AutoCompleteTextViewSimple theActivity = getActivity();
AutoCompleteTextView textView = theActivity.getTextView();
final Instrumentation instrumentation = getInstrumentation();
@@ -103,13 +116,21 @@ public class AutoCompleteTextViewCallbacks
textView.requestFocus();
instrumentation.waitForIdleSync();
sendKeys("A");
+ instrumentation.waitForIdleSync();
// move down into the popup
sendKeys("DPAD_DOWN");
+ instrumentation.waitForIdleSync();
+
+ textView.post(new Runnable() {
+ public void run() {
+ // prepare to move down into the popup
+ theActivity.resetItemListeners();
+ }
+ });
- // now move back up out of the popup
- theActivity.resetItemListeners();
sendKeys("DPAD_UP");
+ instrumentation.waitForIdleSync();
// now check for selection callbacks.
assertFalse("onItemClick should not be called", theActivity.mItemClickCalled);
diff --git a/tests/FrameworkTest/tests/src/com/android/frameworktest/radiogroup/RadioGroupPreCheckedTest.java b/tests/FrameworkTest/tests/src/com/android/frameworktest/radiogroup/RadioGroupPreCheckedTest.java
new file mode 100644
index 0000000..8771830
--- /dev/null
+++ b/tests/FrameworkTest/tests/src/com/android/frameworktest/radiogroup/RadioGroupPreCheckedTest.java
@@ -0,0 +1,63 @@
+/*
+ * Copyright (C) 2007 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 com.android.frameworktest.radiogroup;
+
+import android.test.TouchUtils;
+import android.widget.RadioButton;
+import android.widget.RadioGroup;
+import com.android.frameworktest.R;
+
+import android.test.ActivityInstrumentationTestCase2;
+import android.test.suitebuilder.annotation.LargeTest;
+
+/**
+ * Exercises {@link android.widget.RadioGroup}'s check feature.
+ */
+public class RadioGroupPreCheckedTest extends ActivityInstrumentationTestCase2<RadioGroupActivity> {
+ public RadioGroupPreCheckedTest() {
+ super("com.android.frameworktest", RadioGroupActivity.class);
+ }
+
+ @LargeTest
+ public void testRadioButtonPreChecked() throws Exception {
+ final RadioGroupActivity activity = getActivity();
+
+ RadioButton radio = (RadioButton) activity.findViewById(R.id.value_one);
+ assertTrue("The first radio button should be checked", radio.isChecked());
+
+ RadioGroup group = (RadioGroup) activity.findViewById(R.id.group);
+ assertEquals("The first radio button should be checked", R.id.value_one,
+ group.getCheckedRadioButtonId());
+ }
+
+ @LargeTest
+ public void testRadioButtonChangePreChecked() throws Exception {
+ final RadioGroupActivity activity = getActivity();
+
+ RadioButton radio = (RadioButton) activity.findViewById(R.id.value_two);
+ TouchUtils.clickView(this, radio);
+
+ RadioButton old = (RadioButton) activity.findViewById(R.id.value_one);
+
+ assertFalse("The first radio button should not be checked", old.isChecked());
+ assertTrue("The second radio button should be checked", radio.isChecked());
+
+ RadioGroup group = (RadioGroup) activity.findViewById(R.id.group);
+ assertEquals("The second radio button should be checked", R.id.value_two,
+ group.getCheckedRadioButtonId());
+ }
+}