Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(295)

Unified Diff: components/policy/android/java/src/org/chromium/policy/AbstractAppRestrictionsProvider.java

Issue 1387633002: Update instrumentation tests to use PreTestHooks for policies (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Rebase, replace bundle manipulation with a simple variable Created 5 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
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;
+ }
}

Powered by Google App Engine
This is Rietveld 408576698