Add new unit test for RadioGroup/RadioButton.

Also fix the AutoCompleteTextViewCallbacks test.
This commit is contained in:
Romain Guy
2009-12-04 11:50:22 -08:00
parent 8280c2b15f
commit f32b488bd2
5 changed files with 175 additions and 8 deletions

View File

@@ -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>

View File

@@ -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>

View File

@@ -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);
}
}

View File

@@ -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);

View File

@@ -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());
}
}