| Index: ui/base/clipboard/clipboard_test_template.h
|
| diff --git a/ui/base/clipboard/clipboard_unittest.cc b/ui/base/clipboard/clipboard_test_template.h
|
| similarity index 80%
|
| copy from ui/base/clipboard/clipboard_unittest.cc
|
| copy to ui/base/clipboard/clipboard_test_template.h
|
| index b2bb63c81bee41097ff2dd77a4590b03f6153d0f..2a6c2a72b3b03e70657482fe04c1ba13ce1fb19b 100644
|
| --- a/ui/base/clipboard/clipboard_unittest.cc
|
| +++ b/ui/base/clipboard/clipboard_test_template.h
|
| @@ -1,6 +1,16 @@
|
| // Copyright (c) 2012 The Chromium Authors. All rights reserved.
|
| // Use of this source code is governed by a BSD-style license that can be
|
| // found in the LICENSE file.
|
| +//
|
| +// Note: This header doesn't use REGISTER_TYPED_TEST_CASE_P like most
|
| +// type-parameterized gtests. There are lot of test cases in here that are only
|
| +// enabled on certain platforms. However, preprocessor directives in macro
|
| +// arguments result in undefined behavior (and don't work on MSVC). Instead,
|
| +// 'parameterized' tests should typedef TypesToTest (which is used to
|
| +// instantiate the tests using the TYPED_TEST_CASE macro) and then #include this
|
| +// header.
|
| +// TODO(dcheng): This is really horrible. In general, all tests should run on
|
| +// all platforms, to avoid this mess.
|
|
|
| #include "build/build_config.h"
|
|
|
| @@ -21,17 +31,13 @@
|
| #include "third_party/skia/include/core/SkUnPreMultiply.h"
|
| #include "ui/base/clipboard/clipboard.h"
|
| #include "ui/base/clipboard/scoped_clipboard_writer.h"
|
| +#include "ui/base/test/test_clipboard.h"
|
| #include "ui/gfx/size.h"
|
|
|
| #if defined(OS_WIN)
|
| #include "ui/base/clipboard/clipboard_util_win.h"
|
| #endif
|
|
|
| -#if defined(OS_ANDROID)
|
| -#include "base/android/jni_android.h"
|
| -#include "base/android/jni_string.h"
|
| -#endif
|
| -
|
| #if defined(USE_AURA)
|
| #include "ui/events/platform/platform_event_source.h"
|
| #endif
|
| @@ -76,27 +82,13 @@ class ClipboardTest : public PlatformTest {
|
| Clipboard* const clipboard_;
|
| };
|
|
|
| -namespace {
|
| -
|
| -bool MarkupMatches(const base::string16& expected_markup,
|
| - const base::string16& actual_markup) {
|
| - return actual_markup.find(expected_markup) != base::string16::npos;
|
| -}
|
| -
|
| -} // namespace
|
| -
|
| -struct PlatformClipboardTraits {
|
| - static Clipboard* Create() {
|
| - return Clipboard::GetForCurrentThread();
|
| - }
|
| -
|
| - static void Destroy(Clipboard* clipboard) {
|
| - ASSERT_EQ(Clipboard::GetForCurrentThread(), clipboard);
|
| - Clipboard::DestroyClipboardForCurrentThread();
|
| - }
|
| +// Hack for tests that need to call static methods of ClipboardTest.
|
| +struct NullClipboardTraits {
|
| + static Clipboard* Create() { return nullptr; }
|
| + static void Destroy(Clipboard*) {}
|
| };
|
|
|
| -TYPED_TEST_CASE(ClipboardTest, PlatformClipboardTraits);
|
| +TYPED_TEST_CASE(ClipboardTest, TypesToTest);
|
|
|
| TYPED_TEST(ClipboardTest, ClearTest) {
|
| {
|
| @@ -145,10 +137,13 @@ TYPED_TEST(ClipboardTest, HTMLTest) {
|
|
|
| EXPECT_TRUE(this->clipboard().IsFormatAvailable(
|
| Clipboard::GetHtmlFormatType(), CLIPBOARD_TYPE_COPY_PASTE));
|
| - uint32 ignored;
|
| + uint32 fragment_start;
|
| + uint32 fragment_end;
|
| this->clipboard().ReadHTML(CLIPBOARD_TYPE_COPY_PASTE, &markup_result,
|
| - &url_result, &ignored, &ignored);
|
| - EXPECT_PRED2(MarkupMatches, markup, markup_result);
|
| + &url_result, &fragment_start, &fragment_end);
|
| + EXPECT_LE(markup.size(), fragment_end - fragment_start);
|
| + EXPECT_EQ(markup,
|
| + markup_result.substr(fragment_end - markup.size(), markup.size()));
|
| #if defined(OS_WIN)
|
| // TODO(playmobil): It's not clear that non windows clipboards need to support
|
| // this.
|
| @@ -205,11 +200,14 @@ TYPED_TEST(ClipboardTest, MultipleBufferTest) {
|
| this->clipboard().ReadText(CLIPBOARD_TYPE_COPY_PASTE, &text_result);
|
| EXPECT_EQ(text, text_result);
|
|
|
| - uint32 ignored;
|
| base::string16 markup_result;
|
| + uint32 fragment_start;
|
| + uint32 fragment_end;
|
| this->clipboard().ReadHTML(CLIPBOARD_TYPE_SELECTION, &markup_result,
|
| - &url_result, &ignored, &ignored);
|
| - EXPECT_PRED2(MarkupMatches, markup, markup_result);
|
| + &url_result, &fragment_start, &fragment_end);
|
| + EXPECT_LE(markup.size(), fragment_end - fragment_start);
|
| + EXPECT_EQ(markup,
|
| + markup_result.substr(fragment_end - markup.size(), markup.size()));
|
| }
|
| #endif
|
|
|
| @@ -227,10 +225,13 @@ TYPED_TEST(ClipboardTest, TrickyHTMLTest) {
|
|
|
| EXPECT_TRUE(this->clipboard().IsFormatAvailable(
|
| Clipboard::GetHtmlFormatType(), CLIPBOARD_TYPE_COPY_PASTE));
|
| - uint32 ignored;
|
| + uint32 fragment_start;
|
| + uint32 fragment_end;
|
| this->clipboard().ReadHTML(CLIPBOARD_TYPE_COPY_PASTE, &markup_result,
|
| - &url_result, &ignored, &ignored);
|
| - EXPECT_PRED2(MarkupMatches, markup, markup_result);
|
| + &url_result, &fragment_start, &fragment_end);
|
| + EXPECT_LE(markup.size(), fragment_end - fragment_start);
|
| + EXPECT_EQ(markup,
|
| + markup_result.substr(fragment_end - markup.size(), markup.size()));
|
| #if defined(OS_WIN)
|
| // TODO(playmobil): It's not clear that non windows clipboards need to support
|
| // this.
|
| @@ -238,8 +239,9 @@ TYPED_TEST(ClipboardTest, TrickyHTMLTest) {
|
| #endif // defined(OS_WIN)
|
| }
|
|
|
| -#if defined(OS_WIN)
|
| -TYPED_TEST(ClipboardTest, UniodeHTMLTest) {
|
| +// Some platforms store HTML as UTF-8 internally. Make sure fragment indices are
|
| +// adjusted appropriately when converting back to UTF-16.
|
| +TYPED_TEST(ClipboardTest, UnicodeHTMLTest) {
|
| base::string16 markup(UTF8ToUTF16("<div>A \xc3\xb8 \xe6\xb0\xb4</div>")),
|
| markup_result;
|
| std::string url, url_result;
|
| @@ -255,13 +257,13 @@ TYPED_TEST(ClipboardTest, UniodeHTMLTest) {
|
| uint32 fragment_end;
|
| this->clipboard().ReadHTML(CLIPBOARD_TYPE_COPY_PASTE, &markup_result,
|
| &url_result, &fragment_start, &fragment_end);
|
| - EXPECT_PRED2(MarkupMatches, markup, markup_result);
|
| + EXPECT_LE(markup.size(), fragment_end - fragment_start);
|
| + EXPECT_EQ(markup,
|
| + markup_result.substr(fragment_end - markup.size(), markup.size()));
|
| +#if defined(OS_WIN)
|
| EXPECT_EQ(url, url_result);
|
| - // Make sure that fragment indices were adjusted when converting.
|
| - EXPECT_EQ(36, fragment_start);
|
| - EXPECT_EQ(52, fragment_end);
|
| +#endif
|
| }
|
| -#endif // defined(OS_WIN)
|
|
|
| // TODO(estade): Port the following test (decide what target we use for urls)
|
| #if !defined(OS_POSIX) || defined(OS_MACOSX)
|
| @@ -300,10 +302,13 @@ TYPED_TEST(ClipboardTest, MultiFormatTest) {
|
| Clipboard::GetPlainTextWFormatType(), CLIPBOARD_TYPE_COPY_PASTE));
|
| EXPECT_TRUE(this->clipboard().IsFormatAvailable(
|
| Clipboard::GetPlainTextFormatType(), CLIPBOARD_TYPE_COPY_PASTE));
|
| - uint32 ignored;
|
| + uint32 fragment_start;
|
| + uint32 fragment_end;
|
| this->clipboard().ReadHTML(CLIPBOARD_TYPE_COPY_PASTE, &markup_result,
|
| - &url_result, &ignored, &ignored);
|
| - EXPECT_PRED2(MarkupMatches, markup, markup_result);
|
| + &url_result, &fragment_start, &fragment_end);
|
| + EXPECT_LE(markup.size(), fragment_end - fragment_start);
|
| + EXPECT_EQ(markup,
|
| + markup_result.substr(fragment_end - markup.size(), markup.size()));
|
| #if defined(OS_WIN)
|
| // TODO(playmobil): It's not clear that non windows clipboards need to support
|
| // this.
|
| @@ -336,7 +341,8 @@ TYPED_TEST(ClipboardTest, URLTest) {
|
| this->clipboard().ReadAsciiText(CLIPBOARD_TYPE_COPY_PASTE, &ascii_text);
|
| EXPECT_EQ(UTF16ToUTF8(url), ascii_text);
|
|
|
| -#if defined(OS_POSIX) && !defined(OS_MACOSX) && !defined(OS_ANDROID)
|
| +#if defined(OS_POSIX) && !defined(OS_MACOSX) && !defined(OS_ANDROID) && \
|
| + !defined(OS_CHROMEOS)
|
| ascii_text.clear();
|
| this->clipboard().ReadAsciiText(CLIPBOARD_TYPE_SELECTION, &ascii_text);
|
| EXPECT_EQ(UTF16ToUTF8(url), ascii_text);
|
| @@ -384,13 +390,13 @@ static void TestBitmapWrite(Clipboard* clipboard,
|
|
|
| Clipboard::ObjectMap objects;
|
| objects[Clipboard::CBF_SMBITMAP] = params;
|
| - ASSERT_TRUE(Clipboard::ReplaceSharedMemHandle(
|
| - &objects, handle_to_share, current_process));
|
| + ASSERT_TRUE(Clipboard::ReplaceSharedMemHandle(&objects, handle_to_share,
|
| + current_process));
|
|
|
| // This is pretty ugly, but the template type parameter is irrelevant... and
|
| // this test will be going away anyway.
|
| - ClipboardTest<PlatformClipboardTraits>::WriteObjectsToClipboard(clipboard,
|
| - objects);
|
| + ClipboardTest<NullClipboardTraits>::WriteObjectsToClipboard(clipboard,
|
| + objects);
|
|
|
| EXPECT_TRUE(clipboard->IsFormatAvailable(Clipboard::GetBitmapFormatType(),
|
| CLIPBOARD_TYPE_COPY_PASTE));
|
| @@ -402,8 +408,7 @@ static void TestBitmapWrite(Clipboard* clipboard,
|
| for (int i = 0; i < image.width(); ++i) {
|
| int offset = i + j * image.width();
|
| uint32 pixel = SkPreMultiplyColor(bitmap_data[offset]);
|
| - EXPECT_EQ(pixel, row_address[i])
|
| - << "i = " << i << ", j = " << j;
|
| + EXPECT_EQ(pixel, row_address[i]) << "i = " << i << ", j = " << j;
|
| }
|
| }
|
| }
|
| @@ -626,9 +631,9 @@ TYPED_TEST(ClipboardTest, MultipleDataTest) {
|
| TYPED_TEST(ClipboardTest, HyperlinkTest) {
|
| const std::string kTitle("The <Example> Company's \"home page\"");
|
| const std::string kUrl("http://www.example.com?x=3<=3#\"'<>");
|
| - const std::string kExpectedHtml(
|
| + const base::string16 kExpectedHtml(UTF8ToUTF16(
|
| "<a href=\"http://www.example.com?x=3&lt=3#"'<>\">"
|
| - "The <Example> Company's "home page"</a>");
|
| + "The <Example> Company's "home page"</a>"));
|
|
|
| std::string url_result;
|
| base::string16 html_result;
|
| @@ -639,10 +644,13 @@ TYPED_TEST(ClipboardTest, HyperlinkTest) {
|
|
|
| EXPECT_TRUE(this->clipboard().IsFormatAvailable(
|
| Clipboard::GetHtmlFormatType(), CLIPBOARD_TYPE_COPY_PASTE));
|
| - uint32 ignored;
|
| + uint32 fragment_start;
|
| + uint32 fragment_end;
|
| this->clipboard().ReadHTML(CLIPBOARD_TYPE_COPY_PASTE, &html_result,
|
| - &url_result, &ignored, &ignored);
|
| - EXPECT_PRED2(MarkupMatches, ASCIIToUTF16(kExpectedHtml), html_result);
|
| + &url_result, &fragment_start, &fragment_end);
|
| + EXPECT_EQ(kExpectedHtml,
|
| + html_result.substr(fragment_end - kExpectedHtml.size(),
|
| + kExpectedHtml.size()));
|
| }
|
| #endif
|
|
|
| @@ -667,36 +675,38 @@ void HtmlTestHelper(const std::string& cf_html,
|
| TYPED_TEST(ClipboardTest, HtmlTest) {
|
| // Test converting from CF_HTML format data with <!--StartFragment--> and
|
| // <!--EndFragment--> comments, like from MS Word.
|
| - HtmlTestHelper("Version:1.0\r\n"
|
| - "StartHTML:0000000105\r\n"
|
| - "EndHTML:0000000199\r\n"
|
| - "StartFragment:0000000123\r\n"
|
| - "EndFragment:0000000161\r\n"
|
| - "\r\n"
|
| - "<html>\r\n"
|
| - "<body>\r\n"
|
| - "<!--StartFragment-->\r\n"
|
| - "\r\n"
|
| - "<p>Foo</p>\r\n"
|
| - "\r\n"
|
| - "<!--EndFragment-->\r\n"
|
| - "</body>\r\n"
|
| - "</html>\r\n\r\n",
|
| - "<p>Foo</p>");
|
| + HtmlTestHelper(
|
| + "Version:1.0\r\n"
|
| + "StartHTML:0000000105\r\n"
|
| + "EndHTML:0000000199\r\n"
|
| + "StartFragment:0000000123\r\n"
|
| + "EndFragment:0000000161\r\n"
|
| + "\r\n"
|
| + "<html>\r\n"
|
| + "<body>\r\n"
|
| + "<!--StartFragment-->\r\n"
|
| + "\r\n"
|
| + "<p>Foo</p>\r\n"
|
| + "\r\n"
|
| + "<!--EndFragment-->\r\n"
|
| + "</body>\r\n"
|
| + "</html>\r\n\r\n",
|
| + "<p>Foo</p>");
|
|
|
| // Test converting from CF_HTML format data without <!--StartFragment--> and
|
| // <!--EndFragment--> comments, like from OpenOffice Writer.
|
| - HtmlTestHelper("Version:1.0\r\n"
|
| - "StartHTML:0000000105\r\n"
|
| - "EndHTML:0000000151\r\n"
|
| - "StartFragment:0000000121\r\n"
|
| - "EndFragment:0000000131\r\n"
|
| - "<html>\r\n"
|
| - "<body>\r\n"
|
| - "<p>Foo</p>\r\n"
|
| - "</body>\r\n"
|
| - "</html>\r\n\r\n",
|
| - "<p>Foo</p>");
|
| + HtmlTestHelper(
|
| + "Version:1.0\r\n"
|
| + "StartHTML:0000000105\r\n"
|
| + "EndHTML:0000000151\r\n"
|
| + "StartFragment:0000000121\r\n"
|
| + "EndFragment:0000000131\r\n"
|
| + "<html>\r\n"
|
| + "<body>\r\n"
|
| + "<p>Foo</p>\r\n"
|
| + "</body>\r\n"
|
| + "</html>\r\n\r\n",
|
| + "<p>Foo</p>");
|
| }
|
| #endif // defined(OS_WIN)
|
|
|
| @@ -744,73 +754,4 @@ TYPED_TEST(ClipboardTest, GetSequenceNumber) {
|
| }
|
| #endif
|
|
|
| -#if defined(OS_ANDROID)
|
| -
|
| -// Test that if another application writes some text to the pasteboard the
|
| -// clipboard properly invalidates other types.
|
| -TYPED_TEST(ClipboardTest, InternalClipboardInvalidation) {
|
| - // Write a Webkit smart paste tag to our clipboard.
|
| - {
|
| - ScopedClipboardWriter clipboard_writer(CLIPBOARD_TYPE_COPY_PASTE);
|
| - clipboard_writer.WriteWebSmartPaste();
|
| - }
|
| - EXPECT_TRUE(this->clipboard().IsFormatAvailable(
|
| - Clipboard::GetWebKitSmartPasteFormatType(), CLIPBOARD_TYPE_COPY_PASTE));
|
| -
|
| - //
|
| - // Simulate that another application copied something in the Clipboard
|
| - //
|
| - std::string new_value("Some text copied by some other app");
|
| - using base::android::ConvertUTF8ToJavaString;
|
| - using base::android::MethodID;
|
| - using base::android::ScopedJavaLocalRef;
|
| -
|
| - JNIEnv* env = base::android::AttachCurrentThread();
|
| - ASSERT_TRUE(env);
|
| -
|
| - jobject context = base::android::GetApplicationContext();
|
| - ASSERT_TRUE(context);
|
| -
|
| - ScopedJavaLocalRef<jclass> context_class =
|
| - base::android::GetClass(env, "android/content/Context");
|
| -
|
| - jmethodID get_system_service = MethodID::Get<MethodID::TYPE_INSTANCE>(
|
| - env, context_class.obj(), "getSystemService",
|
| - "(Ljava/lang/String;)Ljava/lang/Object;");
|
| -
|
| - // Retrieve the system service.
|
| - ScopedJavaLocalRef<jstring> service_name = ConvertUTF8ToJavaString(
|
| - env, "clipboard");
|
| - ScopedJavaLocalRef<jobject> clipboard_manager(
|
| - env, env->CallObjectMethod(
|
| - context, get_system_service, service_name.obj()));
|
| - ASSERT_TRUE(clipboard_manager.obj() && !base::android::ClearException(env));
|
| -
|
| - ScopedJavaLocalRef<jclass> clipboard_class =
|
| - base::android::GetClass(env, "android/text/ClipboardManager");
|
| - jmethodID set_text = MethodID::Get<MethodID::TYPE_INSTANCE>(
|
| - env, clipboard_class.obj(), "setText", "(Ljava/lang/CharSequence;)V");
|
| - ScopedJavaLocalRef<jstring> new_value_string = ConvertUTF8ToJavaString(
|
| - env, new_value.c_str());
|
| -
|
| - // Will need to call toString as CharSequence is not always a String.
|
| - env->CallVoidMethod(clipboard_manager.obj(),
|
| - set_text,
|
| - new_value_string.obj());
|
| -
|
| - // The WebKit smart paste tag should now be gone.
|
| - EXPECT_FALSE(this->clipboard().IsFormatAvailable(
|
| - Clipboard::GetWebKitSmartPasteFormatType(), CLIPBOARD_TYPE_COPY_PASTE));
|
| -
|
| - // Make sure some text is available
|
| - EXPECT_TRUE(this->clipboard().IsFormatAvailable(
|
| - Clipboard::GetPlainTextWFormatType(), CLIPBOARD_TYPE_COPY_PASTE));
|
| -
|
| - // Make sure the text is what we inserted while simulating the other app
|
| - std::string contents;
|
| - this->clipboard().ReadAsciiText(CLIPBOARD_TYPE_COPY_PASTE, &contents);
|
| - EXPECT_EQ(contents, new_value);
|
| -}
|
| -#endif
|
| -
|
| } // namespace ui
|
|
|