1 /*
2  * Copyright (C) 2018 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.documentsui.ui;
18 
19 import static org.junit.Assume.assumeFalse;
20 
21 import android.content.Context;
22 import android.content.res.Configuration;
23 
24 import androidx.test.InstrumentationRegistry;
25 import androidx.test.filters.SmallTest;
26 import androidx.test.runner.AndroidJUnit4;
27 
28 import com.android.documentsui.tests.R;
29 import com.android.documentsui.util.VersionUtils;
30 
31 import org.junit.Before;
32 import org.junit.Test;
33 import org.junit.runner.RunWith;
34 
35 /**
36  * This class test default Dark Theme (Night Mode Disable)
37  * Verify ActionBar background, Window background, and GridItem background to meet Light style
38  */
39 @SmallTest
40 @RunWith(AndroidJUnit4.class)
41 public class DarkThemeUiTest extends ThemeUiTestBase {
42     Context mTestContext;
43 
44     @Before
setUp()45     public void setUp() throws Exception {
46         super.setUp();
47         mTestContext = InstrumentationRegistry.getContext();
48         mTheme = getThemeByUiMode(mTargetContext, Configuration.UI_MODE_NIGHT_YES);
49     }
50 
51     @Test
themeNightModeEnable_actionBarColorShouldBeDark()52     public void themeNightModeEnable_actionBarColorShouldBeDark() throws Exception {
53         assumeFalse(VersionUtils.isAtLeastS()); // Disable for S dynamic color
54         assertTheme(R.styleable.ThemeColor, R.styleable.ThemeColor_android_colorBackground,
55                 mTheme.getResources().getColor(com.android.documentsui.R.color.app_background_color,
56                         mTheme));
57     }
58 
59     @Test
themeNightModeEnable_windowLightNavigationBarShouldBeFalse()60     public void themeNightModeEnable_windowLightNavigationBarShouldBeFalse() {
61         assertTheme(R.styleable.SystemWindow,
62                 R.styleable.SystemWindow_android_windowLightNavigationBar, false);
63     }
64 
65     @Test
themeNightModeEnable_windowLightStatusBarShouldBeFalse()66     public void themeNightModeEnable_windowLightStatusBarShouldBeFalse() {
67         assertTheme(R.styleable.SystemWindow,
68                 R.styleable.SystemWindow_android_windowLightNavigationBar, false);
69     }
70 
71     @Test
themeNightModeEnable_navigationBarColorShouldBeDark()72     public void themeNightModeEnable_navigationBarColorShouldBeDark() throws Exception {
73         assumeFalse(VersionUtils.isAtLeastS()); // Disable for S dynamic color
74         assertTheme(R.styleable.SystemWindow, R.styleable.SystemWindow_android_navigationBarColor,
75                 mTheme.getResources().getColor(android.R.color.black, mTheme));
76     }
77 
78     @Test
themeNightModeEnable_windowBackgroundColorShouldBeDark()79     public void themeNightModeEnable_windowBackgroundColorShouldBeDark() throws Exception {
80         assumeFalse(VersionUtils.isAtLeastS()); // Disable for S dynamic color
81         assertTheme(R.styleable.SystemWindow, R.styleable.SystemWindow_android_windowBackground,
82                 mTheme.getResources().getColor(com.android.documentsui.R.color.app_background_color,
83                         mTheme));
84     }
85 
86     @Test
themeNightModeEnable_statusBarColorShouldBeDark()87     public void themeNightModeEnable_statusBarColorShouldBeDark() throws Exception {
88         assumeFalse(VersionUtils.isAtLeastS()); // Disable for S dynamic color
89         assertTheme(R.styleable.SystemWindow, R.styleable.SystemWindow_android_statusBarColor,
90                 mTheme.getResources().getColor(com.android.documentsui.R.color.app_background_color,
91                         mTheme));
92     }
93 
94     @Test
appCompatThemeNightModeEnable_colorPrimaryShouldBeThemeable()95     public void appCompatThemeNightModeEnable_colorPrimaryShouldBeThemeable() throws Exception {
96         assumeFalse(VersionUtils.isAtLeastS()); // Disable for S dynamic color
97         assertTheme(R.styleable.ThemeColor, R.styleable.ThemeColor_android_colorPrimary,
98                 mTheme.getResources().getColor(com.android.documentsui.R.color.primary, mTheme));
99     }
100 }
101