Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(53)

Side by Side Diff: ash/system/tray/system_tray_unittest.cc

Issue 2930123002: Tablet WM : Swiping on system tray bubble. (Closed)
Patch Set: Addressed xiyuan's comments. Created 3 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "ash/system/tray/system_tray.h" 5 #include "ash/system/tray/system_tray.h"
6 6
7 #include <string> 7 #include <string>
8 #include <vector> 8 #include <vector>
9 9
10 #include "ash/accelerators/accelerator_controller.h" 10 #include "ash/accelerators/accelerator_controller.h"
11 #include "ash/accessibility_delegate.h" 11 #include "ash/accessibility_delegate.h"
12 #include "ash/public/cpp/shell_window_ids.h" 12 #include "ash/public/cpp/shell_window_ids.h"
13 #include "ash/root_window_controller.h" 13 #include "ash/root_window_controller.h"
14 #include "ash/shelf/shelf.h" 14 #include "ash/shelf/shelf.h"
15 #include "ash/shell.h" 15 #include "ash/shell.h"
16 #include "ash/system/status_area_widget.h" 16 #include "ash/system/status_area_widget.h"
17 #include "ash/system/tray/system_tray_bubble.h" 17 #include "ash/system/tray/system_tray_bubble.h"
18 #include "ash/system/tray/system_tray_item.h" 18 #include "ash/system/tray/system_tray_item.h"
19 #include "ash/system/tray/system_tray_test_api.h"
19 #include "ash/system/tray/tray_constants.h" 20 #include "ash/system/tray/tray_constants.h"
20 #include "ash/system/web_notification/web_notification_tray.h" 21 #include "ash/system/web_notification/web_notification_tray.h"
21 #include "ash/test/ash_test_base.h" 22 #include "ash/test/ash_test_base.h"
22 #include "ash/test/status_area_widget_test_helper.h" 23 #include "ash/test/status_area_widget_test_helper.h"
23 #include "ash/test/test_system_tray_item.h" 24 #include "ash/test/test_system_tray_item.h"
24 #include "ash/wm/window_util.h" 25 #include "ash/wm/window_util.h"
25 #include "base/memory/ptr_util.h" 26 #include "base/memory/ptr_util.h"
26 #include "base/run_loop.h" 27 #include "base/run_loop.h"
27 #include "base/test/histogram_tester.h" 28 #include "base/test/histogram_tester.h"
28 #include "ui/base/ui_base_types.h" 29 #include "ui/base/ui_base_types.h"
(...skipping 20 matching lines...) Expand all
49 ~ModalWidgetDelegate() override {} 50 ~ModalWidgetDelegate() override {}
50 51
51 ui::ModalType GetModalType() const override { return ui::MODAL_TYPE_SYSTEM; } 52 ui::ModalType GetModalType() const override { return ui::MODAL_TYPE_SYSTEM; }
52 53
53 private: 54 private:
54 DISALLOW_COPY_AND_ASSIGN(ModalWidgetDelegate); 55 DISALLOW_COPY_AND_ASSIGN(ModalWidgetDelegate);
55 }; 56 };
56 57
57 } // namespace 58 } // namespace
58 59
59 typedef AshTestBase SystemTrayTest; 60 class SystemTrayTest : public AshTestBase {
61 public:
62 SystemTrayTest() {}
63 ~SystemTrayTest() override {}
64
65 void SendGestureEvent(gfx::Point& start, float delta) {
66 SystemTray* system_tray = GetPrimarySystemTray();
67 base::TimeTicks timestamp = base::TimeTicks::Now();
68 ui::GestureEventDetails begin_details(ui::ET_GESTURE_SCROLL_BEGIN);
69 ui::GestureEvent begin_event = ui::GestureEvent(
70 start.x(), start.y(), ui::EF_NONE, timestamp, begin_details);
71 system_tray->OnGestureEvent(&begin_event);
72
73 ui::GestureEventDetails update_details(ui::ET_GESTURE_SCROLL_UPDATE, 0,
74 delta);
75 timestamp += base::TimeDelta::FromMilliseconds(100);
76 ui::GestureEvent update_event = ui::GestureEvent(
77 start.x(), start.y(), ui::EF_NONE, timestamp, update_details);
78 system_tray->OnGestureEvent(&update_event);
79
80 ui::GestureEventDetails end_details(ui::ET_GESTURE_SCROLL_END);
81 ui::GestureEvent end_event = ui::GestureEvent(
82 start.x(), start.y() + delta, ui::EF_NONE, timestamp, end_details);
83 system_tray->OnGestureEvent(&end_event);
84 }
85
86 float GetSystemBubbleHeight() {
87 SystemTray* system_tray = GetPrimarySystemTray();
88 gfx::Rect bounds = gfx::Rect();
89 if (system_tray->HasSystemBubble()) {
90 bounds = system_tray->GetSystemBubble()
91 ->bubble_view()
92 ->GetWidget()
93 ->GetWindowBoundsInScreen();
94 }
95 return bounds.height();
96 }
97
98 private:
99 DISALLOW_COPY_AND_ASSIGN(SystemTrayTest);
100 };
101
102 TEST_F(SystemTrayTest, SwipingOnSystemTray) {
tdanderson 2017/06/19 16:19:38 Can you also add a test to verify the correct beha
minch1 2017/06/20 16:45:35 Done.
103 Shelf* shelf = GetPrimaryShelf();
104 SystemTray* system_tray = GetPrimarySystemTray();
105 gfx::Point start = system_tray->GetBoundsInScreen().CenterPoint();
106 shelf->SetAlignment(SHELF_ALIGNMENT_BOTTOM);
107 system_tray->ShowDefaultView(BUBBLE_CREATE_NEW);
108 float delta = -GetSystemBubbleHeight();
109 system_tray->CloseSystemBubble();
110
111 // Swiping up on the system tray has no effect if it is not in maximize mode.
112 SystemTrayTestApi(system_tray).set_in_maximize_mode(false);
113 ASSERT_FALSE(system_tray->HasSystemBubble());
114 SendGestureEvent(start, delta);
115 EXPECT_FALSE(system_tray->HasSystemBubble());
116
117 // Swiping up on the system tray should show the system tray bubble if it is
118 // in maximize mode.
119 SystemTrayTestApi(system_tray).set_in_maximize_mode(true);
120 SendGestureEvent(start, delta);
tdanderson 2017/06/19 16:19:39 Consider adding a test case where |delta| is past
minch1 2017/06/20 16:45:35 Done.
121 EXPECT_TRUE(system_tray->HasSystemBubble());
122 system_tray->CloseSystemBubble();
123
124 // Swiping up less than one third of the bubble's height should not show the
125 // bubble.
126 delta /= 4;
127 SendGestureEvent(start, delta);
128 EXPECT_FALSE(system_tray->HasSystemBubble());
129
130 // Swiping up on system tray should not show the system tray bubble if the
131 // shelf is left alignment.
132 delta = GetSystemBubbleHeight();
133 shelf->SetAlignment(SHELF_ALIGNMENT_LEFT);
134 SendGestureEvent(start, delta);
135 EXPECT_FALSE(system_tray->HasSystemBubble());
136
137 // Swiping up on system tray should not show the system tray bubble if the
138 // shelf is right alignment.
139 shelf->SetAlignment(SHELF_ALIGNMENT_RIGHT);
140 SendGestureEvent(start, delta);
141 EXPECT_FALSE(system_tray->HasSystemBubble());
142
143 // Swiping down on the shelf should not show the system tray bubble.
144 shelf->SetAlignment(SHELF_ALIGNMENT_BOTTOM);
145 delta = -delta;
146 SendGestureEvent(start, delta);
147 EXPECT_FALSE(system_tray->HasSystemBubble());
148 }
60 149
61 // Verifies only the visible default views are recorded in the 150 // Verifies only the visible default views are recorded in the
62 // "Ash.SystemMenu.DefaultView.VisibleItems" histogram. 151 // "Ash.SystemMenu.DefaultView.VisibleItems" histogram.
63 TEST_F(SystemTrayTest, OnlyVisibleItemsRecorded) { 152 TEST_F(SystemTrayTest, OnlyVisibleItemsRecorded) {
64 SystemTray* tray = GetPrimarySystemTray(); 153 SystemTray* tray = GetPrimarySystemTray();
65 ASSERT_TRUE(tray->GetWidget()); 154 ASSERT_TRUE(tray->GetWidget());
66 155
67 TestSystemTrayItem* test_item = new TestSystemTrayItem(); 156 TestSystemTrayItem* test_item = new TestSystemTrayItem();
68 tray->AddTrayItem(base::WrapUnique(test_item)); 157 tray->AddTrayItem(base::WrapUnique(test_item));
69 158
(...skipping 516 matching lines...) Expand 10 before | Expand all | Expand 10 after
586 675
587 EXPECT_EQ(0, notification_tray->tray_bubble_height_for_test()); 676 EXPECT_EQ(0, notification_tray->tray_bubble_height_for_test());
588 } 677 }
589 678
590 TEST_F(SystemTrayTest, SeparatorThickness) { 679 TEST_F(SystemTrayTest, SeparatorThickness) {
591 EXPECT_EQ(kSeparatorWidth, views::Separator::kThickness); 680 EXPECT_EQ(kSeparatorWidth, views::Separator::kThickness);
592 } 681 }
593 682
594 } // namespace test 683 } // namespace test
595 } // namespace ash 684 } // namespace ash
OLDNEW
« ash/system/tray/system_tray_bubble.cc ('K') | « ash/system/tray/system_tray_test_api.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698