1
    2
    3
    4
    5
    6
    7
    8
    9
   10
   11
   12
   13
   14
   15
   16
   17
   18
   19
   20
   21
   22
   23
   24
   25
   26
   27
   28
   29
   30
   31
   32
   33
   34
   35
   36
   37
   38
   39
   40
   41
   42
   43
   44
   45
   46
   47
   48
   49
   50
   51
   52
   53
   54
   55
   56
   57
   58
   59
   60
   61
   62
   63
   64
   65
   66
   67
   68
   69
   70
   71
   72
   73
   74
   75
   76
   77
   78
   79
   80
   81

ash / shelf / shelf_locking_manager_unittest.cc [blame]

// Copyright 2016 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#include "ash/shelf/shelf_locking_manager.h"

#include "ash/shelf/shelf.h"
#include "ash/test/ash_test_base.h"

namespace ash {
namespace {

// Tests the shelf behavior when the screen or session is locked.
class ShelfLockingManagerTest : public AshTestBase {
 public:
  ShelfLockingManagerTest() = default;

  ShelfLockingManagerTest(const ShelfLockingManagerTest&) = delete;
  ShelfLockingManagerTest& operator=(const ShelfLockingManagerTest&) = delete;

  ShelfLockingManager* GetShelfLockingManager() {
    return GetPrimaryShelf()->GetShelfLockingManagerForTesting();
  }

  void SetScreenLocked(bool locked) {
    GetShelfLockingManager()->OnLockStateChanged(locked);
  }

  void SetSessionState(session_manager::SessionState state) {
    GetShelfLockingManager()->OnSessionStateChanged(state);
  }
};

// Makes sure shelf alignment is correct for lock screen.
TEST_F(ShelfLockingManagerTest, AlignmentLockedWhileScreenLocked) {
  Shelf* shelf = GetPrimaryShelf();
  EXPECT_EQ(ShelfAlignment::kBottom, shelf->alignment());

  shelf->SetAlignment(ShelfAlignment::kLeft);
  EXPECT_EQ(ShelfAlignment::kLeft, shelf->alignment());

  SetScreenLocked(true);
  EXPECT_EQ(ShelfAlignment::kBottomLocked, shelf->alignment());
  SetScreenLocked(false);
  EXPECT_EQ(ShelfAlignment::kLeft, shelf->alignment());
}

// Makes sure shelf alignment is correct for login and add user screens.
TEST_F(ShelfLockingManagerTest, AlignmentLockedWhileSessionLocked) {
  Shelf* shelf = GetPrimaryShelf();
  EXPECT_EQ(ShelfAlignment::kBottom, shelf->alignment());

  shelf->SetAlignment(ShelfAlignment::kRight);
  EXPECT_EQ(ShelfAlignment::kRight, shelf->alignment());

  SetSessionState(session_manager::SessionState::LOGIN_PRIMARY);
  EXPECT_EQ(ShelfAlignment::kBottomLocked, shelf->alignment());
  SetSessionState(session_manager::SessionState::ACTIVE);
  EXPECT_EQ(ShelfAlignment::kRight, shelf->alignment());

  SetSessionState(session_manager::SessionState::LOGIN_SECONDARY);
  EXPECT_EQ(ShelfAlignment::kBottomLocked, shelf->alignment());
  SetSessionState(session_manager::SessionState::ACTIVE);
  EXPECT_EQ(ShelfAlignment::kRight, shelf->alignment());
}

// Makes sure shelf alignment changes are stored, not set, while locked.
TEST_F(ShelfLockingManagerTest, AlignmentChangesDeferredWhileLocked) {
  Shelf* shelf = GetPrimaryShelf();
  EXPECT_EQ(ShelfAlignment::kBottom, shelf->alignment());

  SetScreenLocked(true);
  EXPECT_EQ(ShelfAlignment::kBottomLocked, shelf->alignment());
  shelf->SetAlignment(ShelfAlignment::kRight);
  EXPECT_EQ(ShelfAlignment::kBottomLocked, shelf->alignment());
  SetScreenLocked(false);
  EXPECT_EQ(ShelfAlignment::kRight, shelf->alignment());
}

}  // namespace
}  // namespace ash