Chromium Code Reviews| Index: chrome/browser/ui/views/autofill/autofill_popup_view_views_browsertest.cc |
| diff --git a/chrome/browser/ui/views/autofill/autofill_popup_view_views_browsertest.cc b/chrome/browser/ui/views/autofill/autofill_popup_view_views_browsertest.cc |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..e22985338c5de54625e9bf16f10b93dc8482b94d |
| --- /dev/null |
| +++ b/chrome/browser/ui/views/autofill/autofill_popup_view_views_browsertest.cc |
| @@ -0,0 +1,132 @@ |
| +// Copyright (c) 2012 The Chromium Authors. All rights reserved. |
|
sky
2017/03/06 18:02:57
No (c) and 2017.
csashi
2017/03/06 19:27:06
Done.
|
| +// Use of this source code is governed by a BSD-style license that can be |
| +// found in the LICENSE file. |
| + |
| +#include "chrome/browser/ui/views/autofill/autofill_popup_view_views.h" |
| + |
| +#include "base/macros.h" |
| +#include "base/strings/utf_string_conversions.h" |
| +#include "build/build_config.h" |
| +#include "chrome/browser/ui/autofill/autofill_popup_controller.h" |
| +#include "chrome/browser/ui/autofill/autofill_popup_layout_model.h" |
| +#include "chrome/browser/ui/browser.h" |
| +#include "chrome/browser/ui/browser_window.h" |
| +#include "chrome/browser/ui/tabs/tab_strip_model.h" |
| +#include "chrome/test/base/in_process_browser_test.h" |
| +#include "components/autofill/core/browser/suggestion.h" |
| +#include "testing/gmock/include/gmock/gmock.h" |
| +#include "testing/gtest/include/gtest/gtest.h" |
| +#include "ui/accessibility/ax_enums.h" |
| +#include "ui/gfx/geometry/rect.h" |
| +#include "ui/gfx/native_widget_types.h" |
| +#include "ui/native_theme/native_theme.h" |
| +#include "ui/views/widget/widget.h" |
| + |
| +using ::testing::NiceMock; |
| +using ::testing::Return; |
| + |
| +namespace autofill { |
| +namespace { |
| + |
| +const int kNumInitialSuggestions = 3; |
|
sky
2017/03/06 18:02:56
constexpr
csashi
2017/03/06 19:27:06
Done.
|
| + |
| +class MockAutofillPopupController : public AutofillPopupController { |
| + public: |
| + // AutofillPopupViewDelegate |
| + MOCK_METHOD0(Hide, void()); |
| + MOCK_METHOD0(ViewDestroyed, void()); |
| + MOCK_METHOD1(SetSelectionAtPoint, void(const gfx::Point& point)); |
| + MOCK_METHOD0(AcceptSelectedLine, bool()); |
| + MOCK_METHOD0(SelectionCleared, void()); |
| + MOCK_CONST_METHOD0(popup_bounds, gfx::Rect()); |
| + MOCK_METHOD0(container_view, gfx::NativeView()); |
| + MOCK_CONST_METHOD0(element_bounds, const gfx::RectF&()); |
| + MOCK_CONST_METHOD0(IsRTL, bool()); |
| + MOCK_METHOD0(GetSuggestions, const std::vector<autofill::Suggestion>()); |
| +#if !defined(OS_ANDROID) |
| + MOCK_METHOD1(GetElidedValueWidthForRow, int(size_t row)); |
| + MOCK_METHOD1(GetElidedLabelWidthForRow, int(size_t row)); |
| +#endif |
| + |
| + // AutofillPopupController |
| + MOCK_METHOD0(UpdateBoundsAndRedrawPopup, void()); |
| + MOCK_METHOD1(AcceptSuggestion, void(size_t index)); |
| + MOCK_CONST_METHOD0(GetLineCount, size_t()); |
| + MOCK_CONST_METHOD1(GetSuggestionAt, const autofill::Suggestion&(size_t row)); |
| + MOCK_CONST_METHOD1(GetElidedValueAt, const base::string16&(size_t row)); |
| + MOCK_CONST_METHOD1(GetElidedLabelAt, const base::string16&(size_t row)); |
| + MOCK_METHOD3(GetRemovalConfirmationText, |
| + bool(int index, base::string16* title, base::string16* body)); |
| + MOCK_METHOD1(RemoveSuggestion, bool(int index)); |
| + MOCK_CONST_METHOD1(GetBackgroundColorIDForRow, |
| + ui::NativeTheme::ColorId(int index)); |
| + MOCK_CONST_METHOD0(selected_line, int()); |
| + MOCK_CONST_METHOD0(layout_model, const AutofillPopupLayoutModel&()); |
| +}; |
|
sky
2017/03/06 18:02:57
private: DISALLOW...
csashi
2017/03/06 19:27:06
Done.
|
| + |
| +class TestAutofillPopupViewViews : public AutofillPopupViewViews { |
| + public: |
| + TestAutofillPopupViewViews(AutofillPopupController* controller, |
| + views::Widget* parent_widget) |
| + : AutofillPopupViewViews(controller, parent_widget) {} |
| + ~TestAutofillPopupViewViews() override {} |
| + |
| + void DoUpdateBoundsAndRedrawPopup() override {} |
| +}; |
|
sky
2017/03/06 18:02:57
private: DISALLOW...
csashi
2017/03/06 19:27:07
Done.
|
| + |
| +} // namespace |
| + |
| +class AutofillPopupViewViewsTest : public InProcessBrowserTest { |
| + public: |
| + AutofillPopupViewViewsTest() {} |
| + ~AutofillPopupViewViewsTest() override {} |
| + |
| + void SetUpOnMainThread() override { |
| + gfx::NativeView native_view = |
| + browser()->tab_strip_model()->GetActiveWebContents()->GetNativeView(); |
| + EXPECT_CALL(autofill_popup_controller_, container_view()) |
| + .WillRepeatedly(Return(native_view)); |
| + EXPECT_CALL(autofill_popup_controller_, GetLineCount()) |
| + .WillRepeatedly(Return(kNumInitialSuggestions)); |
| + autofill_popup_view_views_ = new TestAutofillPopupViewViews( |
| + &autofill_popup_controller_, |
| + views::Widget::GetWidgetForNativeWindow( |
| + browser()->window()->GetNativeWindow())); |
| + } |
| + |
| + protected: |
| + NiceMock<MockAutofillPopupController> autofill_popup_controller_; |
| + // We intentionally do not destroy this view in the test because of |
|
sky
2017/03/06 18:02:57
This it leak then? If so, that seems potentially e
csashi
2017/03/06 19:27:06
The browser_tests runs fine. If this is important,
|
| + // difficulty in mocking out 'RemoveObserver'. |
| + TestAutofillPopupViewViews* autofill_popup_view_views_; |
| +}; |
|
sky
2017/03/06 18:02:57
private: DISALLOW...
csashi
2017/03/06 19:27:06
Done.
|
| + |
| +IN_PROC_BROWSER_TEST_F(AutofillPopupViewViewsTest, |
| + NotifyAccessibilityEventForRow) { |
| + for (int i = 0; i < kNumInitialSuggestions; ++i) { |
| + autofill_popup_view_views_->NotifyAccessibilityEventForRow( |
| + ui::AX_EVENT_SELECTION, i); |
| + } |
| + |
| + // Increase number of suggestions. |
| + EXPECT_CALL(autofill_popup_controller_, GetLineCount()) |
| + .WillRepeatedly(Return(kNumInitialSuggestions + 1)); |
| + |
| + autofill_popup_view_views_->UpdateBoundsAndRedrawPopup(); |
| + for (int i = 0; i < kNumInitialSuggestions + 1; ++i) { |
| + autofill_popup_view_views_->NotifyAccessibilityEventForRow( |
| + ui::AX_EVENT_SELECTION, i); |
| + } |
| + |
| + // Decrease number of suggestions. |
| + EXPECT_CALL(autofill_popup_controller_, GetLineCount()) |
| + .WillRepeatedly(Return(kNumInitialSuggestions - 1)); |
| + |
| + autofill_popup_view_views_->UpdateBoundsAndRedrawPopup(); |
| + for (int i = 0; i < kNumInitialSuggestions - 1; ++i) { |
| + autofill_popup_view_views_->NotifyAccessibilityEventForRow( |
| + ui::AX_EVENT_SELECTION, i); |
| + } |
| +} |
| + |
| +} // namespace autofill |