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.Context; | 7 import android.content.Context; |
8 import android.content.ContextWrapper; | 8 import android.content.ContextWrapper; |
9 import android.os.ConditionVariable; | 9 import android.os.ConditionVariable; |
10 import android.os.Handler; | 10 import android.os.Handler; |
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
96 UrlRequest urlRequest = mActivity.mUrlRequestContext.createRequest( | 96 UrlRequest urlRequest = mActivity.mUrlRequestContext.createRequest( |
97 NativeTestServer.getEchoHeaderURL(userAgentName), listener, | 97 NativeTestServer.getEchoHeaderURL(userAgentName), listener, |
98 listener.getExecutor()); | 98 listener.getExecutor()); |
99 urlRequest.start(); | 99 urlRequest.start(); |
100 listener.blockForDone(); | 100 listener.blockForDone(); |
101 assertEquals(userAgentValue, listener.mResponseAsString); | 101 assertEquals(userAgentValue, listener.mResponseAsString); |
102 } | 102 } |
103 | 103 |
104 @SmallTest | 104 @SmallTest |
105 @Feature({"Cronet"}) | 105 @Feature({"Cronet"}) |
106 public void testDataReductionProxyEnabled() throws Exception { | |
107 UrlRequestContextConfig config = new UrlRequestContextConfig(); | |
108 config.setLibraryName("cronet_tests"); | |
109 String[] commandLineArgs = { | |
110 CronetTestActivity.CONFIG_KEY, config.toString() | |
111 }; | |
112 mActivity = launchCronetTestAppWithUrlAndCommandLineArgs(null, | |
113 commandLineArgs); | |
mmenke
2015/05/07 20:22:18
Can you just do something like:
// Ensure native
bengr
2015/05/08 22:41:02
Done.
| |
114 assertTrue(NativeTestServer.startNativeTestServer( | |
115 getInstrumentation().getTargetContext())); | |
116 | |
117 String serverHostPort = NativeTestServer.getHostPort(); | |
118 // Shutdown the original context and create a new context that uses the | |
119 // NativeTestServer as the data reduction proxy. | |
120 mActivity.mUrlRequestContext.shutdown(); | |
121 UrlRequestContextConfig config2 = new UrlRequestContextConfig(); | |
122 config2.enableDataReductionProxy("test-key"); | |
123 config2.setDataReductionProxyOptions( | |
124 serverHostPort, "unused.net:9999", | |
125 NativeTestServer.getFileURL("/secureproxychecksuccess.txt")); | |
126 config2.setLibraryName("cronet_tests"); | |
127 mActivity.mUrlRequestContext = | |
128 mActivity.mUrlRequestContext.createContext( | |
129 getInstrumentation().getTargetContext(), config2); | |
130 TestUrlRequestListener listener = new TestUrlRequestListener(); | |
131 UrlRequest urlRequest = mActivity.mUrlRequestContext.createRequest( | |
132 "http://google.com/datareductionproxysuccess.txt", | |
133 listener, listener.getExecutor()); | |
134 | |
135 urlRequest.start(); | |
136 listener.blockForDone(); | |
137 assertEquals(200, listener.mResponseInfo.getHttpStatusCode()); | |
138 assertEquals(serverHostPort, listener.mResponseInfo.getProxyServer()); | |
139 assertEquals("http://www.google.com/datareductionproxysuccess.txt", | |
140 listener.mResponseInfo.getUrl()); | |
mmenke
2015/05/07 20:22:18
Also think it's worth an explanation of just what
bengr
2015/05/08 22:41:02
Done.
| |
141 } | |
142 | |
143 @SmallTest | |
144 @Feature({"Cronet"}) | |
106 public void testShutdown() throws Exception { | 145 public void testShutdown() throws Exception { |
107 mActivity = launchCronetTestApp(); | 146 mActivity = launchCronetTestApp(); |
108 TestUrlRequestListener listener = new ShutdownTestUrlRequestListener(); | 147 TestUrlRequestListener listener = new ShutdownTestUrlRequestListener(); |
109 // Block listener when response starts to verify that shutdown fails | 148 // Block listener when response starts to verify that shutdown fails |
110 // if there are active requests. | 149 // if there are active requests. |
111 listener.setAutoAdvance(false); | 150 listener.setAutoAdvance(false); |
112 UrlRequest urlRequest = mActivity.mUrlRequestContext.createRequest( | 151 UrlRequest urlRequest = mActivity.mUrlRequestContext.createRequest( |
113 TEST_URL, listener, listener.getExecutor()); | 152 TEST_URL, listener, listener.getExecutor()); |
114 urlRequest.start(); | 153 urlRequest.start(); |
115 try { | 154 try { |
(...skipping 471 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
587 new CronetUrlRequestContext(mActivity, mActivity.getContextConfi g()); | 626 new CronetUrlRequestContext(mActivity, mActivity.getContextConfi g()); |
588 CronetUrlRequestContext secondContext = new CronetUrlRequestContext( | 627 CronetUrlRequestContext secondContext = new CronetUrlRequestContext( |
589 mActivity.getApplicationContext(), mActivity.getContextConfig()) ; | 628 mActivity.getApplicationContext(), mActivity.getContextConfig()) ; |
590 CronetUrlRequestContext thirdContext = new CronetUrlRequestContext( | 629 CronetUrlRequestContext thirdContext = new CronetUrlRequestContext( |
591 new ContextWrapper(mActivity), mActivity.getContextConfig()); | 630 new ContextWrapper(mActivity), mActivity.getContextConfig()); |
592 firstContext.shutdown(); | 631 firstContext.shutdown(); |
593 secondContext.shutdown(); | 632 secondContext.shutdown(); |
594 thirdContext.shutdown(); | 633 thirdContext.shutdown(); |
595 } | 634 } |
596 } | 635 } |
OLD | NEW |