| Index: android_webview/javatests/src/org/chromium/android_webview/test/AwDebugTest.java
|
| diff --git a/android_webview/javatests/src/org/chromium/android_webview/test/AwDebugTest.java b/android_webview/javatests/src/org/chromium/android_webview/test/AwDebugTest.java
|
| index 79c0589fec38116f62d03c4ea38d6bd88191bccd..be18ccf8d5e57136dc541a6986b1d444b19bd8c5 100644
|
| --- a/android_webview/javatests/src/org/chromium/android_webview/test/AwDebugTest.java
|
| +++ b/android_webview/javatests/src/org/chromium/android_webview/test/AwDebugTest.java
|
| @@ -7,10 +7,14 @@ package org.chromium.android_webview.test;
|
| import android.support.test.filters.SmallTest;
|
|
|
| import org.chromium.android_webview.AwDebug;
|
| +import org.chromium.base.Log;
|
| import org.chromium.base.test.util.Feature;
|
| import org.chromium.base.test.util.parameter.ParameterizedTest;
|
|
|
| import java.io.File;
|
| +import java.io.FileInputStream;
|
| +import java.io.IOException;
|
| +import java.util.Scanner;
|
|
|
| /**
|
| * A test suite for AwDebug class.
|
| @@ -18,6 +22,12 @@ import java.io.File;
|
| // Only works in single-process mode, crbug.com/568825.
|
| @ParameterizedTest.Set
|
| public class AwDebugTest extends AwTestBase {
|
| + private static final String TAG = "cr_AwDebugTest";
|
| + private static final String DEBUG_KEY = "AW_DEBUG_KEY";
|
| + private static final String DEBUG_KEY_LINE =
|
| + "Content-Disposition: form-data; name=\"" + DEBUG_KEY + "\"";
|
| + private static final String DEBUG_VALUE = "AW_DEBUG_VALUE";
|
| +
|
| @SmallTest
|
| @Feature({"AndroidWebView", "Debug"})
|
| public void testDump() throws Throwable {
|
| @@ -30,4 +40,48 @@ public class AwDebugTest extends AwTestBase {
|
| assertTrue(f.delete());
|
| }
|
| }
|
| +
|
| + @SmallTest
|
| + @Feature({"AndroidWebView", "Debug"})
|
| + public void testDumpContainsWhitelistedKey() throws Throwable {
|
| + File f = File.createTempFile("dump", ".dmp");
|
| + try {
|
| + assertTrue(AwDebug.dumpWithoutCrashing(f));
|
| + String dumpContents = readEntireFile(f);
|
| + Log.e(TAG, "dump contents: \n" + dumpContents);
|
| + // We are expecting the following:
|
| + //
|
| + // Content-Disposition: form-data; name="AW_DEBUG_KEY"
|
| + // AW_DEBUG_VALUE
|
| + //
|
| + assertTrue(dumpContents.contains(DEBUG_KEY_LINE));
|
| + int debug_key_index = dumpContents.indexOf(DEBUG_KEY_LINE);
|
| + // Read the word after the line containing the debug key
|
| + Scanner debugValueScanner =
|
| + new Scanner(dumpContents.substring(debug_key_index + DEBUG_KEY_LINE.length()));
|
| + assertTrue(debugValueScanner.hasNext());
|
| + // TODO this should return the next word in the string - does it?
|
| + String actualDebugValue = debugValueScanner.next();
|
| + assertEquals(DEBUG_VALUE, actualDebugValue);
|
| + } finally {
|
| + assertTrue(f.delete());
|
| + }
|
| + }
|
| +
|
| + @SmallTest
|
| + @Feature({"AndroidWebView", "Debug"})
|
| + public void testDumpDoesNotContainNonWhitelistedKey() throws Throwable {
|
| + // TODO
|
| + }
|
| +
|
| + private static String readEntireFile(File file) throws IOException {
|
| + FileInputStream fileInputStream = new FileInputStream(file);
|
| + try {
|
| + byte[] data = new byte[(int) file.length()];
|
| + fileInputStream.read(data);
|
| + return new String(data);
|
| + } finally {
|
| + fileInputStream.close();
|
| + }
|
| + }
|
| }
|
|
|