| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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" |
| 11 #include "base/pickle.h" | |
| 12 #include "base/string_util.h" | 11 #include "base/string_util.h" |
| 13 #include "base/utf_string_conversions.h" | 12 #include "base/utf_string_conversions.h" |
| 14 #include "testing/gtest/include/gtest/gtest.h" | 13 #include "testing/gtest/include/gtest/gtest.h" |
| 15 #include "testing/platform_test.h" | 14 #include "testing/platform_test.h" |
| 16 #include "third_party/skia/include/core/SkBitmap.h" | 15 #include "third_party/skia/include/core/SkBitmap.h" |
| 17 #include "ui/base/clipboard/clipboard.h" | 16 #include "ui/base/clipboard/clipboard.h" |
| 18 #include "ui/base/clipboard/scoped_clipboard_writer.h" | 17 #include "ui/base/clipboard/scoped_clipboard_writer.h" |
| 19 #include "ui/gfx/size.h" | 18 #include "ui/gfx/size.h" |
| 20 | 19 |
| 21 #if defined(OS_WIN) | 20 #if defined(OS_WIN) |
| 22 #include "base/message_loop.h" | 21 #include "base/message_loop.h" |
| 23 #include "ui/base/clipboard/clipboard_util_win.h" | 22 #include "ui/base/clipboard/clipboard_util_win.h" |
| 24 #endif | 23 #endif |
| 25 | 24 |
| 25 #if defined(OS_WIN) || (defined(OS_POSIX) && !defined(OS_MACOSX)) |
| 26 #include "base/pickle.h" |
| 27 #endif |
| 28 |
| 26 namespace ui { | 29 namespace ui { |
| 27 | 30 |
| 28 #if defined(OS_WIN) | 31 #if defined(OS_WIN) |
| 29 class ClipboardTest : public PlatformTest { | 32 class ClipboardTest : public PlatformTest { |
| 30 protected: | 33 protected: |
| 31 virtual void SetUp() { | 34 virtual void SetUp() { |
| 32 message_loop_.reset(new MessageLoopForUI()); | 35 message_loop_.reset(new MessageLoopForUI()); |
| 33 } | 36 } |
| 34 virtual void TearDown() { | 37 virtual void TearDown() { |
| 35 } | 38 } |
| (...skipping 334 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 370 unsigned int* pixels_2 = reinterpret_cast<unsigned int*>(image_2.getPixels()); | 373 unsigned int* pixels_2 = reinterpret_cast<unsigned int*>(image_2.getPixels()); |
| 371 for (int i = 0; i < fake_bitmap_2_size.width(); ++i) { | 374 for (int i = 0; i < fake_bitmap_2_size.width(); ++i) { |
| 372 for (int j = 0; j < fake_bitmap_2_size.height(); ++j) { | 375 for (int j = 0; j < fake_bitmap_2_size.height(); ++j) { |
| 373 int id = i * fake_bitmap_2_size.height() + j; | 376 int id = i * fake_bitmap_2_size.height() + j; |
| 374 EXPECT_EQ(fake_bitmap_2[id], pixels_2[id]); | 377 EXPECT_EQ(fake_bitmap_2[id], pixels_2[id]); |
| 375 } | 378 } |
| 376 } | 379 } |
| 377 } | 380 } |
| 378 #endif | 381 #endif |
| 379 | 382 |
| 383 #if defined(OS_WIN) || (defined(OS_POSIX) && !defined(OS_MACOSX)) |
| 380 TEST_F(ClipboardTest, DataTest) { | 384 TEST_F(ClipboardTest, DataTest) { |
| 381 Clipboard clipboard; | 385 Clipboard clipboard; |
| 382 #if !defined(OS_MACOSX) | |
| 383 const char* kFormat = "chromium/x-test-format"; | 386 const char* kFormat = "chromium/x-test-format"; |
| 384 #else | |
| 385 const char* kFormat = "org.chromium.test.format"; | |
| 386 #endif // !defined(OS_MACOSX) | |
| 387 std::string payload("test string"); | 387 std::string payload("test string"); |
| 388 Pickle write_pickle; | 388 Pickle write_pickle; |
| 389 write_pickle.WriteString(payload); | 389 write_pickle.WriteString(payload); |
| 390 | 390 |
| 391 { | 391 { |
| 392 ScopedClipboardWriter clipboard_writer(&clipboard); | 392 ScopedClipboardWriter clipboard_writer(&clipboard); |
| 393 clipboard_writer.WritePickledData(write_pickle, kFormat); | 393 clipboard_writer.WritePickledData(write_pickle, kFormat); |
| 394 } | 394 } |
| 395 | 395 |
| 396 ASSERT_TRUE(clipboard.IsFormatAvailableByString( | 396 ASSERT_TRUE(clipboard.IsFormatAvailableByString( |
| (...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 453 std::string output1; | 453 std::string output1; |
| 454 clipboard.ReadData(kFormat1, &output1); | 454 clipboard.ReadData(kFormat1, &output1); |
| 455 ASSERT_FALSE(output1.empty()); | 455 ASSERT_FALSE(output1.empty()); |
| 456 | 456 |
| 457 Pickle read_pickle1(output1.data(), output1.size()); | 457 Pickle read_pickle1(output1.data(), output1.size()); |
| 458 void* iter1 = NULL; | 458 void* iter1 = NULL; |
| 459 std::string unpickled_string1; | 459 std::string unpickled_string1; |
| 460 ASSERT_TRUE(read_pickle1.ReadString(&iter1, &unpickled_string1)); | 460 ASSERT_TRUE(read_pickle1.ReadString(&iter1, &unpickled_string1)); |
| 461 EXPECT_EQ(payload1, unpickled_string1); | 461 EXPECT_EQ(payload1, unpickled_string1); |
| 462 } | 462 } |
| 463 #endif |
| 463 | 464 |
| 464 #if defined(OS_WIN) // Windows only tests. | 465 #if defined(OS_WIN) // Windows only tests. |
| 465 TEST_F(ClipboardTest, HyperlinkTest) { | 466 TEST_F(ClipboardTest, HyperlinkTest) { |
| 466 Clipboard clipboard; | 467 Clipboard clipboard; |
| 467 | 468 |
| 468 const std::string kTitle("The Example Company"); | 469 const std::string kTitle("The Example Company"); |
| 469 const std::string kUrl("http://www.example.com/"); | 470 const std::string kUrl("http://www.example.com/"); |
| 470 const std::string kExpectedHtml("<a href=\"http://www.example.com/\">" | 471 const std::string kExpectedHtml("<a href=\"http://www.example.com/\">" |
| 471 "The Example Company</a>"); | 472 "The Example Company</a>"); |
| 472 std::string url_result; | 473 std::string url_result; |
| (...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 570 writer.WriteBookmark(UTF8ToUTF16("foo"), "bar"); | 571 writer.WriteBookmark(UTF8ToUTF16("foo"), "bar"); |
| 571 writer.WriteHyperlink(ASCIIToUTF16("foo"), "bar"); | 572 writer.WriteHyperlink(ASCIIToUTF16("foo"), "bar"); |
| 572 writer.WriteWebSmartPaste(); | 573 writer.WriteWebSmartPaste(); |
| 573 // Left out: WriteFile, WriteFiles, WriteBitmapFromPixels, WritePickledData. | 574 // Left out: WriteFile, WriteFiles, WriteBitmapFromPixels, WritePickledData. |
| 574 } | 575 } |
| 575 | 576 |
| 576 // Passes if we don't crash. | 577 // Passes if we don't crash. |
| 577 } | 578 } |
| 578 | 579 |
| 579 } // namespace ui | 580 } // namespace ui |
| OLD | NEW |