15cf1d0589a0045ee5f01802975f394847e891215Selim Cinek/* 25cf1d0589a0045ee5f01802975f394847e891215Selim Cinek * Copyright (C) 2017 The Android Open Source Project 35cf1d0589a0045ee5f01802975f394847e891215Selim Cinek * 45cf1d0589a0045ee5f01802975f394847e891215Selim Cinek * Licensed under the Apache License, Version 2.0 (the "License"); 55cf1d0589a0045ee5f01802975f394847e891215Selim Cinek * you may not use this file except in compliance with the License. 65cf1d0589a0045ee5f01802975f394847e891215Selim Cinek * You may obtain a copy of the License at 75cf1d0589a0045ee5f01802975f394847e891215Selim Cinek * 85cf1d0589a0045ee5f01802975f394847e891215Selim Cinek * http://www.apache.org/licenses/LICENSE-2.0 95cf1d0589a0045ee5f01802975f394847e891215Selim Cinek * 105cf1d0589a0045ee5f01802975f394847e891215Selim Cinek * Unless required by applicable law or agreed to in writing, software 115cf1d0589a0045ee5f01802975f394847e891215Selim Cinek * distributed under the License is distributed on an "AS IS" BASIS, 125cf1d0589a0045ee5f01802975f394847e891215Selim Cinek * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 135cf1d0589a0045ee5f01802975f394847e891215Selim Cinek * See the License for the specific language governing permissions and 145cf1d0589a0045ee5f01802975f394847e891215Selim Cinek * limitations under the License 155cf1d0589a0045ee5f01802975f394847e891215Selim Cinek */ 165cf1d0589a0045ee5f01802975f394847e891215Selim Cinek 175cf1d0589a0045ee5f01802975f394847e891215Selim Cinekpackage com.android.systemui.statusbar.notification; 185cf1d0589a0045ee5f01802975f394847e891215Selim Cinek 195cf1d0589a0045ee5f01802975f394847e891215Selim Cinekimport static org.mockito.Mockito.mock; 205cf1d0589a0045ee5f01802975f394847e891215Selim Cinekimport static org.mockito.Mockito.verify; 215cf1d0589a0045ee5f01802975f394847e891215Selim Cinek 225cf1d0589a0045ee5f01802975f394847e891215Selim Cinekimport android.support.test.runner.AndroidJUnit4; 235cf1d0589a0045ee5f01802975f394847e891215Selim Cinekimport android.test.suitebuilder.annotation.SmallTest; 246dceace0eddd08156e6b71c17e3de4ed5f4f2f41Jason Monkimport android.testing.AndroidTestingRunner; 256dceace0eddd08156e6b71c17e3de4ed5f4f2f41Jason Monkimport android.testing.TestableLooper.RunWithLooper; 265cf1d0589a0045ee5f01802975f394847e891215Selim Cinekimport android.widget.FrameLayout; 275cf1d0589a0045ee5f01802975f394847e891215Selim Cinek 285cf1d0589a0045ee5f01802975f394847e891215Selim Cinekimport com.android.systemui.SysuiTestCase; 295cf1d0589a0045ee5f01802975f394847e891215Selim Cinekimport com.android.systemui.statusbar.ExpandableNotificationRow; 305cf1d0589a0045ee5f01802975f394847e891215Selim Cinekimport com.android.systemui.statusbar.NotificationTestHelper; 315cf1d0589a0045ee5f01802975f394847e891215Selim Cinek 325cf1d0589a0045ee5f01802975f394847e891215Selim Cinekimport org.junit.Assert; 335cf1d0589a0045ee5f01802975f394847e891215Selim Cinekimport org.junit.Before; 345cf1d0589a0045ee5f01802975f394847e891215Selim Cinekimport org.junit.Test; 355cf1d0589a0045ee5f01802975f394847e891215Selim Cinekimport org.junit.runner.RunWith; 365cf1d0589a0045ee5f01802975f394847e891215Selim Cinek 375cf1d0589a0045ee5f01802975f394847e891215Selim Cinek@SmallTest 386dceace0eddd08156e6b71c17e3de4ed5f4f2f41Jason Monk@RunWith(AndroidTestingRunner.class) 396dceace0eddd08156e6b71c17e3de4ed5f4f2f41Jason Monk@RunWithLooper(setAsMainLooper = true) 405cf1d0589a0045ee5f01802975f394847e891215Selim Cinekpublic class AboveShelfObserverTest extends SysuiTestCase { 415cf1d0589a0045ee5f01802975f394847e891215Selim Cinek 425cf1d0589a0045ee5f01802975f394847e891215Selim Cinek private AboveShelfObserver mObserver; 435cf1d0589a0045ee5f01802975f394847e891215Selim Cinek private FrameLayout mHostLayout; 445cf1d0589a0045ee5f01802975f394847e891215Selim Cinek private NotificationTestHelper mNotificationTestHelper; 455cf1d0589a0045ee5f01802975f394847e891215Selim Cinek private AboveShelfObserver.HasViewAboveShelfChangedListener mListener; 465cf1d0589a0045ee5f01802975f394847e891215Selim Cinek 475cf1d0589a0045ee5f01802975f394847e891215Selim Cinek @Before 485cf1d0589a0045ee5f01802975f394847e891215Selim Cinek public void setUp() throws Exception { 495cf1d0589a0045ee5f01802975f394847e891215Selim Cinek mNotificationTestHelper = new NotificationTestHelper(getContext()); 505cf1d0589a0045ee5f01802975f394847e891215Selim Cinek mHostLayout = new FrameLayout(getContext()); 515cf1d0589a0045ee5f01802975f394847e891215Selim Cinek mObserver = new AboveShelfObserver(mHostLayout); 525cf1d0589a0045ee5f01802975f394847e891215Selim Cinek ExpandableNotificationRow row = mNotificationTestHelper.createRow(); 535cf1d0589a0045ee5f01802975f394847e891215Selim Cinek row.setAboveShelfChangedListener(mObserver); 545cf1d0589a0045ee5f01802975f394847e891215Selim Cinek mHostLayout.addView(row); 555cf1d0589a0045ee5f01802975f394847e891215Selim Cinek row = mNotificationTestHelper.createRow(); 565cf1d0589a0045ee5f01802975f394847e891215Selim Cinek row.setAboveShelfChangedListener(mObserver); 575cf1d0589a0045ee5f01802975f394847e891215Selim Cinek mHostLayout.addView(row); 585cf1d0589a0045ee5f01802975f394847e891215Selim Cinek mListener = mock(AboveShelfObserver.HasViewAboveShelfChangedListener.class); 595cf1d0589a0045ee5f01802975f394847e891215Selim Cinek } 605cf1d0589a0045ee5f01802975f394847e891215Selim Cinek 615cf1d0589a0045ee5f01802975f394847e891215Selim Cinek @Test 625cf1d0589a0045ee5f01802975f394847e891215Selim Cinek public void testObserverChangesWhenGoingAbove() { 635cf1d0589a0045ee5f01802975f394847e891215Selim Cinek ExpandableNotificationRow row = (ExpandableNotificationRow) mHostLayout.getChildAt(0); 645cf1d0589a0045ee5f01802975f394847e891215Selim Cinek mObserver.setListener(mListener); 655cf1d0589a0045ee5f01802975f394847e891215Selim Cinek row.setHeadsUp(true); 665cf1d0589a0045ee5f01802975f394847e891215Selim Cinek verify(mListener).onHasViewsAboveShelfChanged(true); 675cf1d0589a0045ee5f01802975f394847e891215Selim Cinek } 685cf1d0589a0045ee5f01802975f394847e891215Selim Cinek 695cf1d0589a0045ee5f01802975f394847e891215Selim Cinek @Test 705cf1d0589a0045ee5f01802975f394847e891215Selim Cinek public void testObserverChangesWhenGoingBelow() { 715cf1d0589a0045ee5f01802975f394847e891215Selim Cinek ExpandableNotificationRow row = (ExpandableNotificationRow) mHostLayout.getChildAt(0); 725cf1d0589a0045ee5f01802975f394847e891215Selim Cinek row.setHeadsUp(true); 735cf1d0589a0045ee5f01802975f394847e891215Selim Cinek mObserver.setListener(mListener); 745cf1d0589a0045ee5f01802975f394847e891215Selim Cinek row.setHeadsUp(false); 755cf1d0589a0045ee5f01802975f394847e891215Selim Cinek verify(mListener).onHasViewsAboveShelfChanged(false); 765cf1d0589a0045ee5f01802975f394847e891215Selim Cinek } 775cf1d0589a0045ee5f01802975f394847e891215Selim Cinek 785cf1d0589a0045ee5f01802975f394847e891215Selim Cinek @Test 795cf1d0589a0045ee5f01802975f394847e891215Selim Cinek public void testStaysAboveWhenOneGoesAway() { 805cf1d0589a0045ee5f01802975f394847e891215Selim Cinek ExpandableNotificationRow row = (ExpandableNotificationRow) mHostLayout.getChildAt(0); 815cf1d0589a0045ee5f01802975f394847e891215Selim Cinek row.setHeadsUp(true); 825cf1d0589a0045ee5f01802975f394847e891215Selim Cinek row = (ExpandableNotificationRow) mHostLayout.getChildAt(1); 835cf1d0589a0045ee5f01802975f394847e891215Selim Cinek row.setHeadsUp(true); 845cf1d0589a0045ee5f01802975f394847e891215Selim Cinek row.setHeadsUp(false); 855cf1d0589a0045ee5f01802975f394847e891215Selim Cinek Assert.assertTrue("There are still views above the shelf but removing one cleared it", 865cf1d0589a0045ee5f01802975f394847e891215Selim Cinek mObserver.hasViewsAboveShelf()); 875cf1d0589a0045ee5f01802975f394847e891215Selim Cinek } 885cf1d0589a0045ee5f01802975f394847e891215Selim Cinek} 895cf1d0589a0045ee5f01802975f394847e891215Selim Cinek 90