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/strings/string16.h" | 8 #include "base/strings/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" |
11 #include "chrome/test/base/testing_profile.h" | 11 #include "chrome/test/base/testing_profile.h" |
12 #include "components/autofill/browser/autofill_manager.h" | 12 #include "components/autofill/browser/autofill_manager.h" |
| 13 #include "components/autofill/browser/test_autofill_driver.h" |
13 #include "components/autofill/browser/test_autofill_external_delegate.h" | 14 #include "components/autofill/browser/test_autofill_external_delegate.h" |
14 #include "components/autofill/browser/test_autofill_manager_delegate.h" | 15 #include "components/autofill/browser/test_autofill_manager_delegate.h" |
15 #include "components/autofill/common/form_data.h" | 16 #include "components/autofill/common/form_data.h" |
16 #include "components/autofill/common/form_field_data.h" | 17 #include "components/autofill/common/form_field_data.h" |
17 #include "components/autofill/common/password_form_fill_data.h" | 18 #include "components/autofill/common/password_form_fill_data.h" |
18 #include "testing/gmock/include/gmock/gmock.h" | 19 #include "testing/gmock/include/gmock/gmock.h" |
19 #include "testing/gtest/include/gtest/gtest.h" | 20 #include "testing/gtest/include/gtest/gtest.h" |
20 #include "third_party/WebKit/Source/WebKit/chromium/public/WebAutofillClient.h" | 21 #include "third_party/WebKit/Source/WebKit/chromium/public/WebAutofillClient.h" |
21 #include "ui/gfx/rect.h" | 22 #include "ui/gfx/rect.h" |
22 | 23 |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
62 base::WeakPtr<AutofillPopupDelegate> delegate)); | 63 base::WeakPtr<AutofillPopupDelegate> delegate)); |
63 | 64 |
64 MOCK_METHOD0(HideAutofillPopup, void()); | 65 MOCK_METHOD0(HideAutofillPopup, void()); |
65 | 66 |
66 private: | 67 private: |
67 DISALLOW_COPY_AND_ASSIGN(MockAutofillManagerDelegate); | 68 DISALLOW_COPY_AND_ASSIGN(MockAutofillManagerDelegate); |
68 }; | 69 }; |
69 | 70 |
70 class MockAutofillManager : public AutofillManager { | 71 class MockAutofillManager : public AutofillManager { |
71 public: | 72 public: |
72 MockAutofillManager(content::WebContents* web_contents, | 73 MockAutofillManager(AutofillDriver* driver, |
73 MockAutofillManagerDelegate* delegate) | 74 MockAutofillManagerDelegate* delegate) |
74 // Force to use the constructor designated for unit test, but we don't | 75 // Force to use the constructor designated for unit test, but we don't |
75 // really need personal_data in this test so we pass a NULL pointer. | 76 // really need personal_data in this test so we pass a NULL pointer. |
76 : AutofillManager(web_contents, delegate, NULL) { | 77 : AutofillManager(driver, delegate, NULL) { |
77 } | 78 } |
78 virtual ~MockAutofillManager() {} | 79 virtual ~MockAutofillManager() {} |
79 | 80 |
80 MOCK_METHOD4(OnFillAutofillFormData, | 81 MOCK_METHOD4(OnFillAutofillFormData, |
81 void(int query_id, | 82 void(int query_id, |
82 const FormData& form, | 83 const FormData& form, |
83 const FormFieldData& field, | 84 const FormFieldData& field, |
84 int unique_id)); | 85 int unique_id)); |
85 | 86 |
86 private: | 87 private: |
87 DISALLOW_COPY_AND_ASSIGN(MockAutofillManager); | 88 DISALLOW_COPY_AND_ASSIGN(MockAutofillManager); |
88 }; | 89 }; |
89 | 90 |
90 } // namespace | 91 } // namespace |
91 | 92 |
92 class AutofillExternalDelegateUnitTest | 93 class AutofillExternalDelegateUnitTest |
93 : public ChromeRenderViewHostTestHarness { | 94 : public ChromeRenderViewHostTestHarness { |
94 protected: | 95 protected: |
95 virtual void SetUp() OVERRIDE { | 96 virtual void SetUp() OVERRIDE { |
96 ChromeRenderViewHostTestHarness::SetUp(); | 97 ChromeRenderViewHostTestHarness::SetUp(); |
| 98 autofill_driver_.reset(new TestAutofillDriver(web_contents())); |
97 autofill_manager_.reset( | 99 autofill_manager_.reset( |
98 new MockAutofillManager(web_contents(), &manager_delegate_)); | 100 new MockAutofillManager(autofill_driver_.get(), |
| 101 &manager_delegate_)); |
99 external_delegate_.reset( | 102 external_delegate_.reset( |
100 new testing::NiceMock<MockAutofillExternalDelegate>( | 103 new testing::NiceMock<MockAutofillExternalDelegate>( |
101 web_contents(), | 104 web_contents(), |
102 autofill_manager_.get())); | 105 autofill_manager_.get())); |
103 } | 106 } |
104 | 107 |
105 virtual void TearDown() OVERRIDE { | 108 virtual void TearDown() OVERRIDE { |
106 // Order of destruction is important as AutofillManager relies on | 109 // Order of destruction is important as AutofillManager relies on |
107 // PersonalDataManager to be around when it gets destroyed. Also, a real | 110 // PersonalDataManager to be around when it gets destroyed. Also, a real |
108 // AutofillManager is tied to the lifetime of the WebContents, so it must | 111 // AutofillManager is tied to the lifetime of the WebContents, so it must |
109 // be destroyed at the destruction of the WebContents. | 112 // be destroyed at the destruction of the WebContents. |
110 autofill_manager_.reset(); | 113 autofill_manager_.reset(); |
111 external_delegate_.reset(); | 114 external_delegate_.reset(); |
| 115 autofill_driver_.reset(); |
112 ChromeRenderViewHostTestHarness::TearDown(); | 116 ChromeRenderViewHostTestHarness::TearDown(); |
113 } | 117 } |
114 | 118 |
115 // Issue an OnQuery call with the given |query_id|. | 119 // Issue an OnQuery call with the given |query_id|. |
116 void IssueOnQuery(int query_id) { | 120 void IssueOnQuery(int query_id) { |
117 const FormData form; | 121 const FormData form; |
118 FormFieldData field; | 122 FormFieldData field; |
119 field.is_focusable = true; | 123 field.is_focusable = true; |
120 field.should_autocomplete = true; | 124 field.should_autocomplete = true; |
121 const gfx::RectF element_bounds; | 125 const gfx::RectF element_bounds; |
122 | 126 |
123 external_delegate_->OnQuery(query_id, form, field, element_bounds, true); | 127 external_delegate_->OnQuery(query_id, form, field, element_bounds, true); |
124 } | 128 } |
125 | 129 |
126 MockAutofillManagerDelegate manager_delegate_; | 130 MockAutofillManagerDelegate manager_delegate_; |
| 131 scoped_ptr<AutofillDriver> autofill_driver_; |
127 scoped_ptr<MockAutofillManager> autofill_manager_; | 132 scoped_ptr<MockAutofillManager> autofill_manager_; |
128 scoped_ptr<testing::NiceMock<MockAutofillExternalDelegate> > | 133 scoped_ptr<testing::NiceMock<MockAutofillExternalDelegate> > |
129 external_delegate_; | 134 external_delegate_; |
130 }; | 135 }; |
131 | 136 |
132 // Test that our external delegate called the virtual methods at the right time. | 137 // Test that our external delegate called the virtual methods at the right time. |
133 TEST_F(AutofillExternalDelegateUnitTest, TestExternalDelegateVirtualCalls) { | 138 TEST_F(AutofillExternalDelegateUnitTest, TestExternalDelegateVirtualCalls) { |
134 IssueOnQuery(kQueryId); | 139 IssueOnQuery(kQueryId); |
135 | 140 |
136 // The enums must be cast to ints to prevent compile errors on linux_rel. | 141 // The enums must be cast to ints to prevent compile errors on linux_rel. |
(...skipping 214 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
351 EXPECT_CALL(manager_delegate_, HideAutofillPopup()); | 356 EXPECT_CALL(manager_delegate_, HideAutofillPopup()); |
352 | 357 |
353 external_delegate_->OnSuggestionsReturned(kQueryId, | 358 external_delegate_->OnSuggestionsReturned(kQueryId, |
354 autofill_items, | 359 autofill_items, |
355 autofill_items, | 360 autofill_items, |
356 autofill_items, | 361 autofill_items, |
357 autofill_ids); | 362 autofill_ids); |
358 } | 363 } |
359 | 364 |
360 } // namespace autofill | 365 } // namespace autofill |
OLD | NEW |