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

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

Issue 1817553002: Add host resolver rules experimental flag for Cronet (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: delete registerHostResolverProc and rebase Created 4 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.os.ConditionVariable; 7 import android.os.ConditionVariable;
8 import android.test.suitebuilder.annotation.LargeTest; 8 import android.test.suitebuilder.annotation.LargeTest;
9 import android.test.suitebuilder.annotation.SmallTest; 9 import android.test.suitebuilder.annotation.SmallTest;
10 10
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
45 .put("connection_options", "PACE,IW10,FO O,DEADBEEF") 45 .put("connection_options", "PACE,IW10,FO O,DEADBEEF")
46 .put("host_whitelist", "test.example.com ") 46 .put("host_whitelist", "test.example.com ")
47 .put("max_server_configs_stored_in_prope rties", 2) 47 .put("max_server_configs_stored_in_prope rties", 2)
48 .put("delay_tcp_race", true) 48 .put("delay_tcp_race", true)
49 .put("max_number_of_lossy_connections", 10) 49 .put("max_number_of_lossy_connections", 10)
50 .put("packet_loss_threshold", 0.5) 50 .put("packet_loss_threshold", 0.5)
51 .put("idle_connection_timeout_seconds", 300) 51 .put("idle_connection_timeout_seconds", 300)
52 .put("close_sessions_on_ip_change", fals e) 52 .put("close_sessions_on_ip_change", fals e)
53 .put("migrate_sessions_on_network_change ", true) 53 .put("migrate_sessions_on_network_change ", true)
54 .put("migrate_sessions_early", true); 54 .put("migrate_sessions_early", true);
55 JSONObject experimentalOptions = new JSONObject().put("QUIC", quicParams ); 55 JSONObject hostResolverParams = CronetTestUtil.generateHostResolverRules ();
56 JSONObject experimentalOptions = new JSONObject()
57 .put("QUIC", quicParams)
58 .put("HostResolverRules", hostR esolverParams);
56 mBuilder.setExperimentalOptions(experimentalOptions.toString()); 59 mBuilder.setExperimentalOptions(experimentalOptions.toString());
57 mBuilder.setMockCertVerifierForTesting(QuicTestServer.createMockCertVeri fier()); 60 mBuilder.setMockCertVerifierForTesting(QuicTestServer.createMockCertVeri fier());
58 mBuilder.setStoragePath(CronetTestFramework.getTestStorage(getContext()) ); 61 mBuilder.setStoragePath(CronetTestFramework.getTestStorage(getContext()) );
59 mBuilder.enableHttpCache(CronetEngine.Builder.HTTP_CACHE_DISK_NO_HTTP, 1 000 * 1024); 62 mBuilder.enableHttpCache(CronetEngine.Builder.HTTP_CACHE_DISK_NO_HTTP, 1 000 * 1024);
60 } 63 }
61 64
62 @Override 65 @Override
63 protected void tearDown() throws Exception { 66 protected void tearDown() throws Exception {
64 QuicTestServer.shutdownQuicTestServer(); 67 QuicTestServer.shutdownQuicTestServer();
65 super.tearDown(); 68 super.tearDown();
66 } 69 }
67 70
68 @SmallTest 71 @SmallTest
69 @Feature({"Cronet"}) 72 @Feature({"Cronet"})
70 @SuppressWarnings("deprecation") 73 @SuppressWarnings("deprecation")
71 @OnlyRunNativeCronet 74 @OnlyRunNativeCronet
72 public void testQuicLoadUrl_LegacyAPI() throws Exception { 75 public void testQuicLoadUrl_LegacyAPI() throws Exception {
73 String[] commandLineArgs = { 76 String[] commandLineArgs = {
74 CronetTestFramework.LIBRARY_INIT_KEY, CronetTestFramework.Librar yInitType.LEGACY}; 77 CronetTestFramework.LIBRARY_INIT_KEY, CronetTestFramework.Librar yInitType.LEGACY};
75 mTestFramework = new CronetTestFramework(null, commandLineArgs, getConte xt(), mBuilder); 78 mTestFramework = new CronetTestFramework(null, commandLineArgs, getConte xt(), mBuilder);
76 registerHostResolver(mTestFramework, true);
77 String quicURL = QuicTestServer.getServerURL() + "/simple.txt"; 79 String quicURL = QuicTestServer.getServerURL() + "/simple.txt";
78 80
79 HashMap<String, String> headers = new HashMap<String, String>(); 81 HashMap<String, String> headers = new HashMap<String, String>();
80 TestHttpUrlRequestListener listener = new TestHttpUrlRequestListener(); 82 TestHttpUrlRequestListener listener = new TestHttpUrlRequestListener();
81 83
82 // Although the native stack races QUIC and SPDY for the first request, 84 // Although the native stack races QUIC and SPDY for the first request,
83 // since there is no http server running on the corresponding TCP port, 85 // since there is no http server running on the corresponding TCP port,
84 // QUIC will always succeed with a 200 (see 86 // QUIC will always succeed with a 200 (see
85 // net::HttpStreamFactoryImpl::Request::OnStreamFailed). 87 // net::HttpStreamFactoryImpl::Request::OnStreamFailed).
86 HttpUrlRequest request = mTestFramework.mRequestFactory.createRequest( 88 HttpUrlRequest request = mTestFramework.mRequestFactory.createRequest(
87 quicURL, HttpUrlRequest.REQUEST_PRIORITY_MEDIUM, headers, listen er); 89 quicURL, HttpUrlRequest.REQUEST_PRIORITY_MEDIUM, headers, listen er);
88 request.start(); 90 request.start();
89 listener.blockForComplete(); 91 listener.blockForComplete();
90 assertEquals(200, listener.mHttpStatusCode); 92 assertEquals(200, listener.mHttpStatusCode);
91 assertEquals( 93 assertEquals(
92 "This is a simple text file served by QUIC.\n", 94 "This is a simple text file served by QUIC.\n",
93 listener.mResponseAsString); 95 listener.mResponseAsString);
94 assertEquals("quic/1+spdy/3", listener.mNegotiatedProtocol); 96 assertEquals("quic/1+spdy/3", listener.mNegotiatedProtocol);
95 } 97 }
96 98
97 @LargeTest 99 @LargeTest
98 @Feature({"Cronet"}) 100 @Feature({"Cronet"})
99 @OnlyRunNativeCronet 101 @OnlyRunNativeCronet
100 public void testQuicLoadUrl() throws Exception { 102 public void testQuicLoadUrl() throws Exception {
101 mTestFramework = startCronetTestFrameworkWithUrlAndCronetEngineBuilder(n ull, mBuilder); 103 mTestFramework = startCronetTestFrameworkWithUrlAndCronetEngineBuilder(n ull, mBuilder);
102 registerHostResolver(mTestFramework);
103 String quicURL = QuicTestServer.getServerURL() + "/simple.txt"; 104 String quicURL = QuicTestServer.getServerURL() + "/simple.txt";
104 TestUrlRequestCallback callback = new TestUrlRequestCallback(); 105 TestUrlRequestCallback callback = new TestUrlRequestCallback();
105 106
106 // Although the native stack races QUIC and SPDY for the first request, 107 // Although the native stack races QUIC and SPDY for the first request,
107 // since there is no http server running on the corresponding TCP port, 108 // since there is no http server running on the corresponding TCP port,
108 // QUIC will always succeed with a 200 (see 109 // QUIC will always succeed with a 200 (see
109 // net::HttpStreamFactoryImpl::Request::OnStreamFailed). 110 // net::HttpStreamFactoryImpl::Request::OnStreamFailed).
110 UrlRequest.Builder requestBuilder = new UrlRequest.Builder( 111 UrlRequest.Builder requestBuilder = new UrlRequest.Builder(
111 quicURL, callback, callback.getExecutor(), mTestFramework.mCrone tEngine); 112 quicURL, callback, callback.getExecutor(), mTestFramework.mCrone tEngine);
112 requestBuilder.build().start(); 113 requestBuilder.build().start();
(...skipping 22 matching lines...) Expand all
135 assertTrue(fileContainsString("local_prefs.json", 136 assertTrue(fileContainsString("local_prefs.json",
136 QuicTestServer.getServerHost() + ":" + QuicTestServer.getServerP ort())); 137 QuicTestServer.getServerHost() + ":" + QuicTestServer.getServerP ort()));
137 mTestFramework.mCronetEngine.shutdown(); 138 mTestFramework.mCronetEngine.shutdown();
138 139
139 // Make another request using a new context but with no QUIC hints. 140 // Make another request using a new context but with no QUIC hints.
140 CronetEngine.Builder builder = new CronetEngine.Builder(getContext()); 141 CronetEngine.Builder builder = new CronetEngine.Builder(getContext());
141 builder.setStoragePath(CronetTestFramework.getTestStorage(getContext())) ; 142 builder.setStoragePath(CronetTestFramework.getTestStorage(getContext())) ;
142 builder.enableHttpCache(CronetEngine.Builder.HTTP_CACHE_DISK, 1000 * 102 4); 143 builder.enableHttpCache(CronetEngine.Builder.HTTP_CACHE_DISK, 1000 * 102 4);
143 builder.enableQUIC(true); 144 builder.enableQUIC(true);
144 JSONObject quicParams = new JSONObject().put("host_whitelist", "test.exa mple.com"); 145 JSONObject quicParams = new JSONObject().put("host_whitelist", "test.exa mple.com");
145 JSONObject experimentalOptions = new JSONObject().put("QUIC", quicParams ); 146 JSONObject hostResolverParams = CronetTestUtil.generateHostResolverRules ();
147 JSONObject experimentalOptions = new JSONObject()
148 .put("QUIC", quicParams)
149 .put("HostResolverRules", hostR esolverParams);
146 builder.setExperimentalOptions(experimentalOptions.toString()); 150 builder.setExperimentalOptions(experimentalOptions.toString());
147 builder.setMockCertVerifierForTesting(QuicTestServer.createMockCertVerif ier()); 151 builder.setMockCertVerifierForTesting(QuicTestServer.createMockCertVerif ier());
148 mTestFramework = startCronetTestFrameworkWithUrlAndCronetEngineBuilder(n ull, builder); 152 mTestFramework = startCronetTestFrameworkWithUrlAndCronetEngineBuilder(n ull, builder);
149 registerHostResolver(mTestFramework);
150 TestUrlRequestCallback callback2 = new TestUrlRequestCallback(); 153 TestUrlRequestCallback callback2 = new TestUrlRequestCallback();
151 requestBuilder = new UrlRequest.Builder( 154 requestBuilder = new UrlRequest.Builder(
152 quicURL, callback2, callback2.getExecutor(), mTestFramework.mCro netEngine); 155 quicURL, callback2, callback2.getExecutor(), mTestFramework.mCro netEngine);
153 requestBuilder.build().start(); 156 requestBuilder.build().start();
154 callback2.blockForDone(); 157 callback2.blockForDone();
155 assertEquals(200, callback2.mResponseInfo.getHttpStatusCode()); 158 assertEquals(200, callback2.mResponseInfo.getHttpStatusCode());
156 assertEquals(expectedContent, callback2.mResponseAsString); 159 assertEquals(expectedContent, callback2.mResponseAsString);
157 assertEquals("quic/1+spdy/3", callback2.mResponseInfo.getNegotiatedProto col()); 160 assertEquals("quic/1+spdy/3", callback2.mResponseInfo.getNegotiatedProto col());
158 // The total received bytes should be larger than the content length, to account for 161 // The total received bytes should be larger than the content length, to account for
159 // headers. 162 // headers.
(...skipping 11 matching lines...) Expand all
171 fileInputStream.close(); 174 fileInputStream.close();
172 return new String(data, "UTF-8").contains(content); 175 return new String(data, "UTF-8").contains(content);
173 } 176 }
174 177
175 @LargeTest 178 @LargeTest
176 @Feature({"Cronet"}) 179 @Feature({"Cronet"})
177 @OnlyRunNativeCronet 180 @OnlyRunNativeCronet
178 @SuppressWarnings("deprecation") 181 @SuppressWarnings("deprecation")
179 public void testRealTimeNetworkQualityObservationsWithQuic() throws Exceptio n { 182 public void testRealTimeNetworkQualityObservationsWithQuic() throws Exceptio n {
180 mTestFramework = startCronetTestFrameworkWithUrlAndCronetEngineBuilder(n ull, mBuilder); 183 mTestFramework = startCronetTestFrameworkWithUrlAndCronetEngineBuilder(n ull, mBuilder);
181 registerHostResolver(mTestFramework);
182 String quicURL = QuicTestServer.getServerURL() + "/simple.txt"; 184 String quicURL = QuicTestServer.getServerURL() + "/simple.txt";
183 ConditionVariable waitForThroughput = new ConditionVariable(); 185 ConditionVariable waitForThroughput = new ConditionVariable();
184 186
185 TestNetworkQualityRttListener rttListener = 187 TestNetworkQualityRttListener rttListener =
186 new TestNetworkQualityRttListener(Executors.newSingleThreadExecu tor()); 188 new TestNetworkQualityRttListener(Executors.newSingleThreadExecu tor());
187 TestNetworkQualityThroughputListener throughputListener = 189 TestNetworkQualityThroughputListener throughputListener =
188 new TestNetworkQualityThroughputListener( 190 new TestNetworkQualityThroughputListener(
189 Executors.newSingleThreadExecutor(), waitForThroughput); 191 Executors.newSingleThreadExecutor(), waitForThroughput);
190 192
191 mTestFramework.mCronetEngine.addRttListener(rttListener); 193 mTestFramework.mCronetEngine.addRttListener(rttListener);
(...skipping 26 matching lines...) Expand all
218 // that executor has finished posting the RTT observation to the RTT lis teners. 220 // that executor has finished posting the RTT observation to the RTT lis teners.
219 // NETWORK_QUALITY_OBSERVATION_SOURCE_URL_REQUEST 221 // NETWORK_QUALITY_OBSERVATION_SOURCE_URL_REQUEST
220 assertTrue(rttListener.rttObservationCount(0) > 0); 222 assertTrue(rttListener.rttObservationCount(0) > 0);
221 223
222 // NETWORK_QUALITY_OBSERVATION_SOURCE_QUIC 224 // NETWORK_QUALITY_OBSERVATION_SOURCE_QUIC
223 assertTrue(rttListener.rttObservationCount(2) > 0); 225 assertTrue(rttListener.rttObservationCount(2) > 0);
224 226
225 mTestFramework.mCronetEngine.shutdown(); 227 mTestFramework.mCronetEngine.shutdown();
226 } 228 }
227 } 229 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698