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