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 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
84 quicURL, listener, listener.getExecutor(), mActivity.mCronetEngi
ne); | 84 quicURL, listener, listener.getExecutor(), mActivity.mCronetEngi
ne); |
85 requestBuilder.build().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(listener.mResponseInfo.getReceivedBytesCount() > expectedCont
ent.length()); |
95 listener.mExtendedResponseInfo.getTotalReceivedBytes() > expecte
dContent.length()); | |
96 | 95 |
97 // This test takes a long time, since the update will only be scheduled | 96 // This test takes a long time, since the update will only be scheduled |
98 // after kUpdatePrefsDelayMs in http_server_properties_manager.cc. | 97 // after kUpdatePrefsDelayMs in http_server_properties_manager.cc. |
99 while (true) { | 98 while (true) { |
100 Log.i(TAG, "Still waiting for pref file update....."); | 99 Log.i(TAG, "Still waiting for pref file update....."); |
101 Thread.sleep(10000); | 100 Thread.sleep(10000); |
102 boolean contains = false; | 101 boolean contains = false; |
103 try { | 102 try { |
104 if (fileContainsString("local_prefs.json", "quic")) break; | 103 if (fileContainsString("local_prefs.json", "quic")) break; |
105 } catch (FileNotFoundException e) { | 104 } catch (FileNotFoundException e) { |
(...skipping 15 matching lines...) Expand all Loading... |
121 TestUrlRequestListener listener2 = new TestUrlRequestListener(); | 120 TestUrlRequestListener listener2 = new TestUrlRequestListener(); |
122 requestBuilder = | 121 requestBuilder = |
123 new UrlRequest.Builder(quicURL, listener2, listener2.getExecutor
(), newEngine); | 122 new UrlRequest.Builder(quicURL, listener2, listener2.getExecutor
(), newEngine); |
124 requestBuilder.build().start(); | 123 requestBuilder.build().start(); |
125 listener2.blockForDone(); | 124 listener2.blockForDone(); |
126 assertEquals(200, listener2.mResponseInfo.getHttpStatusCode()); | 125 assertEquals(200, listener2.mResponseInfo.getHttpStatusCode()); |
127 assertEquals(expectedContent, listener2.mResponseAsString); | 126 assertEquals(expectedContent, listener2.mResponseAsString); |
128 assertEquals("quic/1+spdy/3", listener2.mResponseInfo.getNegotiatedProto
col()); | 127 assertEquals("quic/1+spdy/3", listener2.mResponseInfo.getNegotiatedProto
col()); |
129 // The total received bytes should be larger than the content length, to
account for | 128 // The total received bytes should be larger than the content length, to
account for |
130 // headers. | 129 // headers. |
131 assertTrue( | 130 assertTrue(listener2.mResponseInfo.getReceivedBytesCount() > expectedCon
tent.length()); |
132 listener2.mExtendedResponseInfo.getTotalReceivedBytes() > expect
edContent.length()); | |
133 } | 131 } |
134 | 132 |
135 // Returns whether a file contains a particular string. | 133 // Returns whether a file contains a particular string. |
136 @SuppressFBWarnings("OBL_UNSATISFIED_OBLIGATION_EXCEPTION_EDGE") | 134 @SuppressFBWarnings("OBL_UNSATISFIED_OBLIGATION_EXCEPTION_EDGE") |
137 private boolean fileContainsString(String filename, String content) throws I
OException { | 135 private boolean fileContainsString(String filename, String content) throws I
OException { |
138 File file = new File(mActivity.getTestStorage() + "/" + filename); | 136 File file = new File(mActivity.getTestStorage() + "/" + filename); |
139 FileInputStream fileInputStream = new FileInputStream(file); | 137 FileInputStream fileInputStream = new FileInputStream(file); |
140 byte[] data = new byte[(int) file.length()]; | 138 byte[] data = new byte[(int) file.length()]; |
141 fileInputStream.read(data); | 139 fileInputStream.read(data); |
142 fileInputStream.close(); | 140 fileInputStream.close(); |
143 return new String(data, "UTF-8").contains(content); | 141 return new String(data, "UTF-8").contains(content); |
144 } | 142 } |
145 } | 143 } |
OLD | NEW |