OLD | NEW |
---|---|
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.content.ContextWrapper; |
8 import android.os.ConditionVariable; | 8 import android.os.ConditionVariable; |
9 import android.os.Handler; | 9 import android.os.Handler; |
10 import android.os.Looper; | 10 import android.os.Looper; |
(...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
115 UrlRequest urlRequest = mActivity.mUrlRequestContext.createRequest( | 115 UrlRequest urlRequest = mActivity.mUrlRequestContext.createRequest( |
116 NativeTestServer.getEchoHeaderURL(userAgentName), listener, | 116 NativeTestServer.getEchoHeaderURL(userAgentName), listener, |
117 listener.getExecutor()); | 117 listener.getExecutor()); |
118 urlRequest.start(); | 118 urlRequest.start(); |
119 listener.blockForDone(); | 119 listener.blockForDone(); |
120 assertEquals(userAgentValue, listener.mResponseAsString); | 120 assertEquals(userAgentValue, listener.mResponseAsString); |
121 } | 121 } |
122 | 122 |
123 @SmallTest | 123 @SmallTest |
124 @Feature({"Cronet"}) | 124 @Feature({"Cronet"}) |
125 public void testDataReductionProxyEnabled() throws Exception { | |
126 UrlRequestContextConfig config = new UrlRequestContextConfig(); | |
127 config.enableDataReductionProxy(false, "test-key"); | |
128 config.setLibraryName("cronet_tests"); | |
129 String[] commandLineArgs = { | |
130 CronetTestActivity.CONFIG_KEY, config.toString() | |
131 }; | |
132 mActivity = launchCronetTestAppWithUrlAndCommandLineArgs(null, | |
133 commandLineArgs); | |
134 assertTrue(NativeTestServer.startNativeTestServer( | |
135 getInstrumentation().getTargetContext())); | |
136 | |
137 String serverHostPort = "127.0.0.1:" + NativeTestServer.getPort(); | |
mmenke
2015/04/01 16:48:53
Can we just use getHostPortPair instead of getPort
bengr
2015/04/24 02:30:43
NativeTestServer doesn't hold onto the host.
mmenke
2015/04/24 15:54:59
It does. That's how the other NativeTestServer me
bengr
2015/04/24 21:13:50
Done.
| |
138 // Shutdown the original context and create a new context that uses the | |
139 // NativeTestServer as the data reduction proxy. | |
140 mActivity.mUrlRequestContext.shutdown(); | |
mmenke
2015/04/01 16:48:53
Why can't we just start the test server first, and
bengr
2015/04/24 02:30:43
This was a chicken and egg problem. The server nee
mmenke
2015/04/24 15:54:59
See skipFactoryInitInOnCreate.
| |
141 UrlRequestContextConfig config2 = new UrlRequestContextConfig(); | |
142 config2.enableDataReductionProxy(true, "test-key"); | |
143 config2.setDataReductionProxyOptions( | |
144 serverHostPort + "," | |
145 + "unused.net:9999" + "," | |
146 + NativeTestServer.getFileURL("/secureproxychecksuccess.txt")); | |
147 config2.setLibraryName("cronet_tests"); | |
148 mActivity.mUrlRequestContext = | |
149 mActivity.mUrlRequestContext.createContext( | |
150 getInstrumentation().getTargetContext(), config2); | |
151 TestUrlRequestListener listener = new TestUrlRequestListener(); | |
152 UrlRequest urlRequest = mActivity.mUrlRequestContext.createRequest( | |
153 "http://google.com/datareductionproxysuccess.txt", | |
154 listener, listener.getExecutor()); | |
155 | |
156 urlRequest.start(); | |
157 listener.blockForDone(); | |
158 assertEquals(200, listener.mResponseInfo.getHttpStatusCode()); | |
159 assertEquals(serverHostPort, listener.mResponseInfo.getProxyServer()); | |
mmenke
2015/04/01 16:48:53
Should we check that the other parameters work as
mmenke
2015/04/01 16:48:53
Check the URL as well? (http://google.com/datared
bengr
2015/04/24 02:30:43
What other parameters? The race doesn't matter. Th
bengr
2015/04/24 02:30:43
Done.
mmenke
2015/04/24 15:54:59
Other parameters -> The second proxy and the proxy
bengr
2015/04/24 21:13:50
These aren't exposed easily. setDataReductionProxy
| |
160 } | |
161 | |
162 @SmallTest | |
163 @Feature({"Cronet"}) | |
125 public void testShutdown() throws Exception { | 164 public void testShutdown() throws Exception { |
126 mActivity = launchCronetTestApp(); | 165 mActivity = launchCronetTestApp(); |
127 TestUrlRequestListener listener = new ShutdownTestUrlRequestListener(); | 166 TestUrlRequestListener listener = new ShutdownTestUrlRequestListener(); |
128 // Block listener when response starts to verify that shutdown fails | 167 // Block listener when response starts to verify that shutdown fails |
129 // if there are active requests. | 168 // if there are active requests. |
130 listener.setFailure(FailureType.BLOCK, | 169 listener.setFailure(FailureType.BLOCK, |
131 ResponseStep.ON_RESPONSE_STARTED); | 170 ResponseStep.ON_RESPONSE_STARTED); |
132 UrlRequest urlRequest = mActivity.mUrlRequestContext.createRequest( | 171 UrlRequest urlRequest = mActivity.mUrlRequestContext.createRequest( |
133 TEST_URL, listener, listener.getExecutor()); | 172 TEST_URL, listener, listener.getExecutor()); |
134 urlRequest.start(); | 173 urlRequest.start(); |
(...skipping 471 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
606 new CronetUrlRequestContext(mActivity, mActivity.getContextConfi g()); | 645 new CronetUrlRequestContext(mActivity, mActivity.getContextConfi g()); |
607 CronetUrlRequestContext secondContext = new CronetUrlRequestContext( | 646 CronetUrlRequestContext secondContext = new CronetUrlRequestContext( |
608 mActivity.getApplicationContext(), mActivity.getContextConfig()) ; | 647 mActivity.getApplicationContext(), mActivity.getContextConfig()) ; |
609 CronetUrlRequestContext thirdContext = new CronetUrlRequestContext( | 648 CronetUrlRequestContext thirdContext = new CronetUrlRequestContext( |
610 new ContextWrapper(mActivity), mActivity.getContextConfig()); | 649 new ContextWrapper(mActivity), mActivity.getContextConfig()); |
611 firstContext.shutdown(); | 650 firstContext.shutdown(); |
612 secondContext.shutdown(); | 651 secondContext.shutdown(); |
613 thirdContext.shutdown(); | 652 thirdContext.shutdown(); |
614 } | 653 } |
615 } | 654 } |
OLD | NEW |