Robin Lee | 3c82d3d | 2017-01-19 17:09:28 +0000 | [diff] [blame] | 1 | /* |
| 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 | |
| 17 | package com.android.systemui.keyguard; |
| 18 | |
| 19 | import static android.app.ActivityManager.TaskDescription; |
Brett Chabot | 84151d9 | 2019-02-27 15:37:59 -0800 | [diff] [blame] | 20 | |
Robin Lee | 3c82d3d | 2017-01-19 17:09:28 +0000 | [diff] [blame] | 21 | import static org.junit.Assert.assertEquals; |
| 22 | import static org.mockito.Mockito.eq; |
| 23 | import static org.mockito.Mockito.when; |
| 24 | |
Robin Lee | 3c82d3d | 2017-01-19 17:09:28 +0000 | [diff] [blame] | 25 | import android.annotation.ColorInt; |
| 26 | import android.annotation.UserIdInt; |
| 27 | import android.app.KeyguardManager; |
| 28 | import android.app.admin.DevicePolicyManager; |
| 29 | import android.content.Context; |
| 30 | import android.content.Intent; |
| 31 | import android.graphics.Color; |
| 32 | import android.os.Looper; |
| 33 | |
Brett Chabot | 84151d9 | 2019-02-27 15:37:59 -0800 | [diff] [blame] | 34 | import androidx.test.filters.SmallTest; |
| 35 | import androidx.test.runner.AndroidJUnit4; |
| 36 | |
Jason Monk | fba8faf | 2017-05-23 10:42:59 -0400 | [diff] [blame] | 37 | import com.android.systemui.SysuiTestCase; |
Robin Lee | 3c82d3d | 2017-01-19 17:09:28 +0000 | [diff] [blame] | 38 | import com.android.systemui.keyguard.WorkLockActivity; |
| 39 | |
| 40 | import org.junit.Before; |
| 41 | import org.junit.Test; |
| 42 | import org.junit.runner.RunWith; |
| 43 | import org.mockito.Mock; |
| 44 | import org.mockito.MockitoAnnotations; |
| 45 | |
| 46 | /** |
| 47 | * runtest systemui -c com.android.systemui.keyguard.WorkLockActivityTest |
| 48 | */ |
| 49 | @SmallTest |
| 50 | @RunWith(AndroidJUnit4.class) |
Jason Monk | fba8faf | 2017-05-23 10:42:59 -0400 | [diff] [blame] | 51 | public class WorkLockActivityTest extends SysuiTestCase { |
Robin Lee | 3c82d3d | 2017-01-19 17:09:28 +0000 | [diff] [blame] | 52 | 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 | } |