Chromium Code Reviews| Index: ash/common/test/test_session_controller_client.h |
| diff --git a/ash/common/test/test_session_controller_client.h b/ash/common/test/test_session_controller_client.h |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..c4d0aefc5c5e597efd83d0febce9fb8b8c03f0df |
| --- /dev/null |
| +++ b/ash/common/test/test_session_controller_client.h |
| @@ -0,0 +1,79 @@ |
| +// Copyright 2017 The Chromium Authors. All rights reserved. |
| +// Use of this source code is governed by a BSD-style license that can be |
| +// found in the LICENSE file. |
| + |
| +#ifndef ASH_COMMON_TEST_TEST_SESSION_CONTROLLER_CLIENT_H_ |
| +#define ASH_COMMON_TEST_TEST_SESSION_CONTROLLER_CLIENT_H_ |
| + |
| +#include <stdint.h> |
| + |
| +#include <string> |
| + |
| +#include "ash/public/interfaces/session_controller.mojom.h" |
| +#include "base/macros.h" |
| +#include "mojo/public/cpp/bindings/binding.h" |
| + |
| +class AccountId; |
| + |
| +namespace ash { |
| + |
| +class SessionController; |
| + |
| +namespace test { |
| + |
| +// Helper class to mock user sessions in unit tests. |
| +// Note that tests that have an instance of SessionControllerClient should |
| +// NOT use this. |
|
James Cook
2017/03/17 17:14:36
nit: Maybe add to comment an example of that kind
xiyuan
2017/03/17 22:52:02
Done.
|
| +class TestSessionControllerClient : public ash::mojom::SessionControllerClient { |
| + public: |
| + explicit TestSessionControllerClient(SessionController* controller); |
| + ~TestSessionControllerClient() override; |
| + |
| + // Initialize using existing info in |controller| and bind as its client. |
| + void InitializeAndBind(); |
| + |
| + // Sets up the default state of SessionController. |
| + void Reset(); |
| + |
| + // Helpers to set SessionController state. |
| + void SetCanLockScreen(bool can_lock); |
| + void SetShouldLockScreenAutomatically(bool should_lock); |
| + void SetSessionState(session_manager::SessionState state); |
| + |
| + // Sets the |count| pre-defined user sessions. The first four user session |
|
James Cook
2017/03/17 17:14:36
super nit: "Creates |count| pre-defined user sessi
xiyuan
2017/03/17 22:52:02
Done.
|
| + // have special names that are used in a few tests. After that, the users |
| + // are named by numbers using "user%d@tray" template. |
| + // Note that existing user sessions prior this call will be removed without |
| + // sending out notifications. |
| + void SetPredefinedUserSessions(int count); |
|
James Cook
2017/03/17 17:14:36
optional: Maybe CreatePredefinedUserSessions()?
xiyuan
2017/03/17 22:52:02
Done.
|
| + |
| + // Adds a user session from a given display email. The display email will be |
| + // canonicalized and used to construct an AccountId. |
| + void AddUserSession(const std::string& display_email); |
| + |
| + // Simulates screen unlocking. It is virtual so that test cases can override |
| + // it. The default implementation sets the session state of SessionController |
| + // to be ACTIVE. |
| + virtual void UnlockScreen(); |
| + |
| + // ash::mojom::SessionControllerClient: |
| + void RequestLockScreen() override; |
| + void SwitchActiveUser(const AccountId& account_id) override; |
| + void CycleActiveUser(CycleUserDirection direction) override; |
| + |
| + private: |
| + SessionController* const controller_; |
| + |
| + // Binds to the client interface. |
| + mojo::Binding<ash::mojom::SessionControllerClient> binding_; |
| + |
| + int fake_session_id_ = 0; |
| + mojom::SessionInfoPtr session_info_; |
| + |
| + DISALLOW_COPY_AND_ASSIGN(TestSessionControllerClient); |
| +}; |
| + |
| +} // namespace test |
| +} // namespace ash |
| + |
| +#endif // ASH_COMMON_TEST_TEST_SESSION_CONTROLLER_CLIENT_H_ |