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

Side by Side Diff: ui/base/clipboard/clipboard_unittest.cc

Issue 232773008: More removal of GTK code. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: thestig nits Created 6 years, 8 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
OLDNEW
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 141 matching lines...) Expand 10 before | Expand all | Expand 10 after
152 clipboard_writer.WriteRTF(rtf); 152 clipboard_writer.WriteRTF(rtf);
153 } 153 }
154 154
155 EXPECT_TRUE(clipboard().IsFormatAvailable(Clipboard::GetRtfFormatType(), 155 EXPECT_TRUE(clipboard().IsFormatAvailable(Clipboard::GetRtfFormatType(),
156 CLIPBOARD_TYPE_COPY_PASTE)); 156 CLIPBOARD_TYPE_COPY_PASTE));
157 std::string result; 157 std::string result;
158 clipboard().ReadRTF(CLIPBOARD_TYPE_COPY_PASTE, &result); 158 clipboard().ReadRTF(CLIPBOARD_TYPE_COPY_PASTE, &result);
159 EXPECT_EQ(rtf, result); 159 EXPECT_EQ(rtf, result);
160 } 160 }
161 161
162 #if defined(TOOLKIT_GTK)
dcheng 2014/04/11 21:49:50 Shouldn't this test run on Linux Aura?
Elliot Glaysher 2014/04/11 22:16:44 Done.
163 TEST_F(ClipboardTest, MultipleBufferTest) {
164 base::string16 text(ASCIIToUTF16("Standard")), text_result;
165 base::string16 markup(ASCIIToUTF16("<string>Selection</string>"));
166 std::string url("http://www.example.com/"), url_result;
167
168 {
169 ScopedClipboardWriter clipboard_writer(&clipboard(),
170 CLIPBOARD_TYPE_COPY_PASTE);
171 clipboard_writer.WriteText(text);
172 }
173
174 {
175 ScopedClipboardWriter clipboard_writer(&clipboard(),
176 CLIPBOARD_TYPE_SELECTION);
177 clipboard_writer.WriteHTML(markup, url);
178 }
179
180 EXPECT_TRUE(clipboard().IsFormatAvailable(Clipboard::GetPlainTextFormatType(),
181 CLIPBOARD_TYPE_COPY_PASTE));
182 EXPECT_FALSE(clipboard().IsFormatAvailable(
183 Clipboard::GetPlainTextFormatType(),
184 CLIPBOARD_TYPE_SELECTION));
185
186 EXPECT_FALSE(clipboard().IsFormatAvailable(Clipboard::GetHtmlFormatType(),
187 CLIPBOARD_TYPE_COPY_PASTE));
188 EXPECT_TRUE(clipboard().IsFormatAvailable(Clipboard::GetHtmlFormatType(),
189 CLIPBOARD_TYPE_SELECTION));
190
191 clipboard().ReadText(CLIPBOARD_TYPE_COPY_PASTE, &text_result);
192 EXPECT_EQ(text, text_result);
193
194 uint32 ignored;
195 base::string16 markup_result;
196 clipboard().ReadHTML(CLIPBOARD_TYPE_SELECTION,
197 &markup_result,
198 &url_result,
199 &ignored,
200 &ignored);
201 EXPECT_PRED2(MarkupMatches, markup, markup_result);
202 }
203 #endif
204
205 TEST_F(ClipboardTest, TrickyHTMLTest) { 162 TEST_F(ClipboardTest, TrickyHTMLTest) {
206 base::string16 markup(ASCIIToUTF16("<em>Bye!<!--EndFragment --></em>")), 163 base::string16 markup(ASCIIToUTF16("<em>Bye!<!--EndFragment --></em>")),
207 markup_result; 164 markup_result;
208 std::string url, url_result; 165 std::string url, url_result;
209 base::string16 plain(ASCIIToUTF16("Bye!")), plain_result; 166 base::string16 plain(ASCIIToUTF16("Bye!")), plain_result;
210 167
211 { 168 {
212 ScopedClipboardWriter clipboard_writer(&clipboard(), 169 ScopedClipboardWriter clipboard_writer(&clipboard(),
213 CLIPBOARD_TYPE_COPY_PASTE); 170 CLIPBOARD_TYPE_COPY_PASTE);
214 clipboard_writer.WriteText(plain); 171 clipboard_writer.WriteText(plain);
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
247 clipboard().ReadHTML(CLIPBOARD_TYPE_COPY_PASTE, &markup_result, &url_result, 204 clipboard().ReadHTML(CLIPBOARD_TYPE_COPY_PASTE, &markup_result, &url_result,
248 &fragment_start, &fragment_end); 205 &fragment_start, &fragment_end);
249 EXPECT_PRED2(MarkupMatches, markup, markup_result); 206 EXPECT_PRED2(MarkupMatches, markup, markup_result);
250 EXPECT_EQ(url, url_result); 207 EXPECT_EQ(url, url_result);
251 // Make sure that fragment indices were adjusted when converting. 208 // Make sure that fragment indices were adjusted when converting.
252 EXPECT_EQ(36, fragment_start); 209 EXPECT_EQ(36, fragment_start);
253 EXPECT_EQ(52, fragment_end); 210 EXPECT_EQ(52, fragment_end);
254 } 211 }
255 #endif // defined(OS_WIN) 212 #endif // defined(OS_WIN)
256 213
257 #if defined(TOOLKIT_GTK)
258 // Regression test for crbug.com/56298 (pasting empty HTML crashes Linux).
259 TEST_F(ClipboardTest, EmptyHTMLTest) {
260 // ScopedClipboardWriter doesn't let us write empty data to the clipboard.
261 clipboard().clipboard_data_ = new Clipboard::TargetMap();
262 // The 1 is so the compiler doesn't warn about allocating an empty array.
263 char* empty = new char[1];
264 clipboard().InsertMapping("text/html", empty, 0U);
265 clipboard().SetGtkClipboard(CLIPBOARD_TYPE_COPY_PASTE);
266
267 EXPECT_TRUE(clipboard().IsFormatAvailable(Clipboard::GetHtmlFormatType(),
268 CLIPBOARD_TYPE_COPY_PASTE));
269 base::string16 markup_result;
270 std::string url_result;
271 uint32 ignored;
272 clipboard().ReadHTML(CLIPBOARD_TYPE_COPY_PASTE, &markup_result, &url_result,
273 &ignored, &ignored);
274 EXPECT_PRED2(MarkupMatches, base::string16(), markup_result);
275 }
276 #endif
277
278 // TODO(estade): Port the following test (decide what target we use for urls) 214 // TODO(estade): Port the following test (decide what target we use for urls)
279 #if !defined(OS_POSIX) || defined(OS_MACOSX) 215 #if !defined(OS_POSIX) || defined(OS_MACOSX)
280 TEST_F(ClipboardTest, BookmarkTest) { 216 TEST_F(ClipboardTest, BookmarkTest) {
281 base::string16 title(ASCIIToUTF16("The Example Company")), title_result; 217 base::string16 title(ASCIIToUTF16("The Example Company")), title_result;
282 std::string url("http://www.example.com/"), url_result; 218 std::string url("http://www.example.com/"), url_result;
283 219
284 { 220 {
285 ScopedClipboardWriter clipboard_writer(&clipboard(), 221 ScopedClipboardWriter clipboard_writer(&clipboard(),
286 CLIPBOARD_TYPE_COPY_PASTE); 222 CLIPBOARD_TYPE_COPY_PASTE);
287 clipboard_writer.WriteBookmark(title, url); 223 clipboard_writer.WriteBookmark(title, url);
(...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after
407 EXPECT_TRUE(clipboard->IsFormatAvailable(Clipboard::GetBitmapFormatType(), 343 EXPECT_TRUE(clipboard->IsFormatAvailable(Clipboard::GetBitmapFormatType(),
408 CLIPBOARD_TYPE_COPY_PASTE)); 344 CLIPBOARD_TYPE_COPY_PASTE));
409 const SkBitmap& image = clipboard->ReadImage(CLIPBOARD_TYPE_COPY_PASTE); 345 const SkBitmap& image = clipboard->ReadImage(CLIPBOARD_TYPE_COPY_PASTE);
410 EXPECT_EQ(size, gfx::Size(image.width(), image.height())); 346 EXPECT_EQ(size, gfx::Size(image.width(), image.height()));
411 SkAutoLockPixels image_lock(image); 347 SkAutoLockPixels image_lock(image);
412 for (int j = 0; j < image.height(); ++j) { 348 for (int j = 0; j < image.height(); ++j) {
413 const uint32* row_address = image.getAddr32(0, j); 349 const uint32* row_address = image.getAddr32(0, j);
414 for (int i = 0; i < image.width(); ++i) { 350 for (int i = 0; i < image.width(); ++i) {
415 int offset = i + j * image.width(); 351 int offset = i + j * image.width();
416 uint32 pixel = SkPreMultiplyColor(bitmap_data[offset]); 352 uint32 pixel = SkPreMultiplyColor(bitmap_data[offset]);
417 #if defined(TOOLKIT_GTK)
418 // Non-Aura GTK doesn't support alpha transparency. Instead, the alpha
419 // channel is always set to 0xFF - see http://crbug.com/154573.
420 // However, since we premultiplied above, we must also premultiply here
421 // before unpremultiplying and setting alpha to 0xFF; otherwise, the
422 // results will not match GTK's.
423 EXPECT_EQ(
424 SkUnPreMultiply::PMColorToColor(pixel) | 0xFF000000, row_address[i])
425 << "i = " << i << ", j = " << j;
426 #else
427 EXPECT_EQ(pixel, row_address[i]) 353 EXPECT_EQ(pixel, row_address[i])
428 << "i = " << i << ", j = " << j; 354 << "i = " << i << ", j = " << j;
429 #endif // defined(TOOLKIT_GTK)
430 } 355 }
431 } 356 }
432 } 357 }
433 358
434 TEST_F(ClipboardTest, SharedBitmapTest) { 359 TEST_F(ClipboardTest, SharedBitmapTest) {
435 const uint32 fake_bitmap_1[] = { 360 const uint32 fake_bitmap_1[] = {
436 0x46155189, 0xF6A55C8D, 0x79845674, 0xFA57BD89, 361 0x46155189, 0xF6A55C8D, 0x79845674, 0xFA57BD89,
437 0x78FD46AE, 0x87C64F5A, 0x36EDC5AF, 0x4378F568, 362 0x78FD46AE, 0x87C64F5A, 0x36EDC5AF, 0x4378F568,
438 0x91E9F63A, 0xC31EA14F, 0x69AB32DF, 0x643A3FD1, 363 0x91E9F63A, 0xC31EA14F, 0x69AB32DF, 0x643A3FD1,
439 }; 364 };
(...skipping 395 matching lines...) Expand 10 before | Expand all | Expand 10 after
835 EXPECT_TRUE(clipboard().IsFormatAvailable( 760 EXPECT_TRUE(clipboard().IsFormatAvailable(
836 Clipboard::GetPlainTextWFormatType(), CLIPBOARD_TYPE_COPY_PASTE)); 761 Clipboard::GetPlainTextWFormatType(), CLIPBOARD_TYPE_COPY_PASTE));
837 762
838 // Make sure the text is what we inserted while simulating the other app 763 // Make sure the text is what we inserted while simulating the other app
839 std::string contents; 764 std::string contents;
840 clipboard().ReadAsciiText(CLIPBOARD_TYPE_COPY_PASTE, &contents); 765 clipboard().ReadAsciiText(CLIPBOARD_TYPE_COPY_PASTE, &contents);
841 EXPECT_EQ(contents, new_value); 766 EXPECT_EQ(contents, new_value);
842 } 767 }
843 #endif 768 #endif
844 } // namespace ui 769 } // namespace ui
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698