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..2d8d1ce726e9852f5461578e04a6e9e1ee3436de 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,46 @@ 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 implements CronetEngine.Builder.CustomLibraryLoader { |
+ public void loadLibrary(String libName) { |
+ // 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 |
+ implements CronetEngine.Builder.CustomLibraryLoader { |
+ public void loadLibrary(String libName) { |
+ // 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(); |
+ } |
+ |
+ private static native void nativeLibraryExists(); |
} |