Loading tests/AndroidTests/src/com/android/unit_tests/MonitorTest.java +1 −1 Original line number Diff line number Diff line Loading @@ -267,7 +267,7 @@ public class MonitorTest extends TestCase { private static Throwable errorException; private static Thread testThread; @MediumTest // TODO: Flaky test. Add back MediumTest annotation once fixed public void testInterruptTest() throws Exception { Loading tests/FrameworkTest/tests/src/android/widget/AutoCompleteTextViewCallbacks.java +29 −18 Original line number Diff line number Diff line Loading @@ -18,20 +18,23 @@ package android.widget; import android.app.Instrumentation; import android.test.ActivityInstrumentationTestCase2; import android.test.FlakyTest; import android.test.suitebuilder.annotation.MediumTest; public class AutoCompleteTextViewCallbacks extends ActivityInstrumentationTestCase2<AutoCompleteTextViewSimple> { private static final int WAIT_TIME = 200; public AutoCompleteTextViewCallbacks() { super("com.android.frameworktest", AutoCompleteTextViewSimple.class); } /** Test that the initial popup of the suggestions does not select anything. * * TODO: test currently fails. Add back MediumTest annotation when fixed. */ public void testPopupNoSelection() { @MediumTest @FlakyTest(tolerance=3) public void testPopupNoSelection() throws Exception { AutoCompleteTextViewSimple theActivity = getActivity(); AutoCompleteTextView textView = theActivity.getTextView(); final Instrumentation instrumentation = getInstrumentation(); Loading @@ -40,6 +43,8 @@ public class AutoCompleteTextViewCallbacks textView.requestFocus(); instrumentation.waitForIdleSync(); sendKeys("A"); // give UI time to settle Thread.sleep(WAIT_TIME); // now check for selection callbacks. Nothing should be clicked or selected. assertFalse("onItemClick should not be called", theActivity.mItemClickCalled); Loading @@ -48,12 +53,13 @@ public class AutoCompleteTextViewCallbacks // arguably, this should be "false", because we aren't deselecting - we shouldn't // really be calling it. But it's not the end of the world, and we might wind up // breaking something if we change this. assertTrue("onNothingSelected should be called", theActivity.mNothingSelectedCalled); //assertTrue("onNothingSelected should be called", theActivity.mNothingSelectedCalled); } /** Test that arrow-down into the popup calls the onSelected callback */ /** Test that arrow-down into the popup calls the onSelected callback. */ @MediumTest public void testPopupEnterSelection() { @FlakyTest(tolerance=3) public void testPopupEnterSelection() throws Exception { AutoCompleteTextViewSimple theActivity = getActivity(); AutoCompleteTextView textView = theActivity.getTextView(); final Instrumentation instrumentation = getInstrumentation(); Loading @@ -66,6 +72,8 @@ public class AutoCompleteTextViewCallbacks // prepare to move down into the popup theActivity.resetItemListeners(); sendKeys("DPAD_DOWN"); // give UI time to settle Thread.sleep(WAIT_TIME); // now check for selection callbacks. assertFalse("onItemClick should not be called", theActivity.mItemClickCalled); Loading @@ -76,6 +84,8 @@ public class AutoCompleteTextViewCallbacks // try one more time - should move from 0 to 1 theActivity.resetItemListeners(); sendKeys("DPAD_DOWN"); // give UI time to settle Thread.sleep(WAIT_TIME); // now check for selection callbacks. assertFalse("onItemClick should not be called", theActivity.mItemClickCalled); Loading @@ -86,6 +96,7 @@ public class AutoCompleteTextViewCallbacks /** Test that arrow-up out of the popup calls the onNothingSelected callback */ @MediumTest @FlakyTest(tolerance=3) public void testPopupLeaveSelection() { AutoCompleteTextViewSimple theActivity = getActivity(); AutoCompleteTextView textView = theActivity.getTextView(); Loading tests/FrameworkTest/tests/src/android/widget/AutoCompleteTextViewPopup.java +109 −49 Original line number Diff line number Diff line Loading @@ -20,6 +20,7 @@ import android.app.Instrumentation; import android.test.ActivityInstrumentationTestCase2; import android.test.FlakyTest; import android.test.suitebuilder.annotation.MediumTest; import android.util.Log; /** * A collection of tests on aspects of the AutoCompleteTextView's popup Loading @@ -27,12 +28,20 @@ import android.test.suitebuilder.annotation.MediumTest; public class AutoCompleteTextViewPopup extends ActivityInstrumentationTestCase2<AutoCompleteTextViewSimple> { // ms to sleep when checking for intermittent UI state private static final int SLEEP_TIME = 50; // number of times to poll when checking expected UI state // total wait time will be LOOP_AMOUNT * SLEEP_TIME private static final int LOOP_AMOUNT = 10; public AutoCompleteTextViewPopup() { super("com.android.frameworktest", AutoCompleteTextViewSimple.class); } /** Test that we can move the selection and it responds as expected */ @MediumTest @FlakyTest(tolerance=3) public void testPopupSetListSelection() throws Throwable { AutoCompleteTextViewSimple theActivity = getActivity(); final AutoCompleteTextView textView = theActivity.getTextView(); Loading @@ -44,8 +53,7 @@ public class AutoCompleteTextViewPopup sendKeys("A"); // No initial selection assertEquals("getListSelection(-1)", ListView.INVALID_POSITION, textView.getListSelection()); waitAssertListSelection(textView, ListView.INVALID_POSITION); // set and check runTestOnUiThread(new Runnable() { Loading @@ -54,18 +62,22 @@ public class AutoCompleteTextViewPopup } }); instrumentation.waitForIdleSync(); assertEquals("set selection to (0)", 0, textView.getListSelection()); waitAssertListSelection("set selection to (0)", textView, 0); // Use movement to cross-check the movement sendKeys("DPAD_DOWN"); assertEquals("move selection to (1)", 1, textView.getListSelection()); waitAssertListSelection("move selection to (1)", textView, 1); // TODO: FlakyTest repeat runs will not currently call setUp, clear state clearText(textView); } /** Test that we can look at the selection as we move around */ @MediumTest public void testPopupGetListSelection() { @FlakyTest(tolerance=3) public void testPopupGetListSelection() throws Throwable { AutoCompleteTextViewSimple theActivity = getActivity(); AutoCompleteTextView textView = theActivity.getTextView(); final AutoCompleteTextView textView = theActivity.getTextView(); final Instrumentation instrumentation = getInstrumentation(); // focus and type Loading @@ -74,20 +86,23 @@ public class AutoCompleteTextViewPopup sendKeys("A"); // No initial selection assertEquals("getListSelection(-1)", ListView.INVALID_POSITION, textView.getListSelection()); waitAssertListSelection(textView, ListView.INVALID_POSITION); // check for selection position as expected sendKeys("DPAD_DOWN"); assertEquals("move selection to (0)", 0, textView.getListSelection()); waitAssertListSelection("move selection to (0)", textView, 0); // Repeat for one more movement sendKeys("DPAD_DOWN"); assertEquals("move selection to (1)", 1, textView.getListSelection()); waitAssertListSelection("move selection to (1)", textView, 1); // TODO: FlakyTest repeat runs will not currently call setUp, clear state clearText(textView); } /** Test that we can clear the selection */ @MediumTest @FlakyTest(tolerance=3) public void testPopupClearListSelection() throws Throwable { AutoCompleteTextViewSimple theActivity = getActivity(); final AutoCompleteTextView textView = theActivity.getTextView(); Loading @@ -99,12 +114,11 @@ public class AutoCompleteTextViewPopup sendKeys("A"); // No initial selection assertEquals("getListSelection(-1)", ListView.INVALID_POSITION, textView.getListSelection()); waitAssertListSelection(textView, ListView.INVALID_POSITION); // check for selection position as expected sendKeys("DPAD_DOWN"); assertEquals("getListSelection(0)", 0, textView.getListSelection()); waitAssertListSelection(textView, 0); // clear it runTestOnUiThread(new Runnable() { Loading @@ -113,12 +127,16 @@ public class AutoCompleteTextViewPopup } }); instrumentation.waitForIdleSync(); assertEquals("setListSelection(ListView.INVALID_POSITION)", ListView.INVALID_POSITION, textView.getListSelection()); waitAssertListSelection("setListSelection(ListView.INVALID_POSITION)", textView, ListView.INVALID_POSITION); // TODO: FlakyTest repeat runs will not currently call setUp, clear state clearText(textView); } /** Make sure we handle an empty adapter properly */ @MediumTest @FlakyTest(tolerance=3) public void testPopupNavigateNoAdapter() throws Throwable { AutoCompleteTextViewSimple theActivity = getActivity(); final AutoCompleteTextView textView = theActivity.getTextView(); Loading @@ -130,12 +148,11 @@ public class AutoCompleteTextViewPopup sendKeys("A"); // No initial selection assertEquals("getListSelection(-1)", ListView.INVALID_POSITION, textView.getListSelection()); waitAssertListSelection(textView, ListView.INVALID_POSITION); // check for selection position as expected sendKeys("DPAD_DOWN"); assertEquals("getListSelection(0)", 0, textView.getListSelection()); waitAssertListSelection(textView, 0); // Now get rid of the adapter runTestOnUiThread(new Runnable() { Loading @@ -147,11 +164,14 @@ public class AutoCompleteTextViewPopup // now try moving "down" - nothing should happen since there's no longer an adapter sendKeys("DPAD_DOWN"); // TODO: FlakyTest repeat runs will not currently call setUp, clear state clearText(textView); } /** Test the show/hide behavior of the drop-down. */ @FlakyTest(tolerance=5) @MediumTest @FlakyTest(tolerance=3) public void testPopupShow() throws Throwable { AutoCompleteTextViewSimple theActivity = getActivity(); final AutoCompleteTextView textView = theActivity.getTextView(); Loading @@ -166,7 +186,7 @@ public class AutoCompleteTextViewPopup sendKeys("A"); // Drop-down should now be visible assertTrue("isPopupShowing() after typing", textView.isPopupShowing()); waitAssertPopupShowState("isPopupShowing() after typing", textView, true); // Clear the text runTestOnUiThread(new Runnable() { Loading @@ -177,7 +197,7 @@ public class AutoCompleteTextViewPopup instrumentation.waitForIdleSync(); // Drop-down should be hidden when text is cleared assertFalse("isPopupShowing() after text cleared", textView.isPopupShowing()); waitAssertPopupShowState("isPopupShowing() after text cleared", textView, false); // Set the text, without filtering runTestOnUiThread(new Runnable() { Loading @@ -188,7 +208,7 @@ public class AutoCompleteTextViewPopup instrumentation.waitForIdleSync(); // Drop-down should still be hidden assertFalse("isPopupShowing() after setText(\"a\", false)", textView.isPopupShowing()); waitAssertPopupShowState("isPopupShowing() after setText(\"a\", false)", textView, false); // Set the text, now with filtering runTestOnUiThread(new Runnable() { Loading @@ -199,6 +219,46 @@ public class AutoCompleteTextViewPopup instrumentation.waitForIdleSync(); // Drop-down should show up after setText() with filtering assertTrue("isPopupShowing() after text set", textView.isPopupShowing()); waitAssertPopupShowState("isPopupShowing() after text set", textView, true); // TODO: FlakyTest repeat runs will not currently call setUp, clear state clearText(textView); } private void waitAssertPopupShowState(String message, AutoCompleteTextView textView, boolean expected) throws InterruptedException { for (int i = 0; i < LOOP_AMOUNT; i++) { if (textView.isPopupShowing() == expected) { return; } Thread.sleep(SLEEP_TIME); } assertEquals(message, expected, textView.isPopupShowing()); } private void waitAssertListSelection(AutoCompleteTextView textView, int expected) throws Exception { waitAssertListSelection("getListSelection()", textView, expected); } private void waitAssertListSelection(String message, AutoCompleteTextView textView, int expected) throws Exception { int currentSelection = ListView.INVALID_POSITION; for (int i = 0; i < LOOP_AMOUNT; i++) { currentSelection = textView.getListSelection(); if (expected == currentSelection) { return; } Thread.sleep(SLEEP_TIME); } assertEquals(message, expected, textView.getListSelection()); } private void clearText(final AutoCompleteTextView textView) throws Throwable { runTestOnUiThread(new Runnable() { public void run() { textView.setText(""); } }); } } Loading
tests/AndroidTests/src/com/android/unit_tests/MonitorTest.java +1 −1 Original line number Diff line number Diff line Loading @@ -267,7 +267,7 @@ public class MonitorTest extends TestCase { private static Throwable errorException; private static Thread testThread; @MediumTest // TODO: Flaky test. Add back MediumTest annotation once fixed public void testInterruptTest() throws Exception { Loading
tests/FrameworkTest/tests/src/android/widget/AutoCompleteTextViewCallbacks.java +29 −18 Original line number Diff line number Diff line Loading @@ -18,20 +18,23 @@ package android.widget; import android.app.Instrumentation; import android.test.ActivityInstrumentationTestCase2; import android.test.FlakyTest; import android.test.suitebuilder.annotation.MediumTest; public class AutoCompleteTextViewCallbacks extends ActivityInstrumentationTestCase2<AutoCompleteTextViewSimple> { private static final int WAIT_TIME = 200; public AutoCompleteTextViewCallbacks() { super("com.android.frameworktest", AutoCompleteTextViewSimple.class); } /** Test that the initial popup of the suggestions does not select anything. * * TODO: test currently fails. Add back MediumTest annotation when fixed. */ public void testPopupNoSelection() { @MediumTest @FlakyTest(tolerance=3) public void testPopupNoSelection() throws Exception { AutoCompleteTextViewSimple theActivity = getActivity(); AutoCompleteTextView textView = theActivity.getTextView(); final Instrumentation instrumentation = getInstrumentation(); Loading @@ -40,6 +43,8 @@ public class AutoCompleteTextViewCallbacks textView.requestFocus(); instrumentation.waitForIdleSync(); sendKeys("A"); // give UI time to settle Thread.sleep(WAIT_TIME); // now check for selection callbacks. Nothing should be clicked or selected. assertFalse("onItemClick should not be called", theActivity.mItemClickCalled); Loading @@ -48,12 +53,13 @@ public class AutoCompleteTextViewCallbacks // arguably, this should be "false", because we aren't deselecting - we shouldn't // really be calling it. But it's not the end of the world, and we might wind up // breaking something if we change this. assertTrue("onNothingSelected should be called", theActivity.mNothingSelectedCalled); //assertTrue("onNothingSelected should be called", theActivity.mNothingSelectedCalled); } /** Test that arrow-down into the popup calls the onSelected callback */ /** Test that arrow-down into the popup calls the onSelected callback. */ @MediumTest public void testPopupEnterSelection() { @FlakyTest(tolerance=3) public void testPopupEnterSelection() throws Exception { AutoCompleteTextViewSimple theActivity = getActivity(); AutoCompleteTextView textView = theActivity.getTextView(); final Instrumentation instrumentation = getInstrumentation(); Loading @@ -66,6 +72,8 @@ public class AutoCompleteTextViewCallbacks // prepare to move down into the popup theActivity.resetItemListeners(); sendKeys("DPAD_DOWN"); // give UI time to settle Thread.sleep(WAIT_TIME); // now check for selection callbacks. assertFalse("onItemClick should not be called", theActivity.mItemClickCalled); Loading @@ -76,6 +84,8 @@ public class AutoCompleteTextViewCallbacks // try one more time - should move from 0 to 1 theActivity.resetItemListeners(); sendKeys("DPAD_DOWN"); // give UI time to settle Thread.sleep(WAIT_TIME); // now check for selection callbacks. assertFalse("onItemClick should not be called", theActivity.mItemClickCalled); Loading @@ -86,6 +96,7 @@ public class AutoCompleteTextViewCallbacks /** Test that arrow-up out of the popup calls the onNothingSelected callback */ @MediumTest @FlakyTest(tolerance=3) public void testPopupLeaveSelection() { AutoCompleteTextViewSimple theActivity = getActivity(); AutoCompleteTextView textView = theActivity.getTextView(); Loading
tests/FrameworkTest/tests/src/android/widget/AutoCompleteTextViewPopup.java +109 −49 Original line number Diff line number Diff line Loading @@ -20,6 +20,7 @@ import android.app.Instrumentation; import android.test.ActivityInstrumentationTestCase2; import android.test.FlakyTest; import android.test.suitebuilder.annotation.MediumTest; import android.util.Log; /** * A collection of tests on aspects of the AutoCompleteTextView's popup Loading @@ -27,12 +28,20 @@ import android.test.suitebuilder.annotation.MediumTest; public class AutoCompleteTextViewPopup extends ActivityInstrumentationTestCase2<AutoCompleteTextViewSimple> { // ms to sleep when checking for intermittent UI state private static final int SLEEP_TIME = 50; // number of times to poll when checking expected UI state // total wait time will be LOOP_AMOUNT * SLEEP_TIME private static final int LOOP_AMOUNT = 10; public AutoCompleteTextViewPopup() { super("com.android.frameworktest", AutoCompleteTextViewSimple.class); } /** Test that we can move the selection and it responds as expected */ @MediumTest @FlakyTest(tolerance=3) public void testPopupSetListSelection() throws Throwable { AutoCompleteTextViewSimple theActivity = getActivity(); final AutoCompleteTextView textView = theActivity.getTextView(); Loading @@ -44,8 +53,7 @@ public class AutoCompleteTextViewPopup sendKeys("A"); // No initial selection assertEquals("getListSelection(-1)", ListView.INVALID_POSITION, textView.getListSelection()); waitAssertListSelection(textView, ListView.INVALID_POSITION); // set and check runTestOnUiThread(new Runnable() { Loading @@ -54,18 +62,22 @@ public class AutoCompleteTextViewPopup } }); instrumentation.waitForIdleSync(); assertEquals("set selection to (0)", 0, textView.getListSelection()); waitAssertListSelection("set selection to (0)", textView, 0); // Use movement to cross-check the movement sendKeys("DPAD_DOWN"); assertEquals("move selection to (1)", 1, textView.getListSelection()); waitAssertListSelection("move selection to (1)", textView, 1); // TODO: FlakyTest repeat runs will not currently call setUp, clear state clearText(textView); } /** Test that we can look at the selection as we move around */ @MediumTest public void testPopupGetListSelection() { @FlakyTest(tolerance=3) public void testPopupGetListSelection() throws Throwable { AutoCompleteTextViewSimple theActivity = getActivity(); AutoCompleteTextView textView = theActivity.getTextView(); final AutoCompleteTextView textView = theActivity.getTextView(); final Instrumentation instrumentation = getInstrumentation(); // focus and type Loading @@ -74,20 +86,23 @@ public class AutoCompleteTextViewPopup sendKeys("A"); // No initial selection assertEquals("getListSelection(-1)", ListView.INVALID_POSITION, textView.getListSelection()); waitAssertListSelection(textView, ListView.INVALID_POSITION); // check for selection position as expected sendKeys("DPAD_DOWN"); assertEquals("move selection to (0)", 0, textView.getListSelection()); waitAssertListSelection("move selection to (0)", textView, 0); // Repeat for one more movement sendKeys("DPAD_DOWN"); assertEquals("move selection to (1)", 1, textView.getListSelection()); waitAssertListSelection("move selection to (1)", textView, 1); // TODO: FlakyTest repeat runs will not currently call setUp, clear state clearText(textView); } /** Test that we can clear the selection */ @MediumTest @FlakyTest(tolerance=3) public void testPopupClearListSelection() throws Throwable { AutoCompleteTextViewSimple theActivity = getActivity(); final AutoCompleteTextView textView = theActivity.getTextView(); Loading @@ -99,12 +114,11 @@ public class AutoCompleteTextViewPopup sendKeys("A"); // No initial selection assertEquals("getListSelection(-1)", ListView.INVALID_POSITION, textView.getListSelection()); waitAssertListSelection(textView, ListView.INVALID_POSITION); // check for selection position as expected sendKeys("DPAD_DOWN"); assertEquals("getListSelection(0)", 0, textView.getListSelection()); waitAssertListSelection(textView, 0); // clear it runTestOnUiThread(new Runnable() { Loading @@ -113,12 +127,16 @@ public class AutoCompleteTextViewPopup } }); instrumentation.waitForIdleSync(); assertEquals("setListSelection(ListView.INVALID_POSITION)", ListView.INVALID_POSITION, textView.getListSelection()); waitAssertListSelection("setListSelection(ListView.INVALID_POSITION)", textView, ListView.INVALID_POSITION); // TODO: FlakyTest repeat runs will not currently call setUp, clear state clearText(textView); } /** Make sure we handle an empty adapter properly */ @MediumTest @FlakyTest(tolerance=3) public void testPopupNavigateNoAdapter() throws Throwable { AutoCompleteTextViewSimple theActivity = getActivity(); final AutoCompleteTextView textView = theActivity.getTextView(); Loading @@ -130,12 +148,11 @@ public class AutoCompleteTextViewPopup sendKeys("A"); // No initial selection assertEquals("getListSelection(-1)", ListView.INVALID_POSITION, textView.getListSelection()); waitAssertListSelection(textView, ListView.INVALID_POSITION); // check for selection position as expected sendKeys("DPAD_DOWN"); assertEquals("getListSelection(0)", 0, textView.getListSelection()); waitAssertListSelection(textView, 0); // Now get rid of the adapter runTestOnUiThread(new Runnable() { Loading @@ -147,11 +164,14 @@ public class AutoCompleteTextViewPopup // now try moving "down" - nothing should happen since there's no longer an adapter sendKeys("DPAD_DOWN"); // TODO: FlakyTest repeat runs will not currently call setUp, clear state clearText(textView); } /** Test the show/hide behavior of the drop-down. */ @FlakyTest(tolerance=5) @MediumTest @FlakyTest(tolerance=3) public void testPopupShow() throws Throwable { AutoCompleteTextViewSimple theActivity = getActivity(); final AutoCompleteTextView textView = theActivity.getTextView(); Loading @@ -166,7 +186,7 @@ public class AutoCompleteTextViewPopup sendKeys("A"); // Drop-down should now be visible assertTrue("isPopupShowing() after typing", textView.isPopupShowing()); waitAssertPopupShowState("isPopupShowing() after typing", textView, true); // Clear the text runTestOnUiThread(new Runnable() { Loading @@ -177,7 +197,7 @@ public class AutoCompleteTextViewPopup instrumentation.waitForIdleSync(); // Drop-down should be hidden when text is cleared assertFalse("isPopupShowing() after text cleared", textView.isPopupShowing()); waitAssertPopupShowState("isPopupShowing() after text cleared", textView, false); // Set the text, without filtering runTestOnUiThread(new Runnable() { Loading @@ -188,7 +208,7 @@ public class AutoCompleteTextViewPopup instrumentation.waitForIdleSync(); // Drop-down should still be hidden assertFalse("isPopupShowing() after setText(\"a\", false)", textView.isPopupShowing()); waitAssertPopupShowState("isPopupShowing() after setText(\"a\", false)", textView, false); // Set the text, now with filtering runTestOnUiThread(new Runnable() { Loading @@ -199,6 +219,46 @@ public class AutoCompleteTextViewPopup instrumentation.waitForIdleSync(); // Drop-down should show up after setText() with filtering assertTrue("isPopupShowing() after text set", textView.isPopupShowing()); waitAssertPopupShowState("isPopupShowing() after text set", textView, true); // TODO: FlakyTest repeat runs will not currently call setUp, clear state clearText(textView); } private void waitAssertPopupShowState(String message, AutoCompleteTextView textView, boolean expected) throws InterruptedException { for (int i = 0; i < LOOP_AMOUNT; i++) { if (textView.isPopupShowing() == expected) { return; } Thread.sleep(SLEEP_TIME); } assertEquals(message, expected, textView.isPopupShowing()); } private void waitAssertListSelection(AutoCompleteTextView textView, int expected) throws Exception { waitAssertListSelection("getListSelection()", textView, expected); } private void waitAssertListSelection(String message, AutoCompleteTextView textView, int expected) throws Exception { int currentSelection = ListView.INVALID_POSITION; for (int i = 0; i < LOOP_AMOUNT; i++) { currentSelection = textView.getListSelection(); if (expected == currentSelection) { return; } Thread.sleep(SLEEP_TIME); } assertEquals(message, expected, textView.getListSelection()); } private void clearText(final AutoCompleteTextView textView) throws Throwable { runTestOnUiThread(new Runnable() { public void run() { textView.setText(""); } }); } }