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 // Note: This header doesn't use REGISTER_TYPED_TEST_CASE_P like most | 5 // Note: This header doesn't use REGISTER_TYPED_TEST_CASE_P like most |
6 // type-parameterized gtests. There are lot of test cases in here that are only | 6 // type-parameterized gtests. There are lot of test cases in here that are only |
7 // enabled on certain platforms. However, preprocessor directives in macro | 7 // enabled on certain platforms. However, preprocessor directives in macro |
8 // arguments result in undefined behavior (and don't work on MSVC). Instead, | 8 // arguments result in undefined behavior (and don't work on MSVC). Instead, |
9 // 'parameterized' tests should typedef TypesToTest (which is used to | 9 // 'parameterized' tests should typedef TypesToTest (which is used to |
10 // instantiate the tests using the TYPED_TEST_CASE macro) and then #include this | 10 // instantiate the tests using the TYPED_TEST_CASE macro) and then #include this |
(...skipping 417 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
428 { | 428 { |
429 SCOPED_TRACE("second bitmap"); | 429 SCOPED_TRACE("second bitmap"); |
430 TestBitmapWrite(&this->clipboard(), gfx::Size(2, 7), fake_bitmap_2); | 430 TestBitmapWrite(&this->clipboard(), gfx::Size(2, 7), fake_bitmap_2); |
431 } | 431 } |
432 } | 432 } |
433 | 433 |
434 TYPED_TEST(ClipboardTest, DataTest) { | 434 TYPED_TEST(ClipboardTest, DataTest) { |
435 const ui::Clipboard::FormatType kFormat = | 435 const ui::Clipboard::FormatType kFormat = |
436 ui::Clipboard::GetFormatType("chromium/x-test-format"); | 436 ui::Clipboard::GetFormatType("chromium/x-test-format"); |
437 std::string payload("test string"); | 437 std::string payload("test string"); |
438 base::Pickle write_pickle; | |
439 write_pickle.WriteString(payload); | |
440 | 438 |
441 { | 439 { |
442 ScopedClipboardWriter clipboard_writer(CLIPBOARD_TYPE_COPY_PASTE); | 440 ScopedClipboardWriter clipboard_writer(CLIPBOARD_TYPE_COPY_PASTE); |
443 clipboard_writer.WritePickledData(write_pickle, kFormat); | 441 clipboard_writer.WriteData(payload.data(), static_cast<int>(payload.size()), |
dcheng
2017/04/05 08:40:39
I think it'd be easier to read if we just renamed
| |
442 kFormat); | |
444 } | 443 } |
445 | 444 |
446 ASSERT_TRUE( | 445 ASSERT_TRUE( |
447 this->clipboard().IsFormatAvailable(kFormat, CLIPBOARD_TYPE_COPY_PASTE)); | 446 this->clipboard().IsFormatAvailable(kFormat, CLIPBOARD_TYPE_COPY_PASTE)); |
448 std::string output; | 447 std::string output; |
449 this->clipboard().ReadData(kFormat, &output); | 448 this->clipboard().ReadData(kFormat, &output); |
450 ASSERT_FALSE(output.empty()); | 449 EXPECT_EQ(payload, output); |
451 | |
452 base::Pickle read_pickle(output.data(), static_cast<int>(output.size())); | |
453 base::PickleIterator iter(read_pickle); | |
454 std::string unpickled_string; | |
455 ASSERT_TRUE(iter.ReadString(&unpickled_string)); | |
456 EXPECT_EQ(payload, unpickled_string); | |
457 } | 450 } |
458 | 451 |
459 TYPED_TEST(ClipboardTest, MultipleDataTest) { | 452 TYPED_TEST(ClipboardTest, MultipleDataTest) { |
460 const ui::Clipboard::FormatType kFormat1 = | 453 const ui::Clipboard::FormatType kFormat1 = |
461 ui::Clipboard::GetFormatType("chromium/x-test-format1"); | 454 ui::Clipboard::GetFormatType("chromium/x-test-format1"); |
462 std::string payload1("test string1"); | 455 std::string payload1("test string1"); |
463 base::Pickle write_pickle1; | |
464 write_pickle1.WriteString(payload1); | |
465 | 456 |
466 const ui::Clipboard::FormatType kFormat2 = | 457 const ui::Clipboard::FormatType kFormat2 = |
467 ui::Clipboard::GetFormatType("chromium/x-test-format2"); | 458 ui::Clipboard::GetFormatType("chromium/x-test-format2"); |
468 std::string payload2("test string2"); | 459 std::string payload2("test string2"); |
469 base::Pickle write_pickle2; | |
470 write_pickle2.WriteString(payload2); | |
471 | 460 |
472 { | 461 { |
473 ScopedClipboardWriter clipboard_writer(CLIPBOARD_TYPE_COPY_PASTE); | 462 ScopedClipboardWriter clipboard_writer(CLIPBOARD_TYPE_COPY_PASTE); |
474 clipboard_writer.WritePickledData(write_pickle1, kFormat1); | 463 clipboard_writer.WriteData(payload1.data(), |
464 static_cast<int>(payload1.size()) kFormat1); | |
475 // overwrite the previous pickle for fun | 465 // overwrite the previous pickle for fun |
476 clipboard_writer.WritePickledData(write_pickle2, kFormat2); | 466 clipboard_writer.WriteData(payload2.data(), |
467 static_cast<int>(payload2.size()), kFormat2); | |
477 } | 468 } |
478 | 469 |
479 ASSERT_TRUE( | 470 ASSERT_TRUE( |
480 this->clipboard().IsFormatAvailable(kFormat2, CLIPBOARD_TYPE_COPY_PASTE)); | 471 this->clipboard().IsFormatAvailable(kFormat2, CLIPBOARD_TYPE_COPY_PASTE)); |
481 | 472 |
482 // Check string 2. | 473 // Check string 2. |
483 std::string output2; | 474 std::string output2; |
484 this->clipboard().ReadData(kFormat2, &output2); | 475 this->clipboard().ReadData(kFormat2, &output2); |
485 ASSERT_FALSE(output2.empty()); | 476 EXPECT_EQ(payload2, output2); |
486 | |
487 base::Pickle read_pickle2(output2.data(), static_cast<int>(output2.size())); | |
488 base::PickleIterator iter2(read_pickle2); | |
489 std::string unpickled_string2; | |
490 ASSERT_TRUE(iter2.ReadString(&unpickled_string2)); | |
491 EXPECT_EQ(payload2, unpickled_string2); | |
492 | 477 |
493 { | 478 { |
494 ScopedClipboardWriter clipboard_writer(CLIPBOARD_TYPE_COPY_PASTE); | 479 ScopedClipboardWriter clipboard_writer(CLIPBOARD_TYPE_COPY_PASTE); |
495 clipboard_writer.WritePickledData(write_pickle2, kFormat2); | 480 clipboard_writer.WriteData(payload2.data(), |
481 static_cast<int>(payload2.size()), kFormat2); | |
496 // overwrite the previous pickle for fun | 482 // overwrite the previous pickle for fun |
497 clipboard_writer.WritePickledData(write_pickle1, kFormat1); | 483 clipboard_writer.WriteData(payload1.data(), |
484 static_cast<int>(payload1.size()) kFormat1); | |
498 } | 485 } |
499 | 486 |
500 ASSERT_TRUE( | 487 ASSERT_TRUE( |
501 this->clipboard().IsFormatAvailable(kFormat1, CLIPBOARD_TYPE_COPY_PASTE)); | 488 this->clipboard().IsFormatAvailable(kFormat1, CLIPBOARD_TYPE_COPY_PASTE)); |
502 | 489 |
503 // Check string 1. | 490 // Check string 1. |
504 std::string output1; | 491 std::string output1; |
505 this->clipboard().ReadData(kFormat1, &output1); | 492 this->clipboard().ReadData(kFormat1, &output1); |
506 ASSERT_FALSE(output1.empty()); | 493 EXPECT_EQ(payload1, output1); |
494 } | |
507 | 495 |
508 base::Pickle read_pickle1(output1.data(), static_cast<int>(output1.size())); | 496 TYPED_TEST(ClipboardTest, PickledDataTest) { |
509 base::PickleIterator iter1(read_pickle1); | 497 const ui::Clipboard::FormatType kFormat = |
510 std::string unpickled_string1; | 498 ui::Clipboard::GetFormatType("chromium/x-test-format"); |
511 ASSERT_TRUE(iter1.ReadString(&unpickled_string1)); | 499 std::string payload("test string"); |
512 EXPECT_EQ(payload1, unpickled_string1); | 500 base::Pickle write_pickle; |
501 write_pickle.WriteString(payload); | |
502 | |
503 { | |
504 ScopedClipboardWriter clipboard_writer(CLIPBOARD_TYPE_COPY_PASTE); | |
505 clipboard_writer.WritePickledData(write_pickle, kFormat); | |
506 } | |
507 | |
508 ASSERT_TRUE( | |
509 this->clipboard().IsFormatAvailable(kFormat, CLIPBOARD_TYPE_COPY_PASTE)); | |
510 std::string output; | |
511 this->clipboard().ReadData(kFormat, &output); | |
512 ASSERT_FALSE(output.empty()); | |
513 | |
514 base::Pickle read_pickle(output.data(), static_cast<int>(output.size())); | |
515 base::PickleIterator iter(read_pickle); | |
516 std::string unpickled_string; | |
517 ASSERT_TRUE(iter.ReadString(&unpickled_string)); | |
513 } | 518 } |
514 | 519 |
515 #if !defined(OS_MACOSX) && !defined(OS_ANDROID) | 520 #if !defined(OS_MACOSX) && !defined(OS_ANDROID) |
516 TYPED_TEST(ClipboardTest, HyperlinkTest) { | 521 TYPED_TEST(ClipboardTest, HyperlinkTest) { |
517 const std::string kTitle("The <Example> Company's \"home page\""); | 522 const std::string kTitle("The <Example> Company's \"home page\""); |
518 const std::string kUrl("http://www.example.com?x=3<=3#\"'<>"); | 523 const std::string kUrl("http://www.example.com?x=3<=3#\"'<>"); |
519 const base::string16 kExpectedHtml(UTF8ToUTF16( | 524 const base::string16 kExpectedHtml(UTF8ToUTF16( |
520 "<a href=\"http://www.example.com?x=3&lt=3#"'<>\">" | 525 "<a href=\"http://www.example.com?x=3&lt=3#"'<>\">" |
521 "The <Example> Company's "home page"</a>")); | 526 "The <Example> Company's "home page"</a>")); |
522 | 527 |
(...skipping 152 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
675 ScopedClipboardWriter scw(CLIPBOARD_TYPE_COPY_PASTE); | 680 ScopedClipboardWriter scw(CLIPBOARD_TYPE_COPY_PASTE); |
676 scw.WritePickledData(base::Pickle(), Clipboard::GetPlainTextFormatType()); | 681 scw.WritePickledData(base::Pickle(), Clipboard::GetPlainTextFormatType()); |
677 } | 682 } |
678 | 683 |
679 TYPED_TEST(ClipboardTest, WriteImageEmptyParams) { | 684 TYPED_TEST(ClipboardTest, WriteImageEmptyParams) { |
680 ScopedClipboardWriter scw(CLIPBOARD_TYPE_COPY_PASTE); | 685 ScopedClipboardWriter scw(CLIPBOARD_TYPE_COPY_PASTE); |
681 scw.WriteImage(SkBitmap()); | 686 scw.WriteImage(SkBitmap()); |
682 } | 687 } |
683 | 688 |
684 } // namespace ui | 689 } // namespace ui |
OLD | NEW |