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_sample_apk;
7 import android.test.suitebuilder.annotation.SmallTest;
9 import org.chromium.base.test.util.Feature;
14 * Example test that just starts the cronet sample.
16 public class CronetSampleUrlTest extends CronetSampleTestBase {
17 // URL used for base tests.
18 private static final String URL = "http://127.0.0.1:8000";
22 public void testLoadUrl() throws Exception {
23 CronetSampleActivity activity = launchCronetSampleWithUrl(URL);
25 // Make sure the activity was created as expected.
26 assertNotNull(activity);
28 waitForActiveShellToBeDoneLoading();
30 // Make sure that the URL is set as expected.
31 assertEquals(URL, activity.getUrl());
32 assertEquals(200, activity.getHttpStatusCode());
37 public void testInvalidUrl() throws Exception {
38 CronetSampleActivity activity = launchCronetSampleWithUrl(
41 // Make sure the activity was created as expected.
42 assertNotNull(activity);
44 waitForActiveShellToBeDoneLoading();
46 // The load should fail.
47 assertEquals(0, activity.getHttpStatusCode());
52 public void testPostData() throws Exception {
53 String[] commandLineArgs = {
54 CronetSampleActivity.POST_DATA_KEY, "test" };
55 CronetSampleActivity activity =
56 launchCronetSampleWithUrlAndCommandLineArgs(URL,
59 // Make sure the activity was created as expected.
60 assertNotNull(activity);
62 waitForActiveShellToBeDoneLoading();
64 // Make sure that the URL is set as expected.
65 assertEquals(URL, activity.getUrl());
66 assertEquals(200, activity.getHttpStatusCode());
71 public void testNetLog() throws Exception {
72 CronetSampleActivity activity = launchCronetSampleWithUrl(
75 // Make sure the activity was created as expected.
76 assertNotNull(activity);
78 waitForActiveShellToBeDoneLoading();
79 File file = File.createTempFile("cronet", "json");
80 activity.mRequestContext.startNetLogToFile(file.getPath());
81 activity.startWithURL_UrlRequest(URL);
83 activity.mRequestContext.stopNetLog();
84 assertTrue(file.exists());
85 assertTrue(file.length() != 0);
86 assertTrue(file.delete());
87 assertTrue(!file.exists());