From f32b488bd205ae2b026f47ee898073fd4815da90 Mon Sep 17 00:00:00 2001 From: Romain Guy Date: Fri, 4 Dec 2009 11:50:22 -0800 Subject: [PATCH] Add new unit test for RadioGroup/RadioButton. Also fix the AutoCompleteTextViewCallbacks test. --- tests/FrameworkTest/AndroidManifest.xml | 8 +++ .../res/layout/radiogroup_checkedchild.xml | 44 +++++++++++++ .../radiogroup/RadioGroupActivity.java | 31 +++++++++ .../widget/AutoCompleteTextViewCallbacks.java | 37 ++++++++--- .../radiogroup/RadioGroupPreCheckedTest.java | 63 +++++++++++++++++++ 5 files changed, 175 insertions(+), 8 deletions(-) create mode 100644 tests/FrameworkTest/res/layout/radiogroup_checkedchild.xml create mode 100644 tests/FrameworkTest/src/com/android/frameworktest/radiogroup/RadioGroupActivity.java create mode 100644 tests/FrameworkTest/tests/src/com/android/frameworktest/radiogroup/RadioGroupPreCheckedTest.java diff --git a/tests/FrameworkTest/AndroidManifest.xml b/tests/FrameworkTest/AndroidManifest.xml index 4e4ebffc7d373..a906149e5871f 100644 --- a/tests/FrameworkTest/AndroidManifest.xml +++ b/tests/FrameworkTest/AndroidManifest.xml @@ -955,6 +955,14 @@ + + + + + + + + diff --git a/tests/FrameworkTest/res/layout/radiogroup_checkedchild.xml b/tests/FrameworkTest/res/layout/radiogroup_checkedchild.xml new file mode 100644 index 0000000000000..7724729ff5101 --- /dev/null +++ b/tests/FrameworkTest/res/layout/radiogroup_checkedchild.xml @@ -0,0 +1,44 @@ + + + + + + + + + + + + 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 0000000000000..ac9e870507f42 --- /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 29000dd6dd042..1b81c98175f5f 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 0000000000000..8771830c9106b --- /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 { + 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()); + } +}