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

Side by Side Diff: chrome/browser/autofill/autofill_popup_unittest.cc

Issue 9432029: GTK Keyboard Support for New Autofill (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: Using keyboard listener to get keypresses Created 8 years, 9 months 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
OLDNEW
(Empty)
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
3 // found in the LICENSE file.
4
5 #include "chrome/browser/autofill/autofill_popup_view.h"
6
7 #include "base/memory/scoped_ptr.h"
8 #include "chrome/browser/autofill/test_autofill_external_delegate.h"
9 #include "testing/gtest/include/gtest/gtest.h"
10 #include "testing/gmock/include/gmock/gmock.h"
11
12 namespace {
13
14 class MockAutofillExternalDelegate : public TestAutofillExternalDelegate {
15 public:
16 MockAutofillExternalDelegate() : TestAutofillExternalDelegate(NULL, NULL) {};
17 virtual ~MockAutofillExternalDelegate() {};
18
19 virtual void SelectAutofillSuggestionAtIndex(int unique_id, int list_index)
20 OVERRIDE {}
21 };
22
23 class TestAutofillPopupView : public AutofillPopupView {
24 public:
25 explicit TestAutofillPopupView(AutofillExternalDelegate* external_delegate) :
26 AutofillPopupView(NULL, external_delegate) {
27 std::vector<string16> autofill_values;
28 autofill_values.push_back(string16());
29 autofill_values.push_back(string16());
30
31 std::vector<int> autofill_ids;
32 autofill_ids.push_back(0);
33 autofill_ids.push_back(1);
34
35 Show(autofill_values, autofill_values, autofill_values, autofill_ids, 0);
36 }
37 virtual ~TestAutofillPopupView() {}
38
39 // Making protected functions public for testing
40 const std::vector<string16>& autofill_values() const {
41 return AutofillPopupView::autofill_values();
42 }
43 int selected_line() const {
44 return AutofillPopupView::selected_line();
45 }
46 void SetSelectedLine(size_t selected_line) {
47 AutofillPopupView::SetSelectedLine(selected_line);
48 }
49 void IncreaseSelectedLine() {
50 AutofillPopupView::IncreaseSelectedLine();
51 }
52 void DecreaseSelectedLine() {
53 AutofillPopupView::DecreaseSelectedLine();
54 }
55
56 MOCK_METHOD1(InvalidateRow, void(size_t));
57
58 private:
59 virtual void ShowInternal() OVERRIDE {}
60 virtual void HideInternal() OVERRIDE {}
61 virtual void UpdatePopupSize() OVERRIDE {}
62 };
63
64 } // namespace
65
66 class AutofillPopupViewUnitTest : public ::testing::Test {
67 public:
68 AutofillPopupViewUnitTest() {
69 autofill_popup_view_.reset(new TestAutofillPopupView(&external_delegate_));
70 }
71 virtual ~AutofillPopupViewUnitTest() {}
72
73 scoped_ptr<TestAutofillPopupView> autofill_popup_view_;
74
75 private:
76 MockAutofillExternalDelegate external_delegate_;
77 };
78
79 TEST_F(AutofillPopupViewUnitTest, ChangeSelectedLine) {
80 EXPECT_EQ(-1, autofill_popup_view_->selected_line());
81 EXPECT_EQ(2,
82 static_cast<int>(autofill_popup_view_->autofill_values().size()));
83
84 // Test wrapping before the front.
85 autofill_popup_view_->DecreaseSelectedLine();
86 EXPECT_EQ(static_cast<int>(autofill_popup_view_->autofill_values().size() -1),
87 autofill_popup_view_->selected_line());
88
89 // Test wrapping after the end.
90 autofill_popup_view_->IncreaseSelectedLine();
91 EXPECT_EQ(-1, autofill_popup_view_->selected_line());
92 }
93
94 TEST_F(AutofillPopupViewUnitTest, RedrawSelectedLine) {
95 // Make sure that when a new line is selected, it is invalidated so it can
96 // be updated to show it is selected.
97 int selected_line = 0;
98 EXPECT_CALL(*autofill_popup_view_, InvalidateRow(selected_line));
99 autofill_popup_view_->SetSelectedLine(selected_line);
100
101 // Ensure that the row isn't invalidated if it didn't change.
102 EXPECT_CALL(*autofill_popup_view_, InvalidateRow(selected_line)).Times(0);
103 autofill_popup_view_->SetSelectedLine(selected_line);
104
105 // Change back to no selection.
106 EXPECT_CALL(*autofill_popup_view_, InvalidateRow(selected_line));
107 autofill_popup_view_->SetSelectedLine(-1);
108 }
OLDNEW
« no previous file with comments | « no previous file | chrome/browser/autofill/autofill_popup_view.h » ('j') | chrome/browser/autofill/autofill_popup_view.h » ('J')

Powered by Google App Engine
This is Rietveld 408576698