Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(853)

Unified Diff: chrome/android/junit/src/org/chromium/chrome/browser/crash/LogcatExtractionCallableTest.java

Issue 1354723004: [android] Change the recommended log tag format to "cr_foo" (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fix presubmit test broken by another CL Created 5 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: chrome/android/junit/src/org/chromium/chrome/browser/crash/LogcatExtractionCallableTest.java
diff --git a/chrome/android/javatests/src/org/chromium/chrome/browser/crash/LogcatExtractionCallableTest.java b/chrome/android/junit/src/org/chromium/chrome/browser/crash/LogcatExtractionCallableTest.java
similarity index 64%
copy from chrome/android/javatests/src/org/chromium/chrome/browser/crash/LogcatExtractionCallableTest.java
copy to chrome/android/junit/src/org/chromium/chrome/browser/crash/LogcatExtractionCallableTest.java
index 9cf435be42554fd15e2d0417753a44b61bfb85f1..9c74e30e75fa7346cbefe9bc7be5c623cb1aedb9 100644
--- a/chrome/android/javatests/src/org/chromium/chrome/browser/crash/LogcatExtractionCallableTest.java
+++ b/chrome/android/junit/src/org/chromium/chrome/browser/crash/LogcatExtractionCallableTest.java
@@ -6,127 +6,121 @@
import static org.chromium.chrome.browser.crash.LogcatExtractionCallable.BEGIN_MICRODUMP;
import static org.chromium.chrome.browser.crash.LogcatExtractionCallable.END_MICRODUMP;
-
-import android.content.ComponentName;
-import android.content.Context;
-import android.content.Intent;
-import android.test.MoreAsserts;
-import android.test.suitebuilder.annotation.MediumTest;
-import android.test.suitebuilder.annotation.SmallTest;
+import static org.junit.Assert.assertArrayEquals;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.fail;
import android.text.TextUtils;
-import org.chromium.base.test.util.AdvancedMockContext;
+import org.chromium.testing.local.LocalRobolectricTestRunner;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.robolectric.annotation.Config;
import java.io.BufferedReader;
-import java.io.File;
-import java.io.FileReader;
-import java.io.IOException;
import java.io.StringReader;
-
-import java.util.ArrayList;
import java.util.Arrays;
import java.util.LinkedList;
import java.util.List;
-import java.util.concurrent.atomic.AtomicInteger;
/**
- * Unittests for {@link LogcatExtractionCallable}.
+ * junit tests for {@link LogcatExtractionCallable}.
*/
-public class LogcatExtractionCallableTest extends CrashTestCase {
- private File mCrashDir;
-
+@RunWith(LocalRobolectricTestRunner.class)
+@Config(manifest = Config.NONE)
+public class LogcatExtractionCallableTest {
private static final int MAX_LINES = 5;
- protected void setUp() throws Exception {
- super.setUp();
- mCrashDir = new CrashFileManager(mCacheDir).getCrashDirectory();
- }
-
- @SmallTest
+ @Test
public void testElideEmail() {
String original = "email me at someguy@mailservice.com";
String expected = "email me at XXX@EMAIL.ELIDED";
assertEquals(expected, LogcatExtractionCallable.elideEmail(original));
}
- @SmallTest
+ @Test
public void testElideUrl() {
String original = "file bugs at crbug.com";
String expected = "file bugs at HTTP://WEBADDRESS.ELIDED";
assertEquals(expected, LogcatExtractionCallable.elideUrl(original));
}
- @SmallTest
+ @Test
public void testElideUrl2() {
String original =
"exception at org.chromium.chrome.browser.crash.LogcatExtractionCallableTest";
assertEquals(original, LogcatExtractionCallable.elideUrl(original));
}
- @SmallTest
+ @Test
public void testElideUrl3() {
String original = "file bugs at crbug.com or code.google.com";
String expected = "file bugs at HTTP://WEBADDRESS.ELIDED or HTTP://WEBADDRESS.ELIDED";
assertEquals(expected, LogcatExtractionCallable.elideUrl(original));
}
- @SmallTest
+ @Test
public void testElideUrl4() {
String original = "test shorturl.com !!!";
String expected = "test HTTP://WEBADDRESS.ELIDED !!!";
assertEquals(expected, LogcatExtractionCallable.elideUrl(original));
}
- @SmallTest
+ @Test
public void testElideUrl5() {
String original = "test just.the.perfect.len.url !!!";
String expected = "test HTTP://WEBADDRESS.ELIDED !!!";
assertEquals(expected, LogcatExtractionCallable.elideUrl(original));
}
- @SmallTest
+ @Test
public void testElideUrl6() {
String original = "test a.very.very.very.very.very.long.url !!!";
String expected = "test HTTP://WEBADDRESS.ELIDED !!!";
assertEquals(expected, LogcatExtractionCallable.elideUrl(original));
}
- @SmallTest
+ @Test
public void testElideUrl7() {
String original = " at android.content.Intent \n at java.util.ArrayList";
assertEquals(original, LogcatExtractionCallable.elideUrl(original));
}
- @SmallTest
+ @Test
public void testElideIp() {
String original = "traceroute 127.0.0.1";
String expected = "traceroute 1.2.3.4";
assertEquals(expected, LogcatExtractionCallable.elideIp(original));
}
- @SmallTest
+ @Test
public void testElideMac1() {
String original = "MAC: AB-AB-AB-AB-AB-AB";
String expected = "MAC: 01:23:45:67:89:AB";
assertEquals(expected, LogcatExtractionCallable.elideMac(original));
}
- @SmallTest
+ @Test
public void testElideMac2() {
String original = "MAC: AB:AB:AB:AB:AB:AB";
String expected = "MAC: 01:23:45:67:89:AB";
assertEquals(expected, LogcatExtractionCallable.elideMac(original));
}
- @SmallTest
+ @Test
public void testElideConsole() {
String original = "I/chromium(123): [INFO:CONSOLE(2)] hello!";
String expected = "I/chromium(123): [ELIDED:CONSOLE(0)] ELIDED CONSOLE MESSAGE";
assertEquals(expected, LogcatExtractionCallable.elideConsole(original));
}
- @SmallTest
+ @Test
+ public void testLogTagNotElided() {
+ List<String> original = Arrays.asList(new String[] {"I/cr_FooBar(123): Some message"});
+ assertEquals(original, LogcatExtractionCallable.processLogcat(original));
+ }
+
+ @Test
public void testLogcatEmpty() {
final String original = "";
List<String> expected = new LinkedList<>();
@@ -137,17 +131,17 @@ public void testLogcatEmpty() {
} catch (Exception e) {
fail(e.toString());
}
- MoreAsserts.assertEquals(expected.toArray(), logcat.toArray());
+ assertArrayEquals(expected.toArray(), logcat.toArray());
}
- @SmallTest
+ @Test
public void testLogcatWithoutBeginOrEnd_smallLogcat() {
final List<String> original = Arrays.asList("Line 1", "Line 2", "Line 3", "Line 4",
"Line 5");
assertLogcatLists(original, original);
}
- @SmallTest
+ @Test
public void testLogcatWithoutBeginOrEnd_largeLogcat() {
final List<String> original = Arrays.asList("Line 1", "Line 2", "Line 3", "Line 4",
"Line 5", "Redundant Line 1", "Redundant Line 2");
@@ -156,13 +150,13 @@ public void testLogcatWithoutBeginOrEnd_largeLogcat() {
assertLogcatLists(expected, original);
}
- @SmallTest
+ @Test
public void testLogcatBeginsWithBegin() {
final List<String> original = Arrays.asList(BEGIN_MICRODUMP, "a", "b", "c", "d", "e");
assertLogcatLists(new LinkedList<String>(), original);
}
- @SmallTest
+ @Test
public void testLogcatWithBegin() {
final List<String> original = Arrays.asList("Line 1", "Line 2", BEGIN_MICRODUMP, "a",
"b", "c", "d", "e");
@@ -170,13 +164,13 @@ public void testLogcatWithBegin() {
assertLogcatLists(expected, original);
}
- @SmallTest
+ @Test
public void testLogcatWithEnd() {
final List<String> original = Arrays.asList("Line 1", "Line 2", END_MICRODUMP);
assertLogcatLists(new LinkedList<String>(), original);
}
- @SmallTest
+ @Test
public void testLogcatWithBeginAndEnd_smallLogcat() {
final List<String> original = Arrays.asList("Line 1", "Line 2", BEGIN_MICRODUMP, "a", "b",
"c", "d", "e", END_MICRODUMP);
@@ -184,7 +178,7 @@ public void testLogcatWithBeginAndEnd_smallLogcat() {
assertLogcatLists(expected, original);
}
- @SmallTest
+ @Test
public void testLogcatWithBeginAndEnd_largeLogcat() {
final List<String> original = Arrays.asList("Line 1", "Line 2", BEGIN_MICRODUMP, "a", "b",
"c", "d", "e", END_MICRODUMP, "Line 3", "Line 4");
@@ -192,7 +186,7 @@ public void testLogcatWithBeginAndEnd_largeLogcat() {
assertLogcatLists(expected, original);
}
- @SmallTest
+ @Test
public void testLogcatWithEndAndBegin_smallLogcat() {
final List<String> original = Arrays.asList(END_MICRODUMP, "Line 1", "Line 2",
BEGIN_MICRODUMP, "a", "b", "c", "d", "e");
@@ -200,7 +194,7 @@ public void testLogcatWithEndAndBegin_smallLogcat() {
assertLogcatLists(expected, original);
}
- @SmallTest
+ @Test
public void testLogcatWithEndAndBegin_largeLogcat() {
final List<String> original = Arrays.asList(END_MICRODUMP, "Line 1", "Line 2",
BEGIN_MICRODUMP, "a", "b", "c", "d", "e", END_MICRODUMP, "Line 3", "Line 4");
@@ -219,69 +213,6 @@ private void assertLogcatLists(List<String> expected, List<String> original) {
} catch (Exception e) {
fail(e.toString());
}
- MoreAsserts.assertEquals(expected.toArray(), actualLogcat.toArray());
- }
-
- @MediumTest
- public void testExtractToFile() {
- final AtomicInteger numServiceStarts = new AtomicInteger(0);
- final String logContent = "some random log content";
- final Intent testIntent = new Intent();
- File dmp1 = new File(mCrashDir, "test1.dmp");
- File dmp2 = new File(mCrashDir, "test2.dmp");
- File dmp3 = new File(mCrashDir, "test3.dmp");
- final String[] dumps = new String[] {dmp1.getName(), dmp2.getName(), dmp3.getName()};
-
- Context testContext = new AdvancedMockContext(getInstrumentation().getTargetContext()) {
- @Override
- public ComponentName startService(Intent intentToCheck) {
- assertTrue("We should have no more than 3 intents created",
- numServiceStarts.incrementAndGet() <= dumps.length);
- Intent redirectIntent = intentToCheck.getParcelableExtra("redirect_intent");
-
- // Only the very last one will have a non-null redirect_intent.
- if (numServiceStarts.get() == dumps.length) {
- // And it should be == to the one we pass into the constructor.
- assertSame(redirectIntent, testIntent);
- } else {
- assertNull(redirectIntent);
- }
- return new ComponentName(
- getPackageName(), LogcatExtractionCallable.class.getName());
- }
- };
-
- LogcatExtractionCallable callable = new LogcatExtractionCallable(
- testContext, dumps, testIntent) {
- @Override
- protected List<String> getLogcat() throws IOException, InterruptedException {
- List<String> result = new ArrayList<String>();
- result.add(logContent);
- return result;
- }
- };
-
- callable.call();
-
- assertFileContent("test1.logcat", logContent);
- assertFileContent("test2.logcat", logContent);
- assertFileContent("test3.logcat", logContent);
- }
-
- private void assertFileContent(String fileName, String content) {
- try {
- File logfile = new File(mCrashDir, fileName);
- assertTrue("Logfile does not exist!", logfile.exists());
- BufferedReader input = new BufferedReader(new FileReader(logfile));
- StringBuffer sb = new StringBuffer();
- String line = null;
- while ((line = input.readLine()) != null) {
- sb.append(line);
- }
- input.close();
- assertEquals("Content not matched!", content, sb.toString());
- } catch (Exception e) {
- fail(e.toString());
- }
+ assertArrayEquals(expected.toArray(), actualLogcat.toArray());
}
}

Powered by Google App Engine
This is Rietveld 408576698