OLD | NEW |
---|---|
(Empty) | |
1 // Copyright 2013 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/system/chromeos/screen_security/screen_tray_item.h" | |
6 | |
7 #include "ash/system/chromeos/screen_security/screen_capture_tray_item.h" | |
8 #include "ash/system/chromeos/screen_security/screen_share_tray_item.h" | |
9 #include "ash/test/ash_test_base.h" | |
10 #include "base/callback.h" | |
11 #include "base/strings/utf_string_conversions.h" | |
12 #include "ui/base/events/event.h" | |
13 #include "ui/gfx/point.h" | |
14 #include "ui/views/view.h" | |
15 | |
16 namespace ash { | |
17 namespace internal { | |
18 | |
19 // Test with unicode strings. | |
20 const char kTestScreenCaptureAppName[] = "Screen Capture Unit Test ಠ_ಠ"; | |
James Cook
2013/06/07 18:45:56
I don't think you should put raw Unicode character
| |
21 const char kTestScreenShareHelperName[] = "宋腾"; | |
22 | |
23 SystemTray* GetSystemTray() { | |
24 return Shell::GetInstance()->GetPrimarySystemTray(); | |
25 } | |
26 | |
27 SystemTrayNotifier* GetSystemTrayNotifier() { | |
28 return Shell::GetInstance()->system_tray_notifier(); | |
29 } | |
30 | |
31 void ClickViewCenter(views::View* view) { | |
32 gfx::Point click_location_in_local = | |
33 gfx::Point(view->width() / 2, view->height() / 2); | |
34 view->OnMousePressed(ui::MouseEvent(ui::ET_MOUSE_PRESSED, | |
35 click_location_in_local, | |
36 click_location_in_local, | |
37 ui::EF_NONE)); | |
38 } | |
39 | |
40 class ScreenTrayItemTest : public ash::test::AshTestBase { | |
41 public: | |
42 ScreenTrayItemTest() | |
43 : tray_item_(NULL), stop_callback_hit_count_(0) {} | |
44 virtual ~ScreenTrayItemTest() {} | |
45 | |
46 ScreenTrayItem* tray_item() { return tray_item_; } | |
47 void set_tray_item(ScreenTrayItem* tray_item) { tray_item_ = tray_item; } | |
48 | |
49 int stop_callback_hit_count() const { return stop_callback_hit_count_; } | |
50 | |
51 void StartSession() { | |
52 tray_item_->Start( | |
53 base::Bind(&ScreenTrayItemTest::StopCallback, base::Unretained(this))); | |
54 } | |
55 | |
56 void StopSession() { | |
57 tray_item_->Stop(); | |
58 } | |
59 | |
60 void StopCallback() { | |
61 stop_callback_hit_count_++; | |
62 } | |
63 | |
64 private: | |
65 ScreenTrayItem* tray_item_; | |
66 int stop_callback_hit_count_; | |
67 | |
68 DISALLOW_COPY_AND_ASSIGN(ScreenTrayItemTest); | |
69 }; | |
70 | |
71 class ScreenCaptureTest : public ScreenTrayItemTest { | |
72 public: | |
73 ScreenCaptureTest() {} | |
74 virtual ~ScreenCaptureTest() {} | |
75 | |
76 virtual void SetUp() OVERRIDE { | |
77 test::AshTestBase::SetUp(); | |
78 // This tray item is owned by its parent system tray view and will | |
79 // be deleted automatically when its parent is destroyed in AshTestBase. | |
80 set_tray_item(new ScreenCaptureTrayItem(GetSystemTray())); | |
81 } | |
82 | |
83 DISALLOW_COPY_AND_ASSIGN(ScreenCaptureTest); | |
84 }; | |
85 | |
86 class ScreenShareTest : public ScreenTrayItemTest { | |
87 public: | |
88 ScreenShareTest() {} | |
89 virtual ~ScreenShareTest() {} | |
90 | |
91 virtual void SetUp() OVERRIDE { | |
92 test::AshTestBase::SetUp(); | |
93 // This tray item is owned by its parent system tray view and will | |
94 // be deleted automatically when its parent is destroyed in AshTestBase. | |
95 set_tray_item(new ScreenShareTrayItem(GetSystemTray())); | |
96 } | |
97 | |
98 DISALLOW_COPY_AND_ASSIGN(ScreenShareTest); | |
99 }; | |
100 | |
101 void TestStartAndStop(ScreenTrayItemTest* test) { | |
102 ScreenTrayItem* tray_item = test->tray_item(); | |
103 | |
104 EXPECT_FALSE(tray_item->is_started()); | |
105 EXPECT_EQ(0, test->stop_callback_hit_count()); | |
106 | |
107 test->StartSession(); | |
108 EXPECT_TRUE(tray_item->is_started()); | |
109 | |
110 test->StopSession(); | |
111 EXPECT_FALSE(tray_item->is_started()); | |
112 EXPECT_EQ(1, test->stop_callback_hit_count()); | |
113 } | |
114 | |
115 TEST_F(ScreenCaptureTest, StartAndStop) { TestStartAndStop(this); } | |
116 TEST_F(ScreenShareTest, StartAndStop) { TestStartAndStop(this); } | |
117 | |
118 void TestNotificationStartAndStop(ScreenTrayItemTest* test, | |
119 const base::Closure& start_function, | |
120 const base::Closure& stop_function) { | |
121 ScreenTrayItem* tray_item = test->tray_item(); | |
122 EXPECT_FALSE(tray_item->is_started()); | |
123 | |
124 start_function.Run(); | |
125 EXPECT_TRUE(tray_item->is_started()); | |
126 | |
127 // The stop callback shouldn't be called because we stopped | |
128 // through the notification system. | |
129 stop_function.Run(); | |
130 EXPECT_FALSE(tray_item->is_started()); | |
131 EXPECT_EQ(0, test->stop_callback_hit_count()); | |
132 } | |
133 | |
134 TEST_F(ScreenCaptureTest, NotificationStartAndStop) { | |
135 base::Closure start_function = | |
136 base::Bind(&SystemTrayNotifier::NotifyScreenCaptureStart, | |
137 base::Unretained(GetSystemTrayNotifier()), | |
138 base::Bind(&ScreenTrayItemTest::StopCallback, | |
139 base::Unretained(this)), | |
140 base::UTF8ToUTF16(kTestScreenCaptureAppName)); | |
141 | |
142 base::Closure stop_function = | |
143 base::Bind(&SystemTrayNotifier::NotifyScreenCaptureStop, | |
144 base::Unretained(GetSystemTrayNotifier())); | |
145 | |
146 TestNotificationStartAndStop(this, start_function, stop_function); | |
147 } | |
148 | |
149 TEST_F(ScreenShareTest, NotificationStartAndStop) { | |
150 base::Closure start_func = | |
151 base::Bind(&SystemTrayNotifier::NotifyScreenShareStart, | |
152 base::Unretained(GetSystemTrayNotifier()), | |
153 base::Bind(&ScreenTrayItemTest::StopCallback, | |
154 base::Unretained(this)), | |
155 base::UTF8ToUTF16(kTestScreenShareHelperName)); | |
156 | |
157 base::Closure stop_func = | |
158 base::Bind(&SystemTrayNotifier::NotifyScreenShareStop, | |
159 base::Unretained(GetSystemTrayNotifier())); | |
160 | |
161 TestNotificationStartAndStop(this, start_func, stop_func); | |
162 } | |
163 | |
164 | |
165 void TestNotificationView(ScreenTrayItemTest* test) { | |
166 ScreenTrayItem* tray_item = test->tray_item(); | |
167 | |
168 test->StartSession(); | |
169 EXPECT_TRUE(tray_item->notification_view()->visible()); | |
170 | |
171 // Clicking on the notification view should dismiss the view | |
172 ClickViewCenter(tray_item->notification_view()); | |
173 EXPECT_FALSE(tray_item->notification_view()); | |
174 | |
175 test->StopSession(); | |
176 } | |
177 | |
178 TEST_F(ScreenCaptureTest, NotificationView) { TestNotificationView(this); } | |
179 TEST_F(ScreenShareTest, NotificationView) { TestNotificationView(this); } | |
180 | |
181 } // namespace internal | |
182 } // namespace ash | |
OLD | NEW |