| OLD | NEW |
| (Empty) |
| 1 // Copyright 2014 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/common/system/chromeos/screen_security/screen_tray_item.h" | |
| 6 #include "ash/shell.h" | |
| 7 #include "ash/system/chromeos/multi_user/user_switch_util.h" | |
| 8 #include "ash/system/tray/system_tray.h" | |
| 9 #include "ash/test/ash_test_base.h" | |
| 10 | |
| 11 namespace ash { | |
| 12 | |
| 13 class TrySwitchingUserTest : public ash::test::AshTestBase { | |
| 14 public: | |
| 15 // The action type to perform / check for upon user switching. | |
| 16 enum ActionType { | |
| 17 NO_DIALOG, // No dialog should be shown. | |
| 18 ACCEPT_DIALOG, // A dialog should be shown and we should accept it. | |
| 19 DECLINE_DIALOG, // A dialog should be shown and we do not accept it. | |
| 20 }; | |
| 21 TrySwitchingUserTest() | |
| 22 : capture_item_(NULL), | |
| 23 share_item_(NULL), | |
| 24 stop_capture_callback_hit_count_(0), | |
| 25 stop_share_callback_hit_count_(0), | |
| 26 switch_callback_hit_count_(0) {} | |
| 27 ~TrySwitchingUserTest() override {} | |
| 28 | |
| 29 void SetUp() override { | |
| 30 test::AshTestBase::SetUp(); | |
| 31 TrayItemView::DisableAnimationsForTest(); | |
| 32 SystemTray* system_tray = Shell::GetInstance()->GetPrimarySystemTray(); | |
| 33 share_item_ = system_tray->GetScreenShareItem(); | |
| 34 capture_item_ = system_tray->GetScreenCaptureItem(); | |
| 35 EXPECT_TRUE(share_item_); | |
| 36 EXPECT_TRUE(capture_item_); | |
| 37 } | |
| 38 | |
| 39 // Accessing the capture session functionality. | |
| 40 // Simulates a screen capture session start. | |
| 41 void StartCaptureSession() { | |
| 42 capture_item_->Start(base::Bind(&TrySwitchingUserTest::StopCaptureCallback, | |
| 43 base::Unretained(this))); | |
| 44 } | |
| 45 | |
| 46 // The callback which gets called when the screen capture gets stopped. | |
| 47 void StopCaptureSession() { capture_item_->Stop(); } | |
| 48 | |
| 49 // Simulates a screen capture session stop. | |
| 50 void StopCaptureCallback() { stop_capture_callback_hit_count_++; } | |
| 51 | |
| 52 // Accessing the share session functionality. | |
| 53 // Simulate a Screen share session start. | |
| 54 void StartShareSession() { | |
| 55 share_item_->Start(base::Bind(&TrySwitchingUserTest::StopShareCallback, | |
| 56 base::Unretained(this))); | |
| 57 } | |
| 58 | |
| 59 // Simulates a screen share session stop. | |
| 60 void StopShareSession() { share_item_->Stop(); } | |
| 61 | |
| 62 // The callback which gets called when the screen share gets stopped. | |
| 63 void StopShareCallback() { stop_share_callback_hit_count_++; } | |
| 64 | |
| 65 // Issuing a switch user call which might or might not create a dialog. | |
| 66 // The passed |action| type parameter defines the outcome (which will be | |
| 67 // checked) and the action the user will choose. | |
| 68 void SwitchUser(ActionType action) { | |
| 69 TrySwitchingActiveUser(base::Bind(&TrySwitchingUserTest::SwitchCallback, | |
| 70 base::Unretained(this))); | |
| 71 switch (action) { | |
| 72 case NO_DIALOG: | |
| 73 EXPECT_TRUE(!TestAndTerminateDesktopCastingWarningForTest(true)); | |
| 74 return; | |
| 75 case ACCEPT_DIALOG: | |
| 76 EXPECT_TRUE(TestAndTerminateDesktopCastingWarningForTest(true)); | |
| 77 return; | |
| 78 case DECLINE_DIALOG: | |
| 79 EXPECT_TRUE(TestAndTerminateDesktopCastingWarningForTest(false)); | |
| 80 return; | |
| 81 } | |
| 82 } | |
| 83 | |
| 84 // Called when the user will get actually switched. | |
| 85 void SwitchCallback() { switch_callback_hit_count_++; } | |
| 86 | |
| 87 // Various counter accessors. | |
| 88 int stop_capture_callback_hit_count() const { | |
| 89 return stop_capture_callback_hit_count_; | |
| 90 } | |
| 91 int stop_share_callback_hit_count() const { | |
| 92 return stop_share_callback_hit_count_; | |
| 93 } | |
| 94 int switch_callback_hit_count() const { return switch_callback_hit_count_; } | |
| 95 | |
| 96 private: | |
| 97 // The two items from the SystemTray for the screen capture / share | |
| 98 // functionality. | |
| 99 ScreenTrayItem* capture_item_; | |
| 100 ScreenTrayItem* share_item_; | |
| 101 | |
| 102 // Various counters to query for. | |
| 103 int stop_capture_callback_hit_count_; | |
| 104 int stop_share_callback_hit_count_; | |
| 105 int switch_callback_hit_count_; | |
| 106 | |
| 107 DISALLOW_COPY_AND_ASSIGN(TrySwitchingUserTest); | |
| 108 }; | |
| 109 | |
| 110 // Test that when there is no screen operation going on the user switch will be | |
| 111 // performed as planned. | |
| 112 TEST_F(TrySwitchingUserTest, NoLock) { | |
| 113 EXPECT_EQ(0, switch_callback_hit_count()); | |
| 114 SwitchUser(TrySwitchingUserTest::NO_DIALOG); | |
| 115 EXPECT_EQ(1, switch_callback_hit_count()); | |
| 116 } | |
| 117 | |
| 118 // Test that with a screen capture operation going on, the user will need to | |
| 119 // confirm. Declining will neither change the running state or switch users. | |
| 120 TEST_F(TrySwitchingUserTest, CaptureActiveDeclined) { | |
| 121 EXPECT_EQ(0, switch_callback_hit_count()); | |
| 122 StartCaptureSession(); | |
| 123 SwitchUser(TrySwitchingUserTest::DECLINE_DIALOG); | |
| 124 EXPECT_EQ(0, switch_callback_hit_count()); | |
| 125 EXPECT_EQ(0, stop_capture_callback_hit_count()); | |
| 126 EXPECT_EQ(0, stop_share_callback_hit_count()); | |
| 127 StopCaptureSession(); | |
| 128 EXPECT_EQ(0, switch_callback_hit_count()); | |
| 129 EXPECT_EQ(1, stop_capture_callback_hit_count()); | |
| 130 EXPECT_EQ(0, stop_share_callback_hit_count()); | |
| 131 } | |
| 132 | |
| 133 // Test that with a screen share operation going on, the user will need to | |
| 134 // confirm. Declining will neither change the running state or switch users. | |
| 135 TEST_F(TrySwitchingUserTest, ShareActiveDeclined) { | |
| 136 EXPECT_EQ(0, switch_callback_hit_count()); | |
| 137 StartShareSession(); | |
| 138 SwitchUser(TrySwitchingUserTest::DECLINE_DIALOG); | |
| 139 EXPECT_EQ(0, switch_callback_hit_count()); | |
| 140 EXPECT_EQ(0, stop_capture_callback_hit_count()); | |
| 141 EXPECT_EQ(0, stop_share_callback_hit_count()); | |
| 142 StopShareSession(); | |
| 143 EXPECT_EQ(0, switch_callback_hit_count()); | |
| 144 EXPECT_EQ(0, stop_capture_callback_hit_count()); | |
| 145 EXPECT_EQ(1, stop_share_callback_hit_count()); | |
| 146 } | |
| 147 | |
| 148 // Test that with both operations going on, the user will need to confirm. | |
| 149 // Declining will neither change the running state or switch users. | |
| 150 TEST_F(TrySwitchingUserTest, BothActiveDeclined) { | |
| 151 EXPECT_EQ(0, switch_callback_hit_count()); | |
| 152 StartShareSession(); | |
| 153 StartCaptureSession(); | |
| 154 SwitchUser(TrySwitchingUserTest::DECLINE_DIALOG); | |
| 155 EXPECT_EQ(0, switch_callback_hit_count()); | |
| 156 EXPECT_EQ(0, stop_capture_callback_hit_count()); | |
| 157 EXPECT_EQ(0, stop_share_callback_hit_count()); | |
| 158 StopShareSession(); | |
| 159 StopCaptureSession(); | |
| 160 EXPECT_EQ(0, switch_callback_hit_count()); | |
| 161 EXPECT_EQ(1, stop_capture_callback_hit_count()); | |
| 162 EXPECT_EQ(1, stop_share_callback_hit_count()); | |
| 163 } | |
| 164 | |
| 165 // Test that with a screen capture operation going on, the user will need to | |
| 166 // confirm. Accepting will change to stopped state and switch users. | |
| 167 TEST_F(TrySwitchingUserTest, CaptureActiveAccepted) { | |
| 168 EXPECT_EQ(0, switch_callback_hit_count()); | |
| 169 StartCaptureSession(); | |
| 170 SwitchUser(TrySwitchingUserTest::ACCEPT_DIALOG); | |
| 171 EXPECT_EQ(1, switch_callback_hit_count()); | |
| 172 EXPECT_EQ(1, stop_capture_callback_hit_count()); | |
| 173 EXPECT_EQ(0, stop_share_callback_hit_count()); | |
| 174 // Another stop should have no effect. | |
| 175 StopCaptureSession(); | |
| 176 EXPECT_EQ(1, switch_callback_hit_count()); | |
| 177 EXPECT_EQ(1, stop_capture_callback_hit_count()); | |
| 178 EXPECT_EQ(0, stop_share_callback_hit_count()); | |
| 179 } | |
| 180 | |
| 181 // Test that with a screen share operation going on, the user will need to | |
| 182 // confirm. Accepting will change to stopped state and switch users. | |
| 183 TEST_F(TrySwitchingUserTest, ShareActiveAccepted) { | |
| 184 EXPECT_EQ(0, switch_callback_hit_count()); | |
| 185 StartShareSession(); | |
| 186 SwitchUser(TrySwitchingUserTest::ACCEPT_DIALOG); | |
| 187 EXPECT_EQ(1, switch_callback_hit_count()); | |
| 188 EXPECT_EQ(0, stop_capture_callback_hit_count()); | |
| 189 EXPECT_EQ(1, stop_share_callback_hit_count()); | |
| 190 // Another stop should have no effect. | |
| 191 StopShareSession(); | |
| 192 EXPECT_EQ(1, switch_callback_hit_count()); | |
| 193 EXPECT_EQ(0, stop_capture_callback_hit_count()); | |
| 194 EXPECT_EQ(1, stop_share_callback_hit_count()); | |
| 195 } | |
| 196 | |
| 197 // Test that with both operations going on, the user will need to confirm. | |
| 198 // Accepting will change to stopped state and switch users. | |
| 199 TEST_F(TrySwitchingUserTest, BothActiveAccepted) { | |
| 200 EXPECT_EQ(0, switch_callback_hit_count()); | |
| 201 StartShareSession(); | |
| 202 StartCaptureSession(); | |
| 203 SwitchUser(TrySwitchingUserTest::ACCEPT_DIALOG); | |
| 204 EXPECT_EQ(1, switch_callback_hit_count()); | |
| 205 EXPECT_EQ(1, stop_capture_callback_hit_count()); | |
| 206 EXPECT_EQ(1, stop_share_callback_hit_count()); | |
| 207 // Another stop should have no effect. | |
| 208 StopShareSession(); | |
| 209 StopCaptureSession(); | |
| 210 EXPECT_EQ(1, switch_callback_hit_count()); | |
| 211 EXPECT_EQ(1, stop_capture_callback_hit_count()); | |
| 212 EXPECT_EQ(1, stop_share_callback_hit_count()); | |
| 213 } | |
| 214 | |
| 215 } // namespace ash | |
| OLD | NEW |