Jason Monk | b46a3c9 | 2017-06-22 09:19:54 -0400 | [diff] [blame] | 1 | /* |
| 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 | |
| 15 | package com.android.systemui.statusbar.policy; |
| 16 | |
| 17 | import static org.mockito.Mockito.mock; |
| 18 | import static org.mockito.Mockito.spy; |
| 19 | import static org.mockito.Mockito.when; |
| 20 | |
| 21 | import android.content.Intent; |
| 22 | import android.location.LocationManager; |
Jason Monk | b46a3c9 | 2017-06-22 09:19:54 -0400 | [diff] [blame] | 23 | import android.testing.AndroidTestingRunner; |
| 24 | import android.testing.TestableLooper; |
| 25 | import android.testing.TestableLooper.RunWithLooper; |
| 26 | |
Brett Chabot | 84151d9 | 2019-02-27 15:37:59 -0800 | [diff] [blame] | 27 | import androidx.test.filters.SmallTest; |
| 28 | |
Jason Monk | b46a3c9 | 2017-06-22 09:19:54 -0400 | [diff] [blame] | 29 | import com.android.systemui.SysuiTestCase; |
Fabian Kozynski | 5ca7a51 | 2019-10-16 19:56:11 +0000 | [diff] [blame] | 30 | import com.android.systemui.broadcast.BroadcastDispatcher; |
Jason Monk | b46a3c9 | 2017-06-22 09:19:54 -0400 | [diff] [blame] | 31 | import com.android.systemui.statusbar.policy.LocationController.LocationChangeCallback; |
| 32 | |
| 33 | import org.junit.Before; |
Alison Cichowlas | 863cee7 | 2018-02-06 18:06:03 -0500 | [diff] [blame] | 34 | import org.junit.Ignore; |
Jason Monk | b46a3c9 | 2017-06-22 09:19:54 -0400 | [diff] [blame] | 35 | import org.junit.Test; |
| 36 | import org.junit.runner.RunWith; |
| 37 | |
| 38 | @RunWith(AndroidTestingRunner.class) |
| 39 | @RunWithLooper |
| 40 | @SmallTest |
| 41 | public class LocationControllerImplTest extends SysuiTestCase { |
| 42 | |
| 43 | private LocationControllerImpl mLocationController; |
| 44 | |
| 45 | @Before |
| 46 | public void setup() { |
| 47 | mLocationController = spy(new LocationControllerImpl(mContext, |
Fabian Kozynski | 5ca7a51 | 2019-10-16 19:56:11 +0000 | [diff] [blame] | 48 | TestableLooper.get(this).getLooper(), |
| 49 | mock(BroadcastDispatcher.class))); |
Jason Monk | b46a3c9 | 2017-06-22 09:19:54 -0400 | [diff] [blame] | 50 | } |
| 51 | |
| 52 | @Test |
Alison Cichowlas | 5d7d959 | 2018-07-17 15:30:28 -0400 | [diff] [blame] | 53 | @Ignore("flaky") |
Jason Monk | b46a3c9 | 2017-06-22 09:19:54 -0400 | [diff] [blame] | 54 | public void testRemoveSelfActive_DoesNotCrash() { |
| 55 | LocationController.LocationChangeCallback callback = new LocationChangeCallback() { |
| 56 | @Override |
| 57 | public void onLocationActiveChanged(boolean active) { |
| 58 | mLocationController.removeCallback(this); |
| 59 | } |
| 60 | }; |
| 61 | mLocationController.addCallback(callback); |
| 62 | mLocationController.addCallback(mock(LocationChangeCallback.class)); |
| 63 | |
| 64 | when(mLocationController.areActiveHighPowerLocationRequests()).thenReturn(false); |
| 65 | mLocationController.onReceive(mContext, new Intent( |
| 66 | LocationManager.HIGH_POWER_REQUEST_CHANGE_ACTION)); |
| 67 | when(mLocationController.areActiveHighPowerLocationRequests()).thenReturn(true); |
| 68 | mLocationController.onReceive(mContext, new Intent( |
| 69 | LocationManager.HIGH_POWER_REQUEST_CHANGE_ACTION)); |
| 70 | |
| 71 | TestableLooper.get(this).processAllMessages(); |
| 72 | } |
| 73 | |
| 74 | @Test |
Alison Cichowlas | 5d7d959 | 2018-07-17 15:30:28 -0400 | [diff] [blame] | 75 | @Ignore("flaky") |
Jason Monk | b46a3c9 | 2017-06-22 09:19:54 -0400 | [diff] [blame] | 76 | public void testRemoveSelfSettings_DoesNotCrash() { |
| 77 | LocationController.LocationChangeCallback callback = new LocationChangeCallback() { |
| 78 | @Override |
| 79 | public void onLocationSettingsChanged(boolean isEnabled) { |
| 80 | mLocationController.removeCallback(this); |
| 81 | } |
| 82 | }; |
| 83 | mLocationController.addCallback(callback); |
| 84 | mLocationController.addCallback(mock(LocationChangeCallback.class)); |
| 85 | |
| 86 | TestableLooper.get(this).processAllMessages(); |
| 87 | } |
Alison Cichowlas | 863cee7 | 2018-02-06 18:06:03 -0500 | [diff] [blame] | 88 | } |