NavigationBarFragmentTest.java revision 28d5d220cc66eb4263aaae083a8496950258642b
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 15package com.android.systemui.statusbar.phone; 16 17import static org.mockito.Mockito.mock; 18import static org.mockito.Mockito.when; 19 20import android.content.Context; 21import android.os.Looper; 22import android.view.Display; 23import android.view.WindowManager; 24 25import com.android.systemui.Dependency; 26import com.android.systemui.FragmentTestCase; 27import com.android.systemui.SysUIRunner; 28import com.android.systemui.recents.Recents; 29import com.android.systemui.stackdivider.Divider; 30import com.android.systemui.statusbar.CommandQueue; 31import com.android.systemui.utils.TestableLooper.RunWithLooper; 32 33import org.junit.Before; 34import org.junit.Test; 35import org.junit.runner.RunWith; 36 37@RunWith(SysUIRunner.class) 38@RunWithLooper(setAsMainLooper = true) 39public class NavigationBarFragmentTest extends FragmentTestCase { 40 41 public NavigationBarFragmentTest() { 42 super(NavigationBarFragment.class); 43 } 44 45 @Before 46 public void setup() { 47 injectTestDependency(Dependency.BG_LOOPER, Looper.getMainLooper()); 48 mContext.putComponent(CommandQueue.class, mock(CommandQueue.class)); 49 mContext.putComponent(StatusBar.class, mock(StatusBar.class)); 50 mContext.putComponent(Recents.class, mock(Recents.class)); 51 mContext.putComponent(Divider.class, mock(Divider.class)); 52 injectLeakCheckedDependencies(ALL_SUPPORTED_CLASSES); 53 WindowManager windowManager = mock(WindowManager.class); 54 Display defaultDisplay = mContext.getSystemService(WindowManager.class).getDefaultDisplay(); 55 when(windowManager.getDefaultDisplay()).thenReturn( 56 defaultDisplay); 57 mContext.addMockSystemService(Context.WINDOW_SERVICE, windowManager); 58 } 59 60 @Test 61 public void testHomeLongPress() { 62 NavigationBarFragment navigationBarFragment = (NavigationBarFragment) mFragment; 63 64 mFragments.dispatchResume(); 65 processAllMessages(); 66 navigationBarFragment.onHomeLongClick(navigationBarFragment.getView()); 67 } 68 69} 70