blob: a0fb33014928f6c3908f05d2fdbd7e6f5d564c04 [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;
23import android.support.test.filters.SmallTest;
24import android.testing.AndroidTestingRunner;
25import android.testing.TestableLooper;
26import android.testing.TestableLooper.RunWithLooper;
27
28import com.android.systemui.SysuiTestCase;
29import com.android.systemui.statusbar.policy.LocationController.LocationChangeCallback;
30
31import org.junit.Before;
Alison Cichowlas863cee72018-02-06 18:06:03 -050032import org.junit.Ignore;
Jason Monkb46a3c92017-06-22 09:19:54 -040033import org.junit.Test;
34import org.junit.runner.RunWith;
35
36@RunWith(AndroidTestingRunner.class)
37@RunWithLooper
38@SmallTest
39public class LocationControllerImplTest extends SysuiTestCase {
40
41 private LocationControllerImpl mLocationController;
42
43 @Before
44 public void setup() {
45 mLocationController = spy(new LocationControllerImpl(mContext,
46 TestableLooper.get(this).getLooper()));
47 }
48
49 @Test
Alison Cichowlas5d7d9592018-07-17 15:30:28 -040050 @Ignore("flaky")
Jason Monkb46a3c92017-06-22 09:19:54 -040051 public void testRemoveSelfActive_DoesNotCrash() {
52 LocationController.LocationChangeCallback callback = new LocationChangeCallback() {
53 @Override
54 public void onLocationActiveChanged(boolean active) {
55 mLocationController.removeCallback(this);
56 }
57 };
58 mLocationController.addCallback(callback);
59 mLocationController.addCallback(mock(LocationChangeCallback.class));
60
61 when(mLocationController.areActiveHighPowerLocationRequests()).thenReturn(false);
62 mLocationController.onReceive(mContext, new Intent(
63 LocationManager.HIGH_POWER_REQUEST_CHANGE_ACTION));
64 when(mLocationController.areActiveHighPowerLocationRequests()).thenReturn(true);
65 mLocationController.onReceive(mContext, new Intent(
66 LocationManager.HIGH_POWER_REQUEST_CHANGE_ACTION));
67
68 TestableLooper.get(this).processAllMessages();
69 }
70
71 @Test
Alison Cichowlas5d7d9592018-07-17 15:30:28 -040072 @Ignore("flaky")
Jason Monkb46a3c92017-06-22 09:19:54 -040073 public void testRemoveSelfSettings_DoesNotCrash() {
74 LocationController.LocationChangeCallback callback = new LocationChangeCallback() {
75 @Override
76 public void onLocationSettingsChanged(boolean isEnabled) {
77 mLocationController.removeCallback(this);
78 }
79 };
80 mLocationController.addCallback(callback);
81 mLocationController.addCallback(mock(LocationChangeCallback.class));
82
83 TestableLooper.get(this).processAllMessages();
84 }
Alison Cichowlas863cee72018-02-06 18:06:03 -050085}