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/compiler_specific.h" | 7 #include "base/compiler_specific.h" |
8 #include "base/memory/ref_counted.h" | 8 #include "base/memory/ref_counted.h" |
9 #include "base/string16.h" | 9 #include "base/string16.h" |
10 #include "chrome/browser/autofill/autofill_manager.h" | 10 #include "chrome/browser/autofill/autofill_manager.h" |
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
81 | 81 |
82 virtual void SetUp() OVERRIDE { | 82 virtual void SetUp() OVERRIDE { |
83 TabContentsWrapperTestHarness::SetUp(); | 83 TabContentsWrapperTestHarness::SetUp(); |
84 autofill_manager_ = new MockAutofillManager(contents_wrapper()); | 84 autofill_manager_ = new MockAutofillManager(contents_wrapper()); |
85 external_delegate_.reset(new MockAutofillExternalDelegate( | 85 external_delegate_.reset(new MockAutofillExternalDelegate( |
86 contents_wrapper(), | 86 contents_wrapper(), |
87 autofill_manager_)); | 87 autofill_manager_)); |
88 } | 88 } |
89 | 89 |
90 protected: | 90 protected: |
| 91 // Setup the expectation for a platform specific OnQuery call and then execute |
| 92 // it with the given QueryId. |
| 93 void SetupOnQuery(int query_id) { |
| 94 const FormData form; |
| 95 FormField field; |
| 96 field.is_focusable = true; |
| 97 field.should_autocomplete = true; |
| 98 const gfx::Rect bounds; |
| 99 |
| 100 EXPECT_CALL(*external_delegate_, |
| 101 OnQueryPlatformSpecific(query_id, form, field, bounds)); |
| 102 |
| 103 // This should call OnQueryPlatform specific. |
| 104 external_delegate_->OnQuery(query_id, form, field, bounds, false); |
| 105 } |
| 106 |
91 scoped_refptr<MockAutofillManager> autofill_manager_; | 107 scoped_refptr<MockAutofillManager> autofill_manager_; |
92 scoped_ptr<MockAutofillExternalDelegate> external_delegate_; | 108 scoped_ptr<MockAutofillExternalDelegate> external_delegate_; |
93 | 109 |
94 private: | 110 private: |
95 content::TestBrowserThread ui_thread_; | 111 content::TestBrowserThread ui_thread_; |
96 | 112 |
97 DISALLOW_COPY_AND_ASSIGN(AutofillExternalDelegateUnitTest); | 113 DISALLOW_COPY_AND_ASSIGN(AutofillExternalDelegateUnitTest); |
98 }; | 114 }; |
99 | 115 |
100 // Test that our external delegate called the virtual methods at the right time. | 116 // Test that our external delegate called the virtual methods at the right time. |
101 TEST_F(AutofillExternalDelegateUnitTest, TestExternalDelegateVirtualCalls) { | 117 TEST_F(AutofillExternalDelegateUnitTest, TestExternalDelegateVirtualCalls) { |
102 const int kQueryId = 5; | 118 const int kQueryId = 5; |
103 const FormData form; | 119 SetupOnQuery(kQueryId); |
104 FormField field; | |
105 field.is_focusable = true; | |
106 field.should_autocomplete = true; | |
107 const gfx::Rect bounds; | |
108 | |
109 EXPECT_CALL(*external_delegate_, | |
110 OnQueryPlatformSpecific(kQueryId, form, field, bounds)); | |
111 | |
112 // This should call OnQueryPlatform specific. | |
113 external_delegate_->OnQuery(kQueryId, form, field, bounds, false); | |
114 | 120 |
115 EXPECT_CALL(*external_delegate_, ApplyAutofillSuggestions(_, _, _, _)); | 121 EXPECT_CALL(*external_delegate_, ApplyAutofillSuggestions(_, _, _, _)); |
116 | 122 |
117 // This should call ApplyAutofillSuggestions. | 123 // This should call ApplyAutofillSuggestions. |
118 std::vector<string16> autofill_item; | 124 std::vector<string16> autofill_item; |
119 autofill_item.push_back(string16()); | 125 autofill_item.push_back(string16()); |
120 std::vector<int> autofill_ids; | 126 std::vector<int> autofill_ids; |
121 autofill_ids.push_back(1); | 127 autofill_ids.push_back(1); |
122 external_delegate_->OnSuggestionsReturned(kQueryId, | 128 external_delegate_->OnSuggestionsReturned(kQueryId, |
123 autofill_item, | 129 autofill_item, |
124 autofill_item, | 130 autofill_item, |
125 autofill_item, | 131 autofill_item, |
126 autofill_ids); | 132 autofill_ids); |
127 | 133 |
128 | 134 |
129 EXPECT_CALL(*external_delegate_, HideAutofillPopup()); | 135 EXPECT_CALL(*external_delegate_, HideAutofillPopup()); |
130 | 136 |
131 // Called by DidAutofillSuggestions, add expectation to remove warning. | 137 // Called by DidAutofillSuggestions, add expectation to remove warning. |
132 EXPECT_CALL(*autofill_manager_, OnFillAutofillFormData(_, _, _, _)); | 138 EXPECT_CALL(*autofill_manager_, OnFillAutofillFormData(_, _, _, _)); |
133 | 139 |
134 // This should trigger a call to hide the popup since | 140 // This should trigger a call to hide the popup since |
135 // we've selected an option. | 141 // we've selected an option. |
136 external_delegate_->DidAcceptAutofillSuggestions(autofill_item[0], | 142 external_delegate_->DidAcceptAutofillSuggestions(autofill_item[0], |
137 autofill_ids[0], 0); | 143 autofill_ids[0], 0); |
138 } | 144 } |
139 | 145 |
| 146 // Test that data list elements for a node will appear in the Autofill popup. |
| 147 TEST_F(AutofillExternalDelegateUnitTest, ExternalDelegateDataList) { |
| 148 const int kQueryId = 5; |
| 149 SetupOnQuery(kQueryId); |
| 150 |
| 151 std::vector<string16> data_list_items; |
| 152 data_list_items.push_back(string16()); |
| 153 std::vector<int> data_list_ids; |
| 154 data_list_ids.push_back(WebAutofillClient::MenuItemIDDataListEntry); |
| 155 |
| 156 external_delegate_->SetCurrentDataListValues(data_list_items, |
| 157 data_list_items, |
| 158 data_list_items, |
| 159 data_list_ids); |
| 160 |
| 161 EXPECT_CALL(*external_delegate_, |
| 162 ApplyAutofillSuggestions( |
| 163 _, _, _, testing::Contains( |
| 164 WebAutofillClient::MenuItemIDDataListEntry))); |
| 165 |
| 166 // This should call ApplyAutofillSuggestions. |
| 167 std::vector<string16> autofill_item; |
| 168 autofill_item.push_back(string16()); |
| 169 std::vector<int> autofill_ids; |
| 170 autofill_ids.push_back(1); |
| 171 external_delegate_->OnSuggestionsReturned(kQueryId, |
| 172 autofill_item, |
| 173 autofill_item, |
| 174 autofill_item, |
| 175 autofill_ids); |
| 176 } |
| 177 |
140 // Test that the Autofill delegate doesn't try and fill a form with a | 178 // Test that the Autofill delegate doesn't try and fill a form with a |
141 // negative unique id. | 179 // negative unique id. |
142 TEST_F(AutofillExternalDelegateUnitTest, ExternalDelegateInvalidUniqueId) { | 180 TEST_F(AutofillExternalDelegateUnitTest, ExternalDelegateInvalidUniqueId) { |
143 // Ensure it doesn't try to preview the negative id. | 181 // Ensure it doesn't try to preview the negative id. |
144 EXPECT_CALL(*autofill_manager_, OnFillAutofillFormData(_, _, _, _)).Times(0); | 182 EXPECT_CALL(*autofill_manager_, OnFillAutofillFormData(_, _, _, _)).Times(0); |
145 external_delegate_->SelectAutofillSuggestionAtIndex(-1); | 183 external_delegate_->SelectAutofillSuggestionAtIndex(-1); |
146 | 184 |
147 // Ensure it doesn't try to fill the form in with the negative id. | 185 // Ensure it doesn't try to fill the form in with the negative id. |
148 EXPECT_CALL(*autofill_manager_, OnFillAutofillFormData(_, _, _, _)).Times(0); | 186 EXPECT_CALL(*autofill_manager_, OnFillAutofillFormData(_, _, _, _)).Times(0); |
149 external_delegate_->DidAcceptAutofillSuggestions(string16(), -1, 0); | 187 external_delegate_->DidAcceptAutofillSuggestions(string16(), -1, 0); |
(...skipping 16 matching lines...) Expand all Loading... |
166 external_delegate_->SelectAutofillSuggestionAtIndex(1); | 204 external_delegate_->SelectAutofillSuggestionAtIndex(1); |
167 } | 205 } |
168 | 206 |
169 // Test that the popup is hidden once we are done editing the autofill field. | 207 // Test that the popup is hidden once we are done editing the autofill field. |
170 TEST_F(AutofillExternalDelegateUnitTest, | 208 TEST_F(AutofillExternalDelegateUnitTest, |
171 ExternalDelegateHidePopupAfterEditing) { | 209 ExternalDelegateHidePopupAfterEditing) { |
172 EXPECT_CALL(*external_delegate_, HideAutofillPopup()); | 210 EXPECT_CALL(*external_delegate_, HideAutofillPopup()); |
173 | 211 |
174 external_delegate_->DidEndTextFieldEditing(); | 212 external_delegate_->DidEndTextFieldEditing(); |
175 } | 213 } |
OLD | NEW |