| Index: ui/base/clipboard/clipboard_test_template.h
|
| diff --git a/ui/base/clipboard/clipboard_test_template.h b/ui/base/clipboard/clipboard_test_template.h
|
| index 9d519213888de22f50ff226541931b849b235c45..bb538a9ebeff6c43f48ad508ad22b70ac1d75f11 100644
|
| --- a/ui/base/clipboard/clipboard_test_template.h
|
| +++ b/ui/base/clipboard/clipboard_test_template.h
|
| @@ -2,13 +2,21 @@
|
| // 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.
|
| +// Unlike most type-parameterized test templates, instantiating the tests in
|
| +// this header requires two things:
|
| +// 1. #define CLIPBOARD_TEST_FIXTURE_NAME to something unique.
|
| +// 2. #define CLIPBOARD_TYPE_TO_TEST to the name of the clipboard traits.
|
| +//
|
| +// This complexity results from several factors:
|
| +// - not all clipboard tests work on all platforms, so this header cannot use
|
| +// the standard REGISTER_TYPED_TEST_CASE_P macro.
|
| +// - as a result of using the TYPED_TEST_CASE/TYPED_TEST macros, multiple
|
| +// instantiations of this test template in the same binary result in
|
| +// multiply-defined symbols, hence the CLIPBOARD_TEST_FIXTURE_NAME
|
| +// requirement.
|
| +// - the test fixture name also needs to encoder whether or not the tests need
|
| +// to run serially.
|
| +//
|
| // TODO(dcheng): This is really horrible. In general, all tests should run on
|
| // all platforms, to avoid this mess.
|
|
|
| @@ -17,6 +25,7 @@
|
| #include <string>
|
|
|
| #include "base/basictypes.h"
|
| +#include "base/gtest_prod_util.h"
|
| #include "base/memory/scoped_ptr.h"
|
| #include "base/message_loop/message_loop.h"
|
| #include "base/pickle.h"
|
| @@ -42,6 +51,26 @@
|
| #include "ui/events/platform/platform_event_source.h"
|
| #endif
|
|
|
| +#if !defined(CLIPBOARD_TEST_FIXTURE_NAME)
|
| +#error CLIPBOARD_TEST_FIXTURE_NAME must be #defined!
|
| +#endif
|
| +
|
| +#if !defined(CLIPBOARD_TYPE_TO_TEST)
|
| +#error CLIPBOARD_TYPE_TO_TEST must be #defined!
|
| +#endif
|
| +
|
| +#define CLIPBOARD_TYPED_TEST_CASE_HELPER(x, y) TYPED_TEST_CASE(x, y)
|
| +#if defined(CLIPBOARD_TESTS_RUN_SERIALLY)
|
| +#define CLIPBOARD_TYPED_TEST_HELPER(x, y) TYPED_TEST_SERIALIZE(x, y)
|
| +#else
|
| +#define CLIPBOARD_TYPED_TEST_HELPER(x, y) TYPED_TEST(x, y)
|
| +#endif
|
| +
|
| +#define CLIPBOARD_TYPED_TEST_CASE(x) \
|
| + CLIPBOARD_TYPED_TEST_CASE_HELPER(CLIPBOARD_TEST_FIXTURE_NAME, x)
|
| +#define CLIPBOARD_TYPED_TEST(x) \
|
| + CLIPBOARD_TYPED_TEST_HELPER(CLIPBOARD_TEST_FIXTURE_NAME, x)
|
| +
|
| using base::ASCIIToUTF16;
|
| using base::UTF8ToUTF16;
|
| using base::UTF16ToUTF8;
|
| @@ -49,17 +78,19 @@ using base::UTF16ToUTF8;
|
| namespace ui {
|
|
|
| template <typename ClipboardTraits>
|
| -class ClipboardTest : public PlatformTest {
|
| +class CLIPBOARD_TEST_FIXTURE_NAME : public PlatformTest {
|
| public:
|
| #if defined(USE_AURA)
|
| - ClipboardTest()
|
| + CLIPBOARD_TEST_FIXTURE_NAME()
|
| : event_source_(PlatformEventSource::CreateDefault()),
|
| clipboard_(ClipboardTraits::Create()) {}
|
| #else
|
| - ClipboardTest() : clipboard_(ClipboardTraits::Create()) {}
|
| + CLIPBOARD_TEST_FIXTURE_NAME() : clipboard_(ClipboardTraits::Create()) {}
|
| #endif
|
|
|
| - ~ClipboardTest() override { ClipboardTraits::Destroy(clipboard_); }
|
| + ~CLIPBOARD_TEST_FIXTURE_NAME() override {
|
| + ClipboardTraits::Destroy(clipboard_);
|
| + }
|
|
|
| protected:
|
| Clipboard& clipboard() { return *clipboard_; }
|
| @@ -73,15 +104,9 @@ class ClipboardTest : public PlatformTest {
|
| Clipboard* const clipboard_;
|
| };
|
|
|
| -// 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, TypesToTest);
|
| +CLIPBOARD_TYPED_TEST_CASE(CLIPBOARD_TYPE_TO_TEST);
|
|
|
| -TYPED_TEST(ClipboardTest, ClearTest) {
|
| +CLIPBOARD_TYPED_TEST(ClearTest) {
|
| {
|
| ScopedClipboardWriter clipboard_writer(CLIPBOARD_TYPE_COPY_PASTE);
|
| clipboard_writer.WriteText(ASCIIToUTF16("clear me"));
|
| @@ -95,7 +120,7 @@ TYPED_TEST(ClipboardTest, ClearTest) {
|
| Clipboard::GetPlainTextFormatType(), CLIPBOARD_TYPE_COPY_PASTE));
|
| }
|
|
|
| -TYPED_TEST(ClipboardTest, TextTest) {
|
| +CLIPBOARD_TYPED_TEST(TextTest) {
|
| base::string16 text(ASCIIToUTF16("This is a base::string16!#$")), text_result;
|
| std::string ascii_text;
|
|
|
| @@ -115,7 +140,7 @@ TYPED_TEST(ClipboardTest, TextTest) {
|
| EXPECT_EQ(UTF16ToUTF8(text), ascii_text);
|
| }
|
|
|
| -TYPED_TEST(ClipboardTest, HTMLTest) {
|
| +CLIPBOARD_TYPED_TEST(HTMLTest) {
|
| base::string16 markup(ASCIIToUTF16("<string>Hi!</string>")), markup_result;
|
| base::string16 plain(ASCIIToUTF16("Hi!")), plain_result;
|
| std::string url("http://www.example.com/"), url_result;
|
| @@ -142,7 +167,7 @@ TYPED_TEST(ClipboardTest, HTMLTest) {
|
| #endif // defined(OS_WIN)
|
| }
|
|
|
| -TYPED_TEST(ClipboardTest, RTFTest) {
|
| +CLIPBOARD_TYPED_TEST(RTFTest) {
|
| std::string rtf =
|
| "{\\rtf1\\ansi{\\fonttbl\\f0\\fswiss Helvetica;}\\f0\\pard\n"
|
| "This is some {\\b bold} text.\\par\n"
|
| @@ -163,7 +188,7 @@ TYPED_TEST(ClipboardTest, RTFTest) {
|
| // TODO(dnicoara) Enable test once Ozone implements clipboard support:
|
| // crbug.com/361707
|
| #if defined(OS_LINUX) && !defined(OS_CHROMEOS) && !defined(USE_OZONE)
|
| -TYPED_TEST(ClipboardTest, MultipleBufferTest) {
|
| +CLIPBOARD_TYPED_TEST(MultipleBufferTest) {
|
| base::string16 text(ASCIIToUTF16("Standard")), text_result;
|
| base::string16 markup(ASCIIToUTF16("<string>Selection</string>"));
|
| std::string url("http://www.example.com/"), url_result;
|
| @@ -202,7 +227,7 @@ TYPED_TEST(ClipboardTest, MultipleBufferTest) {
|
| }
|
| #endif
|
|
|
| -TYPED_TEST(ClipboardTest, TrickyHTMLTest) {
|
| +CLIPBOARD_TYPED_TEST(TrickyHTMLTest) {
|
| base::string16 markup(ASCIIToUTF16("<em>Bye!<!--EndFragment --></em>")),
|
| markup_result;
|
| std::string url, url_result;
|
| @@ -232,7 +257,7 @@ TYPED_TEST(ClipboardTest, TrickyHTMLTest) {
|
|
|
| // 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) {
|
| +CLIPBOARD_TYPED_TEST(UnicodeHTMLTest) {
|
| base::string16 markup(UTF8ToUTF16("<div>A \xc3\xb8 \xe6\xb0\xb4</div>")),
|
| markup_result;
|
| std::string url, url_result;
|
| @@ -258,7 +283,7 @@ TYPED_TEST(ClipboardTest, UnicodeHTMLTest) {
|
|
|
| // TODO(estade): Port the following test (decide what target we use for urls)
|
| #if !defined(OS_POSIX) || defined(OS_MACOSX)
|
| -TYPED_TEST(ClipboardTest, BookmarkTest) {
|
| +CLIPBOARD_TYPED_TEST(BookmarkTest) {
|
| base::string16 title(ASCIIToUTF16("The Example Company")), title_result;
|
| std::string url("http://www.example.com/"), url_result;
|
|
|
| @@ -275,7 +300,7 @@ TYPED_TEST(ClipboardTest, BookmarkTest) {
|
| }
|
| #endif // !defined(OS_POSIX) || defined(OS_MACOSX)
|
|
|
| -TYPED_TEST(ClipboardTest, MultiFormatTest) {
|
| +CLIPBOARD_TYPED_TEST(MultiFormatTest) {
|
| base::string16 text(ASCIIToUTF16("Hi!")), text_result;
|
| base::string16 markup(ASCIIToUTF16("<strong>Hi!</string>")), markup_result;
|
| std::string url("http://www.example.com/"), url_result;
|
| @@ -311,7 +336,7 @@ TYPED_TEST(ClipboardTest, MultiFormatTest) {
|
| EXPECT_EQ(UTF16ToUTF8(text), ascii_text);
|
| }
|
|
|
| -TYPED_TEST(ClipboardTest, URLTest) {
|
| +CLIPBOARD_TYPED_TEST(URLTest) {
|
| base::string16 url(ASCIIToUTF16("http://www.google.com/"));
|
|
|
| {
|
| @@ -368,7 +393,7 @@ static void TestBitmapWrite(Clipboard* clipboard,
|
| }
|
| }
|
|
|
| -TYPED_TEST(ClipboardTest, SharedBitmapTest) {
|
| +CLIPBOARD_TYPED_TEST(SharedBitmapTest) {
|
| const uint32 fake_bitmap_1[] = {
|
| 0x46061626, 0xf69f5988, 0x793f2937, 0xfa55b986,
|
| 0x78772152, 0x87692a30, 0x36322a25, 0x4320401b,
|
| @@ -394,7 +419,7 @@ TYPED_TEST(ClipboardTest, SharedBitmapTest) {
|
| }
|
| }
|
|
|
| -TYPED_TEST(ClipboardTest, DataTest) {
|
| +CLIPBOARD_TYPED_TEST(DataTest) {
|
| const ui::Clipboard::FormatType kFormat =
|
| ui::Clipboard::GetFormatType("chromium/x-test-format");
|
| std::string payload("test string");
|
| @@ -419,7 +444,7 @@ TYPED_TEST(ClipboardTest, DataTest) {
|
| EXPECT_EQ(payload, unpickled_string);
|
| }
|
|
|
| -TYPED_TEST(ClipboardTest, MultipleDataTest) {
|
| +CLIPBOARD_TYPED_TEST(MultipleDataTest) {
|
| const ui::Clipboard::FormatType kFormat1 =
|
| ui::Clipboard::GetFormatType("chromium/x-test-format1");
|
| std::string payload1("test string1");
|
| @@ -476,7 +501,7 @@ TYPED_TEST(ClipboardTest, MultipleDataTest) {
|
| }
|
|
|
| #if !defined(OS_MACOSX) && !defined(OS_ANDROID)
|
| -TYPED_TEST(ClipboardTest, HyperlinkTest) {
|
| +CLIPBOARD_TYPED_TEST(HyperlinkTest) {
|
| const std::string kTitle("The <Example> Company's \"home page\"");
|
| const std::string kUrl("http://www.example.com?x=3<=3#\"'<>");
|
| const base::string16 kExpectedHtml(UTF8ToUTF16(
|
| @@ -502,7 +527,7 @@ TYPED_TEST(ClipboardTest, HyperlinkTest) {
|
| }
|
| #endif
|
|
|
| -TYPED_TEST(ClipboardTest, WebSmartPasteTest) {
|
| +CLIPBOARD_TYPED_TEST(WebSmartPasteTest) {
|
| {
|
| ScopedClipboardWriter clipboard_writer(CLIPBOARD_TYPE_COPY_PASTE);
|
| clipboard_writer.WriteWebSmartPaste();
|
| @@ -513,14 +538,14 @@ TYPED_TEST(ClipboardTest, WebSmartPasteTest) {
|
| }
|
|
|
| #if defined(OS_WIN) // Windows only tests.
|
| -void HtmlTestHelper(const std::string& cf_html,
|
| - const std::string& expected_html) {
|
| +static void HtmlTestHelper(const std::string& cf_html,
|
| + const std::string& expected_html) {
|
| std::string html;
|
| ClipboardUtil::CFHtmlToHtml(cf_html, &html, NULL);
|
| EXPECT_EQ(html, expected_html);
|
| }
|
|
|
| -TYPED_TEST(ClipboardTest, HtmlTest) {
|
| +CLIPBOARD_TYPED_TEST(HtmlTest) {
|
| // Test converting from CF_HTML format data with <!--StartFragment--> and
|
| // <!--EndFragment--> comments, like from MS Word.
|
| HtmlTestHelper(
|
| @@ -559,7 +584,7 @@ TYPED_TEST(ClipboardTest, HtmlTest) {
|
| #endif // defined(OS_WIN)
|
|
|
| // Test writing all formats we have simultaneously.
|
| -TYPED_TEST(ClipboardTest, WriteEverything) {
|
| +CLIPBOARD_TYPED_TEST(WriteEverything) {
|
| {
|
| ScopedClipboardWriter writer(CLIPBOARD_TYPE_COPY_PASTE);
|
| writer.WriteText(UTF8ToUTF16("foo"));
|
| @@ -582,7 +607,7 @@ TYPED_TEST(ClipboardTest, WriteEverything) {
|
| // Simple test that the sequence number appears to change when the clipboard is
|
| // written to.
|
| // TODO(dcheng): Add a version to test CLIPBOARD_TYPE_SELECTION.
|
| -TYPED_TEST(ClipboardTest, GetSequenceNumber) {
|
| +CLIPBOARD_TYPED_TEST(GetSequenceNumber) {
|
| const uint64 first_sequence_number =
|
| this->clipboard().GetSequenceNumber(CLIPBOARD_TYPE_COPY_PASTE);
|
|
|
| @@ -604,42 +629,42 @@ TYPED_TEST(ClipboardTest, GetSequenceNumber) {
|
|
|
| // Test that writing empty parameters doesn't try to dereference an empty data
|
| // vector. Not crashing = passing.
|
| -TYPED_TEST(ClipboardTest, WriteTextEmptyParams) {
|
| +CLIPBOARD_TYPED_TEST(WriteTextEmptyParams) {
|
| ScopedClipboardWriter scw(CLIPBOARD_TYPE_COPY_PASTE);
|
| scw.WriteText(base::string16());
|
| }
|
|
|
| -TYPED_TEST(ClipboardTest, WriteURLEmptyParams) {
|
| +CLIPBOARD_TYPED_TEST(WriteURLEmptyParams) {
|
| ScopedClipboardWriter scw(CLIPBOARD_TYPE_COPY_PASTE);
|
| scw.WriteURL(base::string16());
|
| }
|
|
|
| -TYPED_TEST(ClipboardTest, WriteHTMLEmptyParams) {
|
| +CLIPBOARD_TYPED_TEST(WriteHTMLEmptyParams) {
|
| ScopedClipboardWriter scw(CLIPBOARD_TYPE_COPY_PASTE);
|
| scw.WriteHTML(base::string16(), std::string());
|
| }
|
|
|
| -TYPED_TEST(ClipboardTest, WriteRTFEmptyParams) {
|
| +CLIPBOARD_TYPED_TEST(WriteRTFEmptyParams) {
|
| ScopedClipboardWriter scw(CLIPBOARD_TYPE_COPY_PASTE);
|
| scw.WriteRTF(std::string());
|
| }
|
|
|
| -TYPED_TEST(ClipboardTest, WriteBookmarkEmptyParams) {
|
| +CLIPBOARD_TYPED_TEST(WriteBookmarkEmptyParams) {
|
| ScopedClipboardWriter scw(CLIPBOARD_TYPE_COPY_PASTE);
|
| scw.WriteBookmark(base::string16(), std::string());
|
| }
|
|
|
| -TYPED_TEST(ClipboardTest, WriteHyperlinkEmptyParams) {
|
| +CLIPBOARD_TYPED_TEST(WriteHyperlinkEmptyParams) {
|
| ScopedClipboardWriter scw(CLIPBOARD_TYPE_COPY_PASTE);
|
| scw.WriteHyperlink(base::string16(), std::string());
|
| }
|
|
|
| -TYPED_TEST(ClipboardTest, WritePickledData) {
|
| +CLIPBOARD_TYPED_TEST(WritePickledData) {
|
| ScopedClipboardWriter scw(CLIPBOARD_TYPE_COPY_PASTE);
|
| scw.WritePickledData(Pickle(), Clipboard::GetPlainTextFormatType());
|
| }
|
|
|
| -TYPED_TEST(ClipboardTest, WriteImageEmptyParams) {
|
| +CLIPBOARD_TYPED_TEST(WriteImageEmptyParams) {
|
| ScopedClipboardWriter scw(CLIPBOARD_TYPE_COPY_PASTE);
|
| scw.WriteImage(SkBitmap());
|
| }
|
|
|