Chromium Code Reviews| 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 // Note: This header doesn't use REGISTER_TYPED_TEST_CASE_P like most | 5 // Note: This header doesn't use REGISTER_TYPED_TEST_CASE_P like most |
| 6 // type-parameterized gtests. There are lot of test cases in here that are only | 6 // type-parameterized gtests. There are lot of test cases in here that are only |
| 7 // enabled on certain platforms. However, preprocessor directives in macro | 7 // enabled on certain platforms. However, preprocessor directives in macro |
| 8 // arguments result in undefined behavior (and don't work on MSVC). Instead, | 8 // arguments result in undefined behavior (and don't work on MSVC). Instead, |
| 9 // 'parameterized' tests should typedef TypesToTest (which is used to | 9 // 'parameterized' tests should typedef TypesToTest (which is used to |
| 10 // instantiate the tests using the TYPED_TEST_CASE macro) and then #include this | 10 // instantiate the tests using the TYPED_TEST_CASE macro) and then #include this |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 49 | 49 |
| 50 using testing::Contains; | 50 using testing::Contains; |
| 51 | 51 |
| 52 namespace ui { | 52 namespace ui { |
| 53 | 53 |
| 54 template <typename ClipboardTraits> | 54 template <typename ClipboardTraits> |
| 55 class ClipboardTest : public PlatformTest { | 55 class ClipboardTest : public PlatformTest { |
| 56 public: | 56 public: |
| 57 #if defined(USE_AURA) | 57 #if defined(USE_AURA) |
| 58 ClipboardTest() | 58 ClipboardTest() |
| 59 : event_source_(PlatformEventSource::CreateDefault()), | 59 : event_source_(ClipboardTraits::GetEventSource()), |
| 60 clipboard_(ClipboardTraits::Create()) {} | 60 clipboard_(ClipboardTraits::Create()) {} |
| 61 #else | 61 #else |
| 62 ClipboardTest() : clipboard_(ClipboardTraits::Create()) {} | 62 ClipboardTest() : clipboard_(ClipboardTraits::Create()) {} |
| 63 #endif | 63 #endif |
| 64 | 64 |
| 65 ~ClipboardTest() override { ClipboardTraits::Destroy(clipboard_); } | 65 ~ClipboardTest() override { ClipboardTraits::Destroy(clipboard_); } |
| 66 | 66 |
| 67 bool IsMusTest() { return ClipboardTraits::IsMusTest(); } | |
| 68 | |
| 67 protected: | 69 protected: |
| 68 Clipboard& clipboard() { return *clipboard_; } | 70 Clipboard& clipboard() { return *clipboard_; } |
| 69 | 71 |
| 70 std::vector<base::string16> GetAvailableTypes(ClipboardType type) { | 72 std::vector<base::string16> GetAvailableTypes(ClipboardType type) { |
| 71 bool contains_filenames; | 73 bool contains_filenames; |
| 72 std::vector<base::string16> types; | 74 std::vector<base::string16> types; |
| 73 clipboard().ReadAvailableTypes(type, &types, &contains_filenames); | 75 clipboard().ReadAvailableTypes(type, &types, &contains_filenames); |
| 74 return types; | 76 return types; |
| 75 } | 77 } |
| 76 | 78 |
| 77 private: | 79 private: |
| 78 base::MessageLoopForUI message_loop_; | 80 base::MessageLoopForUI message_loop_; |
| 79 #if defined(USE_AURA) | 81 #if defined(USE_AURA) |
| 80 std::unique_ptr<PlatformEventSource> event_source_; | 82 std::unique_ptr<PlatformEventSource> event_source_; |
| 81 #endif | 83 #endif |
| 82 // ui::Clipboard has a protected destructor, so scoped_ptr doesn't work here. | 84 // ui::Clipboard has a protected destructor, so scoped_ptr doesn't work here. |
| 83 Clipboard* const clipboard_; | 85 Clipboard* const clipboard_; |
| 84 }; | 86 }; |
| 85 | 87 |
| 86 // Hack for tests that need to call static methods of ClipboardTest. | 88 // Hack for tests that need to call static methods of ClipboardTest. |
| 87 struct NullClipboardTraits { | 89 struct NullClipboardTraits { |
| 88 static Clipboard* Create() { return nullptr; } | 90 static Clipboard* Create() { return nullptr; } |
| 91 static bool IsMusTest() { return false; } | |
| 89 static void Destroy(Clipboard*) {} | 92 static void Destroy(Clipboard*) {} |
| 90 }; | 93 }; |
| 91 | 94 |
| 92 TYPED_TEST_CASE(ClipboardTest, TypesToTest); | 95 TYPED_TEST_CASE(ClipboardTest, TypesToTest); |
| 93 | 96 |
| 94 TYPED_TEST(ClipboardTest, ClearTest) { | 97 TYPED_TEST(ClipboardTest, ClearTest) { |
| 95 { | 98 { |
| 96 ScopedClipboardWriter clipboard_writer(CLIPBOARD_TYPE_COPY_PASTE); | 99 ScopedClipboardWriter clipboard_writer(CLIPBOARD_TYPE_COPY_PASTE); |
| 97 clipboard_writer.WriteText(ASCIIToUTF16("clear me")); | 100 clipboard_writer.WriteText(ASCIIToUTF16("clear me")); |
| 98 } | 101 } |
| (...skipping 260 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 359 this->clipboard().ReadText(CLIPBOARD_TYPE_COPY_PASTE, &text_result); | 362 this->clipboard().ReadText(CLIPBOARD_TYPE_COPY_PASTE, &text_result); |
| 360 | 363 |
| 361 EXPECT_EQ(text_result, url); | 364 EXPECT_EQ(text_result, url); |
| 362 | 365 |
| 363 std::string ascii_text; | 366 std::string ascii_text; |
| 364 this->clipboard().ReadAsciiText(CLIPBOARD_TYPE_COPY_PASTE, &ascii_text); | 367 this->clipboard().ReadAsciiText(CLIPBOARD_TYPE_COPY_PASTE, &ascii_text); |
| 365 EXPECT_EQ(UTF16ToUTF8(url), ascii_text); | 368 EXPECT_EQ(UTF16ToUTF8(url), ascii_text); |
| 366 | 369 |
| 367 #if defined(OS_POSIX) && !defined(OS_MACOSX) && !defined(OS_ANDROID) && \ | 370 #if defined(OS_POSIX) && !defined(OS_MACOSX) && !defined(OS_ANDROID) && \ |
| 368 !defined(OS_CHROMEOS) | 371 !defined(OS_CHROMEOS) |
| 369 ascii_text.clear(); | 372 if (!this->IsMusTest()) { |
|
dcheng
2016/06/04 06:14:00
Why do we exclude mus here? Wouldn't we expect thi
Elliot Glaysher
2016/06/06 20:10:12
Because mus is chromeos in a linux build.
When ch
dcheng
2016/06/07 05:39:00
It feels a bit odd, but I can live with this reaso
| |
| 370 this->clipboard().ReadAsciiText(CLIPBOARD_TYPE_SELECTION, &ascii_text); | 373 ascii_text.clear(); |
| 371 EXPECT_EQ(UTF16ToUTF8(url), ascii_text); | 374 this->clipboard().ReadAsciiText(CLIPBOARD_TYPE_SELECTION, &ascii_text); |
| 375 EXPECT_EQ(UTF16ToUTF8(url), ascii_text); | |
| 376 } | |
| 372 #endif | 377 #endif |
| 373 } | 378 } |
| 374 | 379 |
| 375 static void TestBitmapWrite(Clipboard* clipboard, | 380 static void TestBitmapWrite(Clipboard* clipboard, |
| 376 const gfx::Size& size, | 381 const gfx::Size& size, |
| 377 const uint32_t* bitmap_data) { | 382 const uint32_t* bitmap_data) { |
| 378 { | 383 { |
| 379 ScopedClipboardWriter scw(CLIPBOARD_TYPE_COPY_PASTE); | 384 ScopedClipboardWriter scw(CLIPBOARD_TYPE_COPY_PASTE); |
| 380 SkBitmap bitmap; | 385 SkBitmap bitmap; |
| 381 ASSERT_TRUE(bitmap.setInfo( | 386 ASSERT_TRUE(bitmap.setInfo( |
| (...skipping 288 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 670 ScopedClipboardWriter scw(CLIPBOARD_TYPE_COPY_PASTE); | 675 ScopedClipboardWriter scw(CLIPBOARD_TYPE_COPY_PASTE); |
| 671 scw.WritePickledData(base::Pickle(), Clipboard::GetPlainTextFormatType()); | 676 scw.WritePickledData(base::Pickle(), Clipboard::GetPlainTextFormatType()); |
| 672 } | 677 } |
| 673 | 678 |
| 674 TYPED_TEST(ClipboardTest, WriteImageEmptyParams) { | 679 TYPED_TEST(ClipboardTest, WriteImageEmptyParams) { |
| 675 ScopedClipboardWriter scw(CLIPBOARD_TYPE_COPY_PASTE); | 680 ScopedClipboardWriter scw(CLIPBOARD_TYPE_COPY_PASTE); |
| 676 scw.WriteImage(SkBitmap()); | 681 scw.WriteImage(SkBitmap()); |
| 677 } | 682 } |
| 678 | 683 |
| 679 } // namespace ui | 684 } // namespace ui |
| OLD | NEW |