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.HttpUrlRequestFactory;
11 import org.chromium.net.HttpUrlRequestFactoryConfig;
13 import java.util.regex.Pattern;
16 * Tests for {@link HttpUrlRequestFactory}
18 public class HttpUrlRequestFactoryTest extends CronetTestBase {
19 // URL used for base tests.
20 private static final String URL = "http://127.0.0.1:8000";
24 public void testCreateFactory() throws Throwable {
25 HttpUrlRequestFactoryConfig config = new HttpUrlRequestFactoryConfig();
26 config.enableQUIC(true);
27 config.addQuicHint("www.google.com", 443, 443);
28 config.addQuicHint("www.youtube.com", 443, 443);
29 config.setLibraryName("cronet_tests");
30 String[] commandLineArgs = {
31 CronetTestActivity.CONFIG_KEY, config.toString() };
32 CronetTestActivity activity =
33 launchCronetTestAppWithUrlAndCommandLineArgs(URL,
35 // Make sure the activity was created as expected.
36 assertNotNull(activity);
37 waitForActiveShellToBeDoneLoading();
38 HttpUrlRequestFactory factory = activity.mRequestFactory;
39 assertNotNull("Factory should be created", factory);
40 assertTrue("Factory should be Chromium/n.n.n.n@r but is " +
42 Pattern.matches("Chromium/\\d+\\.\\d+\\.\\d+\\.\\d+@\\w+",
48 public void testCreateLegacyFactory() {
49 HttpUrlRequestFactoryConfig config = new HttpUrlRequestFactoryConfig();
50 config.enableLegacyMode(true);
52 HttpUrlRequestFactory factory = HttpUrlRequestFactory.createFactory(
53 getInstrumentation().getContext(), config);
54 assertNotNull("Factory should be created", factory);
55 assertTrue("Factory should be HttpUrlConnection/n.n.n.n@r but is " +
58 "HttpUrlConnection/\\d+\\.\\d+\\.\\d+\\.\\d+@\\w+",