blob: 347b26deacd42c875765fb99fcfcd008b6414bfe [file] [log] [blame]
Robert Snoebergerf2af1202019-06-05 14:38:01 -04001/*
2 * Copyright (C) 2019 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.keyguard.clock
18
19import android.graphics.Color
20import android.testing.AndroidTestingRunner
21import androidx.test.filters.SmallTest
22import com.android.systemui.SysuiTestCase
23import com.google.common.truth.Truth.assertThat
24import org.junit.Before
25import org.junit.Test
26import org.junit.runner.RunWith
27
28@RunWith(AndroidTestingRunner::class)
29@SmallTest
30class ClockPaletteTest : SysuiTestCase() {
31
32 private lateinit var clockPalette: ClockPalette
33 private lateinit var colors: IntArray
34
35 @Before
36 fun setUp() {
37 clockPalette = ClockPalette()
38 // colors used are reds from light to dark.
39 val hsv: FloatArray = FloatArray(3)
40 Color.colorToHSV(Color.RED, hsv)
41 colors = IntArray(10)
42 val step: Float = (0f - hsv[2]) / colors.size
43 for (i in 0 until colors.size) {
44 hsv[2] += step
45 colors[i] = Color.HSVToColor(hsv)
46 }
47 }
48
49 @Test
50 fun testDark() {
51 // GIVEN on AOD
52 clockPalette.setDarkAmount(1f)
53 // AND GIVEN that wallpaper doesn't support dark text
54 clockPalette.setColorPalette(false, colors)
55 // THEN the secondary color should be lighter than the primary color
56 assertThat(value(clockPalette.getPrimaryColor()))
57 .isGreaterThan(value(clockPalette.getSecondaryColor()))
58 }
59
60 @Test
61 fun testDarkText() {
62 // GIVEN on lock screen
63 clockPalette.setDarkAmount(0f)
64 // AND GIVEN that wallpaper supports dark text
65 clockPalette.setColorPalette(true, colors)
66 // THEN the secondary color should be darker the primary color
67 assertThat(value(clockPalette.getPrimaryColor()))
68 .isLessThan(value(clockPalette.getSecondaryColor()))
69 }
70
71 @Test
72 fun testLightText() {
73 // GIVEN on lock screen
74 clockPalette.setDarkAmount(0f)
75 // AND GIVEN that wallpaper doesn't support dark text
76 clockPalette.setColorPalette(false, colors)
77 // THEN the secondary color should be darker than the primary color
78 assertThat(value(clockPalette.getPrimaryColor()))
79 .isGreaterThan(value(clockPalette.getSecondaryColor()))
80 }
81
82 @Test
83 fun testNullColors() {
84 // GIVEN on AOD
85 clockPalette.setDarkAmount(1f)
86 // AND GIVEN that wallpaper colors are null
87 clockPalette.setColorPalette(false, null)
88 // THEN the primary color should be whilte
89 assertThat(clockPalette.getPrimaryColor()).isEqualTo(Color.WHITE)
90 }
91
92 private fun value(color: Int): Float {
93 val hsv: FloatArray = FloatArray(3)
94 Color.colorToHSV(color, hsv)
95 return hsv[2]
96 }
97}