Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(196)

Side by Side Diff: components/cronet/android/test/javatests/src/org/chromium/net/CronetUrlRequestContextTest.java

Issue 1619673004: Add API for custom library loading (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 package org.chromium.net; 5 package org.chromium.net;
6 6
7 import static org.chromium.base.CollectionUtil.newHashSet; 7 import static org.chromium.base.CollectionUtil.newHashSet;
8 8
9 import android.content.Context; 9 import android.content.Context;
10 import android.content.ContextWrapper; 10 import android.content.ContextWrapper;
(...skipping 942 matching lines...) Expand 10 before | Expand all | Expand 10 after
953 builder.setDataReductionProxyOptions("mnop", "qrst", "uvwx"); 953 builder.setDataReductionProxyOptions("mnop", "qrst", "uvwx");
954 builder.setStoragePath(CronetTestFramework.getTestStorage(getContext())) ; 954 builder.setStoragePath(CronetTestFramework.getTestStorage(getContext())) ;
955 nativeVerifyUrlRequestContextConfig( 955 nativeVerifyUrlRequestContextConfig(
956 CronetUrlRequestContext.createNativeUrlRequestContextConfig(buil der), 956 CronetUrlRequestContext.createNativeUrlRequestContextConfig(buil der),
957 CronetTestFramework.getTestStorage(getContext())); 957 CronetTestFramework.getTestStorage(getContext()));
958 } 958 }
959 959
960 // Verifies that CronetEngine.Builder config from testCronetEngineBuilderCon fig() is properly 960 // Verifies that CronetEngine.Builder config from testCronetEngineBuilderCon fig() is properly
961 // translated to a native UrlRequestContextConfig. 961 // translated to a native UrlRequestContextConfig.
962 private static native void nativeVerifyUrlRequestContextConfig(long config, String storagePath); 962 private static native void nativeVerifyUrlRequestContextConfig(long config, String storagePath);
963
964 private static class TestBadLibraryLoader implements CronetEngine.Builder.Cu stomLibraryLoader {
965 public void loadLibrary(String libName) {
966 // Don't do anything
967 }
968 }
969
970 @SmallTest
971 @Feature({"Cronet"})
972 public void testSkipLibraryLoading() throws Exception {
973 CronetEngine.Builder builder = new CronetEngine.Builder(getContext());
974 builder.setLibraryLoader(new TestBadLibraryLoader()).setLibraryName("cro net_tests");
975 try {
976 // ensureInitialized() calls native code to check the version right after library load
977 // and will error with the message below if library loading was skip ped
978 CronetLibraryLoader.ensureInitialized(getContext(), builder);
979 fail("Native library should not be loaded");
980 } catch (UnsatisfiedLinkError e) {
981 assertTrue(e.getMessage().contains(
982 "No implementation found for java.lang.String org.chromium.n et"));
983 }
984 }
985
986 private static class TestCustomLibraryLoader
987 implements CronetEngine.Builder.CustomLibraryLoader {
988 public void loadLibrary(String libName) {
989 // Ignore the given name, always load the test library
990 System.loadLibrary("cronet_tests");
991 }
992 }
993
994 @SmallTest
995 @Feature({"Cronet"})
996 public void testOverrideLibraryLoading() throws Exception {
997 CronetEngine.Builder builder = new CronetEngine.Builder(getContext());
998 // Don't tell the builder directly that it needs to load the test librar y
999 // Instead, let the custom library loader do that
1000 builder.setLibraryLoader(new TestCustomLibraryLoader()).build();
1001 nativeLibraryExists();
1002 }
1003
1004 private static native void nativeLibraryExists();
963 } 1005 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698