Index: components/cronet/android/test/javatests/src/org/chromium/net/CronetUrlRequestContextTest.java |
diff --git a/components/cronet/android/test/javatests/src/org/chromium/net/CronetUrlRequestContextTest.java b/components/cronet/android/test/javatests/src/org/chromium/net/CronetUrlRequestContextTest.java |
index ce07d6bdca5eb22145ced74721f3991f8d7bd926..d533de4fe1282025fe377274729bf3dfab78dd65 100644 |
--- a/components/cronet/android/test/javatests/src/org/chromium/net/CronetUrlRequestContextTest.java |
+++ b/components/cronet/android/test/javatests/src/org/chromium/net/CronetUrlRequestContextTest.java |
@@ -960,4 +960,45 @@ public class CronetUrlRequestContextTest extends CronetTestBase { |
// Verifies that CronetEngine.Builder config from testCronetEngineBuilderConfig() is properly |
// translated to a native UrlRequestContextConfig. |
private static native void nativeVerifyUrlRequestContextConfig(long config, String storagePath); |
+ |
+ private static class TestBadLibraryLoader extends CronetEngine.Builder.LibraryLoader { |
+ public void loadLibrary(Context context, String name) { |
+ // Don't do anything |
+ } |
+ } |
+ |
+ @SmallTest |
+ @Feature({"Cronet"}) |
+ public void testSkipLibraryLoading() throws Exception { |
+ CronetEngine.Builder builder = new CronetEngine.Builder(getContext()); |
+ builder.setLibraryLoader(new TestBadLibraryLoader()).setLibraryName("cronet_tests"); |
+ try { |
+ // ensureInitialized() calls native code to check the version right after library load |
+ // and will error with the message below if library loading was skipped |
+ CronetLibraryLoader.ensureInitialized(getContext(), builder); |
+ fail("Native library should not be loaded"); |
+ } catch (UnsatisfiedLinkError e) { |
+ assertTrue(e.getMessage().contains( |
+ "No implementation found for java.lang.String org.chromium.net")); |
+ } |
+ } |
+ |
+ private static class TestCustomLibraryLoader extends CronetEngine.Builder.LibraryLoader { |
+ public void loadLibrary(Context context, String name) { |
+ // Ignore the given name, always load the test library |
+ System.loadLibrary("cronet_tests"); |
+ } |
+ } |
+ |
+ @SmallTest |
+ @Feature({"Cronet"}) |
+ public void testOverrideLibraryLoading() throws Exception { |
+ CronetEngine.Builder builder = new CronetEngine.Builder(getContext()); |
+ // Don't tell the builder directly that it needs to load the test library |
+ // Instead, let the custom library loader do that |
+ builder.setLibraryLoader(new TestCustomLibraryLoader()).build(); |
+ nativeLibraryExists(); |
xunjieli
2016/01/21 19:50:53
How does this work? The Builder.loadLibrary has no
mgersh
2016/01/22 17:41:16
It gets invoked during the call to build(), throug
xunjieli
2016/01/22 22:53:15
Ah, yes, you are right. There are plenty of tests
mgersh
2016/01/25 17:31:11
Done.
|
+ } |
+ |
+ private static native void nativeLibraryExists(); |
} |