Upstream version 7.35.144.0
[platform/framework/web/crosswalk.git] / src / net / cronet / android / sample / javatests / src / org / chromium / cronet_sample_apk / CronetSampleUrlTest.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_sample_apk;
6
7 import android.test.suitebuilder.annotation.SmallTest;
8
9 import org.chromium.base.test.util.Feature;
10
11 /**
12  * Example test that just starts the cronet sample.
13  */
14 public class CronetSampleUrlTest extends CronetSampleTestBase {
15     // URL used for base tests.
16     private static final String URL = "http://127.0.0.1:8000";
17
18     @SmallTest
19     @Feature({"Main"})
20     public void testLoadUrl() throws Exception {
21         CronetSampleActivity activity = launchCronetSampleWithUrl(URL);
22
23         // Make sure the activity was created as expected.
24         assertNotNull(activity);
25
26         waitForActiveShellToBeDoneLoading();
27
28         // Make sure that the URL is set as expected.
29         assertEquals(URL, activity.getUrl());
30         assertEquals(200, activity.getHttpStatusCode());
31     }
32
33     @SmallTest
34     @Feature({"Main"})
35     public void testInvalidUrl() throws Exception {
36         CronetSampleActivity activity = launchCronetSampleWithUrl(
37                 "127.0.0.1:8000");
38
39         // Make sure the activity was created as expected.
40         assertNotNull(activity);
41
42         waitForActiveShellToBeDoneLoading();
43
44         // The load should fail.
45         assertEquals(0, activity.getHttpStatusCode());
46     }
47
48     @SmallTest
49     @Feature({"Main"})
50     public void testPostData() throws Exception {
51         String[] commandLineArgs = {
52                 CronetSampleActivity.POST_DATA_KEY, "test" };
53         CronetSampleActivity activity =
54                 launchCronetSampleWithUrlAndCommandLineArgs(URL,
55                                                             commandLineArgs);
56
57         // Make sure the activity was created as expected.
58         assertNotNull(activity);
59
60         waitForActiveShellToBeDoneLoading();
61
62         // Make sure that the URL is set as expected.
63         assertEquals(URL, activity.getUrl());
64         // TODO(mef): The test server doesn't seem to work with chunked uploads.
65         assertEquals(411, activity.getHttpStatusCode());
66     }
67 }