• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
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  */
16 package com.android.keyguard;
17 
18 import android.graphics.Color;
19 import android.net.Uri;
20 import android.test.suitebuilder.annotation.SmallTest;
21 import android.testing.AndroidTestingRunner;
22 import android.testing.TestableLooper.RunWithLooper;
23 import android.view.LayoutInflater;
24 
25 import androidx.slice.Slice;
26 import androidx.slice.SliceProvider;
27 import androidx.slice.SliceSpecs;
28 import androidx.slice.builders.ListBuilder;
29 import androidx.slice.widget.RowContent;
30 
31 import com.android.systemui.R;
32 import com.android.systemui.SysuiTestCase;
33 import com.android.systemui.keyguard.KeyguardSliceProvider;
34 
35 import org.junit.Assert;
36 import org.junit.Before;
37 import org.junit.Test;
38 import org.junit.runner.RunWith;
39 import org.mockito.MockitoAnnotations;
40 
41 import java.util.Collections;
42 import java.util.HashSet;
43 import java.util.concurrent.atomic.AtomicBoolean;
44 
45 @SmallTest
46 @RunWithLooper(setAsMainLooper = true)
47 @RunWith(AndroidTestingRunner.class)
48 public class KeyguardSliceViewTest extends SysuiTestCase {
49     private KeyguardSliceView mKeyguardSliceView;
50     private Uri mSliceUri;
51 
52     @Before
setUp()53     public void setUp() throws Exception {
54         MockitoAnnotations.initMocks(this);
55         LayoutInflater layoutInflater = LayoutInflater.from(getContext());
56         mKeyguardSliceView = (KeyguardSliceView) layoutInflater
57                 .inflate(R.layout.keyguard_status_area, null);
58         mSliceUri = Uri.parse(KeyguardSliceProvider.KEYGUARD_SLICE_URI);
59         SliceProvider.setSpecs(new HashSet<>(Collections.singletonList(SliceSpecs.LIST)));
60     }
61 
62     @Test
showSlice_notifiesListener()63     public void showSlice_notifiesListener() {
64         ListBuilder builder = new ListBuilder(getContext(), mSliceUri, ListBuilder.INFINITY);
65         builder.setHeader(new ListBuilder.HeaderBuilder().setTitle("header title!"));
66         Slice slice = builder.build();
67         RowContent rowContent = new RowContent(slice.getItemArray()[0], 0);
68 
69         AtomicBoolean notified = new AtomicBoolean();
70         mKeyguardSliceView.setContentChangeListener(()-> notified.set(true));
71         mKeyguardSliceView.showSlice(rowContent, Collections.EMPTY_LIST);
72         Assert.assertTrue("Listener should be notified about slice changes.",
73                 notified.get());
74     }
75 
76     @Test
showSlice_emptySliceNotifiesListener()77     public void showSlice_emptySliceNotifiesListener() {
78         AtomicBoolean notified = new AtomicBoolean();
79         mKeyguardSliceView.setContentChangeListener(()-> notified.set(true));
80         mKeyguardSliceView.showSlice(null, Collections.EMPTY_LIST);
81         Assert.assertTrue("Listener should be notified about slice changes.",
82                 notified.get());
83     }
84 
85     @Test
hasHeader_readsSliceData()86     public void hasHeader_readsSliceData() {
87         ListBuilder builder = new ListBuilder(getContext(), mSliceUri, ListBuilder.INFINITY);
88         mKeyguardSliceView.showSlice(null, Collections.EMPTY_LIST);
89         Assert.assertFalse("View should not have a header", mKeyguardSliceView.hasHeader());
90 
91         builder.setHeader(new ListBuilder.HeaderBuilder().setTitle("header title!"));
92         Slice slice = builder.build();
93         RowContent rowContent = new RowContent(slice.getItemArray()[0], 0);
94         mKeyguardSliceView.showSlice(rowContent, Collections.EMPTY_LIST);
95         Assert.assertTrue("View should have a header", mKeyguardSliceView.hasHeader());
96     }
97 
98     @Test
getTextColor_whiteTextWhenAOD()99     public void getTextColor_whiteTextWhenAOD() {
100         // Set text color to red since the default is white and test would always pass
101         mKeyguardSliceView.setTextColor(Color.RED);
102         mKeyguardSliceView.setDarkAmount(0);
103         Assert.assertEquals("Should be using regular text color", Color.RED,
104                 mKeyguardSliceView.getTextColor());
105         mKeyguardSliceView.setDarkAmount(1);
106         Assert.assertEquals("Should be using AOD text color", Color.WHITE,
107                 mKeyguardSliceView.getTextColor());
108     }
109 }
110