| 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/memory/ref_counted.h" | 8 #include "base/memory/ref_counted.h" |
| 9 #include "base/string16.h" | 9 #include "base/string16.h" |
| 10 #include "chrome/browser/autofill/autofill_manager.h" | 10 #include "chrome/browser/autofill/autofill_manager.h" |
| (...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 56 MOCK_METHOD0(ClearPreviewedForm, void()); | 56 MOCK_METHOD0(ClearPreviewedForm, void()); |
| 57 | 57 |
| 58 MOCK_METHOD0(HideAutofillPopup, void()); | 58 MOCK_METHOD0(HideAutofillPopup, void()); |
| 59 | 59 |
| 60 private: | 60 private: |
| 61 virtual void HideAutofillPopupInternal() {}; | 61 virtual void HideAutofillPopupInternal() {}; |
| 62 }; | 62 }; |
| 63 | 63 |
| 64 class MockAutofillManager : public AutofillManager { | 64 class MockAutofillManager : public AutofillManager { |
| 65 public: | 65 public: |
| 66 explicit MockAutofillManager(TabContents* tab_contents) | 66 explicit MockAutofillManager(autofill::AutofillManagerDelegate* delegate, |
| 67 TabContents* tab_contents) |
| 67 // Force to use the constructor designated for unit test, but we don't | 68 // Force to use the constructor designated for unit test, but we don't |
| 68 // really need personal_data in this test so we pass a NULL pointer. | 69 // really need personal_data in this test so we pass a NULL pointer. |
| 69 : AutofillManager(&delegate_, tab_contents, NULL), | 70 : AutofillManager(delegate, tab_contents, NULL) { |
| 70 delegate_(tab_contents) { | |
| 71 } | 71 } |
| 72 | 72 |
| 73 MOCK_METHOD4(OnFillAutofillFormData, | 73 MOCK_METHOD4(OnFillAutofillFormData, |
| 74 void(int query_id, | 74 void(int query_id, |
| 75 const webkit::forms::FormData& form, | 75 const webkit::forms::FormData& form, |
| 76 const webkit::forms::FormField& field, | 76 const webkit::forms::FormField& field, |
| 77 int unique_id)); | 77 int unique_id)); |
| 78 | 78 |
| 79 protected: | 79 protected: |
| 80 virtual ~MockAutofillManager() {} | 80 virtual ~MockAutofillManager() {} |
| 81 | |
| 82 private: | |
| 83 TabAutofillManagerDelegate delegate_; | |
| 84 }; | 81 }; |
| 85 | 82 |
| 86 } // namespace | 83 } // namespace |
| 87 | 84 |
| 88 class AutofillExternalDelegateUnitTest : public TabContentsTestHarness { | 85 class AutofillExternalDelegateUnitTest : public TabContentsTestHarness { |
| 89 public: | 86 public: |
| 90 AutofillExternalDelegateUnitTest() | 87 AutofillExternalDelegateUnitTest() |
| 91 : ui_thread_(BrowserThread::UI, &message_loop_) {} | 88 : ui_thread_(BrowserThread::UI, &message_loop_) {} |
| 92 virtual ~AutofillExternalDelegateUnitTest() {} | 89 virtual ~AutofillExternalDelegateUnitTest() {} |
| 93 | 90 |
| 94 virtual void SetUp() OVERRIDE { | 91 virtual void SetUp() OVERRIDE { |
| 95 TabContentsTestHarness::SetUp(); | 92 TabContentsTestHarness::SetUp(); |
| 96 autofill_manager_ = new MockAutofillManager(tab_contents()); | 93 manager_delegate_.reset(new TabAutofillManagerDelegate(tab_contents())); |
| 94 autofill_manager_ = new MockAutofillManager(manager_delegate_.get(), |
| 95 tab_contents()); |
| 97 external_delegate_.reset(new MockAutofillExternalDelegate( | 96 external_delegate_.reset(new MockAutofillExternalDelegate( |
| 98 tab_contents(), | 97 tab_contents(), |
| 99 autofill_manager_)); | 98 autofill_manager_)); |
| 100 } | 99 } |
| 101 | 100 |
| 102 protected: | 101 protected: |
| 103 // Set up the expectation for a platform specific OnQuery call and then | 102 // Set up the expectation for a platform specific OnQuery call and then |
| 104 // execute it with the given QueryId. | 103 // execute it with the given QueryId. |
| 105 void IssueOnQuery(int query_id) { | 104 void IssueOnQuery(int query_id) { |
| 106 const FormData form; | 105 const FormData form; |
| 107 FormField field; | 106 FormField field; |
| 108 field.is_focusable = true; | 107 field.is_focusable = true; |
| 109 field.should_autocomplete = true; | 108 field.should_autocomplete = true; |
| 110 const gfx::Rect bounds; | 109 const gfx::Rect bounds; |
| 111 | 110 |
| 112 EXPECT_CALL(*external_delegate_, | 111 EXPECT_CALL(*external_delegate_, |
| 113 OnQueryPlatformSpecific(query_id, form, field, bounds)); | 112 OnQueryPlatformSpecific(query_id, form, field, bounds)); |
| 114 | 113 |
| 115 // This should call OnQueryPlatform specific. | 114 // This should call OnQueryPlatform specific. |
| 116 external_delegate_->OnQuery(query_id, form, field, bounds, false); | 115 external_delegate_->OnQuery(query_id, form, field, bounds, false); |
| 117 } | 116 } |
| 118 | 117 |
| 118 scoped_ptr<TabAutofillManagerDelegate> manager_delegate_; |
| 119 scoped_refptr<MockAutofillManager> autofill_manager_; | 119 scoped_refptr<MockAutofillManager> autofill_manager_; |
| 120 scoped_ptr<MockAutofillExternalDelegate> external_delegate_; | 120 scoped_ptr<MockAutofillExternalDelegate> external_delegate_; |
| 121 | 121 |
| 122 private: | 122 private: |
| 123 content::TestBrowserThread ui_thread_; | 123 content::TestBrowserThread ui_thread_; |
| 124 | 124 |
| 125 DISALLOW_COPY_AND_ASSIGN(AutofillExternalDelegateUnitTest); | 125 DISALLOW_COPY_AND_ASSIGN(AutofillExternalDelegateUnitTest); |
| 126 }; | 126 }; |
| 127 | 127 |
| 128 // Test that our external delegate called the virtual methods at the right time. | 128 // Test that our external delegate called the virtual methods at the right time. |
| (...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 245 external_delegate_->SelectAutofillSuggestionAtIndex(1); | 245 external_delegate_->SelectAutofillSuggestionAtIndex(1); |
| 246 } | 246 } |
| 247 | 247 |
| 248 // Test that the popup is hidden once we are done editing the autofill field. | 248 // Test that the popup is hidden once we are done editing the autofill field. |
| 249 TEST_F(AutofillExternalDelegateUnitTest, | 249 TEST_F(AutofillExternalDelegateUnitTest, |
| 250 ExternalDelegateHidePopupAfterEditing) { | 250 ExternalDelegateHidePopupAfterEditing) { |
| 251 EXPECT_CALL(*external_delegate_, HideAutofillPopup()); | 251 EXPECT_CALL(*external_delegate_, HideAutofillPopup()); |
| 252 | 252 |
| 253 external_delegate_->DidEndTextFieldEditing(); | 253 external_delegate_->DidEndTextFieldEditing(); |
| 254 } | 254 } |
| OLD | NEW |