Commit 62e9dc64 authored by torne's avatar torne Committed by Commit bot

Support setting just the Java Context for JUnit tests.

JUnit/Robolectric tests run on the host without native code and so can't
set the application context the usual way. Provide a test-only method to
set only the Java-side context for this purpose.

Move the assertion about not changing the set context to
initApplicationContext because the JUnit tests will use a different
mock context for each test case.

BUG=552419
R=dgn@chromium.org

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

Cr-Commit-Position: refs/heads/master@{#361350}
parent c63975dd
......@@ -41,14 +41,22 @@ public class ContextUtils {
* both sides.
*/
public static void initApplicationContext(Context appContext) {
assert appContext != null;
assert sApplicationContext == null || sApplicationContext == appContext;
initJavaSideApplicationContext(appContext);
nativeInitNativeSideApplicationContext(appContext);
}
/**
* JUnit Robolectric tests run without native code; allow them to set just the Java-side
* context. Do not use in configurations that actually run on Android!
*/
public static void initApplicationContextForJUnitTests(Context appContext) {
initJavaSideApplicationContext(appContext);
}
@CalledByNative
private static void initJavaSideApplicationContext(Context appContext) {
assert appContext != null;
assert sApplicationContext == null || sApplicationContext == appContext;
sApplicationContext = appContext;
}
......
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