blob: 187c72a065a79db2c440f4cc06c96943e37e18cf [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;
Fabian Kozynski5ca7a512019-10-16 19:56:11 +000038import com.android.systemui.broadcast.BroadcastDispatcher;
Robin Lee3c82d3d2017-01-19 17:09:28 +000039import com.android.systemui.keyguard.WorkLockActivity;
40
41import org.junit.Before;
42import org.junit.Test;
43import org.junit.runner.RunWith;
44import org.mockito.Mock;
45import org.mockito.MockitoAnnotations;
46
47/**
48 * runtest systemui -c com.android.systemui.keyguard.WorkLockActivityTest
49 */
50@SmallTest
51@RunWith(AndroidJUnit4.class)
Jason Monkfba8faf2017-05-23 10:42:59 -040052public class WorkLockActivityTest extends SysuiTestCase {
Robin Lee3c82d3d2017-01-19 17:09:28 +000053 private static final @UserIdInt int USER_ID = 270;
54 private static final String TASK_LABEL = "task label";
55
56 private @Mock DevicePolicyManager mDevicePolicyManager;
57 private @Mock KeyguardManager mKeyguardManager;
58 private @Mock Context mContext;
Fabian Kozynski5ca7a512019-10-16 19:56:11 +000059 private @Mock BroadcastDispatcher mBroadcastDispatcher;
Robin Lee3c82d3d2017-01-19 17:09:28 +000060
61 private WorkLockActivity mActivity;
62
63 private static class WorkLockActivityTestable extends WorkLockActivity {
Fabian Kozynski5ca7a512019-10-16 19:56:11 +000064 WorkLockActivityTestable(Context baseContext, BroadcastDispatcher broadcastDispatcher) {
65 super(broadcastDispatcher);
Robin Lee3c82d3d2017-01-19 17:09:28 +000066 attachBaseContext(baseContext);
67 }
68 }
69
70 @Before
71 public void setUp() throws Exception {
72 MockitoAnnotations.initMocks(this);
73
74 when(mContext.getSystemService(eq(Context.DEVICE_POLICY_SERVICE)))
75 .thenReturn(mDevicePolicyManager);
76 when(mContext.getSystemService(eq(Context.KEYGUARD_SERVICE)))
77 .thenReturn(mKeyguardManager);
78
79 if (Looper.myLooper() == null) {
80 Looper.prepare();
81 }
Fabian Kozynski5ca7a512019-10-16 19:56:11 +000082 mActivity = new WorkLockActivityTestable(mContext, mBroadcastDispatcher);
Robin Lee3c82d3d2017-01-19 17:09:28 +000083 }
84
85 @Test
86 public void testBackgroundAlwaysOpaque() throws Exception {
87 final @ColorInt int orgColor = Color.rgb(250, 199, 67);
88 when(mDevicePolicyManager.getOrganizationColorForUser(eq(USER_ID))).thenReturn(orgColor);
89
90 final @ColorInt int opaqueColor= Color.rgb(164, 198, 57);
91 final @ColorInt int transparentColor = Color.argb(0, 0, 0, 0);
92 TaskDescription opaque = new TaskDescription(null, null, opaqueColor);
93 TaskDescription transparent = new TaskDescription(null, null, transparentColor);
94
95 // When a task description is provided with a suitable (opaque) primaryColor, it should be
96 // used as the scrim's background color.
97 mActivity.setIntent(new Intent()
98 .putExtra(Intent.EXTRA_USER_ID, USER_ID)
99 .putExtra(WorkLockActivity.EXTRA_TASK_DESCRIPTION, opaque));
100 assertEquals(opaqueColor, mActivity.getPrimaryColor());
101
102 // When a task description is provided but has no primaryColor / the primaryColor is
103 // transparent, the organization color should be used instead.
104 mActivity.setIntent(new Intent()
105 .putExtra(Intent.EXTRA_USER_ID, USER_ID)
106 .putExtra(WorkLockActivity.EXTRA_TASK_DESCRIPTION, transparent));
107 assertEquals(orgColor, mActivity.getPrimaryColor());
108
109 // When no task description is provided at all, it should be treated like a transparent
110 // description and the organization color shown instead.
111 mActivity.setIntent(new Intent()
112 .putExtra(Intent.EXTRA_USER_ID, USER_ID));
113 assertEquals(orgColor, mActivity.getPrimaryColor());
114 }
115}