blob: b3accbc3b4bbe7d0315e845224d3c6f32176a83b [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
Lucas Dupinad079442019-04-03 13:14:11 -070030import com.android.systemui.SystemUIFactory;
Lucas Dupinf8e274c2018-02-22 17:01:55 -080031import com.android.systemui.SysuiTestCase;
Lucas Dupin4e023812018-04-02 21:19:23 -070032import com.android.systemui.keyguard.KeyguardSliceProvider;
Lucas Dupinad079442019-04-03 13:14:11 -070033import com.android.systemui.util.InjectionInflationController;
Lucas Dupinf8e274c2018-02-22 17:01:55 -080034
35import org.junit.Assert;
36import org.junit.Before;
37import org.junit.Test;
38import org.junit.runner.RunWith;
39
Lucas Dupin4e023812018-04-02 21:19:23 -070040import java.util.Collections;
41import java.util.HashSet;
Lucas Dupinf39ce102018-05-02 14:23:44 -070042import java.util.concurrent.atomic.AtomicBoolean;
Lucas Dupin4e023812018-04-02 21:19:23 -070043
Lucas Dupinf8e274c2018-02-22 17:01:55 -080044@SmallTest
Jason Monka716bac2018-12-05 15:48:21 -050045@RunWithLooper
Lucas Dupinf8e274c2018-02-22 17:01:55 -080046@RunWith(AndroidTestingRunner.class)
47public class KeyguardSliceViewTest extends SysuiTestCase {
48 private KeyguardSliceView mKeyguardSliceView;
Lucas Dupin4e023812018-04-02 21:19:23 -070049 private Uri mSliceUri;
Lucas Dupinf8e274c2018-02-22 17:01:55 -080050
51 @Before
52 public void setUp() throws Exception {
Jason Monka716bac2018-12-05 15:48:21 -050053 com.android.systemui.util.Assert.sMainLooper = TestableLooper.get(this).getLooper();
Lucas Dupinad079442019-04-03 13:14:11 -070054 InjectionInflationController inflationController = new InjectionInflationController(
55 SystemUIFactory.getInstance().getRootComponent());
56 LayoutInflater layoutInflater = inflationController
57 .injectable(LayoutInflater.from(getContext()));
58 mKeyguardSliceView = (KeyguardSliceView) layoutInflater
Lucas Dupinf8e274c2018-02-22 17:01:55 -080059 .inflate(R.layout.keyguard_status_area, null);
Lucas Dupin4e023812018-04-02 21:19:23 -070060 mSliceUri = Uri.parse(KeyguardSliceProvider.KEYGUARD_SLICE_URI);
61 SliceProvider.setSpecs(new HashSet<>(Collections.singletonList(SliceSpecs.LIST)));
62 }
63
64 @Test
65 public void showSlice_notifiesListener() {
Jason Monk1045e0b2018-08-06 09:42:10 -040066 ListBuilder builder = new ListBuilder(getContext(), mSliceUri, ListBuilder.INFINITY);
Lucas Dupinf39ce102018-05-02 14:23:44 -070067 AtomicBoolean notified = new AtomicBoolean();
Lucas Dupin3978e6e2018-05-22 18:08:35 -070068 mKeyguardSliceView.setContentChangeListener(()-> notified.set(true));
Lucas Dupin4e023812018-04-02 21:19:23 -070069 mKeyguardSliceView.onChanged(builder.build());
Lucas Dupinf39ce102018-05-02 14:23:44 -070070 Assert.assertTrue("Listener should be notified about slice changes.",
71 notified.get());
72 }
73
74 @Test
75 public void showSlice_emptySliceNotifiesListener() {
76 AtomicBoolean notified = new AtomicBoolean();
Lucas Dupin3978e6e2018-05-22 18:08:35 -070077 mKeyguardSliceView.setContentChangeListener(()-> notified.set(true));
Lucas Dupinf39ce102018-05-02 14:23:44 -070078 mKeyguardSliceView.onChanged(null);
79 Assert.assertTrue("Listener should be notified about slice changes.",
80 notified.get());
Lucas Dupin4e023812018-04-02 21:19:23 -070081 }
82
83 @Test
Lucas Dupine570af62019-02-10 14:52:30 -080084 public void hasHeader_readsSliceData() {
85 ListBuilder builder = new ListBuilder(getContext(), mSliceUri, ListBuilder.INFINITY);
86 mKeyguardSliceView.onChanged(builder.build());
87 Assert.assertFalse("View should not have a header", mKeyguardSliceView.hasHeader());
88
89 builder.setHeader(new ListBuilder.HeaderBuilder().setTitle("header title!"));
90 mKeyguardSliceView.onChanged(builder.build());
91 Assert.assertTrue("View should have a header", mKeyguardSliceView.hasHeader());
92 }
93
94 @Test
Lucas Dupin9fedb892018-05-04 17:42:33 -070095 public void refresh_replacesSliceContentAndNotifiesListener() {
96 AtomicBoolean notified = new AtomicBoolean();
Lucas Dupin3978e6e2018-05-22 18:08:35 -070097 mKeyguardSliceView.setContentChangeListener(()-> notified.set(true));
Lucas Dupin9fedb892018-05-04 17:42:33 -070098 mKeyguardSliceView.refresh();
99 Assert.assertTrue("Listener should be notified about slice changes.",
100 notified.get());
101 }
102
103 @Test
Lucas Dupinf8e274c2018-02-22 17:01:55 -0800104 public void getTextColor_whiteTextWhenAOD() {
105 // Set text color to red since the default is white and test would always pass
106 mKeyguardSliceView.setTextColor(Color.RED);
Lucas Dupin4e023812018-04-02 21:19:23 -0700107 mKeyguardSliceView.setDarkAmount(0);
Lucas Dupinf8e274c2018-02-22 17:01:55 -0800108 Assert.assertEquals("Should be using regular text color", Color.RED,
109 mKeyguardSliceView.getTextColor());
Lucas Dupin4e023812018-04-02 21:19:23 -0700110 mKeyguardSliceView.setDarkAmount(1);
Lucas Dupinf8e274c2018-02-22 17:01:55 -0800111 Assert.assertEquals("Should be using AOD text color", Color.WHITE,
112 mKeyguardSliceView.getTextColor());
113 }
Lucas Dupin4e023812018-04-02 21:19:23 -0700114}