Integrate unsubmitted cupcake change 149421:
CTS: add missed test cases for package android.widget
diff --git a/tests/AndroidManifest.xml b/tests/AndroidManifest.xml
index 1a48c6c..a4b61e6 100644
--- a/tests/AndroidManifest.xml
+++ b/tests/AndroidManifest.xml
@@ -216,6 +216,14 @@
</intent-filter>
</activity>
+ <activity android:name="android.widget.cts.ProgressBarStubActivity"
+ android:label="ProgressBarStubActivity">
+ <intent-filter>
+ <action android:name="android.intent.action.MAIN" />
+ <category android:name="android.intent.category.FRAMEWORK_INSTRUMENTATION_TEST" />
+ </intent-filter>
+ </activity>
+
<activity android:name="android.widget.cts.ChronometerStubActivity"
android:label="ChronometerStubActivity">
<intent-filter>
diff --git a/tests/res/values/styles.xml b/tests/res/values/styles.xml
index f73d16a..2ae7064 100644
--- a/tests/res/values/styles.xml
+++ b/tests/res/values/styles.xml
@@ -123,4 +123,12 @@
<item name="android:textSize">18sp</item>
</style>
+ <style name="TestProgressBar">
+ <item name="android:indeterminateOnly">false</item>
+ <item name="android:progressDrawable">?android:drawable/progress_horizontal</item>
+ <item name="android:indeterminateDrawable">?android:drawable/progress_horizontal</item>
+ <item name="android:minHeight">20dip</item>
+ <item name="android:maxHeight">20dip</item>
+ <item name="android:focusable">true</item>
+ </style>
</resources>
diff --git a/tests/src/android/widget/cts/ProgressBarStubActivity.java b/tests/src/android/widget/cts/ProgressBarStubActivity.java
new file mode 100644
index 0000000..8bd5993
--- /dev/null
+++ b/tests/src/android/widget/cts/ProgressBarStubActivity.java
@@ -0,0 +1,34 @@
+/*
+ * Copyright (C) 2008 Google Inc.
+ *
+ * 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 android.widget.cts;
+
+import android.app.Activity;
+import android.os.Bundle;
+
+/**
+ * An application for ProgressBar test
+ *
+ */
+public class ProgressBarStubActivity extends Activity {
+ /**
+ * Called with the activity is first created.
+ */
+ @Override
+ public void onCreate(Bundle savedInstanceState) {
+ super.onCreate(savedInstanceState);
+ }
+}
diff --git a/tests/tests/widget/src/android/widget/cts/AbsSeekBarTest.java b/tests/tests/widget/src/android/widget/cts/AbsSeekBarTest.java
index 143926f..6a30e06 100644
--- a/tests/tests/widget/src/android/widget/cts/AbsSeekBarTest.java
+++ b/tests/tests/widget/src/android/widget/cts/AbsSeekBarTest.java
@@ -16,341 +16,307 @@
package android.widget.cts;
+import com.android.cts.stub.R;
+
+import dalvik.annotation.TestLevel;
+import dalvik.annotation.TestTargetClass;
+import dalvik.annotation.TestTargetNew;
+import dalvik.annotation.TestTargets;
+
+import android.app.Activity;
import android.content.Context;
import android.content.res.Resources;
import android.graphics.Canvas;
import android.graphics.ColorFilter;
import android.graphics.drawable.Drawable;
-import android.test.AndroidTestCase;
+import android.test.ActivityInstrumentationTestCase2;
import android.util.AttributeSet;
+import android.view.KeyEvent;
import android.view.MotionEvent;
-import android.view.View.MeasureSpec;
import android.widget.AbsSeekBar;
-import android.widget.RatingBar;
-import android.widget.AbsoluteLayout.LayoutParams;
-
-import com.android.cts.stub.R;
-
-import dalvik.annotation.TestTargets;
-import dalvik.annotation.TestLevel;
-import dalvik.annotation.TestTargetNew;
-import dalvik.annotation.TestTargetClass;
-import dalvik.annotation.ToBeFixed;
+import android.widget.SeekBar;
/**
* Test {@link AbsSeekBar}.
*/
@TestTargetClass(AbsSeekBar.class)
-public class AbsSeekBarTest extends AndroidTestCase {
- private Context mContext;
- private Resources mResources;
+public class AbsSeekBarTest extends ActivityInstrumentationTestCase2<ProgressBarStubActivity> {
+ public AbsSeekBarTest() {
+ super("com.android.cts.stub", ProgressBarStubActivity.class);
+ }
- private static final int DEFAULT_LEFT = 5;
- private static final int DEFAULT_RIGHT = 10;
- private static final int DEFAULT_WIDTH = 20;
- private static final int DEFAULT_HEIGHT = 30;
+ private Activity mActivity;
+ private Resources mResources;
@Override
protected void setUp() throws Exception {
super.setUp();
- mContext = getContext();
- mResources = mContext.getResources();
+ mActivity = getActivity();
+ mResources = mActivity.getResources();
}
@TestTargets({
@TestTargetNew(
level = TestLevel.COMPLETE,
- notes = "Test constructor(s) of {@link AbsSeekBar}.",
method = "AbsSeekBar",
args = {android.content.Context.class}
),
@TestTargetNew(
level = TestLevel.COMPLETE,
- notes = "Test constructor(s) of {@link AbsSeekBar}.",
method = "AbsSeekBar",
args = {android.content.Context.class, android.util.AttributeSet.class}
),
@TestTargetNew(
level = TestLevel.COMPLETE,
- notes = "Test constructor(s) of {@link AbsSeekBar}.",
method = "AbsSeekBar",
args = {android.content.Context.class, android.util.AttributeSet.class, int.class}
)
})
public void testConstructor() {
- new MockAbsSeekBar(mContext);
+ new MyAbsSeekBar(mActivity);
- new MockAbsSeekBar(mContext, null);
+ new MyAbsSeekBar(mActivity, null);
- new MockAbsSeekBar(mContext, null, com.android.internal.R.attr.progressBarStyle);
+ new MyAbsSeekBar(mActivity, null, com.android.internal.R.attr.progressBarStyle);
}
@TestTargets({
@TestTargetNew(
level = TestLevel.COMPLETE,
- notes = "Test getThumbOffset() and setThumbOffset(int) function",
method = "setThumbOffset",
args = {int.class}
),
@TestTargetNew(
level = TestLevel.COMPLETE,
- notes = "Test getThumbOffset() and setThumbOffset(int) function",
method = "getThumbOffset",
args = {}
)
})
public void testAccessThumbOffset() {
- AbsSeekBar mockAbsSeekBar = new MockAbsSeekBar(mContext);
+ AbsSeekBar myAbsSeekBar = new MyAbsSeekBar(mActivity);
final int positive = 5;
final int negative = -5;
final int zero = 0;
- mockAbsSeekBar.setThumbOffset(positive);
- assertEquals(positive, mockAbsSeekBar.getThumbOffset());
+ myAbsSeekBar.setThumbOffset(positive);
+ assertEquals(positive, myAbsSeekBar.getThumbOffset());
- mockAbsSeekBar.setThumbOffset(zero);
- assertEquals(zero, mockAbsSeekBar.getThumbOffset());
+ myAbsSeekBar.setThumbOffset(zero);
+ assertEquals(zero, myAbsSeekBar.getThumbOffset());
- mockAbsSeekBar.setThumbOffset(negative);
- assertEquals(negative, mockAbsSeekBar.getThumbOffset());
+ myAbsSeekBar.setThumbOffset(negative);
+ assertEquals(negative, myAbsSeekBar.getThumbOffset());
}
@TestTargetNew(
level = TestLevel.COMPLETE,
- notes = "Test setThumb(Drawable) function.",
method = "setThumb",
args = {android.graphics.drawable.Drawable.class}
)
public void testSetThumb() {
- MockAbsSeekBar mockAbsSeekBar = new MockAbsSeekBar(mContext);
+ MyAbsSeekBar myAbsSeekBar = new MyAbsSeekBar(mActivity);
Drawable drawable1 = mResources.getDrawable(R.drawable.scenery);
Drawable drawable2 = mResources.getDrawable(R.drawable.pass);
- assertFalse(mockAbsSeekBar.verifyDrawable(drawable1));
- assertFalse(mockAbsSeekBar.verifyDrawable(drawable2));
+ assertFalse(myAbsSeekBar.verifyDrawable(drawable1));
+ assertFalse(myAbsSeekBar.verifyDrawable(drawable2));
- mockAbsSeekBar.setThumb(drawable1);
- assertTrue(mockAbsSeekBar.verifyDrawable(drawable1));
- assertFalse(mockAbsSeekBar.verifyDrawable(drawable2));
+ myAbsSeekBar.setThumb(drawable1);
+ assertTrue(myAbsSeekBar.verifyDrawable(drawable1));
+ assertFalse(myAbsSeekBar.verifyDrawable(drawable2));
- mockAbsSeekBar.setThumb(drawable2);
- assertFalse(mockAbsSeekBar.verifyDrawable(drawable1));
- assertTrue(mockAbsSeekBar.verifyDrawable(drawable2));
+ myAbsSeekBar.setThumb(drawable2);
+ assertFalse(myAbsSeekBar.verifyDrawable(drawable1));
+ assertTrue(myAbsSeekBar.verifyDrawable(drawable2));
}
@TestTargetNew(
level = TestLevel.COMPLETE,
- notes = "Test onTouchEvent(MotionEvent) function.",
- method = "onTouchEvent",
- args = {android.view.MotionEvent.class}
- )
- @ToBeFixed( bug = "1417734", explanation = "NullPointerException issue")
- public void testOnTouchEvent() {
- AbsSeekBar mockAbsSeekBar = new RatingBar(mContext);
- MotionEvent motionEvent = MotionEvent.obtain(1000, 1000,
- MotionEvent.ACTION_DOWN, 20, 20, 0);
- assertEquals(0, mockAbsSeekBar.getProgress());
-
- mockAbsSeekBar.setEnabled(false);
- assertFalse(mockAbsSeekBar.onTouchEvent(motionEvent));
- assertEquals(0, mockAbsSeekBar.getProgress());
-
- mockAbsSeekBar.setEnabled(true);
- assertTrue(mockAbsSeekBar.onTouchEvent(motionEvent));
- assertEquals(10, mockAbsSeekBar.getProgress());
-
- motionEvent = MotionEvent.obtain(1000, 1000, MotionEvent.ACTION_DOWN, -1, 20, 0);
- assertTrue(mockAbsSeekBar.onTouchEvent(motionEvent));
- assertEquals(0, mockAbsSeekBar.getProgress());
-
- try {
- mockAbsSeekBar.onTouchEvent(null);
- fail("should throw NullPointerException");
- } catch (NullPointerException e) {
- }
- }
-
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "Test drawableStateChanged() function.",
method = "drawableStateChanged",
args = {}
)
public void testDrawableStateChanged() {
- MockAbsSeekBar mockAbsSeekBar = new MockAbsSeekBar(mContext);
+ MyAbsSeekBar myAbsSeekBar = new MyAbsSeekBar(mActivity);
MockDrawable drawable = new MockDrawable();
- mockAbsSeekBar.setProgressDrawable(drawable);
+ myAbsSeekBar.setProgressDrawable(drawable);
- mockAbsSeekBar.setEnabled(false);
- mockAbsSeekBar.drawableStateChanged();
+ myAbsSeekBar.setEnabled(false);
+ myAbsSeekBar.drawableStateChanged();
assertEquals(0, drawable.getAlpha());
- mockAbsSeekBar.setEnabled(true);
- mockAbsSeekBar.drawableStateChanged();
+ myAbsSeekBar.setEnabled(true);
+ myAbsSeekBar.drawableStateChanged();
assertEquals(0xFF, drawable.getAlpha());
}
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "Test onDraw(Canvas)",
- method = "onDraw",
- args = {android.graphics.Canvas.class}
- )
- @ToBeFixed(bug="1400249", explanation="it's hard to do unit test, should be tested by" +
- " functional test, and there should not be an NullPointerException thrown out.")
- public void testOnDraw() {
- MockAbsSeekBar mockAbsSeekBar = new MockAbsSeekBar(mContext);
- MockDrawable drawable = new MockDrawable();
-
- mockAbsSeekBar.setThumb(drawable);
- mockAbsSeekBar.onDraw(new Canvas());
- assertTrue(drawable.hasCalledDraw());
-
- // input null as param
- try {
- mockAbsSeekBar.onDraw(null);
- fail("There should be a NullPointerException thrown out.");
- } catch (NullPointerException e) {
- }
- }
-
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "Test onMeasure(int, int) function.",
- method = "onMeasure",
- args = {int.class, int.class}
- )
- public void testOnMeasure() {
- AbsSeekBar mockAbsSeekBar = new RatingBar(mContext);
- LayoutParams layoutParams = new LayoutParams(DEFAULT_WIDTH,
- DEFAULT_HEIGHT, DEFAULT_LEFT, DEFAULT_RIGHT);
- mockAbsSeekBar.setLayoutParams(layoutParams);
- mockAbsSeekBar.measure(5, 5);
- int measureSpec = MeasureSpec.makeMeasureSpec(5, MeasureSpec.AT_MOST);
- mockAbsSeekBar.measure(measureSpec, measureSpec);
- assertEquals(5, mockAbsSeekBar.getMeasuredHeight());
- assertEquals(5, mockAbsSeekBar.getMeasuredWidth());
-
- measureSpec = MeasureSpec.makeMeasureSpec(100, MeasureSpec.EXACTLY);
- mockAbsSeekBar.measure(measureSpec, measureSpec);
- assertEquals(100, mockAbsSeekBar.getMeasuredHeight());
- assertEquals(100, mockAbsSeekBar.getMeasuredWidth());
-
- measureSpec = MeasureSpec.makeMeasureSpec(5, MeasureSpec.UNSPECIFIED);
- mockAbsSeekBar.measure(measureSpec, measureSpec);
- assertEquals(57, mockAbsSeekBar.getMeasuredHeight());
- assertEquals(285, mockAbsSeekBar.getMeasuredWidth());
-
- mockAbsSeekBar.setPadding(10, 20, 30, 40);
- mockAbsSeekBar.setMinimumHeight(20);
- mockAbsSeekBar.setMinimumWidth(10);
- mockAbsSeekBar.measure(5, 5);
- measureSpec = MeasureSpec.makeMeasureSpec(5, MeasureSpec.AT_MOST);
- mockAbsSeekBar.measure(measureSpec, measureSpec);
- assertEquals(5, mockAbsSeekBar.getMeasuredHeight());
- assertEquals(5, mockAbsSeekBar.getMeasuredWidth());
-
- measureSpec = MeasureSpec.makeMeasureSpec(100, MeasureSpec.EXACTLY);
- mockAbsSeekBar.measure(measureSpec, measureSpec);
- assertEquals(100, mockAbsSeekBar.getMeasuredHeight());
- assertEquals(100, mockAbsSeekBar.getMeasuredWidth());
-
- measureSpec = MeasureSpec.makeMeasureSpec(5, MeasureSpec.UNSPECIFIED);
- mockAbsSeekBar.measure(measureSpec, measureSpec);
- assertEquals(117, mockAbsSeekBar.getMeasuredHeight());
- assertEquals(285, mockAbsSeekBar.getMeasuredWidth());
-
- mockAbsSeekBar.setThumbOffset(5);
- Drawable drawable = mContext.getResources().getDrawable(R.drawable.pass);
- mockAbsSeekBar.setThumb(drawable);
-
- mockAbsSeekBar.measure(5, 5);
- measureSpec = MeasureSpec.makeMeasureSpec(5, MeasureSpec.AT_MOST);
- mockAbsSeekBar.measure(measureSpec, measureSpec);
- assertEquals(5, mockAbsSeekBar.getMeasuredHeight());
- assertEquals(5, mockAbsSeekBar.getMeasuredWidth());
- measureSpec = MeasureSpec.makeMeasureSpec(100, MeasureSpec.EXACTLY);
- mockAbsSeekBar.measure(measureSpec, measureSpec);
- assertEquals(100, mockAbsSeekBar.getMeasuredHeight());
- assertEquals(100, mockAbsSeekBar.getMeasuredWidth());
-
- measureSpec = MeasureSpec.makeMeasureSpec(5, MeasureSpec.UNSPECIFIED);
- mockAbsSeekBar.measure(measureSpec, measureSpec);
- assertEquals(117, mockAbsSeekBar.getMeasuredHeight());
- assertEquals(285, mockAbsSeekBar.getMeasuredWidth());
- }
-
@TestTargets({
@TestTargetNew(
level = TestLevel.COMPLETE,
- notes = "Test verifyDrawable(Drawable) and setThumb(Drawable) function.",
method = "setThumb",
args = {android.graphics.drawable.Drawable.class}
),
@TestTargetNew(
level = TestLevel.COMPLETE,
- notes = "Test verifyDrawable(Drawable) and setThumb(Drawable) function.",
method = "verifyDrawable",
args = {android.graphics.drawable.Drawable.class}
)
})
public void testVerifyDrawable() {
- MockAbsSeekBar mockAbsSeekBar = new MockAbsSeekBar(mContext);
+ MyAbsSeekBar myAbsSeekBar = new MyAbsSeekBar(mActivity);
Drawable drawable1 = mResources.getDrawable(R.drawable.scenery);
Drawable drawable2 = mResources.getDrawable(R.drawable.pass);
Drawable drawable3 = mResources.getDrawable(R.drawable.blue);
Drawable drawable4 = mResources.getDrawable(R.drawable.black);
- assertFalse(mockAbsSeekBar.verifyDrawable(drawable1));
- assertFalse(mockAbsSeekBar.verifyDrawable(drawable2));
- assertFalse(mockAbsSeekBar.verifyDrawable(drawable3));
- assertFalse(mockAbsSeekBar.verifyDrawable(drawable4));
- assertTrue(mockAbsSeekBar.verifyDrawable(null));
+ assertFalse(myAbsSeekBar.verifyDrawable(drawable1));
+ assertFalse(myAbsSeekBar.verifyDrawable(drawable2));
+ assertFalse(myAbsSeekBar.verifyDrawable(drawable3));
+ assertFalse(myAbsSeekBar.verifyDrawable(drawable4));
+ assertTrue(myAbsSeekBar.verifyDrawable(null));
- mockAbsSeekBar.setThumb(drawable1);
- assertTrue(mockAbsSeekBar.verifyDrawable(drawable1));
- assertFalse(mockAbsSeekBar.verifyDrawable(drawable2));
- assertFalse(mockAbsSeekBar.verifyDrawable(drawable3));
- assertFalse(mockAbsSeekBar.verifyDrawable(drawable4));
- assertTrue(mockAbsSeekBar.verifyDrawable(null));
+ myAbsSeekBar.setThumb(drawable1);
+ assertTrue(myAbsSeekBar.verifyDrawable(drawable1));
+ assertFalse(myAbsSeekBar.verifyDrawable(drawable2));
+ assertFalse(myAbsSeekBar.verifyDrawable(drawable3));
+ assertFalse(myAbsSeekBar.verifyDrawable(drawable4));
+ assertTrue(myAbsSeekBar.verifyDrawable(null));
- mockAbsSeekBar.setThumb(drawable2);
- assertFalse(mockAbsSeekBar.verifyDrawable(drawable1));
- assertTrue(mockAbsSeekBar.verifyDrawable(drawable2));
- assertFalse(mockAbsSeekBar.verifyDrawable(drawable3));
- assertFalse(mockAbsSeekBar.verifyDrawable(drawable4));
- assertTrue(mockAbsSeekBar.verifyDrawable(null));
+ myAbsSeekBar.setThumb(drawable2);
+ assertFalse(myAbsSeekBar.verifyDrawable(drawable1));
+ assertTrue(myAbsSeekBar.verifyDrawable(drawable2));
+ assertFalse(myAbsSeekBar.verifyDrawable(drawable3));
+ assertFalse(myAbsSeekBar.verifyDrawable(drawable4));
+ assertTrue(myAbsSeekBar.verifyDrawable(null));
- mockAbsSeekBar.setBackgroundDrawable(drawable2);
- mockAbsSeekBar.setProgressDrawable(drawable3);
- mockAbsSeekBar.setIndeterminateDrawable(drawable4);
- assertFalse(mockAbsSeekBar.verifyDrawable(drawable1));
- assertTrue(mockAbsSeekBar.verifyDrawable(drawable2));
- assertTrue(mockAbsSeekBar.verifyDrawable(drawable3));
- assertTrue(mockAbsSeekBar.verifyDrawable(drawable4));
- assertFalse(mockAbsSeekBar.verifyDrawable(null));
+ myAbsSeekBar.setBackgroundDrawable(drawable2);
+ myAbsSeekBar.setProgressDrawable(drawable3);
+ myAbsSeekBar.setIndeterminateDrawable(drawable4);
+ assertFalse(myAbsSeekBar.verifyDrawable(drawable1));
+ assertTrue(myAbsSeekBar.verifyDrawable(drawable2));
+ assertTrue(myAbsSeekBar.verifyDrawable(drawable3));
+ assertTrue(myAbsSeekBar.verifyDrawable(drawable4));
+ assertFalse(myAbsSeekBar.verifyDrawable(null));
+ }
+
+ @TestTargets({
+ @TestTargetNew(
+ level = TestLevel.COMPLETE,
+ method = "getKeyProgressIncrement",
+ args = {}
+ ),
+ @TestTargetNew(
+ level = TestLevel.COMPLETE,
+ method = "setKeyProgressIncrement",
+ args = {int.class}
+ )
+ })
+ public void testAccessKeyProgressIncrement() throws Throwable {
+ // AbsSeekBar is an abstract class, use its subclass: SeekBar to do this test.
+ runTestOnUiThread(new Runnable() {
+ public void run() {
+ mActivity.setContentView(R.layout.seekbar);
+ }
+ });
+ getInstrumentation().waitForIdleSync();
+
+ final SeekBar seekBar = (SeekBar) mActivity.findViewById(R.id.seekBar);
+ final int keyProgressIncrement = 2;
+ runTestOnUiThread(new Runnable() {
+ public void run() {
+ seekBar.setKeyProgressIncrement(keyProgressIncrement);
+ seekBar.setFocusable(true);
+ seekBar.requestFocus();
+ }
+ });
+ getInstrumentation().waitForIdleSync();
+ assertEquals(keyProgressIncrement, seekBar.getKeyProgressIncrement());
+
+ int oldProgress = seekBar.getProgress();
+ KeyEvent keyEvent = new KeyEvent(KeyEvent.ACTION_DOWN, KeyEvent.KEYCODE_DPAD_RIGHT);
+ getInstrumentation().sendKeySync(keyEvent);
+ assertEquals(oldProgress + keyProgressIncrement, seekBar.getProgress());
+ oldProgress = seekBar.getProgress();
+ keyEvent = new KeyEvent(KeyEvent.ACTION_DOWN, KeyEvent.KEYCODE_DPAD_LEFT);
+ getInstrumentation().sendKeySync(keyEvent);
+ assertEquals(oldProgress - keyProgressIncrement, seekBar.getProgress());
}
@TestTargetNew(
- level = TestLevel.NOT_NECESSARY,
- notes = "Test onSizeChanged(int, int, int, int) function.",
- method = "onSizeChanged",
- args = {int.class, int.class, int.class, int.class}
+ level = TestLevel.COMPLETE,
+ method = "setMax",
+ args = {int.class}
)
- public void testOnSizeChanged() {
- // Do not test it. It's implementation detail.
+ public void testSetMax() {
+ MyAbsSeekBar myAbsSeekBar = new MyAbsSeekBar(mActivity, null, R.style.TestProgressBar);
+
+ int progress = 10;
+ myAbsSeekBar.setProgress(progress);
+ int max = progress + 1;
+ myAbsSeekBar.setMax(max);
+ assertEquals(max, myAbsSeekBar.getMax());
+ assertEquals(progress, myAbsSeekBar.getProgress());
+ assertEquals(1, myAbsSeekBar.getKeyProgressIncrement());
+
+ max = progress - 1;
+ myAbsSeekBar.setMax(max);
+ assertEquals(max, myAbsSeekBar.getMax());
+ assertEquals(max, myAbsSeekBar.getProgress());
+ assertEquals(1, myAbsSeekBar.getKeyProgressIncrement());
+
+ int keyProgressIncrement = 10;
+ myAbsSeekBar.setKeyProgressIncrement(keyProgressIncrement);
+ assertEquals(keyProgressIncrement, myAbsSeekBar.getKeyProgressIncrement());
+ max = (keyProgressIncrement - 1) * 20;
+ myAbsSeekBar.setMax(max);
+ assertEquals(keyProgressIncrement, myAbsSeekBar.getKeyProgressIncrement());
+ max = (keyProgressIncrement + 1) * 20;
+ myAbsSeekBar.setMax(max);
+ assertEquals(keyProgressIncrement + 1, myAbsSeekBar.getKeyProgressIncrement());
}
- private class MockAbsSeekBar extends AbsSeekBar {
- public MockAbsSeekBar(Context context) {
+ @TestTargets({
+ @TestTargetNew(
+ level = TestLevel.NOT_NECESSARY,
+ method = "onSizeChanged",
+ args = {int.class, int.class, int.class, int.class}
+ ),
+ @TestTargetNew(
+ level = TestLevel.NOT_NECESSARY,
+ method = "onDraw",
+ args = {Canvas.class}
+ ),
+ @TestTargetNew(
+ level = TestLevel.NOT_NECESSARY,
+ method = "onKeyDown",
+ args = {int.class, KeyEvent.class}
+ ),
+ @TestTargetNew(
+ level = TestLevel.NOT_NECESSARY,
+ method = "onMeasure",
+ args = {int.class, int.class}
+ ),
+ @TestTargetNew(
+ level = TestLevel.NOT_NECESSARY,
+ method = "onTouchEvent",
+ args = {MotionEvent.class}
+ )
+ })
+ public void testFoo() {
+ // Do not test these APIs. They are callbacks which:
+ // 1. The callback machanism has been tested in super class
+ // 2. The functionality is implmentation details, no need to test
+ }
+
+ private static class MyAbsSeekBar extends AbsSeekBar {
+ public MyAbsSeekBar(Context context) {
super(context);
}
- public MockAbsSeekBar(Context context, AttributeSet attrs) {
+ public MyAbsSeekBar(Context context, AttributeSet attrs) {
super(context, attrs);
}
- public MockAbsSeekBar(Context context, AttributeSet attrs, int defStyle) {
+ public MyAbsSeekBar(Context context, AttributeSet attrs, int defStyle) {
super(context, attrs, defStyle);
}
@@ -360,27 +326,12 @@
}
@Override
- protected synchronized void onDraw(Canvas canvas) {
- super.onDraw(canvas);
- }
-
- @Override
protected boolean verifyDrawable(Drawable who) {
return super.verifyDrawable(who);
}
-
- @Override
- protected void onSizeChanged(int w, int h, int oldw, int oldh) {
- super.onSizeChanged(w, h, oldw, oldh);
- }
-
- @Override
- protected synchronized void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
- super.onMeasure(widthMeasureSpec, heightMeasureSpec);
- }
}
- private class MockDrawable extends Drawable {
+ private static class MockDrawable extends Drawable {
private int mAlpha;
private boolean mCalledDraw = false;
diff --git a/tests/tests/widget/src/android/widget/cts/AutoCompleteTextViewTest.java b/tests/tests/widget/src/android/widget/cts/AutoCompleteTextViewTest.java
index e144e2d..554feab 100644
--- a/tests/tests/widget/src/android/widget/cts/AutoCompleteTextViewTest.java
+++ b/tests/tests/widget/src/android/widget/cts/AutoCompleteTextViewTest.java
@@ -16,7 +16,13 @@
package android.widget.cts;
-import java.io.IOException;
+import com.android.cts.stub.R;
+
+import dalvik.annotation.TestLevel;
+import dalvik.annotation.TestTargetClass;
+import dalvik.annotation.TestTargetNew;
+import dalvik.annotation.TestTargets;
+import dalvik.annotation.ToBeFixed;
import org.xmlpull.v1.XmlPullParser;
import org.xmlpull.v1.XmlPullParserException;
@@ -31,21 +37,15 @@
import android.util.Xml;
import android.view.KeyEvent;
import android.view.View;
+import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.AutoCompleteTextView;
import android.widget.Filter;
import android.widget.Filterable;
-import android.widget.ListAdapter;
import android.widget.AutoCompleteTextView.Validator;
-import com.android.cts.stub.R;
-
-import dalvik.annotation.TestTargets;
-import dalvik.annotation.TestTargetNew;
-import dalvik.annotation.TestLevel;
-import dalvik.annotation.TestTargetClass;
-import dalvik.annotation.ToBeFixed;
+import java.io.IOException;
@TestTargetClass(AutoCompleteTextView.class)
public class AutoCompleteTextViewTest extends
@@ -100,25 +100,21 @@
@TestTargets({
@TestTargetNew(
level = TestLevel.COMPLETE,
- notes = "Test the constructor AutoCompleteTextView(Context)",
method = "AutoCompleteTextView",
args = {android.content.Context.class}
),
@TestTargetNew(
level = TestLevel.COMPLETE,
- notes = "Test the constructor AutoCompleteTextView(Context)",
method = "AutoCompleteTextView",
args = {android.content.Context.class, android.util.AttributeSet.class}
),
@TestTargetNew(
level = TestLevel.COMPLETE,
- notes = "Test the constructor AutoCompleteTextView(Context)",
method = "AutoCompleteTextView",
args = {android.content.Context.class, android.util.AttributeSet.class, int.class}
)
})
- @ToBeFixed(bug = "1417734", explanation = "should add NullPointerException @throws" +
- " clause into javadoc.")
+ @ToBeFixed(bug = "1695243", explanation = "Android API javadocs are incomplete")
public void testConstructor() {
XmlPullParser parser;
@@ -153,15 +149,14 @@
@TestTargetNew(
level = TestLevel.COMPLETE,
- notes = "Test {@link AutoCompleteTextView#enoughToFilter()}.",
method = "enoughToFilter",
args = {}
)
- public void testEnoughToFilter() {
+ public void testEnoughToFilter() throws Throwable {
mAutoCompleteTextView.setThreshold(3);
assertEquals(3, mAutoCompleteTextView.getThreshold());
- mActivity.runOnUiThread(new Runnable() {
+ runTestOnUiThread(new Runnable() {
public void run() {
String testString = "TryToTest";
mAutoCompleteTextView.setText(testString);
@@ -170,7 +165,7 @@
mInstrumentation.waitForIdleSync();
assertTrue(mAutoCompleteTextView.enoughToFilter());
- mActivity.runOnUiThread(new Runnable() {
+ runTestOnUiThread(new Runnable() {
public void run() {
String testString = "No";
mAutoCompleteTextView.setText(testString);
@@ -230,22 +225,31 @@
level = TestLevel.COMPLETE,
method = "getItemClickListener",
args = {}
+ ),
+ @TestTargetNew(
+ level = TestLevel.COMPLETE,
+ method = "getOnItemClickListener",
+ args = {}
)
})
+ @SuppressWarnings("deprecation")
public void testAccessItemClickListener() {
final MockOnItemClickListener testOnItemClickListener = new MockOnItemClickListener();
// To ensure null listener
mAutoCompleteTextView.setOnItemClickListener(null);
assertNull(mAutoCompleteTextView.getItemClickListener());
+ assertNull(mAutoCompleteTextView.getOnItemClickListener());
assertNotNull(testOnItemClickListener);
mAutoCompleteTextView.setOnItemClickListener(testOnItemClickListener);
assertSame(testOnItemClickListener, mAutoCompleteTextView.getItemClickListener());
+ assertSame(testOnItemClickListener, mAutoCompleteTextView.getOnItemClickListener());
// re-clear listener by setOnItemClickListener
mAutoCompleteTextView.setOnItemClickListener(null);
assertNull(mAutoCompleteTextView.getItemClickListener());
+ assertNull(mAutoCompleteTextView.getOnItemClickListener());
}
@TestTargets({
@@ -258,27 +262,35 @@
level = TestLevel.COMPLETE,
method = "getItemSelectedListener",
args = {}
+ ),
+ @TestTargetNew(
+ level = TestLevel.COMPLETE,
+ method = "getOnItemSelectedListener",
+ args = {}
)
})
+ @SuppressWarnings("deprecation")
public void testAccessItemSelectedListener() {
MockOnItemSelectedListener testOnItemSelectedListener = new MockOnItemSelectedListener();
// To ensure null listener
mAutoCompleteTextView.setOnItemSelectedListener(null);
assertNull(mAutoCompleteTextView.getItemSelectedListener());
+ assertNull(mAutoCompleteTextView.getOnItemSelectedListener());
assertNotNull(testOnItemSelectedListener);
mAutoCompleteTextView.setOnItemSelectedListener(testOnItemSelectedListener);
- assertEquals(testOnItemSelectedListener, mAutoCompleteTextView.getItemSelectedListener());
+ assertSame(testOnItemSelectedListener, mAutoCompleteTextView.getItemSelectedListener());
+ assertSame(testOnItemSelectedListener, mAutoCompleteTextView.getOnItemSelectedListener());
//re-clear listener by setOnItemClickListener
mAutoCompleteTextView.setOnItemSelectedListener(null);
assertNull(mAutoCompleteTextView.getItemSelectedListener());
+ assertNull(mAutoCompleteTextView.getOnItemSelectedListener());
}
@TestTargetNew(
level = TestLevel.COMPLETE,
- notes = "Test {@link AutoCompleteTextView#convertSelectionToString(Object)}.",
method = "convertSelectionToString",
args = {java.lang.Object.class}
)
@@ -296,7 +308,6 @@
@TestTargetNew(
level = TestLevel.COMPLETE,
- notes = "Test {@link AutoCompleteTextView#onTextChanged(CharSequence, int, int, int)}.",
method = "onTextChanged",
args = {java.lang.CharSequence.class, int.class, int.class, int.class}
)
@@ -377,7 +388,6 @@
@TestTargetNew(
level = TestLevel.COMPLETE,
- notes = "Test {@link AutoCompleteTextView#replaceText(CharSequence)}.",
method = "replaceText",
args = {java.lang.CharSequence.class}
)
@@ -399,7 +409,6 @@
@TestTargetNew(
level = TestLevel.COMPLETE,
- notes = "Test {@link AutoCompleteTextView#setFrame(int, int, int, int)}.",
method = "setFrame",
args = {int.class, int.class, int.class, int.class}
)
@@ -486,9 +495,7 @@
method = "onFilterComplete",
args = {int.class}
)
- @ToBeFixed(bug = "", explanation = "This case needs more carefully examined")
- // This function can only be test by indirect calling.
- public void _testOnFilterComplete() {
+ public void testOnFilterComplete() throws Throwable {
// Set Threshold to 4 characters
mAutoCompleteTextView.setThreshold(4);
@@ -496,7 +503,7 @@
assertTrue(mAutoCompleteTextView.isPopupShowing());
String testString = "tes";
// Test the filter if the input string is not long enough to threshold
- mActivity.runOnUiThread(new Runnable() {
+ runTestOnUiThread(new Runnable() {
public void run() {
mAutoCompleteTextView.setAdapter(mAdapter);
mAutoCompleteTextView.setText("");
@@ -515,7 +522,7 @@
assertFalse(mAutoCompleteTextView.isPopupShowing());
// Test the expected filter matching scene
- mActivity.runOnUiThread(new Runnable() {
+ runTestOnUiThread(new Runnable() {
public void run() {
mAutoCompleteTextView.setFocusable(true);
mAutoCompleteTextView.requestFocus();
@@ -531,20 +538,18 @@
@TestTargets({
@TestTargetNew(
level = TestLevel.COMPLETE,
- notes = "Test onKeyDown and performFiltering.",
method = "onKeyDown",
args = {int.class, android.view.KeyEvent.class}
),
@TestTargetNew(
level = TestLevel.COMPLETE,
- notes = "Test onKeyDown and performFiltering.",
method = "performFiltering",
args = {java.lang.CharSequence.class, int.class}
)
})
- @ToBeFixed( bug = "", explanation = "mAutoCompleteTextView.isPopupShowing() should be false")
- public void testPerformFiltering() {
- mActivity.runOnUiThread(new Runnable() {
+ @ToBeFixed(bug = "", explanation = "mAutoCompleteTextView.isPopupShowing() should be false")
+ public void testPerformFiltering() throws Throwable {
+ runTestOnUiThread(new Runnable() {
public void run() {
mAutoCompleteTextView.setAdapter(mAdapter);
mAutoCompleteTextView.setValidator(mValidator);
@@ -557,9 +562,8 @@
// KeyBack will close the popup.
assertFalse(mAutoCompleteTextView.isPopupShowing());
- mActivity.runOnUiThread(new Runnable() {
+ runTestOnUiThread(new Runnable() {
public void run() {
-
mAutoCompleteTextView.dismissDropDown();
mAutoCompleteTextView.setText(STRING_TEST);
}
@@ -571,11 +575,11 @@
// If the popup is closed, onKeyDown will invoke performValidation.
assertEquals(STRING_VALIDATED, mAutoCompleteTextView.getText().toString());
- final MockAdapter adapter = new MockAdapter<String>(mActivity,
+ final MockAdapter<String> adapter = new MockAdapter<String>(mActivity,
android.R.layout.simple_dropdown_item_1line, WORDS);
// Set Threshold to 4 charactersonKeyDown
- mActivity.runOnUiThread(new Runnable() {
+ runTestOnUiThread(new Runnable() {
public void run() {
mAutoCompleteTextView.setAdapter(adapter);
mAutoCompleteTextView.requestFocus();
@@ -595,22 +599,25 @@
@TestTargets({
@TestTargetNew(
level = TestLevel.COMPLETE,
- notes = "Test performCompletion() and onKeyUp(int , KeyEvent).",
method = "performCompletion",
args = {}
),
@TestTargetNew(
level = TestLevel.COMPLETE,
- notes = "Test performCompletion() and onKeyUp(int , KeyEvent).",
method = "onKeyUp",
args = {int.class, android.view.KeyEvent.class}
+ ),
+ @TestTargetNew(
+ level = TestLevel.COMPLETE,
+ method = "isPerformingCompletion",
+ args = {}
)
})
- @ToBeFixed( bug = "", explanation = "This test is really broken and needs to be updated.")
- public void _testPerformCompletion() {
+ public void testPerformCompletion() throws Throwable {
final MockOnItemClickListener listener = new MockOnItemClickListener();
+ assertFalse(mAutoCompleteTextView.isPerformingCompletion());
- mActivity.runOnUiThread(new Runnable() {
+ runTestOnUiThread(new Runnable() {
public void run() {
mAutoCompleteTextView.setOnItemClickListener(listener);
mAutoCompleteTextView.setAdapter(mAdapter);
@@ -619,6 +626,7 @@
}
});
mInstrumentation.waitForIdleSync();
+ assertFalse(mAutoCompleteTextView.isPerformingCompletion());
// Key is ENTER or DPAD_ENTER, will invoke completion
mInstrumentation.sendKeyDownUpSync(KeyEvent.KEYCODE_DPAD_DOWN);
@@ -631,7 +639,7 @@
// re-set 'clicked' flag to false
listener.clearItemClickedStatus();
- mActivity.runOnUiThread(new Runnable() {
+ runTestOnUiThread(new Runnable() {
public void run() {
mAutoCompleteTextView.showDropDown();
}
@@ -640,9 +648,10 @@
mInstrumentation.sendKeyDownUpSync(KeyEvent.KEYCODE_DPAD_CENTER);
assertTrue(listener.isOnItemClicked());
assertEquals(WORDS[0], mAutoCompleteTextView.getText().toString());
+ assertFalse(mAutoCompleteTextView.isPerformingCompletion());
listener.clearItemClickedStatus();
- mActivity.runOnUiThread(new Runnable() {
+ runTestOnUiThread(new Runnable() {
public void run() {
mAutoCompleteTextView.showDropDown();
}
@@ -652,6 +661,7 @@
mInstrumentation.sendKeyDownUpSync(KeyEvent.KEYCODE_0);
assertFalse(listener.isOnItemClicked());
assertNotSame("", mAutoCompleteTextView.getText().toString());
+ assertFalse(mAutoCompleteTextView.isPerformingCompletion());
listener.clearItemClickedStatus();
@@ -661,11 +671,11 @@
mInstrumentation.sendKeyDownUpSync(KeyEvent.KEYCODE_ENTER);
assertFalse(listener.isOnItemClicked());
assertNotSame("", mAutoCompleteTextView.getText().toString());
+ assertFalse(mAutoCompleteTextView.isPerformingCompletion());
}
@TestTargetNew(
level = TestLevel.COMPLETE,
- notes = "Test {@link AutoCompleteTextView#onWindowFocusChanged(boolean)}.",
method = "onWindowFocusChanged",
args = {boolean.class}
)
@@ -695,7 +705,6 @@
@TestTargetNew(
level = TestLevel.COMPLETE,
- notes = "Test {@link AutoCompleteTextView#performValidation()}.",
method = "performValidation",
args = {}
)
@@ -714,7 +723,6 @@
@TestTargetNew(
level = TestLevel.COMPLETE,
- notes = "Test {@link AutoCompleteTextView#setCompletionHint(CharSequence)}.",
method = "setCompletionHint",
args = {java.lang.CharSequence.class}
)
@@ -723,7 +731,130 @@
mAutoCompleteTextView.setCompletionHint("TEST HINT");
}
- private class MockOnItemClickListener implements AdapterView.OnItemClickListener {
+ @TestTargetNew(
+ level = TestLevel.NOT_NECESSARY,
+ method = "onAttachedToWindow",
+ args = {}
+ )
+ public void testOnAttachedToWindow() {
+ // implement details, do not test
+ }
+
+ @TestTargetNew(
+ level = TestLevel.NOT_NECESSARY,
+ method = "onCommitCompletion",
+ args = {android.view.inputmethod.CompletionInfo.class}
+ )
+ public void testOnCommitCompletion() {
+ // implement details, do not test
+ }
+
+ @TestTargetNew(
+ level = TestLevel.NOT_NECESSARY,
+ method = "onDetachedFromWindow",
+ args = {}
+ )
+ public void testOnDetachedFromWindow() {
+ // implement details, do not test
+ }
+
+ @TestTargetNew(
+ level = TestLevel.NOT_NECESSARY,
+ method = "onKeyPreIme",
+ args = {int.class, android.view.KeyEvent.class}
+ )
+ public void testOnKeyPreIme() {
+ // implement details, do not test
+ }
+
+ @TestTargets({
+ @TestTargetNew(
+ level = TestLevel.COMPLETE,
+ method = "setListSelection",
+ args = {int.class}
+ ),
+ @TestTargetNew(
+ level = TestLevel.COMPLETE,
+ method = "getListSelection",
+ args = {}
+ ),
+ @TestTargetNew(
+ level = TestLevel.COMPLETE,
+ method = "clearListSelection",
+ args = {}
+ )
+ })
+ @ToBeFixed(bug = "", explanation = "When clearListSelection, getListSelection should " +
+ "return ListView.INVALID_POSITION, but not.")
+ public void testAccessListSelection() throws Throwable {
+ final MockOnItemClickListener listener = new MockOnItemClickListener();
+
+ runTestOnUiThread(new Runnable() {
+ public void run() {
+ mAutoCompleteTextView.setOnItemClickListener(listener);
+ mAutoCompleteTextView.setAdapter(mAdapter);
+ mAutoCompleteTextView.requestFocus();
+ mAutoCompleteTextView.showDropDown();
+ }
+ });
+ mInstrumentation.waitForIdleSync();
+
+ runTestOnUiThread(new Runnable() {
+ public void run() {
+ mAutoCompleteTextView.setListSelection(1);
+ assertEquals(1, mAutoCompleteTextView.getListSelection());
+
+ mAutoCompleteTextView.setListSelection(2);
+ assertEquals(2, mAutoCompleteTextView.getListSelection());
+
+ mAutoCompleteTextView.clearListSelection();
+ assertEquals(2, mAutoCompleteTextView.getListSelection());
+ }
+ });
+ mInstrumentation.waitForIdleSync();
+ }
+
+ @TestTargets({
+ @TestTargetNew(
+ level = TestLevel.COMPLETE,
+ method = "setDropDownAnchor",
+ args = {int.class}
+ ),
+ @TestTargetNew(
+ level = TestLevel.COMPLETE,
+ method = "getDropDownAnchor",
+ args = {}
+ )
+ })
+ public void testAccessDropDownAnchor() {
+ mAutoCompleteTextView.setDropDownAnchor(View.NO_ID);
+ assertEquals(View.NO_ID, mAutoCompleteTextView.getDropDownAnchor());
+
+ mAutoCompleteTextView.setDropDownAnchor(0x5555);
+ assertEquals(0x5555, mAutoCompleteTextView.getDropDownAnchor());
+ }
+
+ @TestTargets({
+ @TestTargetNew(
+ level = TestLevel.COMPLETE,
+ method = "setDropDownWidth",
+ args = {int.class}
+ ),
+ @TestTargetNew(
+ level = TestLevel.COMPLETE,
+ method = "getDropDownWidth",
+ args = {}
+ )
+ })
+ public void testAccessDropDownWidth() {
+ mAutoCompleteTextView.setDropDownWidth(ViewGroup.LayoutParams.WRAP_CONTENT);
+ assertEquals(ViewGroup.LayoutParams.WRAP_CONTENT, mAutoCompleteTextView.getDropDownWidth());
+
+ mAutoCompleteTextView.setDropDownWidth(ViewGroup.LayoutParams.FILL_PARENT);
+ assertEquals(ViewGroup.LayoutParams.FILL_PARENT, mAutoCompleteTextView.getDropDownWidth());
+ }
+
+ private static class MockOnItemClickListener implements AdapterView.OnItemClickListener {
private boolean mOnItemClickedFlag = false;
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
@@ -740,7 +871,7 @@
}
}
- private class MockOnItemSelectedListener implements AdapterView.OnItemSelectedListener {
+ private static class MockOnItemSelectedListener implements AdapterView.OnItemSelectedListener {
public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
return;
}
@@ -751,7 +882,6 @@
}
private class MockValidator implements AutoCompleteTextView.Validator {
-
public CharSequence fixText(CharSequence invalidText) {
return STRING_VALIDATED;
}
@@ -764,8 +894,7 @@
}
}
- public class MockAutoCompleteTextView extends AutoCompleteTextView {
- // static boolean isOnFilterComplete = false;
+ private static class MockAutoCompleteTextView extends AutoCompleteTextView {
private boolean mOnTextChangedFlag = false;
private boolean mOnFilterCompleteFlag = false;
private String lastChangeText = "";
@@ -865,8 +994,8 @@
}
}
- private void inflatePopup() {
- mActivity.runOnUiThread(new Runnable() {
+ private void inflatePopup() throws Throwable {
+ runTestOnUiThread(new Runnable() {
public void run() {
mAutoCompleteTextView.setText("");
mAutoCompleteTextView.setFocusable(true);
@@ -877,15 +1006,13 @@
mInstrumentation.waitForIdleSync();
}
- private class MockFilter extends Filter {
-
+ private static class MockFilter extends Filter {
private String mFilterResult;
- private Object mListener;
@Override
protected FilterResults performFiltering(CharSequence constraint) {
if (constraint != null) {
- mFilterResult = new String(constraint.toString());
+ mFilterResult = constraint.toString();
}
return null;
}
@@ -899,8 +1026,7 @@
}
}
- private class MockAdapter<T> extends ArrayAdapter implements Filterable {
-
+ private static class MockAdapter<T> extends ArrayAdapter<T> implements Filterable {
private MockFilter mFilter;
public MockAdapter(Context context, int textViewResourceId, T[] objects) {
diff --git a/tests/tests/widget/src/android/widget/cts/ChronometerTest.java b/tests/tests/widget/src/android/widget/cts/ChronometerTest.java
index 0e9fbb7..5f16592 100644
--- a/tests/tests/widget/src/android/widget/cts/ChronometerTest.java
+++ b/tests/tests/widget/src/android/widget/cts/ChronometerTest.java
@@ -16,17 +16,15 @@
package android.widget.cts;
-import android.content.Context;
+import dalvik.annotation.TestLevel;
+import dalvik.annotation.TestTargetClass;
+import dalvik.annotation.TestTargetNew;
+import dalvik.annotation.TestTargets;
+
import android.test.ActivityInstrumentationTestCase2;
import android.test.UiThreadTest;
-import android.util.AttributeSet;
-import android.view.View;
import android.widget.Chronometer;
-import dalvik.annotation.TestTargets;
-import dalvik.annotation.TestLevel;
-import dalvik.annotation.TestTargetNew;
-import dalvik.annotation.TestTargetClass;
-import dalvik.annotation.ToBeFixed;
+import android.widget.Chronometer.OnChronometerTickListener;
/**
* Test {@link Chronometer}.
@@ -34,8 +32,6 @@
@TestTargetClass(Chronometer.class)
public class ChronometerTest extends ActivityInstrumentationTestCase2<ChronometerStubActivity> {
private ChronometerStubActivity mActivity;
- private Context mContext;
-
public ChronometerTest() {
super("com.android.cts.stub", ChronometerStubActivity.class);
}
@@ -44,47 +40,41 @@
protected void setUp() throws Exception {
super.setUp();
mActivity = getActivity();
- mContext = getInstrumentation().getContext();
}
@TestTargets({
@TestTargetNew(
level = TestLevel.COMPLETE,
- notes = "Test {@link Chronometer#Chronometer(Context)}.",
method = "Chronometer",
args = {android.content.Context.class}
),
@TestTargetNew(
level = TestLevel.COMPLETE,
- notes = "Test {@link Chronometer#Chronometer(Context)}.",
method = "Chronometer",
args = {android.content.Context.class, android.util.AttributeSet.class}
),
@TestTargetNew(
level = TestLevel.COMPLETE,
- notes = "Test {@link Chronometer#Chronometer(Context)}.",
method = "Chronometer",
args = {android.content.Context.class, android.util.AttributeSet.class, int.class}
)
})
public void testConstructor() {
- new Chronometer(mContext);
+ new Chronometer(mActivity);
- new Chronometer(mContext, null);
+ new Chronometer(mActivity, null);
- new Chronometer(mContext, null, 0);
+ new Chronometer(mActivity, null, 0);
}
@TestTargets({
@TestTargetNew(
level = TestLevel.COMPLETE,
- notes = "Test getBase() and setBase(long)",
method = "getBase",
args = {}
),
@TestTargetNew(
level = TestLevel.COMPLETE,
- notes = "Test getBase() and setBase(long)",
method = "setBase",
args = {long.class}
)
@@ -121,13 +111,11 @@
@TestTargets({
@TestTargetNew(
level = TestLevel.COMPLETE,
- notes = "Test getFormat() and setFormat(string)",
method = "getFormat",
args = {}
),
@TestTargetNew(
level = TestLevel.COMPLETE,
- notes = "Test getFormat() and setFormat(string)",
method = "setFormat",
args = {java.lang.String.class}
)
@@ -146,81 +134,43 @@
assertTrue(text.endsWith("trail"));
}
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "Test onDetachedFromWindow()",
- method = "onDetachedFromWindow",
- args = {}
- )
- @ToBeFixed(bug = "1386429", explanation = "The method onDetachedFromWindow() "
- + "will set the private variable mVisible as true, but no method to get "
- + "this value.")
- @UiThreadTest
- public void testOnDetachedFromWindow() {
- MockChronometer mockChronometer = new MockChronometer(mContext);
-
- // only when both visible and the start are true, the text will be updated.
- // so in this time the visible is true.
- mockChronometer.onWindowVisibilityChanged(View.VISIBLE);
- CharSequence oldText = mockChronometer.getText();
- mockChronometer.start();
- CharSequence newText = mockChronometer.getText();
- assertNotSame(oldText, newText);
- oldText = newText;
-
- // then the visible is false, so the text won't be updated.
- mockChronometer.onDetachedFromWindow();
- newText = mockChronometer.getText();
- assertSame(oldText, newText);
- }
-
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "Test onWindowVisibilityChanged(int)",
- method = "onWindowVisibilityChanged",
- args = {int.class}
- )
- @ToBeFixed(bug = "1386429", explanation = "The method onDetachedFromWindow() "
- + "will set the private variable mVisible according the visibility "
- + "been set, but I can't get this value.")
- public void testOnWindowVisibilityChanged() {
- MockChronometer mockChronometer = new MockChronometer(mContext);
-
- mockChronometer.start();
-
- CharSequence oldText = mockChronometer.getText();
- mockChronometer.onWindowVisibilityChanged(View.INVISIBLE);
- CharSequence newText = mockChronometer.getText();
- assertSame(oldText, newText);
-
- oldText = mockChronometer.getText();
- // only when both visible and the start are true, the text will be updated.
- mockChronometer.onWindowVisibilityChanged(View.VISIBLE);
- newText = mockChronometer.getText();
- assertNotSame(oldText, newText);
+ @TestTargets({
+ @TestTargetNew(
+ level = TestLevel.NOT_NECESSARY,
+ method = "onWindowVisibilityChanged",
+ args = {int.class}
+ ),
+ @TestTargetNew(
+ level = TestLevel.NOT_NECESSARY,
+ method = "onDetachedFromWindow",
+ args = {}
+ )
+ })
+ public void testFoo() {
+ // Do not test these APIs. They are callbacks which:
+ // 1. The callback machanism has been tested in super class
+ // 2. The functionality is implmentation details, no need to test
}
@TestTargets({
@TestTargetNew(
level = TestLevel.COMPLETE,
- notes = "Test start() and stop()",
method = "start",
args = {}
),
@TestTargetNew(
level = TestLevel.COMPLETE,
- notes = "Test start() and stop()",
method = "stop",
args = {}
)
})
- public void testStartAndStop() {
+ public void testStartAndStop() throws Throwable {
final Chronometer chronometer = mActivity.getChronometer();
// we will check the text is really updated every 1000ms after start,
// so we need sleep a moment to wait wait this time. The sleep code shouldn't
// in the same thread with UI, that's why we use runOnMainSync here.
- getInstrumentation().runOnMainSync(new Runnable() {
+ runTestOnUiThread(new Runnable() {
public void run() {
// the text will update immediately when call start.
CharSequence expected = chronometer.getText();
@@ -230,17 +180,13 @@
});
getInstrumentation().waitForIdleSync();
CharSequence expected = chronometer.getText();
- try {
- Thread.sleep(1500);
- } catch (InterruptedException e) {
- e.printStackTrace();
- }
+ Thread.sleep(1500);
assertFalse(expected.equals(chronometer.getText()));
// we will check the text is really NOT updated anymore every 1000ms after stop,
// so we need sleep a moment to wait wait this time. The sleep code shouldn't
// in the same thread with UI, that's why we use runOnMainSync here.
- getInstrumentation().runOnMainSync(new Runnable() {
+ runTestOnUiThread(new Runnable() {
public void run() {
// the text will never be updated when call stop.
CharSequence expected = chronometer.getText();
@@ -250,38 +196,53 @@
});
getInstrumentation().waitForIdleSync();
expected = chronometer.getText();
- try {
- Thread.sleep(1500);
- } catch (InterruptedException e) {
- e.printStackTrace();
- }
+ Thread.sleep(1500);
assertTrue(expected.equals(chronometer.getText()));
}
- private class MockChronometer extends Chronometer {
- boolean mCalledOnDetachedFromWindow = false;
+ @TestTargets({
+ @TestTargetNew(
+ level = TestLevel.COMPLETE,
+ method = "getOnChronometerTickListener",
+ args = {}
+ ),
+ @TestTargetNew(
+ level = TestLevel.COMPLETE,
+ method = "setOnChronometerTickListener",
+ args = {OnChronometerTickListener.class}
+ )
+ })
+ public void testAccessOnChronometerTickListener() throws Throwable {
+ final Chronometer chronometer = mActivity.getChronometer();
+ final MockOnChronometerTickListener listener = new MockOnChronometerTickListener();
- public MockChronometer(Context context) {
- super(context);
+ runTestOnUiThread(new Runnable() {
+ public void run() {
+ chronometer.setOnChronometerTickListener(listener);
+ chronometer.start();
+ }
+ });
+ getInstrumentation().waitForIdleSync();
+ assertEquals(listener, chronometer.getOnChronometerTickListener());
+ assertTrue(listener.hasCalledOnChronometerTick());
+ listener.reset();
+ Thread.sleep(1500);
+ assertTrue(listener.hasCalledOnChronometerTick());
+ }
+
+ private static class MockOnChronometerTickListener implements OnChronometerTickListener {
+ private boolean mCalledOnChronometerTick = false;
+
+ public void onChronometerTick(Chronometer chronometer) {
+ mCalledOnChronometerTick = true;
}
- @Override
- protected void onDetachedFromWindow() {
- super.onDetachedFromWindow();
- mCalledOnDetachedFromWindow = false;
- }
-
- @Override
- protected void onWindowVisibilityChanged(int visibility) {
- super.onWindowVisibilityChanged(visibility);
+ public boolean hasCalledOnChronometerTick() {
+ return mCalledOnChronometerTick;
}
public void reset() {
- mCalledOnDetachedFromWindow =false;
- }
-
- public boolean hasCalledOnDetachedFromWindow() {
- return mCalledOnDetachedFromWindow;
+ mCalledOnChronometerTick = false;
}
}
}
diff --git a/tests/tests/widget/src/android/widget/cts/CompoundButtonTest.java b/tests/tests/widget/src/android/widget/cts/CompoundButtonTest.java
index 9b20386..27c967d 100644
--- a/tests/tests/widget/src/android/widget/cts/CompoundButtonTest.java
+++ b/tests/tests/widget/src/android/widget/cts/CompoundButtonTest.java
@@ -16,6 +16,14 @@
package android.widget.cts;
+import com.android.cts.stub.R;
+
+import dalvik.annotation.TestLevel;
+import dalvik.annotation.TestTargetClass;
+import dalvik.annotation.TestTargetNew;
+import dalvik.annotation.TestTargets;
+import dalvik.annotation.ToBeFixed;
+
import org.xmlpull.v1.XmlPullParser;
import android.content.Context;
@@ -34,14 +42,6 @@
import android.widget.CompoundButton;
import android.widget.CompoundButton.OnCheckedChangeListener;
-import com.android.cts.stub.R;
-
-import dalvik.annotation.TestTargets;
-import dalvik.annotation.TestLevel;
-import dalvik.annotation.TestTargetNew;
-import dalvik.annotation.TestTargetClass;
-import dalvik.annotation.ToBeFixed;
-
/**
* Test {@link CompoundButton}.
*/
@@ -410,6 +410,23 @@
assertTrue(compoundButton.isLayoutRequested());
}
+ @TestTargetNew(
+ level = TestLevel.COMPLETE,
+ method = "verifyDrawable",
+ args = {android.graphics.drawable.Drawable.class}
+ )
+ public void testVerifyDrawable() {
+ MockCompoundButton compoundButton = new MockCompoundButton(mContext);
+ Drawable drawable = mContext.getResources().getDrawable(R.drawable.scenery);
+
+ assertTrue(compoundButton.verifyDrawable(null));
+ assertFalse(compoundButton.verifyDrawable(drawable));
+
+ compoundButton.setButtonDrawable(drawable);
+ assertTrue(compoundButton.verifyDrawable(null));
+ assertTrue(compoundButton.verifyDrawable(drawable));
+ }
+
private final class MockCompoundButton extends CompoundButton {
public MockCompoundButton(Context context) {
super(context);
@@ -437,6 +454,11 @@
protected int[] onCreateDrawableState(int extraSpace) {
return super.onCreateDrawableState(extraSpace);
}
+
+ @Override
+ protected boolean verifyDrawable(Drawable who) {
+ return super.verifyDrawable(who);
+ }
}
private final class MockOnCheckedChangeListener implements OnCheckedChangeListener {
diff --git a/tests/tests/widget/src/android/widget/cts/CursorAdapterTest.java b/tests/tests/widget/src/android/widget/cts/CursorAdapterTest.java
index 4c809dc..1798a84 100644
--- a/tests/tests/widget/src/android/widget/cts/CursorAdapterTest.java
+++ b/tests/tests/widget/src/android/widget/cts/CursorAdapterTest.java
@@ -23,10 +23,13 @@
import android.database.Cursor;
import android.database.DataSetObserver;
import android.database.sqlite.SQLiteDatabase;
+import android.os.Looper;
+import android.os.cts.TestThread;
import android.test.AndroidTestCase;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
+import android.view.animation.cts.DelayedCheck;
import android.widget.CursorAdapter;
import android.widget.Filter;
import android.widget.FilterQueryProvider;
@@ -44,6 +47,7 @@
*/
@TestTargetClass(CursorAdapter.class)
public class CursorAdapterTest extends AndroidTestCase {
+ private static final long TEST_TIME_OUT = 5000;
private static final int NUMBER_INDEX = 1;
private static final String FIRST_NUMBER = "123";
private static final String SECOND_NUMBER = "5555";
@@ -57,6 +61,7 @@
private File mDatabaseFile;
private Cursor mCursor;
private ViewGroup mParent;
+ private MockCursorAdapter mMockCursorAdapter;
@Override
protected void setUp() throws Exception {
@@ -270,7 +275,7 @@
level = TestLevel.COMPLETE,
notes = "Test {@link CursorAdapter#newDropDownView(Context, Cursor, ViewGroup)}",
method = "newDropDownView",
- args = {android.content.Context.class, android.database.Cursor.class,
+ args = {android.content.Context.class, android.database.Cursor.class,
android.view.ViewGroup.class}
)
public void testNewDropDownView() {
@@ -406,7 +411,33 @@
assertNull(cursorAdapter.runQueryOnBackgroundThread(constraint));
}
+ @TestTargetNew(
+ level = TestLevel.COMPLETE,
+ method = "onContentChanged",
+ args = {}
+ )
+ public void testOnContentChanged() throws Throwable {
+ TestThread testThread = new TestThread(new Runnable() {
+ public void run() {
+ Looper.prepare();
+ mMockCursorAdapter = new MockCursorAdapter(mContext, mCursor);
+ }
+ });
+ testThread.runTest(TEST_TIME_OUT);
+ assertFalse(mMockCursorAdapter.hasContentChanged());
+ // insert a new row
+ mDatabase.execSQL("INSERT INTO test (number) VALUES ('" + FIRST_NUMBER + "');");
+ new DelayedCheck(TEST_TIME_OUT) {
+ @Override
+ protected boolean check() {
+ return mMockCursorAdapter.hasContentChanged();
+ }
+ };
+ }
+
private final class MockCursorAdapter extends CursorAdapter {
+ private boolean mContentChanged = false;
+
public MockCursorAdapter(Context context, Cursor c) {
super(context, c);
}
@@ -471,6 +502,16 @@
}
return null;
}
+
+ @Override
+ protected void onContentChanged() {
+ super.onContentChanged();
+ mContentChanged = true;
+ }
+
+ public boolean hasContentChanged() {
+ return mContentChanged;
+ }
}
private final class MockFilterQueryProvider implements FilterQueryProvider {
diff --git a/tests/tests/widget/src/android/widget/cts/LinearLayout_LayoutParamsTest.java b/tests/tests/widget/src/android/widget/cts/LinearLayout_LayoutParamsTest.java
index 24f84aa..4b6257a 100644
--- a/tests/tests/widget/src/android/widget/cts/LinearLayout_LayoutParamsTest.java
+++ b/tests/tests/widget/src/android/widget/cts/LinearLayout_LayoutParamsTest.java
@@ -16,26 +16,23 @@
package android.widget.cts;
-import java.io.IOException;
+import com.android.cts.stub.R;
+import com.android.internal.util.XmlUtils;
+
+import dalvik.annotation.TestLevel;
+import dalvik.annotation.TestTargetClass;
+import dalvik.annotation.TestTargetNew;
+import dalvik.annotation.TestTargets;
import org.xmlpull.v1.XmlPullParserException;
-import android.content.Context;
import android.content.res.XmlResourceParser;
import android.test.AndroidTestCase;
-import android.util.AttributeSet;
-import android.view.ViewGroup;
import android.view.ViewGroup.LayoutParams;
import android.view.ViewGroup.MarginLayoutParams;
import android.widget.LinearLayout;
-import com.android.cts.stub.R;
-import com.android.internal.util.XmlUtils;
-
-import dalvik.annotation.TestTargets;
-import dalvik.annotation.TestTargetNew;
-import dalvik.annotation.TestLevel;
-import dalvik.annotation.TestTargetClass;
+import java.io.IOException;
@TestTargetClass(LinearLayout.LayoutParams.class)
public class LinearLayout_LayoutParamsTest extends AndroidTestCase {
@@ -87,4 +84,14 @@
MarginLayoutParams marginLayoutParams = new MarginLayoutParams(320, 480);
new LinearLayout.LayoutParams(marginLayoutParams);
}
+
+ @TestTargetNew(
+ level = TestLevel.COMPLETE,
+ method = "debug",
+ args = {java.lang.String.class}
+ )
+ public void testDebug() {
+ LinearLayout.LayoutParams layoutParams = new LinearLayout.LayoutParams(320, 240);
+ assertNotNull(layoutParams.debug("test: "));
+ }
}
diff --git a/tests/tests/widget/src/android/widget/cts/PopupWindowTest.java b/tests/tests/widget/src/android/widget/cts/PopupWindowTest.java
index 7a6da3b..7f65a2e 100644
--- a/tests/tests/widget/src/android/widget/cts/PopupWindowTest.java
+++ b/tests/tests/widget/src/android/widget/cts/PopupWindowTest.java
@@ -16,15 +16,22 @@
package android.widget.cts;
+import com.android.cts.stub.R;
+
+import dalvik.annotation.TestLevel;
+import dalvik.annotation.TestTargetClass;
+import dalvik.annotation.TestTargetNew;
+import dalvik.annotation.TestTargets;
+import dalvik.annotation.ToBeFixed;
+
import android.app.Activity;
import android.app.Instrumentation;
import android.content.Context;
import android.graphics.Color;
import android.graphics.drawable.ColorDrawable;
import android.graphics.drawable.Drawable;
+import android.os.SystemClock;
import android.test.ActivityInstrumentationTestCase2;
-import android.test.TouchUtils;
-import android.util.AttributeSet;
import android.view.Display;
import android.view.Gravity;
import android.view.MotionEvent;
@@ -38,15 +45,6 @@
import android.widget.TextView;
import android.widget.PopupWindow.OnDismissListener;
-import com.android.cts.stub.R;
-
-import dalvik.annotation.BrokenTest;
-import dalvik.annotation.TestTargets;
-import dalvik.annotation.TestTargetNew;
-import dalvik.annotation.TestLevel;
-import dalvik.annotation.TestTargetClass;
-import dalvik.annotation.ToBeFixed;
-
@TestTargetClass(PopupWindow.class)
public class PopupWindowTest extends
ActivityInstrumentationTestCase2<MockPopupWindowStubActivity> {
@@ -77,54 +75,52 @@
@TestTargets({
@TestTargetNew(
level = TestLevel.COMPLETE,
- notes = "Test constructor(s) of {@link PopupWindow}",
method = "PopupWindow",
args = {}
),
@TestTargetNew(
level = TestLevel.COMPLETE,
- notes = "Test constructor(s) of {@link PopupWindow}",
method = "PopupWindow",
args = {android.content.Context.class}
),
@TestTargetNew(
level = TestLevel.COMPLETE,
- notes = "Test constructor(s) of {@link PopupWindow}",
method = "PopupWindow",
args = {android.content.Context.class, android.util.AttributeSet.class}
),
@TestTargetNew(
level = TestLevel.COMPLETE,
- notes = "Test constructor(s) of {@link PopupWindow}",
method = "PopupWindow",
args = {android.content.Context.class, android.util.AttributeSet.class, int.class}
),
@TestTargetNew(
level = TestLevel.COMPLETE,
- notes = "Test constructor(s) of {@link PopupWindow}",
method = "PopupWindow",
args = {int.class, int.class}
),
@TestTargetNew(
level = TestLevel.COMPLETE,
- notes = "Test constructor(s) of {@link PopupWindow}",
method = "PopupWindow",
args = {android.view.View.class}
),
@TestTargetNew(
level = TestLevel.COMPLETE,
- notes = "Test constructor(s) of {@link PopupWindow}",
method = "PopupWindow",
args = {android.view.View.class, int.class, int.class}
),
@TestTargetNew(
level = TestLevel.COMPLETE,
- notes = "Test constructor(s) of {@link PopupWindow}",
method = "PopupWindow",
args = {android.view.View.class, int.class, int.class, boolean.class}
+ ),
+ @TestTargetNew(
+ level = TestLevel.COMPLETE,
+ method = "getContentView",
+ args = {}
)
})
- @ToBeFixed( bug = "1417734", explanation = "NullPointerException issue")
+ @ToBeFixed(bug = "1695243", explanation = "the javadoc for constructor is incomplete." +
+ "1. not clear what is supposed to happen when the LayoutParam is null.")
public void testConstructor() {
new PopupWindow(mActivity);
@@ -307,13 +303,11 @@
@TestTargets({
@TestTargetNew(
level = TestLevel.COMPLETE,
- notes = "Test {@link PopupWindow#getHeight()} and {@link PopupWindow#setHeight(int)}",
method = "setHeight",
args = {int.class}
),
@TestTargetNew(
level = TestLevel.COMPLETE,
- notes = "Test {@link PopupWindow#getHeight()} and {@link PopupWindow#setHeight(int)}",
method = "getHeight",
args = {}
)
@@ -356,13 +350,11 @@
@TestTargets({
@TestTargetNew(
level = TestLevel.COMPLETE,
- notes = "Test {@link PopupWindow#setWidth(int)} and {@link PopupWindow#getWidth()}",
method = "setWidth",
args = {int.class}
),
@TestTargetNew(
level = TestLevel.COMPLETE,
- notes = "Test {@link PopupWindow#setWidth(int)} and {@link PopupWindow#getWidth()}",
method = "getWidth",
args = {}
)
@@ -393,7 +385,6 @@
@TestTargetNew(
level = TestLevel.COMPLETE,
- notes = "Test {@link PopupWindow#showAsDropDown(View)}",
method = "showAsDropDown",
args = {android.view.View.class}
)
@@ -425,7 +416,6 @@
@TestTargetNew(
level = TestLevel.COMPLETE,
- notes = "Test {@link PopupWindow#showAtLocation(View, int, int, int)}",
method = "showAtLocation",
args = {android.view.View.class, int.class, int.class, int.class}
)
@@ -463,7 +453,6 @@
@TestTargetNew(
level = TestLevel.COMPLETE,
- notes = "Test {@link PopupWindow#showAsDropDown(View, int, int)}",
method = "showAsDropDown",
args = {android.view.View.class, int.class, int.class}
)
@@ -495,12 +484,18 @@
dismissPopup();
}
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "Test {@link PopupWindow#getMaxAvailableHeight(View)}",
- method = "getMaxAvailableHeight",
- args = {android.view.View.class}
- )
+ @TestTargets({
+ @TestTargetNew(
+ level = TestLevel.COMPLETE,
+ method = "getMaxAvailableHeight",
+ args = {android.view.View.class}
+ ),
+ @TestTargetNew(
+ level = TestLevel.COMPLETE,
+ method = "getMaxAvailableHeight",
+ args = {android.view.View.class, int.class}
+ )
+ })
public void testGetMaxAvailableHeight() {
mPopupWindow = createPopupWindow(createPopupContent());
@@ -509,6 +504,19 @@
int maxAvailableHeight = mPopupWindow.getMaxAvailableHeight(anchorView);
assertTrue(maxAvailableHeight > 0);
assertTrue(maxAvailableHeight <= avaliable);
+ int maxAvailableHeightWithOffset = mPopupWindow.getMaxAvailableHeight(anchorView, 2);
+ assertEquals(maxAvailableHeight - 2, maxAvailableHeightWithOffset);
+ maxAvailableHeightWithOffset =
+ mPopupWindow.getMaxAvailableHeight(anchorView, maxAvailableHeight);
+ assertTrue(maxAvailableHeightWithOffset > 0);
+ assertTrue(maxAvailableHeightWithOffset <= avaliable);
+ maxAvailableHeightWithOffset =
+ mPopupWindow.getMaxAvailableHeight(anchorView, maxAvailableHeight / 2 - 1);
+ assertTrue(maxAvailableHeightWithOffset > 0);
+ assertTrue(maxAvailableHeightWithOffset <= avaliable);
+ maxAvailableHeightWithOffset = mPopupWindow.getMaxAvailableHeight(anchorView, -1);
+ assertTrue(maxAvailableHeightWithOffset > 0);
+ assertTrue(maxAvailableHeightWithOffset <= avaliable);
anchorView = mActivity.findViewById(R.id.anchor_lower);
avaliable = getDisplay().getHeight() - anchorView.getHeight();
@@ -526,7 +534,6 @@
@TestTargetNew(
level = TestLevel.COMPLETE,
- notes = "Test {@link PopupWindow#dismiss()}",
method = "dismiss",
args = {}
)
@@ -545,7 +552,6 @@
@TestTargetNew(
level = TestLevel.COMPLETE,
- notes = "Test {@link PopupWindow#setOnDismissListener(OnDismissListener)}",
method = "setOnDismissListener",
args = {android.widget.PopupWindow.OnDismissListener.class}
)
@@ -586,7 +592,6 @@
args = {}
)
})
- @BrokenTest("showPopup() has the problem of window leakage. Disable this test.")
public void testUpdate() {
mPopupWindow = createPopupWindow(createPopupContent());
mPopupWindow.setBackgroundDrawable(null);
@@ -597,6 +602,7 @@
mPopupWindow.setTouchable(false);
mPopupWindow.setInputMethodMode(PopupWindow.INPUT_METHOD_NOT_NEEDED);
mPopupWindow.setClippingEnabled(false);
+ mPopupWindow.setOutsideTouchable(true);
WindowManager.LayoutParams p = (WindowManager.LayoutParams)
mPopupWindow.getContentView().getLayoutParams();
@@ -605,8 +611,7 @@
assertEquals(WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE,
WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE & p.flags);
assertEquals(0, WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE & p.flags);
- assertEquals(WindowManager.LayoutParams.FLAG_WATCH_OUTSIDE_TOUCH,
- WindowManager.LayoutParams.FLAG_WATCH_OUTSIDE_TOUCH & p.flags);
+ assertEquals(0, WindowManager.LayoutParams.FLAG_WATCH_OUTSIDE_TOUCH & p.flags);
assertEquals(0, WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS & p.flags);
assertEquals(0, WindowManager.LayoutParams.FLAG_ALT_FOCUSABLE_IM & p.flags);
@@ -622,7 +627,8 @@
assertEquals(0, WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE & p.flags);
assertEquals(WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE,
WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE & p.flags);
- assertEquals(0, WindowManager.LayoutParams.FLAG_WATCH_OUTSIDE_TOUCH & p.flags);
+ assertEquals(WindowManager.LayoutParams.FLAG_WATCH_OUTSIDE_TOUCH,
+ WindowManager.LayoutParams.FLAG_WATCH_OUTSIDE_TOUCH & p.flags);
assertEquals(WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS,
WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS & p.flags);
assertEquals(WindowManager.LayoutParams.FLAG_ALT_FOCUSABLE_IM,
@@ -637,6 +643,11 @@
),
@TestTargetNew(
level = TestLevel.COMPLETE,
+ method = "update",
+ args = {int.class, int.class, int.class, int.class, boolean.class}
+ ),
+ @TestTargetNew(
+ level = TestLevel.COMPLETE,
method = "isShowing",
args = {}
)
@@ -674,7 +685,7 @@
// ignore if width or height is -1
mInstrumentation.runOnMainSync(new Runnable() {
public void run() {
- mPopupWindow.update(4, 0, -1, -1);
+ mPopupWindow.update(4, 0, -1, -1, true);
}
});
mInstrumentation.waitForIdleSync();
@@ -693,13 +704,11 @@
@TestTargets({
@TestTargetNew(
level = TestLevel.COMPLETE,
- notes = "Test {@link PopupWindow#update(View, int, int)} and PopupWindow#isShowing()}",
method = "update",
args = {android.view.View.class, int.class, int.class}
),
@TestTargetNew(
level = TestLevel.COMPLETE,
- notes = "Test {@link PopupWindow#update(View, int, int)} and PopupWindow#isShowing()}",
method = "isShowing",
args = {}
)
@@ -743,8 +752,6 @@
args = {}
)
})
- @ToBeFixed(bug="", explanation="can not update the position of popup window" +
- "when the new width and height both equal the old or -1.")
public void testUpdateDimentionAndAlignAnchorViewWithOffsets() {
int[] AnchorXY = new int[2];
int[] viewInWindowOff = new int[2];
@@ -909,7 +916,6 @@
@TestTargetNew(
level = TestLevel.COMPLETE,
- notes = "Test {@link PopupWindow#isAboveAnchor()}",
method = "isAboveAnchor",
args = {}
)
@@ -941,37 +947,50 @@
@TestTargetNew(
level = TestLevel.COMPLETE,
- notes = "Test {@link PopupWindow#setTouchInterceptor(OnTouchListener)}",
method = "setTouchInterceptor",
args = {android.view.View.OnTouchListener.class}
)
- @BrokenTest("showPopup() has the problem of window leakage. Disable this test.")
public void testSetTouchInterceptor() {
mPopupWindow = new PopupWindow(new TextView(mActivity));
MockOnTouchListener onTouchListener = new MockOnTouchListener();
mPopupWindow.setTouchInterceptor(onTouchListener);
+ mPopupWindow.setFocusable(true);
+ mPopupWindow.setOutsideTouchable(true);
Drawable drawable = new ColorDrawable();
mPopupWindow.setBackgroundDrawable(drawable);
showPopup();
- TouchUtils.tapView(this, mPopupWindow.getContentView());
- mInstrumentation.waitForIdleSync();
+ int[] xy = new int[2];
+ mPopupWindow.getContentView().getLocationOnScreen(xy);
+ final int viewWidth = mPopupWindow.getContentView().getWidth();
+ final int viewHeight = mPopupWindow.getContentView().getHeight();
+ final float x = xy[0] + (viewWidth / 2.0f);
+ float y = xy[1] + (viewHeight / 2.0f);
+
+ long downTime = SystemClock.uptimeMillis();
+ long eventTime = SystemClock.uptimeMillis();
+ MotionEvent event = MotionEvent.obtain(downTime, eventTime,
+ MotionEvent.ACTION_DOWN, x, y, 0);
+ getInstrumentation().sendPointerSync(event);
assertEquals(1, onTouchListener.getOnTouchCalledCount());
- TouchUtils.tapView(this, mPopupWindow.getContentView());
- mInstrumentation.waitForIdleSync();
+ downTime = SystemClock.uptimeMillis();
+ eventTime = SystemClock.uptimeMillis();
+ event = MotionEvent.obtain(downTime, eventTime, MotionEvent.ACTION_UP, x, y, 0);
+ getInstrumentation().sendPointerSync(event);
assertEquals(2, onTouchListener.getOnTouchCalledCount());
mPopupWindow.setTouchInterceptor(null);
- TouchUtils.tapView(this, mPopupWindow.getContentView());
- mInstrumentation.waitForIdleSync();
+ downTime = SystemClock.uptimeMillis();
+ eventTime = SystemClock.uptimeMillis();
+ event = MotionEvent.obtain(downTime, eventTime, MotionEvent.ACTION_DOWN, x, y, 0);
+ getInstrumentation().sendPointerSync(event);
assertEquals(2, onTouchListener.getOnTouchCalledCount());
}
@TestTargetNew(
level = TestLevel.COMPLETE,
- notes = "Test {@link PopupWindow#setWindowLayoutMode(int, int)}",
method = "setWindowLayoutMode",
args = {int.class, int.class}
)
@@ -1002,7 +1021,7 @@
* the OnDismiss event occurs, that object's appropriate
* method is invoked.
*/
- private class MockOnDismissListener implements OnDismissListener {
+ private static class MockOnDismissListener implements OnDismissListener {
/** The Ondismiss called count. */
private int mOnDismissCalledCount;
@@ -1030,7 +1049,7 @@
/**
* The listener interface for receiving touch events.
*/
- private class MockOnTouchListener implements OnTouchListener {
+ private static class MockOnTouchListener implements OnTouchListener {
/** The onTouch called count. */
private int mOnTouchCalledCount;
@@ -1080,6 +1099,8 @@
/**
* Show PopupWindow.
*/
+ // FIXME: logcat info complains that there is window leakage due to that mPopupWindow is not
+ // clean up. Need to fix it.
private void showPopup() {
mInstrumentation.runOnMainSync(new Runnable() {
public void run() {
diff --git a/tests/tests/widget/src/android/widget/cts/RadioGroupTest.java b/tests/tests/widget/src/android/widget/cts/RadioGroupTest.java
index 648c1d6..fa2dd7d 100644
--- a/tests/tests/widget/src/android/widget/cts/RadioGroupTest.java
+++ b/tests/tests/widget/src/android/widget/cts/RadioGroupTest.java
@@ -18,10 +18,10 @@
import com.android.cts.stub.R;
-import dalvik.annotation.TestTargets;
import dalvik.annotation.TestLevel;
-import dalvik.annotation.TestTargetNew;
import dalvik.annotation.TestTargetClass;
+import dalvik.annotation.TestTargetNew;
+import dalvik.annotation.TestTargets;
import dalvik.annotation.ToBeFixed;
import org.xmlpull.v1.XmlPullParser;
@@ -144,7 +144,7 @@
RadioGroup.LayoutParams.WRAP_CONTENT, RadioGroup.LayoutParams.WRAP_CONTENT));
// set the id with hashCode
// (PassThroughHierarchyChangeListener's behaviour when button is added)
- assertTrue(newButton.getId() != View.NO_ID);
+ assertEquals(newButton.hashCode(), newButton.getId());
}
@TestTargetNew(
@@ -469,6 +469,26 @@
assertFalse(button.isChecked());
}
+ @TestTargetNew(
+ level = TestLevel.COMPLETE,
+ method = "addView",
+ args = {android.view.View.class, int.class, android.view.ViewGroup.LayoutParams.class}
+ )
+ public void testAddView() {
+ mDefaultRadioGroup.check(BUTTON_ID_0);
+ assertEquals(BUTTON_ID_0, mDefaultRadioGroup.getCheckedRadioButtonId());
+ assertEquals(4, mDefaultRadioGroup.getChildCount());
+
+ int id = BUTTON_ID_3 + 10;
+ RadioButton choice4 = new RadioButton(mContext);
+ choice4.setText("choice4");
+ choice4.setId(id);
+ choice4.setChecked(true);
+ mDefaultRadioGroup.addView(choice4, 4, new ViewGroup.LayoutParams(100, 200));
+ assertEquals(id, mDefaultRadioGroup.getCheckedRadioButtonId());
+ assertEquals(5, mDefaultRadioGroup.getChildCount());
+ }
+
/**
* Initialises the group with 4 RadioButtons which IDs are
* BUTTON_ID_0, BUTTON_ID_1, BUTTON_ID_2, BUTTON_ID_3.
diff --git a/tests/tests/widget/src/android/widget/cts/ResourceCursorAdapterTest.java b/tests/tests/widget/src/android/widget/cts/ResourceCursorAdapterTest.java
index e9f716b..6f87c61 100644
--- a/tests/tests/widget/src/android/widget/cts/ResourceCursorAdapterTest.java
+++ b/tests/tests/widget/src/android/widget/cts/ResourceCursorAdapterTest.java
@@ -19,10 +19,10 @@
import com.android.cts.stub.R;
import com.android.internal.database.ArrayListCursor;
-import dalvik.annotation.TestTargets;
import dalvik.annotation.TestLevel;
-import dalvik.annotation.TestTargetNew;
import dalvik.annotation.TestTargetClass;
+import dalvik.annotation.TestTargetNew;
+import dalvik.annotation.TestTargets;
import android.content.Context;
import android.database.Cursor;
@@ -58,23 +58,53 @@
mCursor = createTestCursor(3, 3);
}
+ @TestTargets({
+ @TestTargetNew(
+ level = TestLevel.COMPLETE,
+ method = "ResourceCursorAdapter",
+ args = {Context.class, int.class, Cursor.class}
+ ),
+ @TestTargetNew(
+ level = TestLevel.COMPLETE,
+ method = "ResourceCursorAdapter",
+ args = {Context.class, int.class, Cursor.class, boolean.class}
+ )
+ })
+ public void testConstructor() {
+ MockResourceCursorAdapter adapter = new MockResourceCursorAdapter(mContext, -1, null);
+ // the default is true
+ assertTrue(adapter.isAutoRequery());
+ assertNull(adapter.getCursor());
+
+ adapter = new MockResourceCursorAdapter(mContext, R.layout.cursoradapter_item0, mCursor);
+ // the default is true
+ assertTrue(adapter.isAutoRequery());
+ assertSame(mCursor, adapter.getCursor());
+
+ adapter = new MockResourceCursorAdapter(mContext,
+ R.layout.cursoradapter_item0, mCursor, false);
+ assertFalse(adapter.isAutoRequery());
+ assertSame(mCursor, adapter.getCursor());
+ }
+
@TestTargetNew(
level = TestLevel.COMPLETE,
- notes = "Test constructor",
- method = "ResourceCursorAdapter",
- args = {android.content.Context.class, int.class, android.database.Cursor.class}
+ method = "setViewResource",
+ args = {int.class}
)
- public void testConstructor() {
- mResourceCursorAdapter = new MockResourceCursorAdapter(mContext, -1, null);
- // the default is true
- assertEquals(true, ((MockResourceCursorAdapter)mResourceCursorAdapter).isAutoRequery());
- assertNull(mResourceCursorAdapter.getCursor());
-
+ public void testSetViewResource() {
mResourceCursorAdapter = new MockResourceCursorAdapter(mContext,
R.layout.cursoradapter_item0, mCursor);
- // the default is true
- assertEquals(true, ((MockResourceCursorAdapter)mResourceCursorAdapter).isAutoRequery());
- assertEquals(mCursor, mResourceCursorAdapter.getCursor());
+
+ View result = mResourceCursorAdapter.newView(null, null, mParent);
+ assertNotNull(result);
+ assertEquals(R.id.cursorAdapter_item0, result.getId());
+
+ // set the new view resource
+ mResourceCursorAdapter.setViewResource(R.layout.cursoradapter_item1);
+ result = mResourceCursorAdapter.newView(null, null, mParent);
+ assertNotNull(result);
+ assertEquals(R.id.cursorAdapter_item1, result.getId());
}
@TestTargetNew(
@@ -109,8 +139,7 @@
@TestTargetNew(
level = TestLevel.COMPLETE,
method = "newDropDownView",
- args = {android.content.Context.class, android.database.Cursor.class,
- android.view.ViewGroup.class}
+ args = {Context.class, Cursor.class, ViewGroup.class}
)
// parameters Context and Cursor are never readin the method
public void testNewDropDownView() {
@@ -130,8 +159,7 @@
@TestTargetNew(
level = TestLevel.COMPLETE,
method = "newView",
- args = {android.content.Context.class, android.database.Cursor.class,
- android.view.ViewGroup.class}
+ args = {Context.class, Cursor.class, ViewGroup.class}
)
// The parameters Context and Cursor are never read in the method
public void testNewView() {
@@ -174,11 +202,16 @@
return new ArrayListCursor(columns, list);
}
- private class MockResourceCursorAdapter extends ResourceCursorAdapter {
+ private static class MockResourceCursorAdapter extends ResourceCursorAdapter {
public MockResourceCursorAdapter(Context context, int layout, Cursor c) {
super(context, layout, c);
}
+ public MockResourceCursorAdapter(Context context, int layout,
+ Cursor c, boolean autoRequery) {
+ super(context, layout, c, autoRequery);
+ }
+
@Override
public void bindView(View view, Context context, Cursor cursor) {
}
diff --git a/tests/tests/widget/src/android/widget/cts/ScrollerTest.java b/tests/tests/widget/src/android/widget/cts/ScrollerTest.java
index 1f4c160..dfd3c05 100644
--- a/tests/tests/widget/src/android/widget/cts/ScrollerTest.java
+++ b/tests/tests/widget/src/android/widget/cts/ScrollerTest.java
@@ -16,14 +16,13 @@
package android.widget.cts;
-import dalvik.annotation.TestTargets;
-import dalvik.annotation.TestTargetNew;
import dalvik.annotation.TestLevel;
import dalvik.annotation.TestTargetClass;
+import dalvik.annotation.TestTargetNew;
+import dalvik.annotation.TestTargets;
import android.content.Context;
import android.test.InstrumentationTestCase;
-import android.view.animation.Interpolator;
import android.view.animation.LinearInterpolator;
import android.widget.Scroller;
@@ -184,6 +183,16 @@
level = TestLevel.COMPLETE,
method = "getCurrY",
args = {}
+ ),
+ @TestTargetNew(
+ level = TestLevel.COMPLETE,
+ method = "getStartX",
+ args = {}
+ ),
+ @TestTargetNew(
+ level = TestLevel.COMPLETE,
+ method = "getStartY",
+ args = {}
)
})
// We can not get the precise currX and currY when scrolling
@@ -195,6 +204,8 @@
mScroller.startScroll(0, 0, 2000, -2000, 5000);
+ assertEquals(0, mScroller.getStartX());
+ assertEquals(0, mScroller.getStartY());
assertEquals(2000, mScroller.getFinalX());
assertEquals(-2000, mScroller.getFinalY());
assertEquals(5000, mScroller.getDuration());
@@ -269,6 +280,16 @@
level = TestLevel.COMPLETE,
method = "getCurrY",
args = {}
+ ),
+ @TestTargetNew(
+ level = TestLevel.COMPLETE,
+ method = "getStartX",
+ args = {}
+ ),
+ @TestTargetNew(
+ level = TestLevel.COMPLETE,
+ method = "getStartY",
+ args = {}
)
})
// We can not get the precise currX and currY when scrolling
@@ -276,11 +297,13 @@
assertEquals(0, mScroller.getFinalX());
assertEquals(0, mScroller.getFinalY());
- assertEquals(0, mScroller.getDuration());
+ assertEquals(0, mScroller.getDuration());
assertTrue(mScroller.isFinished());
mScroller.startScroll(0, 0, -2000, 2000);
+ assertEquals(0, mScroller.getStartX());
+ assertEquals(0, mScroller.getStartY());
assertEquals(-2000, mScroller.getFinalX());
assertEquals(2000, mScroller.getFinalY());
int defaultDuration = mScroller.getDuration();
@@ -308,7 +331,7 @@
@TestTargetNew(
level = TestLevel.COMPLETE,
method = "fling",
- args = {int.class, int.class, int.class, int.class, int.class, int.class, int.class,
+ args = {int.class, int.class, int.class, int.class, int.class, int.class, int.class,
int.class}
),
@TestTargetNew(
@@ -325,6 +348,16 @@
level = TestLevel.COMPLETE,
method = "getCurrY",
args = {}
+ ),
+ @TestTargetNew(
+ level = TestLevel.COMPLETE,
+ method = "getStartX",
+ args = {}
+ ),
+ @TestTargetNew(
+ level = TestLevel.COMPLETE,
+ method = "getStartY",
+ args = {}
)
})
// We can not get the precise currX and currY when scrolling
@@ -337,6 +370,8 @@
mScroller.fling(0, 0, - 3000, 4000, Integer.MIN_VALUE, Integer.MAX_VALUE,
Integer.MIN_VALUE, Integer.MAX_VALUE);
+ assertEquals(0, mScroller.getStartX());
+ assertEquals(0, mScroller.getStartY());
int duration = mScroller.getDuration();
assertTrue(mScroller.getFinalX() < 0);
assertTrue(mScroller.getFinalY() > 0);
diff --git a/tests/tests/widget/src/android/widget/cts/SimpleCursorAdapterTest.java b/tests/tests/widget/src/android/widget/cts/SimpleCursorAdapterTest.java
index e8f04de..2b5e872 100644
--- a/tests/tests/widget/src/android/widget/cts/SimpleCursorAdapterTest.java
+++ b/tests/tests/widget/src/android/widget/cts/SimpleCursorAdapterTest.java
@@ -16,13 +16,13 @@
package android.widget.cts;
-import com.android.internal.R;
+import com.android.cts.stub.R;
import com.android.internal.database.ArrayListCursor;
-import dalvik.annotation.TestTargets;
import dalvik.annotation.TestLevel;
-import dalvik.annotation.TestTargetNew;
import dalvik.annotation.TestTargetClass;
+import dalvik.annotation.TestTargetNew;
+import dalvik.annotation.TestTargets;
import dalvik.annotation.ToBeFixed;
import android.content.Context;
@@ -31,6 +31,7 @@
import android.test.InstrumentationTestCase;
import android.view.LayoutInflater;
import android.view.View;
+import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.SimpleCursorAdapter;
@@ -48,11 +49,11 @@
*/
@TestTargetClass(SimpleCursorAdapter.class)
public class SimpleCursorAdapterTest extends InstrumentationTestCase {
- private static final int DEFAULT_ROW_COUNT = 20;
+ private static final int ADAPTER_ROW_COUNT = 20;
private static final int DEFAULT_COLUMN_COUNT = 2;
- private static final int[] VIEWS_TO = new int[] { R.id.text1 };
+ private static final int[] VIEWS_TO = new int[] { R.id.cursorAdapter_item0 };
private static final String[] COLUMNS_FROM = new String[] { "column1" };
@@ -67,8 +68,6 @@
private Context mContext;
- private LayoutInflater mInflater;
-
/**
* The original cursor and its content will be set to:
* <TABLE>
@@ -101,39 +100,37 @@
protected void setUp() throws Exception {
super.setUp();
mContext = getInstrumentation().getTargetContext();
- mInflater = (LayoutInflater) mContext.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
- mCursor = createTestCursor(DEFAULT_COLUMN_COUNT, DEFAULT_ROW_COUNT);
- mSimpleCursorAdapter = new SimpleCursorAdapter(mContext, R.layout.simple_list_item_1,
+ mCursor = createTestCursor(DEFAULT_COLUMN_COUNT, ADAPTER_ROW_COUNT);
+ mSimpleCursorAdapter = new SimpleCursorAdapter(mContext, R.layout.cursoradapter_item0,
mCursor, COLUMNS_FROM, VIEWS_TO);
}
@TestTargetNew(
level = TestLevel.COMPLETE,
- notes = "Test constructor",
method = "SimpleCursorAdapter",
- args = {android.content.Context.class, int.class, android.database.Cursor.class,
+ args = {android.content.Context.class, int.class, android.database.Cursor.class,
java.lang.String[].class, int[].class}
)
public void testConstructor() {
- new SimpleCursorAdapter(mContext, R.layout.simple_list_item_1,
- createTestCursor(DEFAULT_COLUMN_COUNT, DEFAULT_ROW_COUNT),
+ new SimpleCursorAdapter(mContext, R.layout.cursoradapter_item0,
+ createTestCursor(DEFAULT_COLUMN_COUNT, ADAPTER_ROW_COUNT),
COLUMNS_FROM, VIEWS_TO);
}
@TestTargetNew(
level = TestLevel.COMPLETE,
method = "bindView",
- args = {android.view.View.class, android.content.Context.class,
+ args = {android.view.View.class, android.content.Context.class,
android.database.Cursor.class}
)
@ToBeFixed(bug = "1417734", explanation = "should add @throws clause into javadoc of "
+ "SimpleCursorAdapter#bindView(View, Context, Cursor) if the param view is "
+ "not TextView or ImageView and ViewBinder failed to bind the view")
public void testBindView() {
- TextView listItem = (TextView) mInflater.inflate(R.layout.simple_list_item_1, null);
- listItem.setTag(new View[]{listItem.findViewById(R.id.text1)});
+ TextView listItem = (TextView) mSimpleCursorAdapter.newView(mContext, null, null);
+ listItem.setText("");
mCursor.moveToFirst();
mSimpleCursorAdapter.bindView(listItem, null, mCursor);
assertEquals("01", listItem.getText().toString());
@@ -160,13 +157,16 @@
assertTrue(binder.hasCalledSetViewValueCalledCount());
assertEquals("191", listItem.getText().toString());
- LinearLayout illegalView = new LinearLayout(mContext);
- illegalView.setId(R.id.text1);
- illegalView.setTag(new View[]{illegalView.findViewById(R.id.text1)});
+ final int [] to = { R.id.cursorAdapter_host };
+ mSimpleCursorAdapter = new SimpleCursorAdapter(mContext, R.layout.cursoradapter_host,
+ mCursor, COLUMNS_FROM, to);
+ LinearLayout illegalView = (LinearLayout)mSimpleCursorAdapter.newView(mContext, null, null);
try {
+ // The IllegalStateException already gets thrown in the line above.
mSimpleCursorAdapter.bindView(illegalView, null, mCursor);
fail("Should throw IllegalStateException if the view is not TextView or ImageView");
} catch (IllegalStateException e) {
+ // expected
}
}
@@ -179,7 +179,7 @@
@TestTargetNew(
level = TestLevel.COMPLETE,
method = "setViewBinder",
- args = {android.widget.SimpleCursorAdapter.ViewBinder.class}
+ args = {ViewBinder.class}
)
})
public void testAccessViewBinder() {
@@ -199,9 +199,8 @@
@TestTargetNew(
level = TestLevel.COMPLETE,
- notes = "Test {@link SimpleCursorAdapter#setViewText(TextView, String)}",
method = "setViewText",
- args = {android.widget.TextView.class, java.lang.String.class}
+ args = {TextView.class, String.class}
)
public void testSetViewText() {
TextView view = new TextView(mContext);
@@ -214,21 +213,20 @@
@TestTargetNew(
level = TestLevel.COMPLETE,
- notes = "Test {@link SimpleCursorAdapter#setViewImage(ImageView, String)}",
method = "setViewImage",
- args = {android.widget.ImageView.class, java.lang.String.class}
+ args = {ImageView.class, String.class}
)
@ToBeFixed(bug = "1417734", explanation = "should add @throws clause into javadoc of "
+ "SimpleCursorAdapter#setViewImage(ImageView, String) if the param String is null")
public void testSetViewImage() {
// resId
+ int sceneryImgResId = com.android.cts.stub.R.drawable.scenery;
ImageView view = new ImageView(mContext);
assertNull(view.getDrawable());
- mSimpleCursorAdapter.setViewImage(view,
- String.valueOf(com.android.cts.stub.R.drawable.scenery));
+ mSimpleCursorAdapter.setViewImage(view, String.valueOf(sceneryImgResId));
assertNotNull(view.getDrawable());
BitmapDrawable d = (BitmapDrawable) mContext.getResources().getDrawable(
- com.android.cts.stub.R.drawable.scenery);
+ sceneryImgResId);
WidgetTestUtils.assertEquals(d.getBitmap(),
((BitmapDrawable) view.getDrawable()).getBitmap());
@@ -246,17 +244,18 @@
mSimpleCursorAdapter.setViewImage(view, null);
fail("Should throw NullPointerException if the uri or value is null");
} catch (NullPointerException e) {
+ // expected
}
// uri
view = new ImageView(mContext);
assertNull(view.getDrawable());
try {
- mSimpleCursorAdapter.setViewImage(view, createTestImage(mContext, SAMPLE_IMAGE_NAME,
- com.android.cts.stub.R.raw.testimage));
+ int testimgRawId = com.android.cts.stub.R.raw.testimage;
+ mSimpleCursorAdapter.setViewImage(view,
+ createTestImage(mContext, SAMPLE_IMAGE_NAME, testimgRawId));
assertNotNull(view.getDrawable());
- d = (BitmapDrawable) mContext.getResources()
- .getDrawable(com.android.cts.stub.R.raw.testimage);
+ d = (BitmapDrawable) mContext.getResources().getDrawable(testimgRawId);
WidgetTestUtils.assertEquals(d.getBitmap(),
((BitmapDrawable) view.getDrawable()).getBitmap());
} finally {
@@ -303,7 +302,7 @@
@TestTargetNew(
level = TestLevel.COMPLETE,
method = "setCursorToStringConverter",
- args = {android.widget.SimpleCursorAdapter.CursorToStringConverter.class}
+ args = {CursorToStringConverter.class}
)
})
public void testAccessCursorToStringConverter() {
@@ -322,24 +321,25 @@
level = TestLevel.COMPLETE,
notes = "Test {@link SimpleCursorAdapter#changeCursor(Cursor)}",
method = "changeCursor",
- args = {android.database.Cursor.class}
+ args = {Cursor.class}
)
@ToBeFixed(bug = "1417734", explanation = "should add @throws clause into javadoc of "
+ "SimpleCursorAdapter#changeCursor(Cursor) if the param cursor does not contain"
+ "any column passed in the constructor")
public void testChangeCursor() {
// have "column1"
- Cursor curWith3Columns = createTestCursor(3, DEFAULT_ROW_COUNT);
+ Cursor curWith3Columns = createTestCursor(3, ADAPTER_ROW_COUNT);
mSimpleCursorAdapter.changeCursor(curWith3Columns);
assertSame(curWith3Columns, mSimpleCursorAdapter.getCursor());
// does not have "column1"
- Cursor curWith1Column = createTestCursor(1, DEFAULT_ROW_COUNT);
+ Cursor curWith1Column = createTestCursor(1, ADAPTER_ROW_COUNT);
try {
mSimpleCursorAdapter.changeCursor(curWith1Column);
fail("Should throw exception if the cursor does not have the "
+ "original column passed in the constructor");
} catch (IllegalArgumentException e) {
+ // expected
}
}
@@ -347,7 +347,7 @@
level = TestLevel.COMPLETE,
notes = "Test {@link SimpleCursorAdapter#convertToString(Cursor)}",
method = "convertToString",
- args = {android.database.Cursor.class}
+ args = {Cursor.class}
)
@ToBeFixed(bug = "1417734", explanation = "should add @throws clause into javadoc of "
+ "SimpleCursorAdapter#convertToString(Cursor) if the StringConversionColumn set "
@@ -366,14 +366,15 @@
// converter is null, StringConversionColumn is set to 3 (larger than columns count)
// the cursor has 3 columns including column0, column1 and _id which is added automatically
- mSimpleCursorAdapter.setStringConversionColumn(3);
+ mSimpleCursorAdapter.setStringConversionColumn(DEFAULT_COLUMN_COUNT + 1);
try {
mSimpleCursorAdapter.convertToString(mCursor);
fail("Should throw IndexOutOfBoundsException if index is beyond the columns count");
} catch (IndexOutOfBoundsException e) {
+ // expected
}
- Cursor curWith3Columns = createTestCursor(3, DEFAULT_ROW_COUNT);
+ Cursor curWith3Columns = createTestCursor(DEFAULT_COLUMN_COUNT + 1, ADAPTER_ROW_COUNT);
curWith3Columns.moveToFirst();
// converter is null, StringConversionColumn is set to 3
@@ -390,6 +391,74 @@
assertTrue(((MockCursorToStringConverter) converter).hasCalledConvertToString());
}
+ @TestTargetNew(
+ level = TestLevel.COMPLETE,
+ method = "newView",
+ args = {Context.class, Cursor.class, ViewGroup.class}
+ )
+ public void testNewView() {
+ LayoutInflater layoutInflater = (LayoutInflater) mContext.getSystemService(
+ Context.LAYOUT_INFLATER_SERVICE);
+ ViewGroup viewGroup = (ViewGroup) layoutInflater.inflate(
+ com.android.cts.stub.R.layout.cursoradapter_host, null);
+ View result = mSimpleCursorAdapter.newView(mContext, null, viewGroup);
+ assertNotNull(result);
+ assertEquals(R.id.cursorAdapter_item0, result.getId());
+
+ result = mSimpleCursorAdapter.newView(mContext, null, null);
+ assertNotNull(result);
+ assertEquals(R.id.cursorAdapter_item0, result.getId());
+ }
+
+ @TestTargetNew(
+ level = TestLevel.COMPLETE,
+ method = "newDropDownView",
+ args = {Context.class, Cursor.class, ViewGroup.class}
+ )
+ public void testNewDropDownView() {
+ LayoutInflater layoutInflater = (LayoutInflater) mContext.getSystemService(
+ Context.LAYOUT_INFLATER_SERVICE);
+ ViewGroup viewGroup = (ViewGroup) layoutInflater.inflate(
+ com.android.cts.stub.R.layout.cursoradapter_host, null);
+ View result = mSimpleCursorAdapter.newDropDownView(null, null, viewGroup);
+ assertNotNull(result);
+ assertEquals(R.id.cursorAdapter_item0, result.getId());
+ }
+
+ @TestTargetNew(
+ level = TestLevel.COMPLETE,
+ method = "changeCursorAndColumns",
+ args = {Cursor.class, String[].class, int[].class}
+ )
+ public void testChangeCursorAndColumns() {
+ assertSame(mCursor, mSimpleCursorAdapter.getCursor());
+
+ TextView listItem = (TextView) mSimpleCursorAdapter.newView(mContext, null, null);
+
+ mCursor.moveToFirst();
+ mSimpleCursorAdapter.bindView(listItem, null, mCursor);
+ assertEquals("01", listItem.getText().toString());
+
+ mCursor.moveToLast();
+ mSimpleCursorAdapter.bindView(listItem, null, mCursor);
+ assertEquals("191", listItem.getText().toString());
+
+ Cursor newCursor = createTestCursor(3, ADAPTER_ROW_COUNT);
+ final String[] from = new String[] { "column2" };
+ mSimpleCursorAdapter.changeCursorAndColumns(newCursor, from, VIEWS_TO);
+ assertSame(newCursor, mSimpleCursorAdapter.getCursor());
+ newCursor.moveToFirst();
+ mSimpleCursorAdapter.bindView(listItem, null, newCursor);
+ assertEquals("02", listItem.getText().toString());
+
+ newCursor.moveToLast();
+ mSimpleCursorAdapter.bindView(listItem, null, newCursor);
+ assertEquals("192", listItem.getText().toString());
+
+ mSimpleCursorAdapter.changeCursorAndColumns(null, null, null);
+ assertNull(mSimpleCursorAdapter.getCursor());
+ }
+
/**
* Creates the test cursor.
*
@@ -416,7 +485,7 @@
return new ArrayListCursor(columns, list);
}
- private class MockViewBinder implements ViewBinder {
+ private static class MockViewBinder implements ViewBinder {
private boolean mExpectedResult;
private boolean mHasCalledSetViewValue;
@@ -473,7 +542,7 @@
context.deleteFile(fileName);
}
- private class MockCursorToStringConverter implements CursorToStringConverter {
+ private static class MockCursorToStringConverter implements CursorToStringConverter {
private boolean mHasCalledConvertToString;
public boolean hasCalledConvertToString() {
@@ -490,4 +559,3 @@
}
}
}
-
diff --git a/tests/tests/widget/src/android/widget/cts/TextViewTest.java b/tests/tests/widget/src/android/widget/cts/TextViewTest.java
index 44fff7a..4047139 100644
--- a/tests/tests/widget/src/android/widget/cts/TextViewTest.java
+++ b/tests/tests/widget/src/android/widget/cts/TextViewTest.java
@@ -45,6 +45,7 @@
import android.net.Uri;
import android.os.Bundle;
import android.test.ActivityInstrumentationTestCase2;
+import android.test.TouchUtils;
import android.test.UiThreadTest;
import android.text.Editable;
import android.text.InputFilter;
@@ -86,9 +87,14 @@
import android.view.View.OnCreateContextMenuListener;
import android.view.View.OnLongClickListener;
import android.view.animation.cts.DelayedCheck;
+import android.view.inputmethod.BaseInputConnection;
+import android.view.inputmethod.EditorInfo;
+import android.view.inputmethod.ExtractedText;
+import android.view.inputmethod.ExtractedTextRequest;
import android.widget.Scroller;
import android.widget.TextView;
import android.widget.TextView.BufferType;
+import android.widget.TextView.OnEditorActionListener;
import java.io.IOException;
@@ -1211,12 +1217,12 @@
@TestTargets({
@TestTargetNew(
- level = TestLevel.COMPLETE,
+ level = TestLevel.PARTIAL_COMPLETE,
method = "setFreezesText",
args = {boolean.class}
),
@TestTargetNew(
- level = TestLevel.COMPLETE,
+ level = TestLevel.PARTIAL_COMPLETE,
method = "getFreezesText",
args = {}
)
@@ -1245,7 +1251,7 @@
mInstrumentation.waitForIdleSync();
final URLSpan urlSpan = new URLSpan("ctstest://TextView/test");
-
+ // TODO: How to simulate the TextView in frozen icicles.
Instrumentation instrumentation = getInstrumentation();
ActivityMonitor am = instrumentation.addMonitor(MockURLSpanTestActivity.class.getName(),
null, false);
@@ -1261,10 +1267,11 @@
Activity newActivity = am.waitForActivityWithTimeout(TIMEOUT);
assertNotNull(newActivity);
newActivity.finish();
+ instrumentation.removeMonitor(am);
// the text of TextView is removed.
mTextView = findTextView(R.id.freezesText_false);
- // FIXME: the text of TextView is still there.
- //assertEquals("", mTextView.getText().toString());
+
+ assertEquals(text.toString(), mTextView.getText().toString());
mTextView.setFreezesText(true);
assertTrue(mTextView.getFreezesText());
@@ -1275,7 +1282,7 @@
}
});
mInstrumentation.waitForIdleSync();
-
+ // TODO: How to simulate the TextView in frozen icicles.
am = instrumentation.addMonitor(MockURLSpanTestActivity.class.getName(),
null, false);
@@ -1290,6 +1297,7 @@
newActivity = am.waitForActivityWithTimeout(TIMEOUT);
assertNotNull(newActivity);
newActivity.finish();
+ instrumentation.removeMonitor(am);
// the text of TextView is still there.
mTextView = findTextView(R.id.freezesText_false);
assertEquals(text.toString(), mTextView.getText().toString());
@@ -2834,16 +2842,12 @@
)
@UiThreadTest
@ToBeFixed(bug = "1695243", explanation = "Android API javadocs are incomplete, "
- + "this method should not accept neagtive "
- + " values as maximum line count")
+ + "this method should not accept neagtive values as maximum line count")
public void testSetMaxLinesException() {
- mTextView = findTextView(R.id.textview_text);
+ mTextView = new TextView(mActivity);
+ mActivity.setContentView(mTextView);
mTextView.setWidth(mTextView.getWidth() >> 3);
- // the flowing code will cause handler of the view to raise exception
- // when it gets layout next time
- // the code is commented because we can not catch the that exception
- // which will interupt the other tests
- //mTextView.setMaxLines(-1);
+ mTextView.setMaxLines(-1);
}
@TestTargetNew(
@@ -2897,16 +2901,12 @@
)
@UiThreadTest
@ToBeFixed(bug = "1695243", explanation = "Android API javadocs are incomplete, "
- + "this method should not accept neagtive "
- + " values as maximum line count")
+ + "this method should not accept neagtive values as maximum line count")
public void testSetLinesException() {
- mTextView = findTextView(R.id.textview_text);
- mTextView.setWidth((mTextView.getWidth() >> 3));
- // the flowing code will cause handler of the view to raise exception
- // when it gets layout next time
- // the code is commented because we can not catch the that exception
- // which will interupt the other tests
- // mTextView.setLines(-1);
+ mTextView = new TextView(mActivity);
+ mActivity.setContentView(mTextView);
+ mTextView.setWidth(mTextView.getWidth() >> 3);
+ mTextView.setLines(-1);
}
@TestTargetNew(
@@ -3444,9 +3444,6 @@
};
mActivity.runOnUiThread(runnable);
- final float leftFadingEdgeStrength = textView.getLeftFadingEdgeStrength();
- final float rightFadingEdgeStrength = textView.getRightFadingEdgeStrength();
-
// wait for the marquee to run
// fading is shown on both sides if the marquee runs for a while
new DelayedCheck(TIMEOUT) {
@@ -3457,6 +3454,9 @@
}
}.run();
+ final float leftFadingEdgeStrength = textView.getLeftFadingEdgeStrength();
+ final float rightFadingEdgeStrength = textView.getRightFadingEdgeStrength();
+
// wait for the marquee to continue
// the left fading becomes thicker while the right fading becomes thiner
// as the text moves towards left
@@ -3739,6 +3739,407 @@
// Do not test. Implementation details.
}
+ @TestTargets({
+ @TestTargetNew(
+ level = TestLevel.NOT_NECESSARY,
+ method = "onAttachedToWindow",
+ args = {}
+ ),
+ @TestTargetNew(
+ level = TestLevel.NOT_NECESSARY,
+ method = "onBeginBatchEdit",
+ args = {}
+ ),
+ @TestTargetNew(
+ level = TestLevel.NOT_NECESSARY,
+ method = "onCheckIsTextEditor",
+ args = {}
+ ),
+ @TestTargetNew(
+ level = TestLevel.NOT_NECESSARY,
+ method = "onCommitCompletion",
+ args = {android.view.inputmethod.CompletionInfo.class}
+ ),
+ @TestTargetNew(
+ level = TestLevel.NOT_NECESSARY,
+ method = "onCreateInputConnection",
+ args = {android.view.inputmethod.EditorInfo.class}
+ ),
+ @TestTargetNew(
+ level = TestLevel.NOT_NECESSARY,
+ method = "onEditorAction",
+ args = {int.class}
+ ),
+ @TestTargetNew(
+ level = TestLevel.NOT_NECESSARY,
+ method = "onEndBatchEdit",
+ args = {}
+ ),
+ @TestTargetNew(
+ level = TestLevel.NOT_NECESSARY,
+ method = "onFinishTemporaryDetach",
+ args = {}
+ ),
+ @TestTargetNew(
+ level = TestLevel.NOT_NECESSARY,
+ method = "onSelectionChanged",
+ args = {int.class, int.class}
+ ),
+ @TestTargetNew(
+ level = TestLevel.NOT_NECESSARY,
+ method = "onStartTemporaryDetach",
+ args = {}
+ ),
+ @TestTargetNew(
+ level = TestLevel.NOT_NECESSARY,
+ method = "onTextContextMenuItem",
+ args = {int.class}
+ )
+ })
+ public void testFoo() {
+ // Do not test. Implementation details.
+ }
+
+ @TestTargetNew(
+ level = TestLevel.COMPLETE,
+ method = "verifyDrawable",
+ args = {android.graphics.drawable.Drawable.class}
+ )
+ public void testVerifyDrawable() {
+ MockTextView textView = new MockTextView(mActivity);
+
+ Drawable d = mActivity.getResources().getDrawable(R.drawable.pass);
+ assertFalse(textView.verifyDrawable(d));
+
+ textView.setCompoundDrawables(null, d, null, null);
+ assertTrue(textView.verifyDrawable(d));
+ }
+
+ @TestTargets({
+ @TestTargetNew(
+ level = TestLevel.COMPLETE,
+ method = "setPrivateImeOptions",
+ args = {java.lang.String.class}
+ ),
+ @TestTargetNew(
+ level = TestLevel.COMPLETE,
+ method = "getPrivateImeOptions",
+ args = {}
+ )
+ })
+ public void testAccessPrivateImeOptions() {
+ mTextView = findTextView(R.id.textview_text);
+ assertNull(mTextView.getPrivateImeOptions());
+
+ mTextView.setPrivateImeOptions("com.example.myapp.SpecialMode=3");
+ assertEquals("com.example.myapp.SpecialMode=3", mTextView.getPrivateImeOptions());
+
+ mTextView.setPrivateImeOptions(null);
+ assertNull(mTextView.getPrivateImeOptions());
+ }
+
+ @TestTargetNew(
+ level = TestLevel.COMPLETE,
+ method = "setOnEditorActionListener",
+ args = {android.widget.TextView.OnEditorActionListener.class}
+ )
+ public void testSetOnEditorActionListener() {
+ mTextView = findTextView(R.id.textview_text);
+
+ MockOnEditorActionListener listener = new MockOnEditorActionListener();
+ assertFalse(listener.isOnEditorActionCalled());
+
+ mTextView.setOnEditorActionListener(listener);
+ assertFalse(listener.isOnEditorActionCalled());
+
+ mTextView.onEditorAction(EditorInfo.IME_ACTION_DONE);
+ assertTrue(listener.isOnEditorActionCalled());
+ }
+
+ @TestTargets({
+ @TestTargetNew(
+ level = TestLevel.COMPLETE,
+ method = "setImeOptions",
+ args = {int.class}
+ ),
+ @TestTargetNew(
+ level = TestLevel.COMPLETE,
+ method = "getImeOptions",
+ args = {}
+ )
+ })
+ public void testAccessImeOptions() {
+ mTextView = findTextView(R.id.textview_text);
+ assertEquals(EditorInfo.IME_NULL, mTextView.getImeOptions());
+
+ mTextView.setImeOptions(EditorInfo.IME_ACTION_GO);
+ assertEquals(EditorInfo.IME_ACTION_GO, mTextView.getImeOptions());
+
+ mTextView.setImeOptions(EditorInfo.IME_ACTION_DONE);
+ assertEquals(EditorInfo.IME_ACTION_DONE, mTextView.getImeOptions());
+
+ mTextView.setImeOptions(EditorInfo.IME_NULL);
+ assertEquals(EditorInfo.IME_NULL, mTextView.getImeOptions());
+ }
+
+ @TestTargets({
+ @TestTargetNew(
+ level = TestLevel.COMPLETE,
+ method = "setImeActionLabel",
+ args = {java.lang.CharSequence.class, int.class}
+ ),
+ @TestTargetNew(
+ level = TestLevel.COMPLETE,
+ method = "getImeActionLabel",
+ args = {}
+ ),
+ @TestTargetNew(
+ level = TestLevel.COMPLETE,
+ method = "getImeActionId",
+ args = {}
+ )
+ })
+ public void testAccessImeActionLabel() {
+ mTextView = findTextView(R.id.textview_text);
+ assertNull(mTextView.getImeActionLabel());
+ assertEquals(0, mTextView.getImeActionId());
+
+ mTextView.setImeActionLabel("pinyin", 1);
+ assertEquals("pinyin", mTextView.getImeActionLabel().toString());
+ assertEquals(1, mTextView.getImeActionId());
+ }
+
+ @TestTargetNew(
+ level = TestLevel.COMPLETE,
+ method = "setExtractedText",
+ args = {android.view.inputmethod.ExtractedText.class}
+ )
+ @UiThreadTest
+ public void testSetExtractedText() {
+ mTextView = findTextView(R.id.textview_text);
+ assertEquals(mActivity.getResources().getString(R.string.text_view_hello),
+ mTextView.getText().toString());
+
+ ExtractedText et = new ExtractedText();
+ et.text = "test";
+
+ mTextView.setExtractedText(et);
+ assertEquals("test", mTextView.getText().toString());
+ }
+
+ @TestTargetNew(
+ level = TestLevel.COMPLETE,
+ method = "moveCursorToVisibleOffset",
+ args = {}
+ )
+ public void testMoveCursorToVisibleOffset() throws Throwable {
+ mTextView = findTextView(R.id.textview_text);
+
+ // not a spannable text
+ runTestOnUiThread(new Runnable() {
+ public void run() {
+ assertFalse(mTextView.moveCursorToVisibleOffset());
+ }
+ });
+ mInstrumentation.waitForIdleSync();
+
+ // a selection range
+ final String spannableText = "text";
+ mTextView = new TextView(mActivity);
+
+ runTestOnUiThread(new Runnable() {
+ public void run() {
+ mTextView.setText(spannableText, BufferType.SPANNABLE);
+ }
+ });
+ mInstrumentation.waitForIdleSync();
+ Selection.setSelection((Spannable) mTextView.getText(), 0, spannableText.length());
+
+ assertEquals(0, mTextView.getSelectionStart());
+ assertEquals(spannableText.length(), mTextView.getSelectionEnd());
+ runTestOnUiThread(new Runnable() {
+ public void run() {
+ assertFalse(mTextView.moveCursorToVisibleOffset());
+ }
+ });
+ mInstrumentation.waitForIdleSync();
+
+ // a spannable without range
+ runTestOnUiThread(new Runnable() {
+ public void run() {
+ mTextView = findTextView(R.id.textview_text);
+ mTextView.setText(spannableText, BufferType.SPANNABLE);
+ }
+ });
+ mInstrumentation.waitForIdleSync();
+
+ runTestOnUiThread(new Runnable() {
+ public void run() {
+ assertTrue(mTextView.moveCursorToVisibleOffset());
+ }
+ });
+ mInstrumentation.waitForIdleSync();
+ }
+
+ @TestTargetNew(
+ level = TestLevel.COMPLETE,
+ method = "isInputMethodTarget",
+ args = {}
+ )
+ @UiThreadTest
+ public void testIsInputMethodTarget() {
+ mTextView = findTextView(R.id.textview_text);
+ assertFalse(mTextView.isInputMethodTarget());
+
+ assertFalse(mTextView.isFocused());
+ mTextView.setFocusable(true);
+ mTextView.requestFocus();
+ assertTrue(mTextView.isFocused());
+
+ assertTrue(mTextView.isInputMethodTarget());
+ }
+
+ @TestTargets({
+ @TestTargetNew(
+ level = TestLevel.COMPLETE,
+ method = "beginBatchEdit",
+ args = {}
+ ),
+ @TestTargetNew(
+ level = TestLevel.COMPLETE,
+ method = "endBatchEdit",
+ args = {}
+ )
+ })
+ @ToBeFixed(bug = "1695243", explanation = "Android API javadocs are incomplete")
+ public void testBeginEndBatchEdit() {
+ mTextView = findTextView(R.id.textview_text);
+
+ mTextView.beginBatchEdit();
+ mTextView.endBatchEdit();
+ }
+
+ @TestTargetNew(
+ level = TestLevel.NOT_FEASIBLE,
+ notes = "it's hard to do unit test, should be tested by functional test",
+ method = "bringPointIntoView",
+ args = {int.class}
+ )
+ @UiThreadTest
+ public void testBringPointIntoView() throws Throwable {
+ mTextView = findTextView(R.id.textview_text);
+ assertFalse(mTextView.bringPointIntoView(1));
+
+ mTextView.layout(0, 0, 100, 100);
+ assertFalse(mTextView.bringPointIntoView(2));
+ }
+
+ @TestTargetNew(
+ level = TestLevel.NOT_FEASIBLE,
+ notes = "it's hard to do unit test, should be tested by functional test",
+ method = "cancelLongPress",
+ args = {}
+ )
+ public void testCancelLongPress() {
+ mTextView = findTextView(R.id.textview_text);
+ TouchUtils.longClickView(this, mTextView);
+ mTextView.cancelLongPress();
+ }
+
+ @TestTargetNew(
+ level = TestLevel.COMPLETE,
+ method = "clearComposingText",
+ args = {}
+ )
+ @UiThreadTest
+ public void testClearComposingText() {
+ mTextView = findTextView(R.id.textview_text);
+ mTextView.setText("Hello world!", BufferType.SPANNABLE);
+ Spannable text = (Spannable) mTextView.getText();
+
+ assertEquals(-1, BaseInputConnection.getComposingSpanStart(text));
+ assertEquals(-1, BaseInputConnection.getComposingSpanStart(text));
+
+ BaseInputConnection.setComposingSpans((Spannable) mTextView.getText());
+ assertEquals(0, BaseInputConnection.getComposingSpanStart(text));
+ assertEquals(0, BaseInputConnection.getComposingSpanStart(text));
+
+ mTextView.clearComposingText();
+ assertEquals(-1, BaseInputConnection.getComposingSpanStart(text));
+ assertEquals(-1, BaseInputConnection.getComposingSpanStart(text));
+ }
+
+ @TestTargetNew(
+ level = TestLevel.NOT_FEASIBLE,
+ notes = "it's hard to do unit test, should be tested by functional test",
+ method = "computeVerticalScrollExtent",
+ args = {}
+ )
+ public void testComputeVerticalScrollExtent() {
+ MockTextView textView = new MockTextView(mActivity);
+ assertEquals(0, textView.computeVerticalScrollExtent());
+
+ Drawable d = mActivity.getResources().getDrawable(R.drawable.pass);
+ textView.setCompoundDrawables(null, d, null, d);
+
+ assertEquals(0, textView.computeVerticalScrollExtent());
+ }
+
+ @TestTargetNew(
+ level = TestLevel.COMPLETE,
+ method = "didTouchFocusSelect",
+ args = {}
+ )
+ @UiThreadTest
+ public void testDidTouchFocusSelect() {
+ mTextView = new TextView(mActivity);
+ assertFalse(mTextView.didTouchFocusSelect());
+
+ mTextView.setFocusable(true);
+ mTextView.requestFocus();
+ assertTrue(mTextView.didTouchFocusSelect());
+ }
+
+ @TestTargetNew(
+ level = TestLevel.COMPLETE,
+ method = "extractText",
+ args = {android.view.inputmethod.ExtractedTextRequest.class,
+ android.view.inputmethod.ExtractedText.class}
+ )
+ @ToBeFixed(bug = "", explanation = "even the TextView did not contains editable content, " +
+ "it also returns true.")
+ public void testExtractText() {
+ mTextView = new TextView(mActivity);
+
+ ExtractedTextRequest request = new ExtractedTextRequest();
+ ExtractedText outText = new ExtractedText();
+
+ request.token = 0;
+ request.flags = 10;
+ request.hintMaxLines = 2;
+ request.hintMaxChars = 20;
+ assertTrue(mTextView.extractText(request, outText));
+
+ mTextView = findTextView(R.id.textview_text);
+ assertTrue(mTextView.extractText(request, outText));
+
+ assertEquals(mActivity.getResources().getString(R.string.text_view_hello),
+ outText.text.toString());
+ }
+
+ private static class MockOnEditorActionListener implements OnEditorActionListener {
+ private boolean isOnEditorActionCalled;
+
+ public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
+ isOnEditorActionCalled = true;
+ return true;
+ }
+
+ public boolean isOnEditorActionCalled() {
+ return isOnEditorActionCalled;
+ }
+ }
+
private void layout(final TextView textView) {
mActivity.runOnUiThread(new Runnable() {
public void run() {
@@ -4285,5 +4686,15 @@
protected boolean isPaddingOffsetRequired() {
return super.isPaddingOffsetRequired();
}
+
+ @Override
+ protected boolean verifyDrawable(Drawable who) {
+ return super.verifyDrawable(who);
+ }
+
+ @Override
+ protected int computeVerticalScrollExtent() {
+ return super.computeVerticalScrollExtent();
+ }
}
}
diff --git a/tests/tests/widget/src/android/widget/cts/ViewAnimatorTest.java b/tests/tests/widget/src/android/widget/cts/ViewAnimatorTest.java
index 3b5988d..e8e5dcf 100644
--- a/tests/tests/widget/src/android/widget/cts/ViewAnimatorTest.java
+++ b/tests/tests/widget/src/android/widget/cts/ViewAnimatorTest.java
@@ -16,12 +16,19 @@
package android.widget.cts;
+import com.android.cts.stub.R;
+
+import dalvik.annotation.TestLevel;
+import dalvik.annotation.TestTargetClass;
+import dalvik.annotation.TestTargetNew;
+import dalvik.annotation.TestTargets;
+import dalvik.annotation.ToBeFixed;
+
import org.xmlpull.v1.XmlPullParser;
import android.app.Activity;
import android.app.Instrumentation;
-import android.content.Context;
-import android.test.ActivityInstrumentationTestCase;
+import android.test.ActivityInstrumentationTestCase2;
import android.test.UiThreadTest;
import android.util.AttributeSet;
import android.util.Xml;
@@ -33,17 +40,9 @@
import android.widget.RelativeLayout;
import android.widget.ViewAnimator;
-import com.android.cts.stub.R;
-
-import dalvik.annotation.TestTargets;
-import dalvik.annotation.TestLevel;
-import dalvik.annotation.TestTargetNew;
-import dalvik.annotation.TestTargetClass;
-import dalvik.annotation.ToBeFixed;
-
@TestTargetClass(ViewAnimator.class)
public class ViewAnimatorTest extends
- ActivityInstrumentationTestCase<ViewAnimatorStubActivity> {
+ ActivityInstrumentationTestCase2<ViewAnimatorStubActivity> {
private ViewAnimator mViewAnimator;
private Activity mActivity;
private Instrumentation mInstrumentation;
@@ -72,13 +71,11 @@
@TestTargets({
@TestTargetNew(
level = TestLevel.COMPLETE,
- notes = "Test constructor(s) of ViewAnimator.",
method = "ViewAnimator",
args = {android.content.Context.class}
),
@TestTargetNew(
level = TestLevel.COMPLETE,
- notes = "Test constructor(s) of ViewAnimator.",
method = "ViewAnimator",
args = {android.content.Context.class, android.util.AttributeSet.class}
)
@@ -100,19 +97,16 @@
@TestTargets({
@TestTargetNew(
level = TestLevel.COMPLETE,
- notes = "Test setInAnimation(Animation inAnimation) and getInAnimation().",
method = "setInAnimation",
args = {android.view.animation.Animation.class}
),
@TestTargetNew(
level = TestLevel.COMPLETE,
- notes = "Test setInAnimation(Animation inAnimation) and getInAnimation().",
method = "setInAnimation",
args = {android.content.Context.class, int.class}
),
@TestTargetNew(
level = TestLevel.COMPLETE,
- notes = "Test setInAnimation(Animation inAnimation) and getInAnimation().",
method = "getInAnimation",
args = {}
)
@@ -136,7 +130,6 @@
@TestTargetNew(
level = TestLevel.COMPLETE,
- notes = "Test showNext().",
method = "showNext",
args = {}
)
@@ -179,27 +172,25 @@
}
@TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "Test setAnimateFirstView(boolean animate).",
+ level = TestLevel.PARTIAL,
method = "setAnimateFirstView",
args = {boolean.class}
)
- @ToBeFixed(bug = "", explanation = "no getter to check.")
public void testSetAnimateFirstView() {
mViewAnimator.setAnimateFirstView(true);
mViewAnimator.setAnimateFirstView(false);
+
+ // TODO: how to check
}
@TestTargets({
@TestTargetNew(
level = TestLevel.COMPLETE,
- notes = "Test setDisplayedChild(int whichChild) and getDisplayedChild().",
method = "setDisplayedChild",
args = {int.class}
),
@TestTargetNew(
level = TestLevel.COMPLETE,
- notes = "Test setDisplayedChild(int whichChild) and getDisplayedChild().",
method = "getDisplayedChild",
args = {}
)
@@ -241,13 +232,11 @@
@TestTargets({
@TestTargetNew(
level = TestLevel.COMPLETE,
- notes = "Test setDisplayedChild(int whichChild) and getDisplayedChild().",
method = "setDisplayedChild",
args = {int.class}
),
@TestTargetNew(
level = TestLevel.COMPLETE,
- notes = "Test setDisplayedChild(int whichChild) and getDisplayedChild().",
method = "getDisplayedChild",
args = {}
)
@@ -282,7 +271,6 @@
@TestTargetNew(
level = TestLevel.COMPLETE,
- notes = "Test getBaseline().",
method = "getBaseline",
args = {}
)
@@ -314,7 +302,6 @@
@TestTargetNew(
level = TestLevel.COMPLETE,
- notes = "Test showPrevious().",
method = "showPrevious",
args = {}
)
@@ -359,7 +346,6 @@
@TestTargetNew(
level = TestLevel.COMPLETE,
- notes = "Test getCurrentView().",
method = "getCurrentView",
args = {}
)
@@ -382,12 +368,18 @@
assertEquals(0, mViewAnimator.getChildCount());
}
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "Test addView(View child, int index, LayoutParams params).",
- method = "addView",
- args = {android.view.View.class, int.class, android.view.ViewGroup.LayoutParams.class}
- )
+ @TestTargets({
+ @TestTargetNew(
+ level = TestLevel.COMPLETE,
+ method = "addView",
+ args = {android.view.View.class, int.class, android.view.ViewGroup.LayoutParams.class}
+ ),
+ @TestTargetNew(
+ level = TestLevel.COMPLETE,
+ method = "removeAllViews",
+ args = {}
+ )
+ })
@UiThreadTest
public void testAddView() {
final View v1 = mActivity.findViewById(R.id.ok);
@@ -415,19 +407,16 @@
@TestTargets({
@TestTargetNew(
level = TestLevel.COMPLETE,
- notes = "Test setOutAnimation(Animation outAnimation) and getOutAnimation().",
method = "setOutAnimation",
args = {android.view.animation.Animation.class}
),
@TestTargetNew(
level = TestLevel.COMPLETE,
- notes = "Test setOutAnimation(Animation outAnimation) and getOutAnimation().",
method = "setOutAnimation",
args = {android.content.Context.class, int.class}
),
@TestTargetNew(
level = TestLevel.COMPLETE,
- notes = "Test setOutAnimation(Animation outAnimation) and getOutAnimation().",
method = "getOutAnimation",
args = {}
)
@@ -447,4 +436,93 @@
assertTrue(animation.getInterpolator() instanceof AccelerateInterpolator);
assertEquals(500, animation.getDuration());
}
+
+ @TestTargets({
+ @TestTargetNew(
+ level = TestLevel.COMPLETE,
+ method = "removeView",
+ args = {android.view.View.class}
+ ),
+ @TestTargetNew(
+ level = TestLevel.COMPLETE,
+ method = "removeViewAt",
+ args = {int.class}
+ ),
+ @TestTargetNew(
+ level = TestLevel.COMPLETE,
+ method = "removeViewInLayout",
+ args = {android.view.View.class}
+ ),
+ @TestTargetNew(
+ level = TestLevel.COMPLETE,
+ method = "removeViews",
+ args = {int.class, int.class}
+ ),
+ @TestTargetNew(
+ level = TestLevel.COMPLETE,
+ method = "removeViewsInLayout",
+ args = {int.class, int.class}
+ ),
+ @TestTargetNew(
+ level = TestLevel.COMPLETE,
+ method = "removeAllViews",
+ args = {}
+ )
+ })
+ @UiThreadTest
+ public void testRemoveViews() {
+ final View v1 = mActivity.findViewById(R.id.ok);
+ final View v2 = mActivity.findViewById(R.id.cancel);
+ final View v3 = mActivity.findViewById(R.id.label);
+ final View v4 = mActivity.findViewById(R.id.entry);
+ final RelativeLayout parent = (RelativeLayout) v1.getParent();
+
+ parent.removeView(v1);
+ parent.removeView(v2);
+ parent.removeView(v3);
+ parent.removeView(v4);
+ assertEquals(0, mViewAnimator.getChildCount());
+
+ mViewAnimator.addView(v1);
+ mViewAnimator.addView(v2);
+ mViewAnimator.addView(v3);
+ mViewAnimator.addView(v4);
+ assertEquals(4, mViewAnimator.getChildCount());
+
+ mViewAnimator.removeViewAt(3);
+ assertEquals(3, mViewAnimator.getChildCount());
+ assertSame(v1, mViewAnimator.getChildAt(0));
+ assertSame(v2, mViewAnimator.getChildAt(1));
+ assertSame(v3, mViewAnimator.getChildAt(2));
+
+ mViewAnimator.removeView(v3);
+ assertEquals(2, mViewAnimator.getChildCount());
+ assertSame(v1, mViewAnimator.getChildAt(0));
+ assertSame(v2, mViewAnimator.getChildAt(1));
+
+ mViewAnimator.removeViewInLayout(v2);
+ assertEquals(1, mViewAnimator.getChildCount());
+ assertSame(v1, mViewAnimator.getChildAt(0));
+
+ mViewAnimator.addView(v2);
+ mViewAnimator.addView(v3);
+ mViewAnimator.addView(v4);
+ assertEquals(4, mViewAnimator.getChildCount());
+
+ mViewAnimator.removeViews(0, 2);
+ assertEquals(2, mViewAnimator.getChildCount());
+
+ // the remain views should be v3, v4
+ assertSame(v3, mViewAnimator.getChildAt(0));
+ assertSame(v4, mViewAnimator.getChildAt(1));
+
+ mViewAnimator.removeViewsInLayout(1, 1);
+ assertEquals(1, mViewAnimator.getChildCount());
+
+ // the remain view should be v3
+ assertSame(v3, mViewAnimator.getChildAt(0));
+
+ mViewAnimator.removeAllViews();
+ assertEquals(0, mViewAnimator.getChildCount());
+ }
}