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

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

Issue 1363723002: [Cronet] Create Builders, rename UrlRequestContext to CronetEngine (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 2 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.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;
(...skipping 12 matching lines...) Expand all
23 public class QuicTest extends CronetTestBase { 23 public class QuicTest extends CronetTestBase {
24 private static final String TAG = "cr.QuicTest"; 24 private static final String TAG = "cr.QuicTest";
25 private CronetTestActivity mActivity; 25 private CronetTestActivity mActivity;
26 26
27 @Override 27 @Override
28 protected void setUp() throws Exception { 28 protected void setUp() throws Exception {
29 super.setUp(); 29 super.setUp();
30 // 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.
31 System.loadLibrary("cronet_tests"); 31 System.loadLibrary("cronet_tests");
32 QuicTestServer.startQuicTestServer(getInstrumentation().getTargetContext ()); 32 QuicTestServer.startQuicTestServer(getInstrumentation().getTargetContext ());
33 UrlRequestContextConfig config = new UrlRequestContextConfig(); 33 CronetEngine.Builder builder = new CronetEngine.Builder();
34 config.enableQUIC(true); 34 builder.enableQUIC(true);
35 config.addQuicHint(QuicTestServer.getServerHost(), QuicTestServer.getSer verPort(), 35 builder.addQuicHint(QuicTestServer.getServerHost(), QuicTestServer.getSe rverPort(),
36 QuicTestServer.getServerPort()); 36 QuicTestServer.getServerPort());
37 config.setExperimentalQuicConnectionOptions("PACE,IW10,FOO,DEADBEEF"); 37 builder.setExperimentalQuicConnectionOptions("PACE,IW10,FOO,DEADBEEF");
38 38
39 String[] commandLineArgs = {CronetTestActivity.CONFIG_KEY, config.toStri ng(), 39 String[] commandLineArgs = {CronetTestActivity.CONFIG_KEY, builder.toStr ing(),
40 CronetTestActivity.CACHE_KEY, CronetTestActivity.CACHE_DISK_NO_H TTP}; 40 CronetTestActivity.CACHE_KEY, CronetTestActivity.CACHE_DISK_NO_H TTP};
41 mActivity = launchCronetTestAppWithUrlAndCommandLineArgs(null, commandLi neArgs); 41 mActivity = launchCronetTestAppWithUrlAndCommandLineArgs(null, commandLi neArgs);
42 } 42 }
43 43
44 @Override 44 @Override
45 protected void tearDown() throws Exception { 45 protected void tearDown() throws Exception {
46 QuicTestServer.shutdownQuicTestServer(); 46 QuicTestServer.shutdownQuicTestServer();
47 super.tearDown(); 47 super.tearDown();
48 } 48 }
49 49
(...skipping 23 matching lines...) Expand all
73 @LargeTest 73 @LargeTest
74 @Feature({"Cronet"}) 74 @Feature({"Cronet"})
75 public void testQuicLoadUrl() throws Exception { 75 public void testQuicLoadUrl() throws Exception {
76 String quicURL = QuicTestServer.getServerURL() + "/simple.txt"; 76 String quicURL = QuicTestServer.getServerURL() + "/simple.txt";
77 TestUrlRequestListener listener = new TestUrlRequestListener(); 77 TestUrlRequestListener listener = new TestUrlRequestListener();
78 78
79 // 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,
80 // 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,
81 // QUIC will always succeed with a 200 (see 81 // QUIC will always succeed with a 200 (see
82 // net::HttpStreamFactoryImpl::Request::OnStreamFailed). 82 // net::HttpStreamFactoryImpl::Request::OnStreamFailed).
83 UrlRequest request = mActivity.mUrlRequestContext.createRequest( 83 UrlRequest.Builder requestBuilder =
84 quicURL, listener, listener.getExecutor()); 84 new UrlRequest.Builder(quicURL, listener, listener.getExecutor() );
85 request.start(); 85 mActivity.mCronetEngine.executeRequest(requestBuilder);
86 listener.blockForDone(); 86 listener.blockForDone();
87 87
88 assertEquals(200, listener.mResponseInfo.getHttpStatusCode()); 88 assertEquals(200, listener.mResponseInfo.getHttpStatusCode());
89 String expectedContent = "This is a simple text file served by QUIC.\n"; 89 String expectedContent = "This is a simple text file served by QUIC.\n";
90 assertEquals(expectedContent, listener.mResponseAsString); 90 assertEquals(expectedContent, listener.mResponseAsString);
91 assertEquals("quic/1+spdy/3", listener.mResponseInfo.getNegotiatedProtoc ol()); 91 assertEquals("quic/1+spdy/3", listener.mResponseInfo.getNegotiatedProtoc ol());
92 assertEquals( 92 assertEquals(
93 expectedContent.length(), listener.mExtendedResponseInfo.getTota lReceivedBytes()); 93 expectedContent.length(), listener.mExtendedResponseInfo.getTota lReceivedBytes());
94 94
95 // This test takes a long time, since the update will only be scheduled 95 // This test takes a long time, since the update will only be scheduled
96 // after kUpdatePrefsDelayMs in http_server_properties_manager.cc. 96 // after kUpdatePrefsDelayMs in http_server_properties_manager.cc.
97 while (true) { 97 while (true) {
98 Log.i(TAG, "Still waiting for pref file update....."); 98 Log.i(TAG, "Still waiting for pref file update.....");
99 Thread.sleep(10000); 99 Thread.sleep(10000);
100 boolean contains = false; 100 boolean contains = false;
101 try { 101 try {
102 if (fileContainsString("local_prefs.json", "quic")) break; 102 if (fileContainsString("local_prefs.json", "quic")) break;
103 } catch (FileNotFoundException e) { 103 } catch (FileNotFoundException e) {
104 // Ignored this exception since the file will only be created wh en updates are 104 // Ignored this exception since the file will only be created wh en updates are
105 // flushed to the disk. 105 // flushed to the disk.
106 } 106 }
107 } 107 }
108 assertTrue(fileContainsString("local_prefs.json", 108 assertTrue(fileContainsString("local_prefs.json",
109 QuicTestServer.getServerHost() + ":" + QuicTestServer.getServerP ort())); 109 QuicTestServer.getServerHost() + ":" + QuicTestServer.getServerP ort()));
110 mActivity.mUrlRequestContext.shutdown(); 110 mActivity.mCronetEngine.shutdown();
111 111
112 // Make another request using a new context but with no QUIC hints. 112 // Make another request using a new context but with no QUIC hints.
113 UrlRequestContextConfig config = new UrlRequestContextConfig(); 113 CronetEngine.Builder builder = new CronetEngine.Builder();
114 config.setStoragePath(mActivity.getTestStorage()); 114 builder.setStoragePath(mActivity.getTestStorage());
115 config.enableHttpCache(UrlRequestContextConfig.HTTP_CACHE_DISK, 1000 * 1 024); 115 builder.enableHttpCache(CronetEngine.Builder.HTTP_CACHE_DISK, 1000 * 102 4);
116 config.enableQUIC(true); 116 builder.enableQUIC(true);
117 CronetUrlRequestContext newContext = 117 CronetUrlRequestContext newContext =
mef 2015/09/25 21:32:19 newEngine?
pauljensen 2015/09/28 14:18:12 Done. I thought because it was a CronetUrlRequest
118 new CronetUrlRequestContext(getInstrumentation().getTargetContex t(), config); 118 new CronetUrlRequestContext(getInstrumentation().getTargetContex t(), builder);
119 TestUrlRequestListener listener2 = new TestUrlRequestListener(); 119 TestUrlRequestListener listener2 = new TestUrlRequestListener();
120 UrlRequest request2 = newContext.createRequest(quicURL, listener2, liste ner2.getExecutor()); 120 requestBuilder = new UrlRequest.Builder(quicURL, listener2, listener2.ge tExecutor());
121 request2.start(); 121 newContext.executeRequest(requestBuilder);
122 listener2.blockForDone(); 122 listener2.blockForDone();
123 assertEquals(200, listener2.mResponseInfo.getHttpStatusCode()); 123 assertEquals(200, listener2.mResponseInfo.getHttpStatusCode());
124 assertEquals(expectedContent, listener2.mResponseAsString); 124 assertEquals(expectedContent, listener2.mResponseAsString);
125 assertEquals("quic/1+spdy/3", listener2.mResponseInfo.getNegotiatedProto col()); 125 assertEquals("quic/1+spdy/3", listener2.mResponseInfo.getNegotiatedProto col());
126 assertEquals( 126 assertEquals(
127 expectedContent.length(), listener2.mExtendedResponseInfo.getTot alReceivedBytes()); 127 expectedContent.length(), listener2.mExtendedResponseInfo.getTot alReceivedBytes());
128 } 128 }
129 129
130 // Returns whether a file contains a particular string. 130 // Returns whether a file contains a particular string.
131 @SuppressFBWarnings("OBL_UNSATISFIED_OBLIGATION_EXCEPTION_EDGE") 131 @SuppressFBWarnings("OBL_UNSATISFIED_OBLIGATION_EXCEPTION_EDGE")
132 private boolean fileContainsString(String filename, String content) throws I OException { 132 private boolean fileContainsString(String filename, String content) throws I OException {
133 File file = new File(mActivity.getTestStorage() + "/" + filename); 133 File file = new File(mActivity.getTestStorage() + "/" + filename);
134 FileInputStream fileInputStream = new FileInputStream(file); 134 FileInputStream fileInputStream = new FileInputStream(file);
135 byte[] data = new byte[(int) file.length()]; 135 byte[] data = new byte[(int) file.length()];
136 fileInputStream.read(data); 136 fileInputStream.read(data);
137 fileInputStream.close(); 137 fileInputStream.close();
138 return new String(data, "UTF-8").contains(content); 138 return new String(data, "UTF-8").contains(content);
139 } 139 }
140 } 140 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698