| 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.test.suitebuilder.annotation.LargeTest; | 7 import android.test.suitebuilder.annotation.LargeTest; |
| 8 import android.test.suitebuilder.annotation.SmallTest; | 8 import android.test.suitebuilder.annotation.SmallTest; |
| 9 | 9 |
| 10 import org.chromium.base.Log; | 10 import org.chromium.base.Log; |
| 11 import org.chromium.base.annotations.SuppressFBWarnings; | 11 import org.chromium.base.annotations.SuppressFBWarnings; |
| 12 import org.chromium.base.test.util.Feature; | 12 import org.chromium.base.test.util.Feature; |
| 13 import org.chromium.net.CronetTestBase.OnlyRunNativeCronet; |
| 13 import org.json.JSONObject; | 14 import org.json.JSONObject; |
| 14 | 15 |
| 15 import java.io.File; | 16 import java.io.File; |
| 16 import java.io.FileInputStream; | 17 import java.io.FileInputStream; |
| 17 import java.io.FileNotFoundException; | 18 import java.io.FileNotFoundException; |
| 18 import java.io.IOException; | 19 import java.io.IOException; |
| 19 import java.util.HashMap; | 20 import java.util.HashMap; |
| 20 | 21 |
| 21 /** | 22 /** |
| 22 * Tests making requests using QUIC. | 23 * Tests making requests using QUIC. |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 56 | 57 |
| 57 @Override | 58 @Override |
| 58 protected void tearDown() throws Exception { | 59 protected void tearDown() throws Exception { |
| 59 QuicTestServer.shutdownQuicTestServer(); | 60 QuicTestServer.shutdownQuicTestServer(); |
| 60 super.tearDown(); | 61 super.tearDown(); |
| 61 } | 62 } |
| 62 | 63 |
| 63 @SmallTest | 64 @SmallTest |
| 64 @Feature({"Cronet"}) | 65 @Feature({"Cronet"}) |
| 65 @SuppressWarnings("deprecation") | 66 @SuppressWarnings("deprecation") |
| 67 @OnlyRunNativeCronet |
| 66 public void testQuicLoadUrl_LegacyAPI() throws Exception { | 68 public void testQuicLoadUrl_LegacyAPI() throws Exception { |
| 67 String[] commandLineArgs = { | 69 String[] commandLineArgs = { |
| 68 CronetTestFramework.LIBRARY_INIT_KEY, CronetTestFramework.Librar
yInitType.LEGACY}; | 70 CronetTestFramework.LIBRARY_INIT_KEY, CronetTestFramework.Librar
yInitType.LEGACY}; |
| 69 mTestFramework = new CronetTestFramework(null, commandLineArgs, getConte
xt(), mBuilder); | 71 mTestFramework = new CronetTestFramework(null, commandLineArgs, getConte
xt(), mBuilder); |
| 70 registerHostResolver(mTestFramework, true); | 72 registerHostResolver(mTestFramework, true); |
| 71 String quicURL = QuicTestServer.getServerURL() + "/simple.txt"; | 73 String quicURL = QuicTestServer.getServerURL() + "/simple.txt"; |
| 72 | 74 |
| 73 HashMap<String, String> headers = new HashMap<String, String>(); | 75 HashMap<String, String> headers = new HashMap<String, String>(); |
| 74 TestHttpUrlRequestListener listener = new TestHttpUrlRequestListener(); | 76 TestHttpUrlRequestListener listener = new TestHttpUrlRequestListener(); |
| 75 | 77 |
| 76 // Although the native stack races QUIC and SPDY for the first request, | 78 // Although the native stack races QUIC and SPDY for the first request, |
| 77 // since there is no http server running on the corresponding TCP port, | 79 // since there is no http server running on the corresponding TCP port, |
| 78 // QUIC will always succeed with a 200 (see | 80 // QUIC will always succeed with a 200 (see |
| 79 // net::HttpStreamFactoryImpl::Request::OnStreamFailed). | 81 // net::HttpStreamFactoryImpl::Request::OnStreamFailed). |
| 80 HttpUrlRequest request = mTestFramework.mRequestFactory.createRequest( | 82 HttpUrlRequest request = mTestFramework.mRequestFactory.createRequest( |
| 81 quicURL, HttpUrlRequest.REQUEST_PRIORITY_MEDIUM, headers, listen
er); | 83 quicURL, HttpUrlRequest.REQUEST_PRIORITY_MEDIUM, headers, listen
er); |
| 82 request.start(); | 84 request.start(); |
| 83 listener.blockForComplete(); | 85 listener.blockForComplete(); |
| 84 assertEquals(200, listener.mHttpStatusCode); | 86 assertEquals(200, listener.mHttpStatusCode); |
| 85 assertEquals( | 87 assertEquals( |
| 86 "This is a simple text file served by QUIC.\n", | 88 "This is a simple text file served by QUIC.\n", |
| 87 listener.mResponseAsString); | 89 listener.mResponseAsString); |
| 88 assertEquals("quic/1+spdy/3", listener.mNegotiatedProtocol); | 90 assertEquals("quic/1+spdy/3", listener.mNegotiatedProtocol); |
| 89 } | 91 } |
| 90 | 92 |
| 91 @LargeTest | 93 @LargeTest |
| 92 @Feature({"Cronet"}) | 94 @Feature({"Cronet"}) |
| 95 @OnlyRunNativeCronet |
| 93 public void testQuicLoadUrl() throws Exception { | 96 public void testQuicLoadUrl() throws Exception { |
| 94 mTestFramework = startCronetTestFrameworkWithUrlAndCronetEngineBuilder(n
ull, mBuilder); | 97 mTestFramework = startCronetTestFrameworkWithUrlAndCronetEngineBuilder(n
ull, mBuilder); |
| 95 registerHostResolver(mTestFramework); | 98 registerHostResolver(mTestFramework); |
| 96 String quicURL = QuicTestServer.getServerURL() + "/simple.txt"; | 99 String quicURL = QuicTestServer.getServerURL() + "/simple.txt"; |
| 97 TestUrlRequestCallback callback = new TestUrlRequestCallback(); | 100 TestUrlRequestCallback callback = new TestUrlRequestCallback(); |
| 98 | 101 |
| 99 // Although the native stack races QUIC and SPDY for the first request, | 102 // Although the native stack races QUIC and SPDY for the first request, |
| 100 // since there is no http server running on the corresponding TCP port, | 103 // since there is no http server running on the corresponding TCP port, |
| 101 // QUIC will always succeed with a 200 (see | 104 // QUIC will always succeed with a 200 (see |
| 102 // net::HttpStreamFactoryImpl::Request::OnStreamFailed). | 105 // net::HttpStreamFactoryImpl::Request::OnStreamFailed). |
| (...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 155 @SuppressFBWarnings("OBL_UNSATISFIED_OBLIGATION_EXCEPTION_EDGE") | 158 @SuppressFBWarnings("OBL_UNSATISFIED_OBLIGATION_EXCEPTION_EDGE") |
| 156 private boolean fileContainsString(String filename, String content) throws I
OException { | 159 private boolean fileContainsString(String filename, String content) throws I
OException { |
| 157 File file = new File(CronetTestFramework.getTestStorage(getContext()) +
"/" + filename); | 160 File file = new File(CronetTestFramework.getTestStorage(getContext()) +
"/" + filename); |
| 158 FileInputStream fileInputStream = new FileInputStream(file); | 161 FileInputStream fileInputStream = new FileInputStream(file); |
| 159 byte[] data = new byte[(int) file.length()]; | 162 byte[] data = new byte[(int) file.length()]; |
| 160 fileInputStream.read(data); | 163 fileInputStream.read(data); |
| 161 fileInputStream.close(); | 164 fileInputStream.close(); |
| 162 return new String(data, "UTF-8").contains(content); | 165 return new String(data, "UTF-8").contains(content); |
| 163 } | 166 } |
| 164 } | 167 } |
| OLD | NEW |