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/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" |
11 #include "components/autofill/browser/autofill_manager.h" | 11 #include "components/autofill/browser/autofill_manager.h" |
12 #include "components/autofill/browser/test_autofill_external_delegate.h" | 12 #include "components/autofill/browser/test_autofill_external_delegate.h" |
13 #include "components/autofill/browser/test_autofill_manager_delegate.h" | 13 #include "components/autofill/browser/test_autofill_manager_delegate.h" |
14 #include "components/autofill/common/form_data.h" | 14 #include "components/autofill/common/form_data.h" |
15 #include "components/autofill/common/form_field_data.h" | 15 #include "components/autofill/common/form_field_data.h" |
16 #include "content/public/test/test_browser_thread.h" | |
17 #include "testing/gmock/include/gmock/gmock.h" | 16 #include "testing/gmock/include/gmock/gmock.h" |
18 #include "testing/gtest/include/gtest/gtest.h" | 17 #include "testing/gtest/include/gtest/gtest.h" |
19 #include "third_party/WebKit/Source/WebKit/chromium/public/WebAutofillClient.h" | 18 #include "third_party/WebKit/Source/WebKit/chromium/public/WebAutofillClient.h" |
20 #include "ui/gfx/rect.h" | 19 #include "ui/gfx/rect.h" |
21 | 20 |
22 using content::BrowserThread; | |
23 using testing::_; | 21 using testing::_; |
24 using WebKit::WebAutofillClient; | 22 using WebKit::WebAutofillClient; |
25 | 23 |
26 namespace autofill { | 24 namespace autofill { |
27 | 25 |
28 namespace { | 26 namespace { |
29 | 27 |
30 // A constant value to use as the Autofill query ID. | 28 // A constant value to use as the Autofill query ID. |
31 const int kQueryId = 5; | 29 const int kQueryId = 5; |
32 | 30 |
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
83 int unique_id)); | 81 int unique_id)); |
84 | 82 |
85 private: | 83 private: |
86 DISALLOW_COPY_AND_ASSIGN(MockAutofillManager); | 84 DISALLOW_COPY_AND_ASSIGN(MockAutofillManager); |
87 }; | 85 }; |
88 | 86 |
89 } // namespace | 87 } // namespace |
90 | 88 |
91 class AutofillExternalDelegateUnitTest | 89 class AutofillExternalDelegateUnitTest |
92 : public ChromeRenderViewHostTestHarness { | 90 : public ChromeRenderViewHostTestHarness { |
93 public: | |
94 AutofillExternalDelegateUnitTest() | |
95 : ui_thread_(BrowserThread::UI, &message_loop_) {} | |
96 virtual ~AutofillExternalDelegateUnitTest() {} | |
97 | |
98 protected: | 91 protected: |
99 // Issue an OnQuery call with the given |query_id|. | |
100 void IssueOnQuery(int query_id) { | |
101 const FormData form; | |
102 FormFieldData field; | |
103 field.is_focusable = true; | |
104 field.should_autocomplete = true; | |
105 const gfx::RectF element_bounds; | |
106 | |
107 external_delegate_->OnQuery(query_id, form, field, element_bounds, false); | |
108 } | |
109 | |
110 MockAutofillManagerDelegate manager_delegate_; | |
111 scoped_ptr<MockAutofillManager> autofill_manager_; | |
112 scoped_ptr<testing::NiceMock<MockAutofillExternalDelegate> > | |
113 external_delegate_; | |
114 | |
115 private: | |
116 virtual void SetUp() OVERRIDE { | 92 virtual void SetUp() OVERRIDE { |
117 ChromeRenderViewHostTestHarness::SetUp(); | 93 ChromeRenderViewHostTestHarness::SetUp(); |
118 autofill_manager_.reset( | 94 autofill_manager_.reset( |
119 new MockAutofillManager(web_contents(), &manager_delegate_)); | 95 new MockAutofillManager(web_contents(), &manager_delegate_)); |
120 external_delegate_.reset( | 96 external_delegate_.reset( |
121 new testing::NiceMock<MockAutofillExternalDelegate>( | 97 new testing::NiceMock<MockAutofillExternalDelegate>( |
122 web_contents(), | 98 web_contents(), |
123 autofill_manager_.get())); | 99 autofill_manager_.get())); |
124 } | 100 } |
125 | 101 |
126 virtual void TearDown() OVERRIDE { | 102 virtual void TearDown() OVERRIDE { |
127 // Order of destruction is important as AutofillManager relies on | 103 // Order of destruction is important as AutofillManager relies on |
128 // PersonalDataManager to be around when it gets destroyed. Also, a real | 104 // PersonalDataManager to be around when it gets destroyed. Also, a real |
129 // AutofillManager is tied to the lifetime of the WebContents, so it must | 105 // AutofillManager is tied to the lifetime of the WebContents, so it must |
130 // be destroyed at the destruction of the WebContents. | 106 // be destroyed at the destruction of the WebContents. |
131 autofill_manager_.reset(); | 107 autofill_manager_.reset(); |
132 external_delegate_.reset(); | 108 external_delegate_.reset(); |
133 ChromeRenderViewHostTestHarness::TearDown(); | 109 ChromeRenderViewHostTestHarness::TearDown(); |
134 } | 110 } |
135 | 111 |
136 content::TestBrowserThread ui_thread_; | 112 // Issue an OnQuery call with the given |query_id|. |
| 113 void IssueOnQuery(int query_id) { |
| 114 const FormData form; |
| 115 FormFieldData field; |
| 116 field.is_focusable = true; |
| 117 field.should_autocomplete = true; |
| 118 const gfx::RectF element_bounds; |
137 | 119 |
138 DISALLOW_COPY_AND_ASSIGN(AutofillExternalDelegateUnitTest); | 120 external_delegate_->OnQuery(query_id, form, field, element_bounds, false); |
| 121 } |
| 122 |
| 123 MockAutofillManagerDelegate manager_delegate_; |
| 124 scoped_ptr<MockAutofillManager> autofill_manager_; |
| 125 scoped_ptr<testing::NiceMock<MockAutofillExternalDelegate> > |
| 126 external_delegate_; |
139 }; | 127 }; |
140 | 128 |
141 // Test that our external delegate called the virtual methods at the right time. | 129 // Test that our external delegate called the virtual methods at the right time. |
142 TEST_F(AutofillExternalDelegateUnitTest, TestExternalDelegateVirtualCalls) { | 130 TEST_F(AutofillExternalDelegateUnitTest, TestExternalDelegateVirtualCalls) { |
143 IssueOnQuery(kQueryId); | 131 IssueOnQuery(kQueryId); |
144 | 132 |
145 // The enums must be cast to ints to prevent compile errors on linux_rel. | 133 // The enums must be cast to ints to prevent compile errors on linux_rel. |
146 EXPECT_CALL(manager_delegate_, | 134 EXPECT_CALL(manager_delegate_, |
147 ShowAutofillPopup( | 135 ShowAutofillPopup( |
148 _, _, _, _, | 136 _, _, _, _, |
(...skipping 180 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
329 EXPECT_CALL(manager_delegate_, HideAutofillPopup()); | 317 EXPECT_CALL(manager_delegate_, HideAutofillPopup()); |
330 | 318 |
331 external_delegate_->OnSuggestionsReturned(kQueryId, | 319 external_delegate_->OnSuggestionsReturned(kQueryId, |
332 autofill_items, | 320 autofill_items, |
333 autofill_items, | 321 autofill_items, |
334 autofill_items, | 322 autofill_items, |
335 autofill_ids); | 323 autofill_ids); |
336 } | 324 } |
337 | 325 |
338 } // namespace autofill | 326 } // namespace autofill |
OLD | NEW |