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 package com.android.systemui.qs.car; 15 16 import static org.junit.Assert.assertNotNull; 17 import static org.mockito.Mockito.mock; 18 19 import android.content.Context; 20 import android.support.test.filters.SmallTest; 21 import android.testing.AndroidTestingRunner; 22 import android.testing.LayoutInflaterBuilder; 23 import android.testing.TestableLooper; 24 import android.testing.TestableLooper.RunWithLooper; 25 import android.view.View; 26 import android.widget.FrameLayout; 27 28 import com.android.keyguard.CarrierText; 29 import com.android.systemui.Dependency; 30 import com.android.systemui.SysuiBaseFragmentTest; 31 import com.android.systemui.statusbar.CommandQueue; 32 import com.android.systemui.statusbar.policy.Clock; 33 34 import org.junit.Before; 35 import org.junit.Ignore; 36 import org.junit.Test; 37 import org.junit.runner.RunWith; 38 39 /** 40 * Tests for {@link CarQSFragment}. 41 */ 42 @RunWith(AndroidTestingRunner.class) 43 @RunWithLooper(setAsMainLooper = true) 44 @SmallTest 45 @Ignore("Flaky") 46 public class CarQsFragmentTest extends SysuiBaseFragmentTest { 47 public CarQsFragmentTest() { 48 super(CarQSFragment.class); 49 } 50 51 @Before 52 public void initDependencies() { 53 mContext.addMockSystemService(Context.LAYOUT_INFLATER_SERVICE, 54 new LayoutInflaterBuilder(mContext) 55 .replace("com.android.systemui.statusbar.policy.SplitClockView", 56 FrameLayout.class) 57 .replace("TextClock", View.class) 58 .replace(CarrierText.class, View.class) 59 .replace(Clock.class, View.class) 60 .build()); 61 mSysuiContext.putComponent(CommandQueue.class, mock(CommandQueue.class)); 62 mDependency.injectTestDependency(Dependency.BG_LOOPER, 63 TestableLooper.get(this).getLooper()); 64 } 65 66 @Test 67 public void testLayoutInflation() { 68 CarQSFragment fragment = (CarQSFragment) mFragment; 69 mFragments.dispatchResume(); 70 71 assertNotNull(fragment.getHeader()); 72 assertNotNull(fragment.getFooter()); 73 } 74 75 @Test 76 public void testListening() { 77 CarQSFragment qs = (CarQSFragment) mFragment; 78 mFragments.dispatchResume(); 79 processAllMessages(); 80 81 qs.setListening(true); 82 processAllMessages(); 83 84 qs.setListening(false); 85 processAllMessages(); 86 } 87 } 88