| 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 141 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 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) | 162 #if defined(OS_LINUX) && !defined(OS_CHROMEOS) |
| 163 TEST_F(ClipboardTest, MultipleBufferTest) { | 163 TEST_F(ClipboardTest, MultipleBufferTest) { |
| 164 base::string16 text(ASCIIToUTF16("Standard")), text_result; | 164 base::string16 text(ASCIIToUTF16("Standard")), text_result; |
| 165 base::string16 markup(ASCIIToUTF16("<string>Selection</string>")); | 165 base::string16 markup(ASCIIToUTF16("<string>Selection</string>")); |
| 166 std::string url("http://www.example.com/"), url_result; | 166 std::string url("http://www.example.com/"), url_result; |
| 167 | 167 |
| 168 { | 168 { |
| 169 ScopedClipboardWriter clipboard_writer(&clipboard(), | 169 ScopedClipboardWriter clipboard_writer(&clipboard(), |
| 170 CLIPBOARD_TYPE_COPY_PASTE); | 170 CLIPBOARD_TYPE_COPY_PASTE); |
| 171 clipboard_writer.WriteText(text); | 171 clipboard_writer.WriteText(text); |
| 172 } | 172 } |
| (...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 247 clipboard().ReadHTML(CLIPBOARD_TYPE_COPY_PASTE, &markup_result, &url_result, | 247 clipboard().ReadHTML(CLIPBOARD_TYPE_COPY_PASTE, &markup_result, &url_result, |
| 248 &fragment_start, &fragment_end); | 248 &fragment_start, &fragment_end); |
| 249 EXPECT_PRED2(MarkupMatches, markup, markup_result); | 249 EXPECT_PRED2(MarkupMatches, markup, markup_result); |
| 250 EXPECT_EQ(url, url_result); | 250 EXPECT_EQ(url, url_result); |
| 251 // Make sure that fragment indices were adjusted when converting. | 251 // Make sure that fragment indices were adjusted when converting. |
| 252 EXPECT_EQ(36, fragment_start); | 252 EXPECT_EQ(36, fragment_start); |
| 253 EXPECT_EQ(52, fragment_end); | 253 EXPECT_EQ(52, fragment_end); |
| 254 } | 254 } |
| 255 #endif // defined(OS_WIN) | 255 #endif // defined(OS_WIN) |
| 256 | 256 |
| 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) | 257 // TODO(estade): Port the following test (decide what target we use for urls) |
| 279 #if !defined(OS_POSIX) || defined(OS_MACOSX) | 258 #if !defined(OS_POSIX) || defined(OS_MACOSX) |
| 280 TEST_F(ClipboardTest, BookmarkTest) { | 259 TEST_F(ClipboardTest, BookmarkTest) { |
| 281 base::string16 title(ASCIIToUTF16("The Example Company")), title_result; | 260 base::string16 title(ASCIIToUTF16("The Example Company")), title_result; |
| 282 std::string url("http://www.example.com/"), url_result; | 261 std::string url("http://www.example.com/"), url_result; |
| 283 | 262 |
| 284 { | 263 { |
| 285 ScopedClipboardWriter clipboard_writer(&clipboard(), | 264 ScopedClipboardWriter clipboard_writer(&clipboard(), |
| 286 CLIPBOARD_TYPE_COPY_PASTE); | 265 CLIPBOARD_TYPE_COPY_PASTE); |
| 287 clipboard_writer.WriteBookmark(title, url); | 266 clipboard_writer.WriteBookmark(title, url); |
| (...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 407 EXPECT_TRUE(clipboard->IsFormatAvailable(Clipboard::GetBitmapFormatType(), | 386 EXPECT_TRUE(clipboard->IsFormatAvailable(Clipboard::GetBitmapFormatType(), |
| 408 CLIPBOARD_TYPE_COPY_PASTE)); | 387 CLIPBOARD_TYPE_COPY_PASTE)); |
| 409 const SkBitmap& image = clipboard->ReadImage(CLIPBOARD_TYPE_COPY_PASTE); | 388 const SkBitmap& image = clipboard->ReadImage(CLIPBOARD_TYPE_COPY_PASTE); |
| 410 EXPECT_EQ(size, gfx::Size(image.width(), image.height())); | 389 EXPECT_EQ(size, gfx::Size(image.width(), image.height())); |
| 411 SkAutoLockPixels image_lock(image); | 390 SkAutoLockPixels image_lock(image); |
| 412 for (int j = 0; j < image.height(); ++j) { | 391 for (int j = 0; j < image.height(); ++j) { |
| 413 const uint32* row_address = image.getAddr32(0, j); | 392 const uint32* row_address = image.getAddr32(0, j); |
| 414 for (int i = 0; i < image.width(); ++i) { | 393 for (int i = 0; i < image.width(); ++i) { |
| 415 int offset = i + j * image.width(); | 394 int offset = i + j * image.width(); |
| 416 uint32 pixel = SkPreMultiplyColor(bitmap_data[offset]); | 395 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]) | 396 EXPECT_EQ(pixel, row_address[i]) |
| 428 << "i = " << i << ", j = " << j; | 397 << "i = " << i << ", j = " << j; |
| 429 #endif // defined(TOOLKIT_GTK) | |
| 430 } | 398 } |
| 431 } | 399 } |
| 432 } | 400 } |
| 433 | 401 |
| 434 TEST_F(ClipboardTest, SharedBitmapTest) { | 402 TEST_F(ClipboardTest, SharedBitmapTest) { |
| 435 const uint32 fake_bitmap_1[] = { | 403 const uint32 fake_bitmap_1[] = { |
| 436 0x46155189, 0xF6A55C8D, 0x79845674, 0xFA57BD89, | 404 0x46155189, 0xF6A55C8D, 0x79845674, 0xFA57BD89, |
| 437 0x78FD46AE, 0x87C64F5A, 0x36EDC5AF, 0x4378F568, | 405 0x78FD46AE, 0x87C64F5A, 0x36EDC5AF, 0x4378F568, |
| 438 0x91E9F63A, 0xC31EA14F, 0x69AB32DF, 0x643A3FD1, | 406 0x91E9F63A, 0xC31EA14F, 0x69AB32DF, 0x643A3FD1, |
| 439 }; | 407 }; |
| (...skipping 395 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 835 EXPECT_TRUE(clipboard().IsFormatAvailable( | 803 EXPECT_TRUE(clipboard().IsFormatAvailable( |
| 836 Clipboard::GetPlainTextWFormatType(), CLIPBOARD_TYPE_COPY_PASTE)); | 804 Clipboard::GetPlainTextWFormatType(), CLIPBOARD_TYPE_COPY_PASTE)); |
| 837 | 805 |
| 838 // Make sure the text is what we inserted while simulating the other app | 806 // Make sure the text is what we inserted while simulating the other app |
| 839 std::string contents; | 807 std::string contents; |
| 840 clipboard().ReadAsciiText(CLIPBOARD_TYPE_COPY_PASTE, &contents); | 808 clipboard().ReadAsciiText(CLIPBOARD_TYPE_COPY_PASTE, &contents); |
| 841 EXPECT_EQ(contents, new_value); | 809 EXPECT_EQ(contents, new_value); |
| 842 } | 810 } |
| 843 #endif | 811 #endif |
| 844 } // namespace ui | 812 } // namespace ui |
| OLD | NEW |