blob: 6e726cf6bf8d2cde451b818a426fa69940912006 [file] [log] [blame]
Robin Lee3c82d3d2017-01-19 17:09:28 +00001/*
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.systemui.keyguard;
18
19import static android.app.ActivityManager.TaskDescription;
Brett Chabot84151d92019-02-27 15:37:59 -080020
Robin Lee3c82d3d2017-01-19 17:09:28 +000021import static org.junit.Assert.assertEquals;
22import static org.mockito.Mockito.eq;
23import static org.mockito.Mockito.when;
24
Robin Lee3c82d3d2017-01-19 17:09:28 +000025import android.annotation.ColorInt;
26import android.annotation.UserIdInt;
27import android.app.KeyguardManager;
28import android.app.admin.DevicePolicyManager;
29import android.content.Context;
30import android.content.Intent;
31import android.graphics.Color;
32import android.os.Looper;
33
Brett Chabot84151d92019-02-27 15:37:59 -080034import androidx.test.filters.SmallTest;
35import androidx.test.runner.AndroidJUnit4;
36
Jason Monkfba8faf2017-05-23 10:42:59 -040037import com.android.systemui.SysuiTestCase;
Robin Lee3c82d3d2017-01-19 17:09:28 +000038import com.android.systemui.keyguard.WorkLockActivity;
39
40import org.junit.Before;
41import org.junit.Test;
42import org.junit.runner.RunWith;
43import org.mockito.Mock;
44import org.mockito.MockitoAnnotations;
45
46/**
47 * runtest systemui -c com.android.systemui.keyguard.WorkLockActivityTest
48 */
49@SmallTest
50@RunWith(AndroidJUnit4.class)
Jason Monkfba8faf2017-05-23 10:42:59 -040051public class WorkLockActivityTest extends SysuiTestCase {
Robin Lee3c82d3d2017-01-19 17:09:28 +000052 private static final @UserIdInt int USER_ID = 270;
53 private static final String TASK_LABEL = "task label";
54
55 private @Mock DevicePolicyManager mDevicePolicyManager;
56 private @Mock KeyguardManager mKeyguardManager;
57 private @Mock Context mContext;
58
59 private WorkLockActivity mActivity;
60
61 private static class WorkLockActivityTestable extends WorkLockActivity {
62 WorkLockActivityTestable(Context baseContext) {
63 super();
64 attachBaseContext(baseContext);
65 }
66 }
67
68 @Before
69 public void setUp() throws Exception {
70 MockitoAnnotations.initMocks(this);
71
72 when(mContext.getSystemService(eq(Context.DEVICE_POLICY_SERVICE)))
73 .thenReturn(mDevicePolicyManager);
74 when(mContext.getSystemService(eq(Context.KEYGUARD_SERVICE)))
75 .thenReturn(mKeyguardManager);
76
77 if (Looper.myLooper() == null) {
78 Looper.prepare();
79 }
80 mActivity = new WorkLockActivityTestable(mContext);
81 }
82
83 @Test
84 public void testBackgroundAlwaysOpaque() throws Exception {
85 final @ColorInt int orgColor = Color.rgb(250, 199, 67);
86 when(mDevicePolicyManager.getOrganizationColorForUser(eq(USER_ID))).thenReturn(orgColor);
87
88 final @ColorInt int opaqueColor= Color.rgb(164, 198, 57);
89 final @ColorInt int transparentColor = Color.argb(0, 0, 0, 0);
90 TaskDescription opaque = new TaskDescription(null, null, opaqueColor);
91 TaskDescription transparent = new TaskDescription(null, null, transparentColor);
92
93 // When a task description is provided with a suitable (opaque) primaryColor, it should be
94 // used as the scrim's background color.
95 mActivity.setIntent(new Intent()
96 .putExtra(Intent.EXTRA_USER_ID, USER_ID)
97 .putExtra(WorkLockActivity.EXTRA_TASK_DESCRIPTION, opaque));
98 assertEquals(opaqueColor, mActivity.getPrimaryColor());
99
100 // When a task description is provided but has no primaryColor / the primaryColor is
101 // transparent, the organization color should be used instead.
102 mActivity.setIntent(new Intent()
103 .putExtra(Intent.EXTRA_USER_ID, USER_ID)
104 .putExtra(WorkLockActivity.EXTRA_TASK_DESCRIPTION, transparent));
105 assertEquals(orgColor, mActivity.getPrimaryColor());
106
107 // When no task description is provided at all, it should be treated like a transparent
108 // description and the organization color shown instead.
109 mActivity.setIntent(new Intent()
110 .putExtra(Intent.EXTRA_USER_ID, USER_ID));
111 assertEquals(orgColor, mActivity.getPrimaryColor());
112 }
113}