Commit e32a4b5f authored by Ahmed Mehfooz's avatar Ahmed Mehfooz Committed by Commit Bot

Make SystemTrayTestApi publicly accessible for Tast tests

Bug: 1035647
Change-Id: I8fa699b0dcb7ecae115d90377ab1f384cdd78859
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2148169Reviewed-by: default avatarXiyuan Xia <xiyuan@chromium.org>
Commit-Queue: Ahmed Mehfooz <amehfooz@chromium.org>
Cr-Commit-Position: refs/heads/master@{#758993}
parent 5b5a02ec
...@@ -55,6 +55,7 @@ component("ash") { ...@@ -55,6 +55,7 @@ component("ash") {
"public/cpp/shelf_config.h", "public/cpp/shelf_config.h",
"public/cpp/shelf_test_api.h", "public/cpp/shelf_test_api.h",
"public/cpp/split_view_test_api.h", "public/cpp/split_view_test_api.h",
"public/cpp/system_tray_test_api.h",
"public/cpp/window_finder.h", "public/cpp/window_finder.h",
"public/cpp/window_tree_host_lookup.h", "public/cpp/window_tree_host_lookup.h",
"root_window_controller.h", "root_window_controller.h",
...@@ -2350,7 +2351,6 @@ static_library("test_support") { ...@@ -2350,7 +2351,6 @@ static_library("test_support") {
"//components/exo/wayland:*", "//components/exo/wayland:*",
] ]
public = [ public = [
"public/cpp/system_tray_test_api.h",
"public/cpp/test/accessibility_controller_test_api.h", "public/cpp/test/accessibility_controller_test_api.h",
"public/cpp/test/assistant_test_api.h", "public/cpp/test/assistant_test_api.h",
] ]
...@@ -2435,8 +2435,7 @@ static_library("test_support") { ...@@ -2435,8 +2435,7 @@ static_library("test_support") {
"system/power/power_event_observer_test_api.h", "system/power/power_event_observer_test_api.h",
"system/status_area_widget_test_helper.cc", "system/status_area_widget_test_helper.cc",
"system/status_area_widget_test_helper.h", "system/status_area_widget_test_helper.h",
"system/unified/unified_system_tray_test_api.cc", "system/unified/system_tray_test_api.cc",
"system/unified/unified_system_tray_test_api.h",
"test/ash_test_base.cc", "test/ash_test_base.cc",
"test/ash_test_base.h", "test/ash_test_base.h",
"test/ash_test_helper.cc", "test/ash_test_helper.cc",
......
...@@ -27,6 +27,7 @@ ...@@ -27,6 +27,7 @@
#include "ash/public/cpp/presentation_time_recorder.h" #include "ash/public/cpp/presentation_time_recorder.h"
#include "ash/public/cpp/shelf_config.h" #include "ash/public/cpp/shelf_config.h"
#include "ash/public/cpp/shelf_types.h" #include "ash/public/cpp/shelf_types.h"
#include "ash/public/cpp/system_tray_test_api.h"
#include "ash/public/cpp/window_properties.h" #include "ash/public/cpp/window_properties.h"
#include "ash/shelf/shelf.h" #include "ash/shelf/shelf.h"
#include "ash/shelf/shelf_layout_manager.h" #include "ash/shelf/shelf_layout_manager.h"
...@@ -34,7 +35,6 @@ ...@@ -34,7 +35,6 @@
#include "ash/shelf/shelf_view_test_api.h" #include "ash/shelf/shelf_view_test_api.h"
#include "ash/shelf/shelf_widget.h" #include "ash/shelf/shelf_widget.h"
#include "ash/shell.h" #include "ash/shell.h"
#include "ash/system/unified/unified_system_tray_test_api.h"
#include "ash/test/ash_test_base.h" #include "ash/test/ash_test_base.h"
#include "ash/wm/tablet_mode/tablet_mode_controller.h" #include "ash/wm/tablet_mode/tablet_mode_controller.h"
#include "ash/wm/window_state.h" #include "ash/wm/window_state.h"
...@@ -451,7 +451,7 @@ TEST_F(AppListControllerImplTest, CloseNotificationWithAppListShown) { ...@@ -451,7 +451,7 @@ TEST_F(AppListControllerImplTest, CloseNotificationWithAppListShown) {
1u, message_center::MessageCenter::Get()->GetPopupNotifications().size()); 1u, message_center::MessageCenter::Get()->GetPopupNotifications().size());
// Calculate the drag start point and end point. // Calculate the drag start point and end point.
UnifiedSystemTrayTestApi test_api(GetPrimaryUnifiedSystemTray()); SystemTrayTestApi test_api;
message_center::MessagePopupView* popup_view = message_center::MessagePopupView* popup_view =
test_api.GetPopupViewForNotificationID(notification_id); test_api.GetPopupViewForNotificationID(notification_id);
ASSERT_TRUE(popup_view); ASSERT_TRUE(popup_view);
......
...@@ -10,6 +10,10 @@ ...@@ -10,6 +10,10 @@
#include "ash/ash_export.h" #include "ash/ash_export.h"
#include "base/strings/string16.h" #include "base/strings/string16.h"
namespace message_center {
class MessagePopupView;
}
namespace ash { namespace ash {
// Public test API for the system tray. Methods only apply to the system tray // Public test API for the system tray. Methods only apply to the system tray
...@@ -18,43 +22,51 @@ class ASH_EXPORT SystemTrayTestApi { ...@@ -18,43 +22,51 @@ class ASH_EXPORT SystemTrayTestApi {
public: public:
static std::unique_ptr<SystemTrayTestApi> Create(); static std::unique_ptr<SystemTrayTestApi> Create();
virtual ~SystemTrayTestApi() {} SystemTrayTestApi();
~SystemTrayTestApi();
// Disables animations (e.g. the tray view icon slide-in).
virtual void DisableAnimations() = 0;
// Returns true if the system tray bubble menu is open. // Returns true if the system tray bubble menu is open.
virtual bool IsTrayBubbleOpen() = 0; bool IsTrayBubbleOpen();
// Returns true if the system tray bubble menu is expanded.
bool IsTrayBubbleExpanded();
// Shows the system tray bubble menu. // Shows the system tray bubble menu.
virtual void ShowBubble() = 0; void ShowBubble();
// Closes the system tray bubble menu. // Closes the system tray bubble menu.
virtual void CloseBubble() = 0; void CloseBubble();
// Collapse the system tray bubble menu.
void CollapseBubble();
// Expand the system tray bubble menu.
void ExpandBubble();
// Shows the submenu view for the given section of the bubble menu. // Shows the submenu view for the given section of the bubble menu.
virtual void ShowAccessibilityDetailedView() = 0; void ShowAccessibilityDetailedView();
virtual void ShowNetworkDetailedView() = 0; void ShowNetworkDetailedView();
// Returns true if the view exists in the bubble and is visible. // Returns true if the view exists in the bubble and is visible.
// If |open_tray| is true, it also opens system tray bubble. // If |open_tray| is true, it also opens system tray bubble.
virtual bool IsBubbleViewVisible(int view_id, bool open_tray) = 0; bool IsBubbleViewVisible(int view_id, bool open_tray);
// Clicks the view |view_id|. // Clicks the view |view_id|.
virtual void ClickBubbleView(int view_id) = 0; void ClickBubbleView(int view_id);
// Returns the tooltip for a bubble view, or the empty string if the view // Returns the tooltip for a bubble view, or the empty string if the view
// does not exist. // does not exist.
virtual base::string16 GetBubbleViewTooltip(int view_id) = 0; base::string16 GetBubbleViewTooltip(int view_id);
// Get the notification pop up view based on the notification id.
message_center::MessagePopupView* GetPopupViewForNotificationID(
const std::string& notification_id);
// Returns true if the clock is using 24 hour time. // Returns true if the clock is using 24 hour time.
virtual bool Is24HourClock() = 0; bool Is24HourClock();
// Taps on the Select-to-Speak tray. // Taps on the Select-to-Speak tray.
virtual void TapSelectToSpeakTray() = 0; void TapSelectToSpeakTray();
protected:
SystemTrayTestApi() {}
}; };
} // namespace ash } // namespace ash
......
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
// Use of this source code is governed by a BSD-style license that can be // Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file. // found in the LICENSE file.
#include "ash/system/unified/unified_system_tray_test_api.h" #include "ash/public/cpp/system_tray_test_api.h"
#include "ash/root_window_controller.h" #include "ash/root_window_controller.h"
#include "ash/shell.h" #include "ash/shell.h"
...@@ -14,55 +14,73 @@ ...@@ -14,55 +14,73 @@
#include "ash/system/unified/unified_system_tray_bubble.h" #include "ash/system/unified/unified_system_tray_bubble.h"
#include "ash/system/unified/unified_system_tray_controller.h" #include "ash/system/unified/unified_system_tray_controller.h"
#include "base/strings/string16.h" #include "base/strings/string16.h"
#include "ui/compositor/scoped_animation_duration_scale_mode.h"
#include "ui/events/test/event_generator.h" #include "ui/events/test/event_generator.h"
#include "ui/views/controls/label.h" #include "ui/views/controls/label.h"
#include "ui/views/view.h" #include "ui/views/view.h"
#include "ui/views/widget/widget_utils.h" #include "ui/views/widget/widget_utils.h"
namespace {
ash::UnifiedSystemTray* GetTray() {
return ash::Shell::Get()
->GetPrimaryRootWindowController()
->GetStatusAreaWidget()
->unified_system_tray();
}
views::View* GetBubbleView(int view_id) {
return GetTray()->bubble()->GetBubbleView()->GetViewByID(view_id);
}
} // namespace
namespace ash { namespace ash {
UnifiedSystemTrayTestApi::UnifiedSystemTrayTestApi(UnifiedSystemTray* tray) SystemTrayTestApi::SystemTrayTestApi() = default;
: tray_(tray) {}
UnifiedSystemTrayTestApi::~UnifiedSystemTrayTestApi() = default; SystemTrayTestApi::~SystemTrayTestApi() = default;
void UnifiedSystemTrayTestApi::DisableAnimations() { bool SystemTrayTestApi::IsTrayBubbleOpen() {
disable_animations_ = std::make_unique<ui::ScopedAnimationDurationScaleMode>( return GetTray()->IsBubbleShown();
ui::ScopedAnimationDurationScaleMode::ZERO_DURATION);
} }
bool UnifiedSystemTrayTestApi::IsTrayBubbleOpen() { bool SystemTrayTestApi::IsTrayBubbleExpanded() {
return tray_->IsBubbleShown(); return GetTray()->bubble_->controller_->IsExpanded();
} }
void UnifiedSystemTrayTestApi::ShowBubble() { void SystemTrayTestApi::ShowBubble() {
tray_->ShowBubble(false /* show_by_click */); GetTray()->ShowBubble(false /* show_by_click */);
} }
void UnifiedSystemTrayTestApi::CloseBubble() { void SystemTrayTestApi::CloseBubble() {
tray_->CloseBubble(); GetTray()->CloseBubble();
} }
void UnifiedSystemTrayTestApi::ShowAccessibilityDetailedView() { void SystemTrayTestApi::CollapseBubble() {
tray_->ShowBubble(false /* show_by_click */); GetTray()->EnsureQuickSettingsCollapsed(true /*animate*/);
tray_->bubble_->controller_->ShowAccessibilityDetailedView();
} }
void UnifiedSystemTrayTestApi::ShowNetworkDetailedView() { void SystemTrayTestApi::ExpandBubble() {
tray_->ShowBubble(false /* show_by_click */); GetTray()->EnsureBubbleExpanded();
tray_->bubble_->controller_->ShowNetworkDetailedView(true /* force */);
} }
bool UnifiedSystemTrayTestApi::IsBubbleViewVisible(int view_id, void SystemTrayTestApi::ShowAccessibilityDetailedView() {
bool open_tray) { GetTray()->ShowBubble(false /* show_by_click */);
GetTray()->bubble_->controller_->ShowAccessibilityDetailedView();
}
void SystemTrayTestApi::ShowNetworkDetailedView() {
GetTray()->ShowBubble(false /* show_by_click */);
GetTray()->bubble_->controller_->ShowNetworkDetailedView(true /* force */);
}
bool SystemTrayTestApi::IsBubbleViewVisible(int view_id, bool open_tray) {
if (open_tray) if (open_tray)
tray_->ShowBubble(false /* show_by_click */); GetTray()->ShowBubble(false /* show_by_click */);
views::View* view = GetBubbleView(view_id); views::View* view = GetBubbleView(view_id);
return view && view->GetVisible(); return view && view->GetVisible();
} }
void UnifiedSystemTrayTestApi::ClickBubbleView(int view_id) { void SystemTrayTestApi::ClickBubbleView(int view_id) {
views::View* view = GetBubbleView(view_id); views::View* view = GetBubbleView(view_id);
if (view && view->GetVisible()) { if (view && view->GetVisible()) {
gfx::Point cursor_location = view->GetLocalBounds().CenterPoint(); gfx::Point cursor_location = view->GetLocalBounds().CenterPoint();
...@@ -74,46 +92,38 @@ void UnifiedSystemTrayTestApi::ClickBubbleView(int view_id) { ...@@ -74,46 +92,38 @@ void UnifiedSystemTrayTestApi::ClickBubbleView(int view_id) {
} }
} }
base::string16 UnifiedSystemTrayTestApi::GetBubbleViewTooltip(int view_id) { base::string16 SystemTrayTestApi::GetBubbleViewTooltip(int view_id) {
views::View* view = GetBubbleView(view_id); views::View* view = GetBubbleView(view_id);
return view ? view->GetTooltipText(gfx::Point()) : base::string16(); return view ? view->GetTooltipText(gfx::Point()) : base::string16();
} }
bool UnifiedSystemTrayTestApi::Is24HourClock() { bool SystemTrayTestApi::Is24HourClock() {
base::HourClockType type = base::HourClockType type =
tray_->time_view_->time_view()->GetHourTypeForTesting(); GetTray()->time_view_->time_view()->GetHourTypeForTesting();
return type == base::k24HourClock; return type == base::k24HourClock;
} }
void UnifiedSystemTrayTestApi::TapSelectToSpeakTray() { void SystemTrayTestApi::TapSelectToSpeakTray() {
// The Select-to-Speak tray doesn't actually use the event, so construct // The Select-to-Speak tray doesn't actually use the event, so construct
// a bare bones event to perform the action. // a bare bones event to perform the action.
ui::TouchEvent event( ui::TouchEvent event(
ui::ET_TOUCH_PRESSED, gfx::Point(), base::TimeTicks::Now(), ui::ET_TOUCH_PRESSED, gfx::Point(), base::TimeTicks::Now(),
ui::PointerDetails(ui::EventPointerType::POINTER_TYPE_TOUCH), 0); ui::PointerDetails(ui::EventPointerType::POINTER_TYPE_TOUCH), 0);
StatusAreaWidget* status_area_widget = StatusAreaWidget* status_area_widget =
RootWindowController::ForWindow(tray_->GetWidget()->GetNativeWindow()) RootWindowController::ForWindow(GetTray()->GetWidget()->GetNativeWindow())
->GetStatusAreaWidget(); ->GetStatusAreaWidget();
status_area_widget->select_to_speak_tray()->PerformAction(event); status_area_widget->select_to_speak_tray()->PerformAction(event);
} }
message_center::MessagePopupView* message_center::MessagePopupView*
UnifiedSystemTrayTestApi::GetPopupViewForNotificationID( SystemTrayTestApi::GetPopupViewForNotificationID(
const std::string& notification_id) { const std::string& notification_id) {
return tray_->GetPopupViewForNotificationID(notification_id); return GetTray()->GetPopupViewForNotificationID(notification_id);
}
views::View* UnifiedSystemTrayTestApi::GetBubbleView(int view_id) const {
return tray_->bubble_->bubble_view_->GetViewByID(view_id);
} }
// static // static
std::unique_ptr<SystemTrayTestApi> SystemTrayTestApi::Create() { std::unique_ptr<SystemTrayTestApi> SystemTrayTestApi::Create() {
UnifiedSystemTray* primary_tray = Shell::Get() return std::make_unique<SystemTrayTestApi>();
->GetPrimaryRootWindowController()
->GetStatusAreaWidget()
->unified_system_tray();
return std::make_unique<UnifiedSystemTrayTestApi>(primary_tray);
} }
} // namespace ash } // namespace ash
...@@ -153,8 +153,8 @@ class ASH_EXPORT UnifiedSystemTray : public TrayBackgroundView, ...@@ -153,8 +153,8 @@ class ASH_EXPORT UnifiedSystemTray : public TrayBackgroundView,
private: private:
static const base::TimeDelta kNotificationCountUpdateDelay; static const base::TimeDelta kNotificationCountUpdateDelay;
friend class SystemTrayTestApi;
friend class UnifiedSystemTrayTest; friend class UnifiedSystemTrayTest;
friend class UnifiedSystemTrayTestApi;
// Private class implements MessageCenterUiDelegate. // Private class implements MessageCenterUiDelegate.
class UiDelegate; class UiDelegate;
......
...@@ -138,7 +138,7 @@ class ASH_EXPORT UnifiedSystemTrayBubble ...@@ -138,7 +138,7 @@ class ASH_EXPORT UnifiedSystemTrayBubble
} }
private: private:
friend class UnifiedSystemTrayTestApi; friend class SystemTrayTestApi;
void UpdateBubbleBounds(); void UpdateBubbleBounds();
......
...@@ -139,6 +139,7 @@ class ASH_EXPORT UnifiedSystemTrayController ...@@ -139,6 +139,7 @@ class ASH_EXPORT UnifiedSystemTrayController
} }
private: private:
friend class SystemTrayTestApi;
friend class UnifiedSystemTrayControllerTest; friend class UnifiedSystemTrayControllerTest;
friend class UnifiedMessageCenterBubbleTest; friend class UnifiedMessageCenterBubbleTest;
......
// Copyright 2018 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_SYSTEM_UNIFIED_UNIFIED_SYSTEM_TRAY_TEST_API_H_
#define ASH_SYSTEM_UNIFIED_UNIFIED_SYSTEM_TRAY_TEST_API_H_
#include <memory>
#include "ash/public/cpp/system_tray_test_api.h"
#include "base/macros.h"
namespace ui {
class ScopedAnimationDurationScaleMode;
} // namespace ui
namespace views {
class View;
} // namespace views
namespace message_center {
class MessagePopupView;
} // namespace message_center
namespace ash {
class UnifiedSystemTray;
// Use by tests to access private state of UnifiedSystemTray.
// TODO(jamescook): Rename class to SystemTrayTestApiImpl.
class UnifiedSystemTrayTestApi : public SystemTrayTestApi {
public:
explicit UnifiedSystemTrayTestApi(UnifiedSystemTray* tray);
~UnifiedSystemTrayTestApi() override;
// SystemTrayTestApi:
void DisableAnimations() override;
bool IsTrayBubbleOpen() override;
void ShowBubble() override;
void CloseBubble() override;
void ShowAccessibilityDetailedView() override;
void ShowNetworkDetailedView() override;
bool IsBubbleViewVisible(int view_id, bool open_tray) override;
void ClickBubbleView(int view_id) override;
base::string16 GetBubbleViewTooltip(int view_id) override;
bool Is24HourClock() override;
void TapSelectToSpeakTray() override;
message_center::MessagePopupView* GetPopupViewForNotificationID(
const std::string& notification_id);
private:
// Returns a view in the bubble menu (not the tray itself). Returns null if
// not found.
views::View* GetBubbleView(int view_id) const;
UnifiedSystemTray* const tray_;
std::unique_ptr<ui::ScopedAnimationDurationScaleMode> disable_animations_;
DISALLOW_COPY_AND_ASSIGN(UnifiedSystemTrayTestApi);
};
} // namespace ash
#endif // ASH_SYSTEM_UNIFIED_UNIFIED_SYSTEM_TRAY_TEST_API_H_
...@@ -14,6 +14,7 @@ ...@@ -14,6 +14,7 @@
#include "ash/wm/overview/overview_controller.h" #include "ash/wm/overview/overview_controller.h"
#include "base/macros.h" #include "base/macros.h"
#include "components/account_id/account_id.h" #include "components/account_id/account_id.h"
#include "ui/compositor/scoped_animation_duration_scale_mode.h"
#include "ui/views/widget/widget.h" #include "ui/views/widget/widget.h"
namespace ash { namespace ash {
...@@ -37,13 +38,16 @@ class UserChooserDetailedViewControllerTest : public AshTestBase { ...@@ -37,13 +38,16 @@ class UserChooserDetailedViewControllerTest : public AshTestBase {
// AshTestBase // AshTestBase
void SetUp() override { void SetUp() override {
AshTestBase::SetUp(); AshTestBase::SetUp();
tray_test_api_ = SystemTrayTestApi::Create(); tray_test_api_ = std::make_unique<SystemTrayTestApi>();
tray_test_api_->DisableAnimations(); disable_animations_ =
std::make_unique<ui::ScopedAnimationDurationScaleMode>(
ui::ScopedAnimationDurationScaleMode::ZERO_DURATION);
} }
SystemTrayTestApi* tray_test_api() { return tray_test_api_.get(); } SystemTrayTestApi* tray_test_api() { return tray_test_api_.get(); }
private: private:
std::unique_ptr<ui::ScopedAnimationDurationScaleMode> disable_animations_;
std::unique_ptr<SystemTrayTestApi> tray_test_api_; std::unique_ptr<SystemTrayTestApi> tray_test_api_;
DISALLOW_COPY_AND_ASSIGN(UserChooserDetailedViewControllerTest); DISALLOW_COPY_AND_ASSIGN(UserChooserDetailedViewControllerTest);
}; };
......
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