OLD | NEW |
---|---|
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 Loading... | |
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 extends CronetEngine.Builder.Libra ryLoader { | |
965 public void loadLibrary(Context context, String name) { | |
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 extends CronetEngine.Builder.Li braryLoader { | |
987 public void loadLibrary(Context context, String name) { | |
988 // Ignore the given name, always load the test library | |
989 System.loadLibrary("cronet_tests"); | |
990 } | |
991 } | |
992 | |
993 @SmallTest | |
994 @Feature({"Cronet"}) | |
995 public void testOverrideLibraryLoading() throws Exception { | |
996 CronetEngine.Builder builder = new CronetEngine.Builder(getContext()); | |
997 // Don't tell the builder directly that it needs to load the test librar y | |
998 // Instead, let the custom library loader do that | |
999 builder.setLibraryLoader(new TestCustomLibraryLoader()).build(); | |
1000 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.
| |
1001 } | |
1002 | |
1003 private static native void nativeLibraryExists(); | |
963 } | 1004 } |
OLD | NEW |