Lucas Dupin | f8e274c | 2018-02-22 17:01:55 -0800 | [diff] [blame] | 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; |
Lucas Dupin | 3d7ccaf | 2018-04-02 21:19:23 -0700 | [diff] [blame] | 19 | import android.net.Uri; |
Lucas Dupin | f8e274c | 2018-02-22 17:01:55 -0800 | [diff] [blame] | 20 | import android.test.suitebuilder.annotation.SmallTest; |
| 21 | import android.testing.AndroidTestingRunner; |
| 22 | import android.testing.TestableLooper.RunWithLooper; |
| 23 | import android.view.LayoutInflater; |
Lucas Dupin | 3d7ccaf | 2018-04-02 21:19:23 -0700 | [diff] [blame] | 24 | import android.view.View; |
| 25 | import android.view.View.MeasureSpec; |
| 26 | import android.view.ViewGroup; |
Lucas Dupin | f8e274c | 2018-02-22 17:01:55 -0800 | [diff] [blame] | 27 | |
| 28 | import com.android.systemui.SysuiTestCase; |
Lucas Dupin | 3d7ccaf | 2018-04-02 21:19:23 -0700 | [diff] [blame] | 29 | import com.android.systemui.keyguard.KeyguardSliceProvider; |
Lucas Dupin | f8e274c | 2018-02-22 17:01:55 -0800 | [diff] [blame] | 30 | |
| 31 | import org.junit.Assert; |
| 32 | import org.junit.Before; |
| 33 | import org.junit.Test; |
| 34 | import org.junit.runner.RunWith; |
| 35 | |
Lucas Dupin | 3d7ccaf | 2018-04-02 21:19:23 -0700 | [diff] [blame] | 36 | import java.util.Collections; |
| 37 | import java.util.HashSet; |
| 38 | |
| 39 | import androidx.slice.SliceProvider; |
| 40 | import androidx.slice.SliceSpecs; |
| 41 | import androidx.slice.builders.ListBuilder; |
| 42 | |
Lucas Dupin | f8e274c | 2018-02-22 17:01:55 -0800 | [diff] [blame] | 43 | @SmallTest |
Lucas Dupin | 3d7ccaf | 2018-04-02 21:19:23 -0700 | [diff] [blame] | 44 | @RunWithLooper(setAsMainLooper = true) |
Lucas Dupin | f8e274c | 2018-02-22 17:01:55 -0800 | [diff] [blame] | 45 | @RunWith(AndroidTestingRunner.class) |
| 46 | public class KeyguardSliceViewTest extends SysuiTestCase { |
| 47 | private KeyguardSliceView mKeyguardSliceView; |
Lucas Dupin | 3d7ccaf | 2018-04-02 21:19:23 -0700 | [diff] [blame] | 48 | private Uri mSliceUri; |
Lucas Dupin | f8e274c | 2018-02-22 17:01:55 -0800 | [diff] [blame] | 49 | |
| 50 | @Before |
| 51 | public void setUp() throws Exception { |
| 52 | mKeyguardSliceView = (KeyguardSliceView) LayoutInflater.from(getContext()) |
| 53 | .inflate(R.layout.keyguard_status_area, null); |
Lucas Dupin | 3d7ccaf | 2018-04-02 21:19:23 -0700 | [diff] [blame] | 54 | mSliceUri = Uri.parse(KeyguardSliceProvider.KEYGUARD_SLICE_URI); |
| 55 | SliceProvider.setSpecs(new HashSet<>(Collections.singletonList(SliceSpecs.LIST))); |
| 56 | } |
| 57 | |
| 58 | @Test |
| 59 | public void showSlice_notifiesListener() { |
| 60 | ListBuilder builder = new ListBuilder(getContext(), mSliceUri); |
| 61 | boolean[] notified = {false}; |
| 62 | mKeyguardSliceView.setContentChangeListener((hasHeader)-> { |
| 63 | notified[0] = true; |
| 64 | }); |
| 65 | mKeyguardSliceView.onChanged(builder.build()); |
| 66 | Assert.assertTrue("Listener should be notified about slice changes.", notified[0]); |
| 67 | } |
| 68 | |
| 69 | @Test |
| 70 | public void hasHeader_readsSliceData() { |
| 71 | ListBuilder builder = new ListBuilder(getContext(), mSliceUri); |
| 72 | mKeyguardSliceView.onChanged(builder.build()); |
| 73 | Assert.assertFalse("View should not have a header", mKeyguardSliceView.hasHeader()); |
| 74 | |
| 75 | builder.setHeader((ListBuilder.HeaderBuilder headerBuilder) -> { |
| 76 | headerBuilder.setTitle("header title!"); |
| 77 | }); |
| 78 | mKeyguardSliceView.onChanged(builder.build()); |
| 79 | Assert.assertTrue("View should have a header", mKeyguardSliceView.hasHeader()); |
Lucas Dupin | f8e274c | 2018-02-22 17:01:55 -0800 | [diff] [blame] | 80 | } |
| 81 | |
| 82 | @Test |
| 83 | public void getTextColor_whiteTextWhenAOD() { |
| 84 | // Set text color to red since the default is white and test would always pass |
| 85 | mKeyguardSliceView.setTextColor(Color.RED); |
Lucas Dupin | 3d7ccaf | 2018-04-02 21:19:23 -0700 | [diff] [blame] | 86 | mKeyguardSliceView.setDarkAmount(0); |
Lucas Dupin | f8e274c | 2018-02-22 17:01:55 -0800 | [diff] [blame] | 87 | Assert.assertEquals("Should be using regular text color", Color.RED, |
| 88 | mKeyguardSliceView.getTextColor()); |
Lucas Dupin | 3d7ccaf | 2018-04-02 21:19:23 -0700 | [diff] [blame] | 89 | mKeyguardSliceView.setDarkAmount(1); |
Lucas Dupin | f8e274c | 2018-02-22 17:01:55 -0800 | [diff] [blame] | 90 | Assert.assertEquals("Should be using AOD text color", Color.WHITE, |
| 91 | mKeyguardSliceView.getTextColor()); |
| 92 | } |
| 93 | } |