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
3 // found in the LICENSE file.
5 package org.chromium.cronet_test_apk;
7 import android.test.suitebuilder.annotation.SmallTest;
9 import org.chromium.base.test.util.Feature;
10 import org.chromium.net.HttpUrlRequest;
11 import org.chromium.net.HttpUrlRequestFactory;
12 import org.chromium.net.HttpUrlRequestFactoryConfig;
14 import java.util.HashMap;
15 import java.util.regex.Pattern;
18 * Tests for {@link HttpUrlRequestFactory}
20 public class HttpUrlRequestFactoryTest extends CronetTestBase {
21 // URL used for base tests.
22 private static final String URL = "http://127.0.0.1:8000";
26 public void testCreateFactory() throws Throwable {
27 HttpUrlRequestFactoryConfig config = new HttpUrlRequestFactoryConfig();
28 config.enableQUIC(true);
29 config.addQuicHint("www.google.com", 443, 443);
30 config.addQuicHint("www.youtube.com", 443, 443);
31 config.setLibraryName("cronet_tests");
32 String[] commandLineArgs = {
33 CronetTestActivity.CONFIG_KEY, config.toString() };
34 CronetTestActivity activity =
35 launchCronetTestAppWithUrlAndCommandLineArgs(URL,
37 // Make sure the activity was created as expected.
38 assertNotNull(activity);
39 waitForActiveShellToBeDoneLoading();
40 HttpUrlRequestFactory factory = activity.mRequestFactory;
41 assertNotNull("Factory should be created", factory);
42 assertTrue("Factory should be Chromium/n.n.n.n@r but is "
44 Pattern.matches("Chromium/\\d+\\.\\d+\\.\\d+\\.\\d+@\\w+",
50 public void testCreateLegacyFactory() {
51 HttpUrlRequestFactoryConfig config = new HttpUrlRequestFactoryConfig();
52 config.enableLegacyMode(true);
54 HttpUrlRequestFactory factory = HttpUrlRequestFactory.createFactory(
55 getInstrumentation().getTargetContext(), config);
56 assertNotNull("Factory should be created", factory);
57 assertTrue("Factory should be HttpUrlConnection/n.n.n.n@r but is "
60 "HttpUrlConnection/\\d+\\.\\d+\\.\\d+\\.\\d+@\\w+",
62 HashMap<String, String> headers = new HashMap<String, String>();
63 TestHttpUrlRequestListener listener = new TestHttpUrlRequestListener();
64 HttpUrlRequest request = factory.createRequest(
65 URL, 0, headers, listener);
67 listener.blockForComplete();
68 assertEquals(200, listener.mHttpStatusCode);
69 assertEquals("OK", listener.mHttpStatusText);
74 public void testQuicHintHost() {
75 HttpUrlRequestFactoryConfig config = new HttpUrlRequestFactoryConfig();
76 config.addQuicHint("www.google.com", 443, 443);
78 config.addQuicHint("https://www.google.com", 443, 443);
79 } catch (IllegalArgumentException e) {
82 fail("IllegalArgumentException must be thrown");