Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(64)

Side by Side Diff: ui/base/clipboard/clipboard_unittest.cc

Issue 11038015: Android: lazy initialization for method id. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Rebased Created 8 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « ui/base/clipboard/clipboard_android.cc ('k') | webkit/glue/fling_animator_impl_android.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 628 matching lines...) Expand 10 before | Expand all | Expand 10 after
639 { 639 {
640 ScopedClipboardWriter clipboard_writer(&clipboard(), 640 ScopedClipboardWriter clipboard_writer(&clipboard(),
641 Clipboard::BUFFER_STANDARD); 641 Clipboard::BUFFER_STANDARD);
642 clipboard_writer.WriteBitmapFromPixels(kFakeBitmap, gfx::Size(3, 4)); 642 clipboard_writer.WriteBitmapFromPixels(kFakeBitmap, gfx::Size(3, 4));
643 } 643 }
644 644
645 // 645 //
646 // Simulate that another application copied something in the Clipboard 646 // Simulate that another application copied something in the Clipboard
647 // 647 //
648 std::string new_value("Some text copied by some other app"); 648 std::string new_value("Some text copied by some other app");
649 using base::android::MethodID;
649 using base::android::ScopedJavaLocalRef; 650 using base::android::ScopedJavaLocalRef;
650 651
651 JNIEnv* env = base::android::AttachCurrentThread(); 652 JNIEnv* env = base::android::AttachCurrentThread();
652 ASSERT_TRUE(env); 653 ASSERT_TRUE(env);
653 654
654 jobject context = base::android::GetApplicationContext(); 655 jobject context = base::android::GetApplicationContext();
655 ASSERT_TRUE(context); 656 ASSERT_TRUE(context);
656 657
657 ScopedJavaLocalRef<jclass> context_class = 658 ScopedJavaLocalRef<jclass> context_class =
658 base::android::GetClass(env, "android/content/Context"); 659 base::android::GetClass(env, "android/content/Context");
659 660
660 jmethodID get_system_service = base::android::GetMethodID(env, context_class, 661 jmethodID get_system_service = MethodID::Get<MethodID::TYPE_INSTANCE>(
661 "getSystemService", "(Ljava/lang/String;)Ljava/lang/Object;"); 662 env, context_class.obj(), "getSystemService",
663 "(Ljava/lang/String;)Ljava/lang/Object;");
662 664
663 // Retrieve the system service. 665 // Retrieve the system service.
664 ScopedJavaLocalRef<jstring> service_name(env, env->NewStringUTF("clipboard")); 666 ScopedJavaLocalRef<jstring> service_name(env, env->NewStringUTF("clipboard"));
665 ScopedJavaLocalRef<jobject> clipboard_manager( 667 ScopedJavaLocalRef<jobject> clipboard_manager(
666 env, env->CallObjectMethod( 668 env, env->CallObjectMethod(
667 context, get_system_service, service_name.obj())); 669 context, get_system_service, service_name.obj()));
668 ASSERT_TRUE(clipboard_manager.obj() && !base::android::ClearException(env)); 670 ASSERT_TRUE(clipboard_manager.obj() && !base::android::ClearException(env));
669 671
670 ScopedJavaLocalRef<jclass> clipboard_class = 672 ScopedJavaLocalRef<jclass> clipboard_class =
671 base::android::GetClass(env, "android/text/ClipboardManager"); 673 base::android::GetClass(env, "android/text/ClipboardManager");
672 jmethodID set_text = base::android::GetMethodID(env, clipboard_class, 674 jmethodID set_text = MethodID::Get<MethodID::TYPE_INSTANCE>(
673 "setText", "(Ljava/lang/CharSequence;)V"); 675 env, clipboard_class.obj(), "setText", "(Ljava/lang/CharSequence;)V");
674 676
675 // Will need to call toString as CharSequence is not always a String. 677 // Will need to call toString as CharSequence is not always a String.
676 env->CallVoidMethod(clipboard_manager.obj(), 678 env->CallVoidMethod(clipboard_manager.obj(),
677 set_text, 679 set_text,
678 env->NewStringUTF(new_value.c_str())); 680 env->NewStringUTF(new_value.c_str()));
679 681
680 // The bitmap that should have been available should be gone. 682 // The bitmap that should have been available should be gone.
681 EXPECT_FALSE(clipboard().IsFormatAvailable(Clipboard::GetBitmapFormatType(), 683 EXPECT_FALSE(clipboard().IsFormatAvailable(Clipboard::GetBitmapFormatType(),
682 Clipboard::BUFFER_STANDARD)); 684 Clipboard::BUFFER_STANDARD));
683 685
684 // Make sure some text is available 686 // Make sure some text is available
685 EXPECT_TRUE(clipboard().IsFormatAvailable( 687 EXPECT_TRUE(clipboard().IsFormatAvailable(
686 Clipboard::GetPlainTextWFormatType(), Clipboard::BUFFER_STANDARD)); 688 Clipboard::GetPlainTextWFormatType(), Clipboard::BUFFER_STANDARD));
687 689
688 // Make sure the text is what we inserted while simulating the other app 690 // Make sure the text is what we inserted while simulating the other app
689 std::string contents; 691 std::string contents;
690 clipboard().ReadAsciiText(Clipboard::BUFFER_STANDARD, &contents); 692 clipboard().ReadAsciiText(Clipboard::BUFFER_STANDARD, &contents);
691 EXPECT_EQ(contents, new_value); 693 EXPECT_EQ(contents, new_value);
692 } 694 }
693 #endif 695 #endif
694 } // namespace ui 696 } // namespace ui
OLDNEW
« no previous file with comments | « ui/base/clipboard/clipboard_android.cc ('k') | webkit/glue/fling_animator_impl_android.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698