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

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: update Ben's tests 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(mActivity);
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 = new UrlRequest.Builder(
84 quicURL, listener, listener.getExecutor()); 84 quicURL, listener, listener.getExecutor(), mActivity.mCronetEngi ne);
85 request.start(); 85 requestBuilder.build().start();
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 // The total received bytes should be larger than the content length, to account for 92 // The total received bytes should be larger than the content length, to account for
93 // headers. 93 // headers.
94 assertTrue( 94 assertTrue(
95 listener.mExtendedResponseInfo.getTotalReceivedBytes() > expecte dContent.length()); 95 listener.mExtendedResponseInfo.getTotalReceivedBytes() > expecte dContent.length());
96 96
97 // This test takes a long time, since the update will only be scheduled 97 // This test takes a long time, since the update will only be scheduled
98 // after kUpdatePrefsDelayMs in http_server_properties_manager.cc. 98 // after kUpdatePrefsDelayMs in http_server_properties_manager.cc.
99 while (true) { 99 while (true) {
100 Log.i(TAG, "Still waiting for pref file update....."); 100 Log.i(TAG, "Still waiting for pref file update.....");
101 Thread.sleep(10000); 101 Thread.sleep(10000);
102 boolean contains = false; 102 boolean contains = false;
103 try { 103 try {
104 if (fileContainsString("local_prefs.json", "quic")) break; 104 if (fileContainsString("local_prefs.json", "quic")) break;
105 } catch (FileNotFoundException e) { 105 } catch (FileNotFoundException e) {
106 // Ignored this exception since the file will only be created wh en updates are 106 // Ignored this exception since the file will only be created wh en updates are
107 // flushed to the disk. 107 // flushed to the disk.
108 } 108 }
109 } 109 }
110 assertTrue(fileContainsString("local_prefs.json", 110 assertTrue(fileContainsString("local_prefs.json",
111 QuicTestServer.getServerHost() + ":" + QuicTestServer.getServerP ort())); 111 QuicTestServer.getServerHost() + ":" + QuicTestServer.getServerP ort()));
112 mActivity.mUrlRequestContext.shutdown(); 112 mActivity.mCronetEngine.shutdown();
113 113
114 // Make another request using a new context but with no QUIC hints. 114 // Make another request using a new context but with no QUIC hints.
115 UrlRequestContextConfig config = new UrlRequestContextConfig(); 115 CronetEngine.Builder builder =
116 config.setStoragePath(mActivity.getTestStorage()); 116 new CronetEngine.Builder(getInstrumentation().getTargetContext() );
117 config.enableHttpCache(UrlRequestContextConfig.HTTP_CACHE_DISK, 1000 * 1 024); 117 builder.setStoragePath(mActivity.getTestStorage());
118 config.enableQUIC(true); 118 builder.enableHttpCache(CronetEngine.Builder.HTTP_CACHE_DISK, 1000 * 102 4);
119 CronetUrlRequestContext newContext = 119 builder.enableQUIC(true);
120 new CronetUrlRequestContext(getInstrumentation().getTargetContex t(), config); 120 CronetEngine newEngine = new CronetUrlRequestContext(builder);
121 TestUrlRequestListener listener2 = new TestUrlRequestListener(); 121 TestUrlRequestListener listener2 = new TestUrlRequestListener();
122 UrlRequest request2 = newContext.createRequest(quicURL, listener2, liste ner2.getExecutor()); 122 requestBuilder =
123 request2.start(); 123 new UrlRequest.Builder(quicURL, listener2, listener2.getExecutor (), newEngine);
124 requestBuilder.build().start();
124 listener2.blockForDone(); 125 listener2.blockForDone();
125 assertEquals(200, listener2.mResponseInfo.getHttpStatusCode()); 126 assertEquals(200, listener2.mResponseInfo.getHttpStatusCode());
126 assertEquals(expectedContent, listener2.mResponseAsString); 127 assertEquals(expectedContent, listener2.mResponseAsString);
127 assertEquals("quic/1+spdy/3", listener2.mResponseInfo.getNegotiatedProto col()); 128 assertEquals("quic/1+spdy/3", listener2.mResponseInfo.getNegotiatedProto col());
128 // The total received bytes should be larger than the content length, to account for 129 // The total received bytes should be larger than the content length, to account for
129 // headers. 130 // headers.
130 assertTrue( 131 assertTrue(
131 listener2.mExtendedResponseInfo.getTotalReceivedBytes() > expect edContent.length()); 132 listener2.mExtendedResponseInfo.getTotalReceivedBytes() > expect edContent.length());
132 } 133 }
133 134
134 // Returns whether a file contains a particular string. 135 // Returns whether a file contains a particular string.
135 @SuppressFBWarnings("OBL_UNSATISFIED_OBLIGATION_EXCEPTION_EDGE") 136 @SuppressFBWarnings("OBL_UNSATISFIED_OBLIGATION_EXCEPTION_EDGE")
136 private boolean fileContainsString(String filename, String content) throws I OException { 137 private boolean fileContainsString(String filename, String content) throws I OException {
137 File file = new File(mActivity.getTestStorage() + "/" + filename); 138 File file = new File(mActivity.getTestStorage() + "/" + filename);
138 FileInputStream fileInputStream = new FileInputStream(file); 139 FileInputStream fileInputStream = new FileInputStream(file);
139 byte[] data = new byte[(int) file.length()]; 140 byte[] data = new byte[(int) file.length()];
140 fileInputStream.read(data); 141 fileInputStream.read(data);
141 fileInputStream.close(); 142 fileInputStream.close();
142 return new String(data, "UTF-8").contains(content); 143 return new String(data, "UTF-8").contains(content);
143 } 144 }
144 } 145 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698