Fix ViewTreeObserverTest in Landscape Orientation
Bug 5679517
The content view had a LinearLayout with horizontal orientation,
so the button ended up near the navigation bar which rejected
the simulated pointer event. Change the layout to use vertical
orientation.
The changes in ViewTreeObserverTest are just to remove warnings
and get rid of the testing annotations.
Change-Id: Ibd062336ef1285305fc8238a5a78190a3ec57656
diff --git a/tests/res/layout/viewtreeobserver_layout.xml b/tests/res/layout/viewtreeobserver_layout.xml
index 88112ec..461a4bc 100644
--- a/tests/res/layout/viewtreeobserver_layout.xml
+++ b/tests/res/layout/viewtreeobserver_layout.xml
@@ -16,6 +16,7 @@
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/linearlayout"
+ android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="wrap_content">
diff --git a/tests/tests/view/src/android/view/cts/ViewTreeObserverTest.java b/tests/tests/view/src/android/view/cts/ViewTreeObserverTest.java
index c0b1b96..1dee2b3 100644
--- a/tests/tests/view/src/android/view/cts/ViewTreeObserverTest.java
+++ b/tests/tests/view/src/android/view/cts/ViewTreeObserverTest.java
@@ -18,11 +18,6 @@
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.app.Instrumentation;
import android.app.cts.MockActivity;
@@ -42,10 +37,6 @@
import android.widget.ListView;
import android.widget.ScrollView;
-/**
- * Test {@link ViewTreeObserver}.
- */
-@TestTargetClass(ViewTreeObserver.class)
public class ViewTreeObserverTest extends ActivityInstrumentationTestCase2<MockActivity> {
ViewTreeObserver mViewTreeObserver;
@@ -62,11 +53,12 @@
}
public ViewTreeObserverTest() {
- super("com.android.cts.stub", MockActivity.class);
+ super(MockActivity.class);
}
private void layout(final int layoutId) {
mInstrumentation.runOnMainSync(new Runnable() {
+ @Override
public void run() {
mActivity.setContentView(layoutId);
}
@@ -74,12 +66,6 @@
mInstrumentation.waitForIdleSync();
}
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "Test addOnGlobalFocusChangeListener(OnGlobalFocusChangeListener)",
- method = "addOnGlobalFocusChangeListener",
- args = {android.view.ViewTreeObserver.OnGlobalFocusChangeListener.class}
- )
public void testAddOnGlobalFocusChangeListener() {
final LinearLayout layout = (LinearLayout) mActivity.findViewById(R.id.linearlayout);
final ListView lv1 = (ListView) mActivity.findViewById(R.id.listview1);
@@ -91,6 +77,7 @@
assertFalse(listener.hasCalledOnGlobalFocusChanged());
mInstrumentation.runOnMainSync(new Runnable() {
+ @Override
public void run() {
layout.requestChildFocus(lv1, lv2);
}
@@ -100,12 +87,6 @@
assertTrue(listener.hasCalledOnGlobalFocusChanged());
}
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "Test addOnGlobalLayoutListener(OnGlobalLayoutListener)",
- method = "addOnGlobalLayoutListener",
- args = {android.view.ViewTreeObserver.OnGlobalLayoutListener.class}
- )
public void testAddOnGlobalLayoutListener() {
final LinearLayout layout =
(LinearLayout) mActivity.findViewById(R.id.linearlayout);
@@ -118,12 +99,6 @@
assertTrue(listener.hasCalledOnGlobalLayout());
}
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "Test addOnPreDrawListener(OnPreDrawListener)",
- method = "addOnPreDrawListener",
- args = {android.view.ViewTreeObserver.OnPreDrawListener.class}
- )
public void testAddOnPreDrawListener() {
final LinearLayout layout = (LinearLayout) mActivity.findViewById(R.id.linearlayout);
mViewTreeObserver = layout.getViewTreeObserver();
@@ -135,14 +110,9 @@
assertTrue(listener.hasCalledOnPreDraw());
}
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "Test addOnTouchModeChangeListener(OnTouchModeChangeListener)",
- method = "addOnTouchModeChangeListener",
- args = {android.view.ViewTreeObserver.OnTouchModeChangeListener.class}
- )
public void testAddOnTouchModeChangeListener() {
final Button b = (Button) mActivity.findViewById(R.id.button1);
+
// let the button be touch mode.
TouchUtils.tapView(this, b);
@@ -153,6 +123,7 @@
mViewTreeObserver.addOnTouchModeChangeListener(listener);
mInstrumentation.runOnMainSync(new Runnable() {
+ @Override
public void run() {
b.requestFocusFromTouch();
}
@@ -162,12 +133,6 @@
assertTrue(listener.hasCalledOnTouchModeChanged());
}
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "Test addOnComputeInternalInsetsListener(OnComputeInternalInsetsListener)",
- method = "addOnComputeInternalInsetsListener",
- args = {android.view.ViewTreeObserver.OnComputeInternalInsetsListener.class}
- )
public void testAddOnComputeInternalInsetsListener() {
final ListView lv1 = (ListView) mActivity.findViewById(R.id.listview1);
mViewTreeObserver = lv1.getViewTreeObserver();
@@ -176,12 +141,6 @@
mViewTreeObserver.addOnComputeInternalInsetsListener(listener);
}
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "Test removeOnComputeInternalInsetsListener(OnComputeInternalInsetsListener)",
- method = "removeOnComputeInternalInsetsListener",
- args = {android.view.ViewTreeObserver.OnComputeInternalInsetsListener.class}
- )
public void testRemoveOnComputeInternalInsetsListener() {
final ListView lv1 = (ListView) mActivity.findViewById(R.id.listview1);
mViewTreeObserver = lv1.getViewTreeObserver();
@@ -190,12 +149,6 @@
mViewTreeObserver.removeOnComputeInternalInsetsListener(listener);
}
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "Test dispatchOnGlobalLayout()",
- method = "dispatchOnGlobalLayout",
- args = {}
- )
public void testDispatchOnGlobalLayout() {
final LinearLayout layout = (LinearLayout) mActivity.findViewById(R.id.linearlayout);
mViewTreeObserver = layout.getViewTreeObserver();
@@ -207,12 +160,6 @@
assertTrue(listener.hasCalledOnGlobalLayout());
}
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "Test dispatchOnPreDraw()",
- method = "dispatchOnPreDraw",
- args = {}
- )
public void testDispatchOnPreDraw() {
final LinearLayout layout = (LinearLayout) mActivity.findViewById(R.id.linearlayout);
mViewTreeObserver = layout.getViewTreeObserver();
@@ -224,12 +171,6 @@
assertTrue(listener.hasCalledOnPreDraw());
}
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "Test isAlive()",
- method = "isAlive",
- args = {}
- )
public void testIsAlive() {
final LinearLayout layout = (LinearLayout) mActivity.findViewById(R.id.linearlayout);
@@ -237,12 +178,6 @@
assertTrue(mViewTreeObserver.isAlive());
}
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "Test removeGlobalOnLayoutListener(OnGlobalLayoutListener)",
- method = "removeGlobalOnLayoutListener",
- args = {android.view.ViewTreeObserver.OnGlobalLayoutListener.class}
- )
public void testRemoveGlobalOnLayoutListener() {
final LinearLayout layout = (LinearLayout) mActivity.findViewById(R.id.linearlayout);
mViewTreeObserver = layout.getViewTreeObserver();
@@ -260,12 +195,6 @@
assertFalse(listener.hasCalledOnGlobalLayout());
}
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "Test removeOnGlobalFocusChangeListener(OnGlobalFocusChangeListener)",
- method = "removeOnGlobalFocusChangeListener",
- args = {android.view.ViewTreeObserver.OnGlobalFocusChangeListener.class}
- )
public void testRemoveOnGlobalFocusChangeListener() {
final LinearLayout layout = (LinearLayout) mActivity.findViewById(R.id.linearlayout);
final ListView lv1 = (ListView) mActivity.findViewById(R.id.listview1);
@@ -276,6 +205,7 @@
mViewTreeObserver.addOnGlobalFocusChangeListener(listener);
assertFalse(listener.hasCalledOnGlobalFocusChanged());
mInstrumentation.runOnMainSync(new Runnable() {
+ @Override
public void run() {
layout.requestChildFocus(lv1, lv2);
}
@@ -287,6 +217,7 @@
mViewTreeObserver.removeOnGlobalFocusChangeListener(listener);
assertFalse(listener.hasCalledOnGlobalFocusChanged());
mInstrumentation.runOnMainSync(new Runnable() {
+ @Override
public void run() {
layout.requestChildFocus(lv1, lv2);
}
@@ -295,12 +226,6 @@
assertFalse(listener.hasCalledOnGlobalFocusChanged());
}
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "Test removeOnPreDrawListener(OnPreDrawListener)",
- method = "removeOnPreDrawListener",
- args = {android.view.ViewTreeObserver.OnPreDrawListener.class}
- )
public void testRemoveOnPreDrawListener() {
final LinearLayout layout = (LinearLayout) mActivity.findViewById(R.id.linearlayout);
mViewTreeObserver = layout.getViewTreeObserver();
@@ -318,12 +243,6 @@
assertFalse(listener.hasCalledOnPreDraw());
}
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "Test removeOnTouchModeChangeListener(OnTouchModeChangeListener)",
- method = "removeOnTouchModeChangeListener",
- args = {android.view.ViewTreeObserver.OnTouchModeChangeListener.class}
- )
public void testRemoveOnTouchModeChangeListener() {
final Button b = (Button) mActivity.findViewById(R.id.button1);
// let the button be touch mode.
@@ -335,6 +254,7 @@
mViewTreeObserver.addOnTouchModeChangeListener(listener);
assertFalse(listener.hasCalledOnTouchModeChanged());
mInstrumentation.runOnMainSync(new Runnable() {
+ @Override
public void run() {
b.requestFocusFromTouch();
}
@@ -346,6 +266,7 @@
listener = new MockOnTouchModeChangeListener();
assertFalse(listener.hasCalledOnTouchModeChanged());
mInstrumentation.runOnMainSync(new Runnable() {
+ @Override
public void run() {
b.requestFocusFromTouch();
}
@@ -355,18 +276,6 @@
assertFalse(listener.hasCalledOnTouchModeChanged());
}
- @TestTargets({
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- method = "addOnScrollChangedListener",
- args = {android.view.ViewTreeObserver.OnScrollChangedListener.class}
- ),
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- method = "removeOnScrollChangedListener",
- args = {android.view.ViewTreeObserver.OnScrollChangedListener.class}
- )
- })
public void testAccessOnScrollChangedListener() throws Throwable {
layout(R.layout.scrollview_layout);
final ScrollView scrollView = (ScrollView) mActivity.findViewById(R.id.scroll_view);
@@ -378,6 +287,7 @@
mViewTreeObserver.addOnScrollChangedListener(listener);
runTestOnUiThread(new Runnable() {
+ @Override
public void run() {
scrollView.fullScroll(View.FOCUS_DOWN);
}
@@ -390,6 +300,7 @@
mViewTreeObserver.removeOnScrollChangedListener(listener);
runTestOnUiThread(new Runnable() {
+ @Override
public void run() {
scrollView.fullScroll(View.FOCUS_UP);
}
@@ -400,6 +311,7 @@
private class MockOnGlobalFocusChangeListener implements OnGlobalFocusChangeListener {
private boolean mCalledOnGlobalFocusChanged = false;
+ @Override
public void onGlobalFocusChanged(View oldFocus, View newFocus) {
mCalledOnGlobalFocusChanged = true;
}
@@ -416,6 +328,7 @@
private class MockOnGlobalLayoutListener implements OnGlobalLayoutListener {
private boolean mCalledOnGlobalLayout = false;
+ @Override
public void onGlobalLayout() {
mCalledOnGlobalLayout = true;
}
@@ -432,6 +345,7 @@
private class MockOnPreDrawListener implements OnPreDrawListener {
private boolean mCalledOnPreDraw = false;
+ @Override
public boolean onPreDraw() {
mCalledOnPreDraw = true;
return true;
@@ -449,6 +363,7 @@
private class MockOnTouchModeChangeListener implements OnTouchModeChangeListener {
private boolean mCalledOnTouchModeChanged = false;
+ @Override
public void onTouchModeChanged(boolean isInTouchMode) {
mCalledOnTouchModeChanged = true;
}
@@ -459,14 +374,8 @@
}
private class MockOnComputeInternalInsetsListener implements OnComputeInternalInsetsListener {
- private boolean mCalledOnComputeInternalInsets = false;
-
+ @Override
public void onComputeInternalInsets(InternalInsetsInfo inoutInfo) {
- mCalledOnComputeInternalInsets = true;
- }
-
- public boolean hasCalledOnComputeInternalInsets() {
- return mCalledOnComputeInternalInsets;
}
}
@@ -477,6 +386,7 @@
return mCalledOnScrollChanged;
}
+ @Override
public void onScrollChanged() {
mCalledOnScrollChanged = true;
}