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

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

Issue 2471643002: mash: remove the LockStateControllerDelegate. (Closed)
Patch Set: sky comments 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/test/test_session_state_delegate.h" 11 #include "ash/common/test/test_session_state_delegate.h"
12 #include "ash/common/wm/maximize_mode/maximize_mode_controller.h" 12 #include "ash/common/wm/maximize_mode/maximize_mode_controller.h"
13 #include "ash/common/wm_shell.h" 13 #include "ash/common/wm_shell.h"
14 #include "ash/shell.h" 14 #include "ash/shell.h"
15 #include "ash/test/ash_test_base.h" 15 #include "ash/test/ash_test_base.h"
16 #include "ash/test/test_lock_state_controller_delegate.h" 16 #include "ash/test/lock_state_controller_test_api.h"
17 #include "ash/test/test_screenshot_delegate.h" 17 #include "ash/test/test_screenshot_delegate.h"
18 #include "ash/test/test_session_state_animator.h" 18 #include "ash/test/test_session_state_animator.h"
19 #include "ash/test/test_shell_delegate.h" 19 #include "ash/test/test_shell_delegate.h"
20 #include "ash/test/test_shutdown_client.h"
20 #include "ash/wm/power_button_controller.h" 21 #include "ash/wm/power_button_controller.h"
21 #include "ash/wm/session_state_animator.h" 22 #include "ash/wm/session_state_animator.h"
22 #include "base/memory/scoped_vector.h" 23 #include "base/memory/scoped_vector.h"
23 #include "base/time/time.h" 24 #include "base/time/time.h"
24 #include "chromeos/dbus/dbus_thread_manager.h" 25 #include "chromeos/dbus/dbus_thread_manager.h"
25 #include "chromeos/dbus/fake_session_manager_client.h" 26 #include "chromeos/dbus/fake_session_manager_client.h"
26 #include "ui/display/chromeos/display_configurator.h" 27 #include "ui/display/chromeos/display_configurator.h"
27 #include "ui/display/fake_display_snapshot.h" 28 #include "ui/display/fake_display_snapshot.h"
28 #include "ui/display/types/display_constants.h" 29 #include "ui/display/types/display_constants.h"
29 #include "ui/events/test/event_generator.h" 30 #include "ui/events/test/event_generator.h"
(...skipping 12 matching lines...) Expand all
42 (*flag) = true; 43 (*flag) = true;
43 } 44 }
44 45
45 } // namespace 46 } // namespace
46 47
47 class LockStateControllerTest : public AshTestBase { 48 class LockStateControllerTest : public AshTestBase {
48 public: 49 public:
49 LockStateControllerTest() 50 LockStateControllerTest()
50 : power_button_controller_(nullptr), 51 : power_button_controller_(nullptr),
51 lock_state_controller_(nullptr), 52 lock_state_controller_(nullptr),
52 lock_state_controller_delegate_(nullptr), 53 shutdown_client_(nullptr),
53 session_manager_client_(nullptr), 54 session_manager_client_(nullptr),
54 test_animator_(nullptr) {} 55 test_animator_(nullptr) {}
55 ~LockStateControllerTest() override {} 56 ~LockStateControllerTest() override {}
56 57
57 void SetUp() override { 58 void SetUp() override {
58 session_manager_client_ = new chromeos::FakeSessionManagerClient; 59 session_manager_client_ = new chromeos::FakeSessionManagerClient;
59 chromeos::DBusThreadManager::GetSetterForTesting()->SetSessionManagerClient( 60 chromeos::DBusThreadManager::GetSetterForTesting()->SetSessionManagerClient(
60 base::WrapUnique(session_manager_client_)); 61 base::WrapUnique(session_manager_client_));
61 AshTestBase::SetUp(); 62 AshTestBase::SetUp();
62 63
63 std::unique_ptr<LockStateControllerDelegate> lock_state_controller_delegate( 64 shutdown_client_ = new TestShutdownClient;
64 lock_state_controller_delegate_ = new TestLockStateControllerDelegate); 65 std::unique_ptr<TestShutdownClient> shutdown_client(shutdown_client_);
66
65 test_animator_ = new TestSessionStateAnimator; 67 test_animator_ = new TestSessionStateAnimator;
66 68
67 lock_state_controller_ = Shell::GetInstance()->lock_state_controller(); 69 lock_state_controller_ = Shell::GetInstance()->lock_state_controller();
68 lock_state_controller_->SetDelegate(
69 std::move(lock_state_controller_delegate));
70 lock_state_controller_->set_animator_for_test(test_animator_); 70 lock_state_controller_->set_animator_for_test(test_animator_);
71 71
72 test_api_.reset(new LockStateController::TestApi(lock_state_controller_)); 72 test_api_.reset(new LockStateControllerTestApi(lock_state_controller_));
73 test_api_->SetShutdownClient(std::move(shutdown_client));
73 74
74 power_button_controller_ = Shell::GetInstance()->power_button_controller(); 75 power_button_controller_ = Shell::GetInstance()->power_button_controller();
75 76
76 shell_delegate_ = 77 shell_delegate_ =
77 static_cast<TestShellDelegate*>(WmShell::Get()->delegate()); 78 static_cast<TestShellDelegate*>(WmShell::Get()->delegate());
78 } 79 }
79 80
80 void TearDown() override { 81 void TearDown() override {
81 AshTestBase::TearDown(); 82 AshTestBase::TearDown();
82 chromeos::DBusThreadManager::Shutdown(); 83 chromeos::DBusThreadManager::Shutdown();
83 } 84 }
84 85
85 protected: 86 protected:
86 void GenerateMouseMoveEvent() { 87 void GenerateMouseMoveEvent() {
87 ui::test::EventGenerator generator(Shell::GetPrimaryRootWindow()); 88 ui::test::EventGenerator generator(Shell::GetPrimaryRootWindow());
88 generator.MoveMouseTo(10, 10); 89 generator.MoveMouseTo(10, 10);
89 } 90 }
90 91
91 int NumShutdownRequests() { 92 int NumShutdownRequests() {
92 return lock_state_controller_delegate_->num_shutdown_requests() + 93 return shutdown_client_->num_shutdown_requests() +
93 shell_delegate_->num_exit_requests(); 94 shell_delegate_->num_exit_requests();
94 } 95 }
95 96
96 void Advance(SessionStateAnimator::AnimationSpeed speed) { 97 void Advance(SessionStateAnimator::AnimationSpeed speed) {
97 test_animator_->Advance(test_animator_->GetDuration(speed)); 98 test_animator_->Advance(test_animator_->GetDuration(speed));
98 } 99 }
99 100
100 void AdvancePartially(SessionStateAnimator::AnimationSpeed speed, 101 void AdvancePartially(SessionStateAnimator::AnimationSpeed speed,
101 float factor) { 102 float factor) {
102 base::TimeDelta duration = test_animator_->GetDuration(speed); 103 base::TimeDelta duration = test_animator_->GetDuration(speed);
(...skipping 216 matching lines...) Expand 10 before | Expand all | Expand 10 after
319 legacy_button); 320 legacy_button);
320 lock_state_controller_->OnLoginStateChanged(status); 321 lock_state_controller_->OnLoginStateChanged(status);
321 SetUserLoggedIn(status != LoginStatus::NOT_LOGGED_IN); 322 SetUserLoggedIn(status != LoginStatus::NOT_LOGGED_IN);
322 if (status == LoginStatus::GUEST) 323 if (status == LoginStatus::GUEST)
323 TestSessionStateDelegate::SetCanLockScreen(false); 324 TestSessionStateDelegate::SetCanLockScreen(false);
324 lock_state_controller_->OnLockStateChanged(false); 325 lock_state_controller_->OnLockStateChanged(false);
325 } 326 }
326 327
327 PowerButtonController* power_button_controller_; // not owned 328 PowerButtonController* power_button_controller_; // not owned
328 LockStateController* lock_state_controller_; // not owned 329 LockStateController* lock_state_controller_; // not owned
329 TestLockStateControllerDelegate* 330 TestShutdownClient* shutdown_client_; // not owned
330 lock_state_controller_delegate_; // not owned
331 // Ownership is passed on to chromeos::DBusThreadManager. 331 // Ownership is passed on to chromeos::DBusThreadManager.
332 chromeos::FakeSessionManagerClient* session_manager_client_; 332 chromeos::FakeSessionManagerClient* session_manager_client_;
333 TestSessionStateAnimator* test_animator_; // not owned 333 TestSessionStateAnimator* test_animator_; // not owned
334 std::unique_ptr<LockStateController::TestApi> test_api_; 334 std::unique_ptr<LockStateControllerTestApi> test_api_;
335 TestShellDelegate* shell_delegate_; // not owned 335 TestShellDelegate* shell_delegate_; // not owned
336 336
337 private: 337 private:
338 DISALLOW_COPY_AND_ASSIGN(LockStateControllerTest); 338 DISALLOW_COPY_AND_ASSIGN(LockStateControllerTest);
339 }; 339 };
340 340
341 // Test the lock-to-shutdown flow for non-Chrome-OS hardware that doesn't 341 // Test the lock-to-shutdown flow for non-Chrome-OS hardware that doesn't
342 // correctly report power button releases. We should lock immediately the first 342 // correctly report power button releases. We should lock immediately the first
343 // time the button is pressed and shut down when it's pressed from the locked 343 // time the button is pressed and shut down when it's pressed from the locked
344 // state. 344 // state.
(...skipping 743 matching lines...) Expand 10 before | Expand all | Expand 10 after
1088 ReleasePowerButton(); 1088 ReleasePowerButton();
1089 1089
1090 ExpectPreLockAnimationStarted(); 1090 ExpectPreLockAnimationStarted();
1091 1091
1092 test_animator_->CompleteAllAnimations(true); 1092 test_animator_->CompleteAllAnimations(true);
1093 EXPECT_EQ(1, session_manager_client_->request_lock_screen_call_count()); 1093 EXPECT_EQ(1, session_manager_client_->request_lock_screen_call_count());
1094 } 1094 }
1095 1095
1096 } // namespace test 1096 } // namespace test
1097 } // namespace ash 1097 } // 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