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

Side by Side Diff: ash/wm/lock_state_controller_unittest.cc

Issue 2497123002: chromeos: Move device shutdown handling out of chrome into ash (Closed)
Patch Set: rebase 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
« no previous file with comments | « ash/wm/lock_state_controller.cc ('k') | ash/wm/shutdown_client_proxy.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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/wm/lock_state_controller.h" 5 #include "ash/wm/lock_state_controller.h"
6 6
7 #include <memory> 7 #include <memory>
8 #include <utility> 8 #include <utility>
9 9
10 #include "ash/common/session/session_state_delegate.h" 10 #include "ash/common/session/session_state_delegate.h"
11 #include "ash/common/shutdown_controller.h"
11 #include "ash/common/test/test_session_state_delegate.h" 12 #include "ash/common/test/test_session_state_delegate.h"
12 #include "ash/common/wm/maximize_mode/maximize_mode_controller.h" 13 #include "ash/common/wm/maximize_mode/maximize_mode_controller.h"
13 #include "ash/common/wm_shell.h" 14 #include "ash/common/wm_shell.h"
14 #include "ash/shell.h" 15 #include "ash/shell.h"
15 #include "ash/test/ash_test_base.h" 16 #include "ash/test/ash_test_base.h"
16 #include "ash/test/lock_state_controller_test_api.h" 17 #include "ash/test/lock_state_controller_test_api.h"
17 #include "ash/test/test_screenshot_delegate.h" 18 #include "ash/test/test_screenshot_delegate.h"
18 #include "ash/test/test_session_state_animator.h" 19 #include "ash/test/test_session_state_animator.h"
19 #include "ash/test/test_shell_delegate.h" 20 #include "ash/test/test_shell_delegate.h"
20 #include "ash/test/test_shutdown_client.h"
21 #include "ash/wm/power_button_controller.h" 21 #include "ash/wm/power_button_controller.h"
22 #include "ash/wm/session_state_animator.h" 22 #include "ash/wm/session_state_animator.h"
23 #include "base/memory/scoped_vector.h" 23 #include "base/memory/scoped_vector.h"
24 #include "base/time/time.h" 24 #include "base/time/time.h"
25 #include "chromeos/dbus/dbus_thread_manager.h" 25 #include "chromeos/dbus/dbus_thread_manager.h"
26 #include "chromeos/dbus/fake_session_manager_client.h" 26 #include "chromeos/dbus/fake_session_manager_client.h"
27 #include "ui/display/chromeos/display_configurator.h" 27 #include "ui/display/chromeos/display_configurator.h"
28 #include "ui/display/fake_display_snapshot.h" 28 #include "ui/display/fake_display_snapshot.h"
29 #include "ui/display/types/display_constants.h" 29 #include "ui/display/types/display_constants.h"
30 #include "ui/events/test/event_generator.h" 30 #include "ui/events/test/event_generator.h"
31 #include "ui/gfx/geometry/size.h" 31 #include "ui/gfx/geometry/size.h"
32 32
33 namespace ash { 33 namespace ash {
34 namespace test { 34 namespace test {
35 namespace { 35 namespace {
36 36
37 bool cursor_visible() { 37 bool cursor_visible() {
38 return Shell::GetInstance()->cursor_manager()->IsCursorVisible(); 38 return Shell::GetInstance()->cursor_manager()->IsCursorVisible();
39 } 39 }
40 40
41 void CheckCalledCallback(bool* flag) { 41 void CheckCalledCallback(bool* flag) {
42 if (flag) 42 if (flag)
43 (*flag) = true; 43 (*flag) = true;
44 } 44 }
45 45
46 // ShutdownController that tracks how many shutdown requests have been made.
47 class TestShutdownController : public ShutdownController {
48 public:
49 TestShutdownController() {}
50 ~TestShutdownController() override {}
51
52 int num_shutdown_requests() const { return num_shutdown_requests_; }
53
54 private:
55 // ShutdownController:
56 void ShutDownOrReboot() override { num_shutdown_requests_++; }
57
58 int num_shutdown_requests_ = 0;
59
60 DISALLOW_COPY_AND_ASSIGN(TestShutdownController);
61 };
62
46 } // namespace 63 } // namespace
47 64
48 class LockStateControllerTest : public AshTestBase { 65 class LockStateControllerTest : public AshTestBase {
49 public: 66 public:
50 LockStateControllerTest() 67 LockStateControllerTest()
51 : power_button_controller_(nullptr), 68 : power_button_controller_(nullptr),
52 lock_state_controller_(nullptr), 69 lock_state_controller_(nullptr),
53 shutdown_client_(nullptr),
54 session_manager_client_(nullptr), 70 session_manager_client_(nullptr),
55 test_animator_(nullptr) {} 71 test_animator_(nullptr) {}
56 ~LockStateControllerTest() override {} 72 ~LockStateControllerTest() override {}
57 73
58 void SetUp() override { 74 void SetUp() override {
59 session_manager_client_ = new chromeos::FakeSessionManagerClient; 75 session_manager_client_ = new chromeos::FakeSessionManagerClient;
60 chromeos::DBusThreadManager::GetSetterForTesting()->SetSessionManagerClient( 76 chromeos::DBusThreadManager::GetSetterForTesting()->SetSessionManagerClient(
61 base::WrapUnique(session_manager_client_)); 77 base::WrapUnique(session_manager_client_));
62 AshTestBase::SetUp(); 78 AshTestBase::SetUp();
63 79
64 shutdown_client_ = new TestShutdownClient;
65 std::unique_ptr<TestShutdownClient> shutdown_client(shutdown_client_);
66
67 test_animator_ = new TestSessionStateAnimator; 80 test_animator_ = new TestSessionStateAnimator;
68 81
69 lock_state_controller_ = Shell::GetInstance()->lock_state_controller(); 82 lock_state_controller_ = Shell::GetInstance()->lock_state_controller();
70 lock_state_controller_->set_animator_for_test(test_animator_); 83 lock_state_controller_->set_animator_for_test(test_animator_);
71 84
72 test_api_.reset(new LockStateControllerTestApi(lock_state_controller_)); 85 test_api_.reset(new LockStateControllerTestApi(lock_state_controller_));
73 test_api_->SetShutdownClient(std::move(shutdown_client)); 86 test_api_->set_shutdown_controller(&test_shutdown_controller_);
74 87
75 power_button_controller_ = Shell::GetInstance()->power_button_controller(); 88 power_button_controller_ = Shell::GetInstance()->power_button_controller();
76 89
77 shell_delegate_ = 90 shell_delegate_ =
78 static_cast<TestShellDelegate*>(WmShell::Get()->delegate()); 91 static_cast<TestShellDelegate*>(WmShell::Get()->delegate());
79 } 92 }
80 93
81 void TearDown() override { 94 void TearDown() override {
82 AshTestBase::TearDown(); 95 AshTestBase::TearDown();
83 chromeos::DBusThreadManager::Shutdown(); 96 chromeos::DBusThreadManager::Shutdown();
84 } 97 }
85 98
86 protected: 99 protected:
87 void GenerateMouseMoveEvent() { 100 void GenerateMouseMoveEvent() {
88 ui::test::EventGenerator generator(Shell::GetPrimaryRootWindow()); 101 ui::test::EventGenerator generator(Shell::GetPrimaryRootWindow());
89 generator.MoveMouseTo(10, 10); 102 generator.MoveMouseTo(10, 10);
90 } 103 }
91 104
92 int NumShutdownRequests() { 105 int NumShutdownRequests() {
93 return shutdown_client_->num_shutdown_requests() + 106 return test_shutdown_controller_.num_shutdown_requests() +
94 shell_delegate_->num_exit_requests(); 107 shell_delegate_->num_exit_requests();
95 } 108 }
96 109
97 void Advance(SessionStateAnimator::AnimationSpeed speed) { 110 void Advance(SessionStateAnimator::AnimationSpeed speed) {
98 test_animator_->Advance(test_animator_->GetDuration(speed)); 111 test_animator_->Advance(test_animator_->GetDuration(speed));
99 } 112 }
100 113
101 void AdvancePartially(SessionStateAnimator::AnimationSpeed speed, 114 void AdvancePartially(SessionStateAnimator::AnimationSpeed speed,
102 float factor) { 115 float factor) {
103 base::TimeDelta duration = test_animator_->GetDuration(speed); 116 base::TimeDelta duration = test_animator_->GetDuration(speed);
(...skipping 216 matching lines...) Expand 10 before | Expand all | Expand 10 after
320 legacy_button); 333 legacy_button);
321 lock_state_controller_->OnLoginStateChanged(status); 334 lock_state_controller_->OnLoginStateChanged(status);
322 SetUserLoggedIn(status != LoginStatus::NOT_LOGGED_IN); 335 SetUserLoggedIn(status != LoginStatus::NOT_LOGGED_IN);
323 if (status == LoginStatus::GUEST) 336 if (status == LoginStatus::GUEST)
324 TestSessionStateDelegate::SetCanLockScreen(false); 337 TestSessionStateDelegate::SetCanLockScreen(false);
325 lock_state_controller_->OnLockStateChanged(false); 338 lock_state_controller_->OnLockStateChanged(false);
326 } 339 }
327 340
328 PowerButtonController* power_button_controller_; // not owned 341 PowerButtonController* power_button_controller_; // not owned
329 LockStateController* lock_state_controller_; // not owned 342 LockStateController* lock_state_controller_; // not owned
330 TestShutdownClient* shutdown_client_; // not owned 343 TestShutdownController test_shutdown_controller_;
331 // Ownership is passed on to chromeos::DBusThreadManager. 344 // Ownership is passed on to chromeos::DBusThreadManager.
332 chromeos::FakeSessionManagerClient* session_manager_client_; 345 chromeos::FakeSessionManagerClient* session_manager_client_;
333 TestSessionStateAnimator* test_animator_; // not owned 346 TestSessionStateAnimator* test_animator_; // not owned
334 std::unique_ptr<LockStateControllerTestApi> test_api_; 347 std::unique_ptr<LockStateControllerTestApi> test_api_;
335 TestShellDelegate* shell_delegate_; // not owned 348 TestShellDelegate* shell_delegate_; // not owned
336 349
337 private: 350 private:
338 DISALLOW_COPY_AND_ASSIGN(LockStateControllerTest); 351 DISALLOW_COPY_AND_ASSIGN(LockStateControllerTest);
339 }; 352 };
340 353
(...skipping 747 matching lines...) Expand 10 before | Expand all | Expand 10 after
1088 ReleasePowerButton(); 1101 ReleasePowerButton();
1089 1102
1090 ExpectPreLockAnimationStarted(); 1103 ExpectPreLockAnimationStarted();
1091 1104
1092 test_animator_->CompleteAllAnimations(true); 1105 test_animator_->CompleteAllAnimations(true);
1093 EXPECT_EQ(1, session_manager_client_->request_lock_screen_call_count()); 1106 EXPECT_EQ(1, session_manager_client_->request_lock_screen_call_count());
1094 } 1107 }
1095 1108
1096 } // namespace test 1109 } // namespace test
1097 } // namespace ash 1110 } // namespace ash
OLDNEW
« no previous file with comments | « ash/wm/lock_state_controller.cc ('k') | ash/wm/shutdown_client_proxy.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698