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

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

Issue 1503943003: [Cronet] Unit test refactoring and fixes (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Removed changes related to CronetHttpURLConnection tests 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;
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
48 commandLineArgs.add(CronetTestFramework.LIBRARY_INIT_KEY); 48 commandLineArgs.add(CronetTestFramework.LIBRARY_INIT_KEY);
49 commandLineArgs.add(CronetTestFramework.LibraryInitType.LEGACY); 49 commandLineArgs.add(CronetTestFramework.LibraryInitType.LEGACY);
50 } else { 50 } else {
51 commandLineArgs.add(CronetTestFramework.LIBRARY_INIT_KEY); 51 commandLineArgs.add(CronetTestFramework.LIBRARY_INIT_KEY);
52 commandLineArgs.add(CronetTestFramework.LibraryInitType.CRONET); 52 commandLineArgs.add(CronetTestFramework.LibraryInitType.CRONET);
53 } 53 }
54 54
55 String[] args = new String[commandLineArgs.size()]; 55 String[] args = new String[commandLineArgs.size()];
56 mTestFramework = startCronetTestFrameworkWithUrlAndCommandLineArgs( 56 mTestFramework = startCronetTestFrameworkWithUrlAndCommandLineArgs(
57 null, commandLineArgs.toArray(args)); 57 null, commandLineArgs.toArray(args));
58 long urlRequestContextAdapter = (api == Api.LEGACY) 58 registerHostResolver(mTestFramework, api == Api.LEGACY);
59 ? getContextAdapter((ChromiumUrlRequestFactory) mTestFramework.m RequestFactory)
60 : getContextAdapter((CronetUrlRequestContext) mTestFramework.mCr onetEngine);
61 NativeTestServer.registerHostResolverProc(urlRequestContextAdapter, api == Api.LEGACY);
62 // Start NativeTestServer. 59 // Start NativeTestServer.
63 assertTrue(NativeTestServer.startNativeTestServer(getContext())); 60 assertTrue(NativeTestServer.startNativeTestServer(getContext()));
64 } 61 }
65 62
66 @Override 63 @Override
67 protected void tearDown() throws Exception { 64 protected void tearDown() throws Exception {
68 NativeTestServer.shutdownNativeTestServer(); 65 NativeTestServer.shutdownNativeTestServer();
69 super.tearDown(); 66 super.tearDown();
70 } 67 }
71 68
(...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after
166 // TODO(xunjieli): Remove once crbug.com/486120 is fixed. 163 // TODO(xunjieli): Remove once crbug.com/486120 is fixed.
167 Thread.sleep(5000); 164 Thread.sleep(5000);
168 mTestFramework.mCronetEngine.shutdown(); 165 mTestFramework.mCronetEngine.shutdown();
169 166
170 // Shutting down the context will make JsonPrefStore to flush pending 167 // Shutting down the context will make JsonPrefStore to flush pending
171 // writes to disk. 168 // writes to disk.
172 String dictUrl = NativeTestServer.getSdchURL() + "/sdch/dict/LeQxM80O"; 169 String dictUrl = NativeTestServer.getSdchURL() + "/sdch/dict/LeQxM80O";
173 assertTrue(fileContainsString("local_prefs.json", dictUrl)); 170 assertTrue(fileContainsString("local_prefs.json", dictUrl));
174 171
175 // Test persistence. 172 // Test persistence.
176 CronetUrlRequestContext newContext = 173 mTestFramework = startCronetTestFrameworkWithUrlAndCronetEngineBuilder(
177 new CronetUrlRequestContext(mTestFramework.getCronetEngineBuilde r()); 174 null, mTestFramework.getCronetEngineBuilder());
178 175 CronetUrlRequestContext newContext = (CronetUrlRequestContext) mTestFram ework.mCronetEngine;
179 long newContextAdapter = getContextAdapter(newContext); 176 long newContextAdapter = getContextAdapter(newContext);
180 NativeTestServer.registerHostResolverProc(newContextAdapter, false); 177 registerHostResolver(mTestFramework);
181 DictionaryAddedObserver newObserver = 178 DictionaryAddedObserver newObserver =
182 new DictionaryAddedObserver(targetUrl, newContextAdapter, false /** Legacy Api */); 179 new DictionaryAddedObserver(targetUrl, newContextAdapter, false /** Legacy Api */);
183 newObserver.waitForDictionaryAdded(); 180 newObserver.waitForDictionaryAdded();
184 181
185 // Make a request to fetch encoded response at /sdch/test. 182 // Make a request to fetch encoded response at /sdch/test.
186 TestUrlRequestCallback callback3 = startAndWaitForComplete(newContext, t argetUrl); 183 TestUrlRequestCallback callback3 = startAndWaitForComplete(newContext, t argetUrl);
187 assertEquals(200, callback3.mResponseInfo.getHttpStatusCode()); 184 assertEquals(200, callback3.mResponseInfo.getHttpStatusCode());
188 assertEquals("The quick brown fox jumps over the lazy dog.\n", callback3 .mResponseAsString); 185 assertEquals("The quick brown fox jumps over the lazy dog.\n", callback3 .mResponseAsString);
189 } 186 }
190 187
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after
280 while ((line = reader.readLine()) != null) { 277 while ((line = reader.readLine()) != null) {
281 if (line.contains(content)) { 278 if (line.contains(content)) {
282 reader.close(); 279 reader.close();
283 return true; 280 return true;
284 } 281 }
285 } 282 }
286 reader.close(); 283 reader.close();
287 return false; 284 return false;
288 } 285 }
289 } 286 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698