Home | History | Annotate | Download | only in phone
      1 /*
      2  * Copyright (C) 2017 The Android Open Source Project
      3  *
      4  * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file
      5  * except in compliance with the License. You may obtain a copy of the License at
      6  *
      7  *      http://www.apache.org/licenses/LICENSE-2.0
      8  *
      9  * Unless required by applicable law or agreed to in writing, software distributed under the
     10  * License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
     11  * KIND, either express or implied. See the License for the specific language governing
     12  * permissions and limitations under the License.
     13  */
     14 
     15 package com.android.systemui.statusbar.phone;
     16 
     17 import static org.mockito.Mockito.mock;
     18 import static org.mockito.Mockito.when;
     19 
     20 import android.content.Context;
     21 import android.os.Looper;
     22 import android.support.test.filters.SmallTest;
     23 import android.testing.AndroidTestingRunner;
     24 import android.testing.LeakCheck.Tracker;
     25 import android.view.Display;
     26 import android.view.WindowManager;
     27 
     28 import com.android.systemui.Dependency;
     29 
     30 import com.android.systemui.OverviewProxyService;
     31 import com.android.systemui.SysuiBaseFragmentTest;
     32 import com.android.systemui.recents.Recents;
     33 import com.android.systemui.stackdivider.Divider;
     34 import com.android.systemui.statusbar.CommandQueue;
     35 import com.android.systemui.statusbar.policy.AccessibilityManagerWrapper;
     36 
     37 import android.testing.TestableLooper.RunWithLooper;
     38 import android.view.accessibility.AccessibilityManager.AccessibilityServicesStateChangeListener;
     39 
     40 import org.junit.Before;
     41 import org.junit.Test;
     42 import org.junit.runner.RunWith;
     43 
     44 @RunWith(AndroidTestingRunner.class)
     45 @RunWithLooper(setAsMainLooper = true)
     46 @SmallTest
     47 public class NavigationBarFragmentTest extends SysuiBaseFragmentTest {
     48 
     49     public NavigationBarFragmentTest() {
     50         super(NavigationBarFragment.class);
     51     }
     52 
     53     protected void createRootView() {
     54         mView = new NavigationBarFrame(mContext);
     55     }
     56 
     57     @Before
     58     public void setup() {
     59         mDependency.injectTestDependency(Dependency.BG_LOOPER, Looper.getMainLooper());
     60         mSysuiContext.putComponent(CommandQueue.class, mock(CommandQueue.class));
     61         mSysuiContext.putComponent(StatusBar.class, mock(StatusBar.class));
     62         mSysuiContext.putComponent(Recents.class, mock(Recents.class));
     63         mSysuiContext.putComponent(Divider.class, mock(Divider.class));
     64         injectLeakCheckedDependencies(ALL_SUPPORTED_CLASSES);
     65         mDependency.injectMockDependency(OverviewProxyService.class);
     66         WindowManager windowManager = mock(WindowManager.class);
     67         Display defaultDisplay = mContext.getSystemService(WindowManager.class).getDefaultDisplay();
     68         when(windowManager.getDefaultDisplay()).thenReturn(
     69                 defaultDisplay);
     70         mContext.addMockSystemService(Context.WINDOW_SERVICE, windowManager);
     71 
     72         Tracker tracker = mLeakCheck.getTracker("accessibility_manager");
     73         AccessibilityManagerWrapper wrapper = new AccessibilityManagerWrapper(mContext) {
     74             @Override
     75             public void addCallback(AccessibilityServicesStateChangeListener listener) {
     76                 tracker.getLeakInfo(listener).addAllocation(new Throwable());
     77             }
     78 
     79             @Override
     80             public void removeCallback(AccessibilityServicesStateChangeListener listener) {
     81                 tracker.getLeakInfo(listener).clearAllocations();
     82             }
     83         };
     84         mDependency.injectTestDependency(AccessibilityManagerWrapper.class, wrapper);
     85     }
     86 
     87     @Test
     88     public void testHomeLongPress() {
     89         NavigationBarFragment navigationBarFragment = (NavigationBarFragment) mFragment;
     90 
     91         mFragments.dispatchResume();
     92         processAllMessages();
     93         navigationBarFragment.onHomeLongClick(navigationBarFragment.getView());
     94     }
     95 
     96 }
     97