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

Unified Diff: components/policy/android/javatests/src/org/chromium/policy/test/PolicyData.java

Issue 1387633002: Update instrumentation tests to use PreTestHooks for policies (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: 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/javatests/src/org/chromium/policy/test/PolicyData.java
diff --git a/components/policy/android/javatests/src/org/chromium/policy/test/PolicyData.java b/components/policy/android/javatests/src/org/chromium/policy/test/PolicyData.java
new file mode 100644
index 0000000000000000000000000000000000000000..60136e7e72ebea1d3826dd14b0b2f5d958f54955
--- /dev/null
+++ b/components/policy/android/javatests/src/org/chromium/policy/test/PolicyData.java
@@ -0,0 +1,93 @@
+// Copyright 2015 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+package org.chromium.policy.test;
+
+import android.os.Bundle;
+import android.text.TextUtils;
+
+/**
+ * Helper class to transform Java types to {@link Bundle}s usable by the Policy system.
+ *
+ * Use the subclasses to define the data and then transform it using {@link #asBundle(Iterable)}
+ */
+public abstract class PolicyData {
+ public final String mKey;
+
+ public PolicyData(String key) {
+ mKey = key;
+ }
+
+ public abstract void putInBundle(Bundle bundle);
+
+ public static Bundle asBundle(Iterable<PolicyData> policies) {
+ Bundle bundle = new Bundle();
+ for (PolicyData data : policies) {
+ data.putInBundle(bundle);
+ }
+ return bundle;
+ }
+
+ @Override
+ public int hashCode() {
+ final int prime = 31;
+ int result = 1;
+ result = prime * result + ((mKey == null) ? 0 : mKey.hashCode());
+ return result;
+ }
+
+ /** Equality for this class hierarchy is based only on the key. */
+ @Override
+ public boolean equals(Object obj) {
+ if (this == obj) return true;
+ if (obj == null) return false;
+ if (!(obj instanceof PolicyData)) return false;
+ PolicyData other = (PolicyData) obj;
+ return TextUtils.equals(mKey, other.mKey);
+ }
+
+ /** {@link PolicyData} for the {@link String} type. */
+ public static class Str extends PolicyData {
+ public final String mValue;
+
+ public Str(String key, String value) {
+ super(key);
+ mValue = value;
+ }
+
+ @Override
+ public void putInBundle(Bundle bundle) {
+ bundle.putString(mKey, mValue);
+ }
+ }
+
+ /** {@link PolicyData} with no type, for error states. Doesn't put anything in a bundle.*/
+ public static class Undefined extends PolicyData {
+ public Undefined(String key) {
+ super(key);
+ }
+
+ @Override
+ public void putInBundle(Bundle bundle) {}
+ }
+
+ /**
+ * {@link PolicyData} for the {@link String } array type.
+ * Outputs a string encoded as a JSON array.
+ */
+ public static class StrArray extends PolicyData {
+ public final String[] mValue;
+
+ public StrArray(String key, String[] value) {
+ super(key);
+ mValue = value;
+ }
+
+ @Override
+ public void putInBundle(Bundle bundle) {
+ String joinedStrings = TextUtils.join("\",\"", mValue);
+ bundle.putString(mKey, "[\"" + joinedStrings + "\"]");
+ }
+ }
+}

Powered by Google App Engine
This is Rietveld 408576698