Chromium Code Reviews| Index: chrome/android/sync_shell/javatests/src/chromium/chrome/browser/sync/SyncTestUtil.java |
| diff --git a/chrome/test/android/javatests/src/org/chromium/chrome/test/util/browser/sync/SyncTestUtil.java b/chrome/android/sync_shell/javatests/src/chromium/chrome/browser/sync/SyncTestUtil.java |
| similarity index 90% |
| rename from chrome/test/android/javatests/src/org/chromium/chrome/test/util/browser/sync/SyncTestUtil.java |
| rename to chrome/android/sync_shell/javatests/src/chromium/chrome/browser/sync/SyncTestUtil.java |
| index d525a4ff59ee19df2bc55a6fe974f0b60319e1c1..4812053674df1fb8cbc3e8ad9f970d7dbebcb9dc 100644 |
| --- a/chrome/test/android/javatests/src/org/chromium/chrome/test/util/browser/sync/SyncTestUtil.java |
| +++ b/chrome/android/sync_shell/javatests/src/chromium/chrome/browser/sync/SyncTestUtil.java |
| @@ -2,7 +2,7 @@ |
| // Use of this source code is governed by a BSD-style license that can be |
| // found in the LICENSE file. |
| -package org.chromium.chrome.test.util.browser.sync; |
| +package org.chromium.chrome.browser.sync; |
|
rlarocque
2014/08/19 18:04:19
Just making sure I understand this:
This code use
pval...(no longer on Chromium)
2014/08/19 18:43:22
It used to be in ChromeShellTest.apk and now it is
|
| import static org.chromium.base.test.util.ScalableTimeout.scaleTimeout; |
| @@ -16,13 +16,13 @@ import junit.framework.Assert; |
| import org.chromium.base.CommandLine; |
| import org.chromium.base.ThreadUtils; |
| import org.chromium.base.test.util.AdvancedMockContext; |
| -import org.chromium.chrome.browser.sync.ProfileSyncService; |
| import org.chromium.chrome.test.util.TestHttpServerClient; |
| import org.chromium.content.browser.test.util.Criteria; |
| import org.chromium.content.browser.test.util.CriteriaHelper; |
| import org.chromium.sync.signin.AccountManagerHelper; |
| import org.chromium.sync.signin.ChromeSigninController; |
| import org.chromium.sync.test.util.AccountHolder; |
| +import org.chromium.sync.test.util.FakeServerHelper; |
| import org.chromium.sync.test.util.MockAccountManager; |
| import org.json.JSONArray; |
| import org.json.JSONException; |
| @@ -62,6 +62,10 @@ public final class SyncTestUtil { |
| // Native switch - chrome_switches::kSyncServiceURL |
| private static final String SYNC_URL = "sync-url"; |
| + // Pointer value for the FakeServer. This pointer is not owned by native |
| + // code, so it must be stored here for future deletion. |
| + private static long sNativeFakeServer = 0L; |
| + |
| private SyncTestUtil() { |
| } |
| @@ -392,4 +396,42 @@ public final class SyncTestUtil { |
| return super.getSystemService(name); |
| } |
| } |
| + |
| + /** |
| + * Creates and configures FakeServer. |
| + * |
| + * Each call to this method should be accompanied by a later call to deleteFakeServer to avoid |
| + * a memory leak. |
| + */ |
| + public static void useFakeServer(final Context context) { |
| + if (sNativeFakeServer != 0L) { |
| + throw new IllegalStateException( |
| + "deleteFakeServer must be called before calling useFakeServer again."); |
| + } |
| + |
| + sNativeFakeServer = ThreadUtils.runOnUiThreadBlockingNoException(new Callable<Long>() { |
| + @Override |
| + public Long call() { |
| + FakeServerHelper fakeServerHelper = FakeServerHelper.get(); |
| + long nativeFakeServer = fakeServerHelper.createFakeServer(); |
| + long resources = fakeServerHelper.createNetworkResources(nativeFakeServer); |
| + ProfileSyncService.get(context).overrideNetworkResourcesForTest(resources); |
| + |
| + return nativeFakeServer; |
| + } |
| + }); |
| + } |
| + |
| + /** |
| + * Deletes the existing FakeServer. |
| + */ |
| + public static void deleteFakeServer() { |
| + if (sNativeFakeServer == 0L) { |
| + throw new IllegalStateException( |
| + "useFakeServer must be called before calling deleteFakeServer."); |
| + } |
| + |
| + FakeServerHelper.get().deleteFakeServer(sNativeFakeServer); |
| + sNativeFakeServer = 0L; |
| + } |
| } |