| OLD | NEW |
| (Empty) |
| 1 // Copyright 2015 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. | |
| 4 | |
| 5 package org.chromium.chrome.browser.crash; | |
| 6 | |
| 7 import static org.junit.Assert.assertArrayEquals; | |
| 8 import static org.junit.Assert.assertEquals; | |
| 9 | |
| 10 import static org.chromium.chrome.browser.crash.LogcatExtractionCallable.BEGIN_M
ICRODUMP; | |
| 11 import static org.chromium.chrome.browser.crash.LogcatExtractionCallable.END_MIC
RODUMP; | |
| 12 import static org.chromium.chrome.browser.crash.LogcatExtractionCallable.SNIPPED
_MICRODUMP; | |
| 13 | |
| 14 import org.junit.Test; | |
| 15 import org.junit.runner.RunWith; | |
| 16 import org.robolectric.annotation.Config; | |
| 17 | |
| 18 import org.chromium.testing.local.LocalRobolectricTestRunner; | |
| 19 | |
| 20 import java.util.Arrays; | |
| 21 import java.util.LinkedList; | |
| 22 import java.util.List; | |
| 23 | |
| 24 /** | |
| 25 * junit tests for {@link LogcatExtractionCallable}. | |
| 26 */ | |
| 27 @RunWith(LocalRobolectricTestRunner.class) | |
| 28 @Config(manifest = Config.NONE) | |
| 29 public class LogcatExtractionCallableUnitTest { | |
| 30 private static final int MAX_LINES = 5; | |
| 31 | |
| 32 @Test | |
| 33 public void testElideEmail() { | |
| 34 String original = "email me at someguy@mailservice.com"; | |
| 35 String expected = "email me at XXX@EMAIL.ELIDED"; | |
| 36 assertEquals(expected, LogcatExtractionCallable.elideEmail(original)); | |
| 37 } | |
| 38 | |
| 39 @Test | |
| 40 public void testElideUrl() { | |
| 41 String original = "file bugs at crbug.com"; | |
| 42 String expected = "file bugs at HTTP://WEBADDRESS.ELIDED"; | |
| 43 assertEquals(expected, LogcatExtractionCallable.elideUrl(original)); | |
| 44 } | |
| 45 | |
| 46 @Test | |
| 47 public void testElideUrl2() { | |
| 48 String original = | |
| 49 "exception at org.chromium.chrome.browser.crash.LogcatExtraction
CallableUnitTest"; | |
| 50 assertEquals(original, LogcatExtractionCallable.elideUrl(original)); | |
| 51 } | |
| 52 | |
| 53 @Test | |
| 54 public void testElideUrl3() { | |
| 55 String original = "file bugs at crbug.com or code.google.com"; | |
| 56 String expected = "file bugs at HTTP://WEBADDRESS.ELIDED or HTTP://WEBAD
DRESS.ELIDED"; | |
| 57 assertEquals(expected, LogcatExtractionCallable.elideUrl(original)); | |
| 58 } | |
| 59 | |
| 60 @Test | |
| 61 public void testElideUrl4() { | |
| 62 String original = "test shorturl.com !!!"; | |
| 63 String expected = "test HTTP://WEBADDRESS.ELIDED !!!"; | |
| 64 assertEquals(expected, LogcatExtractionCallable.elideUrl(original)); | |
| 65 } | |
| 66 | |
| 67 @Test | |
| 68 public void testElideUrl5() { | |
| 69 String original = "test just.the.perfect.len.url !!!"; | |
| 70 String expected = "test HTTP://WEBADDRESS.ELIDED !!!"; | |
| 71 assertEquals(expected, LogcatExtractionCallable.elideUrl(original)); | |
| 72 } | |
| 73 | |
| 74 @Test | |
| 75 public void testElideUrl6() { | |
| 76 String original = "test a.very.very.very.very.very.long.url !!!"; | |
| 77 String expected = "test HTTP://WEBADDRESS.ELIDED !!!"; | |
| 78 assertEquals(expected, LogcatExtractionCallable.elideUrl(original)); | |
| 79 } | |
| 80 | |
| 81 @Test | |
| 82 public void testElideUrl7() { | |
| 83 String original = " at android.content.Intent \n at java.util.ArrayList"
; | |
| 84 assertEquals(original, LogcatExtractionCallable.elideUrl(original)); | |
| 85 } | |
| 86 | |
| 87 @Test | |
| 88 public void testDontElideFileSuffixes() { | |
| 89 String original = "chromium_android_linker.so"; | |
| 90 assertEquals(original, LogcatExtractionCallable.elideUrl(original)); | |
| 91 } | |
| 92 | |
| 93 @Test | |
| 94 public void testElideIp() { | |
| 95 String original = "traceroute 127.0.0.1"; | |
| 96 String expected = "traceroute 1.2.3.4"; | |
| 97 assertEquals(expected, LogcatExtractionCallable.elideIp(original)); | |
| 98 } | |
| 99 | |
| 100 @Test | |
| 101 public void testElideMac1() { | |
| 102 String original = "MAC: AB-AB-AB-AB-AB-AB"; | |
| 103 String expected = "MAC: 01:23:45:67:89:AB"; | |
| 104 assertEquals(expected, LogcatExtractionCallable.elideMac(original)); | |
| 105 } | |
| 106 | |
| 107 @Test | |
| 108 public void testElideMac2() { | |
| 109 String original = "MAC: AB:AB:AB:AB:AB:AB"; | |
| 110 String expected = "MAC: 01:23:45:67:89:AB"; | |
| 111 assertEquals(expected, LogcatExtractionCallable.elideMac(original)); | |
| 112 } | |
| 113 | |
| 114 @Test | |
| 115 public void testElideConsole() { | |
| 116 String original = "I/chromium(123): [INFO:CONSOLE(2)] hello!"; | |
| 117 String expected = "I/chromium(123): [ELIDED:CONSOLE(0)] ELIDED CONSOLE M
ESSAGE"; | |
| 118 assertEquals(expected, LogcatExtractionCallable.elideConsole(original)); | |
| 119 } | |
| 120 | |
| 121 @Test | |
| 122 public void testLogTagNotElided() { | |
| 123 List<String> original = Arrays.asList(new String[] {"I/cr_FooBar(123): S
ome message"}); | |
| 124 assertEquals(original, LogcatExtractionCallable.processLogcat(original))
; | |
| 125 } | |
| 126 | |
| 127 @Test | |
| 128 public void testLogcatEmpty() { | |
| 129 final List<String> original = new LinkedList<>(); | |
| 130 assertLogcatLists(original, original); | |
| 131 } | |
| 132 | |
| 133 @Test | |
| 134 public void testLogcatWithoutBeginOrEnd_smallLogcat() { | |
| 135 final List<String> original = | |
| 136 Arrays.asList("Line 1", "Line 2", "Line 3", "Line 4", "Line 5"); | |
| 137 assertLogcatLists(original, original); | |
| 138 } | |
| 139 | |
| 140 @Test | |
| 141 public void testLogcatWithoutBeginOrEnd_largeLogcat() { | |
| 142 final List<String> original = Arrays.asList("Trimmed Line 1", "Trimmed L
ine 2", "Line 3", | |
| 143 "Line 4", "Line 5", "Line 6", "Line 7"); | |
| 144 final List<String> expected = | |
| 145 Arrays.asList("Line 3", "Line 4", "Line 5", "Line 6", "Line 7"); | |
| 146 assertLogcatLists(expected, original); | |
| 147 } | |
| 148 | |
| 149 @Test | |
| 150 public void testLogcatBeginsWithBegin() { | |
| 151 final List<String> original = Arrays.asList(BEGIN_MICRODUMP, "a", "b", "
c", "d", "e"); | |
| 152 final List<String> expected = Arrays.asList(SNIPPED_MICRODUMP); | |
| 153 assertLogcatLists(expected, original); | |
| 154 } | |
| 155 | |
| 156 @Test | |
| 157 public void testLogcatWithBegin() { | |
| 158 final List<String> original = | |
| 159 Arrays.asList("Line 1", "Line 2", BEGIN_MICRODUMP, "a", "b", "c"
, "d", "e"); | |
| 160 final List<String> expected = Arrays.asList("Line 1", "Line 2", SNIPPED_
MICRODUMP); | |
| 161 assertLogcatLists(expected, original); | |
| 162 } | |
| 163 | |
| 164 @Test | |
| 165 public void testLogcatWithEnd() { | |
| 166 final List<String> original = Arrays.asList("Line 1", "Line 2", END_MICR
ODUMP); | |
| 167 assertLogcatLists(original, original); | |
| 168 } | |
| 169 | |
| 170 @Test | |
| 171 public void testLogcatWithBeginAndEnd_smallLogcat() { | |
| 172 final List<String> original = Arrays.asList( | |
| 173 "Line 1", "Line 2", BEGIN_MICRODUMP, "a", "b", "c", "d", "e", EN
D_MICRODUMP); | |
| 174 final List<String> expected = Arrays.asList("Line 1", "Line 2", SNIPPED_
MICRODUMP); | |
| 175 assertLogcatLists(expected, original); | |
| 176 } | |
| 177 | |
| 178 @Test | |
| 179 public void testLogcatWithBeginAndEnd_splitLogcat() { | |
| 180 final List<String> original = Arrays.asList("Line 1", "Line 2", BEGIN_MI
CRODUMP, "a", "b", | |
| 181 "c", "d", "e", END_MICRODUMP, "Trimmed Line 3", "Trimmed Line 4"
); | |
| 182 final List<String> expected = Arrays.asList("Line 1", "Line 2", SNIPPED_
MICRODUMP); | |
| 183 assertLogcatLists(expected, original); | |
| 184 } | |
| 185 | |
| 186 @Test | |
| 187 public void testLogcatWithBeginAndEnd_largeLogcat() { | |
| 188 final List<String> original = Arrays.asList("Trimmed Line 1", "Trimmed L
ine 2", "Line 3", | |
| 189 "Line 4", "Line 5", "Line 6", BEGIN_MICRODUMP, "a", "b", "c", "d
", "e", | |
| 190 END_MICRODUMP, "Trimmed Line 7", "Trimmed Line 8"); | |
| 191 final List<String> expected = | |
| 192 Arrays.asList("Line 3", "Line 4", "Line 5", "Line 6", SNIPPED_MI
CRODUMP); | |
| 193 assertLogcatLists(expected, original); | |
| 194 } | |
| 195 | |
| 196 @Test | |
| 197 public void testLogcatWithEndAndBegin_smallLogcat() { | |
| 198 final List<String> original = Arrays.asList( | |
| 199 END_MICRODUMP, "Line 1", "Line 2", BEGIN_MICRODUMP, "a", "b", "c
", "d", "e"); | |
| 200 final List<String> expected = | |
| 201 Arrays.asList(END_MICRODUMP, "Line 1", "Line 2", SNIPPED_MICRODU
MP); | |
| 202 assertLogcatLists(expected, original); | |
| 203 } | |
| 204 | |
| 205 @Test | |
| 206 public void testLogcatWithEndAndBegin_largeLogcat() { | |
| 207 final List<String> original = | |
| 208 Arrays.asList(END_MICRODUMP, "Line 1", "Line 2", BEGIN_MICRODUMP
, "a", "b", "c", | |
| 209 "d", "e", END_MICRODUMP, "Trimmed Line 3", "Trimmed Line
4"); | |
| 210 final List<String> expected = | |
| 211 Arrays.asList(END_MICRODUMP, "Line 1", "Line 2", SNIPPED_MICRODU
MP); | |
| 212 assertLogcatLists(expected, original); | |
| 213 } | |
| 214 | |
| 215 private void assertLogcatLists(List<String> expected, List<String> original)
{ | |
| 216 // trimLogcat() expects a modifiable list as input. | |
| 217 LinkedList<String> rawLogcat = new LinkedList<String>(original); | |
| 218 List<String> actualLogcat = LogcatExtractionCallable.trimLogcat(rawLogca
t, MAX_LINES); | |
| 219 assertArrayEquals(expected.toArray(), actualLogcat.toArray()); | |
| 220 } | |
| 221 } | |
| OLD | NEW |