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

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

Issue 981013002: [Cronet] Make sure to only pass the application Context to InitApplicationContext to avoid DCHECK fa (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 9 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.ContextWrapper;
7 import android.os.ConditionVariable; 8 import android.os.ConditionVariable;
8 import android.os.Handler; 9 import android.os.Handler;
9 import android.os.Looper; 10 import android.os.Looper;
10 import android.test.suitebuilder.annotation.SmallTest; 11 import android.test.suitebuilder.annotation.SmallTest;
11 12
12 import org.chromium.base.PathUtils; 13 import org.chromium.base.PathUtils;
13 import org.chromium.base.test.util.Feature; 14 import org.chromium.base.test.util.Feature;
14 import org.chromium.net.TestUrlRequestListener.FailureType; 15 import org.chromium.net.TestUrlRequestListener.FailureType;
15 import org.chromium.net.TestUrlRequestListener.ResponseStep; 16 import org.chromium.net.TestUrlRequestListener.ResponseStep;
16 17
(...skipping 494 matching lines...) Expand 10 before | Expand all | Expand 10 after
511 assertTrue(NativeTestServer.startNativeTestServer( 512 assertTrue(NativeTestServer.startNativeTestServer(
512 getInstrumentation().getTargetContext())); 513 getInstrumentation().getTargetContext()));
513 String url = NativeTestServer.getFileURL("/cacheable.txt"); 514 String url = NativeTestServer.getFileURL("/cacheable.txt");
514 checkRequestCaching(url, false); 515 checkRequestCaching(url, false);
515 checkRequestCaching(url, true); 516 checkRequestCaching(url, true);
516 NativeTestServer.shutdownNativeTestServer(); 517 NativeTestServer.shutdownNativeTestServer();
517 checkRequestCaching(url, true); 518 checkRequestCaching(url, true);
518 // Shutdown original context and create another that uses the same cache . 519 // Shutdown original context and create another that uses the same cache .
519 mActivity.mUrlRequestContext.shutdown(); 520 mActivity.mUrlRequestContext.shutdown();
520 mActivity.mUrlRequestContext = mActivity.mUrlRequestContext.createContex t( 521 mActivity.mUrlRequestContext = mActivity.mUrlRequestContext.createContex t(
521 getInstrumentation().getTargetContext().getApplicationContext(), 522 getInstrumentation().getTargetContext(), config);
522 config);
523 checkRequestCaching(url, true); 523 checkRequestCaching(url, true);
524 } 524 }
525 525
526 @SmallTest 526 @SmallTest
527 @Feature({"Cronet"}) 527 @Feature({"Cronet"})
528 public void testInitContextAndStartRequest() { 528 public void testInitContextAndStartRequest() {
529 CronetTestActivity activity = skipFactoryInitInOnCreate(); 529 CronetTestActivity activity = skipFactoryInitInOnCreate();
530 530
531 // Immediately make a request after initializing the context. 531 // Immediately make a request after initializing the context.
532 UrlRequestContext requestContext = activity.initRequestContext(); 532 UrlRequestContext requestContext = activity.initRequestContext();
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after
587 RequestThread thread1 = new RequestThread(activity, TEST_URL, runBlocker ); 587 RequestThread thread1 = new RequestThread(activity, TEST_URL, runBlocker );
588 RequestThread thread2 = new RequestThread(activity, URL_404, runBlocker) ; 588 RequestThread thread2 = new RequestThread(activity, URL_404, runBlocker) ;
589 589
590 thread1.start(); 590 thread1.start();
591 thread1.join(); 591 thread1.join();
592 thread2.start(); 592 thread2.start();
593 thread2.join(); 593 thread2.join();
594 assertEquals(200, thread1.mListener.mResponseInfo.getHttpStatusCode()); 594 assertEquals(200, thread1.mListener.mResponseInfo.getHttpStatusCode());
595 assertEquals(404, thread2.mListener.mResponseInfo.getHttpStatusCode()); 595 assertEquals(404, thread2.mListener.mResponseInfo.getHttpStatusCode());
596 } 596 }
597
598 @SmallTest
599 @Feature({"Cronet"})
600 public void testInitDifferentContexts() throws Exception {
xunjieli 2015/03/06 14:50:31 Btw, should we test creating multiple ChromiumUrlR
pauljensen 2015/03/06 17:01:53 Done.
601 // Test that concurrently instantiating Cronet context's upon various
602 // different versions of the same Android Context does not cause crashes
603 // like crbug.com/453845
604 mActivity = launchCronetTestApp();
605 CronetUrlRequestContext firstContext =
606 new CronetUrlRequestContext(mActivity, new UrlRequestContextConf ig());
607 CronetUrlRequestContext secondContext = new CronetUrlRequestContext(
608 mActivity.getApplicationContext(), new UrlRequestContextConfig() );
mmenke 2015/03/06 16:52:23 Shouldn't you just be passing in the mActivity her
pauljensen 2015/03/06 16:57:28 That's what I do on the previous line. I'm trying
609 CronetUrlRequestContext thirdContext = new CronetUrlRequestContext(
610 new ContextWrapper(mActivity), new UrlRequestContextConfig());
611 firstContext.shutdown();
612 secondContext.shutdown();
613 thirdContext.shutdown();
614 }
597 } 615 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698