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

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

Issue 148413002: Add "previewing on hover" support for single-field autocomplete input (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Addressed Ilya's 2nd set comments Created 6 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
1 // Copyright 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 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/message_loop/message_loop.h" 8 #include "base/message_loop/message_loop.h"
9 #include "base/strings/string16.h" 9 #include "base/strings/string16.h"
10 #include "base/strings/utf_string_conversions.h" 10 #include "base/strings/utf_string_conversions.h"
(...skipping 26 matching lines...) Expand all
37 class MockAutofillDriver : public TestAutofillDriver { 37 class MockAutofillDriver : public TestAutofillDriver {
38 public: 38 public:
39 MockAutofillDriver() {} 39 MockAutofillDriver() {}
40 // Mock methods to enable testability. 40 // Mock methods to enable testability.
41 MOCK_METHOD1(SetRendererActionOnFormDataReception, 41 MOCK_METHOD1(SetRendererActionOnFormDataReception,
42 void(RendererFormDataAction action)); 42 void(RendererFormDataAction action));
43 MOCK_METHOD1(RendererShouldAcceptDataListSuggestion, 43 MOCK_METHOD1(RendererShouldAcceptDataListSuggestion,
44 void(const base::string16&)); 44 void(const base::string16&));
45 MOCK_METHOD0(RendererShouldClearFilledForm, void()); 45 MOCK_METHOD0(RendererShouldClearFilledForm, void());
46 MOCK_METHOD0(RendererShouldClearPreviewedForm, void()); 46 MOCK_METHOD0(RendererShouldClearPreviewedForm, void());
47 MOCK_METHOD1(RendererShouldSetNodeText, void(const base::string16&)); 47 MOCK_METHOD1(RendererShouldFillFieldWithValue, void(const base::string16&));
48 MOCK_METHOD1(RendererShouldPreviewFieldWithValue,
49 void(const base::string16&));
48 50
49 private: 51 private:
50 DISALLOW_COPY_AND_ASSIGN(MockAutofillDriver); 52 DISALLOW_COPY_AND_ASSIGN(MockAutofillDriver);
51 }; 53 };
52 54
53 class MockAutofillManagerDelegate 55 class MockAutofillManagerDelegate
54 : public autofill::TestAutofillManagerDelegate { 56 : public autofill::TestAutofillManagerDelegate {
55 public: 57 public:
56 MockAutofillManagerDelegate() {} 58 MockAutofillManagerDelegate() {}
57 59
(...skipping 296 matching lines...) Expand 10 before | Expand all | Expand 10 after
354 } 356 }
355 357
356 // Test that the Autofill delegate doesn't try and fill a form with a 358 // Test that the Autofill delegate doesn't try and fill a form with a
357 // negative unique id. 359 // negative unique id.
358 TEST_F(AutofillExternalDelegateUnitTest, ExternalDelegateInvalidUniqueId) { 360 TEST_F(AutofillExternalDelegateUnitTest, ExternalDelegateInvalidUniqueId) {
359 // Ensure it doesn't try to preview the negative id. 361 // Ensure it doesn't try to preview the negative id.
360 EXPECT_CALL(*autofill_manager_, OnFillAutofillFormData(_, _, _, _)).Times(0); 362 EXPECT_CALL(*autofill_manager_, OnFillAutofillFormData(_, _, _, _)).Times(0);
361 EXPECT_CALL(*autofill_driver_, 363 EXPECT_CALL(*autofill_driver_,
362 SetRendererActionOnFormDataReception(_)).Times(0); 364 SetRendererActionOnFormDataReception(_)).Times(0);
363 EXPECT_CALL(*autofill_driver_, RendererShouldClearPreviewedForm()).Times(1); 365 EXPECT_CALL(*autofill_driver_, RendererShouldClearPreviewedForm()).Times(1);
364 external_delegate_->DidSelectSuggestion(-1); 366 external_delegate_->DidSelectSuggestion(base::string16(), -1);
365 367
366 // Ensure it doesn't try to fill the form in with the negative id. 368 // Ensure it doesn't try to fill the form in with the negative id.
367 EXPECT_CALL(manager_delegate_, HideAutofillPopup()); 369 EXPECT_CALL(manager_delegate_, HideAutofillPopup());
368 EXPECT_CALL(*autofill_manager_, OnFillAutofillFormData(_, _, _, _)).Times(0); 370 EXPECT_CALL(*autofill_manager_, OnFillAutofillFormData(_, _, _, _)).Times(0);
369 EXPECT_CALL(*autofill_driver_, 371 EXPECT_CALL(*autofill_driver_,
370 SetRendererActionOnFormDataReception(_)).Times(0); 372 SetRendererActionOnFormDataReception(_)).Times(0);
371 external_delegate_->DidAcceptSuggestion(base::string16(), -1); 373 external_delegate_->DidAcceptSuggestion(base::string16(), -1);
372 } 374 }
373 375
374 // Test that the ClearPreview call is only sent if the form was being previewed 376 // Test that the ClearPreview call is only sent if the form was being previewed
375 // (i.e. it isn't autofilling a password). 377 // (i.e. it isn't autofilling a password).
376 TEST_F(AutofillExternalDelegateUnitTest, ExternalDelegateClearPreviewedForm) { 378 TEST_F(AutofillExternalDelegateUnitTest, ExternalDelegateClearPreviewedForm) {
377 // Called by DidSelectSuggestion, add expectation to remove warning. 379 // Called by DidSelectSuggestion, add expectation to remove warning.
378 EXPECT_CALL(*autofill_manager_, OnFillAutofillFormData(_, _, _, _)); 380 EXPECT_CALL(*autofill_manager_, OnFillAutofillFormData(_, _, _, _));
379 381
380 // Ensure selecting a new password entries or Autofill entries will 382 // Ensure selecting a new password entries or Autofill entries will
381 // cause any previews to get cleared. 383 // cause any previews to get cleared.
382 EXPECT_CALL(*autofill_driver_, RendererShouldClearPreviewedForm()).Times(1); 384 EXPECT_CALL(*autofill_driver_, RendererShouldClearPreviewedForm()).Times(1);
383 external_delegate_->DidSelectSuggestion(POPUP_ITEM_ID_PASSWORD_ENTRY); 385 external_delegate_->DidSelectSuggestion(ASCIIToUTF16("baz foo"),
386 POPUP_ITEM_ID_PASSWORD_ENTRY);
384 EXPECT_CALL(*autofill_driver_, RendererShouldClearPreviewedForm()).Times(1); 387 EXPECT_CALL(*autofill_driver_, RendererShouldClearPreviewedForm()).Times(1);
385 EXPECT_CALL(*autofill_driver_, SetRendererActionOnFormDataReception( 388 EXPECT_CALL(*autofill_driver_, SetRendererActionOnFormDataReception(
386 AutofillDriver::FORM_DATA_ACTION_PREVIEW)); 389 AutofillDriver::FORM_DATA_ACTION_PREVIEW));
387 external_delegate_->DidSelectSuggestion(1); 390 external_delegate_->DidSelectSuggestion(ASCIIToUTF16("baz foo"), 1);
391
392 // Ensure selecting an autocomplete entries will cause any previews to
Ilya Sherman 2014/03/01 02:57:37 nit: "an autocomplete entries" -> "an autocomplete
ziran.sun 2014/03/04 15:30:19 Done.
393 // get cleared.
394 EXPECT_CALL(*autofill_driver_, RendererShouldClearPreviewedForm()).Times(1);
395 external_delegate_->DidSelectSuggestion(ASCIIToUTF16("baz foo"),
396 POPUP_ITEM_ID_AUTOCOMPLETE_ENTRY);
388 } 397 }
389 398
390 // Test that the popup is hidden once we are done editing the autofill field. 399 // Test that the popup is hidden once we are done editing the autofill field.
391 TEST_F(AutofillExternalDelegateUnitTest, 400 TEST_F(AutofillExternalDelegateUnitTest,
392 ExternalDelegateHidePopupAfterEditing) { 401 ExternalDelegateHidePopupAfterEditing) {
393 EXPECT_CALL(manager_delegate_, ShowAutofillPopup(_, _, _, _, _, _, _)); 402 EXPECT_CALL(manager_delegate_, ShowAutofillPopup(_, _, _, _, _, _, _));
394 autofill::GenerateTestAutofillPopup(external_delegate_.get()); 403 autofill::GenerateTestAutofillPopup(external_delegate_.get());
395 404
396 EXPECT_CALL(manager_delegate_, HideAutofillPopup()); 405 EXPECT_CALL(manager_delegate_, HideAutofillPopup());
397 external_delegate_->DidEndTextFieldEditing(); 406 external_delegate_->DidEndTextFieldEditing();
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after
483 // anything. 492 // anything.
484 EXPECT_CALL(manager_delegate_, HideAutofillPopup()); 493 EXPECT_CALL(manager_delegate_, HideAutofillPopup());
485 494
486 external_delegate_->OnSuggestionsReturned(kQueryId, 495 external_delegate_->OnSuggestionsReturned(kQueryId,
487 autofill_items, 496 autofill_items,
488 autofill_items, 497 autofill_items,
489 autofill_items, 498 autofill_items,
490 autofill_ids); 499 autofill_ids);
491 } 500 }
492 501
493 TEST_F(AutofillExternalDelegateUnitTest, ExternalDelegateSetNodeText) { 502 TEST_F(AutofillExternalDelegateUnitTest, ExternalDelegateFillFieldWithValue) {
494 EXPECT_CALL(manager_delegate_, HideAutofillPopup()); 503 EXPECT_CALL(manager_delegate_, HideAutofillPopup());
495 base::string16 dummy_string(ASCIIToUTF16("baz foo")); 504 base::string16 dummy_string(ASCIIToUTF16("baz foo"));
496 EXPECT_CALL(*autofill_driver_, 505 EXPECT_CALL(*autofill_driver_,
497 RendererShouldSetNodeText(dummy_string)); 506 RendererShouldFillFieldWithValue(dummy_string));
498 external_delegate_->DidAcceptSuggestion(dummy_string, 507 external_delegate_->DidAcceptSuggestion(dummy_string,
499 POPUP_ITEM_ID_AUTOCOMPLETE_ENTRY); 508 POPUP_ITEM_ID_AUTOCOMPLETE_ENTRY);
500 } 509 }
501 510
502 } // namespace autofill 511 } // namespace autofill
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698