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

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

Issue 2626523003: Cronet: a framework for providing alternative Cronet implementations (Closed)
Patch Set: Javadoc fixes Created 3 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 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 145 matching lines...) Expand 10 before | Expand all | Expand 10 after
156 156
157 @SmallTest 157 @SmallTest
158 @Feature({"Cronet"}) 158 @Feature({"Cronet"})
159 @SuppressWarnings("deprecation") 159 @SuppressWarnings("deprecation")
160 public void testConfigUserAgent() throws Exception { 160 public void testConfigUserAgent() throws Exception {
161 String userAgentName = "User-Agent"; 161 String userAgentName = "User-Agent";
162 String userAgentValue = "User-Agent-Value"; 162 String userAgentValue = "User-Agent-Value";
163 ExperimentalCronetEngine.Builder cronetEngineBuilder = 163 ExperimentalCronetEngine.Builder cronetEngineBuilder =
164 new ExperimentalCronetEngine.Builder(getContext()); 164 new ExperimentalCronetEngine.Builder(getContext());
165 if (testingJavaImpl()) { 165 if (testingJavaImpl()) {
166 cronetEngineBuilder.enableLegacyMode(true); 166 cronetEngineBuilder = createJavaEngineBuilder();
167 } 167 }
168 cronetEngineBuilder.setUserAgent(userAgentValue); 168 cronetEngineBuilder.setUserAgent(userAgentValue);
169 final CronetTestFramework testFramework = 169 final CronetTestFramework testFramework =
170 startCronetTestFrameworkWithUrlAndCronetEngineBuilder(mUrl, cron etEngineBuilder); 170 startCronetTestFrameworkWithUrlAndCronetEngineBuilder(mUrl, cron etEngineBuilder);
171 NativeTestServer.shutdownNativeTestServer(); // startNativeTestServer re turns false if it's 171 NativeTestServer.shutdownNativeTestServer(); // startNativeTestServer re turns false if it's
172 // already running 172 // already running
173 assertTrue(NativeTestServer.startNativeTestServer(getContext())); 173 assertTrue(NativeTestServer.startNativeTestServer(getContext()));
174 TestUrlRequestCallback callback = new TestUrlRequestCallback(); 174 TestUrlRequestCallback callback = new TestUrlRequestCallback();
175 UrlRequest.Builder urlRequestBuilder = testFramework.mCronetEngine.newUr lRequestBuilder( 175 UrlRequest.Builder urlRequestBuilder = testFramework.mCronetEngine.newUr lRequestBuilder(
176 NativeTestServer.getEchoHeaderURL(userAgentName), callback, call back.getExecutor()); 176 NativeTestServer.getEchoHeaderURL(userAgentName), callback, call back.getExecutor());
(...skipping 1184 matching lines...) Expand 10 before | Expand all | Expand 10 after
1361 assertTrue(delta2.length != 0); 1361 assertTrue(delta2.length != 0);
1362 assertFalse(Arrays.equals(delta1, delta2)); 1362 assertFalse(Arrays.equals(delta1, delta2));
1363 } 1363 }
1364 1364
1365 @SmallTest 1365 @SmallTest
1366 @Feature({"Cronet"}) 1366 @Feature({"Cronet"})
1367 public void testCronetEngineBuilderConfig() throws Exception { 1367 public void testCronetEngineBuilderConfig() throws Exception {
1368 // This is to prompt load of native library. 1368 // This is to prompt load of native library.
1369 startCronetTestFramework(); 1369 startCronetTestFramework();
1370 // Verify CronetEngine.Builder config is passed down accurately to nativ e code. 1370 // Verify CronetEngine.Builder config is passed down accurately to nativ e code.
1371 CronetEngineBuilderImpl builder = new CronetEngineBuilderImpl(getContext ()); 1371 ExperimentalCronetEngine.Builder builder =
1372 new ExperimentalCronetEngine.Builder(getContext());
1372 builder.enableHttp2(false); 1373 builder.enableHttp2(false);
1373 builder.enableQuic(true); 1374 builder.enableQuic(true);
1374 builder.enableSdch(true); 1375 builder.enableSdch(true);
1375 builder.addQuicHint("example.com", 12, 34); 1376 builder.addQuicHint("example.com", 12, 34);
1376 builder.setCertVerifierData("test_cert_verifier_data"); 1377 builder.setCertVerifierData("test_cert_verifier_data");
1377 builder.enableHttpCache(HTTP_CACHE_IN_MEMORY, 54321); 1378 builder.enableHttpCache(HTTP_CACHE_IN_MEMORY, 54321);
1378 builder.enableDataReductionProxy("abcd"); 1379 builder.enableDataReductionProxy("abcd");
1379 builder.setUserAgent("efgh"); 1380 builder.setUserAgent("efgh");
1380 builder.setExperimentalOptions("ijkl"); 1381 builder.setExperimentalOptions("ijkl");
1381 builder.setDataReductionProxyOptions("mnop", "qrst", "uvwx"); 1382 builder.setDataReductionProxyOptions("mnop", "qrst", "uvwx");
1382 builder.setStoragePath(CronetTestFramework.getTestStorage(getContext())) ; 1383 builder.setStoragePath(CronetTestFramework.getTestStorage(getContext())) ;
1383 builder.enablePublicKeyPinningBypassForLocalTrustAnchors(false); 1384 builder.enablePublicKeyPinningBypassForLocalTrustAnchors(false);
1384 nativeVerifyUrlRequestContextConfig( 1385 nativeVerifyUrlRequestContextConfig(
1385 CronetUrlRequestContext.createNativeUrlRequestContextConfig(buil der), 1386 CronetUrlRequestContext.createNativeUrlRequestContextConfig(
1387 (CronetEngineBuilderImpl) builder.mBuilderDelegate),
1386 CronetTestFramework.getTestStorage(getContext())); 1388 CronetTestFramework.getTestStorage(getContext()));
1387 } 1389 }
1388 1390
1389 // Verifies that CronetEngine.Builder config from testCronetEngineBuilderCon fig() is properly 1391 // Verifies that CronetEngine.Builder config from testCronetEngineBuilderCon fig() is properly
1390 // translated to a native UrlRequestContextConfig. 1392 // translated to a native UrlRequestContextConfig.
1391 private static native void nativeVerifyUrlRequestContextConfig(long config, String storagePath); 1393 private static native void nativeVerifyUrlRequestContextConfig(long config, String storagePath);
1392 1394
1393 private static class TestBadLibraryLoader extends CronetEngine.Builder.Libra ryLoader { 1395 private static class TestBadLibraryLoader extends CronetEngine.Builder.Libra ryLoader {
1394 private boolean mWasCalled = false; 1396 private boolean mWasCalled = false;
1395 1397
1396 public void loadLibrary(String libName) { 1398 public void loadLibrary(String libName) {
1397 // Report that this method was called, but don't load the library 1399 // Report that this method was called, but don't load the library
1398 mWasCalled = true; 1400 mWasCalled = true;
1399 } 1401 }
1400 1402
1401 boolean wasCalled() { 1403 boolean wasCalled() {
1402 return mWasCalled; 1404 return mWasCalled;
1403 } 1405 }
1404 } 1406 }
1405 1407
1406 @SmallTest 1408 @SmallTest
1407 @Feature({"Cronet"}) 1409 @Feature({"Cronet"})
1408 @OnlyRunNativeCronet 1410 @OnlyRunNativeCronet
1409 public void testSkipLibraryLoading() throws Exception { 1411 public void testSkipLibraryLoading() throws Exception {
1410 CronetEngineBuilderImpl builder = new CronetEngineBuilderImpl(getContext ()); 1412 CronetEngine.Builder builder = new CronetEngine.Builder(getContext());
1411 TestBadLibraryLoader loader = new TestBadLibraryLoader(); 1413 TestBadLibraryLoader loader = new TestBadLibraryLoader();
1412 builder.setLibraryLoader(loader); 1414 builder.setLibraryLoader(loader);
1413 try { 1415 try {
1414 // ensureInitialized() calls native code to check the version right after library load 1416 // ensureInitialized() calls native code to check the version right after library load
1415 // and will error with the message below if library loading was skip ped 1417 // and will error with the message below if library loading was skip ped
1416 CronetLibraryLoader.ensureInitialized(getContext().getApplicationCon text(), builder); 1418 CronetLibraryLoader.ensureInitialized(getContext().getApplicationCon text(),
1419 (CronetEngineBuilderImpl) builder.mBuilderDelegate);
1417 fail("Native library should not be loaded"); 1420 fail("Native library should not be loaded");
1418 } catch (UnsatisfiedLinkError e) { 1421 } catch (UnsatisfiedLinkError e) {
1419 assertTrue(loader.wasCalled()); 1422 assertTrue(loader.wasCalled());
1420 } 1423 }
1421 } 1424 }
1422 1425
1423 // Creates a CronetEngine on another thread and then one on the main thread. This shouldn't 1426 // Creates a CronetEngine on another thread and then one on the main thread. This shouldn't
1424 // crash. 1427 // crash.
1425 @SmallTest 1428 @SmallTest
1426 @Feature({"Cronet"}) 1429 @Feature({"Cronet"})
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
1464 TestUrlRequestCallback callback = new TestUrlRequestCallback(); 1467 TestUrlRequestCallback callback = new TestUrlRequestCallback();
1465 URL requestUrl = 1468 URL requestUrl =
1466 new URL("http", resolverTestHostname, testUrl.getPort(), testUrl .getFile()); 1469 new URL("http", resolverTestHostname, testUrl.getPort(), testUrl .getFile());
1467 UrlRequest.Builder urlRequestBuilder = testFramework.mCronetEngine.newUr lRequestBuilder( 1470 UrlRequest.Builder urlRequestBuilder = testFramework.mCronetEngine.newUr lRequestBuilder(
1468 requestUrl.toString(), callback, callback.getExecutor()); 1471 requestUrl.toString(), callback, callback.getExecutor());
1469 urlRequestBuilder.build().start(); 1472 urlRequestBuilder.build().start();
1470 callback.blockForDone(); 1473 callback.blockForDone();
1471 assertEquals(200, callback.mResponseInfo.getHttpStatusCode()); 1474 assertEquals(200, callback.mResponseInfo.getHttpStatusCode());
1472 } 1475 }
1473 } 1476 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698