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

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: Rebase and update code as per Ilya's 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 23 matching lines...) Expand all
34 const int kAutofillProfileId = 1; 34 const int kAutofillProfileId = 1;
35 35
36 class MockAutofillDriver : public TestAutofillDriver { 36 class MockAutofillDriver : public TestAutofillDriver {
37 public: 37 public:
38 MockAutofillDriver() {} 38 MockAutofillDriver() {}
39 // Mock methods to enable testability. 39 // Mock methods to enable testability.
40 MOCK_METHOD1(RendererShouldAcceptDataListSuggestion, 40 MOCK_METHOD1(RendererShouldAcceptDataListSuggestion,
41 void(const base::string16&)); 41 void(const base::string16&));
42 MOCK_METHOD0(RendererShouldClearFilledForm, void()); 42 MOCK_METHOD0(RendererShouldClearFilledForm, void());
43 MOCK_METHOD0(RendererShouldClearPreviewedForm, void()); 43 MOCK_METHOD0(RendererShouldClearPreviewedForm, void());
44 MOCK_METHOD1(RendererShouldSetNodeText, void(const base::string16&)); 44 MOCK_METHOD1(RendererShouldFillFieldWithValue, void(const base::string16&));
45 MOCK_METHOD1(RendererShouldPreviewFieldWithValue,
46 void(const base::string16&));
45 47
46 private: 48 private:
47 DISALLOW_COPY_AND_ASSIGN(MockAutofillDriver); 49 DISALLOW_COPY_AND_ASSIGN(MockAutofillDriver);
48 }; 50 };
49 51
50 class MockAutofillManagerDelegate 52 class MockAutofillManagerDelegate
51 : public autofill::TestAutofillManagerDelegate { 53 : public autofill::TestAutofillManagerDelegate {
52 public: 54 public:
53 MockAutofillManagerDelegate() {} 55 MockAutofillManagerDelegate() {}
54 56
(...skipping 292 matching lines...) Expand 10 before | Expand all | Expand 10 after
347 autofill_item, 349 autofill_item,
348 autofill_ids); 350 autofill_ids);
349 } 351 }
350 352
351 // Test that the Autofill delegate doesn't try and fill a form with a 353 // Test that the Autofill delegate doesn't try and fill a form with a
352 // negative unique id. 354 // negative unique id.
353 TEST_F(AutofillExternalDelegateUnitTest, ExternalDelegateInvalidUniqueId) { 355 TEST_F(AutofillExternalDelegateUnitTest, ExternalDelegateInvalidUniqueId) {
354 // Ensure it doesn't try to preview the negative id. 356 // Ensure it doesn't try to preview the negative id.
355 EXPECT_CALL(*autofill_manager_, FillOrPreviewForm(_, _, _, _, _)).Times(0); 357 EXPECT_CALL(*autofill_manager_, FillOrPreviewForm(_, _, _, _, _)).Times(0);
356 EXPECT_CALL(*autofill_driver_, RendererShouldClearPreviewedForm()).Times(1); 358 EXPECT_CALL(*autofill_driver_, RendererShouldClearPreviewedForm()).Times(1);
357 external_delegate_->DidSelectSuggestion(-1); 359 external_delegate_->DidSelectSuggestion(base::string16(), -1);
358 360
359 // Ensure it doesn't try to fill the form in with the negative id. 361 // Ensure it doesn't try to fill the form in with the negative id.
360 EXPECT_CALL(manager_delegate_, HideAutofillPopup()); 362 EXPECT_CALL(manager_delegate_, HideAutofillPopup());
361 EXPECT_CALL(*autofill_manager_, FillOrPreviewForm(_, _, _, _, _)).Times(0); 363 EXPECT_CALL(*autofill_manager_, FillOrPreviewForm(_, _, _, _, _)).Times(0);
362 external_delegate_->DidAcceptSuggestion(base::string16(), -1); 364 external_delegate_->DidAcceptSuggestion(base::string16(), -1);
363 } 365 }
364 366
365 // Test that the ClearPreview call is only sent if the form was being previewed 367 // Test that the ClearPreview call is only sent if the form was being previewed
366 // (i.e. it isn't autofilling a password). 368 // (i.e. it isn't autofilling a password).
367 TEST_F(AutofillExternalDelegateUnitTest, ExternalDelegateClearPreviewedForm) { 369 TEST_F(AutofillExternalDelegateUnitTest, ExternalDelegateClearPreviewedForm) {
368 // Ensure selecting a new password entries or Autofill entries will 370 // Ensure selecting a new password entries or Autofill entries will
369 // cause any previews to get cleared. 371 // cause any previews to get cleared.
370 EXPECT_CALL(*autofill_driver_, RendererShouldClearPreviewedForm()).Times(1); 372 EXPECT_CALL(*autofill_driver_, RendererShouldClearPreviewedForm()).Times(1);
371 external_delegate_->DidSelectSuggestion(POPUP_ITEM_ID_PASSWORD_ENTRY); 373 external_delegate_->DidSelectSuggestion(ASCIIToUTF16("baz foo"),
374 POPUP_ITEM_ID_PASSWORD_ENTRY);
372 EXPECT_CALL(*autofill_driver_, RendererShouldClearPreviewedForm()).Times(1); 375 EXPECT_CALL(*autofill_driver_, RendererShouldClearPreviewedForm()).Times(1);
373 EXPECT_CALL(*autofill_manager_, 376 EXPECT_CALL(*autofill_manager_,
374 FillOrPreviewForm( 377 FillOrPreviewForm(
375 AutofillDriver::FORM_DATA_ACTION_PREVIEW, _, _, _, _)); 378 AutofillDriver::FORM_DATA_ACTION_PREVIEW, _, _, _, _));
376 external_delegate_->DidSelectSuggestion(1); 379 external_delegate_->DidSelectSuggestion(ASCIIToUTF16("baz foo"), 1);
380
381 // Ensure selecting an autocomplete entry will cause any previews to
382 // get cleared.
383 EXPECT_CALL(*autofill_driver_, RendererShouldClearPreviewedForm()).Times(1);
384 EXPECT_CALL(*autofill_driver_, RendererShouldPreviewFieldWithValue(
385 ASCIIToUTF16("baz foo")));
386 external_delegate_->DidSelectSuggestion(ASCIIToUTF16("baz foo"),
387 POPUP_ITEM_ID_AUTOCOMPLETE_ENTRY);
377 } 388 }
378 389
379 // Test that the popup is hidden once we are done editing the autofill field. 390 // Test that the popup is hidden once we are done editing the autofill field.
380 TEST_F(AutofillExternalDelegateUnitTest, 391 TEST_F(AutofillExternalDelegateUnitTest,
381 ExternalDelegateHidePopupAfterEditing) { 392 ExternalDelegateHidePopupAfterEditing) {
382 EXPECT_CALL(manager_delegate_, ShowAutofillPopup(_, _, _, _, _, _, _)); 393 EXPECT_CALL(manager_delegate_, ShowAutofillPopup(_, _, _, _, _, _, _));
383 autofill::GenerateTestAutofillPopup(external_delegate_.get()); 394 autofill::GenerateTestAutofillPopup(external_delegate_.get());
384 395
385 EXPECT_CALL(manager_delegate_, HideAutofillPopup()); 396 EXPECT_CALL(manager_delegate_, HideAutofillPopup());
386 external_delegate_->DidEndTextFieldEditing(); 397 external_delegate_->DidEndTextFieldEditing();
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after
472 // anything. 483 // anything.
473 EXPECT_CALL(manager_delegate_, HideAutofillPopup()); 484 EXPECT_CALL(manager_delegate_, HideAutofillPopup());
474 485
475 external_delegate_->OnSuggestionsReturned(kQueryId, 486 external_delegate_->OnSuggestionsReturned(kQueryId,
476 autofill_items, 487 autofill_items,
477 autofill_items, 488 autofill_items,
478 autofill_items, 489 autofill_items,
479 autofill_ids); 490 autofill_ids);
480 } 491 }
481 492
482 TEST_F(AutofillExternalDelegateUnitTest, ExternalDelegateSetNodeText) { 493 TEST_F(AutofillExternalDelegateUnitTest, ExternalDelegateFillFieldWithValue) {
483 EXPECT_CALL(manager_delegate_, HideAutofillPopup()); 494 EXPECT_CALL(manager_delegate_, HideAutofillPopup());
484 base::string16 dummy_string(ASCIIToUTF16("baz foo")); 495 base::string16 dummy_string(ASCIIToUTF16("baz foo"));
485 EXPECT_CALL(*autofill_driver_, 496 EXPECT_CALL(*autofill_driver_,
486 RendererShouldSetNodeText(dummy_string)); 497 RendererShouldFillFieldWithValue(dummy_string));
487 external_delegate_->DidAcceptSuggestion(dummy_string, 498 external_delegate_->DidAcceptSuggestion(dummy_string,
488 POPUP_ITEM_ID_AUTOCOMPLETE_ENTRY); 499 POPUP_ITEM_ID_AUTOCOMPLETE_ENTRY);
489 } 500 }
490 501
491 } // namespace autofill 502 } // namespace autofill
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698