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 427 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
438 clipboard_writer.WritePickledData(write_pickle, kFormat); | 438 clipboard_writer.WritePickledData(write_pickle, kFormat); |
439 } | 439 } |
440 | 440 |
441 ASSERT_TRUE(clipboard.IsFormatAvailable( | 441 ASSERT_TRUE(clipboard.IsFormatAvailable( |
442 kFormat, Clipboard::BUFFER_STANDARD)); | 442 kFormat, Clipboard::BUFFER_STANDARD)); |
443 std::string output; | 443 std::string output; |
444 clipboard.ReadData(kFormat, &output); | 444 clipboard.ReadData(kFormat, &output); |
445 ASSERT_FALSE(output.empty()); | 445 ASSERT_FALSE(output.empty()); |
446 | 446 |
447 Pickle read_pickle(output.data(), output.size()); | 447 Pickle read_pickle(output.data(), output.size()); |
448 void* iter = NULL; | 448 PickleIterator iter(read_pickle); |
449 std::string unpickled_string; | 449 std::string unpickled_string; |
450 ASSERT_TRUE(read_pickle.ReadString(&iter, &unpickled_string)); | 450 ASSERT_TRUE(read_pickle.ReadString(&iter, &unpickled_string)); |
451 EXPECT_EQ(payload, unpickled_string); | 451 EXPECT_EQ(payload, unpickled_string); |
452 } | 452 } |
453 | 453 |
454 TEST_F(ClipboardTest, MultipleDataTest) { | 454 TEST_F(ClipboardTest, MultipleDataTest) { |
455 Clipboard clipboard; | 455 Clipboard clipboard; |
456 const ui::Clipboard::FormatType kFormat1 = | 456 const ui::Clipboard::FormatType kFormat1 = |
457 ui::Clipboard::GetFormatType("chromium/x-test-format1"); | 457 ui::Clipboard::GetFormatType("chromium/x-test-format1"); |
458 std::string payload1("test string1"); | 458 std::string payload1("test string1"); |
(...skipping 16 matching lines...) Expand all Loading... |
475 | 475 |
476 ASSERT_TRUE(clipboard.IsFormatAvailable( | 476 ASSERT_TRUE(clipboard.IsFormatAvailable( |
477 kFormat2, Clipboard::BUFFER_STANDARD)); | 477 kFormat2, Clipboard::BUFFER_STANDARD)); |
478 | 478 |
479 // Check string 2. | 479 // Check string 2. |
480 std::string output2; | 480 std::string output2; |
481 clipboard.ReadData(kFormat2, &output2); | 481 clipboard.ReadData(kFormat2, &output2); |
482 ASSERT_FALSE(output2.empty()); | 482 ASSERT_FALSE(output2.empty()); |
483 | 483 |
484 Pickle read_pickle2(output2.data(), output2.size()); | 484 Pickle read_pickle2(output2.data(), output2.size()); |
485 void* iter2 = NULL; | 485 PickleIterator iter2(read_pickle2); |
486 std::string unpickled_string2; | 486 std::string unpickled_string2; |
487 ASSERT_TRUE(read_pickle2.ReadString(&iter2, &unpickled_string2)); | 487 ASSERT_TRUE(read_pickle2.ReadString(&iter2, &unpickled_string2)); |
488 EXPECT_EQ(payload2, unpickled_string2); | 488 EXPECT_EQ(payload2, unpickled_string2); |
489 | 489 |
490 { | 490 { |
491 ScopedClipboardWriter clipboard_writer(&clipboard, | 491 ScopedClipboardWriter clipboard_writer(&clipboard, |
492 Clipboard::BUFFER_STANDARD); | 492 Clipboard::BUFFER_STANDARD); |
493 clipboard_writer.WritePickledData(write_pickle2, kFormat2); | 493 clipboard_writer.WritePickledData(write_pickle2, kFormat2); |
494 // overwrite the previous pickle for fun | 494 // overwrite the previous pickle for fun |
495 clipboard_writer.WritePickledData(write_pickle1, kFormat1); | 495 clipboard_writer.WritePickledData(write_pickle1, kFormat1); |
496 } | 496 } |
497 | 497 |
498 ASSERT_TRUE(clipboard.IsFormatAvailable( | 498 ASSERT_TRUE(clipboard.IsFormatAvailable( |
499 kFormat1, Clipboard::BUFFER_STANDARD)); | 499 kFormat1, Clipboard::BUFFER_STANDARD)); |
500 | 500 |
501 // Check string 1. | 501 // Check string 1. |
502 std::string output1; | 502 std::string output1; |
503 clipboard.ReadData(kFormat1, &output1); | 503 clipboard.ReadData(kFormat1, &output1); |
504 ASSERT_FALSE(output1.empty()); | 504 ASSERT_FALSE(output1.empty()); |
505 | 505 |
506 Pickle read_pickle1(output1.data(), output1.size()); | 506 Pickle read_pickle1(output1.data(), output1.size()); |
507 void* iter1 = NULL; | 507 PickleIterator iter1(read_pickle1); |
508 std::string unpickled_string1; | 508 std::string unpickled_string1; |
509 ASSERT_TRUE(read_pickle1.ReadString(&iter1, &unpickled_string1)); | 509 ASSERT_TRUE(read_pickle1.ReadString(&iter1, &unpickled_string1)); |
510 EXPECT_EQ(payload1, unpickled_string1); | 510 EXPECT_EQ(payload1, unpickled_string1); |
511 } | 511 } |
512 | 512 |
513 #if defined(OS_WIN) // Windows only tests. | 513 #if defined(OS_WIN) // Windows only tests. |
514 TEST_F(ClipboardTest, HyperlinkTest) { | 514 TEST_F(ClipboardTest, HyperlinkTest) { |
515 Clipboard clipboard; | 515 Clipboard clipboard; |
516 | 516 |
517 const std::string kTitle("The Example Company"); | 517 const std::string kTitle("The Example Company"); |
(...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
622 writer.WriteBookmark(UTF8ToUTF16("foo"), "bar"); | 622 writer.WriteBookmark(UTF8ToUTF16("foo"), "bar"); |
623 writer.WriteHyperlink(ASCIIToUTF16("foo"), "bar"); | 623 writer.WriteHyperlink(ASCIIToUTF16("foo"), "bar"); |
624 writer.WriteWebSmartPaste(); | 624 writer.WriteWebSmartPaste(); |
625 // Left out: WriteFile, WriteFiles, WriteBitmapFromPixels, WritePickledData. | 625 // Left out: WriteFile, WriteFiles, WriteBitmapFromPixels, WritePickledData. |
626 } | 626 } |
627 | 627 |
628 // Passes if we don't crash. | 628 // Passes if we don't crash. |
629 } | 629 } |
630 | 630 |
631 } // namespace ui | 631 } // namespace ui |
OLD | NEW |