| Index: components/policy/android/java/src/org/chromium/policy/AbstractAppRestrictionsProvider.java
|
| diff --git a/components/policy/android/java/src/org/chromium/policy/AbstractAppRestrictionsProvider.java b/components/policy/android/java/src/org/chromium/policy/AbstractAppRestrictionsProvider.java
|
| index 60b40bd139a467abdc88342ece61ae473486b3ac..82b19399d9ec1ae6f8fe20fcb4cb678ee251b5ed 100644
|
| --- a/components/policy/android/java/src/org/chromium/policy/AbstractAppRestrictionsProvider.java
|
| +++ b/components/policy/android/java/src/org/chromium/policy/AbstractAppRestrictionsProvider.java
|
| @@ -15,6 +15,7 @@
|
| import android.preference.PreferenceManager;
|
| import android.util.Base64;
|
|
|
| +import org.chromium.base.Log;
|
| import org.chromium.base.VisibleForTesting;
|
| import org.chromium.base.metrics.RecordHistogram;
|
|
|
| @@ -30,6 +31,11 @@
|
| public abstract class AbstractAppRestrictionsProvider extends PolicyProvider {
|
| private static final String PREFERENCE_KEY = "App Restrictions";
|
|
|
| + private static final String TAG = "policy";
|
| +
|
| + /** {@link Bundle} holding the restrictions to be used during tests. */
|
| + private static Bundle sTestRestrictions = null;
|
| +
|
| private final Context mContext;
|
| private final SharedPreferences mSharedPreferences;
|
| private final BroadcastReceiver mAppRestrictionsChangedReceiver = new BroadcastReceiver() {
|
| @@ -79,6 +85,11 @@ public void startListeningForPolicyChanges() {
|
| */
|
| @Override
|
| public void refresh() {
|
| + if (sTestRestrictions != null) {
|
| + notifySettingsAvailable(sTestRestrictions);
|
| + return;
|
| + }
|
| +
|
| final Bundle cachedResult = getCachedPolicies();
|
| if (cachedResult != null) {
|
| notifySettingsAvailable(cachedResult);
|
| @@ -169,4 +180,18 @@ protected void recordStartTimeHistogram(long startTime) {
|
| void setTaskExecutor(Executor testExecutor) {
|
| mExecutor = testExecutor;
|
| }
|
| +
|
| + /**
|
| + * Restrictions to be used during tests. Subsequent attempts to retrieve the restrictions will
|
| + * return the provided bundle instead.
|
| + *
|
| + * Chrome and WebView tests are set up to use annotations for policy testing and reset the
|
| + * restrictions to an empty bundle if nothing is specified. To stop using a test bundle,
|
| + * provide {@code null} as value instead.
|
| + */
|
| + @VisibleForTesting
|
| + public static void setTestRestrictions(Bundle policies) {
|
| + Log.d(TAG, "Test Restrictions: %s", policies.keySet().toArray());
|
| + sTestRestrictions = policies;
|
| + }
|
| }
|
|
|