| OLD | NEW |
| (Empty) | |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #include "ui/views/mus/clipboard_mus.h" |
| 6 |
| 7 #include "base/message_loop/message_loop.h" |
| 8 #include "testing/gtest/include/gtest/gtest.h" |
| 9 #include "ui/events/platform/platform_event_source.h" |
| 10 #include "ui/views/mus/window_manager_connection.h" |
| 11 #include "ui/views/test/scoped_views_test_helper.h" |
| 12 |
| 13 namespace ui { |
| 14 |
| 15 // So we can't make ScopedViewsTestHelper a global. We must set up |
| 16 // ScopedViewsTestHelper on every test (which will create the connection to |
| 17 // mus). And we can't modify PlatformClipboardTraits to not be a pure static |
| 18 // struct. So to solve these lifetime issues, create an adapter that owns the |
| 19 // ScopedViewsTestHelper and then . |
| 20 class ForwardingTestingClipboard : public ui::Clipboard { |
| 21 public: |
| 22 ForwardingTestingClipboard() |
| 23 : test_helper_(new views::ScopedViewsTestHelper), |
| 24 clipboard_to_test_(Clipboard::GetForCurrentThread()) { |
| 25 // If we don't have a window manager connection, we will get the default |
| 26 // platform clipboard instead. |
| 27 EXPECT_TRUE(views::WindowManagerConnection::Exists()); |
| 28 } |
| 29 |
| 30 ~ForwardingTestingClipboard() override { |
| 31 Clipboard::DestroyClipboardForCurrentThread(); |
| 32 } |
| 33 |
| 34 void Destroy() { |
| 35 delete this; |
| 36 } |
| 37 |
| 38 protected: |
| 39 // Overridden from ui::Clipboard: |
| 40 uint64_t GetSequenceNumber(ClipboardType type) const override { |
| 41 return clipboard_to_test_->GetSequenceNumber(type); |
| 42 } |
| 43 bool IsFormatAvailable(const FormatType& format, |
| 44 ClipboardType type) const override { |
| 45 return clipboard_to_test_->IsFormatAvailable(format, type); |
| 46 } |
| 47 void Clear(ClipboardType type) override { |
| 48 clipboard_to_test_->Clear(type); |
| 49 } |
| 50 void ReadAvailableTypes(ClipboardType type, |
| 51 std::vector<base::string16>* types, |
| 52 bool* contains_filenames) const override { |
| 53 clipboard_to_test_->ReadAvailableTypes(type, types, contains_filenames); |
| 54 } |
| 55 void ReadText(ClipboardType type, base::string16* result) const override { |
| 56 clipboard_to_test_->ReadText(type, result); |
| 57 } |
| 58 void ReadAsciiText(ClipboardType type, std::string* result) const override { |
| 59 clipboard_to_test_->ReadAsciiText(type, result); |
| 60 } |
| 61 void ReadHTML(ClipboardType type, base::string16* markup, |
| 62 std::string* src_url, uint32_t* fragment_start, |
| 63 uint32_t* fragment_end) const override { |
| 64 clipboard_to_test_->ReadHTML(type, markup, src_url, |
| 65 fragment_start, fragment_end); |
| 66 } |
| 67 void ReadRTF(ClipboardType type, std::string* result) const override { |
| 68 clipboard_to_test_->ReadRTF(type, result); |
| 69 } |
| 70 SkBitmap ReadImage(ClipboardType type) const override { |
| 71 return clipboard_to_test_->ReadImage(type); |
| 72 } |
| 73 void ReadCustomData(ClipboardType clipboard_type, |
| 74 const base::string16& type, |
| 75 base::string16* result) const override { |
| 76 clipboard_to_test_->ReadCustomData(clipboard_type, type, result); |
| 77 } |
| 78 void ReadBookmark(base::string16* title, std::string* url) const override { |
| 79 clipboard_to_test_->ReadBookmark(title, url); |
| 80 } |
| 81 void ReadData(const FormatType& format, std::string* result) const override { |
| 82 clipboard_to_test_->ReadData(format, result); |
| 83 } |
| 84 void WriteObjects(ClipboardType type, const ObjectMap& objects) override { |
| 85 clipboard_to_test_->WriteObjects(type, objects); |
| 86 } |
| 87 void WriteText(const char* text_data, size_t text_len) override { |
| 88 clipboard_to_test_->WriteText(text_data, text_len); |
| 89 } |
| 90 void WriteHTML(const char* markup_data, |
| 91 size_t markup_len, |
| 92 const char* url_data, |
| 93 size_t url_len) override { |
| 94 clipboard_to_test_->WriteHTML(markup_data, markup_len, url_data, url_len); |
| 95 } |
| 96 void WriteRTF(const char* rtf_data, size_t data_len) override { |
| 97 clipboard_to_test_->WriteRTF(rtf_data, data_len); |
| 98 } |
| 99 void WriteBookmark(const char* title_data, |
| 100 size_t title_len, |
| 101 const char* url_data, |
| 102 size_t url_len) override { |
| 103 clipboard_to_test_->WriteBookmark(title_data, title_len, |
| 104 url_data, url_len); |
| 105 } |
| 106 void WriteWebSmartPaste() override { |
| 107 clipboard_to_test_->WriteWebSmartPaste(); |
| 108 } |
| 109 void WriteBitmap(const SkBitmap& bitmap) override { |
| 110 clipboard_to_test_->WriteBitmap(bitmap); |
| 111 } |
| 112 void WriteData(const FormatType& format, |
| 113 const char* data_data, |
| 114 size_t data_len) override { |
| 115 clipboard_to_test_->WriteData(format, data_data, data_len); |
| 116 } |
| 117 |
| 118 private: |
| 119 std::unique_ptr<views::ScopedViewsTestHelper> test_helper_; |
| 120 ui::Clipboard* clipboard_to_test_; |
| 121 |
| 122 DISALLOW_COPY_AND_ASSIGN(ForwardingTestingClipboard); |
| 123 }; |
| 124 |
| 125 struct PlatformClipboardTraits { |
| 126 static std::unique_ptr<PlatformEventSource> GetEventSource() { |
| 127 return nullptr; |
| 128 } |
| 129 |
| 130 static Clipboard* Create() { |
| 131 return new ForwardingTestingClipboard(); |
| 132 } |
| 133 |
| 134 static bool IsMusTest() { return true; } |
| 135 |
| 136 static void Destroy(Clipboard* clipboard) { |
| 137 static_cast<ForwardingTestingClipboard*>(clipboard)->Destroy(); |
| 138 } |
| 139 }; |
| 140 |
| 141 using TypesToTest = PlatformClipboardTraits; |
| 142 |
| 143 } // namespace ui |
| 144 |
| 145 #include "ui/base/clipboard/clipboard_test_template.h" |
| OLD | NEW |