Create ChromeSyncShell and ChromeSyncShellTest

This CL enables usage of the Sync FakeServer in Android tests. This is
done by creating a new ChromeShell-based APK, ChromeSyncShell, and a
test APK that instruments it (ChromeSyncShellTest).

As part of this CL, previously-disabled tests (SyncTest.java) are
re-enabled. However, these tests will not run as part of the Chromium
waterfall/trybots as they are not configured to run ChromeSyncShellTest.

How to run the tests:
1) Build these targets:
   chrome_sync_shell_apk
   chrome_sync_shell_test_apk

2) Run test script
   build/android/adb_install_apk.py \
   --apk=ChromeSyncShell.apk && \
   build/android/test_runner.py instrumentation \
   --test-apk ChromeSyncShellTest

BUG=323265,348951,348117
TBR=cpu@chromium.org

Review URL: https://codereview.chromium.org/457883002

Cr-Commit-Position: refs/heads/master@{#291190}
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@291190 0039d316-1c4b-4281-b951-d872f2087c98
parent 8153ccfd
#!/usr/bin/python
# Copyright 2013 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.
"""Host-driven Java tests which exercise sync functionality."""
from pylib import constants
from pylib.host_driven import test_case
from pylib.host_driven import test_server
from pylib.host_driven import tests_annotations
class SyncTest(test_case.HostDrivenTestCase):
"""Host-driven Java tests which exercise sync functionality."""
def __init__(self, *args, **kwargs):
super(SyncTest, self).__init__(*args, **kwargs)
self.test_server = None
self.additional_flags = []
def SetUp(self, device, shard_index, push_deps, cleanup_test_files):
self.test_server = test_server.TestServer(
shard_index,
constants.TEST_SYNC_SERVER_PORT,
test_server.TEST_SYNC_SERVER_PATH)
# These ought not to change in the middle of a test for obvious reasons.
self.additional_flags = [
'--sync-url=http://%s:%d/chromiumsync' %
(self.test_server.host, self.test_server.port),
'--sync-deferred-startup-timeout-seconds=0']
super(SyncTest, self).SetUp(device, shard_index, push_deps,
cleanup_test_files,
[self.test_server.port])
def TearDown(self):
super(SyncTest, self).TearDown()
self.test_server.TearDown()
def _RunSyncTests(self, test_names):
full_names = []
for test_name in test_names:
full_names.append('SyncTest.' + test_name)
return self._RunJavaTestFilters(full_names, self.additional_flags)
# http://crbug.com/348951
# @tests_annotations.Feature(['Sync'])
# @tests_annotations.EnormousTest
@tests_annotations.DisabledTest
def testGetAboutSyncInfoYieldsValidData(self):
java_tests = ['testGetAboutSyncInfoYieldsValidData']
return self._RunSyncTests(java_tests)
# http://crbug.com/348117
# @tests_annotations.Feature(['Sync'])
# @tests_annotations.EnormousTest
@tests_annotations.DisabledTest
def testAboutSyncPageDisplaysCurrentSyncStatus(self):
java_tests = ['testAboutSyncPageDisplaysCurrentSyncStatus']
return self._RunSyncTests(java_tests)
# http://crbug.com/348951
# @tests_annotations.Feature(['Sync'])
# @tests_annotations.EnormousTest
@tests_annotations.DisabledTest
def testDisableAndEnableSync(self):
java_tests = ['testDisableAndEnableSync']
return self._RunSyncTests(java_tests)
......@@ -501,6 +501,18 @@ public class ProfileSyncService {
return nativeGetLastSyncedTimeForTest(mNativeProfileSyncServiceAndroid);
}
/**
* Overrides the Sync engine's NetworkResources. This is used to set up the Sync FakeServer for
* testing.
*
* @param networkResources the pointer to the NetworkResources created by the native code. It
* is assumed that the Java caller has ownership of this pointer;
* ownership is transferred as part of this call.
*/
public void overrideNetworkResourcesForTest(long networkResources) {
nativeOverrideNetworkResourcesForTest(mNativeProfileSyncServiceAndroid, networkResources);
}
// Native methods
private native void nativeNudgeSyncer(
long nativeProfileSyncServiceAndroid, int objectSource, String objectId, long version,
......@@ -552,4 +564,6 @@ public class ProfileSyncService {
private native boolean nativeHasUnrecoverableError(long nativeProfileSyncServiceAndroid);
private native String nativeGetAboutInfoForTest(long nativeProfileSyncServiceAndroid);
private native long nativeGetLastSyncedTimeForTest(long nativeProfileSyncServiceAndroid);
private native void nativeOverrideNetworkResourcesForTest(
long nativeProfileSyncServiceAndroid, long networkResources);
}
......@@ -153,7 +153,10 @@ public class SyncController implements ProfileSyncService.SyncStateChangedListen
}
}
private void stop() {
/**
* Stops Sync if a user is currently signed in.
*/
public void stop() {
ThreadUtils.assertOnUiThread();
if (mChromeSigninController.isSignedIn()) {
Log.d(TAG, "Disabling sync");
......
include_rules = [
"+chrome/app",
"+components/search_engines",
"+sync/test/fake_server/android",
]
yfriedman@chromium.org
zea@chromium.org
ChromeSyncShell (and ChromeSyncShellTest) exists because we don't want to
include the Sync FakeServer as part of ChromeShell.
// Copyright 2014 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.
#include "chrome/android/sync_shell/chrome_main_delegate_chrome_sync_shell_android.h"
#include "base/android/jni_android.h"
#include "base/android/jni_registrar.h"
#include "components/search_engines/template_url_prepopulate_data.h"
#include "sync/test/fake_server/android/fake_server_helper_android.h"
static const char kDefaultCountryCode[] = "US";
ChromeMainDelegateAndroid* ChromeMainDelegateAndroid::Create() {
return new ChromeMainDelegateChromeSyncShellAndroid();
}
ChromeMainDelegateChromeSyncShellAndroid::
ChromeMainDelegateChromeSyncShellAndroid() {
}
ChromeMainDelegateChromeSyncShellAndroid::
~ChromeMainDelegateChromeSyncShellAndroid() {
}
bool
ChromeMainDelegateChromeSyncShellAndroid::RegisterApplicationNativeMethods(
JNIEnv* env) {
return ChromeMainDelegateAndroid::RegisterApplicationNativeMethods(env) &&
FakeServerHelperAndroid::Register(env);
}
bool ChromeMainDelegateChromeSyncShellAndroid::BasicStartupComplete(
int* exit_code) {
TemplateURLPrepopulateData::InitCountryCode(kDefaultCountryCode);
return ChromeMainDelegateAndroid::BasicStartupComplete(exit_code);
}
// Copyright 2014 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.
#ifndef CHROME_ANDROID_SYNC_SHELL_CHROME_MAIN_DELEGATE_CHROME_SYNC_SHELL_ANDROID_H_
#define CHROME_ANDROID_SYNC_SHELL_CHROME_MAIN_DELEGATE_CHROME_SYNC_SHELL_ANDROID_H_
#include "chrome/app/android/chrome_main_delegate_android.h"
class ChromeMainDelegateChromeSyncShellAndroid
: public ChromeMainDelegateAndroid {
public:
ChromeMainDelegateChromeSyncShellAndroid();
virtual ~ChromeMainDelegateChromeSyncShellAndroid();
virtual bool RegisterApplicationNativeMethods(JNIEnv* env) OVERRIDE;
virtual bool BasicStartupComplete(int* exit_code) OVERRIDE;
private:
DISALLOW_COPY_AND_ASSIGN(ChromeMainDelegateChromeSyncShellAndroid);
};
#endif // CHROME_ANDROID_SYNC_SHELL_CHROME_MAIN_DELEGATE_CHROME_SYNC_SHELL_ANDROID_H_
This diff is collapsed.
<?xml version="1.0" encoding="utf-8"?>
<!-- Copyright (c) 2012 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 name must be unique so suffix with "tests" so package loader
doesn't ignore this. -->
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="org.chromium.chrome.sync_shell.tests">
<!-- We add an application tag here just so that we can indicate that this
package needs to link against the android.test library, which is
needed when building test cases. -->
<application>
<uses-library android:name="android.test.runner" />
<activity android:name="org.chromium.sync.test.util.MockGrantCredentialsPermissionActivity"
android:exported="false">
<intent-filter>
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
</application>
<uses-sdk android:minSdkVersion="14" android:targetSdkVersion="20" />
<instrumentation android:name="android.test.InstrumentationTestRunner"
android:targetPackage="org.chromium.chrome.sync_shell"
android:label="Tests for org.chromium.chrome.sync_shell"/>
<uses-permission android:name="android.permission.RUN_INSTRUMENTATION" />
<uses-permission android:name="android.permission.INJECT_EVENTS" />
<uses-permission android:name="android.permission.ACCESS_MOCK_LOCATION" />
<uses-permission android:name="android.permission.READ_LOGS"/>
<uses-permission android:name="android.permission.WAKE_LOCK" />
</manifest>
include_rules = [
"+content/public/android/java",
"+sync/android/java/src/org/chromium/sync/notifier",
"+sync/android/java/src/org/chromium/sync/signin",
"+sync/test/android/javatests/src/org/chromium/sync/test/util",
]
// Copyright 2014 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.chrome.browser.sync;
import android.content.Context;
import org.chromium.base.ThreadUtils;
//import org.chromium.chrome.browser.sync.ProfileSyncService;
import java.util.concurrent.Callable;
/**
* Assists in Java interaction the native Sync FakeServer.
*/
public class FakeServerHelper {
// Lazily-instantiated singleton FakeServerHelper.
private static FakeServerHelper sFakeServerHelper;
// 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;
// The pointer to the native object called here.
private final long mNativeFakeServerHelperAndroid;
// Accesses the singleton FakeServerHelper. There is at most one instance created per
// application lifetime, so no deletion mechanism is provided for the native object.
public static FakeServerHelper get() {
ThreadUtils.assertOnUiThread();
if (sFakeServerHelper == null) {
sFakeServerHelper = new FakeServerHelper();
}
return sFakeServerHelper;
}
private FakeServerHelper() {
mNativeFakeServerHelperAndroid = nativeInit();
}
/**
* 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.");
}
ThreadUtils.runOnUiThreadBlockingNoException(new Callable<Void>() {
@Override
public Void call() {
FakeServerHelper.get().deleteFakeServer(sNativeFakeServer);
sNativeFakeServer = 0L;
return null;
}
});
}
/**
* Creates a native FakeServer object and returns its pointer. This pointer is owned by the
* Java caller.
*
* @return the FakeServer pointer
*/
public long createFakeServer() {
return nativeCreateFakeServer(mNativeFakeServerHelperAndroid);
}
/**
* Creates a native NetworkResources object. This pointer is owned by the Java caller, but
* ownership is transferred as part of ProfileSyncService.overrideNetworkResourcesForTest.
*
* @param nativeFakeServer pointer to a native FakeServer object.
* @return the NetworkResources pointer
*/
public long createNetworkResources(long nativeFakeServer) {
return nativeCreateNetworkResources(mNativeFakeServerHelperAndroid, nativeFakeServer);
}
/**
* Deletes a native FakeServer.
*
* @param nativeFakeServer the pointer to be deleted
*/
public void deleteFakeServer(long nativeFakeServer) {
nativeDeleteFakeServer(mNativeFakeServerHelperAndroid, nativeFakeServer);
}
// Native methods.
private native long nativeInit();
private native long nativeCreateFakeServer(long nativeFakeServerHelperAndroid);
private native long nativeCreateNetworkResources(
long nativeFakeServerHelperAndroid, long nativeFakeServer);
private native void nativeDeleteFakeServer(
long nativeFakeServerHelperAndroid, long nativeFakeServer);
}
// Copyright 2013 The Chromium Authors. All rights reserved.
// Copyright 2014 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.
......@@ -6,10 +6,11 @@ package org.chromium.chrome.browser.sync;
import android.accounts.Account;
import android.app.Activity;
import android.test.suitebuilder.annotation.LargeTest;
import android.util.Log;
import org.chromium.base.ThreadUtils;
import org.chromium.base.test.util.HostDrivenTest;
import org.chromium.base.test.util.Feature;
import org.chromium.chrome.browser.identity.UniqueIdentificationGenerator;
import org.chromium.chrome.browser.identity.UniqueIdentificationGeneratorFactory;
import org.chromium.chrome.browser.identity.UuidBasedUniqueIdentificationGenerator;
......@@ -65,10 +66,24 @@ public class SyncTest extends ChromeShellTestBase {
mSyncController = SyncController.get(mContext);
}
});
SyncTestUtil.verifySyncServerIsRunning();
FakeServerHelper.useFakeServer(getInstrumentation().getTargetContext());
}
@HostDrivenTest
@Override
protected void tearDown() throws Exception {
ThreadUtils.runOnUiThreadBlocking(new Runnable() {
@Override
public void run() {
mSyncController.stop();
FakeServerHelper.deleteFakeServer();
}
});
super.tearDown();
}
@LargeTest
@Feature({"Sync"})
public void testGetAboutSyncInfoYieldsValidData() throws Throwable {
setupTestAccountAndSignInToSync(FOREIGN_SESSION_TEST_MACHINE_ID);
......@@ -86,7 +101,8 @@ public class SyncTest extends ChromeShellTestBase {
assertTrue("Couldn't get about info.", gotInfo);
}
@HostDrivenTest
@LargeTest
@Feature({"Sync"})
public void testAboutSyncPageDisplaysCurrentSyncStatus() throws InterruptedException {
setupTestAccountAndSignInToSync(FOREIGN_SESSION_TEST_MACHINE_ID);
......@@ -130,7 +146,8 @@ public class SyncTest extends ChromeShellTestBase {
hadExpectedStatus);
}
@HostDrivenTest
@LargeTest
@Feature({"Sync"})
public void testDisableAndEnableSync() throws InterruptedException {
setupTestAccountAndSignInToSync(FOREIGN_SESSION_TEST_MACHINE_ID);
Account account =
......
......@@ -34,6 +34,7 @@
#include "google_apis/gaia/google_service_auth_error.h"
#include "grit/generated_resources.h"
#include "jni/ProfileSyncService_jni.h"
#include "sync/internal_api/public/network_resources.h"
#include "sync/internal_api/public/read_transaction.h"
#include "ui/base/l10n/l10n_util.h"
......@@ -475,6 +476,16 @@ jlong ProfileSyncServiceAndroid::GetLastSyncedTimeForTest(
profile_->GetPrefs()->GetInt64(sync_driver::prefs::kSyncLastSyncedTime));
}
void ProfileSyncServiceAndroid::OverrideNetworkResourcesForTest(
JNIEnv* env,
jobject obj,
jlong network_resources) {
syncer::NetworkResources* resources =
reinterpret_cast<syncer::NetworkResources*>(network_resources);
sync_service_->OverrideNetworkResourcesForTest(
make_scoped_ptr<syncer::NetworkResources>(resources));
}
void ProfileSyncServiceAndroid::NudgeSyncer(JNIEnv* env,
jobject obj,
jint objectSource,
......
......@@ -198,6 +198,12 @@ class ProfileSyncServiceAndroid : public ProfileSyncServiceObserver {
// the internal value of base::Time.
jlong GetLastSyncedTimeForTest(JNIEnv* env, jobject obj);
// Overrides ProfileSyncService's NetworkResources object. This is used to
// set up the Sync FakeServer for testing.
void OverrideNetworkResourcesForTest(JNIEnv* env,
jobject obj,
jlong network_resources);
static ProfileSyncServiceAndroid* GetProfileSyncServiceAndroid();
// Registers the ProfileSyncServiceAndroid's native methods through JNI.
......
......@@ -8,15 +8,12 @@
# and should be separately customized.
{
'variables': {
'apk_name': 'ChromeShell',
'manifest_package_name': 'org.chromium.chrome.shell',
'native_lib_version_name': '<(version_full)',
'package_name': 'chrome_shell_apk',
},
'targets': [
{
'target_name': 'libchromeshell',
'type': 'shared_library',
'target_name': 'libchromeshell_base',
'type': 'static_library',
'dependencies': [
'../base/base.gyp:base',
'chrome_android_core',
......@@ -24,13 +21,8 @@
'../content/content.gyp:content_app_browser',
],
'sources': [
# This file must always be included in the shared_library step to ensure
# JNI_OnLoad is exported.
'app/android/chrome_jni_onload.cc',
'android/shell/chrome_main_delegate_chrome_shell_android.cc',
'android/shell/chrome_main_delegate_chrome_shell_android.h',
"android/shell/chrome_shell_google_location_settings_helper.cc",
"android/shell/chrome_shell_google_location_settings_helper.h",
'android/shell/chrome_shell_google_location_settings_helper.cc',
'android/shell/chrome_shell_google_location_settings_helper.h',
],
'include_dirs': [
'../skia/config',
......@@ -48,14 +40,45 @@
'../base/allocator/allocator.gyp:allocator', ],
}],
['OS=="android"', {
'ldflags': [
# Some android targets still depend on --gc-sections to link.
# TODO: remove --gc-sections for Debug builds (crbug.com/159847).
'-Wl,--gc-sections',
],
'direct_dependent_settings': {
'ldflags': [
# Some android targets still depend on --gc-sections to link.
# TODO: remove --gc-sections for Debug builds (crbug.com/159847).
'-Wl,--gc-sections',
],
},
}],
],
},
{
'target_name': 'libchromeshell',
'type': 'shared_library',
'sources': [
# This file must always be included in the shared_library step to ensure
# JNI_OnLoad is exported.
'app/android/chrome_jni_onload.cc',
'android/shell/chrome_main_delegate_chrome_shell_android.cc',
'android/shell/chrome_main_delegate_chrome_shell_android.h',
],
'dependencies': [
'libchromeshell_base',
],
},
{
'target_name': 'libchromesyncshell',
'type': 'shared_library',
'sources': [
# This file must always be included in the shared_library step to ensure
# JNI_OnLoad is exported.
'app/android/chrome_jni_onload.cc',
'android/sync_shell/chrome_main_delegate_chrome_sync_shell_android.cc',
'android/sync_shell/chrome_main_delegate_chrome_sync_shell_android.h',
],
'dependencies': [
'libchromeshell_base',
'../sync/sync.gyp:test_support_sync_fake_server_android',
],
},
{
'target_name': 'chrome_shell_apk',
'type': 'none',
......@@ -66,6 +89,8 @@
'../media/media.gyp:media_java',
],
'variables': {
'apk_name': 'ChromeShell',
'native_lib_version_name': '<(version_full)',
'java_in_dir': 'android/shell/java',
'resource_dir': 'android/shell/res',
'asset_location': '<(PRODUCT_DIR)/../assets/<(package_name)',
......@@ -106,6 +131,44 @@
}
],
},
{
'target_name': 'chrome_sync_shell_apk',
'type': 'none',
'dependencies': [
'chrome_java',
'chrome_shell_paks',
'libchromesyncshell',
'../media/media.gyp:media_java',
'../sync/sync.gyp:sync_java_test_support',
],
'variables': {
'apk_name': 'ChromeSyncShell',
'android_manifest_path': 'android/sync_shell/java/AndroidManifest.xml',
'R_package': 'org.chromium.chrome.shell',
'native_lib_version_name': '<(version_full)',
'java_in_dir': 'android/shell/java',
'resource_dir': 'android/shell/res',
'asset_location': '<(PRODUCT_DIR)/../assets/<(package_name)',
'native_lib_target': 'libchromesyncshell',
'additional_input_paths': [
'<@(chrome_android_pak_output_resources)',
],
},
'includes': [ '../build/java_apk.gypi', ],
},
{
# chrome_sync_shell_apk creates a .jar as a side effect. Any java
# targets that need that .jar in their classpath should depend on this
# target. Dependents of chrome_sync_shell_apk receive its jar path in the
# variable 'apk_output_jar_path'. This target should only be used by
# targets which instrument chrome_sync_shell_apk.
'target_name': 'chrome_sync_shell_apk_java',
'type': 'none',
'dependencies': [
'chrome_sync_shell_apk',
],
'includes': [ '../build/apk_fake_jar.gypi' ],
},
],
}
......@@ -2830,6 +2830,25 @@
],
'includes': [ '../build/uiautomator_test.gypi' ],
},
{
'target_name': 'chrome_sync_shell_test_apk',
'type': 'none',
'dependencies': [
'chrome_java',
'chrome_sync_shell_apk_java',
'chrome_java_test_support',
'../base/base.gyp:base',
'../base/base.gyp:base_java_test_support',
'../content/content_shell_and_tests.gyp:content_java_test_support',
],
'variables': {
'apk_name': 'ChromeSyncShellTest',
'java_in_dir': 'android/sync_shell/javatests',
'additional_src_dirs': [ 'android/shell/javatests', ],
'is_test_apk': 1,
},
'includes': [ '../build/java_apk.gypi' ],
},
{
'target_name': 'chrome_java_test_support',
'type': 'none',
......
......@@ -448,6 +448,31 @@
],
'includes': [ '../build/java.gypi' ],
},
{
'target_name': 'sync_fake_server_jni_headers',
'type': 'none',
'sources': [
'../chrome/android/sync_shell/javatests/src/chromium/chrome/browser/sync/FakeServerHelper.java',
],
'variables': {
'jni_gen_package': 'sync/test/fake_server',
'jni_generator_ptr_type': 'long',
},
'includes': [ '../build/jni_generator.gypi' ],
},
{
'target_name': 'test_support_sync_fake_server_android',
'type': 'static_library',
'dependencies': [
'sync_fake_server_jni_headers',
'test_support_sync_fake_server',
'../base/base.gyp:base',
],
'sources': [
'test/fake_server/android/fake_server_helper_android.cc',
'test/fake_server/android/fake_server_helper_android.h',
],
},
],
}],
['OS == "android"', {
......
......@@ -2,4 +2,7 @@ include_rules = [
# Test files can include anything from sync.
"+sync",
"+net",
# For generated JNI code.
"+jni",
]
// Copyright 2014 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.
#include "sync/test/fake_server/android/fake_server_helper_android.h"
#include <jni.h>
#include "base/basictypes.h"
#include "jni/FakeServerHelper_jni.h"
#include "sync/internal_api/public/network_resources.h"
#include "sync/test/fake_server/fake_server.h"
#include "sync/test/fake_server/fake_server_network_resources.h"
FakeServerHelperAndroid::FakeServerHelperAndroid(JNIEnv* env, jobject obj) {
}
FakeServerHelperAndroid::~FakeServerHelperAndroid() { }
static jlong Init(JNIEnv* env, jobject obj) {
FakeServerHelperAndroid* fake_server_android =
new FakeServerHelperAndroid(env, obj);
return reinterpret_cast<intptr_t>(fake_server_android);
}
jlong FakeServerHelperAndroid::CreateFakeServer(JNIEnv* env, jobject obj) {
fake_server::FakeServer* fake_server = new fake_server::FakeServer();
return reinterpret_cast<intptr_t>(fake_server);
}
jlong FakeServerHelperAndroid::CreateNetworkResources(JNIEnv* env,
jobject obj,
jlong fake_server) {
fake_server::FakeServer* fake_server_ptr =
reinterpret_cast<fake_server::FakeServer*>(fake_server);
syncer::NetworkResources* resources =
new fake_server::FakeServerNetworkResources(fake_server_ptr);
return reinterpret_cast<intptr_t>(resources);
}
void FakeServerHelperAndroid::DeleteFakeServer(JNIEnv* env,
jobject obj,
jlong fake_server) {
fake_server::FakeServer* fake_server_ptr =
reinterpret_cast<fake_server::FakeServer*>(fake_server);
delete fake_server_ptr;
}
// static
bool FakeServerHelperAndroid::Register(JNIEnv* env) {
return RegisterNativesImpl(env);
}
// Copyright 2014 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.
#ifndef SYNC_TEST_FAKE_SERVER_ANDROID_FAKE_SERVER_HELPER_ANDROID
#define SYNC_TEST_FAKE_SERVER_ANDROID_FAKE_SERVER_HELPER_ANDROID
#include <jni.h>
#include "base/basictypes.h"
// Helper for utilizing native FakeServer infrastructure in Android tests.
class FakeServerHelperAndroid {
public:
// Registers the native methods.
static bool Register(JNIEnv* env);
// Creates a FakeServerHelperAndroid.
FakeServerHelperAndroid(JNIEnv* env, jobject obj);
// Factory method for creating a native FakeServer object. The caller assumes
// ownership.
jlong CreateFakeServer(JNIEnv* env, jobject obj);
// Factory method for creating a native NetworkResources object. The caller
// assumes ownership.
jlong CreateNetworkResources(JNIEnv* env, jobject obj, jlong fake_server);
// Deletes the given |fake_server| (a FakeServer pointer created via
// CreateFakeServer).
void DeleteFakeServer(JNIEnv* env, jobject obj, jlong fake_server);
private:
virtual ~FakeServerHelperAndroid();
};
#endif // SYNC_TEST_FAKE_SERVER_ANDROID_FAKE_SERVER_HELPER_ANDROID
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment