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

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 comments 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.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
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.enableDataReductionProxy(false, "test-key");
109 config.setLibraryName("cronet_tests");
110 String[] commandLineArgs = {
111 CronetTestActivity.CONFIG_KEY, config.toString()
112 };
113 mActivity = launchCronetTestAppWithUrlAndCommandLineArgs(null,
114 commandLineArgs);
115 assertTrue(NativeTestServer.startNativeTestServer(
116 getInstrumentation().getTargetContext()));
117
118 String serverHostPort = "127.0.0.1:" + NativeTestServer.getPort();
119 // Shutdown the original context and create a new context that uses the
120 // NativeTestServer as the data reduction proxy.
121 mActivity.mUrlRequestContext.shutdown();
122 UrlRequestContextConfig config2 = new UrlRequestContextConfig();
123 config2.enableDataReductionProxy(true, "test-key");
124 config2.setDataReductionProxyOptions(
125 serverHostPort, "unused.net:9999",
126 NativeTestServer.getFileURL("/secureproxychecksuccess.txt"));
127 config2.setLibraryName("cronet_tests");
128 mActivity.mUrlRequestContext =
129 mActivity.mUrlRequestContext.createContext(
130 getInstrumentation().getTargetContext(), config2);
131 TestUrlRequestListener listener = new TestUrlRequestListener();
132 UrlRequest urlRequest = mActivity.mUrlRequestContext.createRequest(
133 "http://google.com/datareductionproxysuccess.txt",
134 listener, listener.getExecutor());
135
136 urlRequest.start();
137 listener.blockForDone();
138 assertEquals(200, listener.mResponseInfo.getHttpStatusCode());
139 assertEquals(serverHostPort, listener.mResponseInfo.getProxyServer());
140 assertEquals("http://www.google.com/datareductionproxysuccess.txt",
141 listener.mResponseInfo.getUrl());
142 }
143
144 @SmallTest
145 @Feature({"Cronet"})
106 public void testShutdown() throws Exception { 146 public void testShutdown() throws Exception {
107 mActivity = launchCronetTestApp(); 147 mActivity = launchCronetTestApp();
108 TestUrlRequestListener listener = new ShutdownTestUrlRequestListener(); 148 TestUrlRequestListener listener = new ShutdownTestUrlRequestListener();
109 // Block listener when response starts to verify that shutdown fails 149 // Block listener when response starts to verify that shutdown fails
110 // if there are active requests. 150 // if there are active requests.
111 listener.setAutoAdvance(false); 151 listener.setAutoAdvance(false);
112 UrlRequest urlRequest = mActivity.mUrlRequestContext.createRequest( 152 UrlRequest urlRequest = mActivity.mUrlRequestContext.createRequest(
113 TEST_URL, listener, listener.getExecutor()); 153 TEST_URL, listener, listener.getExecutor());
114 urlRequest.start(); 154 urlRequest.start();
115 try { 155 try {
(...skipping 471 matching lines...) Expand 10 before | Expand all | Expand 10 after
587 new CronetUrlRequestContext(mActivity, mActivity.getContextConfi g()); 627 new CronetUrlRequestContext(mActivity, mActivity.getContextConfi g());
588 CronetUrlRequestContext secondContext = new CronetUrlRequestContext( 628 CronetUrlRequestContext secondContext = new CronetUrlRequestContext(
589 mActivity.getApplicationContext(), mActivity.getContextConfig()) ; 629 mActivity.getApplicationContext(), mActivity.getContextConfig()) ;
590 CronetUrlRequestContext thirdContext = new CronetUrlRequestContext( 630 CronetUrlRequestContext thirdContext = new CronetUrlRequestContext(
591 new ContextWrapper(mActivity), mActivity.getContextConfig()); 631 new ContextWrapper(mActivity), mActivity.getContextConfig());
592 firstContext.shutdown(); 632 firstContext.shutdown();
593 secondContext.shutdown(); 633 secondContext.shutdown();
594 thirdContext.shutdown(); 634 thirdContext.shutdown();
595 } 635 }
596 } 636 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698