OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 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 | 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/common/system/chromeos/screen_security/screen_tray_item.h" | 5 #include "ash/common/system/chromeos/screen_security/screen_tray_item.h" |
6 #include "ash/common/system/tray/system_tray.h" | 6 #include "ash/common/system/tray/system_tray.h" |
7 #include "ash/common/wm/overview/window_selector_controller.h" | 7 #include "ash/common/wm/overview/window_selector_controller.h" |
8 #include "ash/common/wm_shell.h" | 8 #include "ash/common/wm_shell.h" |
9 #include "ash/test/ash_test_base.h" | 9 #include "ash/test/ash_test_base.h" |
10 #include "base/run_loop.h" | |
11 #include "base/threading/thread_task_runner_handle.h" | |
12 #include "chrome/browser/ui/ash/multi_user/user_switch_util.h" | 10 #include "chrome/browser/ui/ash/multi_user/user_switch_util.h" |
13 #include "chrome/browser/ui/simple_message_box.h" | |
14 #include "ui/aura/window.h" | 11 #include "ui/aura/window.h" |
15 | 12 |
16 namespace ash { | 13 namespace ash { |
17 | 14 |
18 class TrySwitchingUserTest : public ash::test::AshTestBase { | 15 class TrySwitchingUserTest : public ash::test::AshTestBase { |
19 public: | 16 public: |
20 // The action type to perform / check for upon user switching. | 17 // The action type to perform / check for upon user switching. |
21 enum ActionType { | 18 enum ActionType { |
22 NO_DIALOG, // No dialog should be shown. | 19 NO_DIALOG, // No dialog should be shown. |
23 ACCEPT_DIALOG, // A dialog should be shown and we should accept it. | 20 ACCEPT_DIALOG, // A dialog should be shown and we should accept it. |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
64 // Simulates a screen share session stop. | 61 // Simulates a screen share session stop. |
65 void StopShareSession() { share_item_->Stop(); } | 62 void StopShareSession() { share_item_->Stop(); } |
66 | 63 |
67 // The callback which gets called when the screen share gets stopped. | 64 // The callback which gets called when the screen share gets stopped. |
68 void StopShareCallback() { stop_share_callback_hit_count_++; } | 65 void StopShareCallback() { stop_share_callback_hit_count_++; } |
69 | 66 |
70 // Issuing a switch user call which might or might not create a dialog. | 67 // Issuing a switch user call which might or might not create a dialog. |
71 // The passed |action| type parameter defines the outcome (which will be | 68 // The passed |action| type parameter defines the outcome (which will be |
72 // checked) and the action the user will choose. | 69 // checked) and the action the user will choose. |
73 void SwitchUser(ActionType action) { | 70 void SwitchUser(ActionType action) { |
74 base::ThreadTaskRunnerHandle::Get()->PostTask( | |
75 FROM_HERE, base::Bind(&CloseMessageBox, action)); | |
76 TrySwitchingActiveUser(base::Bind(&TrySwitchingUserTest::SwitchCallback, | 71 TrySwitchingActiveUser(base::Bind(&TrySwitchingUserTest::SwitchCallback, |
77 base::Unretained(this))); | 72 base::Unretained(this))); |
78 base::RunLoop().RunUntilIdle(); | 73 switch (action) { |
| 74 case NO_DIALOG: |
| 75 EXPECT_TRUE(!TestAndTerminateDesktopCastingWarningForTest(true)); |
| 76 return; |
| 77 case ACCEPT_DIALOG: |
| 78 EXPECT_TRUE(TestAndTerminateDesktopCastingWarningForTest(true)); |
| 79 return; |
| 80 case DECLINE_DIALOG: |
| 81 EXPECT_TRUE(TestAndTerminateDesktopCastingWarningForTest(false)); |
| 82 return; |
| 83 } |
79 } | 84 } |
80 | 85 |
81 // Called when the user will get actually switched. | 86 // Called when the user will get actually switched. |
82 void SwitchCallback() { switch_callback_hit_count_++; } | 87 void SwitchCallback() { switch_callback_hit_count_++; } |
83 | 88 |
84 // Methods needed to test with overview mode. | 89 // Methods needed to test with overview mode. |
85 const WindowSelectorController* window_selector_controller() const { | 90 const WindowSelectorController* window_selector_controller() const { |
86 return WmShell::Get()->window_selector_controller(); | 91 return WmShell::Get()->window_selector_controller(); |
87 } | 92 } |
88 WindowSelectorController* window_selector_controller() { | 93 WindowSelectorController* window_selector_controller() { |
89 return const_cast<WindowSelectorController*>( | 94 return const_cast<WindowSelectorController*>( |
90 const_cast<const TrySwitchingUserTest*>(this) | 95 const_cast<const TrySwitchingUserTest*>(this) |
91 ->window_selector_controller()); | 96 ->window_selector_controller()); |
92 } | 97 } |
93 void ToggleOverview() { window_selector_controller()->ToggleOverview(); } | 98 void ToggleOverview() { window_selector_controller()->ToggleOverview(); } |
94 bool IsSelecting() const { | 99 bool IsSelecting() const { |
95 return window_selector_controller()->IsSelecting(); | 100 return window_selector_controller()->IsSelecting(); |
96 } | 101 } |
97 | 102 |
98 // Various counter accessors. | 103 // Various counter accessors. |
99 int stop_capture_callback_hit_count() const { | 104 int stop_capture_callback_hit_count() const { |
100 return stop_capture_callback_hit_count_; | 105 return stop_capture_callback_hit_count_; |
101 } | 106 } |
102 int stop_share_callback_hit_count() const { | 107 int stop_share_callback_hit_count() const { |
103 return stop_share_callback_hit_count_; | 108 return stop_share_callback_hit_count_; |
104 } | 109 } |
105 int switch_callback_hit_count() const { return switch_callback_hit_count_; } | 110 int switch_callback_hit_count() const { return switch_callback_hit_count_; } |
106 | 111 |
107 private: | 112 private: |
108 static void CloseMessageBox(ActionType action) { | |
109 switch (action) { | |
110 case NO_DIALOG: | |
111 EXPECT_FALSE(chrome::CloseMessageBoxForTest(true)); | |
112 return; | |
113 case ACCEPT_DIALOG: | |
114 EXPECT_TRUE(chrome::CloseMessageBoxForTest(true)); | |
115 return; | |
116 case DECLINE_DIALOG: | |
117 EXPECT_TRUE(chrome::CloseMessageBoxForTest(false)); | |
118 return; | |
119 } | |
120 } | |
121 | |
122 // The two items from the SystemTray for the screen capture / share | 113 // The two items from the SystemTray for the screen capture / share |
123 // functionality. | 114 // functionality. |
124 ScreenTrayItem* capture_item_; | 115 ScreenTrayItem* capture_item_; |
125 ScreenTrayItem* share_item_; | 116 ScreenTrayItem* share_item_; |
126 | 117 |
127 // Various counters to query for. | 118 // Various counters to query for. |
128 int stop_capture_callback_hit_count_; | 119 int stop_capture_callback_hit_count_; |
129 int stop_share_callback_hit_count_; | 120 int stop_share_callback_hit_count_; |
130 int switch_callback_hit_count_; | 121 int switch_callback_hit_count_; |
131 | 122 |
(...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
243 gfx::Rect bounds(0, 0, 100, 100); | 234 gfx::Rect bounds(0, 0, 100, 100); |
244 std::unique_ptr<aura::Window> w(CreateTestWindowInShellWithBounds(bounds)); | 235 std::unique_ptr<aura::Window> w(CreateTestWindowInShellWithBounds(bounds)); |
245 ToggleOverview(); | 236 ToggleOverview(); |
246 ASSERT_TRUE(IsSelecting()); | 237 ASSERT_TRUE(IsSelecting()); |
247 SwitchUser(TrySwitchingUserTest::NO_DIALOG); | 238 SwitchUser(TrySwitchingUserTest::NO_DIALOG); |
248 ASSERT_FALSE(IsSelecting()); | 239 ASSERT_FALSE(IsSelecting()); |
249 EXPECT_EQ(1, switch_callback_hit_count()); | 240 EXPECT_EQ(1, switch_callback_hit_count()); |
250 } | 241 } |
251 | 242 |
252 } // namespace ash | 243 } // namespace ash |
OLD | NEW |