Make castv2 performance test work.
[chromium-blink-merge.git] / components / cronet / android / test / src / org / chromium / net / MockUrlRequestJobFactory.java
blob79a3cfb467ad73f412531f028911d86e728cc2cd
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.net;
7 import android.content.Context;
9 import org.chromium.base.JNINamespace;
11 /**
12 * Helper class to set up url interceptors for testing purposes.
14 @JNINamespace("cronet")
15 public final class MockUrlRequestJobFactory {
16 public static final String SUCCESS_URL =
17 "http://mock.http/success.txt";
18 public static final String REDIRECT_URL =
19 "http://mock.http/redirect.html";
20 public static final String MULTI_REDIRECT_URL =
21 "http://mock.http/multiredirect.html";
22 public static final String NOTFOUND_URL =
23 "http://mock.http/notfound.html";
24 public static final String FAILED_URL =
25 "http://mock.failed.request/-2";
27 enum FailurePhase {
28 START,
29 READ_ASYNC,
30 READ_SYNC,
33 /**
34 * Constructs a MockUrlRequestJobFactory and sets up mock environment.
35 * @param context application context.
37 public MockUrlRequestJobFactory(Context context) {
38 if (!TestFilesInstaller.areFilesInstalled(context)) {
39 throw new IllegalStateException("test files not installed.");
41 nativeAddUrlInterceptors(TestFilesInstaller.getInstalledPath(context));
44 /**
45 * Constructs a mock URL.
47 * @param path path to a mock file.
49 public String getMockUrl(String path) {
50 return nativeGetMockUrl(path);
53 /**
54 * Constructs a mock URL that hangs or fails at certain phase.
56 * @param path path to a mock file.
57 * @param phase at which request fails.
58 * @param netError reported by UrlRequestJob. Passing -1, results in hang.
60 public String getMockUrlWithFailure(String path, FailurePhase phase,
61 int netError) {
62 return nativeGetMockUrlWithFailure(path, phase.ordinal(), netError);
65 /**
66 * Constructs a mock URL that synchronously responds with data repeated many
67 * times.
69 * @param data to return in response.
70 * @param dataRepeatCount number of times to repeat the data.
72 public String getMockUrlForData(String data, int dataRepeatCount) {
73 return nativeGetMockUrlForData(data, dataRepeatCount);
76 private static native void nativeAddUrlInterceptors(String installedPath);
78 private static native String nativeGetMockUrl(String path);
80 private static native String nativeGetMockUrlWithFailure(String path,
81 int phase, int netError);
83 private static native String nativeGetMockUrlForData(String data,
84 int dataRepeatCount);