| Index: ui/android/junit/src/org/chromium/ui/base/ClipboardTest.java
|
| diff --git a/ui/android/junit/src/org/chromium/ui/base/ClipboardTest.java b/ui/android/junit/src/org/chromium/ui/base/ClipboardTest.java
|
| index a4bd96668dbe8fa699626bf578b8f64cbd693cf4..49bc9873b69a631df6f0bc4d41e4d57ba05820f5 100644
|
| --- a/ui/android/junit/src/org/chromium/ui/base/ClipboardTest.java
|
| +++ b/ui/android/junit/src/org/chromium/ui/base/ClipboardTest.java
|
| @@ -4,7 +4,14 @@
|
|
|
| package org.chromium.ui.base;
|
|
|
| +import android.content.ClipData;
|
| +import android.content.Intent;
|
| +import android.text.SpannableString;
|
| +import android.text.style.RelativeSizeSpan;
|
| +
|
| import static org.junit.Assert.assertEquals;
|
| +import static org.junit.Assert.assertNotNull;
|
| +import static org.junit.Assert.assertNull;
|
| import static org.junit.Assert.assertTrue;
|
|
|
| import org.junit.AfterClass;
|
| @@ -25,6 +32,9 @@ import org.chromium.testing.local.LocalRobolectricTestRunner;
|
| @RunWith(LocalRobolectricTestRunner.class)
|
| @Config(manifest = Config.NONE)
|
| public class ClipboardTest {
|
| + private static final String PLAIN_TEXT = "plain";
|
| + private static final String HTML_TEXT = "<span style=\"color: red;\">HTML</span>";
|
| +
|
| @BeforeClass
|
| public static void beforeClass() {
|
| RecordHistogram.setDisabledForTests(true);
|
| @@ -39,7 +49,7 @@ public class ClipboardTest {
|
|
|
| @Test
|
| public void testGetClipboardContentChangeTimeInMillis() {
|
| - ContextUtils.initApplicationContext(RuntimeEnvironment.application);
|
| + ContextUtils.initApplicationContextForTests(RuntimeEnvironment.application);
|
| // Upon launch, the clipboard should be at start of epoch, i.e., ancient.
|
| Clipboard clipboard = Clipboard.getInstance();
|
| assertEquals(0, clipboard.getClipboardContentChangeTimeInMillis());
|
| @@ -47,4 +57,39 @@ public class ClipboardTest {
|
| clipboard.onPrimaryClipChanged();
|
| assertTrue(clipboard.getClipboardContentChangeTimeInMillis() > 0);
|
| }
|
| +
|
| + @Test
|
| + public void testGetHTMLTextAndGetCoercedText() {
|
| + ContextUtils.initApplicationContextForTests(RuntimeEnvironment.application);
|
| + Clipboard clipboard = Clipboard.getInstance();
|
| +
|
| + // HTML text
|
| + ClipData html = ClipData.newHtmlText("html", PLAIN_TEXT, HTML_TEXT);
|
| + clipboard.setPrimaryClipNoException(html);
|
| + assertEquals(PLAIN_TEXT, clipboard.getCoercedText());
|
| + assertEquals(HTML_TEXT, clipboard.getHTMLText());
|
| +
|
| + // Plain text without span
|
| + ClipData plainTextNoSpan = ClipData.newPlainText("plain", PLAIN_TEXT);
|
| + clipboard.setPrimaryClipNoException(plainTextNoSpan);
|
| + assertEquals(PLAIN_TEXT, clipboard.getCoercedText());
|
| + assertNull(clipboard.getHTMLText());
|
| +
|
| + // Plain text with span
|
| + SpannableString spanned = new SpannableString(PLAIN_TEXT);
|
| + spanned.setSpan(new RelativeSizeSpan(2f), 0, 5, 0);
|
| + ClipData plainTextSpan = ClipData.newPlainText("plain", spanned);
|
| + clipboard.setPrimaryClipNoException(plainTextSpan);
|
| + assertEquals(PLAIN_TEXT, clipboard.getCoercedText());
|
| + assertNotNull(clipboard.getHTMLText());
|
| +
|
| + // Intent
|
| + Intent intent = new Intent(Intent.ACTION_GET_CONTENT);
|
| + intent.addCategory(Intent.CATEGORY_OPENABLE);
|
| + intent.setType("*/*");
|
| + ClipData intentClip = ClipData.newIntent("intent", intent);
|
| + clipboard.setPrimaryClipNoException(intentClip);
|
| + assertNotNull(clipboard.getCoercedText());
|
| + assertNull(clipboard.getHTMLText());
|
| + }
|
| }
|
|
|