Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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 <mshtmcid.h> | 5 #include <mshtmcid.h> |
| 6 #include <string> | 6 #include <string> |
| 7 | 7 |
| 8 #include "base/scoped_variant_win.h" | |
| 8 #include "base/test/test_file_util.h" | 9 #include "base/test/test_file_util.h" |
| 9 #include "base/utf_string_conversions.h" | 10 #include "base/utf_string_conversions.h" |
| 10 #include "base/win/scoped_bstr.h" | 11 #include "base/win/scoped_bstr.h" |
| 11 #include "base/win/scoped_variant.h" | 12 #include "base/win/scoped_variant.h" |
| 12 #include "base/win/windows_version.h" | 13 #include "base/win/windows_version.h" |
| 13 #include "chrome/common/url_constants.h" | 14 #include "chrome/common/url_constants.h" |
| 14 #include "chrome_frame/test/chrome_frame_test_utils.h" | 15 #include "chrome_frame/test/chrome_frame_test_utils.h" |
| 15 #include "chrome_frame/test/chrome_frame_ui_test_utils.h" | 16 #include "chrome_frame/test/chrome_frame_ui_test_utils.h" |
| 16 #include "chrome_frame/test/mock_ie_event_sink_actions.h" | 17 #include "chrome_frame/test/mock_ie_event_sink_actions.h" |
| 17 #include "chrome_frame/test/mock_ie_event_sink_test.h" | 18 #include "chrome_frame/test/mock_ie_event_sink_test.h" |
| (...skipping 326 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 344 EXPECT_CALL(ie_mock_, OnLoad(_, StrEq(GetSimplePageUrl()))) | 345 EXPECT_CALL(ie_mock_, OnLoad(_, StrEq(GetSimplePageUrl()))) |
| 345 .WillOnce(CloseBrowserMock(&ie_mock_)); | 346 .WillOnce(CloseBrowserMock(&ie_mock_)); |
| 346 | 347 |
| 347 LaunchIEAndNavigate(GetSimplePageUrl()); | 348 LaunchIEAndNavigate(GetSimplePageUrl()); |
| 348 } | 349 } |
| 349 | 350 |
| 350 // Test fixture for tests related to the context menu UI. Since the context | 351 // Test fixture for tests related to the context menu UI. Since the context |
| 351 // menus for CF and IE are different, these tests are not parameterized. | 352 // menus for CF and IE are different, these tests are not parameterized. |
| 352 class ContextMenuTest : public MockIEEventSinkTest, public testing::Test { | 353 class ContextMenuTest : public MockIEEventSinkTest, public testing::Test { |
| 353 public: | 354 public: |
| 354 ContextMenuTest() {} | 355 ContextMenuTest(): kTextFieldInitValue(L"SomeInitializedTextValue") {} |
| 355 | 356 |
| 356 virtual void SetUp() { | 357 virtual void SetUp() { |
| 358 context_menu_page_url = GetTestUrl(L"context_menu.html"); | |
| 359 // Clear clipboard to make sure there is no effect from previous tests. | |
| 360 SetClipboardText(L""); | |
| 357 // These are UI-related tests, so we do not care about the exact | 361 // These are UI-related tests, so we do not care about the exact |
| 358 // navigations that occur. | 362 // navigations that occur. |
| 359 ie_mock_.ExpectAnyNavigations(); | 363 ie_mock_.ExpectAnyNavigations(); |
| 360 EXPECT_CALL(ie_mock_, OnLoad(_, _)).Times(testing::AnyNumber()); | 364 EXPECT_CALL(ie_mock_, OnLoad(_, _)).Times(testing::AnyNumber()); |
| 361 EXPECT_CALL(acc_observer_, OnAccDocLoad(_)).Times(testing::AnyNumber()); | 365 EXPECT_CALL(acc_observer_, OnAccDocLoad(_)).Times(testing::AnyNumber()); |
| 362 } | 366 } |
| 363 | 367 |
| 364 // Common helper function for "Save xxx As" tests. | 368 // Common helper function for "Save xxx As" tests. |
| 365 void DoSaveAsTest(const wchar_t* role, const wchar_t* menu_item_name, | 369 void DoSaveAsTest(const wchar_t* role, const wchar_t* menu_item_name, |
| 366 const wchar_t* file_ext) { | 370 const wchar_t* file_ext) { |
| (...skipping 24 matching lines...) Expand all Loading... | |
| 391 AccDoDefaultAction(AccObjectMatcher(L"Save", L"push button")))); | 395 AccDoDefaultAction(AccObjectMatcher(L"Save", L"push button")))); |
| 392 | 396 |
| 393 EXPECT_CALL(win_observer_mock, OnWindowClose(_)) | 397 EXPECT_CALL(win_observer_mock, OnWindowClose(_)) |
| 394 .WillOnce(CloseWhenFileSaved(&ie_mock_, temp_file_path, 5000)); | 398 .WillOnce(CloseWhenFileSaved(&ie_mock_, temp_file_path, 5000)); |
| 395 | 399 |
| 396 LaunchIEAndNavigate(GetTestUrl(L"save_as_context_menu.html")); | 400 LaunchIEAndNavigate(GetTestUrl(L"save_as_context_menu.html")); |
| 397 ASSERT_TRUE(file_util::DieFileDie(temp_file_path, false)); | 401 ASSERT_TRUE(file_util::DieFileDie(temp_file_path, false)); |
| 398 } | 402 } |
| 399 | 403 |
| 400 protected: | 404 protected: |
| 405 // Html page that holds a text field for context menu testing. | |
| 406 std::wstring context_menu_page_url; | |
| 407 // This is the text value used to test cut/copy/paste etc. | |
| 408 const std::wstring kTextFieldInitValue; | |
| 409 | |
| 401 testing::NiceMock<MockAccEventObserver> acc_observer_; | 410 testing::NiceMock<MockAccEventObserver> acc_observer_; |
| 402 }; | 411 }; |
| 403 | 412 |
| 404 // Test reloading from the context menu. | 413 // Test reloading from the context menu. |
| 405 TEST_F(ContextMenuTest, CFReload) { | 414 TEST_F(ContextMenuTest, CFReload) { |
| 406 server_mock_.ExpectAndServeAnyRequests(CFInvocation::MetaTag()); | 415 server_mock_.ExpectAndServeAnyRequests(CFInvocation::MetaTag()); |
| 407 InSequence expect_in_sequence_for_scope; | 416 InSequence expect_in_sequence_for_scope; |
| 408 | 417 |
| 409 EXPECT_CALL(acc_observer_, OnAccDocLoad(_)) | 418 EXPECT_CALL(acc_observer_, OnAccDocLoad(_)) |
| 410 .WillOnce(OpenContextMenuAsync()); | 419 .WillOnce(OpenContextMenuAsync()); |
| (...skipping 229 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 640 OpenContextMenuAsync())); | 649 OpenContextMenuAsync())); |
| 641 EXPECT_CALL(acc_observer_, OnMenuPopup(_)) | 650 EXPECT_CALL(acc_observer_, OnMenuPopup(_)) |
| 642 .WillOnce(AccLeftClick(AccObjectMatcher(L"Forward"))); | 651 .WillOnce(AccLeftClick(AccObjectMatcher(L"Forward"))); |
| 643 | 652 |
| 644 EXPECT_CALL(ie_mock_, OnLoad(IN_IE, StrEq(page2))) | 653 EXPECT_CALL(ie_mock_, OnLoad(IN_IE, StrEq(page2))) |
| 645 .WillOnce(CloseBrowserMock(&ie_mock_)); | 654 .WillOnce(CloseBrowserMock(&ie_mock_)); |
| 646 | 655 |
| 647 LaunchIEAndNavigate(page1); | 656 LaunchIEAndNavigate(page1); |
| 648 } | 657 } |
| 649 | 658 |
| 659 // Test CF link context menu - Open link in new window. | |
| 660 TEST_F(ContextMenuTest, CFOpenLinkInNewWindow) { | |
| 661 server_mock_.ExpectAndServeAnyRequests(CFInvocation::MetaTag()); | |
| 662 MockIEEventSink new_window_mock; | |
| 663 new_window_mock.ExpectAnyNavigations(); | |
| 664 | |
| 665 // Invoke 'Open link in new window' context menu item. | |
| 666 EXPECT_CALL(acc_observer_, OnAccDocLoad(_)) | |
| 667 .WillOnce(AccRightClick(AccObjectMatcher(L"", L"link"))) | |
| 668 .WillOnce(testing::Return()); | |
| 669 EXPECT_CALL(acc_observer_, OnMenuPopup(_)) | |
| 670 .WillOnce(AccLeftClick(AccObjectMatcher(L"Open link in new window*"))); | |
| 671 | |
| 672 ie_mock_.ExpectNewWindow(&new_window_mock); | |
| 673 EXPECT_CALL(new_window_mock, OnLoad(IN_CF, StrEq(GetSimplePageUrl()))) | |
| 674 .WillOnce(CloseBrowserMock(&new_window_mock)); | |
| 675 EXPECT_CALL(new_window_mock, OnQuit()) | |
| 676 .WillOnce(CloseBrowserMock(&ie_mock_)); | |
| 677 | |
| 678 LaunchIEAndNavigate(GetLinkPageUrl()); | |
| 679 } | |
| 680 | |
| 681 // Test CF link context menu - Copy link address. | |
| 682 TEST_F(ContextMenuTest, CFCopyLinkAddress) { | |
| 683 server_mock_.ExpectAndServeAnyRequests(CFInvocation::MetaTag()); | |
| 684 | |
| 685 // Invoke 'Copy link address' context menu item. | |
| 686 EXPECT_CALL(acc_observer_, OnAccDocLoad(_)) | |
| 687 .WillOnce(AccRightClick(AccObjectMatcher(L"", L"link"))); | |
| 688 EXPECT_CALL(acc_observer_, OnMenuPopup(_)) | |
| 689 .WillOnce(testing::DoAll( | |
| 690 AccLeftClick(AccObjectMatcher(L"Copy link address*")), | |
| 691 CloseBrowserMock(&ie_mock_))); | |
| 692 | |
| 693 LaunchIEAndNavigate(GetLinkPageUrl()); | |
| 694 | |
| 695 EXPECT_STREQ(GetSimplePageUrl().c_str(), GetClipboardText().c_str()); | |
| 696 } | |
| 697 | |
| 698 // Test CF text field context menu - cut. | |
| 699 TEST_F(ContextMenuTest, CFTxtFieldCut) { | |
| 700 server_mock_.ExpectAndServeAnyRequests(CFInvocation::MetaTag()); | |
|
amit
2010/11/09 23:45:27
There's a lot of common code between the following
mdu
2010/11/10 01:21:16
To do this we have to split ContextMenuTest into t
| |
| 701 AccObjectMatcher txtfield_matcher(L"", L"editable text"); | |
| 702 | |
| 703 // Invoke "Cut" context menu item of text field. | |
| 704 EXPECT_CALL(acc_observer_, OnAccDocLoad(_)) | |
| 705 .WillOnce(testing::DoAll( | |
| 706 AccRightClick(txtfield_matcher), | |
| 707 AccWatchForOneValueChange(&acc_observer_, txtfield_matcher))); | |
| 708 EXPECT_CALL(acc_observer_, OnMenuPopup(_)) | |
| 709 .WillOnce(AccLeftClick(AccObjectMatcher(L"Cut*"))); | |
| 710 | |
| 711 // Verify that text field is empty after cut operation. | |
| 712 EXPECT_CALL(acc_observer_, OnAccValueChange(_, _, StrEq(L""))) | |
| 713 .WillOnce(CloseBrowserMock(&ie_mock_)); | |
| 714 | |
| 715 LaunchIEAndNavigate(context_menu_page_url); | |
| 716 // Verify that the text value has been cut to clipboard. | |
| 717 EXPECT_STREQ(kTextFieldInitValue.c_str(), GetClipboardText().c_str()); | |
| 718 } | |
| 719 | |
| 720 // Test CF text field context menu - copy. | |
| 721 TEST_F(ContextMenuTest, CFTxtFieldCopy) { | |
| 722 server_mock_.ExpectAndServeAnyRequests(CFInvocation::MetaTag()); | |
| 723 AccObjectMatcher txtfield_matcher(L"", L"editable text"); | |
| 724 | |
| 725 // Invoke "Copy" context menu item of text field. | |
| 726 EXPECT_CALL(acc_observer_, OnAccDocLoad(_)) | |
| 727 .WillOnce(testing::DoAll( | |
| 728 AccRightClick(txtfield_matcher), | |
| 729 AccWatchForOneValueChange(&acc_observer_, txtfield_matcher))); | |
| 730 EXPECT_CALL(acc_observer_, OnMenuPopup(_)) | |
| 731 .WillOnce(testing::DoAll( | |
| 732 AccLeftClick(AccObjectMatcher(L"Copy*")), | |
| 733 CloseBrowserMock(&ie_mock_))); | |
| 734 | |
| 735 // Verify that there is no change on text field value after copy operation. | |
| 736 EXPECT_CALL(acc_observer_, OnAccValueChange(_, _, _)) | |
| 737 .Times(testing::AtMost(0)); | |
| 738 | |
| 739 LaunchIEAndNavigate(context_menu_page_url); | |
| 740 // Verify that the text value has been copied to clipboard. | |
| 741 EXPECT_STREQ(kTextFieldInitValue.c_str(), GetClipboardText().c_str()); | |
| 742 } | |
| 743 | |
| 744 // Test CF text field context menu - paste. | |
| 745 TEST_F(ContextMenuTest, CFTxtFieldPaste) { | |
| 746 server_mock_.ExpectAndServeAnyRequests(CFInvocation::MetaTag()); | |
| 747 AccObjectMatcher txtfield_matcher(L"", L"editable text"); | |
| 748 | |
| 749 // Invoke "Paste" context menu item of text field. | |
| 750 EXPECT_CALL(acc_observer_, OnAccDocLoad(_)) | |
| 751 .WillOnce(testing::DoAll( | |
| 752 AccRightClick(txtfield_matcher), | |
| 753 AccWatchForOneValueChange(&acc_observer_, txtfield_matcher))); | |
| 754 EXPECT_CALL(acc_observer_, OnMenuPopup(_)) | |
| 755 .WillOnce(AccLeftClick(AccObjectMatcher(L"Paste*"))); | |
| 756 // Verify that value has been pasted to text field. | |
| 757 EXPECT_CALL(acc_observer_, OnAccValueChange(_, _, StrEq(kTextFieldInitValue))) | |
| 758 .WillOnce(CloseBrowserMock(&ie_mock_)); | |
| 759 | |
| 760 // Set some text value to clipboard, this is to emulate the 'copy' action. | |
| 761 SetClipboardText(kTextFieldInitValue); | |
| 762 | |
| 763 LaunchIEAndNavigate(context_menu_page_url); | |
| 764 } | |
| 765 | |
| 766 // Test CF text field context menu - delete. | |
| 767 TEST_F(ContextMenuTest, CFTxtFieldDelete) { | |
| 768 server_mock_.ExpectAndServeAnyRequests(CFInvocation::MetaTag()); | |
| 769 AccObjectMatcher txtfield_matcher(L"", L"editable text"); | |
| 770 | |
| 771 // Invoke 'Delete' context menu item of text field. | |
| 772 EXPECT_CALL(acc_observer_, OnAccDocLoad(_)) | |
| 773 .WillOnce(testing::DoAll( | |
| 774 AccRightClick(txtfield_matcher), | |
| 775 AccWatchForOneValueChange(&acc_observer_, txtfield_matcher))); | |
| 776 EXPECT_CALL(acc_observer_, OnMenuPopup(_)) | |
| 777 .WillOnce(AccLeftClick(AccObjectMatcher(L"Delete*"))); | |
| 778 // Verify that value has been deleted from text field. | |
| 779 EXPECT_CALL(acc_observer_, OnAccValueChange(_, _, StrEq(L""))) | |
| 780 .WillOnce(CloseBrowserMock(&ie_mock_)); | |
| 781 | |
| 782 LaunchIEAndNavigate(context_menu_page_url); | |
| 783 } | |
| 784 | |
| 785 // Test CF text field context menu - select all. | |
| 786 TEST_F(ContextMenuTest, CFTxtFieldSelectAll) { | |
| 787 server_mock_.ExpectAndServeAnyRequests(CFInvocation::MetaTag()); | |
| 788 | |
| 789 // Invoke 'Select all' context menu item of text field. | |
| 790 EXPECT_CALL(acc_observer_, OnAccDocLoad(_)) | |
| 791 .WillOnce(AccRightClick(AccObjectMatcher(L"", L"editable text"))); | |
| 792 EXPECT_CALL(acc_observer_, OnMenuPopup(_)) | |
| 793 .WillOnce(testing::DoAll( | |
| 794 AccLeftClick(AccObjectMatcher(L"Select all*")), | |
| 795 PostMessageToCF(&ie_mock_, L"selectall"))); | |
| 796 // Client side script verifies that the text field value has been selected, | |
| 797 // then send 'OK' message. | |
| 798 EXPECT_CALL(ie_mock_, OnMessage(testing::StrCaseEq(L"OK"), _, _)) | |
| 799 .WillOnce(CloseBrowserMock(&ie_mock_)); | |
| 800 | |
| 801 LaunchIEAndNavigate(context_menu_page_url + L"?action=selectall"); | |
| 802 } | |
| 803 | |
| 804 // Test CF text field context menu - undo. | |
| 805 TEST_F(ContextMenuTest, CFTxtFieldUndo) { | |
| 806 server_mock_.ExpectAndServeAnyRequests(CFInvocation::MetaTag()); | |
| 807 AccObjectMatcher txtfield_matcher(L"", L"editable text"); | |
| 808 | |
| 809 // Change the value of text field to 'A', then invoke 'Undo' context menu item | |
| 810 // of text field. | |
| 811 EXPECT_CALL(acc_observer_, OnAccDocLoad(_)) | |
| 812 .WillOnce(testing::DoAll( | |
| 813 AccSendCharMessage(txtfield_matcher, L'A'), | |
| 814 AccRightClick(txtfield_matcher))); | |
| 815 EXPECT_CALL(acc_observer_, OnMenuPopup(_)) | |
| 816 .WillOnce(testing::DoAll( | |
| 817 AccWatchForOneValueChange(&acc_observer_, txtfield_matcher), | |
| 818 AccLeftClick(AccObjectMatcher(L"Undo*")))); | |
| 819 | |
| 820 // Verify that value has been reset to initial value after undo operation. | |
| 821 EXPECT_CALL(acc_observer_, OnAccValueChange(_, _, StrEq(kTextFieldInitValue))) | |
| 822 .WillOnce(CloseBrowserMock(&ie_mock_)); | |
| 823 | |
| 824 LaunchIEAndNavigate(context_menu_page_url); | |
| 825 } | |
| 826 | |
| 827 // Test CF text field context menu - redo. | |
| 828 TEST_F(ContextMenuTest, CFTxtFieldRedo) { | |
| 829 server_mock_.ExpectAndServeAnyRequests(CFInvocation::MetaTag()); | |
| 830 AccObjectMatcher txtfield_matcher(L"", L"editable text"); | |
| 831 InSequence expect_in_sequence_for_scope; | |
| 832 | |
| 833 // Change text field value to 'A', then undo it. | |
| 834 EXPECT_CALL(acc_observer_, OnAccDocLoad(_)) | |
| 835 .WillOnce(testing::DoAll( | |
| 836 AccSendCharMessage(txtfield_matcher, L'A'), | |
| 837 AccRightClick(txtfield_matcher))); | |
| 838 EXPECT_CALL(acc_observer_, OnMenuPopup(_)) | |
| 839 .WillOnce(testing::DoAll( | |
| 840 AccWatchForOneValueChange(&acc_observer_, txtfield_matcher), | |
| 841 AccLeftClick(AccObjectMatcher(L"Undo*")))); | |
| 842 | |
| 843 // After undo operation is done, invoke 'Redo' context menu item. | |
| 844 EXPECT_CALL(acc_observer_, OnAccValueChange(_, _, StrEq(kTextFieldInitValue))) | |
| 845 .WillOnce(testing::DoAll( | |
| 846 AccRightClick(txtfield_matcher), | |
| 847 AccWatchForOneValueChange(&acc_observer_, txtfield_matcher))); | |
| 848 EXPECT_CALL(acc_observer_, OnMenuPopup(_)) | |
| 849 .WillOnce(AccLeftClick(AccObjectMatcher(L"Redo*"))); | |
| 850 | |
| 851 // After redo operation is done, verify that text field value is reset to its | |
| 852 // changed value 'A'. | |
| 853 EXPECT_CALL(acc_observer_, OnAccValueChange(_, _, StrEq(L"A"))) | |
| 854 .WillOnce(CloseBrowserMock(&ie_mock_)); | |
| 855 | |
| 856 LaunchIEAndNavigate(context_menu_page_url); | |
| 857 } | |
| 858 | |
| 650 } // namespace chrome_frame_test | 859 } // namespace chrome_frame_test |
| OLD | NEW |