[go: nahoru, domu]

blob: c43cd56f7ab8fde6bf80e84b27438a8e1dff2309 [file] [log] [blame]
Ahmed Mehfooze32a4b52020-04-14 20:34:101// Copyright 2018 The Chromium Authors. All rights reserved.
2// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
5#include "ash/public/cpp/system_tray_test_api.h"
6
Jan Wilken Dörriead587c32021-03-11 14:09:277#include <string>
8
Ahmed Mehfooze32a4b52020-04-14 20:34:109#include "ash/root_window_controller.h"
10#include "ash/shell.h"
11#include "ash/system/accessibility/select_to_speak_tray.h"
12#include "ash/system/status_area_widget.h"
13#include "ash/system/time/time_tray_item_view.h"
14#include "ash/system/time/time_view.h"
15#include "ash/system/unified/unified_system_tray.h"
16#include "ash/system/unified/unified_system_tray_bubble.h"
17#include "ash/system/unified/unified_system_tray_controller.h"
18#include "base/strings/string16.h"
19#include "ui/events/test/event_generator.h"
20#include "ui/views/controls/label.h"
21#include "ui/views/view.h"
22#include "ui/views/widget/widget_utils.h"
23
24namespace {
25ash::UnifiedSystemTray* GetTray() {
26 return ash::Shell::Get()
27 ->GetPrimaryRootWindowController()
28 ->GetStatusAreaWidget()
29 ->unified_system_tray();
30}
31
32views::View* GetBubbleView(int view_id) {
33 return GetTray()->bubble()->GetBubbleView()->GetViewByID(view_id);
34}
35
36} // namespace
37
38namespace ash {
39
40SystemTrayTestApi::SystemTrayTestApi() = default;
41
42SystemTrayTestApi::~SystemTrayTestApi() = default;
43
44bool SystemTrayTestApi::IsTrayBubbleOpen() {
45 return GetTray()->IsBubbleShown();
46}
47
48bool SystemTrayTestApi::IsTrayBubbleExpanded() {
49 return GetTray()->bubble_->controller_->IsExpanded();
50}
51
52void SystemTrayTestApi::ShowBubble() {
Ahmed Mehfooz15cebdd2021-03-03 01:07:0753 GetTray()->ShowBubble();
Ahmed Mehfooze32a4b52020-04-14 20:34:1054}
55
56void SystemTrayTestApi::CloseBubble() {
57 GetTray()->CloseBubble();
58}
59
60void SystemTrayTestApi::CollapseBubble() {
61 GetTray()->EnsureQuickSettingsCollapsed(true /*animate*/);
62}
63
64void SystemTrayTestApi::ExpandBubble() {
65 GetTray()->EnsureBubbleExpanded();
66}
67
68void SystemTrayTestApi::ShowAccessibilityDetailedView() {
Ahmed Mehfooz15cebdd2021-03-03 01:07:0769 GetTray()->ShowBubble();
Ahmed Mehfooze32a4b52020-04-14 20:34:1070 GetTray()->bubble_->controller_->ShowAccessibilityDetailedView();
71}
72
73void SystemTrayTestApi::ShowNetworkDetailedView() {
Ahmed Mehfooz15cebdd2021-03-03 01:07:0774 GetTray()->ShowBubble();
Ahmed Mehfooze32a4b52020-04-14 20:34:1075 GetTray()->bubble_->controller_->ShowNetworkDetailedView(true /* force */);
76}
77
78bool SystemTrayTestApi::IsBubbleViewVisible(int view_id, bool open_tray) {
79 if (open_tray)
Ahmed Mehfooz15cebdd2021-03-03 01:07:0780 GetTray()->ShowBubble();
Ahmed Mehfooze32a4b52020-04-14 20:34:1081 views::View* view = GetBubbleView(view_id);
82 return view && view->GetVisible();
83}
84
85void SystemTrayTestApi::ClickBubbleView(int view_id) {
86 views::View* view = GetBubbleView(view_id);
87 if (view && view->GetVisible()) {
88 gfx::Point cursor_location = view->GetLocalBounds().CenterPoint();
89 views::View::ConvertPointToScreen(view, &cursor_location);
90
91 ui::test::EventGenerator generator(GetRootWindow(view->GetWidget()));
92 generator.MoveMouseTo(cursor_location);
93 generator.ClickLeftButton();
94 }
95}
96
Jan Wilken Dörrie85285b02021-03-11 23:38:4797std::u16string SystemTrayTestApi::GetBubbleViewTooltip(int view_id) {
Ahmed Mehfooze32a4b52020-04-14 20:34:1098 views::View* view = GetBubbleView(view_id);
Jan Wilken Dörrie85285b02021-03-11 23:38:4799 return view ? view->GetTooltipText(gfx::Point()) : std::u16string();
Ahmed Mehfooze32a4b52020-04-14 20:34:10100}
101
Jan Wilken Dörrie85285b02021-03-11 23:38:47102std::u16string SystemTrayTestApi::GetBubbleViewText(int view_id) {
Andre Lee0f195472020-07-22 21:24:25103 views::View* view = GetBubbleView(view_id);
Jan Wilken Dörrie85285b02021-03-11 23:38:47104 return view ? static_cast<views::Label*>(view)->GetText() : std::u16string();
Andre Lee0f195472020-07-22 21:24:25105}
106
Ahmed Mehfooze32a4b52020-04-14 20:34:10107bool SystemTrayTestApi::Is24HourClock() {
108 base::HourClockType type =
109 GetTray()->time_view_->time_view()->GetHourTypeForTesting();
110 return type == base::k24HourClock;
111}
112
113void SystemTrayTestApi::TapSelectToSpeakTray() {
114 // The Select-to-Speak tray doesn't actually use the event, so construct
115 // a bare bones event to perform the action.
Dave Tapuska1621efb2020-04-29 15:39:54116 ui::TouchEvent event(ui::ET_TOUCH_PRESSED, gfx::Point(),
117 base::TimeTicks::Now(),
118 ui::PointerDetails(ui::EventPointerType::kTouch), 0);
Ahmed Mehfooze32a4b52020-04-14 20:34:10119 StatusAreaWidget* status_area_widget =
120 RootWindowController::ForWindow(GetTray()->GetWidget()->GetNativeWindow())
121 ->GetStatusAreaWidget();
122 status_area_widget->select_to_speak_tray()->PerformAction(event);
123}
124
125message_center::MessagePopupView*
126SystemTrayTestApi::GetPopupViewForNotificationID(
127 const std::string& notification_id) {
128 return GetTray()->GetPopupViewForNotificationID(notification_id);
129}
130
131// static
132std::unique_ptr<SystemTrayTestApi> SystemTrayTestApi::Create() {
133 return std::make_unique<SystemTrayTestApi>();
134}
135
136} // namespace ash