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