OLD | NEW |
(Empty) | |
| 1 // Copyright 2017 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #ifndef ASH_COMMON_TEST_TEST_SESSION_CONTROLLER_CLIENT_H_ |
| 6 #define ASH_COMMON_TEST_TEST_SESSION_CONTROLLER_CLIENT_H_ |
| 7 |
| 8 #include <stdint.h> |
| 9 |
| 10 #include <string> |
| 11 |
| 12 #include "ash/public/interfaces/session_controller.mojom.h" |
| 13 #include "base/macros.h" |
| 14 #include "mojo/public/cpp/bindings/binding.h" |
| 15 |
| 16 class AccountId; |
| 17 |
| 18 namespace ash { |
| 19 |
| 20 class SessionController; |
| 21 |
| 22 namespace test { |
| 23 |
| 24 // Implement SessionControllerClient mojo interface to simulate chrome behavior |
| 25 // in tests. This breaks the ash/chrome dependency to allow testing ash code in |
| 26 // isolation. Note that tests that have an instance of SessionControllerClient |
| 27 // should NOT use this, i.e. tests that run BrowserMain to have chrome's |
| 28 // SessionControllerClient created, e.g. InProcessBrowserTest based tests. On |
| 29 // the other hand, tests code in chrome can use this class as long as it does |
| 30 // not run BrowserMain, e.g. testing::Test based test. |
| 31 class TestSessionControllerClient : public ash::mojom::SessionControllerClient { |
| 32 public: |
| 33 explicit TestSessionControllerClient(SessionController* controller); |
| 34 ~TestSessionControllerClient() override; |
| 35 |
| 36 // Initialize using existing info in |controller| and bind as its client. |
| 37 void InitializeAndBind(); |
| 38 |
| 39 // Sets up the default state of SessionController. |
| 40 void Reset(); |
| 41 |
| 42 // Helpers to set SessionController state. |
| 43 void SetCanLockScreen(bool can_lock); |
| 44 void SetShouldLockScreenAutomatically(bool should_lock); |
| 45 void SetSessionState(session_manager::SessionState state); |
| 46 |
| 47 // Creates the |count| pre-defined user sessions. The users are named by |
| 48 // numbers using "user%d@tray" template. Note that existing user sessions |
| 49 // prior this call will be removed without sending out notifications. |
| 50 void CreatePredefinedUserSessions(int count); |
| 51 |
| 52 // Adds a user session from a given display email. The display email will be |
| 53 // canonicalized and used to construct an AccountId. |
| 54 void AddUserSession(const std::string& display_email); |
| 55 |
| 56 // Simulates screen unlocking. It is virtual so that test cases can override |
| 57 // it. The default implementation sets the session state of SessionController |
| 58 // to be ACTIVE. |
| 59 virtual void UnlockScreen(); |
| 60 |
| 61 // ash::mojom::SessionControllerClient: |
| 62 void RequestLockScreen() override; |
| 63 void SwitchActiveUser(const AccountId& account_id) override; |
| 64 void CycleActiveUser(CycleUserDirection direction) override; |
| 65 |
| 66 private: |
| 67 SessionController* const controller_; |
| 68 |
| 69 // Binds to the client interface. |
| 70 mojo::Binding<ash::mojom::SessionControllerClient> binding_; |
| 71 |
| 72 int fake_session_id_ = 0; |
| 73 mojom::SessionInfoPtr session_info_; |
| 74 |
| 75 DISALLOW_COPY_AND_ASSIGN(TestSessionControllerClient); |
| 76 }; |
| 77 |
| 78 } // namespace test |
| 79 } // namespace ash |
| 80 |
| 81 #endif // ASH_COMMON_TEST_TEST_SESSION_CONTROLLER_CLIENT_H_ |
OLD | NEW |