Index: chrome/android/sync_shell/javatests/src/org/chromium/chrome/browser/sync/FakeServerHelper.java |
diff --git a/chrome/android/sync_shell/javatests/src/org/chromium/chrome/browser/sync/FakeServerHelper.java b/chrome/android/sync_shell/javatests/src/org/chromium/chrome/browser/sync/FakeServerHelper.java |
index bdc99e4d2a64e2e3bb9e381cdf9b09d46d72ea31..8a9a2dea8bdca72abceef87b4f02063c500090a5 100644 |
--- a/chrome/android/sync_shell/javatests/src/org/chromium/chrome/browser/sync/FakeServerHelper.java |
+++ b/chrome/android/sync_shell/javatests/src/org/chromium/chrome/browser/sync/FakeServerHelper.java |
@@ -6,18 +6,25 @@ package org.chromium.chrome.browser.sync; |
import android.content.Context; |
+import com.google.protobuf.nano.InvalidProtocolBufferNanoException; |
import com.google.protobuf.nano.MessageNano; |
import org.chromium.base.ThreadUtils; |
import org.chromium.sync.internal_api.pub.base.ModelType; |
import org.chromium.sync.protocol.EntitySpecifics; |
+import org.chromium.sync.protocol.SyncEntity; |
+import java.util.ArrayList; |
+import java.util.List; |
import java.util.concurrent.Callable; |
+import java.util.concurrent.ExecutionException; |
/** |
* Assists in Java interaction the native Sync FakeServer. |
*/ |
public class FakeServerHelper { |
+ private static final String TAG = "cr.FakeServerHelper"; |
+ |
// Lazily-instantiated singleton FakeServerHelper. |
private static FakeServerHelper sFakeServerHelper; |
@@ -153,6 +160,13 @@ public class FakeServerHelper { |
}); |
} |
+ /** |
+ * Verifies whether the sessions on the fake Sync server match the given set of urls. |
+ * |
+ * @param urls the set of urls to check against; order does not matter. |
+ * |
+ * @return whether the sessions on the server match the given urls. |
+ */ |
public boolean verifySessions(final String[] urls) { |
checkFakeServerInitialized( |
"useFakeServer must be called before data verification."); |
@@ -166,6 +180,32 @@ public class FakeServerHelper { |
} |
/** |
+ * Returns all the SyncEntities on the fake server with the given modelType. |
+ * |
+ * @param modelType the type of entities to return. |
+ * |
+ * @return a list of all the SyncEntity protos for that type. |
+ */ |
+ public List<SyncEntity> getSyncEntitiesByModelType(final ModelType modelType) |
+ throws ExecutionException { |
+ checkFakeServerInitialized("useFakeServer must be called before getting sync entities."); |
+ return ThreadUtils.runOnUiThreadBlocking(new Callable<List<SyncEntity>>() { |
+ @Override |
+ public List<SyncEntity> call() throws InvalidProtocolBufferNanoException { |
+ byte[][] serializedEntities = nativeGetSyncEntitiesByModelType( |
+ mNativeFakeServerHelperAndroid, sNativeFakeServer, modelType.toString()); |
+ List<SyncEntity> entities = new ArrayList<SyncEntity>(serializedEntities.length); |
+ for (int i = 0; i < serializedEntities.length; i++) { |
+ SyncEntity entity = new SyncEntity(); |
+ MessageNano.mergeFrom(entity, serializedEntities[i]); |
+ entities.add(entity); |
+ } |
+ return entities; |
+ } |
+ }); |
+ } |
+ |
+ /** |
* Injects an entity into the fake Sync server. This method only works for entities that will |
* eventually contain a unique client tag (e.g., preferences, typed URLs). |
* |
@@ -340,6 +380,8 @@ public class FakeServerHelper { |
String name); |
private native boolean nativeVerifySessions( |
long nativeFakeServerHelperAndroid, long nativeFakeServer, String[] urlArray); |
+ private native byte[][] nativeGetSyncEntitiesByModelType( |
+ long nativeFakeServerHelperAndroid, long nativeFakeServer, String modelType); |
private native void nativeInjectUniqueClientEntity( |
long nativeFakeServerHelperAndroid, long nativeFakeServer, String name, |
byte[] serializedEntitySpecifics); |