#include <optional>
#include <string>
#include <vector>
#include "ash/test/pixel/ash_pixel_differ.h"
#include "ash/test/pixel/ash_pixel_test_init_params.h"
#include "ash/user_education/user_education_types.h"
#include "ash/user_education/views/help_bubble_view_ash.h"
#include "ash/user_education/views/help_bubble_view_ash_test_base.h"
#include "base/strings/string_util.h"
#include "components/user_education/common/help_bubble/help_bubble_params.h"
#include "testing/gtest/include/gtest/gtest.h"
#include "ui/gfx/color_palette.h"
#include "ui/views/view.h"
#include "ui/views/widget/widget.h"
namespace ash {
namespace {
using user_education::HelpBubbleArrow;
void EmplaceBackIf(std::vector<std::string>& container,
std::string value,
bool condition) {
if (condition) {
container.emplace_back(std::move(value));
}
}
}
class HelpBubbleViewAshPixelTestBase : public HelpBubbleViewAshTestBase {
public:
HelpBubbleViewAshPixelTestBase() = default;
private:
std::optional<pixel_test::InitParams> CreatePixelTestInitParams()
const override {
return pixel_test::InitParams();
}
};
class HelpBubbleViewAshPixelTest
: public HelpBubbleViewAshPixelTestBase,
public testing::WithParamInterface<std::tuple<
/*with_title_text=*/bool,
/*with_body_icon=*/bool,
/*with_buttons=*/bool,
/*with_progress=*/bool>> {
public:
bool with_title_text() const { return std::get<0>(GetParam()); }
bool with_body_icon() const { return std::get<1>(GetParam()); }
bool with_buttons() const { return std::get<2>(GetParam()); }
bool with_progress() const { return std::get<3>(GetParam()); }
};
INSTANTIATE_TEST_SUITE_P(
All,
HelpBubbleViewAshPixelTest,
testing::Combine(
testing::Bool(),
testing::Bool(),
testing::Bool(),
testing::Bool()),
[](const auto& info) {
std::vector<std::string> param_name{"HelpBubbleViewAsh"};
EmplaceBackIf(param_name, "WithTitleText", std::get<0>(info.param));
EmplaceBackIf(param_name, "WithBodyIcon", std::get<1>(info.param));
EmplaceBackIf(param_name, "WithButtons", std::get<2>(info.param));
EmplaceBackIf(param_name, "WithProgress", std::get<3>(info.param));
return base::JoinString(param_name, "_");
});
TEST_P(HelpBubbleViewAshPixelTest, Appearance) {
auto* help_bubble_view =
CreateHelpBubbleView(HelpBubbleArrow::kNone, with_title_text(),
with_body_icon(), with_buttons(), with_progress());
EXPECT_TRUE(GetPixelDiffer()->CompareUiComponentsOnPrimaryScreen(
"appearance", 9, help_bubble_view,
help_bubble_view->anchor_widget()));
}
class HelpBubbleViewAshArrowPixelTest
: public HelpBubbleViewAshPixelTestBase,
public testing::WithParamInterface<HelpBubbleArrow> {
public:
HelpBubbleArrow arrow() const { return GetParam(); }
};
#define ENUM_CASE(Enum, Value) \
case Enum::Value: \
return #Enum "_" #Value;
INSTANTIATE_TEST_SUITE_P(All,
HelpBubbleViewAshArrowPixelTest,
testing::Values(HelpBubbleArrow::kNone,
HelpBubbleArrow::kTopLeft,
HelpBubbleArrow::kTopRight,
HelpBubbleArrow::kBottomLeft,
HelpBubbleArrow::kBottomRight,
HelpBubbleArrow::kLeftTop,
HelpBubbleArrow::kRightTop,
HelpBubbleArrow::kLeftBottom,
HelpBubbleArrow::kRightBottom,
HelpBubbleArrow::kTopCenter,
HelpBubbleArrow::kBottomCenter,
HelpBubbleArrow::kLeftCenter,
HelpBubbleArrow::kRightCenter),
[](const auto& info) {
switch (info.param) {
ENUM_CASE(HelpBubbleArrow, kNone);
ENUM_CASE(HelpBubbleArrow, kTopLeft);
ENUM_CASE(HelpBubbleArrow, kTopRight);
ENUM_CASE(HelpBubbleArrow, kBottomLeft);
ENUM_CASE(HelpBubbleArrow, kBottomRight);
ENUM_CASE(HelpBubbleArrow, kLeftTop);
ENUM_CASE(HelpBubbleArrow, kRightTop);
ENUM_CASE(HelpBubbleArrow, kLeftBottom);
ENUM_CASE(HelpBubbleArrow, kRightBottom);
ENUM_CASE(HelpBubbleArrow, kTopCenter);
ENUM_CASE(HelpBubbleArrow, kBottomCenter);
ENUM_CASE(HelpBubbleArrow, kLeftCenter);
ENUM_CASE(HelpBubbleArrow, kRightCenter);
}
});
TEST_P(HelpBubbleViewAshArrowPixelTest, Placement) {
auto* help_bubble_view = CreateHelpBubbleView(
arrow(), true, true,
true, true);
EXPECT_TRUE(GetPixelDiffer()->CompareUiComponentsOnPrimaryScreen(
"placement", 9, help_bubble_view,
help_bubble_view->anchor_widget()));
}
}