Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(409)

Unified Diff: ui/base/clipboard/clipboard.h

Issue 720373003: Add FakeClipboard implementation for unit tests. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: One more fix... Created 6 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: ui/base/clipboard/clipboard.h
diff --git a/ui/base/clipboard/clipboard.h b/ui/base/clipboard/clipboard.h
index 66a5dcbf426b10be1fb7ea5e3758d9342b6fd235..d06bcabfa586c7a8d6bf86d04649414a7f6e7161 100644
--- a/ui/base/clipboard/clipboard.h
+++ b/ui/base/clipboard/clipboard.h
@@ -10,9 +10,11 @@
#include <vector>
#include "base/compiler_specific.h"
+#include "base/lazy_instance.h"
#include "base/memory/shared_memory.h"
#include "base/process/process.h"
#include "base/strings/string16.h"
+#include "base/synchronization/lock.h"
#include "base/threading/platform_thread.h"
#include "base/threading/thread_checker.h"
#include "ui/base/clipboard/clipboard_types.h"
@@ -50,6 +52,7 @@ class NSString;
namespace ui {
template <typename T>
class ClipboardTest;
+class FakeClipboard;
class ScopedClipboardWriter;
class UI_BASE_EXPORT Clipboard : NON_EXPORTED_BASE(public base::ThreadChecker) {
@@ -71,10 +74,8 @@ class UI_BASE_EXPORT Clipboard : NON_EXPORTED_BASE(public base::ThreadChecker) {
std::string Serialize() const;
static FormatType Deserialize(const std::string& serialization);
-#if !defined(OS_ANDROID)
// FormatType can be used in a set on some platforms.
bool operator<(const FormatType& other) const;
-#endif
#if defined(OS_WIN)
const FORMATETC& ToFormatEtc() const { return data_; }
@@ -187,6 +188,10 @@ class UI_BASE_EXPORT Clipboard : NON_EXPORTED_BASE(public base::ThreadChecker) {
// the IO thread.
static Clipboard* GetForCurrentThread();
+ // Testing helper to Replace any clipboard for the current thread with a fake
sky 2014/11/14 02:10:31 Why the caps for Replace?
dcheng 2014/11/14 03:30:28 Done.
+ // clipboard. Useful for unit tests, since those generally run in parallel.
+ static void UseFakeForCurrentThreadForTest();
sky 2014/11/14 02:10:31 How about UseTestClipboardForCurrentThread? Or Moc
dcheng 2014/11/14 03:30:28 Done.
+
// Destroys the clipboard for the current thread. Usually, this will clean up
// all clipboards, except on Windows. (Previous code leaks the IO thread
// clipboard, so it shouldn't be a problem.)
@@ -195,7 +200,7 @@ class UI_BASE_EXPORT Clipboard : NON_EXPORTED_BASE(public base::ThreadChecker) {
// Returns a sequence number which uniquely identifies clipboard state.
// This can be used to version the data on the clipboard and determine
// whether it has changed.
- virtual uint64 GetSequenceNumber(ClipboardType type) = 0;
+ virtual uint64 GetSequenceNumber(ClipboardType type) const = 0;
// Tests whether the clipboard contains a certain format
virtual bool IsFormatAvailable(const FormatType& format,
@@ -326,6 +331,19 @@ class UI_BASE_EXPORT Clipboard : NON_EXPORTED_BASE(public base::ThreadChecker) {
friend class content::ClipboardMessageFilter;
friend class ScopedClipboardWriter;
+ // A list of allowed threads. By default, this is empty and no thread checking
+ // is done (in the unit test case), but a user (like content) can set which
+ // threads are allowed to call this method.
+ typedef std::vector<base::PlatformThreadId> AllowedThreadsVector;
+ static base::LazyInstance<AllowedThreadsVector> allowed_threads_;
+
+ // Mapping from threads to clipboard objects.
+ typedef std::map<base::PlatformThreadId, Clipboard*> ClipboardMap;
+ static base::LazyInstance<ClipboardMap> clipboard_map_;
+
+ // Mutex that controls access to |g_clipboard_map|.
+ static base::LazyInstance<base::Lock>::Leaky clipboard_map_lock_;
+
DISALLOW_COPY_AND_ASSIGN(Clipboard);
};

Powered by Google App Engine
This is Rietveld 408576698