Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(182)

Side by Side Diff: chrome/browser/ui/ash/multi_user/user_switch_util_unittest.cc

Issue 2441403003: Use a standard message box for DesktopCastingWarningView. (Closed)
Patch Set: msw review Created 4 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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"
10 #include "chrome/browser/ui/ash/multi_user/user_switch_util.h" 12 #include "chrome/browser/ui/ash/multi_user/user_switch_util.h"
13 #include "chrome/browser/ui/simple_message_box.h"
11 #include "ui/aura/window.h" 14 #include "ui/aura/window.h"
12 15
13 namespace ash { 16 namespace ash {
14 17
15 class TrySwitchingUserTest : public ash::test::AshTestBase { 18 class TrySwitchingUserTest : public ash::test::AshTestBase {
16 public: 19 public:
17 // The action type to perform / check for upon user switching. 20 // The action type to perform / check for upon user switching.
18 enum ActionType { 21 enum ActionType {
19 NO_DIALOG, // No dialog should be shown. 22 NO_DIALOG, // No dialog should be shown.
20 ACCEPT_DIALOG, // A dialog should be shown and we should accept it. 23 ACCEPT_DIALOG, // A dialog should be shown and we should accept it.
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
61 // Simulates a screen share session stop. 64 // Simulates a screen share session stop.
62 void StopShareSession() { share_item_->Stop(); } 65 void StopShareSession() { share_item_->Stop(); }
63 66
64 // The callback which gets called when the screen share gets stopped. 67 // The callback which gets called when the screen share gets stopped.
65 void StopShareCallback() { stop_share_callback_hit_count_++; } 68 void StopShareCallback() { stop_share_callback_hit_count_++; }
66 69
67 // Issuing a switch user call which might or might not create a dialog. 70 // Issuing a switch user call which might or might not create a dialog.
68 // The passed |action| type parameter defines the outcome (which will be 71 // The passed |action| type parameter defines the outcome (which will be
69 // checked) and the action the user will choose. 72 // checked) and the action the user will choose.
70 void SwitchUser(ActionType action) { 73 void SwitchUser(ActionType action) {
74 base::ThreadTaskRunnerHandle::Get()->PostTask(
75 FROM_HERE, base::Bind(&CloseMessageBox, action));
71 TrySwitchingActiveUser(base::Bind(&TrySwitchingUserTest::SwitchCallback, 76 TrySwitchingActiveUser(base::Bind(&TrySwitchingUserTest::SwitchCallback,
72 base::Unretained(this))); 77 base::Unretained(this)));
73 switch (action) { 78 base::RunLoop().RunUntilIdle();
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 }
84 } 79 }
85 80
86 // Called when the user will get actually switched. 81 // Called when the user will get actually switched.
87 void SwitchCallback() { switch_callback_hit_count_++; } 82 void SwitchCallback() { switch_callback_hit_count_++; }
88 83
89 // Methods needed to test with overview mode. 84 // Methods needed to test with overview mode.
90 const WindowSelectorController* window_selector_controller() const { 85 const WindowSelectorController* window_selector_controller() const {
91 return WmShell::Get()->window_selector_controller(); 86 return WmShell::Get()->window_selector_controller();
92 } 87 }
93 WindowSelectorController* window_selector_controller() { 88 WindowSelectorController* window_selector_controller() {
94 return const_cast<WindowSelectorController*>( 89 return const_cast<WindowSelectorController*>(
95 const_cast<const TrySwitchingUserTest*>(this) 90 const_cast<const TrySwitchingUserTest*>(this)
96 ->window_selector_controller()); 91 ->window_selector_controller());
97 } 92 }
98 void ToggleOverview() { window_selector_controller()->ToggleOverview(); } 93 void ToggleOverview() { window_selector_controller()->ToggleOverview(); }
99 bool IsSelecting() const { 94 bool IsSelecting() const {
100 return window_selector_controller()->IsSelecting(); 95 return window_selector_controller()->IsSelecting();
101 } 96 }
102 97
103 // Various counter accessors. 98 // Various counter accessors.
104 int stop_capture_callback_hit_count() const { 99 int stop_capture_callback_hit_count() const {
105 return stop_capture_callback_hit_count_; 100 return stop_capture_callback_hit_count_;
106 } 101 }
107 int stop_share_callback_hit_count() const { 102 int stop_share_callback_hit_count() const {
108 return stop_share_callback_hit_count_; 103 return stop_share_callback_hit_count_;
109 } 104 }
110 int switch_callback_hit_count() const { return switch_callback_hit_count_; } 105 int switch_callback_hit_count() const { return switch_callback_hit_count_; }
111 106
112 private: 107 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
113 // The two items from the SystemTray for the screen capture / share 122 // The two items from the SystemTray for the screen capture / share
114 // functionality. 123 // functionality.
115 ScreenTrayItem* capture_item_; 124 ScreenTrayItem* capture_item_;
116 ScreenTrayItem* share_item_; 125 ScreenTrayItem* share_item_;
117 126
118 // Various counters to query for. 127 // Various counters to query for.
119 int stop_capture_callback_hit_count_; 128 int stop_capture_callback_hit_count_;
120 int stop_share_callback_hit_count_; 129 int stop_share_callback_hit_count_;
121 int switch_callback_hit_count_; 130 int switch_callback_hit_count_;
122 131
(...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after
234 gfx::Rect bounds(0, 0, 100, 100); 243 gfx::Rect bounds(0, 0, 100, 100);
235 std::unique_ptr<aura::Window> w(CreateTestWindowInShellWithBounds(bounds)); 244 std::unique_ptr<aura::Window> w(CreateTestWindowInShellWithBounds(bounds));
236 ToggleOverview(); 245 ToggleOverview();
237 ASSERT_TRUE(IsSelecting()); 246 ASSERT_TRUE(IsSelecting());
238 SwitchUser(TrySwitchingUserTest::NO_DIALOG); 247 SwitchUser(TrySwitchingUserTest::NO_DIALOG);
239 ASSERT_FALSE(IsSelecting()); 248 ASSERT_FALSE(IsSelecting());
240 EXPECT_EQ(1, switch_callback_hit_count()); 249 EXPECT_EQ(1, switch_callback_hit_count());
241 } 250 }
242 251
243 } // namespace ash 252 } // namespace ash
OLDNEW
« no previous file with comments | « chrome/browser/ui/ash/multi_user/user_switch_util.cc ('k') | chrome/browser/ui/cocoa/simple_message_box_mac.mm » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698