Home | History | Annotate | Download | only in qs
      1 /*
      2  * Copyright (C) 2016 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.qs;
     16 
     17 import static org.junit.Assert.assertEquals;
     18 import static org.junit.Assert.assertTrue;
     19 import static org.mockito.Mockito.mock;
     20 
     21 import android.app.FragmentController;
     22 import android.app.FragmentManagerNonConfig;
     23 import android.os.Looper;
     24 import android.support.test.filters.FlakyTest;
     25 
     26 import com.android.internal.logging.MetricsLogger;
     27 import com.android.keyguard.CarrierText;
     28 import com.android.systemui.Dependency;
     29 import com.android.systemui.R;
     30 
     31 import android.os.Parcelable;
     32 import android.support.test.filters.SmallTest;
     33 import android.testing.AndroidTestingRunner;
     34 
     35 import com.android.systemui.SysuiBaseFragmentTest;
     36 import com.android.systemui.statusbar.phone.StatusBarIconController;
     37 import com.android.systemui.statusbar.policy.Clock;
     38 import com.android.systemui.statusbar.policy.UserSwitcherController;
     39 import android.testing.LayoutInflaterBuilder;
     40 import android.testing.TestableLooper;
     41 import android.testing.TestableLooper.RunWithLooper;
     42 
     43 import org.junit.Before;
     44 import org.junit.Ignore;
     45 import org.junit.Test;
     46 import org.junit.runner.RunWith;
     47 
     48 import android.content.Context;
     49 import android.view.View;
     50 import android.widget.FrameLayout;
     51 
     52 @RunWith(AndroidTestingRunner.class)
     53 @RunWithLooper(setAsMainLooper = true)
     54 @SmallTest
     55 public class QSFragmentTest extends SysuiBaseFragmentTest {
     56 
     57     private MetricsLogger mMockMetricsLogger;
     58 
     59     public QSFragmentTest() {
     60         super(QSFragment.class);
     61     }
     62 
     63     @Before
     64     public void addLeakCheckDependencies() {
     65         mMockMetricsLogger = mDependency.injectMockDependency(MetricsLogger.class);
     66         mContext.addMockSystemService(Context.LAYOUT_INFLATER_SERVICE,
     67                 new LayoutInflaterBuilder(mContext)
     68                         .replace("com.android.systemui.statusbar.policy.SplitClockView",
     69                                 FrameLayout.class)
     70                         .replace("TextClock", View.class)
     71                         .replace(CarrierText.class, View.class)
     72                         .replace(Clock.class, View.class)
     73                         .build());
     74 
     75         mDependency.injectTestDependency(Dependency.BG_LOOPER,
     76                 TestableLooper.get(this).getLooper());
     77         mDependency.injectMockDependency(UserSwitcherController.class);
     78         injectLeakCheckedDependencies(ALL_SUPPORTED_CLASSES);
     79     }
     80 
     81     @Test
     82     public void testListening() {
     83         assertEquals(Looper.myLooper(), Looper.getMainLooper());
     84         QSFragment qs = (QSFragment) mFragment;
     85         mFragments.dispatchResume();
     86         processAllMessages();
     87         QSTileHost host = new QSTileHost(mContext, null, mock(StatusBarIconController.class));
     88         qs.setHost(host);
     89 
     90         qs.setListening(true);
     91         processAllMessages();
     92 
     93         qs.setListening(false);
     94         processAllMessages();
     95 
     96         // Manually push header through detach so it can handle standard cleanup it does on
     97         // removed from window.
     98         ((QuickStatusBarHeader) qs.getView().findViewById(R.id.header)).onDetachedFromWindow();
     99 
    100         host.destroy();
    101         processAllMessages();
    102     }
    103 
    104     @Test
    105     public void testSaveState() {
    106         QSFragment qs = (QSFragment) mFragment;
    107 
    108         mFragments.dispatchResume();
    109         processAllMessages();
    110 
    111         qs.setListening(true);
    112         qs.setExpanded(true);
    113         processAllMessages();
    114         recreateFragment();
    115         processAllMessages();
    116 
    117         // Get the reference to the new fragment.
    118         qs = (QSFragment) mFragment;
    119         assertTrue(qs.isListening());
    120         assertTrue(qs.isExpanded());
    121     }
    122 }
    123