Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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.support.test.filters.SmallTest; | 7 import android.support.test.filters.SmallTest; |
| 8 | 8 |
| 9 import org.json.JSONObject; | 9 import org.json.JSONObject; |
| 10 | 10 |
| (...skipping 16 matching lines...) Expand all Loading... | |
| 27 private static final String CERT_USED = "quic_test.example.com.crt"; | 27 private static final String CERT_USED = "quic_test.example.com.crt"; |
| 28 private static final String[] CERTS_USED = {CERT_USED}; | 28 private static final String[] CERTS_USED = {CERT_USED}; |
| 29 private static final int DISTANT_FUTURE = Integer.MAX_VALUE; | 29 private static final int DISTANT_FUTURE = Integer.MAX_VALUE; |
| 30 private static final boolean INCLUDE_SUBDOMAINS = true; | 30 private static final boolean INCLUDE_SUBDOMAINS = true; |
| 31 private static final boolean EXCLUDE_SUBDOMAINS = false; | 31 private static final boolean EXCLUDE_SUBDOMAINS = false; |
| 32 private static final boolean KNOWN_ROOT = true; | 32 private static final boolean KNOWN_ROOT = true; |
| 33 private static final boolean UNKNOWN_ROOT = false; | 33 private static final boolean UNKNOWN_ROOT = false; |
| 34 private static final boolean ENABLE_PINNING_BYPASS_FOR_LOCAL_ANCHORS = true; | 34 private static final boolean ENABLE_PINNING_BYPASS_FOR_LOCAL_ANCHORS = true; |
| 35 private static final boolean DISABLE_PINNING_BYPASS_FOR_LOCAL_ANCHORS = fals e; | 35 private static final boolean DISABLE_PINNING_BYPASS_FOR_LOCAL_ANCHORS = fals e; |
| 36 | 36 |
| 37 private CronetTestFramework mTestFramework; | 37 private CronetEngine mCronetEngine; |
| 38 private ExperimentalCronetEngine.Builder mBuilder; | 38 private ExperimentalCronetEngine.Builder mBuilder; |
| 39 private TestUrlRequestCallback mListener; | 39 private TestUrlRequestCallback mListener; |
| 40 private String mServerUrl; // https://test.example.com:6121 | 40 private String mServerUrl; // https://test.example.com:6121 |
| 41 private String mServerHost; // test.example.com | 41 private String mServerHost; // test.example.com |
| 42 private String mDomain; // example.com | 42 private String mDomain; // example.com |
| 43 | 43 |
| 44 @Override | 44 @Override |
| 45 protected void setUp() throws Exception { | 45 protected void setUp() throws Exception { |
| 46 super.setUp(); | 46 super.setUp(); |
| 47 // Start QUIC Test Server | 47 // Start QUIC Test Server |
| (...skipping 348 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 396 JSONObject hostResolverParams = CronetTestUtil.generateHostResolverRules (); | 396 JSONObject hostResolverParams = CronetTestUtil.generateHostResolverRules (); |
| 397 JSONObject experimentalOptions = new JSONObject() | 397 JSONObject experimentalOptions = new JSONObject() |
| 398 .put("HostResolverRules", hostR esolverParams); | 398 .put("HostResolverRules", hostR esolverParams); |
| 399 mBuilder.setExperimentalOptions(experimentalOptions.toString()); | 399 mBuilder.setExperimentalOptions(experimentalOptions.toString()); |
| 400 mBuilder.setStoragePath(CronetTestFramework.getTestStorage(getContext()) ); | 400 mBuilder.setStoragePath(CronetTestFramework.getTestStorage(getContext()) ); |
| 401 mBuilder.enableHttpCache(CronetEngine.Builder.HTTP_CACHE_DISK_NO_HTTP, 1 000 * 1024); | 401 mBuilder.enableHttpCache(CronetEngine.Builder.HTTP_CACHE_DISK_NO_HTTP, 1 000 * 1024); |
| 402 CronetTestUtil.setMockCertVerifierForTesting( | 402 CronetTestUtil.setMockCertVerifierForTesting( |
| 403 mBuilder, MockCertVerifier.createMockCertVerifier(CERTS_USED, kn ownRoot)); | 403 mBuilder, MockCertVerifier.createMockCertVerifier(CERTS_USED, kn ownRoot)); |
| 404 } | 404 } |
| 405 | 405 |
| 406 private void startCronetFramework() { | 406 private void startCronetFramework() { |
|
mgersh
2017/05/23 18:12:13
It's not using a Framework anymore, so this could
pauljensen
2017/05/25 15:15:15
Done.
| |
| 407 mTestFramework = startCronetTestFrameworkWithUrlAndCronetEngineBuilder(n ull, mBuilder); | 407 mCronetEngine = mBuilder.build(); |
| 408 } | 408 } |
| 409 | 409 |
| 410 private void shutdownCronetEngine() { | 410 private void shutdownCronetEngine() { |
| 411 if (mTestFramework != null && mTestFramework.mCronetEngine != null) { | 411 if (mCronetEngine != null) { |
| 412 mTestFramework.mCronetEngine.shutdown(); | 412 mCronetEngine.shutdown(); |
| 413 } | 413 } |
| 414 } | 414 } |
| 415 | 415 |
| 416 private byte[] generateSomeSha256() { | 416 private byte[] generateSomeSha256() { |
| 417 byte[] sha256 = new byte[32]; | 417 byte[] sha256 = new byte[32]; |
| 418 Arrays.fill(sha256, (byte) 58); | 418 Arrays.fill(sha256, (byte) 58); |
| 419 return sha256; | 419 return sha256; |
| 420 } | 420 } |
| 421 | 421 |
| 422 private void addPkpSha256( | 422 private void addPkpSha256( |
| 423 String host, byte[] pinHashValue, boolean includeSubdomain, int maxA geInSec) { | 423 String host, byte[] pinHashValue, boolean includeSubdomain, int maxA geInSec) { |
| 424 Set<byte[]> hashes = new HashSet<>(); | 424 Set<byte[]> hashes = new HashSet<>(); |
| 425 hashes.add(pinHashValue); | 425 hashes.add(pinHashValue); |
| 426 mBuilder.addPublicKeyPins(host, hashes, includeSubdomain, dateInFuture(m axAgeInSec)); | 426 mBuilder.addPublicKeyPins(host, hashes, includeSubdomain, dateInFuture(m axAgeInSec)); |
| 427 } | 427 } |
| 428 | 428 |
| 429 private void sendRequestAndWaitForResult() { | 429 private void sendRequestAndWaitForResult() { |
| 430 mListener = new TestUrlRequestCallback(); | 430 mListener = new TestUrlRequestCallback(); |
| 431 | 431 |
| 432 String quicURL = mServerUrl + "/simple.txt"; | 432 String quicURL = mServerUrl + "/simple.txt"; |
| 433 UrlRequest.Builder requestBuilder = mTestFramework.mCronetEngine.newUrlR equestBuilder( | 433 UrlRequest.Builder requestBuilder = |
| 434 quicURL, mListener, mListener.getExecutor()); | 434 mCronetEngine.newUrlRequestBuilder(quicURL, mListener, mListener .getExecutor()); |
| 435 requestBuilder.build().start(); | 435 requestBuilder.build().start(); |
| 436 mListener.blockForDone(); | 436 mListener.blockForDone(); |
| 437 } | 437 } |
| 438 | 438 |
| 439 private X509Certificate readCertFromFileInPemFormat(String certFileName) thr ows Exception { | 439 private X509Certificate readCertFromFileInPemFormat(String certFileName) thr ows Exception { |
| 440 byte[] certDer = CertTestUtil.pemToDer(CertTestUtil.CERTS_DIRECTORY + ce rtFileName); | 440 byte[] certDer = CertTestUtil.pemToDer(CertTestUtil.CERTS_DIRECTORY + ce rtFileName); |
| 441 CertificateFactory certFactory = CertificateFactory.getInstance("X.509") ; | 441 CertificateFactory certFactory = CertificateFactory.getInstance("X.509") ; |
| 442 return (X509Certificate) certFactory.generateCertificate(new ByteArrayIn putStream(certDer)); | 442 return (X509Certificate) certFactory.generateCertificate(new ByteArrayIn putStream(certDer)); |
| 443 } | 443 } |
| 444 | 444 |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 480 if (!shouldThrowNpe) { | 480 if (!shouldThrowNpe) { |
| 481 fail("Null pointer exception was not expected: " + ex.toString() ); | 481 fail("Null pointer exception was not expected: " + ex.toString() ); |
| 482 } | 482 } |
| 483 return; | 483 return; |
| 484 } | 484 } |
| 485 if (shouldThrowNpe) { | 485 if (shouldThrowNpe) { |
| 486 fail("NullPointerException was expected"); | 486 fail("NullPointerException was expected"); |
| 487 } | 487 } |
| 488 } | 488 } |
| 489 } | 489 } |
| OLD | NEW |