Chromium Code Reviews| Index: ui/base/clipboard/clipboard_unittest.cc |
| diff --git a/ui/base/clipboard/clipboard_unittest.cc b/ui/base/clipboard/clipboard_unittest.cc |
| index 1332f5ed1528879cc190c4b253efd92f9a8dd905..2956e9d424abb71cc1493ac5ab765f7781abee77 100644 |
| --- a/ui/base/clipboard/clipboard_unittest.cc |
| +++ b/ui/base/clipboard/clipboard_unittest.cc |
| @@ -23,6 +23,10 @@ |
| #include "ui/base/clipboard/clipboard_util_win.h" |
| #endif |
| +#if defined(OS_ANDROID) |
| +#include "base/android/jni_android.h" |
| +#endif |
| + |
| namespace ui { |
| #if defined(OS_WIN) |
| @@ -334,7 +338,7 @@ TEST_F(ClipboardTest, URLTest) { |
| clipboard.ReadAsciiText(Clipboard::BUFFER_STANDARD, &ascii_text); |
| EXPECT_EQ(UTF16ToUTF8(url), ascii_text); |
| -#if defined(OS_POSIX) && !defined(OS_MACOSX) |
| +#if defined(OS_POSIX) && !defined(OS_MACOSX) && !defined(OS_ANDROID) |
| ascii_text.clear(); |
| clipboard.ReadAsciiText(Clipboard::BUFFER_SELECTION, &ascii_text); |
| EXPECT_EQ(UTF16ToUTF8(url), ascii_text); |
| @@ -387,7 +391,7 @@ TEST_F(ClipboardTest, SharedBitmapTest) { |
| // The following test somehow fails on GTK. The image when read back from the |
| // clipboard has the alpha channel set to 0xFF for some reason. The other |
| // channels stay intact. So I am turning this on only for aura. |
| -#if defined(USE_AURA) && !defined(OS_WIN) |
| +#if (defined(USE_AURA) && !defined(OS_WIN)) || defined(OS_ANDROID) |
| TEST_F(ClipboardTest, MultipleBitmapReadWriteTest) { |
| Clipboard clipboard; |
| @@ -649,4 +653,75 @@ TEST_F(ClipboardTest, WriteEverything) { |
| // Passes if we don't crash. |
| } |
| +#if defined(OS_ANDROID) |
| + |
| +// Test that if another application writes some text to the pasteboard the |
| +// clipboard properly invalidates other types. |
| +TEST_F(ClipboardTest, InternalClipboardInvalidation) { |
| + unsigned int fake_bitmap[] = { |
|
dcheng
2012/07/02 22:50:19
const unsigned int kFakeBitmap
cjhopman
2012/07/02 23:26:51
unsigned int fake_bitmap is consistent with the re
dcheng
2012/07/02 23:40:26
Hm. Well... how about fixing this one, and I'll fi
cjhopman
2012/07/02 23:53:28
Done.
|
| + 0x46155189, 0xF6A55C8D, 0x79845674, 0xFA57BD89, |
| + 0x78FD46AE, 0x87C64F5A, 0x36EDC5AF, 0x4378F568, |
| + 0x91E9F63A, 0xC31EA14F, 0x69AB32DF, 0x643A3FD1, |
| + }; |
| + |
| + // Write a bitmap in our clipboard. |
| + Clipboard clipboard; |
| + { |
| + ScopedClipboardWriter clipboard_writer(&clipboard, |
| + Clipboard::BUFFER_STANDARD); |
| + clipboard_writer.WriteBitmapFromPixels(fake_bitmap, gfx::Size(3, 4)); |
| + } |
| + |
| + // |
| + // Simulate that another application copied something in the Clipboard |
| + // |
| + std::string new_value("Some text copied by some other app"); |
| + using base::android::ScopedJavaLocalRef; |
| + |
| + JNIEnv* env = base::android::AttachCurrentThread(); |
| + DCHECK(env); |
|
dcheng
2012/07/02 22:50:19
ASSERT instead of DCHECK in unit tests.
cjhopman
2012/07/02 23:26:51
Done.
|
| + // Get the context. |
| + jobject context = base::android::GetApplicationContext(); |
| + DCHECK(context); |
| + |
| + // Get the context class. |
| + ScopedJavaLocalRef<jclass> context_class = |
| + base::android::GetClass(env, "android/content/Context"); |
| + |
| + // Get the system service method. |
| + jmethodID get_system_service = base::android::GetMethodID(env, context_class, |
| + "getSystemService", "(Ljava/lang/String;)Ljava/lang/Object;"); |
| + |
| + // Retrieve the system service. |
| + ScopedJavaLocalRef<jstring> service_name(env, env->NewStringUTF("clipboard")); |
| + ScopedJavaLocalRef<jobject> clipboard_manager( |
| + env, env->CallObjectMethod( |
| + context, get_system_service, service_name.obj())); |
| + DCHECK(clipboard_manager.obj() && !base::android::ClearException(env)); |
| + |
| + // Retain a few methods we'll keep using. |
| + ScopedJavaLocalRef<jclass> clipboard_class = |
| + base::android::GetClass(env, "android/text/ClipboardManager"); |
| + jmethodID set_text = base::android::GetMethodID(env, clipboard_class, |
| + "setText", "(Ljava/lang/CharSequence;)V"); |
| + |
| + // Will need to call toString as CharSequence is not always a String. |
| + env->CallVoidMethod(clipboard_manager.obj(), |
| + set_text, |
| + env->NewStringUTF(new_value.c_str())); |
| + |
| + // The bitmap that should have been available should be gone. |
| + EXPECT_FALSE(clipboard.IsFormatAvailable(Clipboard::GetBitmapFormatType(), |
| + Clipboard::BUFFER_STANDARD)); |
| + |
| + // Make sure some text is available |
| + EXPECT_TRUE(clipboard.IsFormatAvailable( |
| + Clipboard::GetPlainTextWFormatType(), Clipboard::BUFFER_STANDARD)); |
| + |
| + // Make sure the text is what we inserted while simulating the other app |
| + std::string contents; |
| + clipboard.ReadAsciiText(Clipboard::BUFFER_STANDARD, &contents); |
| + EXPECT_TRUE(!contents.compare(new_value)); |
|
dcheng
2012/07/02 22:50:19
EXPECT_EQ() might read a bit more naturally.
cjhopman
2012/07/02 23:26:51
Done.
|
| +} |
| +#endif |
| } // namespace ui |