Chromium Code Reviews| OLD | NEW |
|---|---|
| 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 24 matching lines...) Expand all Loading... | |
| 35 System.loadLibrary("cronet_tests"); | 35 System.loadLibrary("cronet_tests"); |
| 36 QuicTestServer.startQuicTestServer(getContext()); | 36 QuicTestServer.startQuicTestServer(getContext()); |
| 37 | 37 |
| 38 mBuilder = new CronetEngine.Builder(getContext()); | 38 mBuilder = new CronetEngine.Builder(getContext()); |
| 39 mBuilder.enableQUIC(true); | 39 mBuilder.enableQUIC(true); |
| 40 mBuilder.addQuicHint(QuicTestServer.getServerHost(), QuicTestServer.getS erverPort(), | 40 mBuilder.addQuicHint(QuicTestServer.getServerHost(), QuicTestServer.getS erverPort(), |
| 41 QuicTestServer.getServerPort()); | 41 QuicTestServer.getServerPort()); |
| 42 | 42 |
| 43 JSONObject quicParams = new JSONObject() | 43 JSONObject quicParams = new JSONObject() |
| 44 .put("connection_options", "PACE,IW10,FO O,DEADBEEF") | 44 .put("connection_options", "PACE,IW10,FO O,DEADBEEF") |
| 45 .put("host_whitelist", "test.example.com ") | |
| 45 .put("store_server_configs_in_properties ", true) | 46 .put("store_server_configs_in_properties ", true) |
| 46 .put("delay_tcp_race", true) | 47 .put("delay_tcp_race", true) |
| 47 .put("max_number_of_lossy_connections", 10) | 48 .put("max_number_of_lossy_connections", 10) |
| 48 .put("packet_loss_threshold", 0.5) | 49 .put("packet_loss_threshold", 0.5) |
| 49 .put("idle_connection_timeout_seconds", 300); | 50 .put("idle_connection_timeout_seconds", 300); |
| 50 JSONObject experimentalOptions = new JSONObject().put("QUIC", quicParams ); | 51 JSONObject experimentalOptions = new JSONObject().put("QUIC", quicParams ); |
| 51 mBuilder.setExperimentalOptions(experimentalOptions.toString()); | 52 mBuilder.setExperimentalOptions(experimentalOptions.toString()); |
| 52 | 53 |
| 53 mBuilder.setMockCertVerifierForTesting(MockCertVerifier.createMockCertVe rifier(CERTS_USED)); | 54 mBuilder.setMockCertVerifierForTesting(MockCertVerifier.createMockCertVe rifier(CERTS_USED)); |
| 54 mBuilder.setStoragePath(CronetTestFramework.getTestStorage(getContext()) ); | 55 mBuilder.setStoragePath(CronetTestFramework.getTestStorage(getContext()) ); |
| (...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 108 requestBuilder.build().start(); | 109 requestBuilder.build().start(); |
| 109 callback.blockForDone(); | 110 callback.blockForDone(); |
| 110 | 111 |
| 111 assertEquals(200, callback.mResponseInfo.getHttpStatusCode()); | 112 assertEquals(200, callback.mResponseInfo.getHttpStatusCode()); |
| 112 String expectedContent = "This is a simple text file served by QUIC.\n"; | 113 String expectedContent = "This is a simple text file served by QUIC.\n"; |
| 113 assertEquals(expectedContent, callback.mResponseAsString); | 114 assertEquals(expectedContent, callback.mResponseAsString); |
| 114 assertEquals("quic/1+spdy/3", callback.mResponseInfo.getNegotiatedProtoc ol()); | 115 assertEquals("quic/1+spdy/3", callback.mResponseInfo.getNegotiatedProtoc ol()); |
| 115 // The total received bytes should be larger than the content length, to account for | 116 // The total received bytes should be larger than the content length, to account for |
| 116 // headers. | 117 // headers. |
| 117 assertTrue(callback.mResponseInfo.getReceivedBytesCount() > expectedCont ent.length()); | 118 assertTrue(callback.mResponseInfo.getReceivedBytesCount() > expectedCont ent.length()); |
| 118 | |
| 119 // This test takes a long time, since the update will only be scheduled | 119 // This test takes a long time, since the update will only be scheduled |
| 120 // after kUpdatePrefsDelayMs in http_server_properties_manager.cc. | 120 // after kUpdatePrefsDelayMs in http_server_properties_manager.cc. |
| 121 while (true) { | 121 while (true) { |
| 122 Log.i(TAG, "Still waiting for pref file update....."); | 122 Log.i(TAG, "Still waiting for pref file update....."); |
| 123 Thread.sleep(10000); | 123 Thread.sleep(10000); |
| 124 boolean contains = false; | 124 boolean contains = false; |
| 125 try { | 125 try { |
| 126 if (fileContainsString("local_prefs.json", "quic")) break; | 126 if (fileContainsString("local_prefs.json", "quic")) break; |
| 127 } catch (FileNotFoundException e) { | 127 } catch (FileNotFoundException e) { |
| 128 // Ignored this exception since the file will only be created wh en updates are | 128 // Ignored this exception since the file will only be created wh en updates are |
| 129 // flushed to the disk. | 129 // flushed to the disk. |
| 130 } | 130 } |
| 131 } | 131 } |
| 132 assertTrue(fileContainsString("local_prefs.json", | 132 assertTrue(fileContainsString("local_prefs.json", |
| 133 QuicTestServer.getServerHost() + ":" + QuicTestServer.getServerP ort())); | 133 QuicTestServer.getServerHost() + ":" + QuicTestServer.getServerP ort())); |
| 134 mTestFramework.mCronetEngine.shutdown(); | 134 mTestFramework.mCronetEngine.shutdown(); |
| 135 | 135 |
| 136 // Make another request using a new context but with no QUIC hints. | 136 // Make another request using a new context but with no QUIC hints. |
| 137 CronetEngine.Builder builder = new CronetEngine.Builder(getContext()); | 137 CronetEngine.Builder builder = new CronetEngine.Builder(getContext()); |
| 138 builder.setStoragePath(CronetTestFramework.getTestStorage(getContext())) ; | 138 builder.setStoragePath(CronetTestFramework.getTestStorage(getContext())) ; |
| 139 builder.enableHttpCache(CronetEngine.Builder.HTTP_CACHE_DISK, 1000 * 102 4); | 139 builder.enableHttpCache(CronetEngine.Builder.HTTP_CACHE_DISK, 1000 * 102 4); |
| 140 builder.enableQUIC(true); | 140 builder.enableQUIC(true); |
| 141 JSONObject quicParams = new JSONObject() | |
| 142 .put("connection_options", "PACE,IW10,FO O,DEADBEEF") | |
| 143 .put("host_whitelist", "test.example.com ") | |
| 144 .put("store_server_configs_in_properties ", true) | |
|
mef
2016/01/13 22:18:15
nit: do we need all these options, or did you add
Ryan Hamilton
2016/01/13 22:34:58
Good point. I copied them from the previous setup,
| |
| 145 .put("delay_tcp_race", true) | |
| 146 .put("max_number_of_lossy_connections", 10) | |
| 147 .put("packet_loss_threshold", 0.5) | |
| 148 .put("idle_connection_timeout_seconds", 300); | |
| 149 JSONObject experimentalOptions = new JSONObject().put("QUIC", quicParams ); | |
| 150 builder.setExperimentalOptions(experimentalOptions.toString()); | |
| 141 builder.setMockCertVerifierForTesting(MockCertVerifier.createMockCertVer ifier(CERTS_USED)); | 151 builder.setMockCertVerifierForTesting(MockCertVerifier.createMockCertVer ifier(CERTS_USED)); |
| 142 mTestFramework = startCronetTestFrameworkWithUrlAndCronetEngineBuilder(n ull, builder); | 152 mTestFramework = startCronetTestFrameworkWithUrlAndCronetEngineBuilder(n ull, builder); |
| 143 registerHostResolver(mTestFramework); | 153 registerHostResolver(mTestFramework); |
| 144 TestUrlRequestCallback callback2 = new TestUrlRequestCallback(); | 154 TestUrlRequestCallback callback2 = new TestUrlRequestCallback(); |
| 145 requestBuilder = new UrlRequest.Builder( | 155 requestBuilder = new UrlRequest.Builder( |
| 146 quicURL, callback2, callback2.getExecutor(), mTestFramework.mCro netEngine); | 156 quicURL, callback2, callback2.getExecutor(), mTestFramework.mCro netEngine); |
| 147 requestBuilder.build().start(); | 157 requestBuilder.build().start(); |
| 148 callback2.blockForDone(); | 158 callback2.blockForDone(); |
| 149 assertEquals(200, callback2.mResponseInfo.getHttpStatusCode()); | 159 assertEquals(200, callback2.mResponseInfo.getHttpStatusCode()); |
| 150 assertEquals(expectedContent, callback2.mResponseAsString); | 160 assertEquals(expectedContent, callback2.mResponseAsString); |
| 151 assertEquals("quic/1+spdy/3", callback2.mResponseInfo.getNegotiatedProto col()); | 161 assertEquals("quic/1+spdy/3", callback2.mResponseInfo.getNegotiatedProto col()); |
| 152 // The total received bytes should be larger than the content length, to account for | 162 // The total received bytes should be larger than the content length, to account for |
| 153 // headers. | 163 // headers. |
| 154 assertTrue(callback2.mResponseInfo.getReceivedBytesCount() > expectedCon tent.length()); | 164 assertTrue(callback2.mResponseInfo.getReceivedBytesCount() > expectedCon tent.length()); |
| 155 } | 165 } |
| 156 | 166 |
| 157 // Returns whether a file contains a particular string. | 167 // Returns whether a file contains a particular string. |
| 158 @SuppressFBWarnings("OBL_UNSATISFIED_OBLIGATION_EXCEPTION_EDGE") | 168 @SuppressFBWarnings("OBL_UNSATISFIED_OBLIGATION_EXCEPTION_EDGE") |
| 159 private boolean fileContainsString(String filename, String content) throws I OException { | 169 private boolean fileContainsString(String filename, String content) throws I OException { |
| 160 File file = new File(CronetTestFramework.getTestStorage(getContext()) + "/" + filename); | 170 File file = new File(CronetTestFramework.getTestStorage(getContext()) + "/" + filename); |
| 161 FileInputStream fileInputStream = new FileInputStream(file); | 171 FileInputStream fileInputStream = new FileInputStream(file); |
| 162 byte[] data = new byte[(int) file.length()]; | 172 byte[] data = new byte[(int) file.length()]; |
| 163 fileInputStream.read(data); | 173 fileInputStream.read(data); |
| 164 fileInputStream.close(); | 174 fileInputStream.close(); |
| 165 return new String(data, "UTF-8").contains(content); | 175 return new String(data, "UTF-8").contains(content); |
| 166 } | 176 } |
| 167 } | 177 } |
| OLD | NEW |