blob: 589aa03538708d82de268714c561cac2b2cee7c1 [file] [log] [blame]
phweiss679dc242017-07-05 18:54:54 +02001/*
2 * Copyright (C) 2017 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file
5 * except in compliance with the License. You may obtain a copy of the License at
6 *
7 * http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software distributed under the
10 * License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
11 * KIND, either express or implied. See the License for the specific language governing
12 * permissions and limitations under the License.
13 */
14
15package com.android.systemui.statusbar.phone;
16
17import static junit.framework.Assert.assertTrue;
Jason Monka716bac2018-12-05 15:48:21 -050018
phweiss679dc242017-07-05 18:54:54 +020019import static org.mockito.Matchers.any;
Satoshi Sanno3756b092019-05-29 16:39:50 +090020import static org.mockito.Matchers.eq;
phweiss679dc242017-07-05 18:54:54 +020021import static org.mockito.Mockito.verify;
22
Satoshi Sanno3756b092019-05-29 16:39:50 +090023import android.content.BroadcastReceiver;
phweiss679dc242017-07-05 18:54:54 +020024import android.content.Intent;
25import android.content.IntentFilter;
phweiss679dc242017-07-05 18:54:54 +020026import android.testing.AndroidTestingRunner;
27import android.testing.TestableLooper.RunWithLooper;
28
Brett Chabot84151d92019-02-27 15:37:59 -080029import androidx.test.filters.SmallTest;
30
phweiss679dc242017-07-05 18:54:54 +020031import com.android.systemui.SysuiTestCase;
Fabian Kozynskiff5e91f2019-09-24 15:38:08 -040032import com.android.systemui.broadcast.BroadcastDispatcher;
phweiss679dc242017-07-05 18:54:54 +020033
34import org.junit.Before;
35import org.junit.Test;
36import org.junit.runner.RunWith;
37import org.mockito.ArgumentCaptor;
Fabian Kozynskiff5e91f2019-09-24 15:38:08 -040038import org.mockito.Mock;
39import org.mockito.MockitoAnnotations;
phweiss679dc242017-07-05 18:54:54 +020040
phweiss679dc242017-07-05 18:54:54 +020041@RunWith(AndroidTestingRunner.class)
Jason Monka716bac2018-12-05 15:48:21 -050042@RunWithLooper
phweiss679dc242017-07-05 18:54:54 +020043@SmallTest
44public class SystemUIDialogTest extends SysuiTestCase {
45
46 private SystemUIDialog mDialog;
Fabian Kozynskiff5e91f2019-09-24 15:38:08 -040047 @Mock
48 private BroadcastDispatcher mBroadcastDispatcher;
phweiss679dc242017-07-05 18:54:54 +020049
50 @Before
51 public void setup() {
Fabian Kozynskiff5e91f2019-09-24 15:38:08 -040052 MockitoAnnotations.initMocks(this);
53
54 mDependency.injectTestDependency(BroadcastDispatcher.class, mBroadcastDispatcher);
55
56 mDialog = new SystemUIDialog(mContext);
phweiss679dc242017-07-05 18:54:54 +020057 }
58
59 @Test
60 public void testRegisterReceiver() {
Satoshi Sanno3756b092019-05-29 16:39:50 +090061 final ArgumentCaptor<BroadcastReceiver> broadcastReceiverCaptor =
62 ArgumentCaptor.forClass(BroadcastReceiver.class);
phweiss679dc242017-07-05 18:54:54 +020063 final ArgumentCaptor<IntentFilter> intentFilterCaptor =
64 ArgumentCaptor.forClass(IntentFilter.class);
65
Satoshi Sanno3756b092019-05-29 16:39:50 +090066 mDialog.show();
Fabian Kozynskiff5e91f2019-09-24 15:38:08 -040067 verify(mBroadcastDispatcher).registerReceiver(broadcastReceiverCaptor.capture(),
68 intentFilterCaptor.capture(), eq(null), any());
phweiss679dc242017-07-05 18:54:54 +020069
70 assertTrue(intentFilterCaptor.getValue().hasAction(Intent.ACTION_CLOSE_SYSTEM_DIALOGS));
phweiss679dc242017-07-05 18:54:54 +020071
Satoshi Sanno3756b092019-05-29 16:39:50 +090072 mDialog.dismiss();
Fabian Kozynskiff5e91f2019-09-24 15:38:08 -040073 verify(mBroadcastDispatcher).unregisterReceiver(eq(broadcastReceiverCaptor.getValue()));
Satoshi Sanno3756b092019-05-29 16:39:50 +090074 }
phweiss679dc242017-07-05 18:54:54 +020075}