Chromium Code Reviews| Index: ash/login/lock_screen_controller_unittest.cc |
| diff --git a/ash/login/lock_screen_controller_unittest.cc b/ash/login/lock_screen_controller_unittest.cc |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..a40dd76e42fa9e5172a3231e3bb1059cf972d9a8 |
| --- /dev/null |
| +++ b/ash/login/lock_screen_controller_unittest.cc |
| @@ -0,0 +1,73 @@ |
| +// 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. |
| + |
| +#include "ash/login/lock_screen_controller.h" |
| + |
| +#include "ash/shell.h" |
| +#include "ash/test/ash_test_base.h" |
| +#include "base/run_loop.h" |
| +#include "chromeos/cryptohome/system_salt_getter.h" |
| + |
| +namespace ash { |
| + |
| +namespace { |
| + |
| +class TestLockScreenClient : public mojom::LockScreenClient { |
| + public: |
| + TestLockScreenClient() : binding_(this) {} |
| + ~TestLockScreenClient() override = default; |
| + |
| + mojom::LockScreenClientPtr CreateInterfacePtrAndBind() { |
| + return binding_.CreateInterfacePtrAndBind(); |
| + } |
| + |
| + // mojom::LockScreenClient: |
| + void AuthenticateUser(const AccountId& account_id, |
| + const std::string& password, |
| + bool authenticated_by_pin) override { |
| + autentication_requests_count_++; |
|
xiyuan
2017/05/16 18:22:25
nit: pre-inc, i.e. ++autentication_requests_count_
xiaoyinh(OOO Sep 11-29)
2017/05/16 21:11:30
Done.
|
| + } |
| + |
| + int authentication_requests_count() const { |
| + return autentication_requests_count_; |
| + } |
| + |
| + private: |
| + mojo::Binding<ash::mojom::LockScreenClient> binding_; |
| + int autentication_requests_count_ = 0; |
| + |
| + DISALLOW_COPY_AND_ASSIGN(TestLockScreenClient); |
| +}; |
| + |
| +class LockScreenControllerTest : public test::AshTestBase { |
| + protected: |
| + LockScreenControllerTest() {} |
|
James Cook
2017/05/16 20:05:02
nit: = default
Also, you need ~LockScreenControll
xiaoyinh(OOO Sep 11-29)
2017/05/16 21:11:30
This has been simplified as
using LockScreenContr
|
| + |
| + void SetUp() override { |
|
xiyuan
2017/05/16 18:22:25
nit: // test::AshTestBase:
xiaoyinh(OOO Sep 11-29)
2017/05/16 21:11:31
This has been simplified as
using LockScreenContr
|
| + test::AshTestBase::SetUp(); |
| + chromeos::SystemSaltGetter::Initialize(); |
|
xiyuan
2017/05/16 18:22:25
This probably should go into AshTestHelper::SetUp[
xiaoyinh(OOO Sep 11-29)
2017/05/16 21:11:30
Done. Thanks for the information!
|
| + } |
| + void TearDown() override { |
| + chromeos::SystemSaltGetter::Shutdown(); |
| + test::AshTestBase::TearDown(); |
| + } |
| +}; |
| + |
| +} // namespace |
| + |
| +TEST_F(LockScreenControllerTest, RequestAuthentication) { |
| + LockScreenController* lock_screen_controller = |
| + Shell::Get()->lock_screen_controller(); |
| + TestLockScreenClient lock_screen_client; |
| + lock_screen_controller->SetClient( |
| + lock_screen_client.CreateInterfacePtrAndBind()); |
| + EXPECT_EQ(0, lock_screen_client.authentication_requests_count()); |
| + |
| + AccountId id = AccountId::FromUserEmail("user1@test.com"); |
| + lock_screen_controller->AuthenticateUser(id, std::string(), false); |
| + base::RunLoop().RunUntilIdle(); |
| + EXPECT_EQ(1, lock_screen_client.authentication_requests_count()); |
| +} |
|
James Cook
2017/05/16 20:05:02
Hooray for a simple, clean test!
xiaoyinh(OOO Sep 11-29)
2017/05/16 21:11:30
Thanks!
|
| + |
| +} // namespace ash |