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

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

Issue 1492583002: Add HttpUrlConnection backed implementation of CronetEngine. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fix tests Created 5 years 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 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 29 matching lines...) Expand all
52 53
53 @Override 54 @Override
54 protected void tearDown() throws Exception { 55 protected void tearDown() throws Exception {
55 QuicTestServer.shutdownQuicTestServer(); 56 QuicTestServer.shutdownQuicTestServer();
56 super.tearDown(); 57 super.tearDown();
57 } 58 }
58 59
59 @SmallTest 60 @SmallTest
60 @Feature({"Cronet"}) 61 @Feature({"Cronet"})
61 @SuppressWarnings("deprecation") 62 @SuppressWarnings("deprecation")
63 @OnlyRunNativeCronet
62 public void testQuicLoadUrl_LegacyAPI() throws Exception { 64 public void testQuicLoadUrl_LegacyAPI() throws Exception {
63 long urlRequestContextAdapter = ((ChromiumUrlRequestFactory) mTestFramew ork.mRequestFactory) 65 long urlRequestContextAdapter = ((ChromiumUrlRequestFactory) mTestFramew ork.mRequestFactory)
64 .getRequestContext() 66 .getRequestContext()
65 .getUrlRequestContextAdapter(); 67 .getUrlRequestContextAdapter();
66 NativeTestServer.registerHostResolverProc(urlRequestContextAdapter, true ); 68 NativeTestServer.registerHostResolverProc(urlRequestContextAdapter, true );
67 String quicURL = QuicTestServer.getServerURL() + "/simple.txt"; 69 String quicURL = QuicTestServer.getServerURL() + "/simple.txt";
68 70
69 HashMap<String, String> headers = new HashMap<String, String>(); 71 HashMap<String, String> headers = new HashMap<String, String>();
70 TestHttpUrlRequestListener listener = new TestHttpUrlRequestListener(); 72 TestHttpUrlRequestListener listener = new TestHttpUrlRequestListener();
71 73
72 // Although the native stack races QUIC and SPDY for the first request, 74 // Although the native stack races QUIC and SPDY for the first request,
73 // since there is no http server running on the corresponding TCP port, 75 // since there is no http server running on the corresponding TCP port,
74 // QUIC will always succeed with a 200 (see 76 // QUIC will always succeed with a 200 (see
75 // net::HttpStreamFactoryImpl::Request::OnStreamFailed). 77 // net::HttpStreamFactoryImpl::Request::OnStreamFailed).
76 HttpUrlRequest request = mTestFramework.mRequestFactory.createRequest( 78 HttpUrlRequest request = mTestFramework.mRequestFactory.createRequest(
77 quicURL, HttpUrlRequest.REQUEST_PRIORITY_MEDIUM, headers, listen er); 79 quicURL, HttpUrlRequest.REQUEST_PRIORITY_MEDIUM, headers, listen er);
78 request.start(); 80 request.start();
79 listener.blockForComplete(); 81 listener.blockForComplete();
80 assertEquals(200, listener.mHttpStatusCode); 82 assertEquals(200, listener.mHttpStatusCode);
81 assertEquals( 83 assertEquals(
82 "This is a simple text file served by QUIC.\n", 84 "This is a simple text file served by QUIC.\n",
83 listener.mResponseAsString); 85 listener.mResponseAsString);
84 assertEquals("quic/1+spdy/3", listener.mNegotiatedProtocol); 86 assertEquals("quic/1+spdy/3", listener.mNegotiatedProtocol);
85 } 87 }
86 88
87 @LargeTest 89 @LargeTest
88 @Feature({"Cronet"}) 90 @Feature({"Cronet"})
91 @OnlyRunNativeCronet
89 public void testQuicLoadUrl() throws Exception { 92 public void testQuicLoadUrl() throws Exception {
90 long urlRequestContextAdapter = ((CronetUrlRequestContext) mTestFramewor k.mCronetEngine) 93 long urlRequestContextAdapter = ((CronetUrlRequestContext) mTestFramewor k.mCronetEngine)
91 .getUrlRequestContextAdapter(); 94 .getUrlRequestContextAdapter();
92 NativeTestServer.registerHostResolverProc(urlRequestContextAdapter, fals e); 95 NativeTestServer.registerHostResolverProc(urlRequestContextAdapter, fals e);
93 96
94 String quicURL = QuicTestServer.getServerURL() + "/simple.txt"; 97 String quicURL = QuicTestServer.getServerURL() + "/simple.txt";
95 TestUrlRequestCallback callback = new TestUrlRequestCallback(); 98 TestUrlRequestCallback callback = new TestUrlRequestCallback();
96 99
97 // Although the native stack races QUIC and SPDY for the first request, 100 // Although the native stack races QUIC and SPDY for the first request,
98 // since there is no http server running on the corresponding TCP port, 101 // since there is no http server running on the corresponding TCP port,
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after
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 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698