| Index: base/android/junit/src/org/chromium/base/LogTest.java
|
| diff --git a/base/android/junit/src/org/chromium/base/LogTest.java b/base/android/junit/src/org/chromium/base/LogTest.java
|
| index 46bdc67e62dcf970b8b03f97ffb25a90491257ac..e5ce239d048228d8e36f020fa19a9b2a1e349d04 100644
|
| --- a/base/android/junit/src/org/chromium/base/LogTest.java
|
| +++ b/base/android/junit/src/org/chromium/base/LogTest.java
|
| @@ -9,6 +9,7 @@ import static org.junit.Assert.assertNull;
|
| import static org.junit.Assert.assertTrue;
|
|
|
| import org.chromium.testing.local.LocalRobolectricTestRunner;
|
| +import org.junit.Before;
|
| import org.junit.Test;
|
| import org.junit.runner.RunWith;
|
| import org.robolectric.annotation.Config;
|
| @@ -22,20 +23,6 @@ import java.util.List;
|
| @RunWith(LocalRobolectricTestRunner.class)
|
| @Config(manifest = Config.NONE, shadows = {LogTest.PermissiveShadowLog.class})
|
| public class LogTest {
|
| - /** Test method for {@link Log#makeTag(String)} */
|
| - @Test
|
| - public void testMakeTag() {
|
| - assertEquals("cr.Foo", Log.makeTag("Foo"));
|
| - assertEquals("cr", Log.makeTag(null));
|
| - assertEquals("cr", Log.makeTag(""));
|
| - }
|
| -
|
| - /** Test method for {@link Log#makeTag(String)} */
|
| - @Test(expected = IllegalArgumentException.class)
|
| - public void testMakeTagFailure() {
|
| - Log.makeTag("ThisIs21Char.....Long");
|
| - }
|
| -
|
| /** Tests that the computed call origin is the correct one. */
|
| @Test
|
| public void callOriginTest() {
|
| @@ -88,12 +75,138 @@ public class LogTest {
|
| assertEquals("Bar MyThrowable MyOtherThrowable", logs.get(logs.size() - 1).msg);
|
| }
|
|
|
| + public void verboseLoggingTest() {
|
| + PermissiveShadowLog.setLevel(Log.VERBOSE);
|
| + List<ShadowLog.LogItem> logs = ShadowLog.getLogs();
|
| +
|
| + Log.wtf("Foo", "Bar");
|
| + Log.e("Foo", "Bar");
|
| + Log.w("Foo", "Bar");
|
| + Log.i("Foo", "Bar");
|
| + Log.d("Foo", "Bar");
|
| + Log.v("Foo", "Bar");
|
| +
|
| + assertEquals(Log.ASSERT, logs.get(0).type);
|
| + assertEquals(Log.ERROR, logs.get(1).type);
|
| + assertEquals(Log.WARN, logs.get(2).type);
|
| + assertEquals(Log.INFO, logs.get(3).type);
|
| + assertEquals(Log.DEBUG, logs.get(4).type);
|
| + assertEquals(Log.VERBOSE, logs.get(5).type);
|
| + assertEquals(6, logs.size());
|
| + }
|
| +
|
| + @Test
|
| + public void debugLoggingTest() {
|
| + PermissiveShadowLog.setLevel(Log.DEBUG);
|
| + List<ShadowLog.LogItem> logs = ShadowLog.getLogs();
|
| +
|
| + Log.wtf("Foo", "Bar");
|
| + Log.e("Foo", "Bar");
|
| + Log.w("Foo", "Bar");
|
| + Log.i("Foo", "Bar");
|
| + Log.d("Foo", "Bar");
|
| + Log.v("Foo", "Bar");
|
| +
|
| + assertEquals(Log.ASSERT, logs.get(0).type);
|
| + assertEquals(Log.ERROR, logs.get(1).type);
|
| + assertEquals(Log.WARN, logs.get(2).type);
|
| + assertEquals(Log.INFO, logs.get(3).type);
|
| + assertEquals(Log.DEBUG, logs.get(4).type);
|
| + assertEquals(5, logs.size());
|
| + }
|
| +
|
| + @Test
|
| + public void infoLoggingTest() {
|
| + PermissiveShadowLog.setLevel(Log.INFO);
|
| + List<ShadowLog.LogItem> logs = ShadowLog.getLogs();
|
| +
|
| + Log.wtf("Foo", "Bar");
|
| + Log.e("Foo", "Bar");
|
| + Log.w("Foo", "Bar");
|
| + Log.i("Foo", "Bar");
|
| + Log.d("Foo", "Bar");
|
| + Log.v("Foo", "Bar");
|
| +
|
| + assertEquals(Log.ASSERT, logs.get(0).type);
|
| + assertEquals(Log.ERROR, logs.get(1).type);
|
| + assertEquals(Log.WARN, logs.get(2).type);
|
| + assertEquals(Log.INFO, logs.get(3).type);
|
| + assertEquals(4, logs.size());
|
| + }
|
| +
|
| + @Test
|
| + public void warnLoggingTest() {
|
| + PermissiveShadowLog.setLevel(Log.WARN);
|
| + List<ShadowLog.LogItem> logs = ShadowLog.getLogs();
|
| +
|
| + Log.wtf("Foo", "Bar");
|
| + Log.e("Foo", "Bar");
|
| + Log.w("Foo", "Bar");
|
| + Log.i("Foo", "Bar");
|
| + Log.d("Foo", "Bar");
|
| + Log.v("Foo", "Bar");
|
| +
|
| + assertEquals(Log.ASSERT, logs.get(0).type);
|
| + assertEquals(Log.ERROR, logs.get(1).type);
|
| + assertEquals(Log.WARN, logs.get(2).type);
|
| + assertEquals(3, logs.size());
|
| + }
|
| +
|
| + @Test
|
| + public void errorLoggingTest() {
|
| + PermissiveShadowLog.setLevel(Log.ERROR);
|
| + List<ShadowLog.LogItem> logs = ShadowLog.getLogs();
|
| +
|
| + Log.wtf("Foo", "Bar");
|
| + Log.e("Foo", "Bar");
|
| + Log.w("Foo", "Bar");
|
| + Log.i("Foo", "Bar");
|
| + Log.d("Foo", "Bar");
|
| + Log.v("Foo", "Bar");
|
| +
|
| + assertEquals(Log.ASSERT, logs.get(0).type);
|
| + assertEquals(Log.ERROR, logs.get(1).type);
|
| + assertEquals(2, logs.size());
|
| + }
|
| +
|
| + @Test
|
| + public void assertLoggingTest() {
|
| + PermissiveShadowLog.setLevel(Log.ASSERT);
|
| + List<ShadowLog.LogItem> logs = ShadowLog.getLogs();
|
| +
|
| + Log.wtf("Foo", "Bar");
|
| + Log.e("Foo", "Bar");
|
| + Log.w("Foo", "Bar");
|
| + Log.i("Foo", "Bar");
|
| + Log.d("Foo", "Bar");
|
| + Log.v("Foo", "Bar");
|
| +
|
| + assertEquals(Log.ASSERT, logs.get(0).type);
|
| + assertEquals(1, logs.size());
|
| + }
|
| +
|
| + @Before
|
| + public void beforeTest() {
|
| + PermissiveShadowLog.reset();
|
| + }
|
| +
|
| /** Needed to allow debug/verbose logging that is disabled by default. */
|
| @Implements(android.util.Log.class)
|
| public static class PermissiveShadowLog extends ShadowLog {
|
| + private static int sLevel = Log.VERBOSE;
|
| +
|
| + /** Sets the log level for all tags. */
|
| + public static void setLevel(int level) {
|
| + sLevel = level;
|
| + }
|
| +
|
| @Implementation
|
| public static boolean isLoggable(String tag, int level) {
|
| - return true;
|
| + return level >= sLevel;
|
| + }
|
| +
|
| + public static void reset() {
|
| + sLevel = Log.VERBOSE;
|
| }
|
| }
|
| }
|
|
|