From ebdbbb98aa94098a1e9c97bafff6ff3559f6f937 Mon Sep 17 00:00:00 2001 From: Mady Mellor Date: Thu, 15 Nov 2018 14:36:48 -0800 Subject: [PATCH] Add some basic tests for bubble controller * Tests very basic state / interaction * Doesn't test how bubbles are integrated with the rest of the system... Test: atest BubbleControllerTest Bug: 111236845 Change-Id: I05e093dc2b7ea2983e018c316689874b66946726 --- .../systemui/bubbles/BubbleController.java | 9 +- .../phone/StatusBarWindowController.java | 2 +- .../bubbles/BubbleControllerTest.java | 151 ++++++++++++++++++ .../statusbar/NotificationTestHelper.java | 31 ++-- 4 files changed, 182 insertions(+), 11 deletions(-) create mode 100644 packages/SystemUI/tests/src/com/android/systemui/bubbles/BubbleControllerTest.java diff --git a/packages/SystemUI/src/com/android/systemui/bubbles/BubbleController.java b/packages/SystemUI/src/com/android/systemui/bubbles/BubbleController.java index e868f96426c92..4f5a48f256953 100644 --- a/packages/SystemUI/src/com/android/systemui/bubbles/BubbleController.java +++ b/packages/SystemUI/src/com/android/systemui/bubbles/BubbleController.java @@ -32,6 +32,7 @@ import android.view.ViewGroup; import android.view.WindowManager; import android.widget.FrameLayout; +import com.android.internal.annotations.VisibleForTesting; import com.android.systemui.Dependency; import com.android.systemui.R; import com.android.systemui.statusbar.notification.NotificationData; @@ -67,7 +68,8 @@ public class BubbleController { private Point mDisplaySize; // Bubbles get added to the status bar view - private StatusBarWindowController mStatusBarWindowController; + @VisibleForTesting + protected StatusBarWindowController mStatusBarWindowController; // Used for determining view rect for touch interaction private Rect mTempRect = new Rect(); @@ -297,6 +299,11 @@ public class BubbleController { return mTempRect; } + @VisibleForTesting + public BubbleStackView getStackView() { + return mStackView; + } + // TODO: factor in PIP location / maybe last place user had it /** * Gets an appropriate starting point to position the bubble stack. diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/phone/StatusBarWindowController.java b/packages/SystemUI/src/com/android/systemui/statusbar/phone/StatusBarWindowController.java index 62b6d91fc192b..fd1044b003bd4 100644 --- a/packages/SystemUI/src/com/android/systemui/statusbar/phone/StatusBarWindowController.java +++ b/packages/SystemUI/src/com/android/systemui/statusbar/phone/StatusBarWindowController.java @@ -84,7 +84,7 @@ public class StatusBarWindowController implements Callback, Dumpable, Configurat } @VisibleForTesting - StatusBarWindowController(Context context, WindowManager windowManager, + public StatusBarWindowController(Context context, WindowManager windowManager, IActivityManager activityManager, DozeParameters dozeParameters) { mContext = context; mWindowManager = windowManager; diff --git a/packages/SystemUI/tests/src/com/android/systemui/bubbles/BubbleControllerTest.java b/packages/SystemUI/tests/src/com/android/systemui/bubbles/BubbleControllerTest.java new file mode 100644 index 0000000000000..16ef63f1848ad --- /dev/null +++ b/packages/SystemUI/tests/src/com/android/systemui/bubbles/BubbleControllerTest.java @@ -0,0 +1,151 @@ +/* + * Copyright (C) 2018 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.android.systemui.bubbles; + +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertTrue; + +import android.app.IActivityManager; +import android.content.Context; +import android.support.test.filters.SmallTest; +import android.testing.AndroidTestingRunner; +import android.testing.TestableLooper; +import android.view.WindowManager; +import android.widget.FrameLayout; + +import com.android.systemui.SysuiTestCase; +import com.android.systemui.statusbar.NotificationTestHelper; +import com.android.systemui.statusbar.notification.row.ExpandableNotificationRow; +import com.android.systemui.statusbar.phone.DozeParameters; +import com.android.systemui.statusbar.phone.StatusBarWindowController; + +import org.junit.Before; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mockito.Mock; +import org.mockito.MockitoAnnotations; + +@SmallTest +@RunWith(AndroidTestingRunner.class) +@TestableLooper.RunWithLooper(setAsMainLooper = true) +public class BubbleControllerTest extends SysuiTestCase { + + @Mock + private WindowManager mWindowManager; + @Mock + private IActivityManager mActivityManager; + @Mock + private DozeParameters mDozeParameters; + @Mock + private FrameLayout mStatusBarView; + + private TestableBubbleController mBubbleController; + private StatusBarWindowController mStatusBarWindowController; + + private NotificationTestHelper mNotificationTestHelper; + private ExpandableNotificationRow mRow; + private ExpandableNotificationRow mRow2; + + @Before + public void setUp() throws Exception { + MockitoAnnotations.initMocks(this); + + // Bubbles get added to status bar window view + mStatusBarWindowController = new StatusBarWindowController(mContext, mWindowManager, + mActivityManager, mDozeParameters); + mStatusBarWindowController.add(mStatusBarView, 120 /* height */); + + // Need notifications for bubbles + mNotificationTestHelper = new NotificationTestHelper(mContext); + mRow = mNotificationTestHelper.createBubble(); + mRow2 = mNotificationTestHelper.createBubble(); + + mBubbleController = new TestableBubbleController(mContext, mStatusBarWindowController); + } + + @Test + public void testIsBubble() { + assertTrue(mRow.getEntry().isBubble()); + } + + @Test + public void testAddBubble() { + mBubbleController.addBubble(mRow.getEntry()); + assertTrue(mBubbleController.hasBubbles()); + } + + @Test + public void testHasBubbles() { + assertFalse(mBubbleController.hasBubbles()); + mBubbleController.addBubble(mRow.getEntry()); + assertTrue(mBubbleController.hasBubbles()); + } + + @Test + public void testRemoveBubble() { + mBubbleController.addBubble(mRow.getEntry()); + assertTrue(mBubbleController.hasBubbles()); + + mBubbleController.removeBubble(mRow.getEntry().key); + assertFalse(mStatusBarWindowController.getBubblesShowing()); + } + + @Test + public void testDismissStack() { + mBubbleController.addBubble(mRow.getEntry()); + mBubbleController.addBubble(mRow2.getEntry()); + assertTrue(mBubbleController.hasBubbles()); + + mBubbleController.dismissStack(); + assertFalse(mStatusBarWindowController.getBubblesShowing()); + } + + @Test + public void testIsStackExpanded() { + assertFalse(mBubbleController.isStackExpanded()); + mBubbleController.addBubble(mRow.getEntry()); + + BubbleStackView stackView = mBubbleController.getStackView(); + stackView.animateExpansion(true /* expanded */); + assertTrue(mBubbleController.isStackExpanded()); + + stackView.animateExpansion(false /* expanded */); + assertFalse(mBubbleController.isStackExpanded()); + } + + @Test + public void testCollapseStack() { + mBubbleController.addBubble(mRow.getEntry()); + mBubbleController.addBubble(mRow2.getEntry()); + + BubbleStackView stackView = mBubbleController.getStackView(); + stackView.animateExpansion(true /* expanded */); + assertTrue(mBubbleController.isStackExpanded()); + + mBubbleController.collapseStack(); + assertFalse(mBubbleController.isStackExpanded()); + } + + static class TestableBubbleController extends BubbleController { + + TestableBubbleController(Context context, + StatusBarWindowController statusBarWindowController) { + super(context); + mStatusBarWindowController = statusBarWindowController; + } + } +} diff --git a/packages/SystemUI/tests/src/com/android/systemui/statusbar/NotificationTestHelper.java b/packages/SystemUI/tests/src/com/android/systemui/statusbar/NotificationTestHelper.java index aca1f90b5aa86..724e1b6ffcfec 100644 --- a/packages/SystemUI/tests/src/com/android/systemui/statusbar/NotificationTestHelper.java +++ b/packages/SystemUI/tests/src/com/android/systemui/statusbar/NotificationTestHelper.java @@ -33,9 +33,9 @@ import android.widget.RemoteViews; import com.android.systemui.R; import com.android.systemui.statusbar.notification.NotificationData; +import com.android.systemui.statusbar.notification.row.ExpandableNotificationRow; import com.android.systemui.statusbar.notification.row.NotificationInflater.InflationFlag; import com.android.systemui.statusbar.notification.row.NotificationInflaterTest; -import com.android.systemui.statusbar.notification.row.ExpandableNotificationRow; import com.android.systemui.statusbar.phone.HeadsUpManagerPhone; import com.android.systemui.statusbar.phone.NotificationGroupManager; import com.android.systemui.statusbar.policy.HeadsUpManager; @@ -86,7 +86,8 @@ public class NotificationTestHelper { * @throws Exception */ public ExpandableNotificationRow createRow(String pkg, int uid) throws Exception { - return createRow(pkg, uid, false /* isGroupSummary */, null /* groupKey */); + return createRow(pkg, uid, false /* isGroupSummary */, null /* groupKey */, + false /* isBubble */); } /** @@ -97,7 +98,8 @@ public class NotificationTestHelper { * @throws Exception */ public ExpandableNotificationRow createRow(Notification notification) throws Exception { - return generateRow(notification, PKG, UID, 0 /* extraInflationFlags */); + return generateRow(notification, PKG, UID, 0 /* extraInflationFlags */, + false /* isBubble */); } /** @@ -110,7 +112,8 @@ public class NotificationTestHelper { */ public ExpandableNotificationRow createRow(@InflationFlag int extraInflationFlags) throws Exception { - return generateRow(createNotification(), PKG, UID, extraInflationFlags); + return generateRow(createNotification(), PKG, UID, extraInflationFlags, + false /* isBubble */); } /** @@ -131,12 +134,20 @@ public class NotificationTestHelper { return createGroup(2); } + /** + * Retursn an {@link ExpandableNotificationRow} that should be a bubble. + */ + public ExpandableNotificationRow createBubble() throws Exception { + return createRow(PKG, UID, false /* isGroupSummary */, null /* groupKey */, + true /* isBubble */); + } + private ExpandableNotificationRow createGroupSummary(String groupkey) throws Exception { - return createRow(PKG, UID, true /* isGroupSummary */, groupkey); + return createRow(PKG, UID, true /* isGroupSummary */, groupkey, false); } private ExpandableNotificationRow createGroupChild(String groupkey) throws Exception { - return createRow(PKG, UID, false /* isGroupSummary */, groupkey); + return createRow(PKG, UID, false /* isGroupSummary */, groupkey, false); } /** @@ -146,6 +157,7 @@ public class NotificationTestHelper { * @param uid uid used for creating a {@link StatusBarNotification} * @param isGroupSummary whether the notification row is a group summary * @param groupKey the group key for the notification group used across notifications + * @param isBubble * @return a row with that's either a standalone notification or a group notification if the * groupKey is non-null * @throws Exception @@ -154,10 +166,10 @@ public class NotificationTestHelper { String pkg, int uid, boolean isGroupSummary, - @Nullable String groupKey) + @Nullable String groupKey, boolean isBubble) throws Exception { Notification notif = createNotification(isGroupSummary, groupKey); - return generateRow(notif, pkg, uid, 0 /* inflationFlags */); + return generateRow(notif, pkg, uid, 0 /* inflationFlags */, isBubble); } /** @@ -202,7 +214,7 @@ public class NotificationTestHelper { Notification notification, String pkg, int uid, - @InflationFlag int extraInflationFlags) + @InflationFlag int extraInflationFlags, boolean isBubble) throws Exception { LayoutInflater inflater = (LayoutInflater) mContext.getSystemService( mContext.LAYOUT_INFLATER_SERVICE); @@ -232,6 +244,7 @@ public class NotificationTestHelper { entry.channel = new NotificationChannel( notification.getChannelId(), notification.getChannelId(), IMPORTANCE_DEFAULT); entry.channel.setBlockableSystem(true); + entry.setIsBubble(isBubble); row.setEntry(entry); row.getNotificationInflater().addInflationFlags(extraInflationFlags); NotificationInflaterTest.runThenWaitForInflation(