Chromium Code Reviews| 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 <vector> | 5 #include <vector> |
| 6 | 6 |
| 7 #include "base/auto_reset.h" | 7 #include "base/auto_reset.h" |
| 8 #include "base/memory/scoped_ptr.h" | 8 #include "base/memory/scoped_ptr.h" |
| 9 #include "base/message_loop.h" | 9 #include "base/message_loop.h" |
| 10 #include "base/string16.h" | 10 #include "base/string16.h" |
| (...skipping 482 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 493 #endif | 493 #endif |
| 494 TEST_F(TextfieldViewsModelTest, MAYBE_Clipboard) { | 494 TEST_F(TextfieldViewsModelTest, MAYBE_Clipboard) { |
| 495 ui::Clipboard* clipboard | 495 ui::Clipboard* clipboard |
| 496 = views::ViewsDelegate::views_delegate->GetClipboard(); | 496 = views::ViewsDelegate::views_delegate->GetClipboard(); |
| 497 string16 initial_clipboard_text = ASCIIToUTF16("initial text"); | 497 string16 initial_clipboard_text = ASCIIToUTF16("initial text"); |
| 498 ui::ScopedClipboardWriter(clipboard).WriteText(initial_clipboard_text); | 498 ui::ScopedClipboardWriter(clipboard).WriteText(initial_clipboard_text); |
| 499 | 499 |
| 500 string16 clipboard_text; | 500 string16 clipboard_text; |
| 501 TextfieldViewsModel model(NULL); | 501 TextfieldViewsModel model(NULL); |
| 502 model.Append(ASCIIToUTF16("HELLO WORLD")); | 502 model.Append(ASCIIToUTF16("HELLO WORLD")); |
| 503 | |
| 504 // Cut with an empty selection should do nothing. | |
| 503 model.MoveCursor(gfx::LINE_BREAK, gfx::CURSOR_RIGHT, false); | 505 model.MoveCursor(gfx::LINE_BREAK, gfx::CURSOR_RIGHT, false); |
| 504 | |
| 505 // Test for cut: Empty selection. | |
| 506 EXPECT_FALSE(model.Cut()); | 506 EXPECT_FALSE(model.Cut()); |
| 507 clipboard->ReadText(ui::Clipboard::BUFFER_STANDARD, &clipboard_text); | 507 clipboard->ReadText(ui::Clipboard::BUFFER_STANDARD, &clipboard_text); |
| 508 EXPECT_STR_EQ(UTF16ToUTF8(initial_clipboard_text), clipboard_text); | 508 EXPECT_EQ(initial_clipboard_text, clipboard_text); |
| 509 EXPECT_STR_EQ("HELLO WORLD", model.GetText()); | 509 EXPECT_STR_EQ("HELLO WORLD", model.GetText()); |
| 510 EXPECT_EQ(11U, model.GetCursorPosition()); | 510 EXPECT_EQ(11U, model.GetCursorPosition()); |
| 511 | 511 |
| 512 // Test for cut: Non-empty selection. | 512 // Copy with an empty selection should do nothing. |
| 513 model.Copy(); | |
| 514 clipboard->ReadText(ui::Clipboard::BUFFER_STANDARD, &clipboard_text); | |
| 515 EXPECT_EQ(initial_clipboard_text, clipboard_text); | |
| 516 EXPECT_STR_EQ("HELLO WORLD", model.GetText()); | |
| 517 EXPECT_EQ(11U, model.GetCursorPosition()); | |
| 518 | |
| 519 // Cut on obscured (password) text should do nothing. | |
| 520 model.render_text()->SetObscured(true); | |
| 521 model.SelectAll(); | |
| 522 EXPECT_FALSE(model.Cut()); | |
| 523 clipboard->ReadText(ui::Clipboard::BUFFER_STANDARD, &clipboard_text); | |
| 524 EXPECT_EQ(initial_clipboard_text, clipboard_text); | |
| 525 EXPECT_STR_EQ("HELLO WORLD", model.GetText()); | |
| 526 EXPECT_STR_EQ("HELLO WORLD", model.GetSelectedText()); | |
| 527 | |
| 528 // Copy on obscured text should do nothing. | |
| 529 model.SelectAll(); | |
| 530 EXPECT_FALSE(model.Cut()); | |
|
xji
2012/02/18 01:28:47
s/Cut/Copy/
benrg
2012/02/24 19:07:44
Fixed.
| |
| 531 clipboard->ReadText(ui::Clipboard::BUFFER_STANDARD, &clipboard_text); | |
| 532 EXPECT_EQ(initial_clipboard_text, clipboard_text); | |
| 533 EXPECT_STR_EQ("HELLO WORLD", model.GetText()); | |
| 534 EXPECT_STR_EQ("HELLO WORLD", model.GetSelectedText()); | |
| 535 | |
| 536 // Cut with non-empty selection. | |
| 537 model.render_text()->SetObscured(false); | |
| 538 model.MoveCursor(gfx::LINE_BREAK, gfx::CURSOR_RIGHT, false); | |
| 513 model.MoveCursor(gfx::WORD_BREAK, gfx::CURSOR_LEFT, true); | 539 model.MoveCursor(gfx::WORD_BREAK, gfx::CURSOR_LEFT, true); |
| 514 EXPECT_TRUE(model.Cut()); | 540 EXPECT_TRUE(model.Cut()); |
| 515 clipboard->ReadText(ui::Clipboard::BUFFER_STANDARD, &clipboard_text); | 541 clipboard->ReadText(ui::Clipboard::BUFFER_STANDARD, &clipboard_text); |
| 516 EXPECT_STR_EQ("WORLD", clipboard_text); | 542 EXPECT_STR_EQ("WORLD", clipboard_text); |
| 517 EXPECT_STR_EQ("HELLO ", model.GetText()); | 543 EXPECT_STR_EQ("HELLO ", model.GetText()); |
| 518 EXPECT_EQ(6U, model.GetCursorPosition()); | 544 EXPECT_EQ(6U, model.GetCursorPosition()); |
| 519 | 545 |
| 520 // Test for copy: Empty selection. | 546 // Copy with non-empty selection. |
|
msw
2012/02/22 00:33:26
Why remove this portion of the test?
benrg
2012/02/24 19:07:44
I didn't, I just moved it ("Copy with an empty sel
| |
| 521 model.Copy(); | |
| 522 clipboard->ReadText(ui::Clipboard::BUFFER_STANDARD, &clipboard_text); | |
| 523 EXPECT_STR_EQ("WORLD", clipboard_text); | |
| 524 EXPECT_STR_EQ("HELLO ", model.GetText()); | |
| 525 EXPECT_EQ(6U, model.GetCursorPosition()); | |
| 526 | |
| 527 // Test for copy: Non-empty selection. | |
| 528 model.Append(ASCIIToUTF16("HELLO WORLD")); | 547 model.Append(ASCIIToUTF16("HELLO WORLD")); |
| 529 model.SelectAll(); | 548 model.SelectAll(); |
| 530 model.Copy(); | 549 model.Copy(); |
| 531 clipboard->ReadText(ui::Clipboard::BUFFER_STANDARD, &clipboard_text); | 550 clipboard->ReadText(ui::Clipboard::BUFFER_STANDARD, &clipboard_text); |
| 532 EXPECT_STR_EQ("HELLO HELLO WORLD", clipboard_text); | 551 EXPECT_STR_EQ("HELLO HELLO WORLD", clipboard_text); |
| 533 EXPECT_STR_EQ("HELLO HELLO WORLD", model.GetText()); | 552 EXPECT_STR_EQ("HELLO HELLO WORLD", model.GetText()); |
| 534 EXPECT_EQ(17U, model.GetCursorPosition()); | 553 EXPECT_EQ(17U, model.GetCursorPosition()); |
| 535 | 554 |
| 536 // Test for paste. | 555 // Paste (with obscured bit set; should be ignored). |
|
xji
2012/02/18 01:28:47
I feel the comment is a bit confusing. you mean "o
benrg
2012/02/24 19:07:44
Done.
| |
| 537 model.ClearSelection(); | 556 model.ClearSelection(); |
| 538 model.MoveCursor(gfx::LINE_BREAK, gfx::CURSOR_RIGHT, false); | 557 model.MoveCursor(gfx::LINE_BREAK, gfx::CURSOR_RIGHT, false); |
| 539 model.MoveCursor(gfx::WORD_BREAK, gfx::CURSOR_LEFT, true); | 558 model.MoveCursor(gfx::WORD_BREAK, gfx::CURSOR_LEFT, true); |
| 559 model.render_text()->SetObscured(true); | |
|
xji
2012/02/18 01:28:47
keep the original test and add one with obscured =
benrg
2012/02/24 19:07:44
Done.
| |
| 540 EXPECT_TRUE(model.Paste()); | 560 EXPECT_TRUE(model.Paste()); |
| 541 clipboard->ReadText(ui::Clipboard::BUFFER_STANDARD, &clipboard_text); | 561 clipboard->ReadText(ui::Clipboard::BUFFER_STANDARD, &clipboard_text); |
| 542 EXPECT_STR_EQ("HELLO HELLO WORLD", clipboard_text); | 562 EXPECT_STR_EQ("HELLO HELLO WORLD", clipboard_text); |
| 543 EXPECT_STR_EQ("HELLO HELLO HELLO HELLO WORLD", model.GetText()); | 563 EXPECT_STR_EQ("HELLO HELLO HELLO HELLO WORLD", model.GetText()); |
| 544 EXPECT_EQ(29U, model.GetCursorPosition()); | 564 EXPECT_EQ(29U, model.GetCursorPosition()); |
| 545 } | 565 } |
| 546 | 566 |
| 547 static void SelectWordTestVerifier(const TextfieldViewsModel& model, | 567 static void SelectWordTestVerifier(const TextfieldViewsModel& model, |
| 548 const string16 &expected_selected_string, size_t expected_cursor_pos) { | 568 const string16 &expected_selected_string, size_t expected_cursor_pos) { |
| 549 EXPECT_EQ(expected_selected_string, model.GetSelectedText()); | 569 EXPECT_EQ(expected_selected_string, model.GetSelectedText()); |
| (...skipping 977 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1527 EXPECT_TRUE(model.Undo()); | 1547 EXPECT_TRUE(model.Undo()); |
| 1528 EXPECT_STR_EQ("ABCDE", model.GetText()); | 1548 EXPECT_STR_EQ("ABCDE", model.GetText()); |
| 1529 EXPECT_TRUE(model.Redo()); | 1549 EXPECT_TRUE(model.Redo()); |
| 1530 EXPECT_STR_EQ("1234", model.GetText()); | 1550 EXPECT_STR_EQ("1234", model.GetText()); |
| 1531 EXPECT_FALSE(model.Redo()); | 1551 EXPECT_FALSE(model.Redo()); |
| 1532 | 1552 |
| 1533 // TODO(oshima): We need MockInputMethod to test the behavior with IME. | 1553 // TODO(oshima): We need MockInputMethod to test the behavior with IME. |
| 1534 } | 1554 } |
| 1535 | 1555 |
| 1536 } // namespace views | 1556 } // namespace views |
| OLD | NEW |