• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Copyright 2014 The Chromium Authors
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.net;
6 
7 import android.content.Context;
8 
9 import org.chromium.base.annotations.JNINamespace;
10 import org.chromium.base.annotations.NativeMethods;
11 import org.chromium.base.test.util.UrlUtils;
12 
13 /**
14  * Wrapper class to start an in-process native test server, and get URLs
15  * needed to talk to it.
16  */
17 @JNINamespace("cronet")
18 public final class NativeTestServer {
19     // This variable contains the response body of a request to getSuccessURL().
20     public static final String SUCCESS_BODY = "this is a text file\n";
21 
startNativeTestServer(Context context)22     public static boolean startNativeTestServer(Context context) {
23         TestFilesInstaller.installIfNeeded(context);
24         return NativeTestServerJni.get().startNativeTestServer(
25                 TestFilesInstaller.getInstalledPath(context), UrlUtils.getIsolatedTestRoot());
26     }
27 
shutdownNativeTestServer()28     public static void shutdownNativeTestServer() {
29         NativeTestServerJni.get().shutdownNativeTestServer();
30     }
31 
getEchoBodyURL()32     public static String getEchoBodyURL() {
33         return NativeTestServerJni.get().getEchoBodyURL();
34     }
35 
getEchoHeaderURL(String header)36     public static String getEchoHeaderURL(String header) {
37         return NativeTestServerJni.get().getEchoHeaderURL(header);
38     }
39 
getEchoAllHeadersURL()40     public static String getEchoAllHeadersURL() {
41         return NativeTestServerJni.get().getEchoAllHeadersURL();
42     }
43 
getEchoMethodURL()44     public static String getEchoMethodURL() {
45         return NativeTestServerJni.get().getEchoMethodURL();
46     }
47 
getRedirectToEchoBody()48     public static String getRedirectToEchoBody() {
49         return NativeTestServerJni.get().getRedirectToEchoBody();
50     }
51 
getFileURL(String filePath)52     public static String getFileURL(String filePath) {
53         return NativeTestServerJni.get().getFileURL(filePath);
54     }
55 
56     // Returns a URL that the server will return an Exabyte of data
getExabyteResponseURL()57     public static String getExabyteResponseURL() {
58         return NativeTestServerJni.get().getExabyteResponseURL();
59     }
60 
61     // The following URLs will make NativeTestServer serve a response based on
62     // the contents of the corresponding file and its mock-http-headers file.
63 
getSuccessURL()64     public static String getSuccessURL() {
65         return NativeTestServerJni.get().getFileURL("/success.txt");
66     }
67 
getRedirectURL()68     public static String getRedirectURL() {
69         return NativeTestServerJni.get().getFileURL("/redirect.html");
70     }
71 
getMultiRedirectURL()72     public static String getMultiRedirectURL() {
73         return NativeTestServerJni.get().getFileURL("/multiredirect.html");
74     }
75 
getNotFoundURL()76     public static String getNotFoundURL() {
77         return NativeTestServerJni.get().getFileURL("/notfound.html");
78     }
79 
getServerErrorURL()80     public static String getServerErrorURL() {
81         return NativeTestServerJni.get().getFileURL("/server_error.txt");
82     }
83 
getPort()84     public static int getPort() {
85         return NativeTestServerJni.get().getPort();
86     }
87 
getHostPort()88     public static String getHostPort() {
89         return NativeTestServerJni.get().getHostPort();
90     }
91 
92     @NativeMethods("cronet_tests")
93     interface Natives {
startNativeTestServer(String filePath, String testDataDir)94         boolean startNativeTestServer(String filePath, String testDataDir);
shutdownNativeTestServer()95         void shutdownNativeTestServer();
getEchoBodyURL()96         String getEchoBodyURL();
getEchoHeaderURL(String header)97         String getEchoHeaderURL(String header);
getEchoAllHeadersURL()98         String getEchoAllHeadersURL();
getEchoMethodURL()99         String getEchoMethodURL();
getRedirectToEchoBody()100         String getRedirectToEchoBody();
getFileURL(String filePath)101         String getFileURL(String filePath);
getExabyteResponseURL()102         String getExabyteResponseURL();
getHostPort()103         String getHostPort();
getPort()104         int getPort();
105     }
106 }
107