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

Side by Side Diff: components/autofill/browser/autofill_external_delegate_unittest.cc

Issue 15769018: [Autofill] Determine Popup RTLness from page (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Responding to comments Created 7 years, 6 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
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 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
45 45
46 private: 46 private:
47 DISALLOW_COPY_AND_ASSIGN(MockAutofillExternalDelegate); 47 DISALLOW_COPY_AND_ASSIGN(MockAutofillExternalDelegate);
48 }; 48 };
49 49
50 class MockAutofillManagerDelegate 50 class MockAutofillManagerDelegate
51 : public autofill::TestAutofillManagerDelegate { 51 : public autofill::TestAutofillManagerDelegate {
52 public: 52 public:
53 MockAutofillManagerDelegate() {} 53 MockAutofillManagerDelegate() {}
54 54
55 MOCK_METHOD6(ShowAutofillPopup, 55 MOCK_METHOD7(ShowAutofillPopup,
56 void(const gfx::RectF& element_bounds, 56 void(const gfx::RectF& element_bounds,
57 base::i18n::TextDirection text_direction,
57 const std::vector<base::string16>& values, 58 const std::vector<base::string16>& values,
58 const std::vector<base::string16>& labels, 59 const std::vector<base::string16>& labels,
59 const std::vector<base::string16>& icons, 60 const std::vector<base::string16>& icons,
60 const std::vector<int>& identifiers, 61 const std::vector<int>& identifiers,
61 base::WeakPtr<AutofillPopupDelegate> delegate)); 62 base::WeakPtr<AutofillPopupDelegate> delegate));
62 63
63 MOCK_METHOD0(HideAutofillPopup, void()); 64 MOCK_METHOD0(HideAutofillPopup, void());
64 65
65 private: 66 private:
66 DISALLOW_COPY_AND_ASSIGN(MockAutofillManagerDelegate); 67 DISALLOW_COPY_AND_ASSIGN(MockAutofillManagerDelegate);
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after
128 external_delegate_; 129 external_delegate_;
129 }; 130 };
130 131
131 // Test that our external delegate called the virtual methods at the right time. 132 // Test that our external delegate called the virtual methods at the right time.
132 TEST_F(AutofillExternalDelegateUnitTest, TestExternalDelegateVirtualCalls) { 133 TEST_F(AutofillExternalDelegateUnitTest, TestExternalDelegateVirtualCalls) {
133 IssueOnQuery(kQueryId); 134 IssueOnQuery(kQueryId);
134 135
135 // The enums must be cast to ints to prevent compile errors on linux_rel. 136 // The enums must be cast to ints to prevent compile errors on linux_rel.
136 EXPECT_CALL(manager_delegate_, 137 EXPECT_CALL(manager_delegate_,
137 ShowAutofillPopup( 138 ShowAutofillPopup(
138 _, _, _, _, 139 _, _, _, _, _,
139 testing::ElementsAre( 140 testing::ElementsAre(
140 kAutofillProfileId, 141 kAutofillProfileId,
141 static_cast<int>(WebAutofillClient::MenuItemIDSeparator), 142 static_cast<int>(WebAutofillClient::MenuItemIDSeparator),
142 static_cast<int>( 143 static_cast<int>(
143 WebAutofillClient::MenuItemIDAutofillOptions)), 144 WebAutofillClient::MenuItemIDAutofillOptions)),
144 _)); 145 _));
145 146
146 // This should call ShowAutofillPopup. 147 // This should call ShowAutofillPopup.
147 std::vector<base::string16> autofill_item; 148 std::vector<base::string16> autofill_item;
148 autofill_item.push_back(base::string16()); 149 autofill_item.push_back(base::string16());
(...skipping 25 matching lines...) Expand all
174 data_list_ids.push_back(WebAutofillClient::MenuItemIDDataListEntry); 175 data_list_ids.push_back(WebAutofillClient::MenuItemIDDataListEntry);
175 176
176 external_delegate_->SetCurrentDataListValues(data_list_items, 177 external_delegate_->SetCurrentDataListValues(data_list_items,
177 data_list_items, 178 data_list_items,
178 data_list_items, 179 data_list_items,
179 data_list_ids); 180 data_list_ids);
180 181
181 // The enums must be cast to ints to prevent compile errors on linux_rel. 182 // The enums must be cast to ints to prevent compile errors on linux_rel.
182 EXPECT_CALL(manager_delegate_, 183 EXPECT_CALL(manager_delegate_,
183 ShowAutofillPopup( 184 ShowAutofillPopup(
184 _, _, _, _, 185 _, _, _, _, _,
185 testing::ElementsAre( 186 testing::ElementsAre(
186 static_cast<int>( 187 static_cast<int>(
187 WebAutofillClient::MenuItemIDDataListEntry), 188 WebAutofillClient::MenuItemIDDataListEntry),
188 static_cast<int>(WebAutofillClient::MenuItemIDSeparator), 189 static_cast<int>(WebAutofillClient::MenuItemIDSeparator),
189 kAutofillProfileId, 190 kAutofillProfileId,
190 static_cast<int>(WebAutofillClient::MenuItemIDSeparator), 191 static_cast<int>(WebAutofillClient::MenuItemIDSeparator),
191 static_cast<int>( 192 static_cast<int>(
192 WebAutofillClient::MenuItemIDAutofillOptions)), 193 WebAutofillClient::MenuItemIDAutofillOptions)),
193 _)); 194 _));
194 195
195 // This should call ShowAutofillPopup. 196 // This should call ShowAutofillPopup.
196 std::vector<base::string16> autofill_item; 197 std::vector<base::string16> autofill_item;
197 autofill_item.push_back(base::string16()); 198 autofill_item.push_back(base::string16());
198 std::vector<int> autofill_ids; 199 std::vector<int> autofill_ids;
199 autofill_ids.push_back(kAutofillProfileId); 200 autofill_ids.push_back(kAutofillProfileId);
200 external_delegate_->OnSuggestionsReturned(kQueryId, 201 external_delegate_->OnSuggestionsReturned(kQueryId,
201 autofill_item, 202 autofill_item,
202 autofill_item, 203 autofill_item,
203 autofill_item, 204 autofill_item,
204 autofill_ids); 205 autofill_ids);
205 206
206 // Try calling OnSuggestionsReturned with no Autofill values and ensure 207 // Try calling OnSuggestionsReturned with no Autofill values and ensure
207 // the datalist items are still shown. 208 // the datalist items are still shown.
208 // The enum must be cast to an int to prevent compile errors on linux_rel. 209 // The enum must be cast to an int to prevent compile errors on linux_rel.
209 EXPECT_CALL(manager_delegate_, 210 EXPECT_CALL(manager_delegate_,
210 ShowAutofillPopup( 211 ShowAutofillPopup(
211 _, _, _, _, 212 _, _, _, _, _,
212 testing::ElementsAre( 213 testing::ElementsAre(
213 static_cast<int>( 214 static_cast<int>(
214 WebAutofillClient::MenuItemIDDataListEntry)), 215 WebAutofillClient::MenuItemIDDataListEntry)),
215 _)); 216 _));
216 217
217 autofill_item = std::vector<base::string16>(); 218 autofill_item = std::vector<base::string16>();
218 autofill_ids = std::vector<int>(); 219 autofill_ids = std::vector<int>();
219 external_delegate_->OnSuggestionsReturned(kQueryId, 220 external_delegate_->OnSuggestionsReturned(kQueryId,
220 autofill_item, 221 autofill_item,
221 autofill_item, 222 autofill_item,
(...skipping 27 matching lines...) Expand all
249 external_delegate_->DidSelectSuggestion( 250 external_delegate_->DidSelectSuggestion(
250 WebAutofillClient::MenuItemIDPasswordEntry); 251 WebAutofillClient::MenuItemIDPasswordEntry);
251 252
252 EXPECT_CALL(*external_delegate_, ClearPreviewedForm()).Times(1); 253 EXPECT_CALL(*external_delegate_, ClearPreviewedForm()).Times(1);
253 external_delegate_->DidSelectSuggestion(1); 254 external_delegate_->DidSelectSuggestion(1);
254 } 255 }
255 256
256 // Test that the popup is hidden once we are done editing the autofill field. 257 // Test that the popup is hidden once we are done editing the autofill field.
257 TEST_F(AutofillExternalDelegateUnitTest, 258 TEST_F(AutofillExternalDelegateUnitTest,
258 ExternalDelegateHidePopupAfterEditing) { 259 ExternalDelegateHidePopupAfterEditing) {
259 EXPECT_CALL(manager_delegate_, ShowAutofillPopup(_, _, _, _, _, _)); 260 EXPECT_CALL(manager_delegate_, ShowAutofillPopup(_, _, _, _, _, _, _));
260 autofill::GenerateTestAutofillPopup(external_delegate_.get()); 261 autofill::GenerateTestAutofillPopup(external_delegate_.get());
261 262
262 EXPECT_CALL(manager_delegate_, HideAutofillPopup()); 263 EXPECT_CALL(manager_delegate_, HideAutofillPopup());
263 external_delegate_->DidEndTextFieldEditing(); 264 external_delegate_->DidEndTextFieldEditing();
264 } 265 }
265 266
266 // Test that the popup is marked as visible after recieving password 267 // Test that the popup is marked as visible after recieving password
267 // suggestions. 268 // suggestions.
268 TEST_F(AutofillExternalDelegateUnitTest, ExternalDelegatePasswordSuggestions) { 269 TEST_F(AutofillExternalDelegateUnitTest, ExternalDelegatePasswordSuggestions) {
269 static const base::string16 kUsername = ASCIIToUTF16("username"); 270 static const base::string16 kUsername = ASCIIToUTF16("username");
270 std::vector<base::string16> suggestions; 271 std::vector<base::string16> suggestions;
271 suggestions.push_back(kUsername); 272 suggestions.push_back(kUsername);
272 273
273 FormFieldData field; 274 FormFieldData field;
274 field.is_focusable = true; 275 field.is_focusable = true;
275 field.should_autocomplete = true; 276 field.should_autocomplete = true;
276 const gfx::RectF element_bounds; 277 const gfx::RectF element_bounds;
277 278
278 FormFieldData username_field_data; 279 FormFieldData username_field_data;
279 username_field_data.value = kUsername; 280 username_field_data.value = kUsername;
280 PasswordFormFillData password_form_fill_data; 281 PasswordFormFillData password_form_fill_data;
281 password_form_fill_data.basic_data.fields.push_back(username_field_data); 282 password_form_fill_data.basic_data.fields.push_back(username_field_data);
282 external_delegate_->AddPasswordFormMapping(field, password_form_fill_data); 283 external_delegate_->AddPasswordFormMapping(field, password_form_fill_data);
283 284
284 // The enums must be cast to ints to prevent compile errors on linux_rel. 285 // The enums must be cast to ints to prevent compile errors on linux_rel.
285 EXPECT_CALL(manager_delegate_, 286 EXPECT_CALL(manager_delegate_,
286 ShowAutofillPopup( 287 ShowAutofillPopup(
287 _, _, _, _, 288 _, _, _, _, _,
288 testing::ElementsAre( 289 testing::ElementsAre(
289 static_cast<int>( 290 static_cast<int>(
290 WebAutofillClient::MenuItemIDPasswordEntry)), 291 WebAutofillClient::MenuItemIDPasswordEntry)),
291 _)); 292 _));
292 293
293 external_delegate_->OnShowPasswordSuggestions(suggestions, 294 external_delegate_->OnShowPasswordSuggestions(suggestions,
294 field, 295 field,
295 element_bounds); 296 element_bounds);
296 297
297 EXPECT_CALL(manager_delegate_, HideAutofillPopup()); 298 EXPECT_CALL(manager_delegate_, HideAutofillPopup());
(...skipping 25 matching lines...) Expand all
323 EXPECT_CALL(manager_delegate_, HideAutofillPopup()); 324 EXPECT_CALL(manager_delegate_, HideAutofillPopup());
324 325
325 external_delegate_->OnSuggestionsReturned(kQueryId, 326 external_delegate_->OnSuggestionsReturned(kQueryId,
326 autofill_items, 327 autofill_items,
327 autofill_items, 328 autofill_items,
328 autofill_items, 329 autofill_items,
329 autofill_ids); 330 autofill_ids);
330 } 331 }
331 332
332 } // namespace autofill 333 } // namespace autofill
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698