Home | History | Annotate | Download | only in util
      1 /*
      2  * Copyright (C) 2017 The Android Open Source Project
      3  *
      4  * Licensed under the Apache License, Version 2.0 (the "License");
      5  * you may not use this file except in compliance with the License.
      6  * You may obtain a copy of the License at
      7  *
      8  *      http://www.apache.org/licenses/LICENSE-2.0
      9  *
     10  * Unless required by applicable law or agreed to in writing, software
     11  * distributed under the License is distributed on an "AS IS" BASIS,
     12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
     13  * See the License for the specific language governing permissions and
     14  * limitations under the License.
     15  */
     16 
     17 package com.android.setupwizardlib.util;
     18 
     19 import static org.junit.Assert.assertEquals;
     20 
     21 import android.content.Context;
     22 import android.content.res.TypedArray;
     23 import android.support.test.InstrumentationRegistry;
     24 import android.support.test.filters.SmallTest;
     25 import android.support.test.runner.AndroidJUnit4;
     26 import android.view.ContextThemeWrapper;
     27 
     28 import com.android.setupwizardlib.test.R;
     29 
     30 import org.junit.Before;
     31 import org.junit.Test;
     32 import org.junit.runner.RunWith;
     33 
     34 @RunWith(AndroidJUnit4.class)
     35 @SmallTest
     36 public class FallbackThemeWrapperTest {
     37 
     38     private FallbackThemeWrapper mThemedContext;
     39 
     40     @Before
     41     public void setUp() {
     42         Context baseContext = new ContextThemeWrapper(
     43                 InstrumentationRegistry.getContext(),
     44                 R.style.TestBaseTheme);
     45         mThemedContext = new FallbackThemeWrapper(baseContext, R.style.TestFallbackTheme);
     46     }
     47 
     48     @Test
     49     public void testThemeValueOnlyInBase() {
     50         final TypedArray a =
     51                 mThemedContext.obtainStyledAttributes(new int[] {android.R.attr.background});
     52         assertEquals(0xffff0000, a.getColor(0, 0));
     53         a.recycle();
     54     }
     55 
     56     @Test
     57     public void testThemeValueOnlyInFallback() {
     58         final TypedArray a =
     59                 mThemedContext.obtainStyledAttributes(new int[] {android.R.attr.foreground});
     60         assertEquals(0xff0000ff, a.getColor(0, 0));
     61         a.recycle();
     62     }
     63 
     64     @Test
     65     public void testThemeValueInBoth() {
     66         final TypedArray a =
     67                 mThemedContext.obtainStyledAttributes(new int[] {android.R.attr.theme});
     68         assertEquals(R.style.TestBaseTheme, a.getResourceId(0, 0));
     69         a.recycle();
     70     }
     71 }
     72