1 /* 2 * Copyright (C) 2017 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License 15 */ 16 17 package com.android.systemui.statusbar.notification; 18 19 import static org.mockito.Mockito.mock; 20 import static org.mockito.Mockito.verify; 21 22 import android.support.test.runner.AndroidJUnit4; 23 import android.test.suitebuilder.annotation.SmallTest; 24 import android.widget.FrameLayout; 25 26 import com.android.systemui.SysuiTestCase; 27 import com.android.systemui.statusbar.ExpandableNotificationRow; 28 import com.android.systemui.statusbar.NotificationTestHelper; 29 30 import org.junit.Assert; 31 import org.junit.Before; 32 import org.junit.Test; 33 import org.junit.runner.RunWith; 34 35 @SmallTest 36 @RunWith(AndroidJUnit4.class) 37 public class AboveShelfObserverTest extends SysuiTestCase { 38 39 private AboveShelfObserver mObserver; 40 private FrameLayout mHostLayout; 41 private NotificationTestHelper mNotificationTestHelper; 42 private AboveShelfObserver.HasViewAboveShelfChangedListener mListener; 43 44 @Before 45 public void setUp() throws Exception { 46 mNotificationTestHelper = new NotificationTestHelper(getContext()); 47 mHostLayout = new FrameLayout(getContext()); 48 mObserver = new AboveShelfObserver(mHostLayout); 49 ExpandableNotificationRow row = mNotificationTestHelper.createRow(); 50 row.setAboveShelfChangedListener(mObserver); 51 mHostLayout.addView(row); 52 row = mNotificationTestHelper.createRow(); 53 row.setAboveShelfChangedListener(mObserver); 54 mHostLayout.addView(row); 55 mListener = mock(AboveShelfObserver.HasViewAboveShelfChangedListener.class); 56 } 57 58 @Test 59 public void testObserverChangesWhenGoingAbove() { 60 ExpandableNotificationRow row = (ExpandableNotificationRow) mHostLayout.getChildAt(0); 61 mObserver.setListener(mListener); 62 row.setHeadsUp(true); 63 verify(mListener).onHasViewsAboveShelfChanged(true); 64 } 65 66 @Test 67 public void testObserverChangesWhenGoingBelow() { 68 ExpandableNotificationRow row = (ExpandableNotificationRow) mHostLayout.getChildAt(0); 69 row.setHeadsUp(true); 70 mObserver.setListener(mListener); 71 row.setHeadsUp(false); 72 verify(mListener).onHasViewsAboveShelfChanged(false); 73 } 74 75 @Test 76 public void testStaysAboveWhenOneGoesAway() { 77 ExpandableNotificationRow row = (ExpandableNotificationRow) mHostLayout.getChildAt(0); 78 row.setHeadsUp(true); 79 row = (ExpandableNotificationRow) mHostLayout.getChildAt(1); 80 row.setHeadsUp(true); 81 row.setHeadsUp(false); 82 Assert.assertTrue("There are still views above the shelf but removing one cleared it", 83 mObserver.hasViewsAboveShelf()); 84 } 85 } 86 87