-
Notifications
You must be signed in to change notification settings - Fork 6.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add pixel tests for Autofill popups.
This CL adds pixel tests for Autofill popups. These pixel tests add a test case for every AutofillPopupRowView subclass. At the same time, they are not exhaustive in the current state: 1) They do not test the widget border 2) They do not test every possible autofill::Suggestion setup 3) They do not test hover/ selection status. Changing 1) would require changing how screenshots are taken in the pixel test setup. 2) and 3) can be addressed in follow-up work, but it will likely not be necessary to reproduce every possible type of suggestion to test all variations of AutofillPopupRowView. Bug: 1411172 Change-Id: Iad147323e5675f10c451ed93bec9585464bb97ce Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/4203632 Commit-Queue: Jan Keitel <jkeitel@google.com> Reviewed-by: Christoph Schwering <schwering@google.com> Reviewed-by: Mohamed Amir Yosef <mamir@chromium.org> Cr-Commit-Position: refs/heads/main@{#1100363}
- Loading branch information
Jan Keitel
authored and
Chromium LUCI CQ
committed
Feb 2, 2023
1 parent
fcc7c88
commit db3c3f9
Showing
5 changed files
with
224 additions
and
45 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
182 changes: 182 additions & 0 deletions
182
chrome/browser/ui/views/autofill/autofill_popup_view_native_views_browsertest.cc
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,182 @@ | ||
// Copyright 2023 The Chromium Authors | ||
// 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_native_views.h" | ||
|
||
#include <tuple> | ||
#include <utility> | ||
|
||
#include "base/memory/raw_ptr.h" | ||
#include "base/scoped_environment_variable_override.h" | ||
#include "base/strings/strcat.h" | ||
#include "chrome/browser/autofill/mock_autofill_popup_controller.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/browser/ui/test/test_browser_ui.h" | ||
#include "chrome/test/base/in_process_browser_test.h" | ||
#include "chrome/test/base/ui_test_utils.h" | ||
#include "components/autofill/core/browser/ui/suggestion.h" | ||
#include "components/strings/grit/components_strings.h" | ||
#include "content/public/test/browser_test.h" | ||
#include "testing/gmock/include/gmock/gmock.h" | ||
#include "testing/gtest/include/gtest/gtest.h" | ||
#include "ui/base/l10n/l10n_util.h" | ||
#include "ui/base/ui_base_switches.h" | ||
#include "ui/gfx/render_text.h" | ||
#include "ui/views/widget/widget.h" | ||
|
||
namespace autofill { | ||
|
||
using testing::NiceMock; | ||
using testing::Return; | ||
|
||
// If the boolean test parameter is `true`, dark mode is enforced. | ||
class AutofillPopupViewNativeViewsTest | ||
: public UiBrowserTest, | ||
public testing::WithParamInterface<bool> { | ||
public: | ||
AutofillPopupViewNativeViewsTest() = default; | ||
~AutofillPopupViewNativeViewsTest() override = default; | ||
|
||
void SetUpCommandLine(base::CommandLine* command_line) override { | ||
if (GetParam()) { | ||
command_line->AppendSwitch(switches::kForceDarkMode); | ||
} | ||
} | ||
|
||
void SetUpOnMainThread() override { | ||
content::WebContents* web_contents = | ||
browser()->tab_strip_model()->GetActiveWebContents(); | ||
gfx::NativeView native_view = web_contents->GetNativeView(); | ||
EXPECT_CALL(controller_, container_view()) | ||
.WillRepeatedly(Return(native_view)); | ||
EXPECT_CALL(controller_, GetWebContents()) | ||
.WillRepeatedly(Return(web_contents)); | ||
} | ||
|
||
void PrepareSuggestions(std::vector<Suggestion> suggestions) { | ||
controller_.set_suggestions(std::move(suggestions)); | ||
} | ||
|
||
void ShowUi(const std::string& name) override { | ||
EXPECT_CALL(controller_, ViewDestroyed()); | ||
view_ = new AutofillPopupViewNativeViews( | ||
controller_.GetWeakPtr(), views::Widget::GetWidgetForNativeWindow( | ||
browser()->window()->GetNativeWindow())); | ||
view_->Show(); | ||
} | ||
|
||
bool VerifyUi() override { | ||
if (!view_) { | ||
return false; | ||
} | ||
|
||
views::Widget* widget = view_->GetWidget(); | ||
if (!widget) { | ||
return false; | ||
} | ||
|
||
// VerifyPixelUi works only for these platforms. | ||
// TODO(crbug.com/958242): Revise this if supported platforms change. | ||
#if BUILDFLAG(IS_WIN) || (BUILDFLAG(IS_LINUX) || BUILDFLAG(IS_CHROMEOS_LACROS)) | ||
auto* test_info = testing::UnitTest::GetInstance()->current_test_info(); | ||
const std::string screenshot_name = | ||
base::StrCat({test_info->test_case_name(), "_", test_info->name()}); | ||
|
||
return VerifyPixelUi(widget, "AutofillPopupViewNativeViewsTest", | ||
screenshot_name); | ||
#else | ||
return true; | ||
#endif | ||
} | ||
|
||
void WaitForUserDismissal() override { | ||
ui_test_utils::WaitForBrowserToClose(); | ||
} | ||
|
||
void TearDownOnMainThread() override { view_ = nullptr; } | ||
|
||
private: | ||
std::unique_ptr<base::ScopedEnvironmentVariableOverride> scoped_env_override_; | ||
NiceMock<autofill::MockAutofillPopupController> controller_; | ||
raw_ptr<AutofillPopupViewNativeViews> view_ = nullptr; | ||
}; | ||
|
||
IN_PROC_BROWSER_TEST_P(AutofillPopupViewNativeViewsTest, | ||
InvokeUi_Autocomplete) { | ||
PrepareSuggestions({Suggestion("Autocomplete entry 1", "", "", 0), | ||
Suggestion("Autocomplete entry 2", "", "", 0)}); | ||
ShowAndVerifyUi(); | ||
} | ||
|
||
IN_PROC_BROWSER_TEST_P(AutofillPopupViewNativeViewsTest, | ||
InvokeUi_Autofill_Profile) { | ||
std::vector<Suggestion> suggestions; | ||
suggestions.emplace_back("123 Apple St.", "Charles", "accountIcon", 1); | ||
suggestions.emplace_back("3734 Elvis Presley Blvd.", "Elvis", "accountIcon", | ||
2); | ||
|
||
suggestions.emplace_back(POPUP_ITEM_ID_SEPARATOR); | ||
|
||
Suggestion settings(l10n_util::GetStringUTF16(IDS_AUTOFILL_MANAGE_ADDRESSES)); | ||
settings.frontend_id = POPUP_ITEM_ID_AUTOFILL_OPTIONS; | ||
settings.icon = "settingsIcon"; | ||
suggestions.push_back(std::move(settings)); | ||
|
||
PrepareSuggestions(std::move(suggestions)); | ||
ShowAndVerifyUi(); | ||
} | ||
|
||
IN_PROC_BROWSER_TEST_P(AutofillPopupViewNativeViewsTest, | ||
InvokeUi_Passwords_PasswordField) { | ||
// An account store entry. | ||
std::vector<Suggestion> suggestions; | ||
Suggestion entry1(u"User1"); | ||
entry1.main_text.is_primary = Suggestion::Text::IsPrimary(true); | ||
entry1.additional_label = | ||
std::u16string(10, gfx::RenderText::kPasswordReplacementChar); | ||
entry1.frontend_id = POPUP_ITEM_ID_ACCOUNT_STORAGE_PASSWORD_ENTRY; | ||
entry1.icon = "globeIcon"; | ||
entry1.trailing_icon = "google"; | ||
suggestions.push_back(std::move(entry1)); | ||
|
||
// A profile store entry. | ||
Suggestion entry2(u"User2"); | ||
entry2.main_text.is_primary = Suggestion::Text::IsPrimary(true); | ||
entry2.additional_label = | ||
std::u16string(6, gfx::RenderText::kPasswordReplacementChar); | ||
entry2.frontend_id = POPUP_ITEM_ID_PASSWORD_ENTRY; | ||
entry2.icon = "globeIcon"; | ||
entry2.trailing_icon = ""; | ||
suggestions.push_back(std::move(entry2)); | ||
|
||
suggestions.emplace_back(POPUP_ITEM_ID_SEPARATOR); | ||
|
||
// The entry to open settings. | ||
Suggestion settings( | ||
l10n_util::GetStringUTF16(IDS_PASSWORD_MANAGER_MANAGE_PASSWORDS)); | ||
settings.frontend_id = POPUP_ITEM_ID_ALL_SAVED_PASSWORDS_ENTRY; | ||
settings.icon = "settingsIcon"; | ||
settings.trailing_icon = "googlePasswordManager"; | ||
suggestions.push_back(std::move(settings)); | ||
|
||
PrepareSuggestions(std::move(suggestions)); | ||
ShowAndVerifyUi(); | ||
} | ||
|
||
IN_PROC_BROWSER_TEST_P(AutofillPopupViewNativeViewsTest, | ||
InvokeUi_InsecureContext_PaymentDisabled) { | ||
Suggestion warning( | ||
l10n_util::GetStringUTF16(IDS_AUTOFILL_WARNING_INSECURE_CONNECTION)); | ||
warning.frontend_id = POPUP_ITEM_ID_INSECURE_CONTEXT_PAYMENT_DISABLED_MESSAGE; | ||
PrepareSuggestions({std::move(warning)}); | ||
ShowAndVerifyUi(); | ||
} | ||
|
||
INSTANTIATE_TEST_SUITE_P(All, | ||
AutofillPopupViewNativeViewsTest, | ||
testing::Bool()); | ||
|
||
} // namespace autofill |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters