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

Side by Side Diff: base/clipboard_unittest.cc

Issue 174367: Change the ChromiumPasteboard to have a notion of an alternate clipboard... (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 11 years, 3 months 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 | Annotate | Revision Log
« no previous file with comments | « base/clipboard_mac.mm ('k') | base/clipboard_win.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 (c) 2006-2008 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2006-2008 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 <string> 5 #include <string>
6 6
7 #include "base/basictypes.h" 7 #include "base/basictypes.h"
8 #include "base/clipboard.h" 8 #include "base/clipboard.h"
9 #include "base/gfx/size.h" 9 #include "base/gfx/size.h"
10 #include "base/message_loop.h" 10 #include "base/message_loop.h"
(...skipping 26 matching lines...) Expand all
37 ScopedClipboardWriter clipboard_writer(&clipboard); 37 ScopedClipboardWriter clipboard_writer(&clipboard);
38 clipboard_writer.WriteText(ASCIIToUTF16("clear me")); 38 clipboard_writer.WriteText(ASCIIToUTF16("clear me"));
39 } 39 }
40 40
41 { 41 {
42 ScopedClipboardWriter clipboard_writer(&clipboard); 42 ScopedClipboardWriter clipboard_writer(&clipboard);
43 clipboard_writer.WriteHTML(ASCIIToUTF16("<b>broom</b>"), ""); 43 clipboard_writer.WriteHTML(ASCIIToUTF16("<b>broom</b>"), "");
44 } 44 }
45 45
46 EXPECT_FALSE(clipboard.IsFormatAvailable( 46 EXPECT_FALSE(clipboard.IsFormatAvailable(
47 Clipboard::GetPlainTextWFormatType())); 47 Clipboard::GetPlainTextWFormatType(), Clipboard::BUFFER_STANDARD));
48 EXPECT_FALSE(clipboard.IsFormatAvailable( 48 EXPECT_FALSE(clipboard.IsFormatAvailable(
49 Clipboard::GetPlainTextFormatType())); 49 Clipboard::GetPlainTextFormatType(), Clipboard::BUFFER_STANDARD));
50 } 50 }
51 51
52 TEST_F(ClipboardTest, TextTest) { 52 TEST_F(ClipboardTest, TextTest) {
53 Clipboard clipboard; 53 Clipboard clipboard;
54 54
55 string16 text(ASCIIToUTF16("This is a string16!#$")), text_result; 55 string16 text(ASCIIToUTF16("This is a string16!#$")), text_result;
56 std::string ascii_text; 56 std::string ascii_text;
57 57
58 { 58 {
59 ScopedClipboardWriter clipboard_writer(&clipboard); 59 ScopedClipboardWriter clipboard_writer(&clipboard);
60 clipboard_writer.WriteText(text); 60 clipboard_writer.WriteText(text);
61 } 61 }
62 62
63 EXPECT_TRUE(clipboard.IsFormatAvailable( 63 EXPECT_TRUE(clipboard.IsFormatAvailable(
64 Clipboard::GetPlainTextWFormatType())); 64 Clipboard::GetPlainTextWFormatType(), Clipboard::BUFFER_STANDARD));
65 EXPECT_TRUE(clipboard.IsFormatAvailable(Clipboard::GetPlainTextFormatType())); 65 EXPECT_TRUE(clipboard.IsFormatAvailable(Clipboard::GetPlainTextFormatType(),
66 clipboard.ReadText(&text_result); 66 Clipboard::BUFFER_STANDARD));
67 clipboard.ReadText(Clipboard::BUFFER_STANDARD, &text_result);
67 68
68 EXPECT_EQ(text, text_result); 69 EXPECT_EQ(text, text_result);
69 clipboard.ReadAsciiText(&ascii_text); 70 clipboard.ReadAsciiText(Clipboard::BUFFER_STANDARD, &ascii_text);
70 EXPECT_EQ(UTF16ToUTF8(text), ascii_text); 71 EXPECT_EQ(UTF16ToUTF8(text), ascii_text);
71 } 72 }
72 73
73 TEST_F(ClipboardTest, HTMLTest) { 74 TEST_F(ClipboardTest, HTMLTest) {
74 Clipboard clipboard; 75 Clipboard clipboard;
75 76
76 string16 markup(ASCIIToUTF16("<string>Hi!</string>")), markup_result; 77 string16 markup(ASCIIToUTF16("<string>Hi!</string>")), markup_result;
77 std::string url("http://www.example.com/"), url_result; 78 std::string url("http://www.example.com/"), url_result;
78 79
79 { 80 {
80 ScopedClipboardWriter clipboard_writer(&clipboard); 81 ScopedClipboardWriter clipboard_writer(&clipboard);
81 clipboard_writer.WriteHTML(markup, url); 82 clipboard_writer.WriteHTML(markup, url);
82 } 83 }
83 84
84 EXPECT_TRUE(clipboard.IsFormatAvailable(Clipboard::GetHtmlFormatType())); 85 EXPECT_TRUE(clipboard.IsFormatAvailable(Clipboard::GetHtmlFormatType(),
85 clipboard.ReadHTML(&markup_result, &url_result); 86 Clipboard::BUFFER_STANDARD));
87 clipboard.ReadHTML(Clipboard::BUFFER_STANDARD, &markup_result, &url_result);
86 EXPECT_EQ(markup, markup_result); 88 EXPECT_EQ(markup, markup_result);
87 #if defined(OS_WIN) 89 #if defined(OS_WIN)
88 // TODO(playmobil): It's not clear that non windows clipboards need to support 90 // TODO(playmobil): It's not clear that non windows clipboards need to support
89 // this. 91 // this.
90 EXPECT_EQ(url, url_result); 92 EXPECT_EQ(url, url_result);
91 #endif // defined(OS_WIN) 93 #endif // defined(OS_WIN)
92 } 94 }
93 95
94 TEST_F(ClipboardTest, TrickyHTMLTest) { 96 TEST_F(ClipboardTest, TrickyHTMLTest) {
95 Clipboard clipboard; 97 Clipboard clipboard;
96 98
97 string16 markup(ASCIIToUTF16("<em>Bye!<!--EndFragment --></em>")), 99 string16 markup(ASCIIToUTF16("<em>Bye!<!--EndFragment --></em>")),
98 markup_result; 100 markup_result;
99 std::string url, url_result; 101 std::string url, url_result;
100 102
101 { 103 {
102 ScopedClipboardWriter clipboard_writer(&clipboard); 104 ScopedClipboardWriter clipboard_writer(&clipboard);
103 clipboard_writer.WriteHTML(markup, url); 105 clipboard_writer.WriteHTML(markup, url);
104 } 106 }
105 107
106 EXPECT_TRUE(clipboard.IsFormatAvailable(Clipboard::GetHtmlFormatType())); 108 EXPECT_TRUE(clipboard.IsFormatAvailable(Clipboard::GetHtmlFormatType(),
107 clipboard.ReadHTML(&markup_result, &url_result); 109 Clipboard::BUFFER_STANDARD));
110 clipboard.ReadHTML(Clipboard::BUFFER_STANDARD, &markup_result, &url_result);
108 EXPECT_EQ(markup, markup_result); 111 EXPECT_EQ(markup, markup_result);
109 #if defined(OS_WIN) 112 #if defined(OS_WIN)
110 // TODO(playmobil): It's not clear that non windows clipboards need to support 113 // TODO(playmobil): It's not clear that non windows clipboards need to support
111 // this. 114 // this.
112 EXPECT_EQ(url, url_result); 115 EXPECT_EQ(url, url_result);
113 #endif // defined(OS_WIN) 116 #endif // defined(OS_WIN)
114 } 117 }
115 118
116 // TODO(estade): Port the following test (decide what target we use for urls) 119 // TODO(estade): Port the following test (decide what target we use for urls)
117 #if !defined(OS_LINUX) 120 #if !defined(OS_LINUX)
118 TEST_F(ClipboardTest, BookmarkTest) { 121 TEST_F(ClipboardTest, BookmarkTest) {
119 Clipboard clipboard; 122 Clipboard clipboard;
120 123
121 string16 title(ASCIIToUTF16("The Example Company")), title_result; 124 string16 title(ASCIIToUTF16("The Example Company")), title_result;
122 std::string url("http://www.example.com/"), url_result; 125 std::string url("http://www.example.com/"), url_result;
123 126
124 { 127 {
125 ScopedClipboardWriter clipboard_writer(&clipboard); 128 ScopedClipboardWriter clipboard_writer(&clipboard);
126 clipboard_writer.WriteBookmark(title, url); 129 clipboard_writer.WriteBookmark(title, url);
127 } 130 }
128 131
129 EXPECT_TRUE(clipboard.IsFormatAvailable(Clipboard::GetUrlWFormatType())); 132 EXPECT_TRUE(clipboard.IsFormatAvailable(Clipboard::GetUrlWFormatType(),
133 Clipboard::BUFFER_STANDARD));
130 clipboard.ReadBookmark(&title_result, &url_result); 134 clipboard.ReadBookmark(&title_result, &url_result);
131 EXPECT_EQ(title, title_result); 135 EXPECT_EQ(title, title_result);
132 EXPECT_EQ(url, url_result); 136 EXPECT_EQ(url, url_result);
133 } 137 }
134 #endif // defined(OS_WIN) 138 #endif // defined(OS_WIN)
135 139
136 TEST_F(ClipboardTest, MultiFormatTest) { 140 TEST_F(ClipboardTest, MultiFormatTest) {
137 Clipboard clipboard; 141 Clipboard clipboard;
138 142
139 string16 text(ASCIIToUTF16("Hi!")), text_result; 143 string16 text(ASCIIToUTF16("Hi!")), text_result;
140 string16 markup(ASCIIToUTF16("<strong>Hi!</string>")), markup_result; 144 string16 markup(ASCIIToUTF16("<strong>Hi!</string>")), markup_result;
141 std::string url("http://www.example.com/"), url_result; 145 std::string url("http://www.example.com/"), url_result;
142 std::string ascii_text; 146 std::string ascii_text;
143 147
144 { 148 {
145 ScopedClipboardWriter clipboard_writer(&clipboard); 149 ScopedClipboardWriter clipboard_writer(&clipboard);
146 clipboard_writer.WriteHTML(markup, url); 150 clipboard_writer.WriteHTML(markup, url);
147 clipboard_writer.WriteText(text); 151 clipboard_writer.WriteText(text);
148 } 152 }
149 153
150 EXPECT_TRUE(clipboard.IsFormatAvailable(Clipboard::GetHtmlFormatType())); 154 EXPECT_TRUE(clipboard.IsFormatAvailable(Clipboard::GetHtmlFormatType(),
155 Clipboard::BUFFER_STANDARD));
151 EXPECT_TRUE(clipboard.IsFormatAvailable( 156 EXPECT_TRUE(clipboard.IsFormatAvailable(
152 Clipboard::GetPlainTextWFormatType())); 157 Clipboard::GetPlainTextWFormatType(), Clipboard::BUFFER_STANDARD));
153 EXPECT_TRUE(clipboard.IsFormatAvailable( 158 EXPECT_TRUE(clipboard.IsFormatAvailable(
154 Clipboard::GetPlainTextFormatType())); 159 Clipboard::GetPlainTextFormatType(), Clipboard::BUFFER_STANDARD));
155 clipboard.ReadHTML(&markup_result, &url_result); 160 clipboard.ReadHTML(Clipboard::BUFFER_STANDARD, &markup_result, &url_result);
156 EXPECT_EQ(markup, markup_result); 161 EXPECT_EQ(markup, markup_result);
157 #if defined(OS_WIN) 162 #if defined(OS_WIN)
158 // TODO(playmobil): It's not clear that non windows clipboards need to support 163 // TODO(playmobil): It's not clear that non windows clipboards need to support
159 // this. 164 // this.
160 EXPECT_EQ(url, url_result); 165 EXPECT_EQ(url, url_result);
161 #endif // defined(OS_WIN) 166 #endif // defined(OS_WIN)
162 clipboard.ReadText(&text_result); 167 clipboard.ReadText(Clipboard::BUFFER_STANDARD, &text_result);
163 EXPECT_EQ(text, text_result); 168 EXPECT_EQ(text, text_result);
164 clipboard.ReadAsciiText(&ascii_text); 169 clipboard.ReadAsciiText(Clipboard::BUFFER_STANDARD, &ascii_text);
165 EXPECT_EQ(UTF16ToUTF8(text), ascii_text); 170 EXPECT_EQ(UTF16ToUTF8(text), ascii_text);
166 } 171 }
167 172
168 // TODO(estade): Port the following tests (decide what targets we use for files) 173 // TODO(estade): Port the following tests (decide what targets we use for files)
169 #if !defined(OS_LINUX) 174 #if !defined(OS_LINUX)
170 // Files for this test don't actually need to exist on the file system, just 175 // Files for this test don't actually need to exist on the file system, just
171 // don't try to use a non-existent file you've retrieved from the clipboard. 176 // don't try to use a non-existent file you've retrieved from the clipboard.
172 TEST_F(ClipboardTest, FileTest) { 177 TEST_F(ClipboardTest, FileTest) {
173 Clipboard clipboard; 178 Clipboard clipboard;
174 #if defined(OS_WIN) 179 #if defined(OS_WIN)
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
228 const char* format = "chromium/x-test-format"; 233 const char* format = "chromium/x-test-format";
229 std::string payload("test string"); 234 std::string payload("test string");
230 Pickle write_pickle; 235 Pickle write_pickle;
231 write_pickle.WriteString(payload); 236 write_pickle.WriteString(payload);
232 237
233 { 238 {
234 ScopedClipboardWriter clipboard_writer(&clipboard); 239 ScopedClipboardWriter clipboard_writer(&clipboard);
235 clipboard_writer.WritePickledData(write_pickle, format); 240 clipboard_writer.WritePickledData(write_pickle, format);
236 } 241 }
237 242
238 ASSERT_TRUE(clipboard.IsFormatAvailableByString(format)); 243 ASSERT_TRUE(clipboard.IsFormatAvailableByString(
244 format, Clipboard::BUFFER_STANDARD));
239 std::string output; 245 std::string output;
240 clipboard.ReadData(format, &output); 246 clipboard.ReadData(format, &output);
241 ASSERT_FALSE(output.empty()); 247 ASSERT_FALSE(output.empty());
242 248
243 Pickle read_pickle(output.data(), output.size()); 249 Pickle read_pickle(output.data(), output.size());
244 void* iter = NULL; 250 void* iter = NULL;
245 std::string unpickled_string; 251 std::string unpickled_string;
246 ASSERT_TRUE(read_pickle.ReadString(&iter, &unpickled_string)); 252 ASSERT_TRUE(read_pickle.ReadString(&iter, &unpickled_string));
247 EXPECT_EQ(payload, unpickled_string); 253 EXPECT_EQ(payload, unpickled_string);
248 } 254 }
249 #endif 255 #endif
250 256
251 #if defined(OS_WIN) // Windows only tests. 257 #if defined(OS_WIN) // Windows only tests.
252 TEST_F(ClipboardTest, HyperlinkTest) { 258 TEST_F(ClipboardTest, HyperlinkTest) {
253 Clipboard clipboard; 259 Clipboard clipboard;
254 260
255 string16 title(ASCIIToUTF16("The Example Company")), title_result; 261 string16 title(ASCIIToUTF16("The Example Company")), title_result;
256 std::string url("http://www.example.com/"), url_result; 262 std::string url("http://www.example.com/"), url_result;
257 string16 html(ASCIIToUTF16("<a href=\"http://www.example.com/\">" 263 string16 html(ASCIIToUTF16("<a href=\"http://www.example.com/\">"
258 "The Example Company</a>")), html_result; 264 "The Example Company</a>")), html_result;
259 265
260 { 266 {
261 ScopedClipboardWriter clipboard_writer(&clipboard); 267 ScopedClipboardWriter clipboard_writer(&clipboard);
262 clipboard_writer.WriteHyperlink(title, url); 268 clipboard_writer.WriteHyperlink(title, url);
263 } 269 }
264 270
265 EXPECT_TRUE(clipboard.IsFormatAvailable(Clipboard::GetUrlWFormatType())); 271 EXPECT_TRUE(clipboard.IsFormatAvailable(Clipboard::GetUrlWFormatType(),
266 EXPECT_TRUE(clipboard.IsFormatAvailable(Clipboard::GetHtmlFormatType())); 272 Clipboard::BUFFER_STANDARD));
273 EXPECT_TRUE(clipboard.IsFormatAvailable(Clipboard::GetHtmlFormatType(),
274 Clipboard::BUFFER_STANDARD));
267 clipboard.ReadBookmark(&title_result, &url_result); 275 clipboard.ReadBookmark(&title_result, &url_result);
268 EXPECT_EQ(title, title_result); 276 EXPECT_EQ(title, title_result);
269 EXPECT_EQ(url, url_result); 277 EXPECT_EQ(url, url_result);
270 clipboard.ReadHTML(&html_result, &url_result); 278 clipboard.ReadHTML(Clipboard::BUFFER_STANDARD, &html_result, &url_result);
271 EXPECT_EQ(html, html_result); 279 EXPECT_EQ(html, html_result);
272 } 280 }
273 281
274 TEST_F(ClipboardTest, WebSmartPasteTest) { 282 TEST_F(ClipboardTest, WebSmartPasteTest) {
275 Clipboard clipboard; 283 Clipboard clipboard;
276 284
277 { 285 {
278 ScopedClipboardWriter clipboard_writer(&clipboard); 286 ScopedClipboardWriter clipboard_writer(&clipboard);
279 clipboard_writer.WriteWebSmartPaste(); 287 clipboard_writer.WriteWebSmartPaste();
280 } 288 }
281 289
282 EXPECT_TRUE(clipboard.IsFormatAvailable( 290 EXPECT_TRUE(clipboard.IsFormatAvailable(
283 Clipboard::GetWebKitSmartPasteFormatType())); 291 Clipboard::GetWebKitSmartPasteFormatType(), Clipboard::BUFFER_STANDARD));
284 } 292 }
285 293
286 TEST_F(ClipboardTest, BitmapTest) { 294 TEST_F(ClipboardTest, BitmapTest) {
287 unsigned int fake_bitmap[] = { 295 unsigned int fake_bitmap[] = {
288 0x46155189, 0xF6A55C8D, 0x79845674, 0xFA57BD89, 296 0x46155189, 0xF6A55C8D, 0x79845674, 0xFA57BD89,
289 0x78FD46AE, 0x87C64F5A, 0x36EDC5AF, 0x4378F568, 297 0x78FD46AE, 0x87C64F5A, 0x36EDC5AF, 0x4378F568,
290 0x91E9F63A, 0xC31EA14F, 0x69AB32DF, 0x643A3FD1, 298 0x91E9F63A, 0xC31EA14F, 0x69AB32DF, 0x643A3FD1,
291 }; 299 };
292 300
293 Clipboard clipboard; 301 Clipboard clipboard;
294 302
295 { 303 {
296 ScopedClipboardWriter clipboard_writer(&clipboard); 304 ScopedClipboardWriter clipboard_writer(&clipboard);
297 clipboard_writer.WriteBitmapFromPixels(fake_bitmap, gfx::Size(3, 4)); 305 clipboard_writer.WriteBitmapFromPixels(fake_bitmap, gfx::Size(3, 4));
298 } 306 }
299 307
300 EXPECT_TRUE(clipboard.IsFormatAvailable(Clipboard::GetBitmapFormatType())); 308 EXPECT_TRUE(clipboard.IsFormatAvailable(Clipboard::GetBitmapFormatType(),
309 Clipboard::BUFFER_STANDARD));
301 } 310 }
302 #endif // defined(OS_WIN) 311 #endif // defined(OS_WIN)
OLDNEW
« no previous file with comments | « base/clipboard_mac.mm ('k') | base/clipboard_win.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698