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

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

Issue 1175733002: [Cronet] Set up HttpServerPropertiesManager (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Address Findbug error Created 5 years, 5 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 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.SmallTest; 8 import android.test.suitebuilder.annotation.SmallTest;
8 9
10 import org.chromium.base.Log;
11 import org.chromium.base.annotations.SuppressFBWarnings;
9 import org.chromium.base.test.util.Feature; 12 import org.chromium.base.test.util.Feature;
10 13
14 import java.io.File;
15 import java.io.FileInputStream;
16 import java.io.FileNotFoundException;
17 import java.io.IOException;
11 import java.util.HashMap; 18 import java.util.HashMap;
12 19
13 /** 20 /**
14 * Tests making requests using QUIC. 21 * Tests making requests using QUIC.
15 */ 22 */
16 public class QuicTest extends CronetTestBase { 23 public class QuicTest extends CronetTestBase {
17 24 private static final String TAG = "cr.QuicTest";
18 private CronetTestActivity mActivity; 25 private CronetTestActivity mActivity;
19 26
20 @Override 27 @Override
21 protected void setUp() throws Exception { 28 protected void setUp() throws Exception {
22 super.setUp(); 29 super.setUp();
23 // Load library first, since we need the Quic test server's URL. 30 // Load library first, since we need the Quic test server's URL.
24 System.loadLibrary("cronet_tests"); 31 System.loadLibrary("cronet_tests");
25 QuicTestServer.startQuicTestServer(getInstrumentation().getTargetContext ()); 32 QuicTestServer.startQuicTestServer(getInstrumentation().getTargetContext ());
26 UrlRequestContextConfig config = new UrlRequestContextConfig(); 33 UrlRequestContextConfig config = new UrlRequestContextConfig();
27 config.enableQUIC(true); 34 config.enableQUIC(true);
(...skipping 28 matching lines...) Expand all
56 quicURL, HttpUrlRequest.REQUEST_PRIORITY_MEDIUM, headers, listen er); 63 quicURL, HttpUrlRequest.REQUEST_PRIORITY_MEDIUM, headers, listen er);
57 request.start(); 64 request.start();
58 listener.blockForComplete(); 65 listener.blockForComplete();
59 assertEquals(200, listener.mHttpStatusCode); 66 assertEquals(200, listener.mHttpStatusCode);
60 assertEquals( 67 assertEquals(
61 "This is a simple text file served by QUIC.\n", 68 "This is a simple text file served by QUIC.\n",
62 listener.mResponseAsString); 69 listener.mResponseAsString);
63 assertEquals("quic/1+spdy/3", listener.mNegotiatedProtocol); 70 assertEquals("quic/1+spdy/3", listener.mNegotiatedProtocol);
64 } 71 }
65 72
66 @SmallTest 73 @LargeTest
67 @Feature({"Cronet"}) 74 @Feature({"Cronet"})
68 public void testQuicLoadUrl() throws Exception { 75 public void testQuicLoadUrl() throws Exception {
69 String quicURL = QuicTestServer.getServerURL() + "/simple.txt"; 76 String quicURL = QuicTestServer.getServerURL() + "/simple.txt";
70 TestUrlRequestListener listener = new TestUrlRequestListener(); 77 TestUrlRequestListener listener = new TestUrlRequestListener();
71 78
72 // Although the native stack races QUIC and SPDY for the first request, 79 // 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, 80 // since there is no http server running on the corresponding TCP port,
74 // QUIC will always succeed with a 200 (see 81 // QUIC will always succeed with a 200 (see
75 // net::HttpStreamFactoryImpl::Request::OnStreamFailed). 82 // net::HttpStreamFactoryImpl::Request::OnStreamFailed).
76 UrlRequest request = mActivity.mUrlRequestContext.createRequest( 83 UrlRequest request = mActivity.mUrlRequestContext.createRequest(
77 quicURL, listener, listener.getExecutor()); 84 quicURL, listener, listener.getExecutor());
78 request.start(); 85 request.start();
79 listener.blockForDone(); 86 listener.blockForDone();
80 87
81 assertEquals(200, listener.mResponseInfo.getHttpStatusCode()); 88 assertEquals(200, listener.mResponseInfo.getHttpStatusCode());
82 assertEquals("This is a simple text file served by QUIC.\n", listener.mR esponseAsString); 89 assertEquals("This is a simple text file served by QUIC.\n", listener.mR esponseAsString);
83 assertEquals("quic/1+spdy/3", listener.mResponseInfo.getNegotiatedProtoc ol()); 90 assertEquals("quic/1+spdy/3", listener.mResponseInfo.getNegotiatedProtoc ol());
91
92 // This test takes a long time, since the update will only be scheduled
93 // after kUpdatePrefsDelayMs in http_server_properties_manager.cc.
94 while (true) {
95 Log.i(TAG, "Still waiting for pref file update.....");
96 Thread.sleep(10000);
97 boolean contains = false;
98 try {
99 if (fileContainsString("local_prefs.json", "quic")) break;
100 } catch (FileNotFoundException e) {
101 // Ignored this exception since the file will only be created wh en updates are
102 // flushed to the disk.
103 }
104 }
105 assertTrue(fileContainsString("local_prefs.json",
106 QuicTestServer.getServerHost() + ":" + QuicTestServer.getServerP ort()));
107 mActivity.mUrlRequestContext.shutdown();
108
109 // Make another request using a new context but with no QUIC hints.
110 UrlRequestContextConfig config = new UrlRequestContextConfig();
111 config.setStoragePath(mActivity.getTestStorage());
112 config.enableHttpCache(UrlRequestContextConfig.HttpCache.DISK, 1000 * 10 24);
113 config.enableQUIC(true);
114 CronetUrlRequestContext newContext =
115 new CronetUrlRequestContext(getInstrumentation().getTargetContex t(), config);
116 TestUrlRequestListener listener2 = new TestUrlRequestListener();
117 UrlRequest request2 = newContext.createRequest(quicURL, listener2, liste ner2.getExecutor());
118 request2.start();
119 listener2.blockForDone();
120 assertEquals(200, listener2.mResponseInfo.getHttpStatusCode());
121 assertEquals("This is a simple text file served by QUIC.\n", listener2.m ResponseAsString);
122 assertEquals("quic/1+spdy/3", listener2.mResponseInfo.getNegotiatedProto col());
123 }
124
125 // Returns whether a file contains a particular string.
126 @SuppressFBWarnings("OBL_UNSATISFIED_OBLIGATION_EXCEPTION_EDGE")
127 private boolean fileContainsString(String filename, String content) throws I OException {
128 File file = new File(mActivity.getTestStorage() + "/" + filename);
129 FileInputStream fileInputStream = new FileInputStream(file);
130 byte[] data = new byte[(int) file.length()];
131 fileInputStream.read(data);
132 fileInputStream.close();
133 return new String(data, "UTF-8").contains(content);
84 } 134 }
85 } 135 }
OLDNEW
« no previous file with comments | « components/cronet/android/cronet_url_request_context_adapter.cc ('k') | net/url_request/url_request_context_builder.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698