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

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: Switches to CHECK to ensure crash is caught early. 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(
203 *autofill_popup_controller_,
204 NotifyAccessibilityEventForRow(ui::AX_EVENT_SELECTION, selected_line));
200 autofill_popup_controller_->SetSelectedLine(selected_line); 205 autofill_popup_controller_->SetSelectedLine(selected_line);
201 206
202 // Ensure that the row isn't invalidated if it didn't change. 207 // Ensure that the row isn't invalidated if it didn't change.
203 EXPECT_CALL(*autofill_popup_controller_, 208 EXPECT_CALL(*autofill_popup_controller_,
204 InvalidateRow(selected_line)).Times(0); 209 InvalidateRow(selected_line)).Times(0);
210 EXPECT_CALL(*autofill_popup_controller_, NotifyAccessibilityEventForRow(_, _))
211 .Times(0);
205 autofill_popup_controller_->SetSelectedLine(selected_line); 212 autofill_popup_controller_->SetSelectedLine(selected_line);
206 213
207 // Change back to no selection. 214 // Change back to no selection.
208 EXPECT_CALL(*autofill_popup_controller_, InvalidateRow(selected_line)); 215 EXPECT_CALL(*autofill_popup_controller_, InvalidateRow(selected_line));
216 EXPECT_CALL(*autofill_popup_controller_, NotifyAccessibilityEventForRow(_, _))
217 .Times(0);
209 autofill_popup_controller_->SetSelectedLine(-1); 218 autofill_popup_controller_->SetSelectedLine(-1);
210 } 219 }
211 220
212 TEST_F(AutofillPopupControllerUnitTest, RemoveLine) { 221 TEST_F(AutofillPopupControllerUnitTest, RemoveLine) {
213 // Set up the popup. 222 // Set up the popup.
214 std::vector<Suggestion> suggestions; 223 std::vector<Suggestion> suggestions;
215 suggestions.push_back(Suggestion("", "", "", 1)); 224 suggestions.push_back(Suggestion("", "", "", 1));
216 suggestions.push_back(Suggestion("", "", "", 1)); 225 suggestions.push_back(Suggestion("", "", "", 1));
217 suggestions.push_back(Suggestion("", "", "", POPUP_ITEM_ID_AUTOFILL_OPTIONS)); 226 suggestions.push_back(Suggestion("", "", "", POPUP_ITEM_ID_AUTOFILL_OPTIONS));
218 autofill_popup_controller_->Show(suggestions); 227 autofill_popup_controller_->Show(suggestions);
(...skipping 28 matching lines...) Expand all
247 // Generate a popup. 256 // Generate a popup.
248 autofill::GenerateTestAutofillPopup(external_delegate_.get()); 257 autofill::GenerateTestAutofillPopup(external_delegate_.get());
249 258
250 // Select the only line. 259 // Select the only line.
251 autofill_popup_controller_->SetSelectedLine(0); 260 autofill_popup_controller_->SetSelectedLine(0);
252 261
253 // Remove the only line. There should be no row invalidation and the popup 262 // 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. 263 // should then be hidden since there are no Autofill entries left.
255 EXPECT_CALL(*autofill_popup_controller_, Hide()); 264 EXPECT_CALL(*autofill_popup_controller_, Hide());
256 EXPECT_CALL(*autofill_popup_controller_, InvalidateRow(_)).Times(0); 265 EXPECT_CALL(*autofill_popup_controller_, InvalidateRow(_)).Times(0);
266 EXPECT_CALL(*autofill_popup_controller_, NotifyAccessibilityEventForRow(_, _))
267 .Times(0);
257 EXPECT_TRUE(autofill_popup_controller_->RemoveSelectedLine()); 268 EXPECT_TRUE(autofill_popup_controller_->RemoveSelectedLine());
258 } 269 }
259 270
260 TEST_F(AutofillPopupControllerUnitTest, SkipSeparator) { 271 TEST_F(AutofillPopupControllerUnitTest, SkipSeparator) {
261 // Set up the popup. 272 // Set up the popup.
262 std::vector<Suggestion> suggestions; 273 std::vector<Suggestion> suggestions;
263 suggestions.push_back(Suggestion("", "", "", 1)); 274 suggestions.push_back(Suggestion("", "", "", 1));
264 suggestions.push_back(Suggestion("", "", "", POPUP_ITEM_ID_SEPARATOR)); 275 suggestions.push_back(Suggestion("", "", "", POPUP_ITEM_ID_SEPARATOR));
265 suggestions.push_back(Suggestion("", "", "", POPUP_ITEM_ID_AUTOFILL_OPTIONS)); 276 suggestions.push_back(Suggestion("", "", "", POPUP_ITEM_ID_AUTOFILL_OPTIONS));
266 autofill_popup_controller_->Show(suggestions); 277 autofill_popup_controller_->Show(suggestions);
(...skipping 194 matching lines...) Expand 10 before | Expand all | Expand 10 after
461 472
462 // The second element was shorter so it should be unchanged. 473 // The second element was shorter so it should be unchanged.
463 EXPECT_EQ(autofill_popup_controller_->GetSuggestionAt(1).value, 474 EXPECT_EQ(autofill_popup_controller_->GetSuggestionAt(1).value,
464 autofill_popup_controller_->GetElidedValueAt(1)); 475 autofill_popup_controller_->GetElidedValueAt(1));
465 EXPECT_EQ(autofill_popup_controller_->GetSuggestionAt(1).label, 476 EXPECT_EQ(autofill_popup_controller_->GetSuggestionAt(1).label,
466 autofill_popup_controller_->GetElidedLabelAt(1)); 477 autofill_popup_controller_->GetElidedLabelAt(1));
467 } 478 }
468 #endif 479 #endif
469 480
470 } // namespace autofill 481 } // namespace autofill
OLDNEW
« no previous file with comments | « chrome/browser/ui/autofill/autofill_popup_controller_impl.cc ('k') | chrome/browser/ui/autofill/autofill_popup_view.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698