| OLD | NEW |
| 1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2006-2008 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 "app/gfx/canvas.h" | 5 #include "app/gfx/canvas.h" |
| 6 #include "app/gfx/path.h" | 6 #include "app/gfx/path.h" |
| 7 #include "base/clipboard.h" | 7 #include "base/clipboard.h" |
| 8 #include "base/message_loop.h" | 8 #include "base/message_loop.h" |
| 9 #include "testing/gtest/include/gtest/gtest.h" | 9 #include "testing/gtest/include/gtest/gtest.h" |
| 10 #include "views/background.h" | 10 #include "views/background.h" |
| (...skipping 603 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 614 root_view->AddChildView(read_only); | 614 root_view->AddChildView(read_only); |
| 615 root_view->AddChildView(password); | 615 root_view->AddChildView(password); |
| 616 | 616 |
| 617 normal->SetText(kNormalText); | 617 normal->SetText(kNormalText); |
| 618 read_only->SetText(kReadOnlyText); | 618 read_only->SetText(kReadOnlyText); |
| 619 password->SetText(kPasswordText); | 619 password->SetText(kPasswordText); |
| 620 | 620 |
| 621 // | 621 // |
| 622 // Test cut. | 622 // Test cut. |
| 623 // | 623 // |
| 624 ASSERT_TRUE(normal->GetNativeComponent()); | 624 ASSERT_TRUE(normal->GetTestingHandle()); |
| 625 normal->SelectAll(); | 625 normal->SelectAll(); |
| 626 ::SendMessage(normal->GetNativeComponent(), WM_CUT, 0, 0); | 626 ::SendMessage(normal->GetTestingHandle(), WM_CUT, 0, 0); |
| 627 | 627 |
| 628 string16 result; | 628 string16 result; |
| 629 clipboard.ReadText(&result); | 629 clipboard.ReadText(&result); |
| 630 EXPECT_EQ(kNormalText, result); | 630 EXPECT_EQ(kNormalText, result); |
| 631 normal->SetText(kNormalText); // Let's revert to the original content. | 631 normal->SetText(kNormalText); // Let's revert to the original content. |
| 632 | 632 |
| 633 ASSERT_TRUE(read_only->GetNativeComponent()); | 633 ASSERT_TRUE(read_only->GetTestingHandle()); |
| 634 read_only->SelectAll(); | 634 read_only->SelectAll(); |
| 635 ::SendMessage(read_only->GetNativeComponent(), WM_CUT, 0, 0); | 635 ::SendMessage(read_only->GetTestingHandle(), WM_CUT, 0, 0); |
| 636 result.clear(); | 636 result.clear(); |
| 637 clipboard.ReadText(&result); | 637 clipboard.ReadText(&result); |
| 638 // Cut should have failed, so the clipboard content should not have changed. | 638 // Cut should have failed, so the clipboard content should not have changed. |
| 639 EXPECT_EQ(kNormalText, result); | 639 EXPECT_EQ(kNormalText, result); |
| 640 | 640 |
| 641 ASSERT_TRUE(password->GetNativeComponent()); | 641 ASSERT_TRUE(password->GetTestingHandle()); |
| 642 password->SelectAll(); | 642 password->SelectAll(); |
| 643 ::SendMessage(password->GetNativeComponent(), WM_CUT, 0, 0); | 643 ::SendMessage(password->GetTestingHandle(), WM_CUT, 0, 0); |
| 644 result.clear(); | 644 result.clear(); |
| 645 clipboard.ReadText(&result); | 645 clipboard.ReadText(&result); |
| 646 // Cut should have failed, so the clipboard content should not have changed. | 646 // Cut should have failed, so the clipboard content should not have changed. |
| 647 EXPECT_EQ(kNormalText, result); | 647 EXPECT_EQ(kNormalText, result); |
| 648 | 648 |
| 649 // | 649 // |
| 650 // Test copy. | 650 // Test copy. |
| 651 // | 651 // |
| 652 | 652 |
| 653 // Let's start with read_only as the clipboard already contains the content | 653 // Let's start with read_only as the clipboard already contains the content |
| 654 // of normal. | 654 // of normal. |
| 655 read_only->SelectAll(); | 655 read_only->SelectAll(); |
| 656 ::SendMessage(read_only->GetNativeComponent(), WM_COPY, 0, 0); | 656 ::SendMessage(read_only->GetTestingHandle(), WM_COPY, 0, 0); |
| 657 result.clear(); | 657 result.clear(); |
| 658 clipboard.ReadText(&result); | 658 clipboard.ReadText(&result); |
| 659 EXPECT_EQ(kReadOnlyText, result); | 659 EXPECT_EQ(kReadOnlyText, result); |
| 660 | 660 |
| 661 normal->SelectAll(); | 661 normal->SelectAll(); |
| 662 ::SendMessage(normal->GetNativeComponent(), WM_COPY, 0, 0); | 662 ::SendMessage(normal->GetTestingHandle(), WM_COPY, 0, 0); |
| 663 result.clear(); | 663 result.clear(); |
| 664 clipboard.ReadText(&result); | 664 clipboard.ReadText(&result); |
| 665 EXPECT_EQ(kNormalText, result); | 665 EXPECT_EQ(kNormalText, result); |
| 666 | 666 |
| 667 password->SelectAll(); | 667 password->SelectAll(); |
| 668 ::SendMessage(password->GetNativeComponent(), WM_COPY, 0, 0); | 668 ::SendMessage(password->GetTestingHandle(), WM_COPY, 0, 0); |
| 669 result.clear(); | 669 result.clear(); |
| 670 clipboard.ReadText(&result); | 670 clipboard.ReadText(&result); |
| 671 // We don't let you copy from a password field, clipboard should not have | 671 // We don't let you copy from a password field, clipboard should not have |
| 672 // changed. | 672 // changed. |
| 673 EXPECT_EQ(kNormalText, result); | 673 EXPECT_EQ(kNormalText, result); |
| 674 | 674 |
| 675 // | 675 // |
| 676 // Test Paste. | 676 // Test Paste. |
| 677 // | 677 // |
| 678 // Note that we use GetWindowText instead of Textfield::GetText below as the | 678 // Note that we use GetWindowText instead of Textfield::GetText below as the |
| 679 // text in the Textfield class is synced to the text of the HWND on | 679 // text in the Textfield class is synced to the text of the HWND on |
| 680 // WM_KEYDOWN messages that we are not simulating here. | 680 // WM_KEYDOWN messages that we are not simulating here. |
| 681 | 681 |
| 682 // Attempting to copy kNormalText in a read-only text-field should fail. | 682 // Attempting to copy kNormalText in a read-only text-field should fail. |
| 683 read_only->SelectAll(); | 683 read_only->SelectAll(); |
| 684 ::SendMessage(read_only->GetNativeComponent(), WM_KEYDOWN, 0, 0); | 684 ::SendMessage(read_only->GetTestingHandle(), WM_KEYDOWN, 0, 0); |
| 685 wchar_t buffer[1024] = { 0 }; | 685 wchar_t buffer[1024] = { 0 }; |
| 686 ::GetWindowText(read_only->GetNativeComponent(), buffer, 1024); | 686 ::GetWindowText(read_only->GetTestingHandle(), buffer, 1024); |
| 687 EXPECT_EQ(kReadOnlyText, std::wstring(buffer)); | 687 EXPECT_EQ(kReadOnlyText, std::wstring(buffer)); |
| 688 | 688 |
| 689 password->SelectAll(); | 689 password->SelectAll(); |
| 690 ::SendMessage(password->GetNativeComponent(), WM_PASTE, 0, 0); | 690 ::SendMessage(password->GetTestingHandle(), WM_PASTE, 0, 0); |
| 691 ::GetWindowText(password->GetNativeComponent(), buffer, 1024); | 691 ::GetWindowText(password->GetTestingHandle(), buffer, 1024); |
| 692 EXPECT_EQ(kNormalText, std::wstring(buffer)); | 692 EXPECT_EQ(kNormalText, std::wstring(buffer)); |
| 693 | 693 |
| 694 // Copy from read_only so the string we are pasting is not the same as the | 694 // Copy from read_only so the string we are pasting is not the same as the |
| 695 // current one. | 695 // current one. |
| 696 read_only->SelectAll(); | 696 read_only->SelectAll(); |
| 697 ::SendMessage(read_only->GetNativeComponent(), WM_COPY, 0, 0); | 697 ::SendMessage(read_only->GetTestingHandle(), WM_COPY, 0, 0); |
| 698 normal->SelectAll(); | 698 normal->SelectAll(); |
| 699 ::SendMessage(normal->GetNativeComponent(), WM_PASTE, 0, 0); | 699 ::SendMessage(normal->GetTestingHandle(), WM_PASTE, 0, 0); |
| 700 ::GetWindowText(normal->GetNativeComponent(), buffer, 1024); | 700 ::GetWindowText(normal->GetTestingHandle(), buffer, 1024); |
| 701 EXPECT_EQ(kReadOnlyText, std::wstring(buffer)); | 701 EXPECT_EQ(kReadOnlyText, std::wstring(buffer)); |
| 702 } | 702 } |
| 703 #endif | 703 #endif |
| 704 | 704 |
| 705 #if defined(OS_WIN) | 705 #if defined(OS_WIN) |
| 706 //////////////////////////////////////////////////////////////////////////////// | 706 //////////////////////////////////////////////////////////////////////////////// |
| 707 // Mouse-wheel message rerouting | 707 // Mouse-wheel message rerouting |
| 708 //////////////////////////////////////////////////////////////////////////////// | 708 //////////////////////////////////////////////////////////////////////////////// |
| 709 class ButtonTest : public NativeButton { | 709 class ButtonTest : public NativeButton { |
| 710 public: | 710 public: |
| (...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 803 ::SendMessage(view_with_controls->button_->GetHWND(), | 803 ::SendMessage(view_with_controls->button_->GetHWND(), |
| 804 WM_MOUSEWHEEL, MAKEWPARAM(0, -20), MAKELPARAM(250, 250)); | 804 WM_MOUSEWHEEL, MAKEWPARAM(0, -20), MAKELPARAM(250, 250)); |
| 805 EXPECT_EQ(40, scroll_view->GetVisibleRect().y()); | 805 EXPECT_EQ(40, scroll_view->GetVisibleRect().y()); |
| 806 | 806 |
| 807 // Then the check-box. | 807 // Then the check-box. |
| 808 ::SendMessage(view_with_controls->checkbox_->GetHWND(), | 808 ::SendMessage(view_with_controls->checkbox_->GetHWND(), |
| 809 WM_MOUSEWHEEL, MAKEWPARAM(0, -20), MAKELPARAM(250, 250)); | 809 WM_MOUSEWHEEL, MAKEWPARAM(0, -20), MAKELPARAM(250, 250)); |
| 810 EXPECT_EQ(60, scroll_view->GetVisibleRect().y()); | 810 EXPECT_EQ(60, scroll_view->GetVisibleRect().y()); |
| 811 | 811 |
| 812 // Then the text-field. | 812 // Then the text-field. |
| 813 ::SendMessage(view_with_controls->text_field_->GetNativeComponent(), | 813 ::SendMessage(view_with_controls->text_field_->GetTestingHandle(), |
| 814 WM_MOUSEWHEEL, MAKEWPARAM(0, -20), MAKELPARAM(250, 250)); | 814 WM_MOUSEWHEEL, MAKEWPARAM(0, -20), MAKELPARAM(250, 250)); |
| 815 EXPECT_EQ(80, scroll_view->GetVisibleRect().y()); | 815 EXPECT_EQ(80, scroll_view->GetVisibleRect().y()); |
| 816 | 816 |
| 817 // Ensure we don't scroll when the mouse is not over that window. | 817 // Ensure we don't scroll when the mouse is not over that window. |
| 818 ::SendMessage(view_with_controls->text_field_->GetNativeComponent(), | 818 ::SendMessage(view_with_controls->text_field_->GetTestingHandle(), |
| 819 WM_MOUSEWHEEL, MAKEWPARAM(0, -20), MAKELPARAM(50, 50)); | 819 WM_MOUSEWHEEL, MAKEWPARAM(0, -20), MAKELPARAM(50, 50)); |
| 820 EXPECT_EQ(80, scroll_view->GetVisibleRect().y()); | 820 EXPECT_EQ(80, scroll_view->GetVisibleRect().y()); |
| 821 } | 821 } |
| 822 #endif | 822 #endif |
| 823 | 823 |
| 824 //////////////////////////////////////////////////////////////////////////////// | 824 //////////////////////////////////////////////////////////////////////////////// |
| 825 // Dialogs' default button | 825 // Dialogs' default button |
| 826 //////////////////////////////////////////////////////////////////////////////// | 826 //////////////////////////////////////////////////////////////////////////////// |
| 827 | 827 |
| 828 class TestDialogView : public views::View, | 828 class TestDialogView : public views::View, |
| (...skipping 169 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 998 SimularePressingEnterAndCheckDefaultButton(OK); | 998 SimularePressingEnterAndCheckDefaultButton(OK); |
| 999 | 999 |
| 1000 // Focus the cancel button. | 1000 // Focus the cancel button. |
| 1001 client_view_->FocusWillChange(NULL, cancel_button_); | 1001 client_view_->FocusWillChange(NULL, cancel_button_); |
| 1002 EXPECT_FALSE(ok_button_->is_default()); | 1002 EXPECT_FALSE(ok_button_->is_default()); |
| 1003 EXPECT_TRUE(cancel_button_->is_default()); | 1003 EXPECT_TRUE(cancel_button_->is_default()); |
| 1004 EXPECT_FALSE(dialog_view_->button1_->is_default()); | 1004 EXPECT_FALSE(dialog_view_->button1_->is_default()); |
| 1005 EXPECT_FALSE(dialog_view_->button2_->is_default()); | 1005 EXPECT_FALSE(dialog_view_->button2_->is_default()); |
| 1006 SimularePressingEnterAndCheckDefaultButton(CANCEL); | 1006 SimularePressingEnterAndCheckDefaultButton(CANCEL); |
| 1007 } | 1007 } |
| OLD | NEW |