Commit 6f02374d authored by Jeroen Dhollander's avatar Jeroen Dhollander Committed by Commit Bot

Introduce AssistantTestApi.

This API can be used from both ash and browser tests, and exposes
handlers to access, inspect and use the Embedded Assistant UI.

In this CL I also update the Assistant code to use a specific set of
view IDs. This makes it easier to find a specific view during the
unittests (and removes the need for the |GetDescendantViewByName|
methods that I introduced earlier).

BUG: b/141264108
Change-Id: Ib50bae7be1f14c4ce3aabbb31b8a5689b6300619
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1873291
Commit-Queue: Jeroen Dhollander <jeroendh@google.com>
Reviewed-by: default avatarXiaohui Chen <xiaohuic@chromium.org>
Reviewed-by: default avatarXiyuan Xia <xiyuan@chromium.org>
Reviewed-by: default avatarTao Wu <wutao@chromium.org>
Cr-Commit-Position: refs/heads/master@{#709158}
parent 983ae744
......@@ -2203,6 +2203,7 @@ static_library("test_support") {
public = [
"public/cpp/shelf_test_api.h",
"public/cpp/system_tray_test_api.h",
"public/cpp/test/assistant_test_api.h",
]
sources = [
"accessibility/test_accessibility_controller_client.cc",
......@@ -2211,6 +2212,8 @@ static_library("test_support") {
"app_list/test/app_list_test_helper.h",
"app_list/test/test_app_list_client.cc",
"app_list/test/test_app_list_client.h",
"app_list/views/assistant/assistant_test_api_impl.cc",
"app_list/views/assistant/assistant_test_api_impl.h",
"app_menu/notification_menu_view_test_api.cc",
"app_menu/notification_menu_view_test_api.h",
"assistant/test/assistant_ash_test_base.cc",
......@@ -2345,6 +2348,7 @@ static_library("test_support") {
"//ash/app_list:test_support",
"//ash/app_menu",
"//ash/assistant/model:model",
"//ash/assistant/ui:ui",
"//ash/components/fast_ink",
"//ash/public/cpp",
"//ash/public/cpp:test_support",
......
......@@ -7,6 +7,7 @@
#include "ash/assistant/model/assistant_ui_model.h"
#include "ash/assistant/ui/assistant_ui_constants.h"
#include "ash/assistant/ui/assistant_view_delegate.h"
#include "ash/assistant/ui/assistant_view_ids.h"
#include "ash/assistant/ui/base/assistant_button.h"
#include "ash/assistant/ui/dialog_plate/dialog_plate.h"
#include "ash/assistant/ui/dialog_plate/mic_view.h"
......@@ -66,6 +67,7 @@ AssistantDialogPlate::AssistantDialogPlate(ash::AssistantViewDelegate* delegate)
base::Unretained(this)))),
query_history_iterator_(
delegate_->GetInteractionModel()->query_history().GetIterator()) {
SetID(AssistantViewID::kDialogPlate);
InitLayout();
// The AssistantViewDelegate should outlive AssistantDialogPlate.
......@@ -266,6 +268,7 @@ void AssistantDialogPlate::InitLayout() {
// Molecule icon.
molecule_icon_ = ash::LogoView::Create();
molecule_icon_->SetID(AssistantViewID::kModuleIcon);
molecule_icon_->SetPreferredSize(gfx::Size(kIconSizeDip, kIconSizeDip));
molecule_icon_->SetState(ash::LogoView::State::kMoleculeWavy,
/*animate=*/false);
......@@ -310,6 +313,7 @@ void AssistantDialogPlate::InitKeyboardLayoutContainer() {
// Textfield.
textfield_ = new views::Textfield();
textfield_->SetID(AssistantViewID::kTextQueryField);
textfield_->SetBackgroundColor(SK_ColorTRANSPARENT);
textfield_->SetBorder(views::NullBorder());
textfield_->set_controller(this);
......@@ -332,6 +336,7 @@ void AssistantDialogPlate::InitKeyboardLayoutContainer() {
IDS_ASH_ASSISTANT_DIALOG_PLATE_MIC_ACCNAME,
ash::AssistantButtonId::kVoiceInputToggle,
IDS_ASH_ASSISTANT_DIALOG_PLATE_MIC_TOOLTIP);
voice_input_toggle_->SetID(AssistantViewID::kVoiceInputToggle);
keyboard_layout_container_->AddChildView(voice_input_toggle_);
input_modality_layout_container_->AddChildView(keyboard_layout_container_);
......@@ -369,6 +374,7 @@ void AssistantDialogPlate::InitVoiceLayoutContainer() {
// Animated voice input toggle.
animated_voice_input_toggle_ = new ash::MicView(
this, delegate_, ash::AssistantButtonId::kVoiceInputToggle);
animated_voice_input_toggle_->SetID(AssistantViewID::kMicView);
animated_voice_input_toggle_->SetAccessibleName(
l10n_util::GetStringUTF16(IDS_ASH_ASSISTANT_DIALOG_PLATE_MIC_ACCNAME));
voice_layout_container_->AddChildView(animated_voice_input_toggle_);
......@@ -384,6 +390,7 @@ void AssistantDialogPlate::InitVoiceLayoutContainer() {
IDS_ASH_ASSISTANT_DIALOG_PLATE_KEYBOARD_ACCNAME,
ash::AssistantButtonId::kKeyboardInputToggle,
IDS_ASH_ASSISTANT_DIALOG_PLATE_KEYBOARD_TOOLTIP);
keyboard_input_toggle_->SetID(AssistantViewID::kKeyboardInputToggle);
voice_layout_container_->AddChildView(keyboard_input_toggle_);
input_modality_layout_container_->AddChildView(voice_layout_container_);
......
......@@ -9,6 +9,7 @@
#include "ash/assistant/model/assistant_query.h"
#include "ash/assistant/ui/assistant_ui_constants.h"
#include "ash/assistant/ui/assistant_view_delegate.h"
#include "ash/assistant/ui/assistant_view_ids.h"
#include "ash/assistant/ui/base/stack_layout.h"
#include "ash/assistant/ui/main_stage/assistant_footer_view.h"
#include "ash/assistant/ui/main_stage/assistant_progress_indicator.h"
......@@ -99,6 +100,7 @@ bool IsLayerVisible(views::View* view) {
AppListAssistantMainStage::AppListAssistantMainStage(
ash::AssistantViewDelegate* delegate)
: delegate_(delegate) {
SetID(AssistantViewID::kMainStage);
InitLayout();
// The view hierarchy will be destructed before AssistantController in Shell,
......
......@@ -11,6 +11,7 @@
#include "ash/app_list/views/assistant/assistant_main_stage.h"
#include "ash/assistant/ui/assistant_ui_constants.h"
#include "ash/assistant/ui/assistant_view_delegate.h"
#include "ash/assistant/ui/assistant_view_ids.h"
#include "ash/assistant/util/animation_util.h"
#include "ash/assistant/util/assistant_util.h"
#include "ash/public/cpp/app_list/app_list_features.h"
......@@ -31,6 +32,7 @@ constexpr base::TimeDelta kDialogPlateAnimationFadeInDuration =
AssistantMainView::AssistantMainView(AssistantViewDelegate* delegate)
: delegate_(delegate) {
SetID(AssistantViewID::kMainView);
InitLayout();
// The view hierarchy will be destructed before AssistantController in Shell,
......
......@@ -293,10 +293,6 @@ void AssistantPageView::OnUiVisibilityChanged(
}
}
AssistantMainView* AssistantPageView::GetMainViewForTest() {
return assistant_main_view_;
}
int AssistantPageView::GetChildViewHeightForWidth(int width) const {
int height = 0;
if (assistant_view_delegate_) {
......
......@@ -67,8 +67,6 @@ class APP_LIST_EXPORT AssistantPageView : public AppListPage,
base::Optional<AssistantEntryPoint> entry_point,
base::Optional<AssistantExitPoint> exit_point) override;
AssistantMainView* GetMainViewForTest();
private:
int GetChildViewHeightForWidth(int width) const;
void MaybeUpdateAppListState(int child_height);
......
......@@ -2,8 +2,6 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "ash/app_list/views/assistant/assistant_page_view.h"
#include "ash/app_list/views/assistant/assistant_main_view.h"
#include "ash/assistant/test/assistant_ash_test_base.h"
#include "ash/assistant/ui/assistant_ui_constants.h"
#include "base/run_loop.h"
......
// Copyright 2019 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "ash/app_list/views/assistant/assistant_test_api_impl.h"
#include "ash/app_list/app_list_controller_impl.h"
#include "ash/app_list/views/app_list_main_view.h"
#include "ash/app_list/views/app_list_page.h"
#include "ash/app_list/views/app_list_view.h"
#include "ash/app_list/views/contents_view.h"
#include "ash/assistant/ui/assistant_view_ids.h"
#include "ash/public/cpp/tablet_mode.h"
#include "ash/session/session_controller_impl.h"
#include "ash/shell.h"
#include "testing/gtest/include/gtest/gtest.h"
#include "ui/compositor/scoped_animation_duration_scale_mode.h"
#include "ui/events/test/event_generator.h"
#include "ui/views/controls/textfield/textfield.h"
namespace ash {
std::unique_ptr<AssistantTestApi> AssistantTestApi::Create() {
return std::make_unique<AssistantTestApiImpl>();
}
AssistantTestApiImpl::AssistantTestApiImpl() = default;
AssistantTestApiImpl::~AssistantTestApiImpl() {
EnableAnimations();
}
void AssistantTestApiImpl::DisableAnimations() {
AppListView::SetShortAnimationForTesting(true);
scoped_animation_duration_ =
std::make_unique<ui::ScopedAnimationDurationScaleMode>(
ui::ScopedAnimationDurationScaleMode::ZERO_DURATION);
}
bool AssistantTestApiImpl::IsVisible() {
return page_view()->GetVisible();
}
void AssistantTestApiImpl::SendTextQuery(const std::string& query) {
if (!input_text_field()->HasFocus()) {
ADD_FAILURE()
<< "The TextField should be focussed before we can send a query";
}
input_text_field()->SetText(base::UTF8ToUTF16(query));
// Send <return> to commit the query.
SendKeyPress(ui::KeyboardCode::VKEY_RETURN);
}
views::View* AssistantTestApiImpl::page_view() {
const int index = contents_view()->GetPageIndexForState(
AppListState::kStateEmbeddedAssistant);
return static_cast<views::View*>(contents_view()->GetPageView(index));
}
views::View* AssistantTestApiImpl::main_view() {
return page_view()->GetViewByID(AssistantViewID::kMainView);
}
views::Textfield* AssistantTestApiImpl::input_text_field() {
return static_cast<views::Textfield*>(
page_view()->GetViewByID(AssistantViewID::kTextQueryField));
}
views::View* AssistantTestApiImpl::mic_view() {
return page_view()->GetViewByID(AssistantViewID::kMicView);
}
aura::Window* AssistantTestApiImpl::window() {
return main_view()->GetWidget()->GetNativeWindow();
}
void AssistantTestApiImpl::EnableAssistant() {
Shell::Get()->session_controller()->GetPrimaryUserPrefService()->SetBoolean(
chromeos::assistant::prefs::kAssistantEnabled, true);
}
void AssistantTestApiImpl::SetTabletMode(bool enable) {
TabletMode::Get()->SetEnabledForTest(enable);
}
void AssistantTestApiImpl::SetPreferVoice(bool value) {
Shell::Get()->session_controller()->GetPrimaryUserPrefService()->SetBoolean(
chromeos::assistant::prefs::kAssistantLaunchWithMicOpen, value);
}
void AssistantTestApiImpl::EnableAnimations() {
scoped_animation_duration_ = nullptr;
AppListView::SetShortAnimationForTesting(false);
}
ContentsView* AssistantTestApiImpl::contents_view() {
auto* app_list_view =
Shell::Get()->app_list_controller()->presenter()->GetView();
DCHECK(app_list_view) << "AppListView has not been initialized yet. "
"Be sure to display the Assistant UI first.";
return app_list_view->app_list_main_view()->contents_view();
}
void AssistantTestApiImpl::SendKeyPress(ui::KeyboardCode key) {
ui::test::EventGenerator event_generator(window()->GetRootWindow());
event_generator.PressKey(key, /*flags=*/ui::EF_NONE);
}
} // namespace ash
// Copyright 2019 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef ASH_APP_LIST_VIEWS_ASSISTANT_ASSISTANT_TEST_API_IMPL_H_
#define ASH_APP_LIST_VIEWS_ASSISTANT_ASSISTANT_TEST_API_IMPL_H_
#include <memory>
#include "ash/public/cpp/test/assistant_test_api.h"
#include "base/macros.h"
#include "ui/events/keycodes/keyboard_codes_posix.h"
namespace ui {
class ScopedAnimationDurationScaleMode;
} // namespace ui
namespace ash {
class ContentsView;
class AssistantTestApiImpl : public AssistantTestApi {
public:
AssistantTestApiImpl();
~AssistantTestApiImpl() override;
// AssistantTestApi:
void DisableAnimations() override;
bool IsVisible() override;
void SendTextQuery(const std::string& query) override;
void EnableAssistant() override;
void SetTabletMode(bool enable) override;
void SetPreferVoice(bool value) override;
views::View* page_view() override;
views::View* main_view() override;
views::Textfield* input_text_field() override;
views::View* mic_view() override;
aura::Window* window() override;
private:
void EnableAnimations();
ContentsView* contents_view();
void SendKeyPress(ui::KeyboardCode key);
std::unique_ptr<ui::ScopedAnimationDurationScaleMode>
scoped_animation_duration_;
DISALLOW_COPY_AND_ASSIGN(AssistantTestApiImpl);
};
} // namespace ash
#endif // ASH_APP_LIST_VIEWS_ASSISTANT_ASSISTANT_TEST_API_IMPL_H_
......@@ -5,17 +5,14 @@
#include "ash/assistant/test/assistant_ash_test_base.h"
#include "ash/app_list/app_list_controller_impl.h"
#include "ash/app_list/views/app_list_main_view.h"
#include "ash/app_list/views/app_list_view.h"
#include "ash/app_list/views/assistant/assistant_main_view.h"
#include "ash/app_list/views/assistant/assistant_page_view.h"
#include "ash/app_list/views/contents_view.h"
#include "ash/assistant/assistant_controller.h"
#include "ash/keyboard/ui/keyboard_ui_controller.h"
#include "ash/keyboard/ui/test/keyboard_test_util.h"
#include "ash/public/cpp/app_list/app_list_features.h"
#include "ash/public/cpp/keyboard/keyboard_switches.h"
#include "ash/session/session_controller_impl.h"
#include "ash/public/cpp/test/assistant_test_api.h"
#include "ash/shell.h"
#include "ash/wm/tablet_mode/tablet_mode_controller.h"
#include "base/run_loop.h"
......@@ -43,34 +40,10 @@ bool CanProcessEvents(const views::View* view) {
return true;
}
views::View* GetDescendantViewWithNameOrNull(views::View* parent,
const std::string& name) {
for (views::View* child : parent->children()) {
if (child->GetClassName() == name)
return child;
views::View* descendant = GetDescendantViewWithNameOrNull(child, name);
if (descendant)
return descendant;
}
return nullptr;
}
// Recursively search for a descendant view with the given name.
// Asserts if no such view exists.
views::View* GetDescendantViewWithName(views::View* parent,
const std::string& name) {
views::View* descendant_maybe = GetDescendantViewWithNameOrNull(parent, name);
if (descendant_maybe == nullptr) {
ADD_FAILURE() << "View " << parent->GetClassName()
<< " has no descendant with name '" << name << "'.";
}
return descendant_maybe;
}
} // namespace
AssistantAshTestBase::AssistantAshTestBase() = default;
AssistantAshTestBase::AssistantAshTestBase()
: test_api_(AssistantTestApi::Create()) {}
AssistantAshTestBase::~AssistantAshTestBase() = default;
......@@ -88,8 +61,7 @@ void AssistantAshTestBase::SetUp() {
UpdateDisplay("1024x768");
// Enable Assistant in settings.
Shell::Get()->session_controller()->GetPrimaryUserPrefService()->SetBoolean(
chromeos::assistant::prefs::kAssistantEnabled, true);
test_api_->EnableAssistant();
// Cache controller.
controller_ = Shell::Get()->assistant_controller();
......@@ -99,7 +71,7 @@ void AssistantAshTestBase::SetUp() {
// Indicate this by changing status from NOT_READY to READY.
AssistantState::Get()->NotifyStatusChanged(mojom::AssistantState::READY);
DisableAnimations();
test_api_->DisableAnimations();
// Wait for virtual keyboard to load.
SetTouchKeyboardEnabled(true);
......@@ -110,7 +82,6 @@ void AssistantAshTestBase::TearDown() {
SetTouchKeyboardEnabled(false);
AshTestBase::TearDown();
scoped_feature_list_.Reset();
ReenableAnimations();
}
void AssistantAshTestBase::ShowAssistantUi(AssistantEntryPoint entry_point) {
......@@ -135,22 +106,19 @@ void AssistantAshTestBase::CloseLauncher() {
}
void AssistantAshTestBase::SetTabletMode(bool enable) {
ash::Shell::Get()->tablet_mode_controller()->SetEnabledForTest(enable);
test_api_->SetTabletMode(enable);
}
void AssistantAshTestBase::SetPreferVoice(bool prefer_voice) {
Shell::Get()->session_controller()->GetPrimaryUserPrefService()->SetBoolean(
chromeos::assistant::prefs::kAssistantLaunchWithMicOpen, prefer_voice);
test_api_->SetPreferVoice(prefer_voice);
}
AssistantMainView* AssistantAshTestBase::main_view() {
return page_view()->GetMainViewForTest();
views::View* AssistantAshTestBase::main_view() {
return test_api_->main_view();
}
AssistantPageView* AssistantAshTestBase::page_view() {
const int index = contents_view()->GetPageIndexForState(
AppListState::kStateEmbeddedAssistant);
return static_cast<AssistantPageView*>(contents_view()->GetPageView(index));
views::View* AssistantAshTestBase::page_view() {
return test_api_->page_view();
}
void AssistantAshTestBase::MockAssistantInteractionWithResponse(
......@@ -168,15 +136,7 @@ void AssistantAshTestBase::MockAssistantInteractionWithResponse(
}
void AssistantAshTestBase::SendQueryThroughTextField(const std::string& query) {
if (!input_text_field()->HasFocus()) {
ADD_FAILURE()
<< "The TextField should be focussed before we can send a query";
}
input_text_field()->SetText(base::ASCIIToUTF16(query));
// Send <return> to commit the query.
GetEventGenerator()->PressKey(ui::KeyboardCode::VKEY_RETURN,
/*flags=*/ui::EF_NONE);
test_api_->SendTextQuery(query);
}
void AssistantAshTestBase::TapOnTextField() {
......@@ -195,16 +155,15 @@ aura::Window* AssistantAshTestBase::SwitchToNewAppWindow() {
}
aura::Window* AssistantAshTestBase::window() {
return main_view()->GetWidget()->GetNativeWindow();
return test_api_->window();
}
views::Textfield* AssistantAshTestBase::input_text_field() {
views::View* result = GetDescendantViewWithName(main_view(), "Textfield");
return static_cast<views::Textfield*>(result);
return test_api_->input_text_field();
}
views::View* AssistantAshTestBase::mic_view() {
return GetDescendantViewWithName(main_view(), "MicView");
return test_api_->mic_view();
}
void AssistantAshTestBase::ShowKeyboard() {
......@@ -216,16 +175,6 @@ bool AssistantAshTestBase::IsKeyboardShowing() const {
return keyboard::IsKeyboardShowing();
}
ContentsView* AssistantAshTestBase::contents_view() {
auto* app_list_view =
Shell::Get()->app_list_controller()->presenter()->GetView();
DCHECK(app_list_view) << "AppListView has not been initialized yet. "
"Be sure to call |ShowAssistantUI| first";
return app_list_view->app_list_main_view()->contents_view();
}
AssistantInteractionController* AssistantAshTestBase::interaction_controller() {
return controller_->interaction_controller();
}
......@@ -234,17 +183,4 @@ TestAssistantService* AssistantAshTestBase::assistant_service() {
return ash_test_helper()->test_assistant_service();
}
void AssistantAshTestBase::DisableAnimations() {
AppListView::SetShortAnimationForTesting(true);
scoped_animation_duration_ =
std::make_unique<ui::ScopedAnimationDurationScaleMode>(
ui::ScopedAnimationDurationScaleMode::ZERO_DURATION);
}
void AssistantAshTestBase::ReenableAnimations() {
scoped_animation_duration_ = nullptr;
AppListView::SetShortAnimationForTesting(false);
}
} // namespace ash
......@@ -22,10 +22,8 @@ namespace ash {
class AssistantController;
class AssistantInteractionController;
class AssistantMainView;
class AssistantPageView;
class ContentsView;
class TestAssistantService;
class AssistantTestApi;
// Helper class to make testing the Assistant Ash UI easier.
class AssistantAshTestBase : public AshTestBase {
......@@ -56,11 +54,11 @@ class AssistantAshTestBase : public AshTestBase {
// Return the actual displayed Assistant main view.
// Can only be used after |ShowAssistantUi| has been called.
AssistantMainView* main_view();
views::View* main_view();
// This is the top-level Assistant specific view.
// Can only be used after |ShowAssistantUi| has been called.
AssistantPageView* page_view();
views::View* page_view();
// Spoof sending a request to the Assistant service,
// and receiving |response_text| as a response to display.
......@@ -93,18 +91,12 @@ class AssistantAshTestBase : public AshTestBase {
bool IsKeyboardShowing() const;
private:
ContentsView* contents_view();
AssistantInteractionController* interaction_controller();
TestAssistantService* assistant_service();
void DisableAnimations();
void ReenableAnimations();
std::unique_ptr<AssistantTestApi> test_api_;
base::test::ScopedFeatureList scoped_feature_list_;
AssistantController* controller_ = nullptr;
std::unique_ptr<ui::ScopedAnimationDurationScaleMode>
scoped_animation_duration_;
std::vector<std::unique_ptr<aura::Window>> windows_;
......
......@@ -50,6 +50,7 @@ component("ui") {
"assistant_notification_view.h",
"assistant_overlay.h",
"assistant_view_delegate.h",
"assistant_view_ids.h",
"assistant_web_container_view.cc",
"assistant_web_container_view.h",
"assistant_web_view.cc",
......
// Copyright 2019 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef ASH_ASSISTANT_UI_ASSISTANT_VIEW_IDS_H_
#define ASH_ASSISTANT_UI_ASSISTANT_VIEW_IDS_H_
namespace ash {
// IDs used for the main views that compose the Assistant UI.
// Use these for easy access to the views during the unittests.
// Note that these IDs are only guaranteed to be unique inside
// |AssistantPageView|.
enum AssistantViewID {
// We start at 1 because 0 is not a valid view ID.
kMainView = 1,
// Dialog plate and its components.
kDialogPlate,
kKeyboardInputToggle,
kMicView,
kModuleIcon,
kTextQueryField,
kVoiceInputToggle,
// Main stage and its components.
kMainStage,
kFooterView,
kOptInView,
kProgressIndicator,
kQueryView,
kSuggestionContainer,
kUiElementContainer,
kWebView,
};
} // namespace ash
#endif // ASH_ASSISTANT_UI_ASSISTANT_VIEW_IDS_H_
......@@ -10,6 +10,7 @@
#include "ash/assistant/model/assistant_ui_model.h"
#include "ash/assistant/ui/assistant_ui_constants.h"
#include "ash/assistant/ui/assistant_view_delegate.h"
#include "ash/assistant/ui/assistant_view_ids.h"
#include "ash/assistant/util/deep_link_util.h"
#include "ash/public/cpp/app_list/app_list_features.h"
#include "base/bind.h"
......@@ -30,6 +31,7 @@ namespace ash {
AssistantWebView::AssistantWebView(AssistantViewDelegate* delegate)
: delegate_(delegate) {
SetID(AssistantViewID::kWebView);
InitLayout();
delegate_->AddObserver(this);
......
......@@ -8,6 +8,7 @@
#include "ash/assistant/ui/assistant_ui_constants.h"
#include "ash/assistant/ui/assistant_view_delegate.h"
#include "ash/assistant/ui/assistant_view_ids.h"
#include "ash/assistant/ui/main_stage/assistant_opt_in_view.h"
#include "ash/assistant/ui/main_stage/suggestion_container_view.h"
#include "ash/assistant/util/animation_util.h"
......@@ -44,6 +45,7 @@ AssistantFooterView::AssistantFooterView(AssistantViewDelegate* delegate)
/*animation_ended_callback=*/base::BindRepeating(
&AssistantFooterView::OnAnimationEnded,
base::Unretained(this)))) {
SetID(AssistantViewID::kFooterView);
InitLayout();
AssistantState::Get()->AddObserver(this);
}
......
......@@ -9,6 +9,7 @@
#include "ash/assistant/ui/assistant_ui_constants.h"
#include "ash/assistant/ui/assistant_view_delegate.h"
#include "ash/assistant/ui/assistant_view_ids.h"
#include "ash/public/cpp/app_list/app_list_features.h"
#include "ash/strings/grit/ash_strings.h"
#include "ui/base/l10n/l10n_util.h"
......@@ -89,6 +90,7 @@ class AssistantOptInContainer : public views::Button {
AssistantOptInView::AssistantOptInView(AssistantViewDelegate* delegate)
: delegate_(delegate) {
SetID(AssistantViewID::kOptInView);
InitLayout();
AssistantState::Get()->AddObserver(this);
}
......
......@@ -6,6 +6,7 @@
#include <algorithm>
#include "ash/assistant/ui/assistant_view_ids.h"
#include "ash/assistant/util/animation_util.h"
#include "ash/public/cpp/app_list/app_list_features.h"
#include "base/bind.h"
......@@ -83,6 +84,7 @@ class DotBackground : public views::Background {
// AssistantProgressIndicator --------------------------------------------------
AssistantProgressIndicator::AssistantProgressIndicator() {
SetID(AssistantViewID::kProgressIndicator);
InitLayout();
}
......
......@@ -9,6 +9,7 @@
#include "ash/assistant/model/assistant_query.h"
#include "ash/assistant/ui/assistant_ui_constants.h"
#include "ash/assistant/ui/assistant_view_ids.h"
#include "base/strings/utf_string_conversions.h"
#include "net/base/escape.h"
#include "ui/accessibility/ax_enums.mojom.h"
......@@ -39,6 +40,7 @@ views::StyledLabel::RangeStyleInfo CreateStyleInfo(SkColor color) {
// AssistantQueryView ----------------------------------------------------------
AssistantQueryView::AssistantQueryView() {
SetID(AssistantViewID::kQueryView);
InitLayout();
GetViewAccessibility().OverrideRole(ax::mojom::Role::kHeading);
}
......
......@@ -11,6 +11,7 @@
#include "ash/assistant/model/assistant_response.h"
#include "ash/assistant/ui/assistant_ui_constants.h"
#include "ash/assistant/ui/assistant_view_delegate.h"
#include "ash/assistant/ui/assistant_view_ids.h"
#include "ash/assistant/ui/main_stage/animated_container_view.h"
#include "ash/assistant/ui/main_stage/element_animator.h"
#include "ash/assistant/util/animation_util.h"
......@@ -124,6 +125,7 @@ class SuggestionChipAnimator : public ElementAnimator {
SuggestionContainerView::SuggestionContainerView(
AssistantViewDelegate* delegate)
: AnimatedContainerView(delegate) {
SetID(AssistantViewID::kSuggestionContainer);
InitLayout();
// The AssistantViewDelegate should outlive SuggestionContainerView.
......
......@@ -11,6 +11,7 @@
#include "ash/assistant/model/assistant_ui_element.h"
#include "ash/assistant/ui/assistant_ui_constants.h"
#include "ash/assistant/ui/assistant_view_delegate.h"
#include "ash/assistant/ui/assistant_view_ids.h"
#include "ash/assistant/ui/main_stage/animated_container_view.h"
#include "ash/assistant/ui/main_stage/assistant_card_element_view.h"
#include "ash/assistant/ui/main_stage/assistant_text_element_view.h"
......@@ -234,6 +235,7 @@ std::unique_ptr<ElementAnimator> CreateTextAnimator(
UiElementContainerView::UiElementContainerView(AssistantViewDelegate* delegate)
: AnimatedContainerView(delegate) {
SetID(AssistantViewID::kUiElementContainer);
InitLayout();
}
......
// Copyright 2019 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef ASH_PUBLIC_CPP_TEST_ASSISTANT_TEST_API_H_
#define ASH_PUBLIC_CPP_TEST_ASSISTANT_TEST_API_H_
#include <memory>
#include "ash/ash_export.h"
namespace aura {
class Window;
} // namespace aura
namespace views {
class Textfield;
class View;
} // namespace views
namespace ash {
// Public test API for the Assistant UI.
// This API works both for ash and browser tests.
class ASH_EXPORT AssistantTestApi {
public:
static std::unique_ptr<AssistantTestApi> Create();
AssistantTestApi() = default;
virtual ~AssistantTestApi() = default;
virtual void DisableAnimations() = 0;
// Returns true if the Assistant UI is visible.
virtual bool IsVisible() = 0;
// Sends a text query. This requires the UI to be ready to accept text
// queries, i.e. the input text field must be visible and focussed.
virtual void SendTextQuery(const std::string& query) = 0;
// Enables Assistant in settings.
virtual void EnableAssistant() = 0;
virtual void SetTabletMode(bool enable) = 0;
// Changes the user setting controlling whether the user prefers voice or
// keyboard.
virtual void SetPreferVoice(bool value) = 0;
// Returns the top-level Assistant specific view.
// Can only be used after the Assistant UI has been shown at least once.
virtual views::View* page_view() = 0;
// Returns the Assistant main view.
// Can only be used after the Assistant UI has been shown at least once.
virtual views::View* main_view() = 0;
// Returns the text field used for inputting new queries.
// Can only be used after the Assistant UI has been shown at least once.
virtual views::Textfield* input_text_field() = 0;
// Returns the mic field used for dictating new queries.
// Can only be used after the Assistant UI has been shown at least once.
virtual views::View* mic_view() = 0;
// Returns the window containing the Assistant UI.
// Note that this window is shared for all components of the |AppList|.
virtual aura::Window* window() = 0;
};
} // namespace ash
#endif // ASH_PUBLIC_CPP_TEST_ASSISTANT_TEST_API_H_
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment