| 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) { | 29 void TestClipboard::SetLastModifiedTime(const base::Time& time) { |
| 30 last_modified_time_ = time; | 30 last_modified_time_ = time; |
| 31 } | 31 } |
| 32 | 32 |
| 33 void TestClipboard::OnPreShutdown() {} | 33 void TestClipboard::OnPreShutdown() {} |
| 34 | 34 |
| 35 uint64_t TestClipboard::GetSequenceNumber(ClipboardType type) const { | 35 uint64_t TestClipboard::GetSequenceNumber(ClipboardType type) const { |
| 36 return GetStore(type).sequence_number; | 36 return GetStore(type).sequence_number; |
| 37 } | 37 } |
| 38 | 38 |
| 39 bool TestClipboard::IsFormatAvailable(const FormatType& format, | 39 bool TestClipboard::IsFormatAvailable(const FormatType& format, |
| (...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 123 | 123 |
| 124 void TestClipboard::ReadData(const FormatType& format, | 124 void TestClipboard::ReadData(const FormatType& format, |
| 125 std::string* result) const { | 125 std::string* result) const { |
| 126 result->clear(); | 126 result->clear(); |
| 127 const DataStore& store = GetDefaultStore(); | 127 const DataStore& store = GetDefaultStore(); |
| 128 auto it = store.data.find(format); | 128 auto it = store.data.find(format); |
| 129 if (it != store.data.end()) | 129 if (it != store.data.end()) |
| 130 *result = it->second; | 130 *result = it->second; |
| 131 } | 131 } |
| 132 | 132 |
| 133 base::Time TestClipboard::GetClipboardLastModifiedTime() const { | 133 base::Time TestClipboard::GetLastModifiedTime() const { |
| 134 return last_modified_time_; | 134 return last_modified_time_; |
| 135 } | 135 } |
| 136 | 136 |
| 137 void TestClipboard::ClearLastModifiedTime() { |
| 138 last_modified_time_ = base::Time(); |
| 139 } |
| 140 |
| 137 void TestClipboard::WriteObjects(ClipboardType type, const ObjectMap& objects) { | 141 void TestClipboard::WriteObjects(ClipboardType type, const ObjectMap& objects) { |
| 138 Clear(type); | 142 Clear(type); |
| 139 default_store_type_ = type; | 143 default_store_type_ = type; |
| 140 for (const auto& kv : objects) | 144 for (const auto& kv : objects) |
| 141 DispatchObject(static_cast<ObjectType>(kv.first), kv.second); | 145 DispatchObject(static_cast<ObjectType>(kv.first), kv.second); |
| 142 default_store_type_ = CLIPBOARD_TYPE_COPY_PASTE; | 146 default_store_type_ = CLIPBOARD_TYPE_COPY_PASTE; |
| 143 } | 147 } |
| 144 | 148 |
| 145 void TestClipboard::WriteText(const char* text_data, size_t text_len) { | 149 void TestClipboard::WriteText(const char* text_data, size_t text_len) { |
| 146 std::string text(text_data, text_len); | 150 std::string text(text_data, text_len); |
| (...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 220 | 224 |
| 221 const TestClipboard::DataStore& TestClipboard::GetDefaultStore() const { | 225 const TestClipboard::DataStore& TestClipboard::GetDefaultStore() const { |
| 222 return GetStore(default_store_type_); | 226 return GetStore(default_store_type_); |
| 223 } | 227 } |
| 224 | 228 |
| 225 TestClipboard::DataStore& TestClipboard::GetDefaultStore() { | 229 TestClipboard::DataStore& TestClipboard::GetDefaultStore() { |
| 226 return GetStore(default_store_type_); | 230 return GetStore(default_store_type_); |
| 227 } | 231 } |
| 228 | 232 |
| 229 } // namespace ui | 233 } // namespace ui |
| OLD | NEW |