Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(364)

Side by Side Diff: chrome/browser/autocomplete/autocomplete_edit_view_browsertest.cc

Issue 4202005: [Linux] Improve preedit string and Instant suggestion support in omnibox. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Update according to review comment. Created 10 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « no previous file | chrome/browser/autocomplete/autocomplete_edit_view_gtk.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 <stdio.h> 5 #include <stdio.h>
6 6
7 #include "app/keyboard_codes.h" 7 #include "app/keyboard_codes.h"
8 #include "base/message_loop.h" 8 #include "base/message_loop.h"
9 #include "base/string16.h" 9 #include "base/string16.h"
10 #include "base/string_util.h" 10 #include "base/string_util.h"
(...skipping 641 matching lines...) Expand 10 before | Expand all | Expand 10 after
652 break; 652 break;
653 } 653 }
654 654
655 EXPECT_NE(old_text, edit_view->GetText()); 655 EXPECT_NE(old_text, edit_view->GetText());
656 656
657 // Escape shall revert back to the default match item. 657 // Escape shall revert back to the default match item.
658 ASSERT_NO_FATAL_FAILURE(SendKey(app::VKEY_ESCAPE, false, false, false)); 658 ASSERT_NO_FATAL_FAILURE(SendKey(app::VKEY_ESCAPE, false, false, false));
659 EXPECT_EQ(old_text, edit_view->GetText()); 659 EXPECT_EQ(old_text, edit_view->GetText());
660 EXPECT_EQ(old_selected_line, popup_model->selected_line()); 660 EXPECT_EQ(old_selected_line, popup_model->selected_line());
661 } 661 }
662
663 IN_PROC_BROWSER_TEST_F(AutocompleteEditViewTest, BasicTextOperations) {
664 ASSERT_NO_FATAL_FAILURE(SetupComponents());
665 ui_test_utils::NavigateToURL(browser(), GURL(chrome::kAboutBlankURL));
666 browser()->FocusLocationBar();
667
668 AutocompleteEditView* edit_view = NULL;
669 ASSERT_NO_FATAL_FAILURE(GetAutocompleteEditView(&edit_view));
670
671 std::wstring old_text = edit_view->GetText();
672 EXPECT_EQ(UTF8ToWide(chrome::kAboutBlankURL), old_text);
673 EXPECT_TRUE(edit_view->IsSelectAll());
674
675 std::wstring::size_type start, end;
676 edit_view->GetSelectionBounds(&start, &end);
677 EXPECT_EQ(0U, start);
678 EXPECT_EQ(old_text.size(), end);
679
680 // Move the cursor to the end.
681 ASSERT_NO_FATAL_FAILURE(SendKey(app::VKEY_END, false, false, false));
682 EXPECT_FALSE(edit_view->IsSelectAll());
683
684 // Make sure the cursor is placed correctly.
685 edit_view->GetSelectionBounds(&start, &end);
686 EXPECT_EQ(old_text.size(), start);
687 EXPECT_EQ(old_text.size(), end);
688
689 // Insert one character at the end. Make sure we won't insert anything after
690 // the special ZWS mark used in gtk implementation.
691 ASSERT_NO_FATAL_FAILURE(SendKey(app::VKEY_A, false, false, false));
692 EXPECT_EQ(old_text + L"a", edit_view->GetText());
693
694 // Delete one character from the end. Make sure we won't delete the special
695 // ZWS mark used in gtk implementation.
696 ASSERT_NO_FATAL_FAILURE(SendKey(app::VKEY_BACK, false, false, false));
697 EXPECT_EQ(old_text, edit_view->GetText());
698
699 edit_view->SelectAll(true);
700 EXPECT_TRUE(edit_view->IsSelectAll());
701 edit_view->GetSelectionBounds(&start, &end);
702 EXPECT_EQ(0U, start);
703 EXPECT_EQ(old_text.size(), end);
704
705 // Delete the content
706 ASSERT_NO_FATAL_FAILURE(SendKey(app::VKEY_DELETE, false, false, false));
707 EXPECT_TRUE(edit_view->IsSelectAll());
708 edit_view->GetSelectionBounds(&start, &end);
709 EXPECT_EQ(0U, start);
710 EXPECT_EQ(0U, end);
711 EXPECT_TRUE(edit_view->GetText().empty());
712
713 // Check if RevertAll() can set text and cursor correctly.
714 edit_view->RevertAll();
715 EXPECT_FALSE(edit_view->IsSelectAll());
716 EXPECT_EQ(old_text, edit_view->GetText());
717 edit_view->GetSelectionBounds(&start, &end);
718 EXPECT_EQ(old_text.size(), start);
719 EXPECT_EQ(old_text.size(), end);
720 }
721
722 #if defined(OS_LINUX)
723 IN_PROC_BROWSER_TEST_F(AutocompleteEditViewTest, UndoRedoLinux) {
724 ASSERT_NO_FATAL_FAILURE(SetupComponents());
725 ui_test_utils::NavigateToURL(browser(), GURL(chrome::kAboutBlankURL));
726 browser()->FocusLocationBar();
727
728 AutocompleteEditView* edit_view = NULL;
729 ASSERT_NO_FATAL_FAILURE(GetAutocompleteEditView(&edit_view));
730
731 std::wstring old_text = edit_view->GetText();
732 EXPECT_EQ(UTF8ToWide(chrome::kAboutBlankURL), old_text);
733 EXPECT_TRUE(edit_view->IsSelectAll());
734
735 // Undo should clear the omnibox.
736 ASSERT_NO_FATAL_FAILURE(SendKey(app::VKEY_Z, true, false, false));
737 EXPECT_TRUE(edit_view->GetText().empty());
738
739 // Nothing should happen if undo again.
740 ASSERT_NO_FATAL_FAILURE(SendKey(app::VKEY_Z, true, false, false));
741 EXPECT_TRUE(edit_view->GetText().empty());
742
743 // Redo should restore the original text.
744 ASSERT_NO_FATAL_FAILURE(SendKey(app::VKEY_Z, true, true, false));
745 EXPECT_EQ(old_text, edit_view->GetText());
746
747 // Looks like the undo manager doesn't support restoring selection.
748 EXPECT_FALSE(edit_view->IsSelectAll());
749
750 // The cursor should be at the end.
751 std::wstring::size_type start, end;
752 edit_view->GetSelectionBounds(&start, &end);
753 EXPECT_EQ(old_text.size(), start);
754 EXPECT_EQ(old_text.size(), end);
755
756 // Delete two characters.
757 ASSERT_NO_FATAL_FAILURE(SendKey(app::VKEY_BACK, false, false, false));
758 ASSERT_NO_FATAL_FAILURE(SendKey(app::VKEY_BACK, false, false, false));
759 EXPECT_EQ(old_text.substr(0, old_text.size() - 2), edit_view->GetText());
760
761 // Undo delete.
762 ASSERT_NO_FATAL_FAILURE(SendKey(app::VKEY_Z, true, false, false));
763 EXPECT_EQ(old_text, edit_view->GetText());
764
765 // Redo delete.
766 ASSERT_NO_FATAL_FAILURE(SendKey(app::VKEY_Z, true, true, false));
767 EXPECT_EQ(old_text.substr(0, old_text.size() - 2), edit_view->GetText());
768
769 // Delete everything.
770 edit_view->SelectAll(true);
771 ASSERT_NO_FATAL_FAILURE(SendKey(app::VKEY_BACK, false, false, false));
772 EXPECT_TRUE(edit_view->GetText().empty());
773
774 // Undo delete everything.
775 ASSERT_NO_FATAL_FAILURE(SendKey(app::VKEY_Z, true, false, false));
776 EXPECT_EQ(old_text.substr(0, old_text.size() - 2), edit_view->GetText());
777
778 // Undo delete two characters.
779 ASSERT_NO_FATAL_FAILURE(SendKey(app::VKEY_Z, true, false, false));
780 EXPECT_EQ(old_text, edit_view->GetText());
781
782 // Undo again.
783 ASSERT_NO_FATAL_FAILURE(SendKey(app::VKEY_Z, true, false, false));
784 EXPECT_TRUE(edit_view->GetText().empty());
785 }
786 #endif
OLDNEW
« no previous file with comments | « no previous file | chrome/browser/autocomplete/autocomplete_edit_view_gtk.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698