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
17package com.android.setupwizardlib.util;
18
19import static org.junit.Assert.assertEquals;
20
21import android.content.Context;
22import android.content.res.TypedArray;
23import android.support.test.InstrumentationRegistry;
24import android.support.test.filters.SmallTest;
25import android.support.test.runner.AndroidJUnit4;
26import android.view.ContextThemeWrapper;
27
28import com.android.setupwizardlib.test.R;
29
30import org.junit.Before;
31import org.junit.Test;
32import org.junit.runner.RunWith;
33
34@RunWith(AndroidJUnit4.class)
35@SmallTest
36public 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