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

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

Issue 996163005: [Cronet] Delay StartNetLog and StopNetLog until native request context is initialized (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Added DCHECKs Created 5 years, 8 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 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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.content.Context;
7 import android.content.ContextWrapper; 8 import android.content.ContextWrapper;
8 import android.os.ConditionVariable; 9 import android.os.ConditionVariable;
9 import android.os.Handler; 10 import android.os.Handler;
10 import android.os.Looper; 11 import android.os.Looper;
11 import android.test.suitebuilder.annotation.SmallTest; 12 import android.test.suitebuilder.annotation.SmallTest;
12 13
13 import org.chromium.base.PathUtils; 14 import org.chromium.base.PathUtils;
14 import org.chromium.base.test.util.Feature; 15 import org.chromium.base.test.util.Feature;
15 import org.chromium.net.TestUrlRequestListener.FailureType; 16 import org.chromium.net.TestUrlRequestListener.FailureType;
16 import org.chromium.net.TestUrlRequestListener.ResponseStep; 17 import org.chromium.net.TestUrlRequestListener.ResponseStep;
(...skipping 269 matching lines...) Expand 10 before | Expand all | Expand 10 after
286 // Cancel happens when listener returns. 287 // Cancel happens when listener returns.
287 listener.openBlockedStep(); 288 listener.openBlockedStep();
288 Thread.sleep(1000); 289 Thread.sleep(1000);
289 290
290 mActivity.mUrlRequestContext.shutdown(); 291 mActivity.mUrlRequestContext.shutdown();
291 } 292 }
292 293
293 @SmallTest 294 @SmallTest
294 @Feature({"Cronet"}) 295 @Feature({"Cronet"})
295 public void testNetLog() throws Exception { 296 public void testNetLog() throws Exception {
296 mActivity = launchCronetTestApp(); 297 Context context = getInstrumentation().getTargetContext();
297 File directory = new File(PathUtils.getDataDirectory( 298 File directory = new File(PathUtils.getDataDirectory(context));
298 getInstrumentation().getTargetContext()));
299 File file = File.createTempFile("cronet", "json", directory); 299 File file = File.createTempFile("cronet", "json", directory);
300 mActivity.mUrlRequestContext.startNetLogToFile(file.getPath()); 300 CronetUrlRequestContext requestContext = new CronetUrlRequestContext(
301 context,
302 new UrlRequestContextConfig().setLibraryName("cronet_tests"));
303 // Start NetLog immediately after the request context is created to make
304 // sure that the call won't crash the app even when the native request
305 // context is not fully initialized. See crbug.com/470196.
306 requestContext.startNetLogToFile(file.getPath());
307
301 // Start a request. 308 // Start a request.
302 TestUrlRequestListener listener = new TestUrlRequestListener(); 309 TestUrlRequestListener listener = new TestUrlRequestListener();
303 UrlRequest urlRequest = mActivity.mUrlRequestContext.createRequest( 310 UrlRequest request = requestContext.createRequest(
304 TEST_URL, listener, listener.getExecutor()); 311 TEST_URL, listener, listener.getExecutor());
305 urlRequest.start(); 312 request.start();
306 listener.blockForDone(); 313 listener.blockForDone();
307 mActivity.mUrlRequestContext.stopNetLog(); 314 requestContext.stopNetLog();
308 assertTrue(file.exists()); 315 assertTrue(file.exists());
309 assertTrue(file.length() != 0); 316 assertTrue(file.length() != 0);
310 assertTrue(file.delete()); 317 assertTrue(file.delete());
311 assertTrue(!file.exists()); 318 assertTrue(!file.exists());
312 } 319 }
313 320
314 @SmallTest 321 @SmallTest
315 @Feature({"Cronet"}) 322 @Feature({"Cronet"})
316 public void testNetLogAfterShutdown() throws Exception { 323 public void testNetLogAfterShutdown() throws Exception {
317 mActivity = launchCronetTestApp(); 324 mActivity = launchCronetTestApp();
(...skipping 288 matching lines...) Expand 10 before | Expand all | Expand 10 after
606 new CronetUrlRequestContext(mActivity, mActivity.getContextConfi g()); 613 new CronetUrlRequestContext(mActivity, mActivity.getContextConfi g());
607 CronetUrlRequestContext secondContext = new CronetUrlRequestContext( 614 CronetUrlRequestContext secondContext = new CronetUrlRequestContext(
608 mActivity.getApplicationContext(), mActivity.getContextConfig()) ; 615 mActivity.getApplicationContext(), mActivity.getContextConfig()) ;
609 CronetUrlRequestContext thirdContext = new CronetUrlRequestContext( 616 CronetUrlRequestContext thirdContext = new CronetUrlRequestContext(
610 new ContextWrapper(mActivity), mActivity.getContextConfig()); 617 new ContextWrapper(mActivity), mActivity.getContextConfig());
611 firstContext.shutdown(); 618 firstContext.shutdown();
612 secondContext.shutdown(); 619 secondContext.shutdown();
613 thirdContext.shutdown(); 620 thirdContext.shutdown();
614 } 621 }
615 } 622 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698