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 @Ignore("failing")
     56 public class QSFragmentTest extends SysuiBaseFragmentTest {
     57 
     58     private MetricsLogger mMockMetricsLogger;
     59 
     60     public QSFragmentTest() {
     61         super(QSFragment.class);
     62     }
     63 
     64     @Before
     65     public void addLeakCheckDependencies() {
     66         mMockMetricsLogger = mDependency.injectMockDependency(MetricsLogger.class);
     67         mContext.addMockSystemService(Context.LAYOUT_INFLATER_SERVICE,
     68                 new LayoutInflaterBuilder(mContext)
     69                         .replace("com.android.systemui.statusbar.policy.SplitClockView",
     70                                 FrameLayout.class)
     71                         .replace("TextClock", View.class)
     72                         .replace(CarrierText.class, View.class)
     73                         .replace(Clock.class, View.class)
     74                         .build());
     75 
     76         mDependency.injectTestDependency(Dependency.BG_LOOPER,
     77                 TestableLooper.get(this).getLooper());
     78         mDependency.injectMockDependency(UserSwitcherController.class);
     79         injectLeakCheckedDependencies(ALL_SUPPORTED_CLASSES);
     80     }
     81 
     82     @Test
     83     public void testListening() {
     84         assertEquals(Looper.myLooper(), Looper.getMainLooper());
     85         QSFragment qs = (QSFragment) mFragment;
     86         mFragments.dispatchResume();
     87         processAllMessages();
     88         QSTileHost host = new QSTileHost(mContext, null, mock(StatusBarIconController.class));
     89         qs.setHost(host);
     90 
     91         qs.setListening(true);
     92         processAllMessages();
     93 
     94         qs.setListening(false);
     95         processAllMessages();
     96 
     97         // Manually push header through detach so it can handle standard cleanup it does on
     98         // removed from window.
     99         ((QuickStatusBarHeader) qs.getView().findViewById(R.id.header)).onDetachedFromWindow();
    100 
    101         host.destroy();
    102         processAllMessages();
    103     }
    104 
    105     @Test
    106     public void testSaveState() {
    107         QSFragment qs = (QSFragment) mFragment;
    108 
    109         mFragments.dispatchResume();
    110         processAllMessages();
    111 
    112         qs.setListening(true);
    113         qs.setExpanded(true);
    114         processAllMessages();
    115         recreateFragment();
    116         processAllMessages();
    117 
    118         // Get the reference to the new fragment.
    119         qs = (QSFragment) mFragment;
    120         assertTrue(qs.isListening());
    121         assertTrue(qs.isExpanded());
    122     }
    123 }
    124