blob: 3dcb34aac8143036547520b51c9def0648bc57b1 [file] [log] [blame]
Jason Monkb46a3c92017-06-22 09:19:54 -04001/*
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.policy;
16
17import static org.mockito.Mockito.mock;
18import static org.mockito.Mockito.spy;
19import static org.mockito.Mockito.when;
20
21import android.content.Intent;
22import android.location.LocationManager;
Jason Monkb46a3c92017-06-22 09:19:54 -040023import android.testing.AndroidTestingRunner;
24import android.testing.TestableLooper;
25import android.testing.TestableLooper.RunWithLooper;
26
Brett Chabot84151d92019-02-27 15:37:59 -080027import androidx.test.filters.SmallTest;
28
Jason Monkb46a3c92017-06-22 09:19:54 -040029import com.android.systemui.SysuiTestCase;
30import com.android.systemui.statusbar.policy.LocationController.LocationChangeCallback;
31
32import org.junit.Before;
Alison Cichowlas863cee72018-02-06 18:06:03 -050033import org.junit.Ignore;
Jason Monkb46a3c92017-06-22 09:19:54 -040034import org.junit.Test;
35import org.junit.runner.RunWith;
36
37@RunWith(AndroidTestingRunner.class)
38@RunWithLooper
39@SmallTest
40public class LocationControllerImplTest extends SysuiTestCase {
41
42 private LocationControllerImpl mLocationController;
43
44 @Before
45 public void setup() {
46 mLocationController = spy(new LocationControllerImpl(mContext,
47 TestableLooper.get(this).getLooper()));
48 }
49
50 @Test
Alison Cichowlas5d7d9592018-07-17 15:30:28 -040051 @Ignore("flaky")
Jason Monkb46a3c92017-06-22 09:19:54 -040052 public void testRemoveSelfActive_DoesNotCrash() {
53 LocationController.LocationChangeCallback callback = new LocationChangeCallback() {
54 @Override
55 public void onLocationActiveChanged(boolean active) {
56 mLocationController.removeCallback(this);
57 }
58 };
59 mLocationController.addCallback(callback);
60 mLocationController.addCallback(mock(LocationChangeCallback.class));
61
62 when(mLocationController.areActiveHighPowerLocationRequests()).thenReturn(false);
63 mLocationController.onReceive(mContext, new Intent(
64 LocationManager.HIGH_POWER_REQUEST_CHANGE_ACTION));
65 when(mLocationController.areActiveHighPowerLocationRequests()).thenReturn(true);
66 mLocationController.onReceive(mContext, new Intent(
67 LocationManager.HIGH_POWER_REQUEST_CHANGE_ACTION));
68
69 TestableLooper.get(this).processAllMessages();
70 }
71
72 @Test
Alison Cichowlas5d7d9592018-07-17 15:30:28 -040073 @Ignore("flaky")
Jason Monkb46a3c92017-06-22 09:19:54 -040074 public void testRemoveSelfSettings_DoesNotCrash() {
75 LocationController.LocationChangeCallback callback = new LocationChangeCallback() {
76 @Override
77 public void onLocationSettingsChanged(boolean isEnabled) {
78 mLocationController.removeCallback(this);
79 }
80 };
81 mLocationController.addCallback(callback);
82 mLocationController.addCallback(mock(LocationChangeCallback.class));
83
84 TestableLooper.get(this).processAllMessages();
85 }
Alison Cichowlas863cee72018-02-06 18:06:03 -050086}