Fix CTS issues for PopupWindowTest
* Update absolute positioned popup window tests to opt-out of the new
default behavior that sets FLAG_LAYOUT_ATTACHED_IN_DECOR for new
apps to prevent their windows from being positioned beneath system
windows.
* Revert watch-specific configuration code in
MockPopupWindowCtsActivity that was causing problems with a standard
test on other devices.
Bug 18664899
Change-Id: I26426a3312f15a6f9841b8d417c601ef6a072901
diff --git a/tests/tests/widget/src/android/widget/cts/MockPopupWindowCtsActivity.java b/tests/tests/widget/src/android/widget/cts/MockPopupWindowCtsActivity.java
index 41018a9..9589fec 100644
--- a/tests/tests/widget/src/android/widget/cts/MockPopupWindowCtsActivity.java
+++ b/tests/tests/widget/src/android/widget/cts/MockPopupWindowCtsActivity.java
@@ -30,28 +30,10 @@
* Stub activity for testing {@link PopupWindow}
*/
public class MockPopupWindowCtsActivity extends Activity {
- private boolean isFirstRun = true;
-
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
- Window window = getWindow();
- final View decor = window.getDecorView();
- decor.setOnApplyWindowInsetsListener(new OnApplyWindowInsetsListener() {
- @Override
- public WindowInsets onApplyWindowInsets(View v, WindowInsets insets) {
- if (isFirstRun) {
- if (insets.isRound()) {
- decor.setPadding(decor.getPaddingLeft(), decor.getPaddingTop(),
- decor.getPaddingRight(),
- decor.getPaddingBottom() + insets.getSystemWindowInsetBottom());
- }
- isFirstRun = false;
- setContentView(R.layout.popupwindow);
- }
- return insets.consumeSystemWindowInsets();
- }
- });
+ setContentView(R.layout.popupwindow);
}
}
diff --git a/tests/tests/widget/src/android/widget/cts/PopupWindowTest.java b/tests/tests/widget/src/android/widget/cts/PopupWindowTest.java
index e1742c8..c14bb03 100644
--- a/tests/tests/widget/src/android/widget/cts/PopupWindowTest.java
+++ b/tests/tests/widget/src/android/widget/cts/PopupWindowTest.java
@@ -273,18 +273,21 @@
}
public void testShowAtLocation() {
- int[] viewInWindowXY = new int[2];
- int[] viewOnScreenXY = new int[2];
+ int[] popupContentViewInWindowXY = new int[2];
+ int[] popupContentViewOnScreenXY = new int[2];
mPopupWindow = createPopupWindow(createPopupContent());
+ // Do not attach within the decor; we will be measuring location
+ // with regard to screen coordinates.
+ mPopupWindow.setAttachedInDecor(false);
final View upperAnchor = mActivity.findViewById(R.id.anchor_upper);
final int xOff = 10;
final int yOff = 21;
assertFalse(mPopupWindow.isShowing());
- mPopupWindow.getContentView().getLocationInWindow(viewInWindowXY);
- assertEquals(0, viewInWindowXY[0]);
- assertEquals(0, viewInWindowXY[1]);
+ mPopupWindow.getContentView().getLocationInWindow(popupContentViewInWindowXY);
+ assertEquals(0, popupContentViewInWindowXY[0]);
+ assertEquals(0, popupContentViewInWindowXY[1]);
mInstrumentation.runOnMainSync(new Runnable() {
public void run() {
@@ -294,12 +297,12 @@
mInstrumentation.waitForIdleSync();
assertTrue(mPopupWindow.isShowing());
- mPopupWindow.getContentView().getLocationInWindow(viewInWindowXY);
- mPopupWindow.getContentView().getLocationOnScreen(viewOnScreenXY);
- assertTrue(viewInWindowXY[0] >= 0);
- assertTrue(viewInWindowXY[1] >= 0);
- assertEquals(viewInWindowXY[0] + xOff, viewOnScreenXY[0]);
- assertEquals(viewInWindowXY[1] + yOff, viewOnScreenXY[1]);
+ mPopupWindow.getContentView().getLocationInWindow(popupContentViewInWindowXY);
+ mPopupWindow.getContentView().getLocationOnScreen(popupContentViewOnScreenXY);
+ assertTrue(popupContentViewInWindowXY[0] >= 0);
+ assertTrue(popupContentViewInWindowXY[1] >= 0);
+ assertEquals(popupContentViewInWindowXY[0] + xOff, popupContentViewOnScreenXY[0]);
+ assertEquals(popupContentViewInWindowXY[1] + yOff, popupContentViewOnScreenXY[1]);
dismissPopup();
}
@@ -453,6 +456,9 @@
mInstrumentation.runOnMainSync(new Runnable() {
public void run() {
mPopupWindow = createPopupWindow(createPopupContent());
+ // Do not attach within the decor; we will be measuring location
+ // with regard to screen coordinates.
+ mPopupWindow.setAttachedInDecor(false);
}
});