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

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

Issue 937513003: Add Data Saver support to Cronet (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Addressed nit Created 5 years, 7 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.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 87 matching lines...) Expand 10 before | Expand all | Expand 10 after
98 UrlRequest urlRequest = mActivity.mUrlRequestContext.createRequest( 98 UrlRequest urlRequest = mActivity.mUrlRequestContext.createRequest(
99 NativeTestServer.getEchoHeaderURL(userAgentName), listener, 99 NativeTestServer.getEchoHeaderURL(userAgentName), listener,
100 listener.getExecutor()); 100 listener.getExecutor());
101 urlRequest.start(); 101 urlRequest.start();
102 listener.blockForDone(); 102 listener.blockForDone();
103 assertEquals(userAgentValue, listener.mResponseAsString); 103 assertEquals(userAgentValue, listener.mResponseAsString);
104 } 104 }
105 105
106 @SmallTest 106 @SmallTest
107 @Feature({"Cronet"}) 107 @Feature({"Cronet"})
108 public void testDataReductionProxyEnabled() throws Exception {
109 mActivity = launchCronetTestAppAndSkipFactoryInit();
110
111 // Ensure native code is loaded before trying to start test server.
112 UrlRequestContext.createContext(
113 getInstrumentation().getTargetContext(),
114 new UrlRequestContextConfig().setLibraryName("cronet_tests"))
115 .shutdown();
116
117 assertTrue(NativeTestServer.startNativeTestServer(
118 getInstrumentation().getTargetContext()));
119
120 String serverHostPort = NativeTestServer.getHostPort();
121
122 // Enable the Data Reduction Proxy and configure it to use the test
123 // server as its primary proxy, and to check successfully that this
124 // proxy is OK to use.
125 UrlRequestContextConfig config = new UrlRequestContextConfig();
126 config.enableDataReductionProxy("test-key");
127 config.setDataReductionProxyOptions(
128 serverHostPort, "unused.net:9999",
129 NativeTestServer.getFileURL("/secureproxychecksuccess.txt"));
130 config.setLibraryName("cronet_tests");
131 mActivity.mUrlRequestContext =
132 mActivity.mUrlRequestContext.createContext(
133 getInstrumentation().getTargetContext(), config);
134 TestUrlRequestListener listener = new TestUrlRequestListener();
135
136 // Construct and start a request that can only be returned by the test
137 // server. This request will fail if the configuration logic for the
138 // Data Reduction Proxy is not used.
139 UrlRequest urlRequest = mActivity.mUrlRequestContext.createRequest(
140 "http://google.com/datareductionproxysuccess.txt",
141 listener, listener.getExecutor());
142 urlRequest.start();
143 listener.blockForDone();
144
145 // Verify that the request is successful and that the Data Reduction
146 // Proxy logic configured to use the test server as its proxy.
147 assertEquals(200, listener.mResponseInfo.getHttpStatusCode());
148 assertEquals(serverHostPort, listener.mResponseInfo.getProxyServer());
149 assertEquals("http://www.google.com/datareductionproxysuccess.txt",
150 listener.mResponseInfo.getUrl());
151 }
152
153 @SmallTest
154 @Feature({"Cronet"})
108 public void testShutdown() throws Exception { 155 public void testShutdown() throws Exception {
109 mActivity = launchCronetTestApp(); 156 mActivity = launchCronetTestApp();
110 TestUrlRequestListener listener = new ShutdownTestUrlRequestListener(); 157 TestUrlRequestListener listener = new ShutdownTestUrlRequestListener();
111 // Block listener when response starts to verify that shutdown fails 158 // Block listener when response starts to verify that shutdown fails
112 // if there are active requests. 159 // if there are active requests.
113 listener.setAutoAdvance(false); 160 listener.setAutoAdvance(false);
114 UrlRequest urlRequest = mActivity.mUrlRequestContext.createRequest( 161 UrlRequest urlRequest = mActivity.mUrlRequestContext.createRequest(
115 TEST_URL, listener, listener.getExecutor()); 162 TEST_URL, listener, listener.getExecutor());
116 urlRequest.start(); 163 urlRequest.start();
117 try { 164 try {
(...skipping 502 matching lines...) Expand 10 before | Expand all | Expand 10 after
620 new CronetUrlRequestContext(mActivity, mActivity.getContextConfi g()); 667 new CronetUrlRequestContext(mActivity, mActivity.getContextConfi g());
621 CronetUrlRequestContext secondContext = new CronetUrlRequestContext( 668 CronetUrlRequestContext secondContext = new CronetUrlRequestContext(
622 mActivity.getApplicationContext(), mActivity.getContextConfig()) ; 669 mActivity.getApplicationContext(), mActivity.getContextConfig()) ;
623 CronetUrlRequestContext thirdContext = new CronetUrlRequestContext( 670 CronetUrlRequestContext thirdContext = new CronetUrlRequestContext(
624 new ContextWrapper(mActivity), mActivity.getContextConfig()); 671 new ContextWrapper(mActivity), mActivity.getContextConfig());
625 firstContext.shutdown(); 672 firstContext.shutdown();
626 secondContext.shutdown(); 673 secondContext.shutdown();
627 thirdContext.shutdown(); 674 thirdContext.shutdown();
628 } 675 }
629 } 676 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698