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

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

Issue 1492583002: Add HttpUrlConnection backed implementation of CronetEngine. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Rebase on HEAD Created 5 years 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.SmallTest; 8 import android.test.suitebuilder.annotation.SmallTest;
9 9
10 import org.chromium.base.test.util.Feature; 10 import org.chromium.base.test.util.Feature;
11 import org.chromium.net.CronetTestBase.OnlyRunNativeCronet;
11 12
12 import java.io.BufferedReader; 13 import java.io.BufferedReader;
13 import java.io.FileReader; 14 import java.io.FileReader;
14 import java.io.IOException; 15 import java.io.IOException;
15 import java.util.ArrayList; 16 import java.util.ArrayList;
16 import java.util.Arrays; 17 import java.util.Arrays;
17 import java.util.HashMap; 18 import java.util.HashMap;
18 import java.util.List; 19 import java.util.List;
19 import java.util.Map; 20 import java.util.Map;
20 21
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
62 63
63 @Override 64 @Override
64 protected void tearDown() throws Exception { 65 protected void tearDown() throws Exception {
65 NativeTestServer.shutdownNativeTestServer(); 66 NativeTestServer.shutdownNativeTestServer();
66 super.tearDown(); 67 super.tearDown();
67 } 68 }
68 69
69 @SmallTest 70 @SmallTest
70 @Feature({"Cronet"}) 71 @Feature({"Cronet"})
71 @SuppressWarnings("deprecation") 72 @SuppressWarnings("deprecation")
73 @OnlyRunNativeCronet
72 public void testSdchEnabled_LegacyApi() throws Exception { 74 public void testSdchEnabled_LegacyApi() throws Exception {
73 setUp(Sdch.ENABLED, Api.LEGACY); 75 setUp(Sdch.ENABLED, Api.LEGACY);
74 String targetUrl = NativeTestServer.getSdchURL() + "/sdch/test"; 76 String targetUrl = NativeTestServer.getSdchURL() + "/sdch/test";
75 long contextAdapter = 77 long contextAdapter =
76 getContextAdapter((ChromiumUrlRequestFactory) mTestFramework.mRe questFactory); 78 getContextAdapter((ChromiumUrlRequestFactory) mTestFramework.mRe questFactory);
77 DictionaryAddedObserver observer = 79 DictionaryAddedObserver observer =
78 new DictionaryAddedObserver(targetUrl, contextAdapter, true /** Legacy Api */); 80 new DictionaryAddedObserver(targetUrl, contextAdapter, true /** Legacy Api */);
79 81
80 // Make a request to /sdch/index which advertises the dictionary. 82 // Make a request to /sdch/index which advertises the dictionary.
81 TestHttpUrlRequestListener listener1 = 83 TestHttpUrlRequestListener listener1 =
82 startAndWaitForComplete_LegacyApi(mTestFramework.mRequestFactory , 84 startAndWaitForComplete_LegacyApi(mTestFramework.mRequestFactory ,
83 NativeTestServer.getSdchURL() + "/sdch/index?q=LeQxM80O" ); 85 NativeTestServer.getSdchURL() + "/sdch/index?q=LeQxM80O" );
84 assertEquals(200, listener1.mHttpStatusCode); 86 assertEquals(200, listener1.mHttpStatusCode);
85 assertEquals("This is an index page.\n", listener1.mResponseAsString); 87 assertEquals("This is an index page.\n", listener1.mResponseAsString);
86 assertEquals(Arrays.asList("/sdch/dict/LeQxM80O"), 88 assertEquals(Arrays.asList("/sdch/dict/LeQxM80O"),
87 listener1.mResponseHeaders.get("Get-Dictionary")); 89 listener1.mResponseHeaders.get("Get-Dictionary"));
88 90
89 observer.waitForDictionaryAdded(); 91 observer.waitForDictionaryAdded();
90 92
91 // Make a request to fetch encoded response at /sdch/test. 93 // Make a request to fetch encoded response at /sdch/test.
92 TestHttpUrlRequestListener listener2 = 94 TestHttpUrlRequestListener listener2 =
93 startAndWaitForComplete_LegacyApi(mTestFramework.mRequestFactory , targetUrl); 95 startAndWaitForComplete_LegacyApi(mTestFramework.mRequestFactory , targetUrl);
94 assertEquals(200, listener2.mHttpStatusCode); 96 assertEquals(200, listener2.mHttpStatusCode);
95 assertEquals("The quick brown fox jumps over the lazy dog.\n", listener2 .mResponseAsString); 97 assertEquals("The quick brown fox jumps over the lazy dog.\n", listener2 .mResponseAsString);
96 } 98 }
97 99
98 @SmallTest 100 @SmallTest
99 @Feature({"Cronet"}) 101 @Feature({"Cronet"})
100 @SuppressWarnings("deprecation") 102 @SuppressWarnings("deprecation")
103 @OnlyRunNativeCronet
101 public void testSdchDisabled_LegacyApi() throws Exception { 104 public void testSdchDisabled_LegacyApi() throws Exception {
102 setUp(Sdch.DISABLED, Api.LEGACY); 105 setUp(Sdch.DISABLED, Api.LEGACY);
103 // Make a request to /sdch/index. 106 // Make a request to /sdch/index.
104 // Since Sdch is not enabled, no dictionary should be advertised. 107 // Since Sdch is not enabled, no dictionary should be advertised.
105 TestHttpUrlRequestListener listener = 108 TestHttpUrlRequestListener listener =
106 startAndWaitForComplete_LegacyApi(mTestFramework.mRequestFactory , 109 startAndWaitForComplete_LegacyApi(mTestFramework.mRequestFactory ,
107 NativeTestServer.getSdchURL() + "/sdch/index?q=LeQxM80O" ); 110 NativeTestServer.getSdchURL() + "/sdch/index?q=LeQxM80O" );
108 assertEquals(200, listener.mHttpStatusCode); 111 assertEquals(200, listener.mHttpStatusCode);
109 assertEquals("This is an index page.\n", listener.mResponseAsString); 112 assertEquals("This is an index page.\n", listener.mResponseAsString);
110 assertEquals(null, listener.mResponseHeaders.get("Get-Dictionary")); 113 assertEquals(null, listener.mResponseHeaders.get("Get-Dictionary"));
111 } 114 }
112 115
113 @SmallTest 116 @SmallTest
114 @Feature({"Cronet"}) 117 @Feature({"Cronet"})
115 @SuppressWarnings("deprecation") 118 @SuppressWarnings("deprecation")
119 @OnlyRunNativeCronet
116 public void testDictionaryNotFound_LegacyApi() throws Exception { 120 public void testDictionaryNotFound_LegacyApi() throws Exception {
117 setUp(Sdch.ENABLED, Api.LEGACY); 121 setUp(Sdch.ENABLED, Api.LEGACY);
118 // Make a request to /sdch/index which advertises a bad dictionary that 122 // Make a request to /sdch/index which advertises a bad dictionary that
119 // does not exist. 123 // does not exist.
120 TestHttpUrlRequestListener listener1 = 124 TestHttpUrlRequestListener listener1 =
121 startAndWaitForComplete_LegacyApi(mTestFramework.mRequestFactory , 125 startAndWaitForComplete_LegacyApi(mTestFramework.mRequestFactory ,
122 NativeTestServer.getSdchURL() + "/sdch/index?q=NotFound" ); 126 NativeTestServer.getSdchURL() + "/sdch/index?q=NotFound" );
123 assertEquals(200, listener1.mHttpStatusCode); 127 assertEquals(200, listener1.mHttpStatusCode);
124 assertEquals("This is an index page.\n", listener1.mResponseAsString); 128 assertEquals("This is an index page.\n", listener1.mResponseAsString);
125 assertEquals(Arrays.asList("/sdch/dict/NotFound"), 129 assertEquals(Arrays.asList("/sdch/dict/NotFound"),
126 listener1.mResponseHeaders.get("Get-Dictionary")); 130 listener1.mResponseHeaders.get("Get-Dictionary"));
127 131
128 // Make a request to fetch /sdch/test, and make sure request succeeds. 132 // Make a request to fetch /sdch/test, and make sure request succeeds.
129 TestHttpUrlRequestListener listener2 = startAndWaitForComplete_LegacyApi ( 133 TestHttpUrlRequestListener listener2 = startAndWaitForComplete_LegacyApi (
130 mTestFramework.mRequestFactory, NativeTestServer.getSdchURL() + "/sdch/test"); 134 mTestFramework.mRequestFactory, NativeTestServer.getSdchURL() + "/sdch/test");
131 assertEquals(200, listener2.mHttpStatusCode); 135 assertEquals(200, listener2.mHttpStatusCode);
132 assertEquals("Sdch is not used.\n", listener2.mResponseAsString); 136 assertEquals("Sdch is not used.\n", listener2.mResponseAsString);
133 } 137 }
134 138
135 @SmallTest 139 @SmallTest
136 @Feature({"Cronet"}) 140 @Feature({"Cronet"})
141 @OnlyRunNativeCronet
137 public void testSdchEnabled() throws Exception { 142 public void testSdchEnabled() throws Exception {
138 setUp(Sdch.ENABLED, Api.ASYNC); 143 setUp(Sdch.ENABLED, Api.ASYNC);
139 String targetUrl = NativeTestServer.getSdchURL() + "/sdch/test"; 144 String targetUrl = NativeTestServer.getSdchURL() + "/sdch/test";
140 long contextAdapter = 145 long contextAdapter =
141 getContextAdapter((CronetUrlRequestContext) mTestFramework.mCron etEngine); 146 getContextAdapter((CronetUrlRequestContext) mTestFramework.mCron etEngine);
142 DictionaryAddedObserver observer = 147 DictionaryAddedObserver observer =
143 new DictionaryAddedObserver(targetUrl, contextAdapter, false /** Legacy Api */); 148 new DictionaryAddedObserver(targetUrl, contextAdapter, false /** Legacy Api */);
144 149
145 // Make a request to /sdch which advertises the dictionary. 150 // Make a request to /sdch which advertises the dictionary.
146 TestUrlRequestCallback callback1 = startAndWaitForComplete(mTestFramewor k.mCronetEngine, 151 TestUrlRequestCallback callback1 = startAndWaitForComplete(mTestFramewor k.mCronetEngine,
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
180 newObserver.waitForDictionaryAdded(); 185 newObserver.waitForDictionaryAdded();
181 186
182 // Make a request to fetch encoded response at /sdch/test. 187 // Make a request to fetch encoded response at /sdch/test.
183 TestUrlRequestCallback callback3 = startAndWaitForComplete(newContext, t argetUrl); 188 TestUrlRequestCallback callback3 = startAndWaitForComplete(newContext, t argetUrl);
184 assertEquals(200, callback3.mResponseInfo.getHttpStatusCode()); 189 assertEquals(200, callback3.mResponseInfo.getHttpStatusCode());
185 assertEquals("The quick brown fox jumps over the lazy dog.\n", callback3 .mResponseAsString); 190 assertEquals("The quick brown fox jumps over the lazy dog.\n", callback3 .mResponseAsString);
186 } 191 }
187 192
188 @SmallTest 193 @SmallTest
189 @Feature({"Cronet"}) 194 @Feature({"Cronet"})
195 @OnlyRunNativeCronet
190 public void testSdchDisabled() throws Exception { 196 public void testSdchDisabled() throws Exception {
191 setUp(Sdch.DISABLED, Api.ASYNC); 197 setUp(Sdch.DISABLED, Api.ASYNC);
192 // Make a request to /sdch. 198 // Make a request to /sdch.
193 // Since Sdch is not enabled, no dictionary should be advertised. 199 // Since Sdch is not enabled, no dictionary should be advertised.
194 TestUrlRequestCallback callback = startAndWaitForComplete(mTestFramework .mCronetEngine, 200 TestUrlRequestCallback callback = startAndWaitForComplete(mTestFramework .mCronetEngine,
195 NativeTestServer.getSdchURL() + "/sdch/index?q=LeQxM80O"); 201 NativeTestServer.getSdchURL() + "/sdch/index?q=LeQxM80O");
196 assertEquals(200, callback.mResponseInfo.getHttpStatusCode()); 202 assertEquals(200, callback.mResponseInfo.getHttpStatusCode());
197 assertEquals("This is an index page.\n", callback.mResponseAsString); 203 assertEquals("This is an index page.\n", callback.mResponseAsString);
198 assertEquals(null, callback.mResponseInfo.getAllHeaders().get("Get-Dicti onary")); 204 assertEquals(null, callback.mResponseInfo.getAllHeaders().get("Get-Dicti onary"));
199 } 205 }
200 206
201 @SmallTest 207 @SmallTest
202 @Feature({"Cronet"}) 208 @Feature({"Cronet"})
209 @OnlyRunNativeCronet
203 public void testDictionaryNotFound() throws Exception { 210 public void testDictionaryNotFound() throws Exception {
204 setUp(Sdch.ENABLED, Api.ASYNC); 211 setUp(Sdch.ENABLED, Api.ASYNC);
205 // Make a request to /sdch/index which advertises a bad dictionary that 212 // Make a request to /sdch/index which advertises a bad dictionary that
206 // does not exist. 213 // does not exist.
207 TestUrlRequestCallback callback1 = startAndWaitForComplete(mTestFramewor k.mCronetEngine, 214 TestUrlRequestCallback callback1 = startAndWaitForComplete(mTestFramewor k.mCronetEngine,
208 NativeTestServer.getSdchURL() + "/sdch/index?q=NotFound"); 215 NativeTestServer.getSdchURL() + "/sdch/index?q=NotFound");
209 assertEquals(200, callback1.mResponseInfo.getHttpStatusCode()); 216 assertEquals(200, callback1.mResponseInfo.getHttpStatusCode());
210 assertEquals("This is an index page.\n", callback1.mResponseAsString); 217 assertEquals("This is an index page.\n", callback1.mResponseAsString);
211 assertEquals(Arrays.asList("/sdch/dict/NotFound"), 218 assertEquals(Arrays.asList("/sdch/dict/NotFound"),
212 callback1.mResponseInfo.getAllHeaders().get("Get-Dictionary")); 219 callback1.mResponseInfo.getAllHeaders().get("Get-Dictionary"));
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after
277 while ((line = reader.readLine()) != null) { 284 while ((line = reader.readLine()) != null) {
278 if (line.contains(content)) { 285 if (line.contains(content)) {
279 reader.close(); 286 reader.close();
280 return true; 287 return true;
281 } 288 }
282 } 289 }
283 reader.close(); 290 reader.close();
284 return false; 291 return false;
285 } 292 }
286 } 293 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698