| 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 380 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 391 { | 391 { |
| 392 SCOPED_TRACE("second bitmap"); | 392 SCOPED_TRACE("second bitmap"); |
| 393 TestBitmapWrite(&this->clipboard(), gfx::Size(2, 7), fake_bitmap_2); | 393 TestBitmapWrite(&this->clipboard(), gfx::Size(2, 7), fake_bitmap_2); |
| 394 } | 394 } |
| 395 } | 395 } |
| 396 | 396 |
| 397 TYPED_TEST(ClipboardTest, DataTest) { | 397 TYPED_TEST(ClipboardTest, DataTest) { |
| 398 const ui::Clipboard::FormatType kFormat = | 398 const ui::Clipboard::FormatType kFormat = |
| 399 ui::Clipboard::GetFormatType("chromium/x-test-format"); | 399 ui::Clipboard::GetFormatType("chromium/x-test-format"); |
| 400 std::string payload("test string"); | 400 std::string payload("test string"); |
| 401 Pickle write_pickle; | 401 base::Pickle write_pickle; |
| 402 write_pickle.WriteString(payload); | 402 write_pickle.WriteString(payload); |
| 403 | 403 |
| 404 { | 404 { |
| 405 ScopedClipboardWriter clipboard_writer(CLIPBOARD_TYPE_COPY_PASTE); | 405 ScopedClipboardWriter clipboard_writer(CLIPBOARD_TYPE_COPY_PASTE); |
| 406 clipboard_writer.WritePickledData(write_pickle, kFormat); | 406 clipboard_writer.WritePickledData(write_pickle, kFormat); |
| 407 } | 407 } |
| 408 | 408 |
| 409 ASSERT_TRUE( | 409 ASSERT_TRUE( |
| 410 this->clipboard().IsFormatAvailable(kFormat, CLIPBOARD_TYPE_COPY_PASTE)); | 410 this->clipboard().IsFormatAvailable(kFormat, CLIPBOARD_TYPE_COPY_PASTE)); |
| 411 std::string output; | 411 std::string output; |
| 412 this->clipboard().ReadData(kFormat, &output); | 412 this->clipboard().ReadData(kFormat, &output); |
| 413 ASSERT_FALSE(output.empty()); | 413 ASSERT_FALSE(output.empty()); |
| 414 | 414 |
| 415 Pickle read_pickle(output.data(), output.size()); | 415 base::Pickle read_pickle(output.data(), output.size()); |
| 416 PickleIterator iter(read_pickle); | 416 base::PickleIterator iter(read_pickle); |
| 417 std::string unpickled_string; | 417 std::string unpickled_string; |
| 418 ASSERT_TRUE(iter.ReadString(&unpickled_string)); | 418 ASSERT_TRUE(iter.ReadString(&unpickled_string)); |
| 419 EXPECT_EQ(payload, unpickled_string); | 419 EXPECT_EQ(payload, unpickled_string); |
| 420 } | 420 } |
| 421 | 421 |
| 422 TYPED_TEST(ClipboardTest, MultipleDataTest) { | 422 TYPED_TEST(ClipboardTest, MultipleDataTest) { |
| 423 const ui::Clipboard::FormatType kFormat1 = | 423 const ui::Clipboard::FormatType kFormat1 = |
| 424 ui::Clipboard::GetFormatType("chromium/x-test-format1"); | 424 ui::Clipboard::GetFormatType("chromium/x-test-format1"); |
| 425 std::string payload1("test string1"); | 425 std::string payload1("test string1"); |
| 426 Pickle write_pickle1; | 426 base::Pickle write_pickle1; |
| 427 write_pickle1.WriteString(payload1); | 427 write_pickle1.WriteString(payload1); |
| 428 | 428 |
| 429 const ui::Clipboard::FormatType kFormat2 = | 429 const ui::Clipboard::FormatType kFormat2 = |
| 430 ui::Clipboard::GetFormatType("chromium/x-test-format2"); | 430 ui::Clipboard::GetFormatType("chromium/x-test-format2"); |
| 431 std::string payload2("test string2"); | 431 std::string payload2("test string2"); |
| 432 Pickle write_pickle2; | 432 base::Pickle write_pickle2; |
| 433 write_pickle2.WriteString(payload2); | 433 write_pickle2.WriteString(payload2); |
| 434 | 434 |
| 435 { | 435 { |
| 436 ScopedClipboardWriter clipboard_writer(CLIPBOARD_TYPE_COPY_PASTE); | 436 ScopedClipboardWriter clipboard_writer(CLIPBOARD_TYPE_COPY_PASTE); |
| 437 clipboard_writer.WritePickledData(write_pickle1, kFormat1); | 437 clipboard_writer.WritePickledData(write_pickle1, kFormat1); |
| 438 // overwrite the previous pickle for fun | 438 // overwrite the previous pickle for fun |
| 439 clipboard_writer.WritePickledData(write_pickle2, kFormat2); | 439 clipboard_writer.WritePickledData(write_pickle2, kFormat2); |
| 440 } | 440 } |
| 441 | 441 |
| 442 ASSERT_TRUE( | 442 ASSERT_TRUE( |
| 443 this->clipboard().IsFormatAvailable(kFormat2, CLIPBOARD_TYPE_COPY_PASTE)); | 443 this->clipboard().IsFormatAvailable(kFormat2, CLIPBOARD_TYPE_COPY_PASTE)); |
| 444 | 444 |
| 445 // Check string 2. | 445 // Check string 2. |
| 446 std::string output2; | 446 std::string output2; |
| 447 this->clipboard().ReadData(kFormat2, &output2); | 447 this->clipboard().ReadData(kFormat2, &output2); |
| 448 ASSERT_FALSE(output2.empty()); | 448 ASSERT_FALSE(output2.empty()); |
| 449 | 449 |
| 450 Pickle read_pickle2(output2.data(), output2.size()); | 450 base::Pickle read_pickle2(output2.data(), output2.size()); |
| 451 PickleIterator iter2(read_pickle2); | 451 base::PickleIterator iter2(read_pickle2); |
| 452 std::string unpickled_string2; | 452 std::string unpickled_string2; |
| 453 ASSERT_TRUE(iter2.ReadString(&unpickled_string2)); | 453 ASSERT_TRUE(iter2.ReadString(&unpickled_string2)); |
| 454 EXPECT_EQ(payload2, unpickled_string2); | 454 EXPECT_EQ(payload2, unpickled_string2); |
| 455 | 455 |
| 456 { | 456 { |
| 457 ScopedClipboardWriter clipboard_writer(CLIPBOARD_TYPE_COPY_PASTE); | 457 ScopedClipboardWriter clipboard_writer(CLIPBOARD_TYPE_COPY_PASTE); |
| 458 clipboard_writer.WritePickledData(write_pickle2, kFormat2); | 458 clipboard_writer.WritePickledData(write_pickle2, kFormat2); |
| 459 // overwrite the previous pickle for fun | 459 // overwrite the previous pickle for fun |
| 460 clipboard_writer.WritePickledData(write_pickle1, kFormat1); | 460 clipboard_writer.WritePickledData(write_pickle1, kFormat1); |
| 461 } | 461 } |
| 462 | 462 |
| 463 ASSERT_TRUE( | 463 ASSERT_TRUE( |
| 464 this->clipboard().IsFormatAvailable(kFormat1, CLIPBOARD_TYPE_COPY_PASTE)); | 464 this->clipboard().IsFormatAvailable(kFormat1, CLIPBOARD_TYPE_COPY_PASTE)); |
| 465 | 465 |
| 466 // Check string 1. | 466 // Check string 1. |
| 467 std::string output1; | 467 std::string output1; |
| 468 this->clipboard().ReadData(kFormat1, &output1); | 468 this->clipboard().ReadData(kFormat1, &output1); |
| 469 ASSERT_FALSE(output1.empty()); | 469 ASSERT_FALSE(output1.empty()); |
| 470 | 470 |
| 471 Pickle read_pickle1(output1.data(), output1.size()); | 471 base::Pickle read_pickle1(output1.data(), output1.size()); |
| 472 PickleIterator iter1(read_pickle1); | 472 base::PickleIterator iter1(read_pickle1); |
| 473 std::string unpickled_string1; | 473 std::string unpickled_string1; |
| 474 ASSERT_TRUE(iter1.ReadString(&unpickled_string1)); | 474 ASSERT_TRUE(iter1.ReadString(&unpickled_string1)); |
| 475 EXPECT_EQ(payload1, unpickled_string1); | 475 EXPECT_EQ(payload1, unpickled_string1); |
| 476 } | 476 } |
| 477 | 477 |
| 478 #if !defined(OS_MACOSX) && !defined(OS_ANDROID) | 478 #if !defined(OS_MACOSX) && !defined(OS_ANDROID) |
| 479 TYPED_TEST(ClipboardTest, HyperlinkTest) { | 479 TYPED_TEST(ClipboardTest, HyperlinkTest) { |
| 480 const std::string kTitle("The <Example> Company's \"home page\""); | 480 const std::string kTitle("The <Example> Company's \"home page\""); |
| 481 const std::string kUrl("http://www.example.com?x=3<=3#\"'<>"); | 481 const std::string kUrl("http://www.example.com?x=3<=3#\"'<>"); |
| 482 const base::string16 kExpectedHtml(UTF8ToUTF16( | 482 const base::string16 kExpectedHtml(UTF8ToUTF16( |
| (...skipping 146 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 629 scw.WriteBookmark(base::string16(), std::string()); | 629 scw.WriteBookmark(base::string16(), std::string()); |
| 630 } | 630 } |
| 631 | 631 |
| 632 TYPED_TEST(ClipboardTest, WriteHyperlinkEmptyParams) { | 632 TYPED_TEST(ClipboardTest, WriteHyperlinkEmptyParams) { |
| 633 ScopedClipboardWriter scw(CLIPBOARD_TYPE_COPY_PASTE); | 633 ScopedClipboardWriter scw(CLIPBOARD_TYPE_COPY_PASTE); |
| 634 scw.WriteHyperlink(base::string16(), std::string()); | 634 scw.WriteHyperlink(base::string16(), std::string()); |
| 635 } | 635 } |
| 636 | 636 |
| 637 TYPED_TEST(ClipboardTest, WritePickledData) { | 637 TYPED_TEST(ClipboardTest, WritePickledData) { |
| 638 ScopedClipboardWriter scw(CLIPBOARD_TYPE_COPY_PASTE); | 638 ScopedClipboardWriter scw(CLIPBOARD_TYPE_COPY_PASTE); |
| 639 scw.WritePickledData(Pickle(), Clipboard::GetPlainTextFormatType()); | 639 scw.WritePickledData(base::Pickle(), Clipboard::GetPlainTextFormatType()); |
| 640 } | 640 } |
| 641 | 641 |
| 642 TYPED_TEST(ClipboardTest, WriteImageEmptyParams) { | 642 TYPED_TEST(ClipboardTest, WriteImageEmptyParams) { |
| 643 ScopedClipboardWriter scw(CLIPBOARD_TYPE_COPY_PASTE); | 643 ScopedClipboardWriter scw(CLIPBOARD_TYPE_COPY_PASTE); |
| 644 scw.WriteImage(SkBitmap()); | 644 scw.WriteImage(SkBitmap()); |
| 645 } | 645 } |
| 646 | 646 |
| 647 } // namespace ui | 647 } // namespace ui |
| OLD | NEW |