Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit ebdbbb98 authored by Mady Mellor's avatar Mady Mellor
Browse files

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
parent 490db5dd
Loading
Loading
Loading
Loading
+8 −1
Original line number Diff line number Diff line
@@ -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.
+1 −1
Original line number Diff line number Diff line
@@ -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;
+151 −0
Original line number Diff line number Diff line
/*
 * 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;
        }
    }
}
+22 −9
Original line number Diff line number Diff line
@@ -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(