summaryrefslogtreecommitdiffstats
path: root/tests/AndroidTests
diff options
context:
space:
mode:
authorAndroid (Google) Code Review <android-gerrit@google.com>2009-07-16 17:53:44 -0700
committerAndroid Git Automerger <android-git-automerger@android.com>2009-07-16 17:53:44 -0700
commitcad18157e73a93ff5d7c41fdb9e1abd0ca7b5f61 (patch)
tree24eb917a5a0e7001b6b7ffec38771b1c1121db96 /tests/AndroidTests
parentdc6399bcdf18c9046507088f1db543c991f46731 (diff)
parentc93af6dc5bc78f02d4ee549890da12dc669fc2fe (diff)
downloadframeworks_base-cad18157e73a93ff5d7c41fdb9e1abd0ca7b5f61.zip
frameworks_base-cad18157e73a93ff5d7c41fdb9e1abd0ca7b5f61.tar.gz
frameworks_base-cad18157e73a93ff5d7c41fdb9e1abd0ca7b5f61.tar.bz2
am c93af6dc: Merge change 7441 into donut
Merge commit 'c93af6dc5bc78f02d4ee549890da12dc669fc2fe' * commit 'c93af6dc5bc78f02d4ee549890da12dc669fc2fe': Allow system colors in <font> tags
Diffstat (limited to 'tests/AndroidTests')
-rw-r--r--tests/AndroidTests/src/com/android/unit_tests/HtmlTest.java62
1 files changed, 58 insertions, 4 deletions
diff --git a/tests/AndroidTests/src/com/android/unit_tests/HtmlTest.java b/tests/AndroidTests/src/com/android/unit_tests/HtmlTest.java
index 27da4f1..027730f 100644
--- a/tests/AndroidTests/src/com/android/unit_tests/HtmlTest.java
+++ b/tests/AndroidTests/src/com/android/unit_tests/HtmlTest.java
@@ -16,11 +16,25 @@
package com.android.unit_tests;
+import android.content.res.ColorStateList;
+import android.content.res.Resources;
import android.graphics.Typeface;
import android.test.suitebuilder.annotation.MediumTest;
import android.test.suitebuilder.annotation.SmallTest;
-import android.text.*;
-import android.text.style.*;
+import android.text.Html;
+import android.text.Spannable;
+import android.text.SpannableString;
+import android.text.Spanned;
+import android.text.style.ForegroundColorSpan;
+import android.text.style.QuoteSpan;
+import android.text.style.StrikethroughSpan;
+import android.text.style.StyleSpan;
+import android.text.style.SubscriptSpan;
+import android.text.style.SuperscriptSpan;
+import android.text.style.TextAppearanceSpan;
+import android.text.style.TypefaceSpan;
+import android.text.style.URLSpan;
+import android.text.style.UnderlineSpan;
import junit.framework.TestCase;
@@ -35,14 +49,54 @@ public class HtmlTest extends TestCase {
s = Html.fromHtml("<font color=\"#00FF00\">something</font>");
colors = s.getSpans(0, s.length(), ForegroundColorSpan.class);
- assertEquals(colors[0].getForegroundColor(), 0xFF00FF00);
+ assertEquals(1, colors.length);
+ assertEquals(0xFF00FF00, colors[0].getForegroundColor());
s = Html.fromHtml("<font color=\"navy\">something</font>");
colors = s.getSpans(0, s.length(), ForegroundColorSpan.class);
- assertEquals(colors[0].getForegroundColor(), 0xFF000080);
+ assertEquals(1, colors.length);
+ assertEquals(0xFF000080, colors[0].getForegroundColor());
s = Html.fromHtml("<font color=\"gibberish\">something</font>");
colors = s.getSpans(0, s.length(), ForegroundColorSpan.class);
+ assertEquals(0, colors.length);
+ }
+
+ @MediumTest
+ public void testResourceColor() throws Exception {
+ ColorStateList c =
+ Resources.getSystem().getColorStateList(android.R.color.primary_text_dark);
+ Spanned s;
+ TextAppearanceSpan[] colors;
+
+ s = Html.fromHtml("<font color=\"@android:color/primary_text_dark\">something</font>");
+ colors = s.getSpans(0, s.length(), TextAppearanceSpan.class);
+ assertEquals(1, colors.length);
+ assertEquals(c.toString(), colors[0].getTextColor().toString());
+
+ s = Html.fromHtml("<font color=\"@android:primary_text_dark\">something</font>");
+ colors = s.getSpans(0, s.length(), TextAppearanceSpan.class);
+ assertEquals(1, colors.length);
+ assertEquals(c.toString(), colors[0].getTextColor().toString());
+
+ s = Html.fromHtml("<font color=\"@color/primary_text_dark\">something</font>");
+ colors = s.getSpans(0, s.length(), TextAppearanceSpan.class);
+ assertEquals(1, colors.length);
+ assertEquals(c.toString(), colors[0].getTextColor().toString());
+
+ s = Html.fromHtml("<font color=\"@primary_text_dark\">something</font>");
+ colors = s.getSpans(0, s.length(), TextAppearanceSpan.class);
+ assertEquals(1, colors.length);
+ assertEquals(c.toString(), colors[0].getTextColor().toString());
+
+ s = Html.fromHtml("<font color=\"@" + android.R.color.primary_text_dark
+ + "\">something</font>");
+ colors = s.getSpans(0, s.length(), TextAppearanceSpan.class);
+ assertEquals(1, colors.length);
+ assertEquals(c.toString(), colors[0].getTextColor().toString());
+
+ s = Html.fromHtml("<font color=\"gibberish\">something</font>");
+ colors = s.getSpans(0, s.length(), TextAppearanceSpan.class);
assertEquals(colors.length, 0);
}