Home | History | Annotate | Download | only in test
      1 // Copyright (c) 2013 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_TEST_TEST_SESSION_STATE_DELEGATE_H_
      6 #define ASH_TEST_TEST_SESSION_STATE_DELEGATE_H_
      7 
      8 #include <vector>
      9 
     10 #include "ash/session/session_state_delegate.h"
     11 #include "base/basictypes.h"
     12 #include "base/compiler_specific.h"
     13 #include "ui/gfx/image/image_skia.h"
     14 
     15 namespace ash {
     16 namespace test {
     17 
     18 class MockUserInfo;
     19 
     20 class TestSessionStateDelegate : public SessionStateDelegate {
     21  public:
     22   TestSessionStateDelegate();
     23   virtual ~TestSessionStateDelegate();
     24 
     25   void set_logged_in_users(int users) { logged_in_users_ = users; }
     26   void AddUser(const std::string user_id);
     27   const UserInfo* GetActiveUserInfo() const;
     28 
     29   // SessionStateDelegate:
     30   virtual content::BrowserContext* GetBrowserContextByIndex(
     31       MultiProfileIndex index) OVERRIDE;
     32   virtual content::BrowserContext* GetBrowserContextForWindow(
     33       aura::Window* window) OVERRIDE;
     34   virtual int GetMaximumNumberOfLoggedInUsers() const OVERRIDE;
     35   virtual int NumberOfLoggedInUsers() const OVERRIDE;
     36   virtual bool IsActiveUserSessionStarted() const OVERRIDE;
     37   virtual bool CanLockScreen() const OVERRIDE;
     38   virtual bool IsScreenLocked() const OVERRIDE;
     39   virtual bool ShouldLockScreenBeforeSuspending() const OVERRIDE;
     40   virtual void LockScreen() OVERRIDE;
     41   virtual void UnlockScreen() OVERRIDE;
     42   virtual bool IsUserSessionBlocked() const OVERRIDE;
     43   virtual SessionState GetSessionState() const OVERRIDE;
     44   virtual const UserInfo* GetUserInfo(
     45       ash::MultiProfileIndex index) const OVERRIDE;
     46   virtual const UserInfo* GetUserInfo(
     47       content::BrowserContext* context) const OVERRIDE;
     48   virtual bool ShouldShowAvatar(aura::Window* window) const OVERRIDE;
     49   virtual void SwitchActiveUser(const std::string& user_id) OVERRIDE;
     50   virtual void CycleActiveUser(CycleUser cycle_user) OVERRIDE;
     51   virtual void AddSessionStateObserver(
     52       ash::SessionStateObserver* observer) OVERRIDE;
     53   virtual void RemoveSessionStateObserver(
     54       ash::SessionStateObserver* observer) OVERRIDE;
     55 
     56   // TODO(oshima): Use state machine instead of using boolean variables.
     57 
     58   // Updates the internal state that indicates whether a session is in progress
     59   // and there is an active user. If |has_active_user| is |false|,
     60   // |active_user_session_started_| is reset to |false| as well (see below for
     61   // the difference between these two flags).
     62   void SetHasActiveUser(bool has_active_user);
     63 
     64   // Updates the internal state that indicates whether the session has been
     65   // fully started for the active user. If |active_user_session_started| is
     66   // |true|, |has_active_user_| is set to |true| as well (see below for the
     67   // difference between these two flags).
     68   void SetActiveUserSessionStarted(bool active_user_session_started);
     69 
     70   // Updates the internal state that indicates whether the screen can be locked.
     71   // Locking will only actually be allowed when this value is |true| and there
     72   // is an active user.
     73   void SetCanLockScreen(bool can_lock_screen);
     74 
     75   // Updates |should_lock_screen_before_suspending_|.
     76   void SetShouldLockScreenBeforeSuspending(bool should_lock);
     77 
     78   // Updates the internal state that indicates whether user adding screen is
     79   // running now.
     80   void SetUserAddingScreenRunning(bool user_adding_screen_running);
     81 
     82   // Setting non NULL image enables avatar icon.
     83   void SetUserImage(const gfx::ImageSkia& user_image);
     84 
     85  private:
     86   // Whether a session is in progress and there is an active user.
     87   bool has_active_user_;
     88 
     89   // When a user becomes active, the profile and browser UI are not immediately
     90   // available. Only once this flag becomes |true| is the browser startup
     91   // complete and both profile and UI are fully available.
     92   bool active_user_session_started_;
     93 
     94   // Whether the screen can be locked. Locking will only actually be allowed
     95   // when this is |true| and there is an active user.
     96   bool can_lock_screen_;
     97 
     98   // Return value for ShouldLockScreenBeforeSuspending().
     99   bool should_lock_screen_before_suspending_;
    100 
    101   // Whether the screen is currently locked.
    102   bool screen_locked_;
    103 
    104   // Whether user addding screen is running now.
    105   bool user_adding_screen_running_;
    106 
    107   // The number of users logged in.
    108   int logged_in_users_;
    109 
    110   // The index for the activated user.
    111   int active_user_index_;
    112 
    113   std::vector<MockUserInfo*> user_list_;
    114 
    115   DISALLOW_COPY_AND_ASSIGN(TestSessionStateDelegate);
    116 };
    117 
    118 }  // namespace test
    119 }  // namespace ash
    120 
    121 #endif  // ASH_TEST_TEST_SESSION_STATE_DELEGATE_H_
    122