blob: 116f8fc7d3eb2f1d393edc448f9dbe52008674db [file] [log] [blame]
Lucas Dupinf8e274c2018-02-22 17:01:55 -08001/*
2 * Copyright (C) 2018 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 */
16package com.android.keyguard;
17
18import android.graphics.Color;
Lucas Dupin4e023812018-04-02 21:19:23 -070019import android.net.Uri;
Lucas Dupinf8e274c2018-02-22 17:01:55 -080020import android.test.suitebuilder.annotation.SmallTest;
21import android.testing.AndroidTestingRunner;
Jason Monka716bac2018-12-05 15:48:21 -050022import android.testing.TestableLooper;
Lucas Dupinf8e274c2018-02-22 17:01:55 -080023import android.testing.TestableLooper.RunWithLooper;
24import android.view.LayoutInflater;
25
Jason Monka716bac2018-12-05 15:48:21 -050026import androidx.slice.SliceProvider;
27import androidx.slice.SliceSpecs;
28import androidx.slice.builders.ListBuilder;
29
Sunny Goyal87fccf02019-08-13 17:39:10 -070030import com.android.systemui.R;
Lucas Dupinad079442019-04-03 13:14:11 -070031import com.android.systemui.SystemUIFactory;
Lucas Dupinf8e274c2018-02-22 17:01:55 -080032import com.android.systemui.SysuiTestCase;
Lucas Dupin4e023812018-04-02 21:19:23 -070033import com.android.systemui.keyguard.KeyguardSliceProvider;
Lucas Dupinad079442019-04-03 13:14:11 -070034import com.android.systemui.util.InjectionInflationController;
Lucas Dupinf8e274c2018-02-22 17:01:55 -080035
36import org.junit.Assert;
37import org.junit.Before;
38import org.junit.Test;
39import org.junit.runner.RunWith;
40
Lucas Dupin4e023812018-04-02 21:19:23 -070041import java.util.Collections;
42import java.util.HashSet;
Lucas Dupinf39ce102018-05-02 14:23:44 -070043import java.util.concurrent.atomic.AtomicBoolean;
Lucas Dupin4e023812018-04-02 21:19:23 -070044
Lucas Dupinf8e274c2018-02-22 17:01:55 -080045@SmallTest
Jason Monka716bac2018-12-05 15:48:21 -050046@RunWithLooper
Lucas Dupinf8e274c2018-02-22 17:01:55 -080047@RunWith(AndroidTestingRunner.class)
48public class KeyguardSliceViewTest extends SysuiTestCase {
49 private KeyguardSliceView mKeyguardSliceView;
Lucas Dupin4e023812018-04-02 21:19:23 -070050 private Uri mSliceUri;
Lucas Dupinf8e274c2018-02-22 17:01:55 -080051
52 @Before
53 public void setUp() throws Exception {
Jason Monka716bac2018-12-05 15:48:21 -050054 com.android.systemui.util.Assert.sMainLooper = TestableLooper.get(this).getLooper();
Lucas Dupinad079442019-04-03 13:14:11 -070055 InjectionInflationController inflationController = new InjectionInflationController(
56 SystemUIFactory.getInstance().getRootComponent());
57 LayoutInflater layoutInflater = inflationController
58 .injectable(LayoutInflater.from(getContext()));
59 mKeyguardSliceView = (KeyguardSliceView) layoutInflater
Lucas Dupinf8e274c2018-02-22 17:01:55 -080060 .inflate(R.layout.keyguard_status_area, null);
Lucas Dupin4e023812018-04-02 21:19:23 -070061 mSliceUri = Uri.parse(KeyguardSliceProvider.KEYGUARD_SLICE_URI);
62 SliceProvider.setSpecs(new HashSet<>(Collections.singletonList(SliceSpecs.LIST)));
63 }
64
65 @Test
66 public void showSlice_notifiesListener() {
Jason Monk1045e0b2018-08-06 09:42:10 -040067 ListBuilder builder = new ListBuilder(getContext(), mSliceUri, ListBuilder.INFINITY);
Lucas Dupinf39ce102018-05-02 14:23:44 -070068 AtomicBoolean notified = new AtomicBoolean();
Lucas Dupin3978e6e2018-05-22 18:08:35 -070069 mKeyguardSliceView.setContentChangeListener(()-> notified.set(true));
Lucas Dupin4e023812018-04-02 21:19:23 -070070 mKeyguardSliceView.onChanged(builder.build());
Lucas Dupinf39ce102018-05-02 14:23:44 -070071 Assert.assertTrue("Listener should be notified about slice changes.",
72 notified.get());
73 }
74
75 @Test
76 public void showSlice_emptySliceNotifiesListener() {
77 AtomicBoolean notified = new AtomicBoolean();
Lucas Dupin3978e6e2018-05-22 18:08:35 -070078 mKeyguardSliceView.setContentChangeListener(()-> notified.set(true));
Lucas Dupinf39ce102018-05-02 14:23:44 -070079 mKeyguardSliceView.onChanged(null);
80 Assert.assertTrue("Listener should be notified about slice changes.",
81 notified.get());
Lucas Dupin4e023812018-04-02 21:19:23 -070082 }
83
84 @Test
Lucas Dupine570af62019-02-10 14:52:30 -080085 public void hasHeader_readsSliceData() {
86 ListBuilder builder = new ListBuilder(getContext(), mSliceUri, ListBuilder.INFINITY);
87 mKeyguardSliceView.onChanged(builder.build());
88 Assert.assertFalse("View should not have a header", mKeyguardSliceView.hasHeader());
89
90 builder.setHeader(new ListBuilder.HeaderBuilder().setTitle("header title!"));
91 mKeyguardSliceView.onChanged(builder.build());
92 Assert.assertTrue("View should have a header", mKeyguardSliceView.hasHeader());
93 }
94
95 @Test
Lucas Dupin9fedb892018-05-04 17:42:33 -070096 public void refresh_replacesSliceContentAndNotifiesListener() {
97 AtomicBoolean notified = new AtomicBoolean();
Lucas Dupin3978e6e2018-05-22 18:08:35 -070098 mKeyguardSliceView.setContentChangeListener(()-> notified.set(true));
Lucas Dupin9fedb892018-05-04 17:42:33 -070099 mKeyguardSliceView.refresh();
100 Assert.assertTrue("Listener should be notified about slice changes.",
101 notified.get());
102 }
103
104 @Test
Lucas Dupinf8e274c2018-02-22 17:01:55 -0800105 public void getTextColor_whiteTextWhenAOD() {
106 // Set text color to red since the default is white and test would always pass
107 mKeyguardSliceView.setTextColor(Color.RED);
Lucas Dupin4e023812018-04-02 21:19:23 -0700108 mKeyguardSliceView.setDarkAmount(0);
Lucas Dupinf8e274c2018-02-22 17:01:55 -0800109 Assert.assertEquals("Should be using regular text color", Color.RED,
110 mKeyguardSliceView.getTextColor());
Lucas Dupin4e023812018-04-02 21:19:23 -0700111 mKeyguardSliceView.setDarkAmount(1);
Lucas Dupinf8e274c2018-02-22 17:01:55 -0800112 Assert.assertEquals("Should be using AOD text color", Color.WHITE,
113 mKeyguardSliceView.getTextColor());
114 }
Lucas Dupin4e023812018-04-02 21:19:23 -0700115}