Upstream version 10.39.225.0
[platform/framework/web/crosswalk.git] / src / components / cronet / android / test / javatests / src / org / chromium / cronet_test_apk / HttpUrlRequestFactoryTest.java
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.
4
5 package org.chromium.cronet_test_apk;
6
7 import android.test.suitebuilder.annotation.SmallTest;
8
9 import org.chromium.base.test.util.Feature;
10 import org.chromium.net.HttpUrlRequestFactory;
11 import org.chromium.net.HttpUrlRequestFactoryConfig;
12
13 import java.util.regex.Pattern;
14
15 /**
16  * Tests for {@link HttpUrlRequestFactory}
17  */
18 public class HttpUrlRequestFactoryTest extends CronetTestBase {
19     // URL used for base tests.
20     private static final String URL = "http://127.0.0.1:8000";
21
22     @SmallTest
23     @Feature({"Cronet"})
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,
34                                                              commandLineArgs);
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 " +
41                            factory.getName(),
42                    Pattern.matches("Chromium/\\d+\\.\\d+\\.\\d+\\.\\d+@\\w+",
43                            factory.getName()));
44     }
45
46     @SmallTest
47     @Feature({"Cronet"})
48     public void testCreateLegacyFactory() {
49         HttpUrlRequestFactoryConfig config = new HttpUrlRequestFactoryConfig();
50         config.enableLegacyMode(true);
51
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 " +
56                            factory.getName(),
57                    Pattern.matches(
58                            "HttpUrlConnection/\\d+\\.\\d+\\.\\d+\\.\\d+@\\w+",
59                            factory.getName()));
60     }
61 }