| OLD | NEW |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 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 | 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/chromeos/screen_security/screen_tray_item.h" | 5 #include "ash/system/chromeos/screen_security/screen_tray_item.h" |
| 6 | 6 |
| 7 #include "ash/common/system/tray/system_tray_notifier.h" | 7 #include "ash/common/system/tray/system_tray_notifier.h" |
| 8 #include "ash/common/system/tray/tray_item_view.h" | 8 #include "ash/common/system/tray/tray_item_view.h" |
| 9 #include "ash/common/wm_shell.h" | 9 #include "ash/common/wm_shell.h" |
| 10 #include "ash/system/chromeos/screen_security/screen_capture_tray_item.h" | 10 #include "ash/system/chromeos/screen_security/screen_capture_tray_item.h" |
| (...skipping 18 matching lines...) Expand all Loading... |
| 29 void ClickViewCenter(views::View* view) { | 29 void ClickViewCenter(views::View* view) { |
| 30 gfx::Point click_location_in_local = | 30 gfx::Point click_location_in_local = |
| 31 gfx::Point(view->width() / 2, view->height() / 2); | 31 gfx::Point(view->width() / 2, view->height() / 2); |
| 32 view->OnMousePressed(ui::MouseEvent( | 32 view->OnMousePressed(ui::MouseEvent( |
| 33 ui::ET_MOUSE_PRESSED, click_location_in_local, click_location_in_local, | 33 ui::ET_MOUSE_PRESSED, click_location_in_local, click_location_in_local, |
| 34 ui::EventTimeForNow(), ui::EF_NONE, ui::EF_NONE)); | 34 ui::EventTimeForNow(), ui::EF_NONE, ui::EF_NONE)); |
| 35 } | 35 } |
| 36 | 36 |
| 37 class ScreenTrayItemTest : public ash::test::AshTestBase { | 37 class ScreenTrayItemTest : public ash::test::AshTestBase { |
| 38 public: | 38 public: |
| 39 ScreenTrayItemTest() | 39 ScreenTrayItemTest() : tray_item_(NULL), stop_callback_hit_count_(0) {} |
| 40 : tray_item_(NULL), stop_callback_hit_count_(0) {} | |
| 41 ~ScreenTrayItemTest() override {} | 40 ~ScreenTrayItemTest() override {} |
| 42 | 41 |
| 43 ScreenTrayItem* tray_item() { return tray_item_; } | 42 ScreenTrayItem* tray_item() { return tray_item_; } |
| 44 void set_tray_item(ScreenTrayItem* tray_item) { tray_item_ = tray_item; } | 43 void set_tray_item(ScreenTrayItem* tray_item) { tray_item_ = tray_item; } |
| 45 | 44 |
| 46 int stop_callback_hit_count() const { return stop_callback_hit_count_; } | 45 int stop_callback_hit_count() const { return stop_callback_hit_count_; } |
| 47 | 46 |
| 48 void SetUp() override { | 47 void SetUp() override { |
| 49 test::AshTestBase::SetUp(); | 48 test::AshTestBase::SetUp(); |
| 50 TrayItemView::DisableAnimationsForTest(); | 49 TrayItemView::DisableAnimationsForTest(); |
| 51 } | 50 } |
| 52 | 51 |
| 53 void StartSession() { | 52 void StartSession() { |
| 54 tray_item_->Start( | 53 tray_item_->Start( |
| 55 base::Bind(&ScreenTrayItemTest::StopCallback, base::Unretained(this))); | 54 base::Bind(&ScreenTrayItemTest::StopCallback, base::Unretained(this))); |
| 56 } | 55 } |
| 57 | 56 |
| 58 void StopSession() { | 57 void StopSession() { tray_item_->Stop(); } |
| 59 tray_item_->Stop(); | |
| 60 } | |
| 61 | 58 |
| 62 void StopCallback() { | 59 void StopCallback() { stop_callback_hit_count_++; } |
| 63 stop_callback_hit_count_++; | |
| 64 } | |
| 65 | 60 |
| 66 private: | 61 private: |
| 67 ScreenTrayItem* tray_item_; | 62 ScreenTrayItem* tray_item_; |
| 68 int stop_callback_hit_count_; | 63 int stop_callback_hit_count_; |
| 69 | 64 |
| 70 DISALLOW_COPY_AND_ASSIGN(ScreenTrayItemTest); | 65 DISALLOW_COPY_AND_ASSIGN(ScreenTrayItemTest); |
| 71 }; | 66 }; |
| 72 | 67 |
| 73 class ScreenCaptureTest : public ScreenTrayItemTest { | 68 class ScreenCaptureTest : public ScreenTrayItemTest { |
| 74 public: | 69 public: |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 111 EXPECT_EQ(0, test->stop_callback_hit_count()); | 106 EXPECT_EQ(0, test->stop_callback_hit_count()); |
| 112 | 107 |
| 113 test->StartSession(); | 108 test->StartSession(); |
| 114 EXPECT_TRUE(tray_item->is_started()); | 109 EXPECT_TRUE(tray_item->is_started()); |
| 115 | 110 |
| 116 test->StopSession(); | 111 test->StopSession(); |
| 117 EXPECT_FALSE(tray_item->is_started()); | 112 EXPECT_FALSE(tray_item->is_started()); |
| 118 EXPECT_EQ(1, test->stop_callback_hit_count()); | 113 EXPECT_EQ(1, test->stop_callback_hit_count()); |
| 119 } | 114 } |
| 120 | 115 |
| 121 TEST_F(ScreenCaptureTest, StartAndStop) { TestStartAndStop(this); } | 116 TEST_F(ScreenCaptureTest, StartAndStop) { |
| 122 TEST_F(ScreenShareTest, StartAndStop) { TestStartAndStop(this); } | 117 TestStartAndStop(this); |
| 118 } |
| 119 TEST_F(ScreenShareTest, StartAndStop) { |
| 120 TestStartAndStop(this); |
| 121 } |
| 123 | 122 |
| 124 void TestNotificationStartAndStop(ScreenTrayItemTest* test, | 123 void TestNotificationStartAndStop(ScreenTrayItemTest* test, |
| 125 const base::Closure& start_function, | 124 const base::Closure& start_function, |
| 126 const base::Closure& stop_function) { | 125 const base::Closure& stop_function) { |
| 127 ScreenTrayItem* tray_item = test->tray_item(); | 126 ScreenTrayItem* tray_item = test->tray_item(); |
| 128 EXPECT_FALSE(tray_item->is_started()); | 127 EXPECT_FALSE(tray_item->is_started()); |
| 129 | 128 |
| 130 start_function.Run(); | 129 start_function.Run(); |
| 131 EXPECT_TRUE(tray_item->is_started()); | 130 EXPECT_TRUE(tray_item->is_started()); |
| 132 | 131 |
| 133 // The stop callback shouldn't be called because we stopped | 132 // The stop callback shouldn't be called because we stopped |
| 134 // through the notification system. | 133 // through the notification system. |
| 135 stop_function.Run(); | 134 stop_function.Run(); |
| 136 EXPECT_FALSE(tray_item->is_started()); | 135 EXPECT_FALSE(tray_item->is_started()); |
| 137 EXPECT_EQ(0, test->stop_callback_hit_count()); | 136 EXPECT_EQ(0, test->stop_callback_hit_count()); |
| 138 } | 137 } |
| 139 | 138 |
| 140 TEST_F(ScreenCaptureTest, NotificationStartAndStop) { | 139 TEST_F(ScreenCaptureTest, NotificationStartAndStop) { |
| 141 base::Closure start_function = | 140 base::Closure start_function = base::Bind( |
| 142 base::Bind(&SystemTrayNotifier::NotifyScreenCaptureStart, | 141 &SystemTrayNotifier::NotifyScreenCaptureStart, |
| 143 base::Unretained(WmShell::Get()->system_tray_notifier()), | 142 base::Unretained(WmShell::Get()->system_tray_notifier()), |
| 144 base::Bind(&ScreenTrayItemTest::StopCallback, | 143 base::Bind(&ScreenTrayItemTest::StopCallback, base::Unretained(this)), |
| 145 base::Unretained(this)), | 144 base::UTF8ToUTF16(kTestScreenCaptureAppName)); |
| 146 base::UTF8ToUTF16(kTestScreenCaptureAppName)); | |
| 147 | 145 |
| 148 base::Closure stop_function = | 146 base::Closure stop_function = |
| 149 base::Bind(&SystemTrayNotifier::NotifyScreenCaptureStop, | 147 base::Bind(&SystemTrayNotifier::NotifyScreenCaptureStop, |
| 150 base::Unretained(WmShell::Get()->system_tray_notifier())); | 148 base::Unretained(WmShell::Get()->system_tray_notifier())); |
| 151 | 149 |
| 152 TestNotificationStartAndStop(this, start_function, stop_function); | 150 TestNotificationStartAndStop(this, start_function, stop_function); |
| 153 } | 151 } |
| 154 | 152 |
| 155 TEST_F(ScreenShareTest, NotificationStartAndStop) { | 153 TEST_F(ScreenShareTest, NotificationStartAndStop) { |
| 156 base::Closure start_func = | 154 base::Closure start_func = base::Bind( |
| 157 base::Bind(&SystemTrayNotifier::NotifyScreenShareStart, | 155 &SystemTrayNotifier::NotifyScreenShareStart, |
| 158 base::Unretained(WmShell::Get()->system_tray_notifier()), | 156 base::Unretained(WmShell::Get()->system_tray_notifier()), |
| 159 base::Bind(&ScreenTrayItemTest::StopCallback, | 157 base::Bind(&ScreenTrayItemTest::StopCallback, base::Unretained(this)), |
| 160 base::Unretained(this)), | 158 base::UTF8ToUTF16(kTestScreenShareHelperName)); |
| 161 base::UTF8ToUTF16(kTestScreenShareHelperName)); | |
| 162 | 159 |
| 163 base::Closure stop_func = | 160 base::Closure stop_func = |
| 164 base::Bind(&SystemTrayNotifier::NotifyScreenShareStop, | 161 base::Bind(&SystemTrayNotifier::NotifyScreenShareStop, |
| 165 base::Unretained(WmShell::Get()->system_tray_notifier())); | 162 base::Unretained(WmShell::Get()->system_tray_notifier())); |
| 166 | 163 |
| 167 TestNotificationStartAndStop(this, start_func, stop_func); | 164 TestNotificationStartAndStop(this, start_func, stop_func); |
| 168 } | 165 } |
| 169 | 166 |
| 170 void TestNotificationView(ScreenTrayItemTest* test) { | 167 void TestNotificationView(ScreenTrayItemTest* test) { |
| 171 ScreenTrayItem* tray_item = test->tray_item(); | 168 ScreenTrayItem* tray_item = test->tray_item(); |
| 172 | 169 |
| 173 test->StartSession(); | 170 test->StartSession(); |
| 174 message_center::MessageCenter* message_center = | 171 message_center::MessageCenter* message_center = |
| 175 message_center::MessageCenter::Get(); | 172 message_center::MessageCenter::Get(); |
| 176 EXPECT_TRUE(message_center->FindVisibleNotificationById( | 173 EXPECT_TRUE(message_center->FindVisibleNotificationById( |
| 177 tray_item->GetNotificationId())); | 174 tray_item->GetNotificationId())); |
| 178 test->StopSession(); | 175 test->StopSession(); |
| 179 } | 176 } |
| 180 | 177 |
| 181 TEST_F(ScreenCaptureTest, NotificationView) { TestNotificationView(this); } | 178 TEST_F(ScreenCaptureTest, NotificationView) { |
| 182 TEST_F(ScreenShareTest, NotificationView) { TestNotificationView(this); } | 179 TestNotificationView(this); |
| 180 } |
| 181 TEST_F(ScreenShareTest, NotificationView) { |
| 182 TestNotificationView(this); |
| 183 } |
| 183 | 184 |
| 184 void TestSystemTrayInteraction(ScreenTrayItemTest* test) { | 185 void TestSystemTrayInteraction(ScreenTrayItemTest* test) { |
| 185 ScreenTrayItem* tray_item = test->tray_item(); | 186 ScreenTrayItem* tray_item = test->tray_item(); |
| 186 EXPECT_FALSE(tray_item->tray_view()->visible()); | 187 EXPECT_FALSE(tray_item->tray_view()->visible()); |
| 187 | 188 |
| 188 const std::vector<SystemTrayItem*>& tray_items = | 189 const std::vector<SystemTrayItem*>& tray_items = |
| 189 test::AshTestBase::GetPrimarySystemTray()->GetTrayItems(); | 190 test::AshTestBase::GetPrimarySystemTray()->GetTrayItems(); |
| 190 EXPECT_NE(std::find(tray_items.begin(), tray_items.end(), tray_item), | 191 EXPECT_NE(std::find(tray_items.begin(), tray_items.end(), tray_item), |
| 191 tray_items.end()); | 192 tray_items.end()); |
| 192 | 193 |
| (...skipping 16 matching lines...) Expand all Loading... |
| 209 | 210 |
| 210 TEST_F(ScreenCaptureTest, SystemTrayInteraction) { | 211 TEST_F(ScreenCaptureTest, SystemTrayInteraction) { |
| 211 TestSystemTrayInteraction(this); | 212 TestSystemTrayInteraction(this); |
| 212 } | 213 } |
| 213 | 214 |
| 214 TEST_F(ScreenShareTest, SystemTrayInteraction) { | 215 TEST_F(ScreenShareTest, SystemTrayInteraction) { |
| 215 TestSystemTrayInteraction(this); | 216 TestSystemTrayInteraction(this); |
| 216 } | 217 } |
| 217 | 218 |
| 218 } // namespace ash | 219 } // namespace ash |
| OLD | NEW |