OLD | NEW |
---|---|
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "build/build_config.h" | 5 #include "build/build_config.h" |
6 | 6 |
7 #include <string> | 7 #include <string> |
8 | 8 |
9 #include "base/basictypes.h" | 9 #include "base/basictypes.h" |
10 #include "base/memory/scoped_ptr.h" | 10 #include "base/memory/scoped_ptr.h" |
(...skipping 13 matching lines...) Expand all Loading... | |
24 #endif | 24 #endif |
25 | 25 |
26 #if defined(OS_ANDROID) | 26 #if defined(OS_ANDROID) |
27 #include "base/android/jni_android.h" | 27 #include "base/android/jni_android.h" |
28 #endif | 28 #endif |
29 | 29 |
30 #if defined(OS_WIN) || defined(USE_AURA) | 30 #if defined(OS_WIN) || defined(USE_AURA) |
31 #include "base/message_loop.h" | 31 #include "base/message_loop.h" |
32 #endif | 32 #endif |
33 | 33 |
34 #if defined(OS_ANDROID) | |
35 using base::android::MethodID; | |
36 #endif | |
joth
2012/10/04 17:59:59
nit: put this down inside the test where you use i
bulach
2012/10/04 18:58:17
Done (indeed, there was already an "using" clause
| |
37 | |
34 namespace ui { | 38 namespace ui { |
35 | 39 |
36 class ClipboardTest : public PlatformTest { | 40 class ClipboardTest : public PlatformTest { |
37 protected: | 41 protected: |
38 Clipboard& clipboard() { return clipboard_; } | 42 Clipboard& clipboard() { return clipboard_; } |
39 | 43 |
40 private: | 44 private: |
41 MessageLoopForUI message_loop_; | 45 MessageLoopForUI message_loop_; |
42 Clipboard clipboard_; | 46 Clipboard clipboard_; |
43 }; | 47 }; |
(...skipping 606 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
650 | 654 |
651 JNIEnv* env = base::android::AttachCurrentThread(); | 655 JNIEnv* env = base::android::AttachCurrentThread(); |
652 ASSERT_TRUE(env); | 656 ASSERT_TRUE(env); |
653 | 657 |
654 jobject context = base::android::GetApplicationContext(); | 658 jobject context = base::android::GetApplicationContext(); |
655 ASSERT_TRUE(context); | 659 ASSERT_TRUE(context); |
656 | 660 |
657 ScopedJavaLocalRef<jclass> context_class = | 661 ScopedJavaLocalRef<jclass> context_class = |
658 base::android::GetClass(env, "android/content/Context"); | 662 base::android::GetClass(env, "android/content/Context"); |
659 | 663 |
660 jmethodID get_system_service = base::android::GetMethodID(env, context_class, | 664 jmethodID get_system_service = MethodID::Get< |
661 "getSystemService", "(Ljava/lang/String;)Ljava/lang/Object;"); | 665 MethodID::METHODTYPE_NORMAL, MethodID::EXCEPTIONCHECK_YES>( |
666 env, context_class.obj(), "getSystemService", | |
667 "(Ljava/lang/String;)Ljava/lang/Object;"); | |
662 | 668 |
663 // Retrieve the system service. | 669 // Retrieve the system service. |
664 ScopedJavaLocalRef<jstring> service_name(env, env->NewStringUTF("clipboard")); | 670 ScopedJavaLocalRef<jstring> service_name(env, env->NewStringUTF("clipboard")); |
665 ScopedJavaLocalRef<jobject> clipboard_manager( | 671 ScopedJavaLocalRef<jobject> clipboard_manager( |
666 env, env->CallObjectMethod( | 672 env, env->CallObjectMethod( |
667 context, get_system_service, service_name.obj())); | 673 context, get_system_service, service_name.obj())); |
668 ASSERT_TRUE(clipboard_manager.obj() && !base::android::ClearException(env)); | 674 ASSERT_TRUE(clipboard_manager.obj() && !base::android::ClearException(env)); |
669 | 675 |
670 ScopedJavaLocalRef<jclass> clipboard_class = | 676 ScopedJavaLocalRef<jclass> clipboard_class = |
671 base::android::GetClass(env, "android/text/ClipboardManager"); | 677 base::android::GetClass(env, "android/text/ClipboardManager"); |
672 jmethodID set_text = base::android::GetMethodID(env, clipboard_class, | 678 jmethodID set_text = MethodID::Get< |
673 "setText", "(Ljava/lang/CharSequence;)V"); | 679 MethodID::METHODTYPE_NORMAL, MethodID::EXCEPTIONCHECK_YES>( |
680 env, clipboard_class.obj(), "setText", "(Ljava/lang/CharSequence;)V"); | |
674 | 681 |
675 // Will need to call toString as CharSequence is not always a String. | 682 // Will need to call toString as CharSequence is not always a String. |
676 env->CallVoidMethod(clipboard_manager.obj(), | 683 env->CallVoidMethod(clipboard_manager.obj(), |
677 set_text, | 684 set_text, |
678 env->NewStringUTF(new_value.c_str())); | 685 env->NewStringUTF(new_value.c_str())); |
679 | 686 |
680 // The bitmap that should have been available should be gone. | 687 // The bitmap that should have been available should be gone. |
681 EXPECT_FALSE(clipboard().IsFormatAvailable(Clipboard::GetBitmapFormatType(), | 688 EXPECT_FALSE(clipboard().IsFormatAvailable(Clipboard::GetBitmapFormatType(), |
682 Clipboard::BUFFER_STANDARD)); | 689 Clipboard::BUFFER_STANDARD)); |
683 | 690 |
684 // Make sure some text is available | 691 // Make sure some text is available |
685 EXPECT_TRUE(clipboard().IsFormatAvailable( | 692 EXPECT_TRUE(clipboard().IsFormatAvailable( |
686 Clipboard::GetPlainTextWFormatType(), Clipboard::BUFFER_STANDARD)); | 693 Clipboard::GetPlainTextWFormatType(), Clipboard::BUFFER_STANDARD)); |
687 | 694 |
688 // Make sure the text is what we inserted while simulating the other app | 695 // Make sure the text is what we inserted while simulating the other app |
689 std::string contents; | 696 std::string contents; |
690 clipboard().ReadAsciiText(Clipboard::BUFFER_STANDARD, &contents); | 697 clipboard().ReadAsciiText(Clipboard::BUFFER_STANDARD, &contents); |
691 EXPECT_EQ(contents, new_value); | 698 EXPECT_EQ(contents, new_value); |
692 } | 699 } |
693 #endif | 700 #endif |
694 } // namespace ui | 701 } // namespace ui |
OLD | NEW |