| 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..11d413e56457d2536b280622dbdbf012563ae970 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
|
| @@ -5,12 +5,16 @@
|
| package org.chromium.android_webview.test;
|
|
|
| import android.support.test.filters.SmallTest;
|
| +import android.test.UiThreadTest;
|
|
|
| import org.chromium.android_webview.AwDebug;
|
| 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,11 @@ 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 WHITELISTED_DEBUG_KEY = "AW_WHITELISTED_DEBUG_KEY";
|
| + private static final String NON_WHITELISTED_DEBUG_KEY = "AW_NONWHITELISTED_DEBUG_KEY";
|
| + private static final String DEBUG_VALUE = "AW_DEBUG_VALUE";
|
| +
|
| @SmallTest
|
| @Feature({"AndroidWebView", "Debug"})
|
| public void testDump() throws Throwable {
|
| @@ -30,4 +39,77 @@ public class AwDebugTest extends AwTestBase {
|
| assertTrue(f.delete());
|
| }
|
| }
|
| +
|
| + @SmallTest
|
| + @UiThreadTest
|
| + @Feature({"AndroidWebView", "Debug"})
|
| + public void testDumpContainsWhitelistedKey() throws Throwable {
|
| + File f = File.createTempFile("dump", ".dmp");
|
| + try {
|
| + AwDebug.initCrashKeysForTesting();
|
| + AwDebug.setCrashKeyValue(WHITELISTED_DEBUG_KEY, DEBUG_VALUE);
|
| + assertTrue(AwDebug.dumpWithoutCrashing(f));
|
| + assertContainsCrashKeyValue(f, WHITELISTED_DEBUG_KEY, DEBUG_VALUE);
|
| + } finally {
|
| + assertTrue(f.delete());
|
| + }
|
| + }
|
| +
|
| + @SmallTest
|
| + @Feature({"AndroidWebView", "Debug"})
|
| + public void testDumpDoesNotContainNonWhitelistedKey() throws Throwable {
|
| + File f = File.createTempFile("dump", ".dmp");
|
| + try {
|
| + AwDebug.initCrashKeysForTesting();
|
| + AwDebug.setCrashKeyValue(NON_WHITELISTED_DEBUG_KEY, DEBUG_VALUE);
|
| + assertTrue(AwDebug.dumpWithoutCrashing(f));
|
| + assertNotContainsCrashKeyValue(f, NON_WHITELISTED_DEBUG_KEY);
|
| + } finally {
|
| + assertTrue(f.delete());
|
| + }
|
| + }
|
| +
|
| + private void assertNotContainsCrashKeyValue(File dump, String key) throws IOException {
|
| + String dumpContents = readEntireFile(dump);
|
| + // We are expecting the following to NOT be in the dumpContents:
|
| + //
|
| + // Content-Disposition: form-data; name="AW_DEBUG_KEY"
|
| + // AW_DEBUG_VALUE
|
| + assertFalse(dumpContents.contains(getDebugKeyLine(key)));
|
| + }
|
| +
|
| + private void assertContainsCrashKeyValue(File dump, String key, String expectedValue)
|
| + throws IOException {
|
| + String dumpContents = readEntireFile(dump);
|
| + // We are expecting the following lines:
|
| + //
|
| + // Content-Disposition: form-data; name="AW_DEBUG_KEY"
|
| + // AW_DEBUG_VALUE
|
| + String debugKeyLine = getDebugKeyLine(key);
|
| + assertTrue(dumpContents.contains(debugKeyLine));
|
| +
|
| + int debug_key_index = dumpContents.indexOf(debugKeyLine);
|
| + // Read the word after the line containing the debug key
|
| + Scanner debugValueScanner =
|
| + new Scanner(dumpContents.substring(debug_key_index + debugKeyLine.length()));
|
| + assertTrue(debugValueScanner.hasNext());
|
| + // TODO this should return the next word in the string - does it?
|
| + String actualDebugValue = debugValueScanner.next();
|
| + assertEquals(expectedValue, actualDebugValue);
|
| + }
|
| +
|
| + private static String getDebugKeyLine(String debugKey) {
|
| + return "Content-Disposition: form-data; name=\"" + debugKey + "\"";
|
| + }
|
| +
|
| + 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();
|
| + }
|
| + }
|
| }
|
|
|