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

Side by Side Diff: chrome/browser/ui/autofill/autofill_popup_controller_unittest.cc

Issue 2727233003: Uses child views in Autofill Popup so we can trigger (Closed)
Patch Set: Adds test coverage for changing number of suggestions. Created 3 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 (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/strings/utf_string_conversions.h" 11 #include "base/strings/utf_string_conversions.h"
12 #include "build/build_config.h" 12 #include "build/build_config.h"
13 #include "chrome/browser/ui/autofill/autofill_popup_controller_impl.h" 13 #include "chrome/browser/ui/autofill/autofill_popup_controller_impl.h"
14 #include "chrome/browser/ui/autofill/autofill_popup_view.h" 14 #include "chrome/browser/ui/autofill/autofill_popup_view.h"
15 #include "chrome/test/base/chrome_render_view_host_test_harness.h" 15 #include "chrome/test/base/chrome_render_view_host_test_harness.h"
16 #include "chrome/test/base/testing_profile.h" 16 #include "chrome/test/base/testing_profile.h"
17 #include "components/autofill/content/browser/content_autofill_driver.h" 17 #include "components/autofill/content/browser/content_autofill_driver.h"
18 #include "components/autofill/content/browser/content_autofill_driver_factory.h" 18 #include "components/autofill/content/browser/content_autofill_driver_factory.h"
19 #include "components/autofill/core/browser/autofill_external_delegate.h" 19 #include "components/autofill/core/browser/autofill_external_delegate.h"
20 #include "components/autofill/core/browser/autofill_manager.h" 20 #include "components/autofill/core/browser/autofill_manager.h"
21 #include "components/autofill/core/browser/autofill_test_utils.h" 21 #include "components/autofill/core/browser/autofill_test_utils.h"
22 #include "components/autofill/core/browser/popup_item_ids.h" 22 #include "components/autofill/core/browser/popup_item_ids.h"
23 #include "components/autofill/core/browser/test_autofill_client.h" 23 #include "components/autofill/core/browser/test_autofill_client.h"
24 #include "components/autofill/core/browser/test_autofill_external_delegate.h" 24 #include "components/autofill/core/browser/test_autofill_external_delegate.h"
25 #include "components/prefs/pref_service.h" 25 #include "components/prefs/pref_service.h"
26 #include "content/public/browser/web_contents.h" 26 #include "content/public/browser/web_contents.h"
27 #include "testing/gmock/include/gmock/gmock.h" 27 #include "testing/gmock/include/gmock/gmock.h"
28 #include "testing/gtest/include/gtest/gtest.h" 28 #include "testing/gtest/include/gtest/gtest.h"
29 #include "ui/accessibility/ax_enums.h"
29 #include "ui/gfx/geometry/rect.h" 30 #include "ui/gfx/geometry/rect.h"
30 #include "ui/gfx/text_utils.h" 31 #include "ui/gfx/text_utils.h"
31 32
32 using ::testing::_; 33 using ::testing::_;
33 using ::testing::AtLeast; 34 using ::testing::AtLeast;
34 using ::testing::NiceMock; 35 using ::testing::NiceMock;
35 using base::ASCIIToUTF16; 36 using base::ASCIIToUTF16;
36 using base::WeakPtr; 37 using base::WeakPtr;
37 38
38 namespace autofill { 39 namespace autofill {
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
89 using AutofillPopupControllerImpl::selected_line; 90 using AutofillPopupControllerImpl::selected_line;
90 using AutofillPopupControllerImpl::SetSelectedLine; 91 using AutofillPopupControllerImpl::SetSelectedLine;
91 using AutofillPopupControllerImpl::SelectNextLine; 92 using AutofillPopupControllerImpl::SelectNextLine;
92 using AutofillPopupControllerImpl::SelectPreviousLine; 93 using AutofillPopupControllerImpl::SelectPreviousLine;
93 using AutofillPopupControllerImpl::RemoveSelectedLine; 94 using AutofillPopupControllerImpl::RemoveSelectedLine;
94 using AutofillPopupControllerImpl::popup_bounds; 95 using AutofillPopupControllerImpl::popup_bounds;
95 using AutofillPopupControllerImpl::element_bounds; 96 using AutofillPopupControllerImpl::element_bounds;
96 using AutofillPopupControllerImpl::SetValues; 97 using AutofillPopupControllerImpl::SetValues;
97 using AutofillPopupControllerImpl::GetWeakPtr; 98 using AutofillPopupControllerImpl::GetWeakPtr;
98 MOCK_METHOD1(InvalidateRow, void(size_t)); 99 MOCK_METHOD1(InvalidateRow, void(size_t));
100 MOCK_METHOD2(NotifyAccessibilityEventForRow, void(ui::AXEvent, size_t));
99 MOCK_METHOD0(UpdateBoundsAndRedrawPopup, void()); 101 MOCK_METHOD0(UpdateBoundsAndRedrawPopup, void());
100 MOCK_METHOD0(Hide, void()); 102 MOCK_METHOD0(Hide, void());
101 103
102 void DoHide() { 104 void DoHide() {
103 AutofillPopupControllerImpl::Hide(); 105 AutofillPopupControllerImpl::Hide();
104 } 106 }
105 107
106 private: 108 private:
107 void ShowView() override {} 109 void ShowView() override {}
108 }; 110 };
(...skipping 17 matching lines...) Expand all
126 NavigateAndCommit(GURL("about:blank")); 128 NavigateAndCommit(GURL("about:blank"));
127 ContentAutofillDriverFactory* factory = 129 ContentAutofillDriverFactory* factory =
128 ContentAutofillDriverFactory::FromWebContents(web_contents()); 130 ContentAutofillDriverFactory::FromWebContents(web_contents());
129 ContentAutofillDriver* driver = 131 ContentAutofillDriver* driver =
130 factory->DriverForFrame(web_contents()->GetMainFrame()); 132 factory->DriverForFrame(web_contents()->GetMainFrame());
131 external_delegate_.reset( 133 external_delegate_.reset(
132 new NiceMock<MockAutofillExternalDelegate>( 134 new NiceMock<MockAutofillExternalDelegate>(
133 driver->autofill_manager(), 135 driver->autofill_manager(),
134 driver)); 136 driver));
135 137
136 autofill_popup_controller_ = 138 autofill_popup_controller_ = new NiceMock<TestAutofillPopupController>(
137 new testing::NiceMock<TestAutofillPopupController>( 139 external_delegate_->GetWeakPtr(), gfx::RectF());
138 external_delegate_->GetWeakPtr(), gfx::RectF());
139 } 140 }
140 141
141 void TearDown() override { 142 void TearDown() override {
142 // This will make sure the controller and the view (if any) are both 143 // This will make sure the controller and the view (if any) are both
143 // cleaned up. 144 // cleaned up.
144 if (autofill_popup_controller_) 145 if (autofill_popup_controller_)
145 autofill_popup_controller_->DoHide(); 146 autofill_popup_controller_->DoHide();
146 147
147 external_delegate_.reset(); 148 external_delegate_.reset();
148 ChromeRenderViewHostTestHarness::TearDown(); 149 ChromeRenderViewHostTestHarness::TearDown();
149 } 150 }
150 151
151 TestAutofillPopupController* popup_controller() { 152 TestAutofillPopupController* popup_controller() {
152 return autofill_popup_controller_; 153 return autofill_popup_controller_;
153 } 154 }
154 155
155 MockAutofillExternalDelegate* delegate() { 156 MockAutofillExternalDelegate* delegate() {
156 return external_delegate_.get(); 157 return external_delegate_.get();
157 } 158 }
158 159
159 protected: 160 protected:
160 std::unique_ptr<MockAutofillClient> autofill_client_; 161 std::unique_ptr<MockAutofillClient> autofill_client_;
161 std::unique_ptr<NiceMock<MockAutofillExternalDelegate>> external_delegate_; 162 std::unique_ptr<NiceMock<MockAutofillExternalDelegate>> external_delegate_;
162 testing::NiceMock<TestAutofillPopupController>* autofill_popup_controller_; 163 NiceMock<TestAutofillPopupController>* autofill_popup_controller_;
163 }; 164 };
164 165
165 TEST_F(AutofillPopupControllerUnitTest, ChangeSelectedLine) { 166 TEST_F(AutofillPopupControllerUnitTest, ChangeSelectedLine) {
166 // Set up the popup. 167 // Set up the popup.
167 std::vector<Suggestion> suggestions; 168 std::vector<Suggestion> suggestions;
168 suggestions.push_back(Suggestion("", "", "", 0)); 169 suggestions.push_back(Suggestion("", "", "", 0));
169 suggestions.push_back(Suggestion("", "", "", 0)); 170 suggestions.push_back(Suggestion("", "", "", 0));
170 autofill_popup_controller_->Show(suggestions); 171 autofill_popup_controller_->Show(suggestions);
171 172
172 EXPECT_LT(autofill_popup_controller_->selected_line(), 0); 173 EXPECT_LT(autofill_popup_controller_->selected_line(), 0);
(...skipping 17 matching lines...) Expand all
190 // Set up the popup. 191 // Set up the popup.
191 std::vector<Suggestion> suggestions; 192 std::vector<Suggestion> suggestions;
192 suggestions.push_back(Suggestion("", "", "", 0)); 193 suggestions.push_back(Suggestion("", "", "", 0));
193 suggestions.push_back(Suggestion("", "", "", 0)); 194 suggestions.push_back(Suggestion("", "", "", 0));
194 autofill_popup_controller_->Show(suggestions); 195 autofill_popup_controller_->Show(suggestions);
195 196
196 // Make sure that when a new line is selected, it is invalidated so it can 197 // Make sure that when a new line is selected, it is invalidated so it can
197 // be updated to show it is selected. 198 // be updated to show it is selected.
198 int selected_line = 0; 199 int selected_line = 0;
199 EXPECT_CALL(*autofill_popup_controller_, InvalidateRow(selected_line)); 200 EXPECT_CALL(*autofill_popup_controller_, InvalidateRow(selected_line));
201 EXPECT_CALL(
202 *autofill_popup_controller_,
203 NotifyAccessibilityEventForRow(ui::AX_EVENT_SELECTION, selected_line));
200 autofill_popup_controller_->SetSelectedLine(selected_line); 204 autofill_popup_controller_->SetSelectedLine(selected_line);
201 205
202 // Ensure that the row isn't invalidated if it didn't change. 206 // Ensure that the row isn't invalidated if it didn't change.
203 EXPECT_CALL(*autofill_popup_controller_, 207 EXPECT_CALL(*autofill_popup_controller_,
204 InvalidateRow(selected_line)).Times(0); 208 InvalidateRow(selected_line)).Times(0);
209 EXPECT_CALL(*autofill_popup_controller_, NotifyAccessibilityEventForRow(_, _))
210 .Times(0);
205 autofill_popup_controller_->SetSelectedLine(selected_line); 211 autofill_popup_controller_->SetSelectedLine(selected_line);
206 212
207 // Change back to no selection. 213 // Change back to no selection.
208 EXPECT_CALL(*autofill_popup_controller_, InvalidateRow(selected_line)); 214 EXPECT_CALL(*autofill_popup_controller_, InvalidateRow(selected_line));
215 EXPECT_CALL(*autofill_popup_controller_, NotifyAccessibilityEventForRow(_, _))
216 .Times(0);
209 autofill_popup_controller_->SetSelectedLine(-1); 217 autofill_popup_controller_->SetSelectedLine(-1);
210 } 218 }
211 219
212 TEST_F(AutofillPopupControllerUnitTest, RemoveLine) { 220 TEST_F(AutofillPopupControllerUnitTest, RemoveLine) {
213 // Set up the popup. 221 // Set up the popup.
214 std::vector<Suggestion> suggestions; 222 std::vector<Suggestion> suggestions;
215 suggestions.push_back(Suggestion("", "", "", 1)); 223 suggestions.push_back(Suggestion("", "", "", 1));
216 suggestions.push_back(Suggestion("", "", "", 1)); 224 suggestions.push_back(Suggestion("", "", "", 1));
217 suggestions.push_back(Suggestion("", "", "", POPUP_ITEM_ID_AUTOFILL_OPTIONS)); 225 suggestions.push_back(Suggestion("", "", "", POPUP_ITEM_ID_AUTOFILL_OPTIONS));
218 autofill_popup_controller_->Show(suggestions); 226 autofill_popup_controller_->Show(suggestions);
(...skipping 28 matching lines...) Expand all
247 // Generate a popup. 255 // Generate a popup.
248 autofill::GenerateTestAutofillPopup(external_delegate_.get()); 256 autofill::GenerateTestAutofillPopup(external_delegate_.get());
249 257
250 // Select the only line. 258 // Select the only line.
251 autofill_popup_controller_->SetSelectedLine(0); 259 autofill_popup_controller_->SetSelectedLine(0);
252 260
253 // Remove the only line. There should be no row invalidation and the popup 261 // Remove the only line. There should be no row invalidation and the popup
254 // should then be hidden since there are no Autofill entries left. 262 // should then be hidden since there are no Autofill entries left.
255 EXPECT_CALL(*autofill_popup_controller_, Hide()); 263 EXPECT_CALL(*autofill_popup_controller_, Hide());
256 EXPECT_CALL(*autofill_popup_controller_, InvalidateRow(_)).Times(0); 264 EXPECT_CALL(*autofill_popup_controller_, InvalidateRow(_)).Times(0);
265 EXPECT_CALL(*autofill_popup_controller_, NotifyAccessibilityEventForRow(_, _))
Evan Stade 2017/03/06 21:45:33 perhaps it's beyond the scope of this change, but
csashi 2017/03/07 01:53:53 Done.
266 .Times(0);
257 EXPECT_TRUE(autofill_popup_controller_->RemoveSelectedLine()); 267 EXPECT_TRUE(autofill_popup_controller_->RemoveSelectedLine());
258 } 268 }
259 269
260 TEST_F(AutofillPopupControllerUnitTest, SkipSeparator) { 270 TEST_F(AutofillPopupControllerUnitTest, SkipSeparator) {
261 // Set up the popup. 271 // Set up the popup.
262 std::vector<Suggestion> suggestions; 272 std::vector<Suggestion> suggestions;
263 suggestions.push_back(Suggestion("", "", "", 1)); 273 suggestions.push_back(Suggestion("", "", "", 1));
264 suggestions.push_back(Suggestion("", "", "", POPUP_ITEM_ID_SEPARATOR)); 274 suggestions.push_back(Suggestion("", "", "", POPUP_ITEM_ID_SEPARATOR));
265 suggestions.push_back(Suggestion("", "", "", POPUP_ITEM_ID_AUTOFILL_OPTIONS)); 275 suggestions.push_back(Suggestion("", "", "", POPUP_ITEM_ID_AUTOFILL_OPTIONS));
266 autofill_popup_controller_->Show(suggestions); 276 autofill_popup_controller_->Show(suggestions);
(...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after
379 gfx::RectF(), base::i18n::UNKNOWN_DIRECTION); 389 gfx::RectF(), base::i18n::UNKNOWN_DIRECTION);
380 EXPECT_TRUE(controller.get()); 390 EXPECT_TRUE(controller.get());
381 391
382 WeakPtr<AutofillPopupControllerImpl> controller2 = 392 WeakPtr<AutofillPopupControllerImpl> controller2 =
383 AutofillPopupControllerImpl::GetOrCreate( 393 AutofillPopupControllerImpl::GetOrCreate(
384 controller, delegate.GetWeakPtr(), NULL, NULL, gfx::RectF(), 394 controller, delegate.GetWeakPtr(), NULL, NULL, gfx::RectF(),
385 base::i18n::UNKNOWN_DIRECTION); 395 base::i18n::UNKNOWN_DIRECTION);
386 EXPECT_EQ(controller.get(), controller2.get()); 396 EXPECT_EQ(controller.get(), controller2.get());
387 controller->Hide(); 397 controller->Hide();
388 398
389 testing::NiceMock<TestAutofillPopupController>* test_controller = 399 NiceMock<TestAutofillPopupController>* test_controller =
390 new testing::NiceMock<TestAutofillPopupController>(delegate.GetWeakPtr(), 400 new NiceMock<TestAutofillPopupController>(delegate.GetWeakPtr(),
391 gfx::RectF()); 401 gfx::RectF());
392 EXPECT_CALL(*test_controller, Hide()); 402 EXPECT_CALL(*test_controller, Hide());
393 403
394 gfx::RectF bounds(0.f, 0.f, 1.f, 2.f); 404 gfx::RectF bounds(0.f, 0.f, 1.f, 2.f);
395 base::WeakPtr<AutofillPopupControllerImpl> controller3 = 405 base::WeakPtr<AutofillPopupControllerImpl> controller3 =
396 AutofillPopupControllerImpl::GetOrCreate( 406 AutofillPopupControllerImpl::GetOrCreate(
397 test_controller->GetWeakPtr(), 407 test_controller->GetWeakPtr(),
398 delegate.GetWeakPtr(), 408 delegate.GetWeakPtr(),
399 NULL, 409 NULL,
400 NULL, 410 NULL,
401 bounds, 411 bounds,
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after
461 471
462 // The second element was shorter so it should be unchanged. 472 // The second element was shorter so it should be unchanged.
463 EXPECT_EQ(autofill_popup_controller_->GetSuggestionAt(1).value, 473 EXPECT_EQ(autofill_popup_controller_->GetSuggestionAt(1).value,
464 autofill_popup_controller_->GetElidedValueAt(1)); 474 autofill_popup_controller_->GetElidedValueAt(1));
465 EXPECT_EQ(autofill_popup_controller_->GetSuggestionAt(1).label, 475 EXPECT_EQ(autofill_popup_controller_->GetSuggestionAt(1).label,
466 autofill_popup_controller_->GetElidedLabelAt(1)); 476 autofill_popup_controller_->GetElidedLabelAt(1));
467 } 477 }
468 #endif 478 #endif
469 479
470 } // namespace autofill 480 } // namespace autofill
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698