| 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" |
| (...skipping 361 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 372 for (int j = 0; j < fake_bitmap_2_size.height(); ++j) { | 372 for (int j = 0; j < fake_bitmap_2_size.height(); ++j) { |
| 373 int id = i * fake_bitmap_2_size.height() + j; | 373 int id = i * fake_bitmap_2_size.height() + j; |
| 374 EXPECT_EQ(fake_bitmap_2[id], pixels_2[id]); | 374 EXPECT_EQ(fake_bitmap_2[id], pixels_2[id]); |
| 375 } | 375 } |
| 376 } | 376 } |
| 377 } | 377 } |
| 378 #endif | 378 #endif |
| 379 | 379 |
| 380 TEST_F(ClipboardTest, DataTest) { | 380 TEST_F(ClipboardTest, DataTest) { |
| 381 Clipboard clipboard; | 381 Clipboard clipboard; |
| 382 const char* kFormat = "chromium/x-test-format"; | 382 const ui::Clipboard::FormatType kFormat = |
| 383 ui::Clipboard::RegisterFormatType("chromium/x-test-format"); |
| 383 std::string payload("test string"); | 384 std::string payload("test string"); |
| 384 Pickle write_pickle; | 385 Pickle write_pickle; |
| 385 write_pickle.WriteString(payload); | 386 write_pickle.WriteString(payload); |
| 386 | 387 |
| 387 { | 388 { |
| 388 ScopedClipboardWriter clipboard_writer(&clipboard); | 389 ScopedClipboardWriter clipboard_writer(&clipboard); |
| 389 clipboard_writer.WritePickledData(write_pickle, kFormat); | 390 clipboard_writer.WritePickledData(write_pickle, kFormat); |
| 390 } | 391 } |
| 391 | 392 |
| 392 ASSERT_TRUE(clipboard.IsFormatAvailableByString( | 393 ASSERT_TRUE(clipboard.IsFormatAvailable( |
| 393 kFormat, Clipboard::BUFFER_STANDARD)); | 394 kFormat, Clipboard::BUFFER_STANDARD)); |
| 394 std::string output; | 395 std::string output; |
| 395 clipboard.ReadData(kFormat, &output); | 396 clipboard.ReadData(kFormat, &output); |
| 396 ASSERT_FALSE(output.empty()); | 397 ASSERT_FALSE(output.empty()); |
| 397 | 398 |
| 398 Pickle read_pickle(output.data(), output.size()); | 399 Pickle read_pickle(output.data(), output.size()); |
| 399 void* iter = NULL; | 400 void* iter = NULL; |
| 400 std::string unpickled_string; | 401 std::string unpickled_string; |
| 401 ASSERT_TRUE(read_pickle.ReadString(&iter, &unpickled_string)); | 402 ASSERT_TRUE(read_pickle.ReadString(&iter, &unpickled_string)); |
| 402 EXPECT_EQ(payload, unpickled_string); | 403 EXPECT_EQ(payload, unpickled_string); |
| 403 } | 404 } |
| 404 | 405 |
| 405 TEST_F(ClipboardTest, MultipleDataTest) { | 406 TEST_F(ClipboardTest, MultipleDataTest) { |
| 406 Clipboard clipboard; | 407 Clipboard clipboard; |
| 407 const char* kFormat1 = "chromium/x-test-format1"; | 408 const ui::Clipboard::FormatType kFormat1 = |
| 409 ui::Clipboard::RegisterFormatType("chromium/x-test-format1"); |
| 408 std::string payload1("test string1"); | 410 std::string payload1("test string1"); |
| 409 Pickle write_pickle1; | 411 Pickle write_pickle1; |
| 410 write_pickle1.WriteString(payload1); | 412 write_pickle1.WriteString(payload1); |
| 411 | 413 |
| 412 const char* kFormat2 = "chromium/x-test-format2"; | 414 const ui::Clipboard::FormatType kFormat2 = |
| 415 ui::Clipboard::RegisterFormatType("chromium/x-test-format2"); |
| 413 std::string payload2("test string2"); | 416 std::string payload2("test string2"); |
| 414 Pickle write_pickle2; | 417 Pickle write_pickle2; |
| 415 write_pickle2.WriteString(payload2); | 418 write_pickle2.WriteString(payload2); |
| 416 | 419 |
| 417 { | 420 { |
| 418 ScopedClipboardWriter clipboard_writer(&clipboard); | 421 ScopedClipboardWriter clipboard_writer(&clipboard); |
| 419 clipboard_writer.WritePickledData(write_pickle1, kFormat1); | 422 clipboard_writer.WritePickledData(write_pickle1, kFormat1); |
| 420 // overwrite the previous pickle for fun | 423 // overwrite the previous pickle for fun |
| 421 clipboard_writer.WritePickledData(write_pickle2, kFormat2); | 424 clipboard_writer.WritePickledData(write_pickle2, kFormat2); |
| 422 } | 425 } |
| 423 | 426 |
| 424 ASSERT_TRUE(clipboard.IsFormatAvailableByString( | 427 ASSERT_TRUE(clipboard.IsFormatAvailable( |
| 425 kFormat2, Clipboard::BUFFER_STANDARD)); | 428 kFormat2, Clipboard::BUFFER_STANDARD)); |
| 426 | 429 |
| 427 // Check string 2. | 430 // Check string 2. |
| 428 std::string output2; | 431 std::string output2; |
| 429 clipboard.ReadData(kFormat2, &output2); | 432 clipboard.ReadData(kFormat2, &output2); |
| 430 ASSERT_FALSE(output2.empty()); | 433 ASSERT_FALSE(output2.empty()); |
| 431 | 434 |
| 432 Pickle read_pickle2(output2.data(), output2.size()); | 435 Pickle read_pickle2(output2.data(), output2.size()); |
| 433 void* iter2 = NULL; | 436 void* iter2 = NULL; |
| 434 std::string unpickled_string2; | 437 std::string unpickled_string2; |
| 435 ASSERT_TRUE(read_pickle2.ReadString(&iter2, &unpickled_string2)); | 438 ASSERT_TRUE(read_pickle2.ReadString(&iter2, &unpickled_string2)); |
| 436 EXPECT_EQ(payload2, unpickled_string2); | 439 EXPECT_EQ(payload2, unpickled_string2); |
| 437 | 440 |
| 438 { | 441 { |
| 439 ScopedClipboardWriter clipboard_writer(&clipboard); | 442 ScopedClipboardWriter clipboard_writer(&clipboard); |
| 440 clipboard_writer.WritePickledData(write_pickle2, kFormat2); | 443 clipboard_writer.WritePickledData(write_pickle2, kFormat2); |
| 441 // overwrite the previous pickle for fun | 444 // overwrite the previous pickle for fun |
| 442 clipboard_writer.WritePickledData(write_pickle1, kFormat1); | 445 clipboard_writer.WritePickledData(write_pickle1, kFormat1); |
| 443 } | 446 } |
| 444 | 447 |
| 445 ASSERT_TRUE(clipboard.IsFormatAvailableByString( | 448 ASSERT_TRUE(clipboard.IsFormatAvailable( |
| 446 kFormat1, Clipboard::BUFFER_STANDARD)); | 449 kFormat1, Clipboard::BUFFER_STANDARD)); |
| 447 | 450 |
| 448 // Check string 1. | 451 // Check string 1. |
| 449 std::string output1; | 452 std::string output1; |
| 450 clipboard.ReadData(kFormat1, &output1); | 453 clipboard.ReadData(kFormat1, &output1); |
| 451 ASSERT_FALSE(output1.empty()); | 454 ASSERT_FALSE(output1.empty()); |
| 452 | 455 |
| 453 Pickle read_pickle1(output1.data(), output1.size()); | 456 Pickle read_pickle1(output1.data(), output1.size()); |
| 454 void* iter1 = NULL; | 457 void* iter1 = NULL; |
| 455 std::string unpickled_string1; | 458 std::string unpickled_string1; |
| (...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 566 writer.WriteBookmark(UTF8ToUTF16("foo"), "bar"); | 569 writer.WriteBookmark(UTF8ToUTF16("foo"), "bar"); |
| 567 writer.WriteHyperlink(ASCIIToUTF16("foo"), "bar"); | 570 writer.WriteHyperlink(ASCIIToUTF16("foo"), "bar"); |
| 568 writer.WriteWebSmartPaste(); | 571 writer.WriteWebSmartPaste(); |
| 569 // Left out: WriteFile, WriteFiles, WriteBitmapFromPixels, WritePickledData. | 572 // Left out: WriteFile, WriteFiles, WriteBitmapFromPixels, WritePickledData. |
| 570 } | 573 } |
| 571 | 574 |
| 572 // Passes if we don't crash. | 575 // Passes if we don't crash. |
| 573 } | 576 } |
| 574 | 577 |
| 575 } // namespace ui | 578 } // namespace ui |
| OLD | NEW |