Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 997e95bd authored by Bill Lin's avatar Bill Lin
Browse files

Implement Dark Theme UI TestCase

1) Implement Dark/Light theme test base on Resource.theme mechanism
2) Refine stylable android attr, do not override format attr

Bug: 115315612
Test: atest com.android.documentsui.ui
Change-Id: I087420b286d6bec0e7951f1acdeea868bc2afe23
parent afcf7634
Loading
Loading
Loading
Loading
+9 −9
Original line number Diff line number Diff line
@@ -16,9 +16,9 @@
<resources>

    <declare-styleable name="ActionBarView">
        <attr name="android:colorPrimary" format="color" />
        <attr name="android:colorControlNormal" format="color" />
        <attr name="android:textColorPrimary" format="color" />
        <attr name="android:colorPrimary" />
        <attr name="android:colorControlNormal" />
        <attr name="android:textColorPrimary" />
    </declare-styleable>

    <declare-styleable name="CardView">
@@ -42,15 +42,15 @@
    </declare-styleable>

    <declare-styleable name="SnackbarView">
        <attr name="android:textColor" format="reference" />
        <attr name="android:textColor" />
    </declare-styleable>

    <declare-styleable name="SystemWindow">
        <attr name="android:statusBarColor" format="color" />
        <attr name="android:navigationBarColor" format="color" />
        <attr name="android:windowBackground" format="color" />
        <attr name="android:windowLightStatusBar" format="boolean" />
        <attr name="android:windowLightNavigationBar" format="boolean" />
        <attr name="android:statusBarColor" />
        <attr name="android:navigationBarColor" />
        <attr name="android:windowBackground" />
        <attr name="android:windowLightStatusBar" />
        <attr name="android:windowLightNavigationBar" />
    </declare-styleable>

    <declare-styleable name="TextHandleView">
+20 −0
Original line number Diff line number Diff line
<?xml version="1.0" encoding="utf-8"?>
<!-- Copyright (C) 2018 The Android Open Source Project

     Licensed under the Apache License, Version 2.0 (the "License");
     you may not use this file except in compliance with the License.
     You may obtain a copy of the License at

          http://www.apache.org/licenses/LICENSE-2.0

     Unless required by applicable law or agreed to in writing, software
     distributed under the License is distributed on an "AS IS" BASIS,
     WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
     See the License for the specific language governing permissions and
     limitations under the License.
-->

<resources>
    <color name="expected_g_dark_grey">#ff202124</color>     <!--M2 Grey 900-->
    <color name="expected_g_grey">#ff3c4043</color>          <!--M2 Grey 800-->
</resources>
+0 −118
Original line number Diff line number Diff line
/*
 * Copyright (C) 2018 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package com.android.documentsui.dirlist;

import android.app.UiModeManager;
import android.content.res.TypedArray;
import android.graphics.Color;

import android.support.test.filters.SmallTest;

import com.android.documentsui.ActivityTest;
import com.android.documentsui.R;
import com.android.documentsui.files.FilesActivity;

import org.junit.After;
import org.junit.Before;
import org.junit.Test;

/**
* This class test default Light Theme (Night Mode Disable)
* Verify ActionBar background, Window background, and GridItem background to meet Light style
*/
@SmallTest
public class ThemeUiTest extends ActivityTest<FilesActivity> {
    public ThemeUiTest() {
        super(FilesActivity.class);
    }

    @Before
    @Override
    public void setUp() throws Exception {
        super.setUp();
        setSystemUiModeNight(UiModeManager.MODE_NIGHT_NO);
    }

    @After
    @Override
    public void tearDown() throws Exception {
        super.tearDown();
        setSystemUiModeNight(UiModeManager.MODE_NIGHT_NO);
    }

    @Test
    public void testThemeNightModeEnable_actionBarColor() {
        TypedArray ta = getActivity().obtainStyledAttributes(R.styleable.ActionBarView);
        int actionBarBackground = ta.getColor(R.styleable.ActionBarView_android_colorPrimary,
                Color.RED);
        ta.recycle();
        assertEquals(getActivity().getColor(android.R.color.white), actionBarBackground);
    }

    @Test
    public void testThemeNightModeEnable_gridItemBackgroundColor() {
        TypedArray ta = getActivity().obtainStyledAttributes(R.styleable.GridItem);
        int gridItemColor = ta.getColor(R.styleable.GridItem_gridItemColor, Color.RED);
        ta.recycle();
        assertEquals(getActivity().getColor(R.color.item_doc_background), gridItemColor);
    }

    @Test
    public void testThemeNightModeEnable_lightNavigationBar() {
        TypedArray ta = getActivity().obtainStyledAttributes(R.styleable.SystemWindow);
        boolean isLightNavigationBar = ta.getBoolean(
                R.styleable.SystemWindow_android_windowLightNavigationBar, false);
        ta.recycle();
        assertTrue(isLightNavigationBar);
    }

    @Test
    public void testThemeNightModeEnable_lightStatusBar() {
        TypedArray ta = getActivity().obtainStyledAttributes(R.styleable.SystemWindow);
        boolean isLightStatusBar = ta.getBoolean(
                R.styleable.SystemWindow_android_windowLightNavigationBar, false);
        ta.recycle();
        assertTrue(isLightStatusBar);
    }

    @Test
    public void testThemeNightModeEnable_navigationBarColor() {
        TypedArray ta = getActivity().obtainStyledAttributes(R.styleable.SystemWindow);
        int navigationBarColor = ta.getColor(R.styleable.SystemWindow_android_navigationBarColor,
                Color.RED);
        ta.recycle();
        assertEquals(getActivity().getColor(android.R.color.white), navigationBarColor);
    }

    @Test
    public void testThemeNightModeEnable_windowBackgroundColor() {
        TypedArray ta = getActivity().obtainStyledAttributes(R.styleable.SystemWindow);
        int windowBackground = ta.getColor(
                R.styleable.SystemWindow_android_windowBackground, Color.RED);
        ta.recycle();
        assertEquals(getActivity().getColor(android.R.color.white), windowBackground);
    }

    @Test
    public void testThemeNightModeEnable_statusBarColor() {
        TypedArray ta = getActivity().obtainStyledAttributes(R.styleable.SystemWindow);
        int statusBarColor = ta.getColor(R.styleable.SystemWindow_android_statusBarColor,
                Color.RED);
        ta.recycle();
        assertEquals(getActivity().getColor(android.R.color.white), statusBarColor);
    }
}
+93 −0
Original line number Diff line number Diff line
/*
 * Copyright (C) 2018 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package com.android.documentsui.ui;

import android.content.Context;
import android.content.res.Configuration;
import android.support.test.InstrumentationRegistry;
import android.support.test.filters.SmallTest;
import android.support.test.runner.AndroidJUnit4;

import com.android.documentsui.R;

import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;

/**
 * This class test default Dark Theme (Night Mode Disable)
 * Verify ActionBar background, Window background, and GridItem background to meet Light style
 */
@SmallTest
@RunWith(AndroidJUnit4.class)
public class DarkThemeUiTest extends ThemeUiTestBase {
    Context mTestContext;
    int mExpectedDarkGreyColor, mExpectedGreyColor;

    @Before
    public void setUp() throws Exception {
        super.setUp();
        mTestContext = InstrumentationRegistry.getContext();
        mTheme = getThemeByUiMode(mTargetContext, Configuration.UI_MODE_NIGHT_YES);
        mExpectedDarkGreyColor = mTestContext.getResources().getColor(
                com.android.documentsui.tests.R.color.expected_g_dark_grey);
        mExpectedGreyColor = mTestContext.getResources().getColor(
                com.android.documentsui.tests.R.color.expected_g_grey);
    }

    @Test
    public void themeNightModeEnable_actionBarColorShouldBeDark() {

        assertTheme(R.styleable.ActionBarView, R.styleable.ActionBarView_android_colorPrimary,
                mExpectedDarkGreyColor);
    }

    @Test
    public void themeNightModeEnable_gridItemBackgroundColorShouldBeDark() {
        assertTheme(R.styleable.GridItem, R.styleable.GridItem_gridItemColor, mExpectedGreyColor);
    }

    @Test
    public void themeNightModeEnable_windowLightNavigationBarShouldBeFalse() {
        assertTheme(R.styleable.SystemWindow,
                R.styleable.SystemWindow_android_windowLightNavigationBar, false);
    }

    @Test
    public void themeNightModeEnable_windowLightStatusBarShouldBeFalse() {
        assertTheme(R.styleable.SystemWindow,
                R.styleable.SystemWindow_android_windowLightNavigationBar, false);
    }

    @Test
    public void themeNightModeEnable_navigationBarColorShouldBeDark() {
        assertTheme(R.styleable.SystemWindow, R.styleable.SystemWindow_android_navigationBarColor,
                mExpectedDarkGreyColor);
    }

    @Test
    public void themeNightModeEnable_windowBackgroundColorShouldBeDark() {
        assertTheme(R.styleable.SystemWindow, R.styleable.SystemWindow_android_windowBackground,
                mExpectedDarkGreyColor);
    }

    @Test
    public void themeNightModeEnable_statusBarColorShouldBeDark() {
        assertTheme(R.styleable.SystemWindow, R.styleable.SystemWindow_android_statusBarColor,
                mExpectedDarkGreyColor);
    }
}
 No newline at end of file
+84 −0
Original line number Diff line number Diff line
/*
 * Copyright (C) 2018 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package com.android.documentsui.ui;

import android.content.res.Configuration;
import android.graphics.Color;
import android.support.test.filters.SmallTest;
import android.support.test.runner.AndroidJUnit4;

import com.android.documentsui.R;

import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;

/**
 * This class test default Light Theme (Night Mode Disable)
 * Verify ActionBar background, Window background, and GridItem background to meet Light style
 */
@SmallTest
@RunWith(AndroidJUnit4.class)
public class ThemeUiTest extends ThemeUiTestBase {

    @Before
    public void setUp() throws Exception {
        super.setUp();
        mTheme = getThemeByUiMode(mTargetContext, Configuration.UI_MODE_NIGHT_NO);
    }

    @Test
    public void themeNightModeDisable_actionBarColorShouldBeLight() {
        assertTheme(R.styleable.ActionBarView, R.styleable.ActionBarView_android_colorPrimary,
                Color.WHITE);
    }

    @Test
    public void themeNightModeDisable_gridItemBackgroundColorShouldBeLight() {
        assertTheme(R.styleable.GridItem, R.styleable.GridItem_gridItemColor, Color.WHITE);
    }

    @Test
    public void themeNightModeDisable_windowLightNavigationBarShouldBeTrue() {
        assertTheme(R.styleable.SystemWindow,
                R.styleable.SystemWindow_android_windowLightNavigationBar, true);
    }

    @Test
    public void themeNightModeDisable_windowLightStatusBarShouldBeTrue() {
        assertTheme(R.styleable.SystemWindow, R.styleable.SystemWindow_android_windowLightStatusBar,
                true);
    }

    @Test
    public void themeNightModeDisable_navigationBarColorShouldBeLight() {
        assertTheme(R.styleable.SystemWindow, R.styleable.SystemWindow_android_navigationBarColor,
                Color.WHITE);
    }

    @Test
    public void themeNightModeDisable_windowBackgroundColorShouldBeLight() {
        assertTheme(R.styleable.SystemWindow, R.styleable.SystemWindow_android_windowBackground,
                Color.WHITE);
    }

    @Test
    public void themeNightModeDisable_statusBarColorShouldBeLight() {
        assertTheme(R.styleable.SystemWindow, R.styleable.SystemWindow_android_statusBarColor,
                Color.WHITE);
    }
}
Loading