| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 "ui/base/test/test_clipboard.h" | 5 #include "ui/base/test/test_clipboard.h" |
| 6 | 6 |
| 7 #include <stddef.h> | 7 #include <stddef.h> |
| 8 #include "base/memory/ptr_util.h" | 8 #include "base/memory/ptr_util.h" |
| 9 #include "base/numerics/safe_conversions.h" | 9 #include "base/numerics/safe_conversions.h" |
| 10 #include "base/strings/utf_string_conversions.h" | 10 #include "base/strings/utf_string_conversions.h" |
| 11 | 11 |
| 12 namespace ui { | 12 namespace ui { |
| 13 | 13 |
| 14 TestClipboard::TestClipboard() | 14 TestClipboard::TestClipboard() |
| 15 : default_store_type_(CLIPBOARD_TYPE_COPY_PASTE) { | 15 : default_store_type_(CLIPBOARD_TYPE_COPY_PASTE) { |
| 16 } | 16 } |
| 17 | 17 |
| 18 TestClipboard::~TestClipboard() { | 18 TestClipboard::~TestClipboard() { |
| 19 } | 19 } |
| 20 | 20 |
| 21 Clipboard* TestClipboard::CreateForCurrentThread() { | 21 Clipboard* TestClipboard::CreateForCurrentThread() { |
| 22 base::AutoLock lock(Clipboard::clipboard_map_lock_.Get()); | 22 base::AutoLock lock(Clipboard::clipboard_map_lock_.Get()); |
| 23 Clipboard* clipboard = new TestClipboard; | 23 Clipboard* clipboard = new TestClipboard; |
| 24 Clipboard::clipboard_map_.Get()[base::PlatformThread::CurrentId()] = | 24 Clipboard::clipboard_map_.Get()[base::PlatformThread::CurrentId()] = |
| 25 base::WrapUnique(clipboard); | 25 base::WrapUnique(clipboard); |
| 26 return clipboard; | 26 return clipboard; |
| 27 } | 27 } |
| 28 | 28 |
| 29 void TestClipboard::SetClipboardLastModifiedTime(const base::Time& time) { |
| 30 last_modified_time_ = time; |
| 31 } |
| 32 |
| 29 void TestClipboard::OnPreShutdown() {} | 33 void TestClipboard::OnPreShutdown() {} |
| 30 | 34 |
| 31 uint64_t TestClipboard::GetSequenceNumber(ClipboardType type) const { | 35 uint64_t TestClipboard::GetSequenceNumber(ClipboardType type) const { |
| 32 return GetStore(type).sequence_number; | 36 return GetStore(type).sequence_number; |
| 33 } | 37 } |
| 34 | 38 |
| 35 bool TestClipboard::IsFormatAvailable(const FormatType& format, | 39 bool TestClipboard::IsFormatAvailable(const FormatType& format, |
| 36 ClipboardType type) const { | 40 ClipboardType type) const { |
| 37 const DataStore& store = GetStore(type); | 41 const DataStore& store = GetStore(type); |
| 38 return store.data.find(format) != store.data.end(); | 42 return store.data.find(format) != store.data.end(); |
| (...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 119 | 123 |
| 120 void TestClipboard::ReadData(const FormatType& format, | 124 void TestClipboard::ReadData(const FormatType& format, |
| 121 std::string* result) const { | 125 std::string* result) const { |
| 122 result->clear(); | 126 result->clear(); |
| 123 const DataStore& store = GetDefaultStore(); | 127 const DataStore& store = GetDefaultStore(); |
| 124 auto it = store.data.find(format); | 128 auto it = store.data.find(format); |
| 125 if (it != store.data.end()) | 129 if (it != store.data.end()) |
| 126 *result = it->second; | 130 *result = it->second; |
| 127 } | 131 } |
| 128 | 132 |
| 133 base::Time TestClipboard::GetClipboardLastModifiedTime() const { |
| 134 return last_modified_time_; |
| 135 } |
| 136 |
| 129 void TestClipboard::WriteObjects(ClipboardType type, const ObjectMap& objects) { | 137 void TestClipboard::WriteObjects(ClipboardType type, const ObjectMap& objects) { |
| 130 Clear(type); | 138 Clear(type); |
| 131 default_store_type_ = type; | 139 default_store_type_ = type; |
| 132 for (const auto& kv : objects) | 140 for (const auto& kv : objects) |
| 133 DispatchObject(static_cast<ObjectType>(kv.first), kv.second); | 141 DispatchObject(static_cast<ObjectType>(kv.first), kv.second); |
| 134 default_store_type_ = CLIPBOARD_TYPE_COPY_PASTE; | 142 default_store_type_ = CLIPBOARD_TYPE_COPY_PASTE; |
| 135 } | 143 } |
| 136 | 144 |
| 137 void TestClipboard::WriteText(const char* text_data, size_t text_len) { | 145 void TestClipboard::WriteText(const char* text_data, size_t text_len) { |
| 138 std::string text(text_data, text_len); | 146 std::string text(text_data, text_len); |
| (...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 212 | 220 |
| 213 const TestClipboard::DataStore& TestClipboard::GetDefaultStore() const { | 221 const TestClipboard::DataStore& TestClipboard::GetDefaultStore() const { |
| 214 return GetStore(default_store_type_); | 222 return GetStore(default_store_type_); |
| 215 } | 223 } |
| 216 | 224 |
| 217 TestClipboard::DataStore& TestClipboard::GetDefaultStore() { | 225 TestClipboard::DataStore& TestClipboard::GetDefaultStore() { |
| 218 return GetStore(default_store_type_); | 226 return GetStore(default_store_type_); |
| 219 } | 227 } |
| 220 | 228 |
| 221 } // namespace ui | 229 } // namespace ui |
| OLD | NEW |