OLD | NEW |
1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 package org.chromium.chrome.test.util.browser; | 5 package org.chromium.chrome.test.util.browser; |
6 | 6 |
7 import android.content.Context; | |
8 | |
9 import org.chromium.base.ThreadUtils; | 7 import org.chromium.base.ThreadUtils; |
10 import org.chromium.components.location.LocationUtils; | 8 import org.chromium.chrome.browser.preferences.LocationSettings; |
11 | 9 |
12 /** | 10 /** |
13 * Methods for testing location-related features. | 11 * Methods for testing location-related features. |
14 */ | 12 */ |
15 public class LocationSettingsTestUtil { | 13 public class LocationSettingsTestUtil { |
16 | 14 |
17 /** | 15 /** |
18 * Mocks the system location setting as either enabled or disabled. Can be c
alled on any thread. | 16 * Mocks the system location setting as either enabled or disabled. Can be c
alled on any thread. |
19 */ | 17 */ |
20 public static void setSystemLocationSettingEnabled(final boolean enabled) { | 18 public static void setSystemLocationSettingEnabled(final boolean enabled) { |
21 ThreadUtils.runOnUiThreadBlocking(new Runnable() { | 19 ThreadUtils.runOnUiThreadBlocking(new Runnable() { |
22 @Override | 20 @Override |
23 public void run() { | 21 public void run() { |
24 LocationUtils.setFactory(new LocationUtils.Factory() { | 22 LocationSettings.setInstanceForTesting(new LocationSettings(null
) { |
25 @Override | 23 @Override |
26 public LocationUtils create() { | 24 public boolean isSystemLocationSettingEnabled() { |
27 return new LocationUtils() { | 25 return enabled; |
28 @Override | |
29 public boolean isSystemLocationSettingEnabled(Contex
t context) { | |
30 return enabled; | |
31 } | |
32 }; | |
33 } | 26 } |
34 }); | 27 }); |
35 } | 28 } |
36 }); | 29 }); |
37 } | 30 } |
38 } | 31 } |
OLD | NEW |