Chromium Code Reviews| 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_capture_tray_item.h" | |
| 6 #include "ash/system/chromeos/screen_security/screen_share_tray_item.h" | |
| 7 #include "ash/system/chromeos/screen_security/screen_tray_item.h" | |
| 8 | |
|
James Cook
2013/06/07 14:16:37
Either put the primary test class header include o
Tim Song
2013/06/07 18:14:35
Done.
| |
| 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 const char kTestScreenCaptureAppName[] = "Ash Test"; | |
| 20 const char kTestScreenShareHelperName[] = "Ash Test"; | |
|
James Cook
2013/06/07 14:16:37
nit: Generally we use different strings, integers,
Tim Song
2013/06/07 18:14:35
Done. I just realized that it would be a good idea
| |
| 21 | |
| 22 SystemTray* GetSystemTray() { | |
| 23 return Shell::GetInstance()->GetPrimarySystemTray(); | |
| 24 } | |
| 25 | |
| 26 SystemTrayNotifier* GetSystemTrayNotifier() { | |
| 27 return Shell::GetInstance()->system_tray_notifier(); | |
| 28 } | |
| 29 | |
| 30 void ClickViewCenter(views::View* view) { | |
| 31 gfx::Point click_location = gfx::Point(view->width()/2, view->height()/2); | |
|
James Cook
2013/06/07 14:16:37
Spaces around /
Also, click_location should be cl
Tim Song
2013/06/07 18:14:35
Done.
| |
| 32 view->OnMousePressed(ui::MouseEvent(ui::ET_MOUSE_PRESSED, | |
| 33 click_location, | |
| 34 click_location, | |
| 35 ui::EF_NONE)); | |
| 36 } | |
| 37 | |
| 38 class ScreenTrayItemTest : public ash::test::AshTestBase { | |
| 39 public: | |
| 40 explicit ScreenTrayItemTest() | |
|
James Cook
2013/06/07 14:16:37
no explicit
Tim Song
2013/06/07 18:14:35
Done. I should really keep an eye out when copy pa
| |
| 41 : tray_item_(NULL), stop_callback_hit_count_(0) {} | |
| 42 virtual ~ScreenTrayItemTest() {} | |
| 43 | |
| 44 ScreenTrayItem* tray_item() { return tray_item_; } | |
| 45 uint stop_callback_hit_count() { return stop_callback_hit_count_; } | |
|
James Cook
2013/06/07 14:16:37
int would be fine here. Also, const here (but not
Tim Song
2013/06/07 18:14:35
Done.
| |
| 46 | |
| 47 void StartSession() { | |
| 48 tray_item_->Start( | |
| 49 base::Bind(&ScreenTrayItemTest::StopCallback, base::Unretained(this))); | |
| 50 } | |
| 51 | |
| 52 void StopSession() { | |
| 53 tray_item_->Stop(); | |
| 54 } | |
| 55 | |
| 56 void StopCallback() { | |
| 57 stop_callback_hit_count_++; | |
| 58 } | |
| 59 | |
| 60 protected: | |
| 61 ScreenTrayItem* tray_item_; | |
|
James Cook
2013/06/07 14:16:37
Make this private and use a setter. We generally
Tim Song
2013/06/07 18:14:35
Done. I added the comments about memory management
| |
| 62 uint stop_callback_hit_count_; | |
| 63 | |
| 64 DISALLOW_COPY_AND_ASSIGN(ScreenTrayItemTest); | |
| 65 }; | |
| 66 | |
| 67 class ScreenCaptureTest : public ScreenTrayItemTest { | |
| 68 public: | |
| 69 explicit ScreenCaptureTest() {} | |
| 70 virtual ~ScreenCaptureTest() {} | |
| 71 | |
| 72 virtual void SetUp() OVERRIDE { | |
| 73 test::AshTestBase::SetUp(); | |
| 74 tray_item_ = new ScreenCaptureTrayItem(GetSystemTray()); | |
| 75 } | |
| 76 | |
| 77 DISALLOW_COPY_AND_ASSIGN(ScreenCaptureTest); | |
| 78 }; | |
| 79 | |
| 80 class ScreenShareTest : public ScreenTrayItemTest { | |
| 81 public: | |
| 82 explicit ScreenShareTest() {} | |
| 83 virtual ~ScreenShareTest() {} | |
| 84 | |
| 85 virtual void SetUp() OVERRIDE { | |
| 86 test::AshTestBase::SetUp(); | |
| 87 tray_item_ = new ScreenShareTrayItem(GetSystemTray()); | |
| 88 } | |
| 89 | |
| 90 DISALLOW_COPY_AND_ASSIGN(ScreenShareTest); | |
| 91 }; | |
| 92 | |
| 93 | |
|
James Cook
2013/06/07 14:16:37
nit: one blank line
Tim Song
2013/06/07 18:14:35
Done.
| |
| 94 void TestStartAndStop(ScreenTrayItemTest* test) { | |
| 95 ScreenTrayItem* tray_item = test->tray_item(); | |
| 96 | |
| 97 EXPECT_FALSE(tray_item->is_started()); | |
| 98 EXPECT_EQ(test->stop_callback_hit_count(), 0u); | |
|
James Cook
2013/06/07 14:16:37
expected value goes first:
EXPECT_EQ(0, stop_call
Tim Song
2013/06/07 18:14:35
Done.
| |
| 99 | |
| 100 test->StartSession(); | |
| 101 EXPECT_TRUE(tray_item->is_started()); | |
| 102 | |
| 103 test->StopSession(); | |
| 104 EXPECT_FALSE(tray_item->is_started()); | |
| 105 EXPECT_EQ(test->stop_callback_hit_count(), 1u); | |
| 106 } | |
| 107 | |
| 108 TEST_F(ScreenCaptureTest, StartAndStop) { TestStartAndStop(this); } | |
| 109 TEST_F(ScreenShareTest, StartAndStop) { TestStartAndStop(this); } | |
| 110 | |
| 111 void TestNotificationStartAndStop(ScreenTrayItemTest* test, | |
|
James Cook
2013/06/07 14:16:37
Good: nice descriptive function name
Tim Song
2013/06/07 18:14:35
Thanks!
| |
| 112 const base::Closure& start_func, | |
|
James Cook
2013/06/07 14:16:37
no abbrevations: start_function, stop_function
Tim Song
2013/06/07 18:14:35
Done.
| |
| 113 const base::Closure& stop_func) { | |
| 114 ScreenTrayItem* tray_item = test->tray_item(); | |
| 115 EXPECT_FALSE(tray_item->is_started()); | |
| 116 | |
| 117 start_func.Run(); | |
| 118 EXPECT_TRUE(tray_item->is_started()); | |
| 119 | |
| 120 // The stop callback shouldn't be called because we stopped | |
| 121 // through the notification system. | |
| 122 stop_func.Run(); | |
| 123 EXPECT_FALSE(tray_item->is_started()); | |
| 124 EXPECT_EQ(test->stop_callback_hit_count(), 0u); | |
| 125 } | |
| 126 | |
| 127 TEST_F(ScreenCaptureTest, NotificationStartAndStop) { | |
| 128 base::Closure start_func = | |
| 129 base::Bind(&SystemTrayNotifier::NotifyScreenCaptureStart, | |
| 130 base::Unretained(GetSystemTrayNotifier()), | |
| 131 base::Bind(&ScreenTrayItemTest::StopCallback, | |
| 132 base::Unretained(this)), | |
| 133 base::UTF8ToUTF16(kTestScreenCaptureAppName)); | |
| 134 | |
| 135 base::Closure stop_func = | |
| 136 base::Bind(&SystemTrayNotifier::NotifyScreenCaptureStop, | |
| 137 base::Unretained(GetSystemTrayNotifier())); | |
| 138 | |
| 139 TestNotificationStartAndStop(this, start_func, stop_func); | |
| 140 } | |
| 141 | |
| 142 TEST_F(ScreenShareTest, NotificationStartAndStop) { | |
| 143 base::Closure start_func = | |
| 144 base::Bind(&SystemTrayNotifier::NotifyScreenShareStart, | |
| 145 base::Unretained(GetSystemTrayNotifier()), | |
| 146 base::Bind(&ScreenTrayItemTest::StopCallback, | |
| 147 base::Unretained(this)), | |
| 148 base::UTF8ToUTF16(kTestScreenShareHelperName)); | |
| 149 | |
| 150 base::Closure stop_func = | |
| 151 base::Bind(&SystemTrayNotifier::NotifyScreenShareStop, | |
| 152 base::Unretained(GetSystemTrayNotifier())); | |
| 153 | |
| 154 TestNotificationStartAndStop(this, start_func, stop_func); | |
| 155 } | |
| 156 | |
| 157 | |
| 158 void TestNotificationView(ScreenTrayItemTest* test) { | |
| 159 ScreenTrayItem* tray_item = test->tray_item(); | |
| 160 | |
| 161 test->StartSession(); | |
| 162 EXPECT_TRUE(tray_item->notification_view()->visible()); | |
| 163 | |
| 164 // Clicking on the notification view should dismiss the view | |
| 165 ClickViewCenter(tray_item->notification_view()); | |
| 166 EXPECT_FALSE(tray_item->notification_view()); | |
| 167 | |
| 168 test->StopSession(); | |
| 169 } | |
| 170 | |
| 171 TEST_F(ScreenCaptureTest, NotificationView) { TestNotificationView(this); } | |
| 172 TEST_F(ScreenShareTest, NotificationView) { TestNotificationView(this); } | |
| 173 | |
| 174 } // namespace internal | |
| 175 } // namespace ash | |
| OLD | NEW |