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

Side by Side Diff: ui/base/test/test_clipboard.h

Issue 720373003: Add FakeClipboard implementation for unit tests. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: WINDOWS!!! 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 unified diff | Download patch
« no previous file with comments | « ui/base/clipboard/clipboard_win.cc ('k') | ui/base/test/test_clipboard.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 #ifndef UI_BASE_CLIPBOARD_CLIPBOARD_WIN_H_ 5 #ifndef UI_BASE_TEST_TEST_CLIPBOARD_H_
6 #define UI_BASE_CLIPBOARD_CLIPBOARD_WIN_H_ 6 #define UI_BASE_TEST_TEST_CLIPBOARD_H_
7 7
8 #include <map>
9 #include "third_party/skia/include/core/SkBitmap.h"
8 #include "ui/base/clipboard/clipboard.h" 10 #include "ui/base/clipboard/clipboard.h"
9 11
10 #include "base/memory/scoped_ptr.h"
11
12 namespace ui { 12 namespace ui {
13 13
14 class ClipboardWin : public Clipboard { 14 class TestClipboard : public Clipboard {
15 private: 15 public:
16 friend class Clipboard; 16 TestClipboard();
17 ~TestClipboard() override;
17 18
18 ClipboardWin(); 19 static void UseForCurrentThread();
19 ~ClipboardWin() override;
20 20
21 // Clipboard overrides: 21 // Clipboard overrides.
22 uint64 GetSequenceNumber(ClipboardType type) override; 22 uint64 GetSequenceNumber(ClipboardType type) const override;
23 bool IsFormatAvailable(const FormatType& format, 23 bool IsFormatAvailable(const FormatType& format,
24 ClipboardType type) const override; 24 ClipboardType type) const override;
25 void Clear(ClipboardType type) override; 25 void Clear(ClipboardType type) override;
26 void ReadAvailableTypes(ClipboardType type, 26 void ReadAvailableTypes(ClipboardType type,
27 std::vector<base::string16>* types, 27 std::vector<base::string16>* types,
28 bool* contains_filenames) const override; 28 bool* contains_filenames) const override;
29 void ReadText(ClipboardType type, base::string16* result) const override; 29 void ReadText(ClipboardType type, base::string16* result) const override;
30 void ReadAsciiText(ClipboardType type, std::string* result) const override; 30 void ReadAsciiText(ClipboardType type, std::string* result) const override;
31 void ReadHTML(ClipboardType type, 31 void ReadHTML(ClipboardType type,
32 base::string16* markup, 32 base::string16* markup,
(...skipping 17 matching lines...) Expand all
50 void WriteBookmark(const char* title_data, 50 void WriteBookmark(const char* title_data,
51 size_t title_len, 51 size_t title_len,
52 const char* url_data, 52 const char* url_data,
53 size_t url_len) override; 53 size_t url_len) override;
54 void WriteWebSmartPaste() override; 54 void WriteWebSmartPaste() override;
55 void WriteBitmap(const SkBitmap& bitmap) override; 55 void WriteBitmap(const SkBitmap& bitmap) override;
56 void WriteData(const FormatType& format, 56 void WriteData(const FormatType& format,
57 const char* data_data, 57 const char* data_data,
58 size_t data_len) override; 58 size_t data_len) override;
59 59
60 void WriteBitmapFromHandle(HBITMAP source_hbitmap, const gfx::Size& size); 60 private:
61 struct DataStore {
62 DataStore();
63 ~DataStore();
64 void Clear();
65 uint64 sequence_number;
66 std::map<FormatType, std::string> data;
67 std::string url_title;
68 std::string html_src_url;
69 SkBitmap image;
70 };
61 71
62 // Safely write to system clipboard. Free |handle| on failure. 72 // The non-const versions increment the sequence number as a side effect.
63 void WriteToClipboard(unsigned int format, HANDLE handle); 73 const DataStore& GetStore(ClipboardType type) const;
74 const DataStore& GetDefaultStore() const;
75 DataStore& GetStore(ClipboardType type);
76 DataStore& GetDefaultStore();
64 77
65 // Return the window that should be the clipboard owner, creating it 78 ClipboardType default_store_type_;
66 // if neccessary. Marked const for lazily initialization by const methods. 79 mutable std::map<ClipboardType, DataStore> stores_;
67 HWND GetClipboardWindow() const;
68 80
69 // Mark this as mutable so const methods can still do lazy initialization. 81 DISALLOW_COPY_AND_ASSIGN(TestClipboard);
70 mutable scoped_ptr<base::win::MessageWindow> clipboard_owner_;
71
72 DISALLOW_COPY_AND_ASSIGN(ClipboardWin);
73 }; 82 };
74 83
75 } // namespace ui 84 } // namespace ui
76 85
77 #endif // UI_BASE_CLIPBOARD_CLIPBOARD_WIN_H_ 86 #endif // UI_BASE_TEST_TEST_CLIPBOARD_H_
OLDNEW
« no previous file with comments | « ui/base/clipboard/clipboard_win.cc ('k') | ui/base/test/test_clipboard.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698