Skip to content

Commit

Permalink
Complete registration of views for Welcome Tour.
Browse files Browse the repository at this point in the history
This CL completes registration of views for the Welcome Tour by
registering the following in the apps grid:

* Help app
* Settings app

Bug: b:275616974
Change-Id: I4ad8ca6e080eacd892690ba5dcb075cfba92e798
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/4571619
Commit-Queue: David Black <dmblack@google.com>
Reviewed-by: Toni Barzic <tbarzic@chromium.org>
Cr-Commit-Position: refs/heads/main@{#1150021}
  • Loading branch information
David Black authored and Chromium LUCI CQ committed May 27, 2023
1 parent 2fd59b2 commit f4008ef
Show file tree
Hide file tree
Showing 4 changed files with 179 additions and 83 deletions.
15 changes: 15 additions & 0 deletions ash/app_list/views/app_list_item_view.cc
Expand Up @@ -30,6 +30,8 @@
#include "ash/style/dot_indicator.h"
#include "ash/style/style_util.h"
#include "ash/style/typography.h"
#include "ash/user_education/user_education_class_properties.h"
#include "ash/user_education/user_education_controller.h"
#include "base/auto_reset.h"
#include "base/check.h"
#include "base/functional/bind.h"
Expand All @@ -40,6 +42,7 @@
#include "base/time/time.h"
#include "cc/paint/paint_flags.h"
#include "chromeos/constants/chromeos_features.h"
#include "third_party/abseil-cpp/absl/types/optional.h"
#include "third_party/skia/include/core/SkCanvas.h"
#include "third_party/skia/include/core/SkColor.h"
#include "ui/accessibility/ax_node_data.h"
Expand Down Expand Up @@ -73,6 +76,7 @@
#include "ui/views/controls/label.h"
#include "ui/views/controls/menu/menu_runner.h"
#include "ui/views/focus/focus_manager.h"
#include "ui/views/view_class_properties.h"
#include "ui/views/view_utils.h"
#include "ui/views/widget/widget.h"

Expand Down Expand Up @@ -606,6 +610,17 @@ AppListItemView::AppListItemView(const AppListConfig* app_list_config,
SetAnimationDuration(base::TimeDelta());

preview_circle_radius_ = 0;

if (features::IsUserEducationEnabled() && context == Context::kAppsGridView) {
if (absl::optional<ui::ElementIdentifier> element_identifier =
UserEducationController::Get()->GetElementIdentifierForAppId(
item->id())) {
// NOTE: Set `kHelpBubbleContextKey` before `views::kElementIdentifierKey`
// in case registration causes a help bubble to be created synchronously.
SetProperty(kHelpBubbleContextKey, HelpBubbleContext::kAsh);
SetProperty(views::kElementIdentifierKey, *element_identifier);
}
}
}

void AppListItemView::InitializeIconLoader() {
Expand Down
36 changes: 28 additions & 8 deletions ash/user_education/welcome_tour/welcome_tour_controller.cc
Expand Up @@ -103,7 +103,6 @@ ui::ElementContext WelcomeTourController::GetInitialElementContext() const {
GetMatchingViewInPrimaryRootWindow(kShelfViewElementId));
}

// TODO(http://b/275616974): Implement tutorial descriptions.
std::map<TutorialId, user_education::TutorialDescription>
WelcomeTourController::GetTutorialDescriptions() {
std::map<TutorialId, user_education::TutorialDescription>
Expand Down Expand Up @@ -132,7 +131,8 @@ WelcomeTourController::GetTutorialDescriptions() {
user_education::kHelpBubbleNextButtonClickedEvent,
kShelfViewElementId)
.NameElements(NameMatchingElementInPrimaryRootWindowCallback(
kUnifiedSystemTrayElementId, kUnifiedSystemTrayElementName)));
kUnifiedSystemTrayElementId, kUnifiedSystemTrayElementName))
.InSameContext());

// Step 2: Status area.
tutorial_description.steps.emplace_back(
Expand All @@ -141,7 +141,8 @@ WelcomeTourController::GetTutorialDescriptions() {
.SetBubbleBodyText(IDS_ASH_WELCOME_TOUR_STATUS_AREA_BUBBLE_BODY_TEXT)
.SetExtendedProperties(user_education_util::CreateExtendedProperties(
HelpBubbleId::kWelcomeTourStatusArea))
.AddDefaultNextButton());
.AddDefaultNextButton()
.InAnyContext());

// Wait for "Next" button click before proceeding to the next bubble step.
// NOTE: This event step also ensures that the next bubble step will show on
Expand All @@ -151,7 +152,8 @@ WelcomeTourController::GetTutorialDescriptions() {
user_education::kHelpBubbleNextButtonClickedEvent,
kUnifiedSystemTrayElementName)
.NameElements(NameMatchingElementInPrimaryRootWindowCallback(
kHomeButtonElementId, kHomeButtonElementName)));
kHomeButtonElementId, kHomeButtonElementName))
.InSameContext());

// Step 3: Home button.
tutorial_description.steps.emplace_back(
Expand All @@ -162,8 +164,10 @@ WelcomeTourController::GetTutorialDescriptions() {
.AddCustomNextButton(base::BindRepeating([](ui::TrackedElement*) {
Shell::Get()->app_list_controller()->Show(
GetPrimaryDisplayId(), AppListShowSource::kWelcomeTour,
ui::EventTimeForNow(), /*should_record_metrics=*/true);
})));
ui::EventTimeForNow(),
/*should_record_metrics=*/true);
}))
.InAnyContext());

// Step 4: Search box.
tutorial_description.steps.emplace_back(
Expand All @@ -174,20 +178,36 @@ WelcomeTourController::GetTutorialDescriptions() {
.AddDefaultNextButton()
.InAnyContext());

// Wait for "Next" button click before proceeding to the next bubble step.
tutorial_description.steps.emplace_back(
user_education::TutorialDescription::EventStep(
user_education::kHelpBubbleNextButtonClickedEvent,
kSearchBoxViewElementId)
.InSameContext());

// Step 5: Settings app.
tutorial_description.steps.emplace_back(
user_education::TutorialDescription::BubbleStep(kSettingsAppElementId)
.SetBubbleBodyText(IDS_ASH_WELCOME_TOUR_SETTINGS_APP_BUBBLE_BODY_TEXT)
.SetExtendedProperties(user_education_util::CreateExtendedProperties(
HelpBubbleId::kWelcomeTourSettingsApp))
.AddDefaultNextButton());
.AddDefaultNextButton()
.InSameContext());

// Wait for "Next" button click before proceeding to the next bubble step.
tutorial_description.steps.emplace_back(
user_education::TutorialDescription::EventStep(
user_education::kHelpBubbleNextButtonClickedEvent,
kSettingsAppElementId)
.InSameContext());

// Step 6: Explore app.
tutorial_description.steps.emplace_back(
user_education::TutorialDescription::BubbleStep(kExploreAppElementId)
.SetBubbleBodyText(IDS_ASH_WELCOME_TOUR_EXPLORE_APP_BUBBLE_BODY_TEXT)
.SetExtendedProperties(user_education_util::CreateExtendedProperties(
HelpBubbleId::kWelcomeTourExploreApp)));
HelpBubbleId::kWelcomeTourExploreApp))
.InSameContext());

return tutorial_descriptions_by_id;
}
Expand Down
91 changes: 54 additions & 37 deletions ash/user_education/welcome_tour/welcome_tour_controller_unittest.cc
Expand Up @@ -38,10 +38,12 @@ using ::testing::Contains;
using ::testing::ElementsAre;
using ::testing::Eq;
using ::testing::Field;
using ::testing::Matches;
using ::testing::Pair;
using ::testing::StrictMock;
using ::user_education::TutorialDescription;

using ContextMode = TutorialDescription::ContextMode;
using ElementSpecifier = TutorialDescription::ElementSpecifier;

// Actions ---------------------------------------------------------------------
Expand All @@ -60,18 +62,8 @@ auto MoveArgs(T*... out) {

// Matchers --------------------------------------------------------------------

MATCHER_P4(BubbleStep,
help_bubble_id,
element_specifier,
body_text_id,
has_next_button,
"") {
namespace util = user_education_util;
return arg.step_type == ui::InteractionSequence::StepType::kShown &&
util::GetHelpBubbleId(arg.extended_properties) == help_bubble_id &&
arg.body_text_id == body_text_id &&
arg.next_button_callback.is_null() != has_next_button &&
absl::visit(base::Overloaded{
MATCHER_P(ElementSpecifierEq, element_specifier, "") {
return absl::visit(base::Overloaded{
[&](const ui::ElementIdentifier& element_id) {
return arg.element_id == element_id &&
arg.element_name.empty();
Expand All @@ -84,20 +76,31 @@ MATCHER_P4(BubbleStep,
element_specifier);
}

MATCHER_P2(EventStep, element_specifier, has_name_elements_callback, "") {
MATCHER_P5(BubbleStep,
element_specifier,
context_mode,
help_bubble_id,
body_text_id,
has_next_button,
"") {
namespace util = user_education_util;
return arg.step_type == ui::InteractionSequence::StepType::kShown &&
Matches(ElementSpecifierEq(element_specifier))(arg) &&
arg.context_mode == context_mode &&
util::GetHelpBubbleId(arg.extended_properties) == help_bubble_id &&
arg.body_text_id == body_text_id &&
arg.next_button_callback.is_null() != has_next_button;
}

MATCHER_P3(EventStep,
element_specifier,
context_mode,
has_name_elements_callback,
"") {
return arg.step_type == ui::InteractionSequence::StepType::kCustomEvent &&
arg.name_elements_callback.is_null() != has_name_elements_callback &&
absl::visit(base::Overloaded{
[&](const ui::ElementIdentifier& element_id) {
return arg.element_id == element_id &&
arg.element_name.empty();
},
[&](const std::string& element_name) {
return arg.element_name == element_name &&
arg.element_id == ui::ElementIdentifier();
},
},
element_specifier);
Matches(ElementSpecifierEq(element_specifier))(arg) &&
arg.context_mode == context_mode &&
arg.name_elements_callback.is_null() != has_name_elements_callback;
}

} // namespace
Expand Down Expand Up @@ -138,32 +141,46 @@ TEST_F(WelcomeTourControllerTest, GetTutorialDescriptions) {
Field(
&TutorialDescription::steps,
ElementsAre(
BubbleStep(HelpBubbleId::kWelcomeTourShelf,
ElementSpecifier(kShelfViewElementId),
BubbleStep(ElementSpecifier(kShelfViewElementId),
ContextMode::kInitial,
HelpBubbleId::kWelcomeTourShelf,
IDS_ASH_WELCOME_TOUR_SHELF_BUBBLE_BODY_TEXT,
/*has_next_button=*/true),
EventStep(ElementSpecifier(kShelfViewElementId),
ContextMode::kFromPreviousStep,
/*has_name_elements_callback=*/true),
BubbleStep(HelpBubbleId::kWelcomeTourStatusArea,
ElementSpecifier(kUnifiedSystemTrayElementName),
BubbleStep(ElementSpecifier(kUnifiedSystemTrayElementName),
ContextMode::kAny,
HelpBubbleId::kWelcomeTourStatusArea,
IDS_ASH_WELCOME_TOUR_STATUS_AREA_BUBBLE_BODY_TEXT,
/*has_next_button=*/true),
EventStep(ElementSpecifier(kUnifiedSystemTrayElementName),
ContextMode::kFromPreviousStep,
/*has_name_elements_callback=*/true),
BubbleStep(HelpBubbleId::kWelcomeTourHomeButton,
ElementSpecifier(kHomeButtonElementName),
BubbleStep(ElementSpecifier(kHomeButtonElementName),
ContextMode::kAny,
HelpBubbleId::kWelcomeTourHomeButton,
IDS_ASH_WELCOME_TOUR_HOME_BUTTON_BUBBLE_BODY_TEXT,
/*has_next_button=*/true),
BubbleStep(HelpBubbleId::kWelcomeTourSearchBox,
ElementSpecifier(kSearchBoxViewElementId),
BubbleStep(ElementSpecifier(kSearchBoxViewElementId),
ContextMode::kAny,
HelpBubbleId::kWelcomeTourSearchBox,
IDS_ASH_WELCOME_TOUR_SEARCH_BOX_BUBBLE_BODY_TEXT,
/*has_next_button=*/true),
BubbleStep(HelpBubbleId::kWelcomeTourSettingsApp,
ElementSpecifier(kSettingsAppElementId),
EventStep(ElementSpecifier(kSearchBoxViewElementId),
ContextMode::kFromPreviousStep,
/*has_name_elements_callback=*/false),
BubbleStep(ElementSpecifier(kSettingsAppElementId),
ContextMode::kFromPreviousStep,
HelpBubbleId::kWelcomeTourSettingsApp,
IDS_ASH_WELCOME_TOUR_SETTINGS_APP_BUBBLE_BODY_TEXT,
/*has_next_button=*/true),
BubbleStep(HelpBubbleId::kWelcomeTourExploreApp,
ElementSpecifier(kExploreAppElementId),
EventStep(ElementSpecifier(kSettingsAppElementId),
ContextMode::kFromPreviousStep,
/*has_name_elements_callback=*/false),
BubbleStep(ElementSpecifier(kExploreAppElementId),
ContextMode::kFromPreviousStep,
HelpBubbleId::kWelcomeTourExploreApp,
IDS_ASH_WELCOME_TOUR_EXPLORE_APP_BUBBLE_BODY_TEXT,
/*has_next_button=*/false))))));
}
Expand Down

0 comments on commit f4008ef

Please sign in to comment.