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

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

Issue 2670003002: Accessibility for Autofill Popup View in native code (Closed)
Patch Set: Inline implementation of AutofillPopupChildView. 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 81 matching lines...) Expand 10 before | Expand all | Expand 10 after
190 // Set up the popup. 192 // Set up the popup.
191 std::vector<Suggestion> suggestions; 193 std::vector<Suggestion> suggestions;
192 suggestions.push_back(Suggestion("", "", "", 0)); 194 suggestions.push_back(Suggestion("", "", "", 0));
193 suggestions.push_back(Suggestion("", "", "", 0)); 195 suggestions.push_back(Suggestion("", "", "", 0));
194 autofill_popup_controller_->Show(suggestions); 196 autofill_popup_controller_->Show(suggestions);
195 197
196 // Make sure that when a new line is selected, it is invalidated so it can 198 // Make sure that when a new line is selected, it is invalidated so it can
197 // be updated to show it is selected. 199 // be updated to show it is selected.
198 int selected_line = 0; 200 int selected_line = 0;
199 EXPECT_CALL(*autofill_popup_controller_, InvalidateRow(selected_line)); 201 EXPECT_CALL(*autofill_popup_controller_, InvalidateRow(selected_line));
202 EXPECT_CALL(*autofill_popup_controller_, NotifyAccessibilityEventForRow(
203 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(_, _))
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 194 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