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