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/string16.h" | 8 #include "base/string16.h" |
9 #include "base/strings/utf_string_conversions.h" | 9 #include "base/strings/utf_string_conversions.h" |
10 #include "chrome/test/base/chrome_render_view_host_test_harness.h" | 10 #include "chrome/test/base/chrome_render_view_host_test_harness.h" |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
47 | 47 |
48 private: | 48 private: |
49 DISALLOW_COPY_AND_ASSIGN(MockAutofillExternalDelegate); | 49 DISALLOW_COPY_AND_ASSIGN(MockAutofillExternalDelegate); |
50 }; | 50 }; |
51 | 51 |
52 class MockAutofillManagerDelegate | 52 class MockAutofillManagerDelegate |
53 : public autofill::TestAutofillManagerDelegate { | 53 : public autofill::TestAutofillManagerDelegate { |
54 public: | 54 public: |
55 MockAutofillManagerDelegate() {} | 55 MockAutofillManagerDelegate() {} |
56 | 56 |
57 MOCK_METHOD6(ShowAutofillPopup, | 57 MOCK_METHOD7(ShowAutofillPopup, |
58 void(const gfx::RectF& element_bounds, | 58 void(const gfx::RectF& element_bounds, |
| 59 bool is_rtl, |
59 const std::vector<base::string16>& values, | 60 const std::vector<base::string16>& values, |
60 const std::vector<base::string16>& labels, | 61 const std::vector<base::string16>& labels, |
61 const std::vector<base::string16>& icons, | 62 const std::vector<base::string16>& icons, |
62 const std::vector<int>& identifiers, | 63 const std::vector<int>& identifiers, |
63 base::WeakPtr<AutofillPopupDelegate> delegate)); | 64 base::WeakPtr<AutofillPopupDelegate> delegate)); |
64 | 65 |
65 MOCK_METHOD0(HideAutofillPopup, void()); | 66 MOCK_METHOD0(HideAutofillPopup, void()); |
66 | 67 |
67 private: | 68 private: |
68 DISALLOW_COPY_AND_ASSIGN(MockAutofillManagerDelegate); | 69 DISALLOW_COPY_AND_ASSIGN(MockAutofillManagerDelegate); |
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
140 DISALLOW_COPY_AND_ASSIGN(AutofillExternalDelegateUnitTest); | 141 DISALLOW_COPY_AND_ASSIGN(AutofillExternalDelegateUnitTest); |
141 }; | 142 }; |
142 | 143 |
143 // Test that our external delegate called the virtual methods at the right time. | 144 // Test that our external delegate called the virtual methods at the right time. |
144 TEST_F(AutofillExternalDelegateUnitTest, TestExternalDelegateVirtualCalls) { | 145 TEST_F(AutofillExternalDelegateUnitTest, TestExternalDelegateVirtualCalls) { |
145 IssueOnQuery(kQueryId); | 146 IssueOnQuery(kQueryId); |
146 | 147 |
147 // The enums must be cast to ints to prevent compile errors on linux_rel. | 148 // The enums must be cast to ints to prevent compile errors on linux_rel. |
148 EXPECT_CALL(manager_delegate_, | 149 EXPECT_CALL(manager_delegate_, |
149 ShowAutofillPopup( | 150 ShowAutofillPopup( |
150 _, _, _, _, | 151 _, _, _, _, _, |
151 testing::ElementsAre( | 152 testing::ElementsAre( |
152 kAutofillProfileId, | 153 kAutofillProfileId, |
153 static_cast<int>(WebAutofillClient::MenuItemIDSeparator), | 154 static_cast<int>(WebAutofillClient::MenuItemIDSeparator), |
154 static_cast<int>( | 155 static_cast<int>( |
155 WebAutofillClient::MenuItemIDAutofillOptions)), | 156 WebAutofillClient::MenuItemIDAutofillOptions)), |
156 _)); | 157 _)); |
157 | 158 |
158 // This should call ShowAutofillPopup. | 159 // This should call ShowAutofillPopup. |
159 std::vector<base::string16> autofill_item; | 160 std::vector<base::string16> autofill_item; |
160 autofill_item.push_back(base::string16()); | 161 autofill_item.push_back(base::string16()); |
(...skipping 25 matching lines...) Expand all Loading... |
186 data_list_ids.push_back(WebAutofillClient::MenuItemIDDataListEntry); | 187 data_list_ids.push_back(WebAutofillClient::MenuItemIDDataListEntry); |
187 | 188 |
188 external_delegate_->SetCurrentDataListValues(data_list_items, | 189 external_delegate_->SetCurrentDataListValues(data_list_items, |
189 data_list_items, | 190 data_list_items, |
190 data_list_items, | 191 data_list_items, |
191 data_list_ids); | 192 data_list_ids); |
192 | 193 |
193 // The enums must be cast to ints to prevent compile errors on linux_rel. | 194 // The enums must be cast to ints to prevent compile errors on linux_rel. |
194 EXPECT_CALL(manager_delegate_, | 195 EXPECT_CALL(manager_delegate_, |
195 ShowAutofillPopup( | 196 ShowAutofillPopup( |
196 _, _, _, _, | 197 _, _, _, _, _, |
197 testing::ElementsAre( | 198 testing::ElementsAre( |
198 static_cast<int>( | 199 static_cast<int>( |
199 WebAutofillClient::MenuItemIDDataListEntry), | 200 WebAutofillClient::MenuItemIDDataListEntry), |
200 static_cast<int>(WebAutofillClient::MenuItemIDSeparator), | 201 static_cast<int>(WebAutofillClient::MenuItemIDSeparator), |
201 kAutofillProfileId, | 202 kAutofillProfileId, |
202 static_cast<int>(WebAutofillClient::MenuItemIDSeparator), | 203 static_cast<int>(WebAutofillClient::MenuItemIDSeparator), |
203 static_cast<int>( | 204 static_cast<int>( |
204 WebAutofillClient::MenuItemIDAutofillOptions)), | 205 WebAutofillClient::MenuItemIDAutofillOptions)), |
205 _)); | 206 _)); |
206 | 207 |
207 // This should call ShowAutofillPopup. | 208 // This should call ShowAutofillPopup. |
208 std::vector<base::string16> autofill_item; | 209 std::vector<base::string16> autofill_item; |
209 autofill_item.push_back(base::string16()); | 210 autofill_item.push_back(base::string16()); |
210 std::vector<int> autofill_ids; | 211 std::vector<int> autofill_ids; |
211 autofill_ids.push_back(kAutofillProfileId); | 212 autofill_ids.push_back(kAutofillProfileId); |
212 external_delegate_->OnSuggestionsReturned(kQueryId, | 213 external_delegate_->OnSuggestionsReturned(kQueryId, |
213 autofill_item, | 214 autofill_item, |
214 autofill_item, | 215 autofill_item, |
215 autofill_item, | 216 autofill_item, |
216 autofill_ids); | 217 autofill_ids); |
217 | 218 |
218 // Try calling OnSuggestionsReturned with no Autofill values and ensure | 219 // Try calling OnSuggestionsReturned with no Autofill values and ensure |
219 // the datalist items are still shown. | 220 // the datalist items are still shown. |
220 // The enum must be cast to an int to prevent compile errors on linux_rel. | 221 // The enum must be cast to an int to prevent compile errors on linux_rel. |
221 EXPECT_CALL(manager_delegate_, | 222 EXPECT_CALL(manager_delegate_, |
222 ShowAutofillPopup( | 223 ShowAutofillPopup( |
223 _, _, _, _, | 224 _, _, _, _, _, |
224 testing::ElementsAre( | 225 testing::ElementsAre( |
225 static_cast<int>( | 226 static_cast<int>( |
226 WebAutofillClient::MenuItemIDDataListEntry)), | 227 WebAutofillClient::MenuItemIDDataListEntry)), |
227 _)); | 228 _)); |
228 | 229 |
229 autofill_item = std::vector<base::string16>(); | 230 autofill_item = std::vector<base::string16>(); |
230 autofill_ids = std::vector<int>(); | 231 autofill_ids = std::vector<int>(); |
231 external_delegate_->OnSuggestionsReturned(kQueryId, | 232 external_delegate_->OnSuggestionsReturned(kQueryId, |
232 autofill_item, | 233 autofill_item, |
233 autofill_item, | 234 autofill_item, |
(...skipping 27 matching lines...) Expand all Loading... |
261 external_delegate_->DidSelectSuggestion( | 262 external_delegate_->DidSelectSuggestion( |
262 WebAutofillClient::MenuItemIDPasswordEntry); | 263 WebAutofillClient::MenuItemIDPasswordEntry); |
263 | 264 |
264 EXPECT_CALL(*external_delegate_, ClearPreviewedForm()).Times(1); | 265 EXPECT_CALL(*external_delegate_, ClearPreviewedForm()).Times(1); |
265 external_delegate_->DidSelectSuggestion(1); | 266 external_delegate_->DidSelectSuggestion(1); |
266 } | 267 } |
267 | 268 |
268 // Test that the popup is hidden once we are done editing the autofill field. | 269 // Test that the popup is hidden once we are done editing the autofill field. |
269 TEST_F(AutofillExternalDelegateUnitTest, | 270 TEST_F(AutofillExternalDelegateUnitTest, |
270 ExternalDelegateHidePopupAfterEditing) { | 271 ExternalDelegateHidePopupAfterEditing) { |
271 EXPECT_CALL(manager_delegate_, ShowAutofillPopup(_, _, _, _, _, _)); | 272 EXPECT_CALL(manager_delegate_, ShowAutofillPopup(_, _, _, _, _, _, _)); |
272 autofill::GenerateTestAutofillPopup(external_delegate_.get()); | 273 autofill::GenerateTestAutofillPopup(external_delegate_.get()); |
273 | 274 |
274 EXPECT_CALL(manager_delegate_, HideAutofillPopup()); | 275 EXPECT_CALL(manager_delegate_, HideAutofillPopup()); |
275 external_delegate_->DidEndTextFieldEditing(); | 276 external_delegate_->DidEndTextFieldEditing(); |
276 } | 277 } |
277 | 278 |
278 // Test that the popup is marked as visible after recieving password | 279 // Test that the popup is marked as visible after recieving password |
279 // suggestions. | 280 // suggestions. |
280 TEST_F(AutofillExternalDelegateUnitTest, ExternalDelegatePasswordSuggestions) { | 281 TEST_F(AutofillExternalDelegateUnitTest, ExternalDelegatePasswordSuggestions) { |
281 static const base::string16 kUsername = ASCIIToUTF16("username"); | 282 static const base::string16 kUsername = ASCIIToUTF16("username"); |
282 std::vector<base::string16> suggestions; | 283 std::vector<base::string16> suggestions; |
283 suggestions.push_back(kUsername); | 284 suggestions.push_back(kUsername); |
284 | 285 |
285 FormFieldData field; | 286 FormFieldData field; |
286 field.is_focusable = true; | 287 field.is_focusable = true; |
287 field.should_autocomplete = true; | 288 field.should_autocomplete = true; |
288 const gfx::RectF element_bounds; | 289 const gfx::RectF element_bounds; |
289 | 290 |
290 FormFieldData username_field_data; | 291 FormFieldData username_field_data; |
291 username_field_data.value = kUsername; | 292 username_field_data.value = kUsername; |
292 PasswordFormFillData password_form_fill_data; | 293 PasswordFormFillData password_form_fill_data; |
293 password_form_fill_data.basic_data.fields.push_back(username_field_data); | 294 password_form_fill_data.basic_data.fields.push_back(username_field_data); |
294 external_delegate_->AddPasswordFormMapping(field, password_form_fill_data); | 295 external_delegate_->AddPasswordFormMapping(field, password_form_fill_data); |
295 | 296 |
296 // The enums must be cast to ints to prevent compile errors on linux_rel. | 297 // The enums must be cast to ints to prevent compile errors on linux_rel. |
297 EXPECT_CALL(manager_delegate_, | 298 EXPECT_CALL(manager_delegate_, |
298 ShowAutofillPopup( | 299 ShowAutofillPopup( |
299 _, _, _, _, | 300 _, _, _, _, _, |
300 testing::ElementsAre( | 301 testing::ElementsAre( |
301 static_cast<int>( | 302 static_cast<int>( |
302 WebAutofillClient::MenuItemIDPasswordEntry)), | 303 WebAutofillClient::MenuItemIDPasswordEntry)), |
303 _)); | 304 _)); |
304 | 305 |
305 external_delegate_->OnShowPasswordSuggestions(suggestions, | 306 external_delegate_->OnShowPasswordSuggestions(suggestions, |
306 field, | 307 field, |
307 element_bounds); | 308 element_bounds); |
308 | 309 |
309 EXPECT_CALL(manager_delegate_, HideAutofillPopup()); | 310 EXPECT_CALL(manager_delegate_, HideAutofillPopup()); |
(...skipping 25 matching lines...) Expand all Loading... |
335 EXPECT_CALL(manager_delegate_, HideAutofillPopup()); | 336 EXPECT_CALL(manager_delegate_, HideAutofillPopup()); |
336 | 337 |
337 external_delegate_->OnSuggestionsReturned(kQueryId, | 338 external_delegate_->OnSuggestionsReturned(kQueryId, |
338 autofill_items, | 339 autofill_items, |
339 autofill_items, | 340 autofill_items, |
340 autofill_items, | 341 autofill_items, |
341 autofill_ids); | 342 autofill_ids); |
342 } | 343 } |
343 | 344 |
344 } // namespace autofill | 345 } // namespace autofill |
OLD | NEW |