OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 "build/build_config.h" | 5 #include "build/build_config.h" |
6 | 6 |
7 #include <string> | 7 #include <string> |
8 | 8 |
9 #include "base/basictypes.h" | 9 #include "base/basictypes.h" |
10 #include "base/memory/scoped_ptr.h" | 10 #include "base/memory/scoped_ptr.h" |
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
74 | 74 |
75 bool MarkupMatches(const base::string16& expected_markup, | 75 bool MarkupMatches(const base::string16& expected_markup, |
76 const base::string16& actual_markup) { | 76 const base::string16& actual_markup) { |
77 return actual_markup.find(expected_markup) != base::string16::npos; | 77 return actual_markup.find(expected_markup) != base::string16::npos; |
78 } | 78 } |
79 | 79 |
80 } // namespace | 80 } // namespace |
81 | 81 |
82 TEST_F(ClipboardTest, ClearTest) { | 82 TEST_F(ClipboardTest, ClearTest) { |
83 { | 83 { |
84 ScopedClipboardWriter clipboard_writer(&clipboard(), | 84 ScopedClipboardWriter clipboard_writer(CLIPBOARD_TYPE_COPY_PASTE); |
85 CLIPBOARD_TYPE_COPY_PASTE); | |
86 clipboard_writer.WriteText(ASCIIToUTF16("clear me")); | 85 clipboard_writer.WriteText(ASCIIToUTF16("clear me")); |
87 } | 86 } |
88 | 87 |
89 clipboard().Clear(CLIPBOARD_TYPE_COPY_PASTE); | 88 clipboard().Clear(CLIPBOARD_TYPE_COPY_PASTE); |
90 | 89 |
91 EXPECT_FALSE(clipboard().IsFormatAvailable( | 90 EXPECT_FALSE(clipboard().IsFormatAvailable( |
92 Clipboard::GetPlainTextWFormatType(), CLIPBOARD_TYPE_COPY_PASTE)); | 91 Clipboard::GetPlainTextWFormatType(), CLIPBOARD_TYPE_COPY_PASTE)); |
93 EXPECT_FALSE(clipboard().IsFormatAvailable( | 92 EXPECT_FALSE(clipboard().IsFormatAvailable( |
94 Clipboard::GetPlainTextFormatType(), CLIPBOARD_TYPE_COPY_PASTE)); | 93 Clipboard::GetPlainTextFormatType(), CLIPBOARD_TYPE_COPY_PASTE)); |
95 } | 94 } |
96 | 95 |
97 TEST_F(ClipboardTest, TextTest) { | 96 TEST_F(ClipboardTest, TextTest) { |
98 base::string16 text(ASCIIToUTF16("This is a base::string16!#$")), text_result; | 97 base::string16 text(ASCIIToUTF16("This is a base::string16!#$")), text_result; |
99 std::string ascii_text; | 98 std::string ascii_text; |
100 | 99 |
101 { | 100 { |
102 ScopedClipboardWriter clipboard_writer(&clipboard(), | 101 ScopedClipboardWriter clipboard_writer(CLIPBOARD_TYPE_COPY_PASTE); |
103 CLIPBOARD_TYPE_COPY_PASTE); | |
104 clipboard_writer.WriteText(text); | 102 clipboard_writer.WriteText(text); |
105 } | 103 } |
106 | 104 |
107 EXPECT_TRUE(clipboard().IsFormatAvailable( | 105 EXPECT_TRUE(clipboard().IsFormatAvailable( |
108 Clipboard::GetPlainTextWFormatType(), CLIPBOARD_TYPE_COPY_PASTE)); | 106 Clipboard::GetPlainTextWFormatType(), CLIPBOARD_TYPE_COPY_PASTE)); |
109 EXPECT_TRUE(clipboard().IsFormatAvailable(Clipboard::GetPlainTextFormatType(), | 107 EXPECT_TRUE(clipboard().IsFormatAvailable(Clipboard::GetPlainTextFormatType(), |
110 CLIPBOARD_TYPE_COPY_PASTE)); | 108 CLIPBOARD_TYPE_COPY_PASTE)); |
111 clipboard().ReadText(CLIPBOARD_TYPE_COPY_PASTE, &text_result); | 109 clipboard().ReadText(CLIPBOARD_TYPE_COPY_PASTE, &text_result); |
112 | 110 |
113 EXPECT_EQ(text, text_result); | 111 EXPECT_EQ(text, text_result); |
114 clipboard().ReadAsciiText(CLIPBOARD_TYPE_COPY_PASTE, &ascii_text); | 112 clipboard().ReadAsciiText(CLIPBOARD_TYPE_COPY_PASTE, &ascii_text); |
115 EXPECT_EQ(UTF16ToUTF8(text), ascii_text); | 113 EXPECT_EQ(UTF16ToUTF8(text), ascii_text); |
116 } | 114 } |
117 | 115 |
118 TEST_F(ClipboardTest, HTMLTest) { | 116 TEST_F(ClipboardTest, HTMLTest) { |
119 base::string16 markup(ASCIIToUTF16("<string>Hi!</string>")), markup_result; | 117 base::string16 markup(ASCIIToUTF16("<string>Hi!</string>")), markup_result; |
120 base::string16 plain(ASCIIToUTF16("Hi!")), plain_result; | 118 base::string16 plain(ASCIIToUTF16("Hi!")), plain_result; |
121 std::string url("http://www.example.com/"), url_result; | 119 std::string url("http://www.example.com/"), url_result; |
122 | 120 |
123 { | 121 { |
124 ScopedClipboardWriter clipboard_writer(&clipboard(), | 122 ScopedClipboardWriter clipboard_writer(CLIPBOARD_TYPE_COPY_PASTE); |
125 CLIPBOARD_TYPE_COPY_PASTE); | |
126 clipboard_writer.WriteText(plain); | 123 clipboard_writer.WriteText(plain); |
127 clipboard_writer.WriteHTML(markup, url); | 124 clipboard_writer.WriteHTML(markup, url); |
128 } | 125 } |
129 | 126 |
130 EXPECT_TRUE(clipboard().IsFormatAvailable(Clipboard::GetHtmlFormatType(), | 127 EXPECT_TRUE(clipboard().IsFormatAvailable(Clipboard::GetHtmlFormatType(), |
131 CLIPBOARD_TYPE_COPY_PASTE)); | 128 CLIPBOARD_TYPE_COPY_PASTE)); |
132 uint32 ignored; | 129 uint32 ignored; |
133 clipboard().ReadHTML(CLIPBOARD_TYPE_COPY_PASTE, &markup_result, &url_result, | 130 clipboard().ReadHTML(CLIPBOARD_TYPE_COPY_PASTE, &markup_result, &url_result, |
134 &ignored, &ignored); | 131 &ignored, &ignored); |
135 EXPECT_PRED2(MarkupMatches, markup, markup_result); | 132 EXPECT_PRED2(MarkupMatches, markup, markup_result); |
136 #if defined(OS_WIN) | 133 #if defined(OS_WIN) |
137 // TODO(playmobil): It's not clear that non windows clipboards need to support | 134 // TODO(playmobil): It's not clear that non windows clipboards need to support |
138 // this. | 135 // this. |
139 EXPECT_EQ(url, url_result); | 136 EXPECT_EQ(url, url_result); |
140 #endif // defined(OS_WIN) | 137 #endif // defined(OS_WIN) |
141 } | 138 } |
142 | 139 |
143 TEST_F(ClipboardTest, RTFTest) { | 140 TEST_F(ClipboardTest, RTFTest) { |
144 std::string rtf = | 141 std::string rtf = |
145 "{\\rtf1\\ansi{\\fonttbl\\f0\\fswiss Helvetica;}\\f0\\pard\n" | 142 "{\\rtf1\\ansi{\\fonttbl\\f0\\fswiss Helvetica;}\\f0\\pard\n" |
146 "This is some {\\b bold} text.\\par\n" | 143 "This is some {\\b bold} text.\\par\n" |
147 "}"; | 144 "}"; |
148 | 145 |
149 { | 146 { |
150 ScopedClipboardWriter clipboard_writer(&clipboard(), | 147 ScopedClipboardWriter clipboard_writer(CLIPBOARD_TYPE_COPY_PASTE); |
151 CLIPBOARD_TYPE_COPY_PASTE); | |
152 clipboard_writer.WriteRTF(rtf); | 148 clipboard_writer.WriteRTF(rtf); |
153 } | 149 } |
154 | 150 |
155 EXPECT_TRUE(clipboard().IsFormatAvailable(Clipboard::GetRtfFormatType(), | 151 EXPECT_TRUE(clipboard().IsFormatAvailable(Clipboard::GetRtfFormatType(), |
156 CLIPBOARD_TYPE_COPY_PASTE)); | 152 CLIPBOARD_TYPE_COPY_PASTE)); |
157 std::string result; | 153 std::string result; |
158 clipboard().ReadRTF(CLIPBOARD_TYPE_COPY_PASTE, &result); | 154 clipboard().ReadRTF(CLIPBOARD_TYPE_COPY_PASTE, &result); |
159 EXPECT_EQ(rtf, result); | 155 EXPECT_EQ(rtf, result); |
160 } | 156 } |
161 | 157 |
162 // TODO(dnicoara) Enable test once Ozone implements clipboard support: | 158 // TODO(dnicoara) Enable test once Ozone implements clipboard support: |
163 // crbug.com/361707 | 159 // crbug.com/361707 |
164 #if defined(OS_LINUX) && !defined(OS_CHROMEOS) && !defined(USE_OZONE) | 160 #if defined(OS_LINUX) && !defined(OS_CHROMEOS) && !defined(USE_OZONE) |
165 TEST_F(ClipboardTest, MultipleBufferTest) { | 161 TEST_F(ClipboardTest, MultipleBufferTest) { |
166 base::string16 text(ASCIIToUTF16("Standard")), text_result; | 162 base::string16 text(ASCIIToUTF16("Standard")), text_result; |
167 base::string16 markup(ASCIIToUTF16("<string>Selection</string>")); | 163 base::string16 markup(ASCIIToUTF16("<string>Selection</string>")); |
168 std::string url("http://www.example.com/"), url_result; | 164 std::string url("http://www.example.com/"), url_result; |
169 | 165 |
170 { | 166 { |
171 ScopedClipboardWriter clipboard_writer(&clipboard(), | 167 ScopedClipboardWriter clipboard_writer(CLIPBOARD_TYPE_COPY_PASTE); |
172 CLIPBOARD_TYPE_COPY_PASTE); | |
173 clipboard_writer.WriteText(text); | 168 clipboard_writer.WriteText(text); |
174 } | 169 } |
175 | 170 |
176 { | 171 { |
177 ScopedClipboardWriter clipboard_writer(&clipboard(), | 172 ScopedClipboardWriter clipboard_writer(CLIPBOARD_TYPE_SELECTION); |
178 CLIPBOARD_TYPE_SELECTION); | |
179 clipboard_writer.WriteHTML(markup, url); | 173 clipboard_writer.WriteHTML(markup, url); |
180 } | 174 } |
181 | 175 |
182 EXPECT_TRUE(clipboard().IsFormatAvailable(Clipboard::GetPlainTextFormatType(), | 176 EXPECT_TRUE(clipboard().IsFormatAvailable(Clipboard::GetPlainTextFormatType(), |
183 CLIPBOARD_TYPE_COPY_PASTE)); | 177 CLIPBOARD_TYPE_COPY_PASTE)); |
184 EXPECT_FALSE(clipboard().IsFormatAvailable( | 178 EXPECT_FALSE(clipboard().IsFormatAvailable( |
185 Clipboard::GetPlainTextFormatType(), | 179 Clipboard::GetPlainTextFormatType(), |
186 CLIPBOARD_TYPE_SELECTION)); | 180 CLIPBOARD_TYPE_SELECTION)); |
187 | 181 |
188 EXPECT_FALSE(clipboard().IsFormatAvailable(Clipboard::GetHtmlFormatType(), | 182 EXPECT_FALSE(clipboard().IsFormatAvailable(Clipboard::GetHtmlFormatType(), |
(...skipping 15 matching lines...) Expand all Loading... |
204 } | 198 } |
205 #endif | 199 #endif |
206 | 200 |
207 TEST_F(ClipboardTest, TrickyHTMLTest) { | 201 TEST_F(ClipboardTest, TrickyHTMLTest) { |
208 base::string16 markup(ASCIIToUTF16("<em>Bye!<!--EndFragment --></em>")), | 202 base::string16 markup(ASCIIToUTF16("<em>Bye!<!--EndFragment --></em>")), |
209 markup_result; | 203 markup_result; |
210 std::string url, url_result; | 204 std::string url, url_result; |
211 base::string16 plain(ASCIIToUTF16("Bye!")), plain_result; | 205 base::string16 plain(ASCIIToUTF16("Bye!")), plain_result; |
212 | 206 |
213 { | 207 { |
214 ScopedClipboardWriter clipboard_writer(&clipboard(), | 208 ScopedClipboardWriter clipboard_writer(CLIPBOARD_TYPE_COPY_PASTE); |
215 CLIPBOARD_TYPE_COPY_PASTE); | |
216 clipboard_writer.WriteText(plain); | 209 clipboard_writer.WriteText(plain); |
217 clipboard_writer.WriteHTML(markup, url); | 210 clipboard_writer.WriteHTML(markup, url); |
218 } | 211 } |
219 | 212 |
220 EXPECT_TRUE(clipboard().IsFormatAvailable(Clipboard::GetHtmlFormatType(), | 213 EXPECT_TRUE(clipboard().IsFormatAvailable(Clipboard::GetHtmlFormatType(), |
221 CLIPBOARD_TYPE_COPY_PASTE)); | 214 CLIPBOARD_TYPE_COPY_PASTE)); |
222 uint32 ignored; | 215 uint32 ignored; |
223 clipboard().ReadHTML(CLIPBOARD_TYPE_COPY_PASTE, &markup_result, &url_result, | 216 clipboard().ReadHTML(CLIPBOARD_TYPE_COPY_PASTE, &markup_result, &url_result, |
224 &ignored, &ignored); | 217 &ignored, &ignored); |
225 EXPECT_PRED2(MarkupMatches, markup, markup_result); | 218 EXPECT_PRED2(MarkupMatches, markup, markup_result); |
226 #if defined(OS_WIN) | 219 #if defined(OS_WIN) |
227 // TODO(playmobil): It's not clear that non windows clipboards need to support | 220 // TODO(playmobil): It's not clear that non windows clipboards need to support |
228 // this. | 221 // this. |
229 EXPECT_EQ(url, url_result); | 222 EXPECT_EQ(url, url_result); |
230 #endif // defined(OS_WIN) | 223 #endif // defined(OS_WIN) |
231 } | 224 } |
232 | 225 |
233 #if defined(OS_WIN) | 226 #if defined(OS_WIN) |
234 TEST_F(ClipboardTest, UniodeHTMLTest) { | 227 TEST_F(ClipboardTest, UniodeHTMLTest) { |
235 base::string16 markup(UTF8ToUTF16("<div>A \xc3\xb8 \xe6\xb0\xb4</div>")), | 228 base::string16 markup(UTF8ToUTF16("<div>A \xc3\xb8 \xe6\xb0\xb4</div>")), |
236 markup_result; | 229 markup_result; |
237 std::string url, url_result; | 230 std::string url, url_result; |
238 | 231 |
239 { | 232 { |
240 ScopedClipboardWriter clipboard_writer(&clipboard(), | 233 ScopedClipboardWriter clipboard_writer(CLIPBOARD_TYPE_COPY_PASTE); |
241 CLIPBOARD_TYPE_COPY_PASTE); | |
242 clipboard_writer.WriteHTML(markup, url); | 234 clipboard_writer.WriteHTML(markup, url); |
243 } | 235 } |
244 | 236 |
245 EXPECT_TRUE(clipboard().IsFormatAvailable(Clipboard::GetHtmlFormatType(), | 237 EXPECT_TRUE(clipboard().IsFormatAvailable(Clipboard::GetHtmlFormatType(), |
246 CLIPBOARD_TYPE_COPY_PASTE)); | 238 CLIPBOARD_TYPE_COPY_PASTE)); |
247 uint32 fragment_start; | 239 uint32 fragment_start; |
248 uint32 fragment_end; | 240 uint32 fragment_end; |
249 clipboard().ReadHTML(CLIPBOARD_TYPE_COPY_PASTE, &markup_result, &url_result, | 241 clipboard().ReadHTML(CLIPBOARD_TYPE_COPY_PASTE, &markup_result, &url_result, |
250 &fragment_start, &fragment_end); | 242 &fragment_start, &fragment_end); |
251 EXPECT_PRED2(MarkupMatches, markup, markup_result); | 243 EXPECT_PRED2(MarkupMatches, markup, markup_result); |
252 EXPECT_EQ(url, url_result); | 244 EXPECT_EQ(url, url_result); |
253 // Make sure that fragment indices were adjusted when converting. | 245 // Make sure that fragment indices were adjusted when converting. |
254 EXPECT_EQ(36, fragment_start); | 246 EXPECT_EQ(36, fragment_start); |
255 EXPECT_EQ(52, fragment_end); | 247 EXPECT_EQ(52, fragment_end); |
256 } | 248 } |
257 #endif // defined(OS_WIN) | 249 #endif // defined(OS_WIN) |
258 | 250 |
259 // TODO(estade): Port the following test (decide what target we use for urls) | 251 // TODO(estade): Port the following test (decide what target we use for urls) |
260 #if !defined(OS_POSIX) || defined(OS_MACOSX) | 252 #if !defined(OS_POSIX) || defined(OS_MACOSX) |
261 TEST_F(ClipboardTest, BookmarkTest) { | 253 TEST_F(ClipboardTest, BookmarkTest) { |
262 base::string16 title(ASCIIToUTF16("The Example Company")), title_result; | 254 base::string16 title(ASCIIToUTF16("The Example Company")), title_result; |
263 std::string url("http://www.example.com/"), url_result; | 255 std::string url("http://www.example.com/"), url_result; |
264 | 256 |
265 { | 257 { |
266 ScopedClipboardWriter clipboard_writer(&clipboard(), | 258 ScopedClipboardWriter clipboard_writer(CLIPBOARD_TYPE_COPY_PASTE); |
267 CLIPBOARD_TYPE_COPY_PASTE); | |
268 clipboard_writer.WriteBookmark(title, url); | 259 clipboard_writer.WriteBookmark(title, url); |
269 } | 260 } |
270 | 261 |
271 EXPECT_TRUE(clipboard().IsFormatAvailable(Clipboard::GetUrlWFormatType(), | 262 EXPECT_TRUE(clipboard().IsFormatAvailable(Clipboard::GetUrlWFormatType(), |
272 CLIPBOARD_TYPE_COPY_PASTE)); | 263 CLIPBOARD_TYPE_COPY_PASTE)); |
273 clipboard().ReadBookmark(&title_result, &url_result); | 264 clipboard().ReadBookmark(&title_result, &url_result); |
274 EXPECT_EQ(title, title_result); | 265 EXPECT_EQ(title, title_result); |
275 EXPECT_EQ(url, url_result); | 266 EXPECT_EQ(url, url_result); |
276 } | 267 } |
277 #endif // defined(OS_WIN) | 268 #endif // defined(OS_WIN) |
278 | 269 |
279 TEST_F(ClipboardTest, MultiFormatTest) { | 270 TEST_F(ClipboardTest, MultiFormatTest) { |
280 base::string16 text(ASCIIToUTF16("Hi!")), text_result; | 271 base::string16 text(ASCIIToUTF16("Hi!")), text_result; |
281 base::string16 markup(ASCIIToUTF16("<strong>Hi!</string>")), markup_result; | 272 base::string16 markup(ASCIIToUTF16("<strong>Hi!</string>")), markup_result; |
282 std::string url("http://www.example.com/"), url_result; | 273 std::string url("http://www.example.com/"), url_result; |
283 std::string ascii_text; | 274 std::string ascii_text; |
284 | 275 |
285 { | 276 { |
286 ScopedClipboardWriter clipboard_writer(&clipboard(), | 277 ScopedClipboardWriter clipboard_writer(CLIPBOARD_TYPE_COPY_PASTE); |
287 CLIPBOARD_TYPE_COPY_PASTE); | |
288 clipboard_writer.WriteHTML(markup, url); | 278 clipboard_writer.WriteHTML(markup, url); |
289 clipboard_writer.WriteText(text); | 279 clipboard_writer.WriteText(text); |
290 } | 280 } |
291 | 281 |
292 EXPECT_TRUE(clipboard().IsFormatAvailable(Clipboard::GetHtmlFormatType(), | 282 EXPECT_TRUE(clipboard().IsFormatAvailable(Clipboard::GetHtmlFormatType(), |
293 CLIPBOARD_TYPE_COPY_PASTE)); | 283 CLIPBOARD_TYPE_COPY_PASTE)); |
294 EXPECT_TRUE(clipboard().IsFormatAvailable( | 284 EXPECT_TRUE(clipboard().IsFormatAvailable( |
295 Clipboard::GetPlainTextWFormatType(), CLIPBOARD_TYPE_COPY_PASTE)); | 285 Clipboard::GetPlainTextWFormatType(), CLIPBOARD_TYPE_COPY_PASTE)); |
296 EXPECT_TRUE(clipboard().IsFormatAvailable( | 286 EXPECT_TRUE(clipboard().IsFormatAvailable( |
297 Clipboard::GetPlainTextFormatType(), CLIPBOARD_TYPE_COPY_PASTE)); | 287 Clipboard::GetPlainTextFormatType(), CLIPBOARD_TYPE_COPY_PASTE)); |
298 uint32 ignored; | 288 uint32 ignored; |
299 clipboard().ReadHTML(CLIPBOARD_TYPE_COPY_PASTE, &markup_result, &url_result, | 289 clipboard().ReadHTML(CLIPBOARD_TYPE_COPY_PASTE, &markup_result, &url_result, |
300 &ignored, &ignored); | 290 &ignored, &ignored); |
301 EXPECT_PRED2(MarkupMatches, markup, markup_result); | 291 EXPECT_PRED2(MarkupMatches, markup, markup_result); |
302 #if defined(OS_WIN) | 292 #if defined(OS_WIN) |
303 // TODO(playmobil): It's not clear that non windows clipboards need to support | 293 // TODO(playmobil): It's not clear that non windows clipboards need to support |
304 // this. | 294 // this. |
305 EXPECT_EQ(url, url_result); | 295 EXPECT_EQ(url, url_result); |
306 #endif // defined(OS_WIN) | 296 #endif // defined(OS_WIN) |
307 clipboard().ReadText(CLIPBOARD_TYPE_COPY_PASTE, &text_result); | 297 clipboard().ReadText(CLIPBOARD_TYPE_COPY_PASTE, &text_result); |
308 EXPECT_EQ(text, text_result); | 298 EXPECT_EQ(text, text_result); |
309 clipboard().ReadAsciiText(CLIPBOARD_TYPE_COPY_PASTE, &ascii_text); | 299 clipboard().ReadAsciiText(CLIPBOARD_TYPE_COPY_PASTE, &ascii_text); |
310 EXPECT_EQ(UTF16ToUTF8(text), ascii_text); | 300 EXPECT_EQ(UTF16ToUTF8(text), ascii_text); |
311 } | 301 } |
312 | 302 |
313 TEST_F(ClipboardTest, URLTest) { | 303 TEST_F(ClipboardTest, URLTest) { |
314 base::string16 url(ASCIIToUTF16("http://www.google.com/")); | 304 base::string16 url(ASCIIToUTF16("http://www.google.com/")); |
315 | 305 |
316 { | 306 { |
317 ScopedClipboardWriter clipboard_writer(&clipboard(), | 307 ScopedClipboardWriter clipboard_writer(CLIPBOARD_TYPE_COPY_PASTE); |
318 CLIPBOARD_TYPE_COPY_PASTE); | |
319 clipboard_writer.WriteURL(url); | 308 clipboard_writer.WriteURL(url); |
320 } | 309 } |
321 | 310 |
322 EXPECT_TRUE(clipboard().IsFormatAvailable( | 311 EXPECT_TRUE(clipboard().IsFormatAvailable( |
323 Clipboard::GetPlainTextWFormatType(), CLIPBOARD_TYPE_COPY_PASTE)); | 312 Clipboard::GetPlainTextWFormatType(), CLIPBOARD_TYPE_COPY_PASTE)); |
324 EXPECT_TRUE(clipboard().IsFormatAvailable(Clipboard::GetPlainTextFormatType(), | 313 EXPECT_TRUE(clipboard().IsFormatAvailable(Clipboard::GetPlainTextFormatType(), |
325 CLIPBOARD_TYPE_COPY_PASTE)); | 314 CLIPBOARD_TYPE_COPY_PASTE)); |
326 base::string16 text_result; | 315 base::string16 text_result; |
327 clipboard().ReadText(CLIPBOARD_TYPE_COPY_PASTE, &text_result); | 316 clipboard().ReadText(CLIPBOARD_TYPE_COPY_PASTE, &text_result); |
328 | 317 |
(...skipping 206 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
535 } | 524 } |
536 | 525 |
537 TEST_F(ClipboardTest, DataTest) { | 526 TEST_F(ClipboardTest, DataTest) { |
538 const ui::Clipboard::FormatType kFormat = | 527 const ui::Clipboard::FormatType kFormat = |
539 ui::Clipboard::GetFormatType("chromium/x-test-format"); | 528 ui::Clipboard::GetFormatType("chromium/x-test-format"); |
540 std::string payload("test string"); | 529 std::string payload("test string"); |
541 Pickle write_pickle; | 530 Pickle write_pickle; |
542 write_pickle.WriteString(payload); | 531 write_pickle.WriteString(payload); |
543 | 532 |
544 { | 533 { |
545 ScopedClipboardWriter clipboard_writer(&clipboard(), | 534 ScopedClipboardWriter clipboard_writer(CLIPBOARD_TYPE_COPY_PASTE); |
546 CLIPBOARD_TYPE_COPY_PASTE); | |
547 clipboard_writer.WritePickledData(write_pickle, kFormat); | 535 clipboard_writer.WritePickledData(write_pickle, kFormat); |
548 } | 536 } |
549 | 537 |
550 ASSERT_TRUE(clipboard().IsFormatAvailable( | 538 ASSERT_TRUE(clipboard().IsFormatAvailable( |
551 kFormat, CLIPBOARD_TYPE_COPY_PASTE)); | 539 kFormat, CLIPBOARD_TYPE_COPY_PASTE)); |
552 std::string output; | 540 std::string output; |
553 clipboard().ReadData(kFormat, &output); | 541 clipboard().ReadData(kFormat, &output); |
554 ASSERT_FALSE(output.empty()); | 542 ASSERT_FALSE(output.empty()); |
555 | 543 |
556 Pickle read_pickle(output.data(), output.size()); | 544 Pickle read_pickle(output.data(), output.size()); |
(...skipping 10 matching lines...) Expand all Loading... |
567 Pickle write_pickle1; | 555 Pickle write_pickle1; |
568 write_pickle1.WriteString(payload1); | 556 write_pickle1.WriteString(payload1); |
569 | 557 |
570 const ui::Clipboard::FormatType kFormat2 = | 558 const ui::Clipboard::FormatType kFormat2 = |
571 ui::Clipboard::GetFormatType("chromium/x-test-format2"); | 559 ui::Clipboard::GetFormatType("chromium/x-test-format2"); |
572 std::string payload2("test string2"); | 560 std::string payload2("test string2"); |
573 Pickle write_pickle2; | 561 Pickle write_pickle2; |
574 write_pickle2.WriteString(payload2); | 562 write_pickle2.WriteString(payload2); |
575 | 563 |
576 { | 564 { |
577 ScopedClipboardWriter clipboard_writer(&clipboard(), | 565 ScopedClipboardWriter clipboard_writer(CLIPBOARD_TYPE_COPY_PASTE); |
578 CLIPBOARD_TYPE_COPY_PASTE); | |
579 clipboard_writer.WritePickledData(write_pickle1, kFormat1); | 566 clipboard_writer.WritePickledData(write_pickle1, kFormat1); |
580 // overwrite the previous pickle for fun | 567 // overwrite the previous pickle for fun |
581 clipboard_writer.WritePickledData(write_pickle2, kFormat2); | 568 clipboard_writer.WritePickledData(write_pickle2, kFormat2); |
582 } | 569 } |
583 | 570 |
584 ASSERT_TRUE(clipboard().IsFormatAvailable( | 571 ASSERT_TRUE(clipboard().IsFormatAvailable( |
585 kFormat2, CLIPBOARD_TYPE_COPY_PASTE)); | 572 kFormat2, CLIPBOARD_TYPE_COPY_PASTE)); |
586 | 573 |
587 // Check string 2. | 574 // Check string 2. |
588 std::string output2; | 575 std::string output2; |
589 clipboard().ReadData(kFormat2, &output2); | 576 clipboard().ReadData(kFormat2, &output2); |
590 ASSERT_FALSE(output2.empty()); | 577 ASSERT_FALSE(output2.empty()); |
591 | 578 |
592 Pickle read_pickle2(output2.data(), output2.size()); | 579 Pickle read_pickle2(output2.data(), output2.size()); |
593 PickleIterator iter2(read_pickle2); | 580 PickleIterator iter2(read_pickle2); |
594 std::string unpickled_string2; | 581 std::string unpickled_string2; |
595 ASSERT_TRUE(read_pickle2.ReadString(&iter2, &unpickled_string2)); | 582 ASSERT_TRUE(read_pickle2.ReadString(&iter2, &unpickled_string2)); |
596 EXPECT_EQ(payload2, unpickled_string2); | 583 EXPECT_EQ(payload2, unpickled_string2); |
597 | 584 |
598 { | 585 { |
599 ScopedClipboardWriter clipboard_writer(&clipboard(), | 586 ScopedClipboardWriter clipboard_writer(CLIPBOARD_TYPE_COPY_PASTE); |
600 CLIPBOARD_TYPE_COPY_PASTE); | |
601 clipboard_writer.WritePickledData(write_pickle2, kFormat2); | 587 clipboard_writer.WritePickledData(write_pickle2, kFormat2); |
602 // overwrite the previous pickle for fun | 588 // overwrite the previous pickle for fun |
603 clipboard_writer.WritePickledData(write_pickle1, kFormat1); | 589 clipboard_writer.WritePickledData(write_pickle1, kFormat1); |
604 } | 590 } |
605 | 591 |
606 ASSERT_TRUE(clipboard().IsFormatAvailable( | 592 ASSERT_TRUE(clipboard().IsFormatAvailable( |
607 kFormat1, CLIPBOARD_TYPE_COPY_PASTE)); | 593 kFormat1, CLIPBOARD_TYPE_COPY_PASTE)); |
608 | 594 |
609 // Check string 1. | 595 // Check string 1. |
610 std::string output1; | 596 std::string output1; |
(...skipping 11 matching lines...) Expand all Loading... |
622 TEST_F(ClipboardTest, HyperlinkTest) { | 608 TEST_F(ClipboardTest, HyperlinkTest) { |
623 const std::string kTitle("The <Example> Company's \"home page\""); | 609 const std::string kTitle("The <Example> Company's \"home page\""); |
624 const std::string kUrl("http://www.example.com?x=3<=3#\"'<>"); | 610 const std::string kUrl("http://www.example.com?x=3<=3#\"'<>"); |
625 const std::string kExpectedHtml( | 611 const std::string kExpectedHtml( |
626 "<a href=\"http://www.example.com?x=3&lt=3#"'<>\">" | 612 "<a href=\"http://www.example.com?x=3&lt=3#"'<>\">" |
627 "The <Example> Company's "home page"</a>"); | 613 "The <Example> Company's "home page"</a>"); |
628 | 614 |
629 std::string url_result; | 615 std::string url_result; |
630 base::string16 html_result; | 616 base::string16 html_result; |
631 { | 617 { |
632 ScopedClipboardWriter clipboard_writer(&clipboard(), | 618 ScopedClipboardWriter clipboard_writer(CLIPBOARD_TYPE_COPY_PASTE); |
633 CLIPBOARD_TYPE_COPY_PASTE); | |
634 clipboard_writer.WriteHyperlink(ASCIIToUTF16(kTitle), kUrl); | 619 clipboard_writer.WriteHyperlink(ASCIIToUTF16(kTitle), kUrl); |
635 } | 620 } |
636 | 621 |
637 EXPECT_TRUE(clipboard().IsFormatAvailable(Clipboard::GetHtmlFormatType(), | 622 EXPECT_TRUE(clipboard().IsFormatAvailable(Clipboard::GetHtmlFormatType(), |
638 CLIPBOARD_TYPE_COPY_PASTE)); | 623 CLIPBOARD_TYPE_COPY_PASTE)); |
639 uint32 ignored; | 624 uint32 ignored; |
640 clipboard().ReadHTML(CLIPBOARD_TYPE_COPY_PASTE, &html_result, &url_result, | 625 clipboard().ReadHTML(CLIPBOARD_TYPE_COPY_PASTE, &html_result, &url_result, |
641 &ignored, &ignored); | 626 &ignored, &ignored); |
642 EXPECT_PRED2(MarkupMatches, ASCIIToUTF16(kExpectedHtml), html_result); | 627 EXPECT_PRED2(MarkupMatches, ASCIIToUTF16(kExpectedHtml), html_result); |
643 } | 628 } |
644 #endif | 629 #endif |
645 | 630 |
646 #if defined(OS_WIN) // Windows only tests. | 631 #if defined(OS_WIN) // Windows only tests. |
647 TEST_F(ClipboardTest, WebSmartPasteTest) { | 632 TEST_F(ClipboardTest, WebSmartPasteTest) { |
648 { | 633 { |
649 ScopedClipboardWriter clipboard_writer(&clipboard(), | 634 ScopedClipboardWriter clipboard_writer(CLIPBOARD_TYPE_COPY_PASTE); |
650 CLIPBOARD_TYPE_COPY_PASTE); | |
651 clipboard_writer.WriteWebSmartPaste(); | 635 clipboard_writer.WriteWebSmartPaste(); |
652 } | 636 } |
653 | 637 |
654 EXPECT_TRUE(clipboard().IsFormatAvailable( | 638 EXPECT_TRUE(clipboard().IsFormatAvailable( |
655 Clipboard::GetWebKitSmartPasteFormatType(), CLIPBOARD_TYPE_COPY_PASTE)); | 639 Clipboard::GetWebKitSmartPasteFormatType(), CLIPBOARD_TYPE_COPY_PASTE)); |
656 } | 640 } |
657 | 641 |
658 void HtmlTestHelper(const std::string& cf_html, | 642 void HtmlTestHelper(const std::string& cf_html, |
659 const std::string& expected_html) { | 643 const std::string& expected_html) { |
660 std::string html; | 644 std::string html; |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
694 "<p>Foo</p>\r\n" | 678 "<p>Foo</p>\r\n" |
695 "</body>\r\n" | 679 "</body>\r\n" |
696 "</html>\r\n\r\n", | 680 "</html>\r\n\r\n", |
697 "<p>Foo</p>"); | 681 "<p>Foo</p>"); |
698 } | 682 } |
699 #endif // defined(OS_WIN) | 683 #endif // defined(OS_WIN) |
700 | 684 |
701 // Test writing all formats we have simultaneously. | 685 // Test writing all formats we have simultaneously. |
702 TEST_F(ClipboardTest, WriteEverything) { | 686 TEST_F(ClipboardTest, WriteEverything) { |
703 { | 687 { |
704 ScopedClipboardWriter writer(&clipboard(), CLIPBOARD_TYPE_COPY_PASTE); | 688 ScopedClipboardWriter writer(CLIPBOARD_TYPE_COPY_PASTE); |
705 writer.WriteText(UTF8ToUTF16("foo")); | 689 writer.WriteText(UTF8ToUTF16("foo")); |
706 writer.WriteURL(UTF8ToUTF16("foo")); | 690 writer.WriteURL(UTF8ToUTF16("foo")); |
707 writer.WriteHTML(UTF8ToUTF16("foo"), "bar"); | 691 writer.WriteHTML(UTF8ToUTF16("foo"), "bar"); |
708 writer.WriteBookmark(UTF8ToUTF16("foo"), "bar"); | 692 writer.WriteBookmark(UTF8ToUTF16("foo"), "bar"); |
709 writer.WriteHyperlink(ASCIIToUTF16("foo"), "bar"); | 693 writer.WriteHyperlink(ASCIIToUTF16("foo"), "bar"); |
710 writer.WriteWebSmartPaste(); | 694 writer.WriteWebSmartPaste(); |
711 // Left out: WriteFile, WriteFiles, WriteBitmapFromPixels, WritePickledData. | 695 // Left out: WriteFile, WriteFiles, WriteBitmapFromPixels, WritePickledData. |
712 } | 696 } |
713 | 697 |
714 // Passes if we don't crash. | 698 // Passes if we don't crash. |
715 } | 699 } |
716 | 700 |
717 // TODO(dcheng): Fix this test for Android. It's rather involved, since the | 701 // TODO(dcheng): Fix this test for Android. It's rather involved, since the |
718 // clipboard change listener is posted to the Java message loop, and spinning | 702 // clipboard change listener is posted to the Java message loop, and spinning |
719 // that loop from C++ to trigger the callback in the test requires a non-trivial | 703 // that loop from C++ to trigger the callback in the test requires a non-trivial |
720 // amount of additional work. | 704 // amount of additional work. |
721 #if !defined(OS_ANDROID) | 705 #if !defined(OS_ANDROID) |
722 // Simple test that the sequence number appears to change when the clipboard is | 706 // Simple test that the sequence number appears to change when the clipboard is |
723 // written to. | 707 // written to. |
724 // TODO(dcheng): Add a version to test CLIPBOARD_TYPE_SELECTION. | 708 // TODO(dcheng): Add a version to test CLIPBOARD_TYPE_SELECTION. |
725 TEST_F(ClipboardTest, GetSequenceNumber) { | 709 TEST_F(ClipboardTest, GetSequenceNumber) { |
726 const uint64 first_sequence_number = | 710 const uint64 first_sequence_number = |
727 clipboard().GetSequenceNumber(CLIPBOARD_TYPE_COPY_PASTE); | 711 clipboard().GetSequenceNumber(CLIPBOARD_TYPE_COPY_PASTE); |
728 | 712 |
729 { | 713 { |
730 ScopedClipboardWriter writer(&clipboard(), CLIPBOARD_TYPE_COPY_PASTE); | 714 ScopedClipboardWriter writer(CLIPBOARD_TYPE_COPY_PASTE); |
731 writer.WriteText(UTF8ToUTF16("World")); | 715 writer.WriteText(UTF8ToUTF16("World")); |
732 } | 716 } |
733 | 717 |
734 // On some platforms, the sequence number is updated by a UI callback so pump | 718 // On some platforms, the sequence number is updated by a UI callback so pump |
735 // the message loop to make sure we get the notification. | 719 // the message loop to make sure we get the notification. |
736 base::RunLoop().RunUntilIdle(); | 720 base::RunLoop().RunUntilIdle(); |
737 | 721 |
738 const uint64 second_sequence_number = | 722 const uint64 second_sequence_number = |
739 clipboard().GetSequenceNumber(CLIPBOARD_TYPE_COPY_PASTE); | 723 clipboard().GetSequenceNumber(CLIPBOARD_TYPE_COPY_PASTE); |
740 | 724 |
741 EXPECT_NE(first_sequence_number, second_sequence_number); | 725 EXPECT_NE(first_sequence_number, second_sequence_number); |
742 } | 726 } |
743 #endif | 727 #endif |
744 | 728 |
745 #if defined(OS_ANDROID) | 729 #if defined(OS_ANDROID) |
746 | 730 |
747 // Test that if another application writes some text to the pasteboard the | 731 // Test that if another application writes some text to the pasteboard the |
748 // clipboard properly invalidates other types. | 732 // clipboard properly invalidates other types. |
749 TEST_F(ClipboardTest, InternalClipboardInvalidation) { | 733 TEST_F(ClipboardTest, InternalClipboardInvalidation) { |
750 // Write a Webkit smart paste tag to our clipboard. | 734 // Write a Webkit smart paste tag to our clipboard. |
751 { | 735 { |
752 ScopedClipboardWriter clipboard_writer(&clipboard(), | 736 ScopedClipboardWriter clipboard_writer(CLIPBOARD_TYPE_COPY_PASTE); |
753 CLIPBOARD_TYPE_COPY_PASTE); | |
754 clipboard_writer.WriteWebSmartPaste(); | 737 clipboard_writer.WriteWebSmartPaste(); |
755 } | 738 } |
756 EXPECT_TRUE(clipboard().IsFormatAvailable( | 739 EXPECT_TRUE(clipboard().IsFormatAvailable( |
757 Clipboard::GetWebKitSmartPasteFormatType(), CLIPBOARD_TYPE_COPY_PASTE)); | 740 Clipboard::GetWebKitSmartPasteFormatType(), CLIPBOARD_TYPE_COPY_PASTE)); |
758 | 741 |
759 // | 742 // |
760 // Simulate that another application copied something in the Clipboard | 743 // Simulate that another application copied something in the Clipboard |
761 // | 744 // |
762 std::string new_value("Some text copied by some other app"); | 745 std::string new_value("Some text copied by some other app"); |
763 using base::android::ConvertUTF8ToJavaString; | 746 using base::android::ConvertUTF8ToJavaString; |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
805 EXPECT_TRUE(clipboard().IsFormatAvailable( | 788 EXPECT_TRUE(clipboard().IsFormatAvailable( |
806 Clipboard::GetPlainTextWFormatType(), CLIPBOARD_TYPE_COPY_PASTE)); | 789 Clipboard::GetPlainTextWFormatType(), CLIPBOARD_TYPE_COPY_PASTE)); |
807 | 790 |
808 // Make sure the text is what we inserted while simulating the other app | 791 // Make sure the text is what we inserted while simulating the other app |
809 std::string contents; | 792 std::string contents; |
810 clipboard().ReadAsciiText(CLIPBOARD_TYPE_COPY_PASTE, &contents); | 793 clipboard().ReadAsciiText(CLIPBOARD_TYPE_COPY_PASTE, &contents); |
811 EXPECT_EQ(contents, new_value); | 794 EXPECT_EQ(contents, new_value); |
812 } | 795 } |
813 #endif | 796 #endif |
814 } // namespace ui | 797 } // namespace ui |
OLD | NEW |