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

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

Issue 13973004: Convert string16 -> base::string16 in components/ (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 7 years, 8 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 | Annotate | Revision Log
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 "chrome/test/base/chrome_render_view_host_test_harness.h" 9 #include "chrome/test/base/chrome_render_view_host_test_harness.h"
10 #include "chrome/test/base/testing_profile.h" 10 #include "chrome/test/base/testing_profile.h"
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
45 DISALLOW_COPY_AND_ASSIGN(MockAutofillExternalDelegate); 45 DISALLOW_COPY_AND_ASSIGN(MockAutofillExternalDelegate);
46 }; 46 };
47 47
48 class MockAutofillManagerDelegate 48 class MockAutofillManagerDelegate
49 : public autofill::TestAutofillManagerDelegate { 49 : public autofill::TestAutofillManagerDelegate {
50 public: 50 public:
51 MockAutofillManagerDelegate() {} 51 MockAutofillManagerDelegate() {}
52 52
53 MOCK_METHOD6(ShowAutofillPopup, 53 MOCK_METHOD6(ShowAutofillPopup,
54 void(const gfx::RectF& element_bounds, 54 void(const gfx::RectF& element_bounds,
55 const std::vector<string16>& values, 55 const std::vector<base::string16>& values,
56 const std::vector<string16>& labels, 56 const std::vector<base::string16>& labels,
57 const std::vector<string16>& icons, 57 const std::vector<base::string16>& icons,
58 const std::vector<int>& identifiers, 58 const std::vector<int>& identifiers,
59 AutofillPopupDelegate* delegate)); 59 AutofillPopupDelegate* delegate));
60 60
61 MOCK_METHOD0(HideAutofillPopup, void()); 61 MOCK_METHOD0(HideAutofillPopup, void());
62 62
63 private: 63 private:
64 DISALLOW_COPY_AND_ASSIGN(MockAutofillManagerDelegate); 64 DISALLOW_COPY_AND_ASSIGN(MockAutofillManagerDelegate);
65 }; 65 };
66 66
67 class MockAutofillManager : public AutofillManager { 67 class MockAutofillManager : public AutofillManager {
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after
145 ShowAutofillPopup( 145 ShowAutofillPopup(
146 _, _, _, _, 146 _, _, _, _,
147 testing::ElementsAre( 147 testing::ElementsAre(
148 kAutofillProfileId, 148 kAutofillProfileId,
149 static_cast<int>(WebAutofillClient::MenuItemIDSeparator), 149 static_cast<int>(WebAutofillClient::MenuItemIDSeparator),
150 static_cast<int>( 150 static_cast<int>(
151 WebAutofillClient::MenuItemIDAutofillOptions)), 151 WebAutofillClient::MenuItemIDAutofillOptions)),
152 external_delegate_.get())); 152 external_delegate_.get()));
153 153
154 // This should call ShowAutofillPopup. 154 // This should call ShowAutofillPopup.
155 std::vector<string16> autofill_item; 155 std::vector<base::string16> autofill_item;
156 autofill_item.push_back(string16()); 156 autofill_item.push_back(base::string16());
157 std::vector<int> autofill_ids; 157 std::vector<int> autofill_ids;
158 autofill_ids.push_back(kAutofillProfileId); 158 autofill_ids.push_back(kAutofillProfileId);
159 external_delegate_->OnSuggestionsReturned(kQueryId, 159 external_delegate_->OnSuggestionsReturned(kQueryId,
160 autofill_item, 160 autofill_item,
161 autofill_item, 161 autofill_item,
162 autofill_item, 162 autofill_item,
163 autofill_ids); 163 autofill_ids);
164 164
165 // Called by DidAutofillSuggestions, add expectation to remove warning. 165 // Called by DidAutofillSuggestions, add expectation to remove warning.
166 EXPECT_CALL(*autofill_manager_, OnFillAutofillFormData(_, _, _, _)); 166 EXPECT_CALL(*autofill_manager_, OnFillAutofillFormData(_, _, _, _));
167 167
168 EXPECT_CALL(manager_delegate_, HideAutofillPopup()); 168 EXPECT_CALL(manager_delegate_, HideAutofillPopup());
169 169
170 // This should trigger a call to hide the popup since we've selected an 170 // This should trigger a call to hide the popup since we've selected an
171 // option. 171 // option.
172 external_delegate_->DidAcceptSuggestion(autofill_item[0], autofill_ids[0]); 172 external_delegate_->DidAcceptSuggestion(autofill_item[0], autofill_ids[0]);
173 } 173 }
174 174
175 // Test that data list elements for a node will appear in the Autofill popup. 175 // Test that data list elements for a node will appear in the Autofill popup.
176 TEST_F(AutofillExternalDelegateUnitTest, ExternalDelegateDataList) { 176 TEST_F(AutofillExternalDelegateUnitTest, ExternalDelegateDataList) {
177 IssueOnQuery(kQueryId); 177 IssueOnQuery(kQueryId);
178 178
179 std::vector<string16> data_list_items; 179 std::vector<base::string16> data_list_items;
180 data_list_items.push_back(string16()); 180 data_list_items.push_back(base::string16());
181 std::vector<int> data_list_ids; 181 std::vector<int> data_list_ids;
182 data_list_ids.push_back(WebAutofillClient::MenuItemIDDataListEntry); 182 data_list_ids.push_back(WebAutofillClient::MenuItemIDDataListEntry);
183 183
184 external_delegate_->SetCurrentDataListValues(data_list_items, 184 external_delegate_->SetCurrentDataListValues(data_list_items,
185 data_list_items, 185 data_list_items,
186 data_list_items, 186 data_list_items,
187 data_list_ids); 187 data_list_ids);
188 188
189 // The enums must be cast to ints to prevent compile errors on linux_rel. 189 // The enums must be cast to ints to prevent compile errors on linux_rel.
190 EXPECT_CALL(manager_delegate_, 190 EXPECT_CALL(manager_delegate_,
191 ShowAutofillPopup( 191 ShowAutofillPopup(
192 _, _, _, _, 192 _, _, _, _,
193 testing::ElementsAre( 193 testing::ElementsAre(
194 static_cast<int>( 194 static_cast<int>(
195 WebAutofillClient::MenuItemIDDataListEntry), 195 WebAutofillClient::MenuItemIDDataListEntry),
196 static_cast<int>(WebAutofillClient::MenuItemIDSeparator), 196 static_cast<int>(WebAutofillClient::MenuItemIDSeparator),
197 kAutofillProfileId, 197 kAutofillProfileId,
198 static_cast<int>(WebAutofillClient::MenuItemIDSeparator), 198 static_cast<int>(WebAutofillClient::MenuItemIDSeparator),
199 static_cast<int>( 199 static_cast<int>(
200 WebAutofillClient::MenuItemIDAutofillOptions)), 200 WebAutofillClient::MenuItemIDAutofillOptions)),
201 external_delegate_.get())); 201 external_delegate_.get()));
202 202
203 // This should call ShowAutofillPopup. 203 // This should call ShowAutofillPopup.
204 std::vector<string16> autofill_item; 204 std::vector<base::string16> autofill_item;
205 autofill_item.push_back(string16()); 205 autofill_item.push_back(base::string16());
206 std::vector<int> autofill_ids; 206 std::vector<int> autofill_ids;
207 autofill_ids.push_back(kAutofillProfileId); 207 autofill_ids.push_back(kAutofillProfileId);
208 external_delegate_->OnSuggestionsReturned(kQueryId, 208 external_delegate_->OnSuggestionsReturned(kQueryId,
209 autofill_item, 209 autofill_item,
210 autofill_item, 210 autofill_item,
211 autofill_item, 211 autofill_item,
212 autofill_ids); 212 autofill_ids);
213 213
214 // Try calling OnSuggestionsReturned with no Autofill values and ensure 214 // Try calling OnSuggestionsReturned with no Autofill values and ensure
215 // the datalist items are still shown. 215 // the datalist items are still shown.
216 // The enum must be cast to an int to prevent compile errors on linux_rel. 216 // The enum must be cast to an int to prevent compile errors on linux_rel.
217 EXPECT_CALL(manager_delegate_, 217 EXPECT_CALL(manager_delegate_,
218 ShowAutofillPopup( 218 ShowAutofillPopup(
219 _, _, _, _, 219 _, _, _, _,
220 testing::ElementsAre( 220 testing::ElementsAre(
221 static_cast<int>( 221 static_cast<int>(
222 WebAutofillClient::MenuItemIDDataListEntry)), 222 WebAutofillClient::MenuItemIDDataListEntry)),
223 external_delegate_.get())); 223 external_delegate_.get()));
224 224
225 autofill_item = std::vector<string16>(); 225 autofill_item = std::vector<base::string16>();
226 autofill_ids = std::vector<int>(); 226 autofill_ids = std::vector<int>();
227 external_delegate_->OnSuggestionsReturned(kQueryId, 227 external_delegate_->OnSuggestionsReturned(kQueryId,
228 autofill_item, 228 autofill_item,
229 autofill_item, 229 autofill_item,
230 autofill_item, 230 autofill_item,
231 autofill_ids); 231 autofill_ids);
232 } 232 }
233 233
234 // Test that the Autofill delegate doesn't try and fill a form with a 234 // Test that the Autofill delegate doesn't try and fill a form with a
235 // negative unique id. 235 // negative unique id.
236 TEST_F(AutofillExternalDelegateUnitTest, ExternalDelegateInvalidUniqueId) { 236 TEST_F(AutofillExternalDelegateUnitTest, ExternalDelegateInvalidUniqueId) {
237 // Ensure it doesn't try to preview the negative id. 237 // Ensure it doesn't try to preview the negative id.
238 EXPECT_CALL(*autofill_manager_, OnFillAutofillFormData(_, _, _, _)).Times(0); 238 EXPECT_CALL(*autofill_manager_, OnFillAutofillFormData(_, _, _, _)).Times(0);
239 EXPECT_CALL(*external_delegate_, ClearPreviewedForm()).Times(1); 239 EXPECT_CALL(*external_delegate_, ClearPreviewedForm()).Times(1);
240 external_delegate_->DidSelectSuggestion(-1); 240 external_delegate_->DidSelectSuggestion(-1);
241 241
242 // Ensure it doesn't try to fill the form in with the negative id. 242 // Ensure it doesn't try to fill the form in with the negative id.
243 EXPECT_CALL(manager_delegate_, HideAutofillPopup()); 243 EXPECT_CALL(manager_delegate_, HideAutofillPopup());
244 EXPECT_CALL(*autofill_manager_, OnFillAutofillFormData(_, _, _, _)).Times(0); 244 EXPECT_CALL(*autofill_manager_, OnFillAutofillFormData(_, _, _, _)).Times(0);
245 external_delegate_->DidAcceptSuggestion(string16(), -1); 245 external_delegate_->DidAcceptSuggestion(base::string16(), -1);
246 } 246 }
247 247
248 // Test that the ClearPreview IPC is only sent the form was being previewed 248 // Test that the ClearPreview IPC is only sent the form was being previewed
249 // (i.e. it isn't autofilling a password). 249 // (i.e. it isn't autofilling a password).
250 TEST_F(AutofillExternalDelegateUnitTest, ExternalDelegateClearPreviewedForm) { 250 TEST_F(AutofillExternalDelegateUnitTest, ExternalDelegateClearPreviewedForm) {
251 // Called by DidSelectSuggestion, add expectation to remove warning. 251 // Called by DidSelectSuggestion, add expectation to remove warning.
252 EXPECT_CALL(*autofill_manager_, OnFillAutofillFormData(_, _, _, _)); 252 EXPECT_CALL(*autofill_manager_, OnFillAutofillFormData(_, _, _, _));
253 253
254 // Ensure selecting a new password entries or Autofill entries will 254 // Ensure selecting a new password entries or Autofill entries will
255 // cause any previews to get cleared. 255 // cause any previews to get cleared.
(...skipping 11 matching lines...) Expand all
267 EXPECT_CALL(manager_delegate_, ShowAutofillPopup(_, _, _, _, _, _)); 267 EXPECT_CALL(manager_delegate_, ShowAutofillPopup(_, _, _, _, _, _));
268 autofill::GenerateTestAutofillPopup(external_delegate_.get()); 268 autofill::GenerateTestAutofillPopup(external_delegate_.get());
269 269
270 EXPECT_CALL(manager_delegate_, HideAutofillPopup()); 270 EXPECT_CALL(manager_delegate_, HideAutofillPopup());
271 external_delegate_->DidEndTextFieldEditing(); 271 external_delegate_->DidEndTextFieldEditing();
272 } 272 }
273 273
274 // Test that the popup is marked as visible after recieving password 274 // Test that the popup is marked as visible after recieving password
275 // suggestions. 275 // suggestions.
276 TEST_F(AutofillExternalDelegateUnitTest, ExternalDelegatePasswordSuggestions) { 276 TEST_F(AutofillExternalDelegateUnitTest, ExternalDelegatePasswordSuggestions) {
277 std::vector<string16> suggestions; 277 std::vector<base::string16> suggestions;
278 suggestions.push_back(string16()); 278 suggestions.push_back(base::string16());
279 279
280 FormFieldData field; 280 FormFieldData field;
281 field.is_focusable = true; 281 field.is_focusable = true;
282 field.should_autocomplete = true; 282 field.should_autocomplete = true;
283 const gfx::RectF element_bounds; 283 const gfx::RectF element_bounds;
284 284
285 // 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.
286 EXPECT_CALL(manager_delegate_, 286 EXPECT_CALL(manager_delegate_,
287 ShowAutofillPopup( 287 ShowAutofillPopup(
288 _, _, _, _, 288 _, _, _, _,
(...skipping 21 matching lines...) Expand all
310 TEST_F(AutofillExternalDelegateUnitTest, ExternalDelegateHideWarning) { 310 TEST_F(AutofillExternalDelegateUnitTest, ExternalDelegateHideWarning) {
311 // Set up a field that shouldn't get autocompleted or display warnings. 311 // Set up a field that shouldn't get autocompleted or display warnings.
312 const FormData form; 312 const FormData form;
313 FormFieldData field; 313 FormFieldData field;
314 field.is_focusable = true; 314 field.is_focusable = true;
315 field.should_autocomplete = false; 315 field.should_autocomplete = false;
316 const gfx::RectF element_bounds; 316 const gfx::RectF element_bounds;
317 317
318 external_delegate_->OnQuery(kQueryId, form, field, element_bounds, false); 318 external_delegate_->OnQuery(kQueryId, form, field, element_bounds, false);
319 319
320 std::vector<string16> autofill_items; 320 std::vector<base::string16> autofill_items;
321 autofill_items.push_back(string16()); 321 autofill_items.push_back(base::string16());
322 std::vector<int> autofill_ids; 322 std::vector<int> autofill_ids;
323 autofill_ids.push_back(WebAutofillClient::MenuItemIDAutocompleteEntry); 323 autofill_ids.push_back(WebAutofillClient::MenuItemIDAutocompleteEntry);
324 324
325 // Ensure the popup tries to hide itself, since it is not allowed to show 325 // Ensure the popup tries to hide itself, since it is not allowed to show
326 // anything. 326 // anything.
327 EXPECT_CALL(manager_delegate_, HideAutofillPopup()); 327 EXPECT_CALL(manager_delegate_, HideAutofillPopup());
328 328
329 external_delegate_->OnSuggestionsReturned(kQueryId, 329 external_delegate_->OnSuggestionsReturned(kQueryId,
330 autofill_items, 330 autofill_items,
331 autofill_items, 331 autofill_items,
332 autofill_items, 332 autofill_items,
333 autofill_ids); 333 autofill_ids);
334 } 334 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698