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 <stddef.h> | 5 #include <stddef.h> |
6 | 6 |
7 #include <memory> | 7 #include <memory> |
8 | 8 |
9 #include "base/macros.h" | 9 #include "base/macros.h" |
10 #include "base/memory/weak_ptr.h" | 10 #include "base/memory/weak_ptr.h" |
| 11 #include "base/optional.h" |
11 #include "base/strings/utf_string_conversions.h" | 12 #include "base/strings/utf_string_conversions.h" |
12 #include "build/build_config.h" | 13 #include "build/build_config.h" |
13 #include "chrome/browser/ui/autofill/autofill_popup_controller_impl.h" | 14 #include "chrome/browser/ui/autofill/autofill_popup_controller_impl.h" |
14 #include "chrome/browser/ui/autofill/autofill_popup_view.h" | 15 #include "chrome/browser/ui/autofill/autofill_popup_view.h" |
15 #include "chrome/test/base/chrome_render_view_host_test_harness.h" | 16 #include "chrome/test/base/chrome_render_view_host_test_harness.h" |
16 #include "chrome/test/base/testing_profile.h" | 17 #include "chrome/test/base/testing_profile.h" |
17 #include "components/autofill/content/browser/content_autofill_driver.h" | 18 #include "components/autofill/content/browser/content_autofill_driver.h" |
18 #include "components/autofill/content/browser/content_autofill_driver_factory.h" | 19 #include "components/autofill/content/browser/content_autofill_driver_factory.h" |
19 #include "components/autofill/core/browser/autofill_external_delegate.h" | 20 #include "components/autofill/core/browser/autofill_external_delegate.h" |
20 #include "components/autofill/core/browser/autofill_manager.h" | 21 #include "components/autofill/core/browser/autofill_manager.h" |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
62 ~MockAutofillClient() override {} | 63 ~MockAutofillClient() override {} |
63 | 64 |
64 PrefService* GetPrefs() override { return prefs_.get(); } | 65 PrefService* GetPrefs() override { return prefs_.get(); } |
65 | 66 |
66 private: | 67 private: |
67 std::unique_ptr<PrefService> prefs_; | 68 std::unique_ptr<PrefService> prefs_; |
68 | 69 |
69 DISALLOW_COPY_AND_ASSIGN(MockAutofillClient); | 70 DISALLOW_COPY_AND_ASSIGN(MockAutofillClient); |
70 }; | 71 }; |
71 | 72 |
| 73 class MockAutofillPopupView : public AutofillPopupView { |
| 74 public: |
| 75 MockAutofillPopupView() {} |
| 76 |
| 77 MOCK_METHOD0(Show, void()); |
| 78 MOCK_METHOD0(Hide, void()); |
| 79 MOCK_METHOD2(OnSelectedRowChanged, |
| 80 void(base::Optional<size_t> previous_row_selection, |
| 81 base::Optional<size_t> current_row_selection)); |
| 82 MOCK_METHOD0(OnSuggestionsChanged, void()); |
| 83 |
| 84 private: |
| 85 DISALLOW_COPY_AND_ASSIGN(MockAutofillPopupView); |
| 86 }; |
| 87 |
72 class TestAutofillPopupController : public AutofillPopupControllerImpl { | 88 class TestAutofillPopupController : public AutofillPopupControllerImpl { |
73 public: | 89 public: |
74 TestAutofillPopupController( | 90 TestAutofillPopupController( |
75 base::WeakPtr<AutofillExternalDelegate> external_delegate, | 91 base::WeakPtr<AutofillExternalDelegate> external_delegate, |
76 const gfx::RectF& element_bounds) | 92 const gfx::RectF& element_bounds) |
77 : AutofillPopupControllerImpl(external_delegate, | 93 : AutofillPopupControllerImpl(external_delegate, |
78 NULL, | 94 NULL, |
79 NULL, | 95 NULL, |
80 element_bounds, | 96 element_bounds, |
81 base::i18n::UNKNOWN_DIRECTION) {} | 97 base::i18n::UNKNOWN_DIRECTION) {} |
82 ~TestAutofillPopupController() override {} | 98 ~TestAutofillPopupController() override {} |
83 | 99 |
84 // Making protected functions public for testing | 100 // Making protected functions public for testing |
85 using AutofillPopupControllerImpl::GetLineCount; | 101 using AutofillPopupControllerImpl::GetLineCount; |
86 using AutofillPopupControllerImpl::GetSuggestionAt; | 102 using AutofillPopupControllerImpl::GetSuggestionAt; |
87 using AutofillPopupControllerImpl::GetElidedValueAt; | 103 using AutofillPopupControllerImpl::GetElidedValueAt; |
88 using AutofillPopupControllerImpl::GetElidedLabelAt; | 104 using AutofillPopupControllerImpl::GetElidedLabelAt; |
89 using AutofillPopupControllerImpl::selected_line; | 105 using AutofillPopupControllerImpl::selected_line; |
90 using AutofillPopupControllerImpl::SetSelectedLine; | 106 using AutofillPopupControllerImpl::SetSelectedLine; |
91 using AutofillPopupControllerImpl::SelectNextLine; | 107 using AutofillPopupControllerImpl::SelectNextLine; |
92 using AutofillPopupControllerImpl::SelectPreviousLine; | 108 using AutofillPopupControllerImpl::SelectPreviousLine; |
93 using AutofillPopupControllerImpl::RemoveSelectedLine; | 109 using AutofillPopupControllerImpl::RemoveSelectedLine; |
94 using AutofillPopupControllerImpl::popup_bounds; | 110 using AutofillPopupControllerImpl::popup_bounds; |
95 using AutofillPopupControllerImpl::element_bounds; | 111 using AutofillPopupControllerImpl::element_bounds; |
96 using AutofillPopupControllerImpl::SetValues; | 112 using AutofillPopupControllerImpl::SetValues; |
97 using AutofillPopupControllerImpl::GetWeakPtr; | 113 using AutofillPopupControllerImpl::GetWeakPtr; |
98 MOCK_METHOD1(InvalidateRow, void(size_t)); | 114 MOCK_METHOD0(OnSuggestionsChanged, void()); |
99 MOCK_METHOD0(UpdateBoundsAndRedrawPopup, void()); | |
100 MOCK_METHOD0(Hide, void()); | 115 MOCK_METHOD0(Hide, void()); |
101 | 116 |
102 void DoHide() { | 117 void DoHide() { |
103 AutofillPopupControllerImpl::Hide(); | 118 AutofillPopupControllerImpl::Hide(); |
104 } | 119 } |
| 120 }; |
105 | 121 |
106 private: | 122 static constexpr base::Optional<size_t> kNoSelection; |
107 void ShowView() override {} | |
108 }; | |
109 | 123 |
110 } // namespace | 124 } // namespace |
111 | 125 |
112 class AutofillPopupControllerUnitTest : public ChromeRenderViewHostTestHarness { | 126 class AutofillPopupControllerUnitTest : public ChromeRenderViewHostTestHarness { |
113 public: | 127 public: |
114 AutofillPopupControllerUnitTest() | 128 AutofillPopupControllerUnitTest() |
115 : autofill_client_(new MockAutofillClient()), | 129 : autofill_client_(new MockAutofillClient()), |
116 autofill_popup_controller_(NULL) {} | 130 autofill_popup_controller_(NULL) {} |
117 ~AutofillPopupControllerUnitTest() override {} | 131 ~AutofillPopupControllerUnitTest() override {} |
118 | 132 |
119 void SetUp() override { | 133 void SetUp() override { |
120 ChromeRenderViewHostTestHarness::SetUp(); | 134 ChromeRenderViewHostTestHarness::SetUp(); |
121 | 135 |
122 ContentAutofillDriverFactory::CreateForWebContentsAndDelegate( | 136 ContentAutofillDriverFactory::CreateForWebContentsAndDelegate( |
123 web_contents(), autofill_client_.get(), "en-US", | 137 web_contents(), autofill_client_.get(), "en-US", |
124 AutofillManager::ENABLE_AUTOFILL_DOWNLOAD_MANAGER); | 138 AutofillManager::ENABLE_AUTOFILL_DOWNLOAD_MANAGER); |
125 // Make sure RenderFrame is created. | 139 // Make sure RenderFrame is created. |
126 NavigateAndCommit(GURL("about:blank")); | 140 NavigateAndCommit(GURL("about:blank")); |
127 ContentAutofillDriverFactory* factory = | 141 ContentAutofillDriverFactory* factory = |
128 ContentAutofillDriverFactory::FromWebContents(web_contents()); | 142 ContentAutofillDriverFactory::FromWebContents(web_contents()); |
129 ContentAutofillDriver* driver = | 143 ContentAutofillDriver* driver = |
130 factory->DriverForFrame(web_contents()->GetMainFrame()); | 144 factory->DriverForFrame(web_contents()->GetMainFrame()); |
131 external_delegate_.reset( | 145 external_delegate_.reset( |
132 new NiceMock<MockAutofillExternalDelegate>( | 146 new NiceMock<MockAutofillExternalDelegate>( |
133 driver->autofill_manager(), | 147 driver->autofill_manager(), |
134 driver)); | 148 driver)); |
135 | 149 autofill_popup_view_.reset(new NiceMock<MockAutofillPopupView>()); |
136 autofill_popup_controller_ = | 150 autofill_popup_controller_ = new NiceMock<TestAutofillPopupController>( |
137 new testing::NiceMock<TestAutofillPopupController>( | 151 external_delegate_->GetWeakPtr(), gfx::RectF()); |
138 external_delegate_->GetWeakPtr(), gfx::RectF()); | 152 autofill_popup_controller_->SetViewForTesting(autofill_popup_view()); |
139 } | 153 } |
140 | 154 |
141 void TearDown() override { | 155 void TearDown() override { |
142 // This will make sure the controller and the view (if any) are both | 156 // This will make sure the controller and the view (if any) are both |
143 // cleaned up. | 157 // cleaned up. |
144 if (autofill_popup_controller_) | 158 if (autofill_popup_controller_) |
145 autofill_popup_controller_->DoHide(); | 159 autofill_popup_controller_->DoHide(); |
146 | 160 |
147 external_delegate_.reset(); | 161 external_delegate_.reset(); |
148 ChromeRenderViewHostTestHarness::TearDown(); | 162 ChromeRenderViewHostTestHarness::TearDown(); |
149 } | 163 } |
150 | 164 |
151 TestAutofillPopupController* popup_controller() { | 165 TestAutofillPopupController* popup_controller() { |
152 return autofill_popup_controller_; | 166 return autofill_popup_controller_; |
153 } | 167 } |
154 | 168 |
155 MockAutofillExternalDelegate* delegate() { | 169 MockAutofillExternalDelegate* delegate() { |
156 return external_delegate_.get(); | 170 return external_delegate_.get(); |
157 } | 171 } |
158 | 172 |
| 173 MockAutofillPopupView* autofill_popup_view() { |
| 174 return autofill_popup_view_.get(); |
| 175 } |
| 176 |
159 protected: | 177 protected: |
160 std::unique_ptr<MockAutofillClient> autofill_client_; | 178 std::unique_ptr<MockAutofillClient> autofill_client_; |
161 std::unique_ptr<NiceMock<MockAutofillExternalDelegate>> external_delegate_; | 179 std::unique_ptr<NiceMock<MockAutofillExternalDelegate>> external_delegate_; |
162 testing::NiceMock<TestAutofillPopupController>* autofill_popup_controller_; | 180 std::unique_ptr<NiceMock<MockAutofillPopupView>> autofill_popup_view_; |
| 181 NiceMock<TestAutofillPopupController>* autofill_popup_controller_; |
163 }; | 182 }; |
164 | 183 |
165 TEST_F(AutofillPopupControllerUnitTest, ChangeSelectedLine) { | 184 TEST_F(AutofillPopupControllerUnitTest, ChangeSelectedLine) { |
166 // Set up the popup. | 185 // Set up the popup. |
167 std::vector<Suggestion> suggestions; | 186 std::vector<Suggestion> suggestions; |
168 suggestions.push_back(Suggestion("", "", "", 0)); | 187 suggestions.push_back(Suggestion("", "", "", 0)); |
169 suggestions.push_back(Suggestion("", "", "", 0)); | 188 suggestions.push_back(Suggestion("", "", "", 0)); |
170 autofill_popup_controller_->Show(suggestions); | 189 autofill_popup_controller_->Show(suggestions); |
171 | 190 |
172 EXPECT_LT(autofill_popup_controller_->selected_line(), 0); | 191 EXPECT_FALSE(autofill_popup_controller_->selected_line()); |
173 // Check that there are at least 2 values so that the first and last selection | 192 // Check that there are at least 2 values so that the first and last selection |
174 // are different. | 193 // are different. |
175 EXPECT_GE(2, | 194 EXPECT_GE(2, |
176 static_cast<int>(autofill_popup_controller_->GetLineCount())); | 195 static_cast<int>(autofill_popup_controller_->GetLineCount())); |
177 | 196 |
178 // Test wrapping before the front. | 197 // Test wrapping before the front. |
179 autofill_popup_controller_->SelectPreviousLine(); | 198 autofill_popup_controller_->SelectPreviousLine(); |
180 EXPECT_EQ(static_cast<int>( | 199 EXPECT_EQ(autofill_popup_controller_->GetLineCount() - 1, |
181 autofill_popup_controller_->GetLineCount() - 1), | 200 autofill_popup_controller_->selected_line().value()); |
182 autofill_popup_controller_->selected_line()); | |
183 | 201 |
184 // Test wrapping after the end. | 202 // Test wrapping after the end. |
185 autofill_popup_controller_->SelectNextLine(); | 203 autofill_popup_controller_->SelectNextLine(); |
186 EXPECT_EQ(0, autofill_popup_controller_->selected_line()); | 204 EXPECT_EQ(static_cast<size_t>(0), |
| 205 autofill_popup_controller_->selected_line().value()); |
187 } | 206 } |
188 | 207 |
189 TEST_F(AutofillPopupControllerUnitTest, RedrawSelectedLine) { | 208 TEST_F(AutofillPopupControllerUnitTest, RedrawSelectedLine) { |
190 // Set up the popup. | 209 // Set up the popup. |
191 std::vector<Suggestion> suggestions; | 210 std::vector<Suggestion> suggestions; |
192 suggestions.push_back(Suggestion("", "", "", 0)); | 211 suggestions.push_back(Suggestion("", "", "", 0)); |
193 suggestions.push_back(Suggestion("", "", "", 0)); | 212 suggestions.push_back(Suggestion("", "", "", 0)); |
194 autofill_popup_controller_->Show(suggestions); | 213 autofill_popup_controller_->Show(suggestions); |
195 | 214 |
196 // Make sure that when a new line is selected, it is invalidated so it can | 215 // Make sure that when a new line is selected, it is invalidated so it can |
197 // be updated to show it is selected. | 216 // be updated to show it is selected. |
198 int selected_line = 0; | 217 int selected_line = 0; |
199 EXPECT_CALL(*autofill_popup_controller_, InvalidateRow(selected_line)); | 218 EXPECT_CALL(*autofill_popup_view_, |
| 219 OnSelectedRowChanged(kNoSelection, |
| 220 base::Optional<size_t>(selected_line))); |
| 221 |
200 autofill_popup_controller_->SetSelectedLine(selected_line); | 222 autofill_popup_controller_->SetSelectedLine(selected_line); |
201 | 223 |
202 // Ensure that the row isn't invalidated if it didn't change. | 224 // Ensure that the row isn't invalidated if it didn't change. |
203 EXPECT_CALL(*autofill_popup_controller_, | 225 EXPECT_CALL(*autofill_popup_view_, OnSelectedRowChanged(_, _)).Times(0); |
204 InvalidateRow(selected_line)).Times(0); | |
205 autofill_popup_controller_->SetSelectedLine(selected_line); | 226 autofill_popup_controller_->SetSelectedLine(selected_line); |
206 | 227 |
207 // Change back to no selection. | 228 // Change back to no selection. |
208 EXPECT_CALL(*autofill_popup_controller_, InvalidateRow(selected_line)); | 229 EXPECT_CALL(*autofill_popup_view_, |
209 autofill_popup_controller_->SetSelectedLine(-1); | 230 OnSelectedRowChanged(base::Optional<size_t>(selected_line), |
| 231 kNoSelection)); |
| 232 autofill_popup_controller_->SetSelectedLine(kNoSelection); |
210 } | 233 } |
211 | 234 |
212 TEST_F(AutofillPopupControllerUnitTest, RemoveLine) { | 235 TEST_F(AutofillPopupControllerUnitTest, RemoveLine) { |
213 // Set up the popup. | 236 // Set up the popup. |
214 std::vector<Suggestion> suggestions; | 237 std::vector<Suggestion> suggestions; |
215 suggestions.push_back(Suggestion("", "", "", 1)); | 238 suggestions.push_back(Suggestion("", "", "", 1)); |
216 suggestions.push_back(Suggestion("", "", "", 1)); | 239 suggestions.push_back(Suggestion("", "", "", 1)); |
217 suggestions.push_back(Suggestion("", "", "", POPUP_ITEM_ID_AUTOFILL_OPTIONS)); | 240 suggestions.push_back(Suggestion("", "", "", POPUP_ITEM_ID_AUTOFILL_OPTIONS)); |
218 autofill_popup_controller_->Show(suggestions); | 241 autofill_popup_controller_->Show(suggestions); |
219 | 242 |
220 // Generate a popup, so it can be hidden later. It doesn't matter what the | 243 // Generate a popup, so it can be hidden later. It doesn't matter what the |
221 // external_delegate thinks is being shown in the process, since we are just | 244 // external_delegate thinks is being shown in the process, since we are just |
222 // testing the popup here. | 245 // testing the popup here. |
223 autofill::GenerateTestAutofillPopup(external_delegate_.get()); | 246 autofill::GenerateTestAutofillPopup(external_delegate_.get()); |
224 | 247 |
225 // No line is selected so the removal should fail. | 248 // No line is selected so the removal should fail. |
226 EXPECT_FALSE(autofill_popup_controller_->RemoveSelectedLine()); | 249 EXPECT_FALSE(autofill_popup_controller_->RemoveSelectedLine()); |
227 | 250 |
228 // Remove the first entry. The popup should be redrawn since its size has | 251 // Remove the first entry. The popup should be redrawn since its size has |
229 // changed. | 252 // changed. |
230 EXPECT_CALL(*autofill_popup_controller_, UpdateBoundsAndRedrawPopup()); | 253 EXPECT_CALL(*autofill_popup_controller_, OnSuggestionsChanged()); |
231 autofill_popup_controller_->SetSelectedLine(0); | 254 autofill_popup_controller_->SetSelectedLine(0); |
232 EXPECT_TRUE(autofill_popup_controller_->RemoveSelectedLine()); | 255 EXPECT_TRUE(autofill_popup_controller_->RemoveSelectedLine()); |
233 | 256 |
234 // Remove the last entry. The popup should then be hidden since there are | 257 // Remove the last entry. The popup should then be hidden since there are |
235 // no Autofill entries left. | 258 // no Autofill entries left. |
236 EXPECT_CALL(*autofill_popup_controller_, Hide()); | 259 EXPECT_CALL(*autofill_popup_controller_, Hide()); |
237 autofill_popup_controller_->SetSelectedLine(0); | 260 autofill_popup_controller_->SetSelectedLine(0); |
238 EXPECT_TRUE(autofill_popup_controller_->RemoveSelectedLine()); | 261 EXPECT_TRUE(autofill_popup_controller_->RemoveSelectedLine()); |
239 } | 262 } |
240 | 263 |
241 TEST_F(AutofillPopupControllerUnitTest, RemoveOnlyLine) { | 264 TEST_F(AutofillPopupControllerUnitTest, RemoveOnlyLine) { |
242 // Set up the popup. | 265 // Set up the popup. |
243 std::vector<Suggestion> suggestions; | 266 std::vector<Suggestion> suggestions; |
244 suggestions.push_back(Suggestion("", "", "", 1)); | 267 suggestions.push_back(Suggestion("", "", "", 1)); |
245 autofill_popup_controller_->Show(suggestions); | 268 autofill_popup_controller_->Show(suggestions); |
246 | 269 |
247 // Generate a popup. | 270 // Generate a popup. |
248 autofill::GenerateTestAutofillPopup(external_delegate_.get()); | 271 autofill::GenerateTestAutofillPopup(external_delegate_.get()); |
249 | 272 |
250 // Select the only line. | 273 // Select the only line. |
251 autofill_popup_controller_->SetSelectedLine(0); | 274 autofill_popup_controller_->SetSelectedLine(0); |
| 275 EXPECT_CALL(*autofill_popup_view_, |
| 276 OnSelectedRowChanged(kNoSelection, base::Optional<size_t>(0))) |
| 277 .Times(0); |
252 | 278 |
253 // Remove the only line. There should be no row invalidation and the popup | 279 // Remove the only line. The popup should then be hidden since there are no |
254 // should then be hidden since there are no Autofill entries left. | 280 // Autofill entries left. |
255 EXPECT_CALL(*autofill_popup_controller_, Hide()); | 281 EXPECT_CALL(*autofill_popup_controller_, Hide()); |
256 EXPECT_CALL(*autofill_popup_controller_, InvalidateRow(_)).Times(0); | 282 EXPECT_CALL(*autofill_popup_view_, |
| 283 OnSelectedRowChanged(base::Optional<size_t>(0), kNoSelection)); |
257 EXPECT_TRUE(autofill_popup_controller_->RemoveSelectedLine()); | 284 EXPECT_TRUE(autofill_popup_controller_->RemoveSelectedLine()); |
258 } | 285 } |
259 | 286 |
260 TEST_F(AutofillPopupControllerUnitTest, SkipSeparator) { | 287 TEST_F(AutofillPopupControllerUnitTest, SkipSeparator) { |
261 // Set up the popup. | 288 // Set up the popup. |
262 std::vector<Suggestion> suggestions; | 289 std::vector<Suggestion> suggestions; |
263 suggestions.push_back(Suggestion("", "", "", 1)); | 290 suggestions.push_back(Suggestion("", "", "", 1)); |
264 suggestions.push_back(Suggestion("", "", "", POPUP_ITEM_ID_SEPARATOR)); | 291 suggestions.push_back(Suggestion("", "", "", POPUP_ITEM_ID_SEPARATOR)); |
265 suggestions.push_back(Suggestion("", "", "", POPUP_ITEM_ID_AUTOFILL_OPTIONS)); | 292 suggestions.push_back(Suggestion("", "", "", POPUP_ITEM_ID_AUTOFILL_OPTIONS)); |
266 autofill_popup_controller_->Show(suggestions); | 293 autofill_popup_controller_->Show(suggestions); |
267 | 294 |
268 autofill_popup_controller_->SetSelectedLine(0); | 295 autofill_popup_controller_->SetSelectedLine(0); |
269 | 296 |
270 // Make sure next skips the unselectable separator. | 297 // Make sure next skips the unselectable separator. |
271 autofill_popup_controller_->SelectNextLine(); | 298 autofill_popup_controller_->SelectNextLine(); |
272 EXPECT_EQ(2, autofill_popup_controller_->selected_line()); | 299 EXPECT_EQ(static_cast<size_t>(2), |
| 300 autofill_popup_controller_->selected_line().value()); |
273 | 301 |
274 // Make sure previous skips the unselectable separator. | 302 // Make sure previous skips the unselectable separator. |
275 autofill_popup_controller_->SelectPreviousLine(); | 303 autofill_popup_controller_->SelectPreviousLine(); |
276 EXPECT_EQ(0, autofill_popup_controller_->selected_line()); | 304 EXPECT_EQ(static_cast<size_t>(0), |
| 305 autofill_popup_controller_->selected_line().value()); |
277 } | 306 } |
278 | 307 |
279 TEST_F(AutofillPopupControllerUnitTest, UpdateDataListValues) { | 308 TEST_F(AutofillPopupControllerUnitTest, UpdateDataListValues) { |
280 std::vector<Suggestion> suggestions; | 309 std::vector<Suggestion> suggestions; |
281 suggestions.push_back(Suggestion("", "", "", 1)); | 310 suggestions.push_back(Suggestion("", "", "", 1)); |
282 autofill_popup_controller_->Show(suggestions); | 311 autofill_popup_controller_->Show(suggestions); |
283 | 312 |
284 // Add one data list entry. | 313 // Add one data list entry. |
285 base::string16 value1 = ASCIIToUTF16("data list value 1"); | 314 base::string16 value1 = ASCIIToUTF16("data list value 1"); |
286 std::vector<base::string16> data_list_values; | 315 std::vector<base::string16> data_list_values; |
(...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
379 gfx::RectF(), base::i18n::UNKNOWN_DIRECTION); | 408 gfx::RectF(), base::i18n::UNKNOWN_DIRECTION); |
380 EXPECT_TRUE(controller.get()); | 409 EXPECT_TRUE(controller.get()); |
381 | 410 |
382 WeakPtr<AutofillPopupControllerImpl> controller2 = | 411 WeakPtr<AutofillPopupControllerImpl> controller2 = |
383 AutofillPopupControllerImpl::GetOrCreate( | 412 AutofillPopupControllerImpl::GetOrCreate( |
384 controller, delegate.GetWeakPtr(), NULL, NULL, gfx::RectF(), | 413 controller, delegate.GetWeakPtr(), NULL, NULL, gfx::RectF(), |
385 base::i18n::UNKNOWN_DIRECTION); | 414 base::i18n::UNKNOWN_DIRECTION); |
386 EXPECT_EQ(controller.get(), controller2.get()); | 415 EXPECT_EQ(controller.get(), controller2.get()); |
387 controller->Hide(); | 416 controller->Hide(); |
388 | 417 |
389 testing::NiceMock<TestAutofillPopupController>* test_controller = | 418 NiceMock<TestAutofillPopupController>* test_controller = |
390 new testing::NiceMock<TestAutofillPopupController>(delegate.GetWeakPtr(), | 419 new NiceMock<TestAutofillPopupController>(delegate.GetWeakPtr(), |
391 gfx::RectF()); | 420 gfx::RectF()); |
392 EXPECT_CALL(*test_controller, Hide()); | 421 EXPECT_CALL(*test_controller, Hide()); |
393 | 422 |
394 gfx::RectF bounds(0.f, 0.f, 1.f, 2.f); | 423 gfx::RectF bounds(0.f, 0.f, 1.f, 2.f); |
395 base::WeakPtr<AutofillPopupControllerImpl> controller3 = | 424 base::WeakPtr<AutofillPopupControllerImpl> controller3 = |
396 AutofillPopupControllerImpl::GetOrCreate( | 425 AutofillPopupControllerImpl::GetOrCreate( |
397 test_controller->GetWeakPtr(), | 426 test_controller->GetWeakPtr(), |
398 delegate.GetWeakPtr(), | 427 delegate.GetWeakPtr(), |
399 NULL, | 428 NULL, |
400 NULL, | 429 NULL, |
401 bounds, | 430 bounds, |
402 base::i18n::UNKNOWN_DIRECTION); | 431 base::i18n::UNKNOWN_DIRECTION); |
403 EXPECT_EQ( | 432 EXPECT_EQ( |
404 bounds, | 433 bounds, |
405 static_cast<AutofillPopupController*>(controller3.get())-> | 434 static_cast<AutofillPopupController*>(controller3.get())-> |
406 element_bounds()); | 435 element_bounds()); |
407 controller3->Hide(); | 436 controller3->Hide(); |
408 | 437 |
409 // Hide the test_controller to delete it. | 438 // Hide the test_controller to delete it. |
410 test_controller->DoHide(); | 439 test_controller->DoHide(); |
411 } | 440 } |
412 | 441 |
413 TEST_F(AutofillPopupControllerUnitTest, ProperlyResetController) { | 442 TEST_F(AutofillPopupControllerUnitTest, ProperlyResetController) { |
414 std::vector<Suggestion> suggestions; | 443 std::vector<Suggestion> suggestions; |
415 suggestions.push_back(Suggestion("", "", "", 0)); | 444 suggestions.push_back(Suggestion("", "", "", 0)); |
416 suggestions.push_back(Suggestion("", "", "", 0)); | 445 suggestions.push_back(Suggestion("", "", "", 0)); |
417 popup_controller()->SetValues(suggestions); | 446 popup_controller()->Show(suggestions); |
418 popup_controller()->SetSelectedLine(0); | 447 popup_controller()->SetSelectedLine(0); |
419 | 448 |
420 // Now show a new popup with the same controller, but with fewer items. | 449 // Now show a new popup with the same controller, but with fewer items. |
421 WeakPtr<AutofillPopupControllerImpl> controller = | 450 WeakPtr<AutofillPopupControllerImpl> controller = |
422 AutofillPopupControllerImpl::GetOrCreate( | 451 AutofillPopupControllerImpl::GetOrCreate( |
423 popup_controller()->GetWeakPtr(), delegate()->GetWeakPtr(), NULL, | 452 popup_controller()->GetWeakPtr(), delegate()->GetWeakPtr(), NULL, |
424 NULL, gfx::RectF(), base::i18n::UNKNOWN_DIRECTION); | 453 NULL, gfx::RectF(), base::i18n::UNKNOWN_DIRECTION); |
425 EXPECT_NE(0, controller->selected_line()); | 454 EXPECT_NE(static_cast<size_t>(0), controller->selected_line().value()); |
426 EXPECT_EQ(0u, controller->GetLineCount()); | 455 EXPECT_EQ(0u, controller->GetLineCount()); |
427 } | 456 } |
428 | 457 |
429 #if !defined(OS_ANDROID) | 458 #if !defined(OS_ANDROID) |
430 TEST_F(AutofillPopupControllerUnitTest, ElideText) { | 459 TEST_F(AutofillPopupControllerUnitTest, ElideText) { |
431 std::vector<Suggestion> suggestions; | 460 std::vector<Suggestion> suggestions; |
432 suggestions.push_back( | 461 suggestions.push_back( |
433 Suggestion("Text that will need to be trimmed", | 462 Suggestion("Text that will need to be trimmed", |
434 "Label that will be trimmed", "genericCC", 0)); | 463 "Label that will be trimmed", "genericCC", 0)); |
435 suggestions.push_back( | 464 suggestions.push_back( |
(...skipping 25 matching lines...) Expand all Loading... |
461 | 490 |
462 // The second element was shorter so it should be unchanged. | 491 // The second element was shorter so it should be unchanged. |
463 EXPECT_EQ(autofill_popup_controller_->GetSuggestionAt(1).value, | 492 EXPECT_EQ(autofill_popup_controller_->GetSuggestionAt(1).value, |
464 autofill_popup_controller_->GetElidedValueAt(1)); | 493 autofill_popup_controller_->GetElidedValueAt(1)); |
465 EXPECT_EQ(autofill_popup_controller_->GetSuggestionAt(1).label, | 494 EXPECT_EQ(autofill_popup_controller_->GetSuggestionAt(1).label, |
466 autofill_popup_controller_->GetElidedLabelAt(1)); | 495 autofill_popup_controller_->GetElidedLabelAt(1)); |
467 } | 496 } |
468 #endif | 497 #endif |
469 | 498 |
470 } // namespace autofill | 499 } // namespace autofill |
OLD | NEW |