| 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 #include <memory> |
| 6 |
| 7 #include "base/memory/ptr_util.h" |
| 8 #include "base/test/scoped_command_line.h" |
| 9 #include "chrome/browser/chromeos/lock_screen_apps/state_controller.h" |
| 10 #include "chrome/browser/chromeos/lock_screen_apps/state_observer.h" |
| 11 #include "chrome/browser/chromeos/lock_screen_apps/types.h" |
| 12 #include "testing/gtest/include/gtest/gtest.h" |
| 13 |
| 14 namespace { |
| 15 |
| 16 const lock_screen_apps::Action kTestAction = lock_screen_apps::Action::kNewNote; |
| 17 |
| 18 class TestStateObserver : public lock_screen_apps::StateObserver { |
| 19 public: |
| 20 TestStateObserver() = default; |
| 21 ~TestStateObserver() override = default; |
| 22 |
| 23 void OnLockScreenAppsStateChanged( |
| 24 lock_screen_apps::Action action, |
| 25 lock_screen_apps::ActionState state) override { |
| 26 ASSERT_EQ(kTestAction, action); |
| 27 |
| 28 ++state_change_count_; |
| 29 } |
| 30 |
| 31 int state_change_count() const { return state_change_count_; } |
| 32 |
| 33 private: |
| 34 int state_change_count_ = 0; |
| 35 |
| 36 DISALLOW_COPY_AND_ASSIGN(TestStateObserver); |
| 37 }; |
| 38 |
| 39 class LockScreenAppStateControllerNotSupportedTest : public testing::Test { |
| 40 public: |
| 41 LockScreenAppStateControllerNotSupportedTest() = default; |
| 42 |
| 43 ~LockScreenAppStateControllerNotSupportedTest() override = default; |
| 44 |
| 45 void SetUp() override { |
| 46 command_line_ = base::MakeUnique<base::test::ScopedCommandLine>(); |
| 47 command_line_->GetProcessCommandLine()->InitFromArgv({""}); |
| 48 } |
| 49 |
| 50 private: |
| 51 std::unique_ptr<base::test::ScopedCommandLine> command_line_; |
| 52 |
| 53 DISALLOW_COPY_AND_ASSIGN(LockScreenAppStateControllerNotSupportedTest); |
| 54 }; |
| 55 |
| 56 class LockScreenAppStateControllerTest : public testing::Test { |
| 57 public: |
| 58 LockScreenAppStateControllerTest() = default; |
| 59 ~LockScreenAppStateControllerTest() override = default; |
| 60 |
| 61 void SetUp() override { |
| 62 command_line_ = base::MakeUnique<base::test::ScopedCommandLine>(); |
| 63 command_line_->GetProcessCommandLine()->InitFromArgv( |
| 64 {"", "--enable-lock-screen-apps"}); |
| 65 |
| 66 state_controller_ = lock_screen_apps::StateController::Get(); |
| 67 ASSERT_TRUE(state_controller_); |
| 68 |
| 69 state_controller_->AddObserver(&observer_); |
| 70 } |
| 71 |
| 72 void TearDown() override { state_controller_->RemoveObserver(&observer_); } |
| 73 |
| 74 const TestStateObserver& observer() const { return observer_; } |
| 75 |
| 76 lock_screen_apps::StateController* state_controller() { |
| 77 return state_controller_; |
| 78 } |
| 79 |
| 80 private: |
| 81 std::unique_ptr<base::test::ScopedCommandLine> command_line_; |
| 82 |
| 83 lock_screen_apps::StateController* state_controller_; |
| 84 TestStateObserver observer_; |
| 85 |
| 86 DISALLOW_COPY_AND_ASSIGN(LockScreenAppStateControllerTest); |
| 87 }; |
| 88 |
| 89 } // namespace |
| 90 |
| 91 TEST_F(LockScreenAppStateControllerNotSupportedTest, NoControllerInstance) { |
| 92 EXPECT_FALSE(lock_screen_apps::StateController::Get()); |
| 93 } |
| 94 |
| 95 TEST_F(LockScreenAppStateControllerTest, InitialState) { |
| 96 EXPECT_EQ(lock_screen_apps::ActionState::kNotSupported, |
| 97 state_controller()->GetActionState(kTestAction)); |
| 98 |
| 99 ASSERT_EQ(0, observer().state_change_count()); |
| 100 |
| 101 state_controller()->MoveToBackground(); |
| 102 |
| 103 EXPECT_EQ(lock_screen_apps::ActionState::kNotSupported, |
| 104 state_controller()->GetActionState(kTestAction)); |
| 105 |
| 106 ASSERT_EQ(0, observer().state_change_count()); |
| 107 } |
| 108 |
| 109 TEST_F(LockScreenAppStateControllerTest, HandleActionWhenNotAvaiable) { |
| 110 ASSERT_EQ(lock_screen_apps::ActionState::kNotSupported, |
| 111 state_controller()->GetActionState(kTestAction)); |
| 112 EXPECT_FALSE( |
| 113 state_controller()->HandleAction(lock_screen_apps::Action::kNewNote)); |
| 114 } |
| OLD | NEW |