| 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 |
| 7 import org.chromium.base.ThreadUtils; | 9 import org.chromium.base.ThreadUtils; |
| 8 import org.chromium.chrome.browser.preferences.LocationSettings; | 10 import org.chromium.components.location.LocationUtils; |
| 9 | 11 |
| 10 /** | 12 /** |
| 11 * Methods for testing location-related features. | 13 * Methods for testing location-related features. |
| 12 */ | 14 */ |
| 13 public class LocationSettingsTestUtil { | 15 public class LocationSettingsTestUtil { |
| 14 | 16 |
| 15 /** | 17 /** |
| 16 * Mocks the system location setting as either enabled or disabled. Can be c
alled on any thread. | 18 * Mocks the system location setting as either enabled or disabled. Can be c
alled on any thread. |
| 17 */ | 19 */ |
| 18 public static void setSystemLocationSettingEnabled(final boolean enabled) { | 20 public static void setSystemLocationSettingEnabled(final boolean enabled) { |
| 19 ThreadUtils.runOnUiThreadBlocking(new Runnable() { | 21 ThreadUtils.runOnUiThreadBlocking(new Runnable() { |
| 20 @Override | 22 @Override |
| 21 public void run() { | 23 public void run() { |
| 22 LocationSettings.setInstanceForTesting(new LocationSettings(null
) { | 24 LocationUtils.setFactory(new LocationUtils.Factory() { |
| 23 @Override | 25 @Override |
| 24 public boolean isSystemLocationSettingEnabled() { | 26 public LocationUtils create() { |
| 25 return enabled; | 27 return new LocationUtils() { |
| 28 @Override |
| 29 public boolean isSystemLocationSettingEnabled(Contex
t context) { |
| 30 return enabled; |
| 31 } |
| 32 }; |
| 26 } | 33 } |
| 27 }); | 34 }); |
| 28 } | 35 } |
| 29 }); | 36 }); |
| 30 } | 37 } |
| 31 } | 38 } |
| OLD | NEW |