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

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

Issue 2660963002: Cronet: a framework to provide alternative Cronet implementations (Closed)
Patch Set: Created 3 years, 10 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 android.content.Context; 7 import android.content.Context;
8 import android.content.ContextWrapper; 8 import android.content.ContextWrapper;
9 import android.os.ConditionVariable; 9 import android.os.ConditionVariable;
10 import android.os.Handler; 10 import android.os.Handler;
(...skipping 152 matching lines...) Expand 10 before | Expand all | Expand 10 after
163 163
164 @SmallTest 164 @SmallTest
165 @Feature({"Cronet"}) 165 @Feature({"Cronet"})
166 @SuppressWarnings("deprecation") 166 @SuppressWarnings("deprecation")
167 public void testConfigUserAgent() throws Exception { 167 public void testConfigUserAgent() throws Exception {
168 String userAgentName = "User-Agent"; 168 String userAgentName = "User-Agent";
169 String userAgentValue = "User-Agent-Value"; 169 String userAgentValue = "User-Agent-Value";
170 ExperimentalCronetEngine.Builder cronetEngineBuilder = 170 ExperimentalCronetEngine.Builder cronetEngineBuilder =
171 new ExperimentalCronetEngine.Builder(getContext()); 171 new ExperimentalCronetEngine.Builder(getContext());
172 if (testingJavaImpl()) { 172 if (testingJavaImpl()) {
173 cronetEngineBuilder.enableLegacyMode(true); 173 cronetEngineBuilder = createJavaEngineBuilder();
174 } 174 }
175 cronetEngineBuilder.setUserAgent(userAgentValue); 175 cronetEngineBuilder.setUserAgent(userAgentValue);
176 final CronetTestFramework testFramework = 176 final CronetTestFramework testFramework =
177 startCronetTestFrameworkWithUrlAndCronetEngineBuilder(mUrl, cron etEngineBuilder); 177 startCronetTestFrameworkWithUrlAndCronetEngineBuilder(mUrl, cron etEngineBuilder);
178 NativeTestServer.shutdownNativeTestServer(); // startNativeTestServer re turns false if it's 178 NativeTestServer.shutdownNativeTestServer(); // startNativeTestServer re turns false if it's
179 // already running 179 // already running
180 assertTrue(NativeTestServer.startNativeTestServer(getContext())); 180 assertTrue(NativeTestServer.startNativeTestServer(getContext()));
181 TestUrlRequestCallback callback = new TestUrlRequestCallback(); 181 TestUrlRequestCallback callback = new TestUrlRequestCallback();
182 UrlRequest.Builder urlRequestBuilder = testFramework.mCronetEngine.newUr lRequestBuilder( 182 UrlRequest.Builder urlRequestBuilder = testFramework.mCronetEngine.newUr lRequestBuilder(
183 NativeTestServer.getEchoHeaderURL(userAgentName), callback, call back.getExecutor()); 183 NativeTestServer.getEchoHeaderURL(userAgentName), callback, call back.getExecutor());
(...skipping 1202 matching lines...) Expand 10 before | Expand all | Expand 10 after
1386 assertTrue(delta2.length != 0); 1386 assertTrue(delta2.length != 0);
1387 assertFalse(Arrays.equals(delta1, delta2)); 1387 assertFalse(Arrays.equals(delta1, delta2));
1388 } 1388 }
1389 1389
1390 @SmallTest 1390 @SmallTest
1391 @Feature({"Cronet"}) 1391 @Feature({"Cronet"})
1392 public void testCronetEngineBuilderConfig() throws Exception { 1392 public void testCronetEngineBuilderConfig() throws Exception {
1393 // This is to prompt load of native library. 1393 // This is to prompt load of native library.
1394 startCronetTestFramework(); 1394 startCronetTestFramework();
1395 // Verify CronetEngine.Builder config is passed down accurately to nativ e code. 1395 // Verify CronetEngine.Builder config is passed down accurately to nativ e code.
1396 CronetEngineBuilderImpl builder = new CronetEngineBuilderImpl(getContext ()); 1396 ExperimentalCronetEngine.Builder builder =
1397 new ExperimentalCronetEngine.Builder(getContext());
1397 builder.enableHttp2(false); 1398 builder.enableHttp2(false);
1398 builder.enableQuic(true); 1399 builder.enableQuic(true);
1399 builder.enableSdch(true); 1400 builder.enableSdch(true);
1400 builder.addQuicHint("example.com", 12, 34); 1401 builder.addQuicHint("example.com", 12, 34);
1401 builder.setCertVerifierData("test_cert_verifier_data"); 1402 builder.setCertVerifierData("test_cert_verifier_data");
1402 builder.enableHttpCache(HTTP_CACHE_IN_MEMORY, 54321); 1403 builder.enableHttpCache(HTTP_CACHE_IN_MEMORY, 54321);
1403 builder.enableDataReductionProxy("abcd"); 1404 builder.enableDataReductionProxy("abcd");
1404 builder.setUserAgent("efgh"); 1405 builder.setUserAgent("efgh");
1405 builder.setExperimentalOptions("ijkl"); 1406 builder.setExperimentalOptions("ijkl");
1406 builder.setDataReductionProxyOptions("mnop", "qrst", "uvwx"); 1407 builder.setDataReductionProxyOptions("mnop", "qrst", "uvwx");
1407 builder.setStoragePath(CronetTestFramework.getTestStorage(getContext())) ; 1408 builder.setStoragePath(CronetTestFramework.getTestStorage(getContext())) ;
1408 builder.enablePublicKeyPinningBypassForLocalTrustAnchors(false); 1409 builder.enablePublicKeyPinningBypassForLocalTrustAnchors(false);
1409 nativeVerifyUrlRequestContextConfig( 1410 nativeVerifyUrlRequestContextConfig(
1410 CronetUrlRequestContext.createNativeUrlRequestContextConfig(buil der), 1411 CronetUrlRequestContext.createNativeUrlRequestContextConfig(
1412 (CronetEngineBuilderImpl) builder.mBuilderDelegate),
1411 CronetTestFramework.getTestStorage(getContext())); 1413 CronetTestFramework.getTestStorage(getContext()));
1412 } 1414 }
1413 1415
1414 // Verifies that CronetEngine.Builder config from testCronetEngineBuilderCon fig() is properly 1416 // Verifies that CronetEngine.Builder config from testCronetEngineBuilderCon fig() is properly
1415 // translated to a native UrlRequestContextConfig. 1417 // translated to a native UrlRequestContextConfig.
1416 private static native void nativeVerifyUrlRequestContextConfig(long config, String storagePath); 1418 private static native void nativeVerifyUrlRequestContextConfig(long config, String storagePath);
1417 1419
1418 private static class TestBadLibraryLoader extends CronetEngine.Builder.Libra ryLoader { 1420 private static class TestBadLibraryLoader extends CronetEngine.Builder.Libra ryLoader {
1419 private boolean mWasCalled = false; 1421 private boolean mWasCalled = false;
1420 1422
1421 public void loadLibrary(String libName) { 1423 public void loadLibrary(String libName) {
1422 // Report that this method was called, but don't load the library 1424 // Report that this method was called, but don't load the library
1423 mWasCalled = true; 1425 mWasCalled = true;
1424 } 1426 }
1425 1427
1426 boolean wasCalled() { 1428 boolean wasCalled() {
1427 return mWasCalled; 1429 return mWasCalled;
1428 } 1430 }
1429 } 1431 }
1430 1432
1431 @SmallTest 1433 @SmallTest
1432 @Feature({"Cronet"}) 1434 @Feature({"Cronet"})
1433 @OnlyRunNativeCronet 1435 @OnlyRunNativeCronet
1434 public void testSkipLibraryLoading() throws Exception { 1436 public void testSkipLibraryLoading() throws Exception {
1435 CronetEngineBuilderImpl builder = new CronetEngineBuilderImpl(getContext ()); 1437 CronetEngine.Builder builder = new CronetEngine.Builder(getContext());
1436 TestBadLibraryLoader loader = new TestBadLibraryLoader(); 1438 TestBadLibraryLoader loader = new TestBadLibraryLoader();
1437 builder.setLibraryLoader(loader); 1439 builder.setLibraryLoader(loader);
1438 try { 1440 try {
1439 // ensureInitialized() calls native code to check the version right after library load 1441 // ensureInitialized() calls native code to check the version right after library load
1440 // and will error with the message below if library loading was skip ped 1442 // and will error with the message below if library loading was skip ped
1441 CronetLibraryLoader.ensureInitialized(getContext().getApplicationCon text(), builder); 1443 CronetLibraryLoader.ensureInitialized(getContext().getApplicationCon text(),
1444 (CronetEngineBuilderImpl) builder.mBuilderDelegate);
1442 fail("Native library should not be loaded"); 1445 fail("Native library should not be loaded");
1443 } catch (UnsatisfiedLinkError e) { 1446 } catch (UnsatisfiedLinkError e) {
1444 assertTrue(loader.wasCalled()); 1447 assertTrue(loader.wasCalled());
1445 } 1448 }
1446 } 1449 }
1447 1450
1448 // Creates a CronetEngine on another thread and then one on the main thread. This shouldn't 1451 // Creates a CronetEngine on another thread and then one on the main thread. This shouldn't
1449 // crash. 1452 // crash.
1450 @SmallTest 1453 @SmallTest
1451 @Feature({"Cronet"}) 1454 @Feature({"Cronet"})
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
1489 TestUrlRequestCallback callback = new TestUrlRequestCallback(); 1492 TestUrlRequestCallback callback = new TestUrlRequestCallback();
1490 URL requestUrl = 1493 URL requestUrl =
1491 new URL("http", resolverTestHostname, testUrl.getPort(), testUrl .getFile()); 1494 new URL("http", resolverTestHostname, testUrl.getPort(), testUrl .getFile());
1492 UrlRequest.Builder urlRequestBuilder = testFramework.mCronetEngine.newUr lRequestBuilder( 1495 UrlRequest.Builder urlRequestBuilder = testFramework.mCronetEngine.newUr lRequestBuilder(
1493 requestUrl.toString(), callback, callback.getExecutor()); 1496 requestUrl.toString(), callback, callback.getExecutor());
1494 urlRequestBuilder.build().start(); 1497 urlRequestBuilder.build().start();
1495 callback.blockForDone(); 1498 callback.blockForDone();
1496 assertEquals(200, callback.mResponseInfo.getHttpStatusCode()); 1499 assertEquals(200, callback.mResponseInfo.getHttpStatusCode());
1497 } 1500 }
1498 } 1501 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698