@SmallTest @Feature({"Cronet"}) public void testDataReductionProxyEnabled() throws Exception { mActivity = launchCronetTestAppAndSkipFactoryInit(); // Ensure native code is loaded before trying to start test server. new CronetEngine.Builder(getInstrumentation().getTargetContext()) .setLibraryName("cronet_tests") .build() .shutdown(); assertTrue(NativeTestServer.startNativeTestServer(getInstrumentation().getTargetContext())); if (!NativeTestServer.isDataReductionProxySupported()) { return; } String serverHostPort = NativeTestServer.getHostPort(); // Enable the Data Reduction Proxy and configure it to use the test // server as its primary proxy, and to check successfully that this // proxy is OK to use. CronetEngine.Builder cronetEngineBuilder = new CronetEngine.Builder(getInstrumentation().getTargetContext()); cronetEngineBuilder.enableDataReductionProxy("test-key"); cronetEngineBuilder.setDataReductionProxyOptions( serverHostPort, "unused.net:9999", NativeTestServer.getFileURL("/secureproxychecksuccess.txt")); cronetEngineBuilder.setLibraryName("cronet_tests"); mActivity.mCronetEngine = cronetEngineBuilder.build(); TestUrlRequestListener listener = new TestUrlRequestListener(); // Construct and start a request that can only be returned by the test // server. This request will fail if the configuration logic for the // Data Reduction Proxy is not used. UrlRequest.Builder urlRequestBuilder = new UrlRequest.Builder( "http://DomainThatDoesnt.Resolve/datareductionproxysuccess.txt", listener, listener.getExecutor(), mActivity.mCronetEngine); urlRequestBuilder.build().start(); listener.blockForDone(); // Verify that the request is successful and that the Data Reduction // Proxy logic configured to use the test server as its proxy. assertEquals(200, listener.mResponseInfo.getHttpStatusCode()); assertEquals(serverHostPort, listener.mResponseInfo.getProxyServer()); assertEquals( "http://DomainThatDoesnt.Resolve/datareductionproxysuccess.txt", listener.mResponseInfo.getUrl()); }
@SmallTest @Feature({"Cronet"}) public void testConfigUserAgent() throws Exception { String userAgentName = "User-Agent"; String userAgentValue = "User-Agent-Value"; CronetEngine.Builder cronetEngineBuilder = new CronetEngine.Builder(mActivity); cronetEngineBuilder.setUserAgent(userAgentValue); cronetEngineBuilder.setLibraryName("cronet_tests"); String[] commandLineArgs = {CronetTestActivity.CONFIG_KEY, cronetEngineBuilder.toString()}; mActivity = launchCronetTestAppWithUrlAndCommandLineArgs(TEST_URL, commandLineArgs); assertTrue(NativeTestServer.startNativeTestServer(getInstrumentation().getTargetContext())); TestUrlRequestListener listener = new TestUrlRequestListener(); UrlRequest.Builder urlRequestBuilder = new UrlRequest.Builder( NativeTestServer.getEchoHeaderURL(userAgentName), listener, listener.getExecutor(), mActivity.mCronetEngine); urlRequestBuilder.build().start(); listener.blockForDone(); assertEquals(userAgentValue, listener.mResponseAsString); }