Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2017 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "ash/login/lock_screen_controller.h" | 5 #include "ash/login/lock_screen_controller.h" |
| 6 | 6 |
| 7 #include "ash/shell.h" | 7 #include "ash/shell.h" |
| 8 #include "ash/test/ash_test_base.h" | 8 #include "ash/test/ash_test_base.h" |
| 9 #include "base/run_loop.h" | 9 #include "base/run_loop.h" |
| 10 #include "chromeos/cryptohome/system_salt_getter.h" | 10 #include "chromeos/cryptohome/system_salt_getter.h" |
| (...skipping 11 matching lines...) Expand all Loading... | |
| 22 return binding_.CreateInterfacePtrAndBind(); | 22 return binding_.CreateInterfacePtrAndBind(); |
| 23 } | 23 } |
| 24 | 24 |
| 25 // mojom::LockScreenClient: | 25 // mojom::LockScreenClient: |
| 26 void AuthenticateUser(const AccountId& account_id, | 26 void AuthenticateUser(const AccountId& account_id, |
| 27 const std::string& password, | 27 const std::string& password, |
| 28 bool authenticated_by_pin) override { | 28 bool authenticated_by_pin) override { |
| 29 ++autentication_requests_count_; | 29 ++autentication_requests_count_; |
| 30 } | 30 } |
| 31 | 31 |
| 32 void AttemptUnlock(const AccountId& account_id) override { | |
| 33 ++attempt_unlock_count_; | |
| 34 } | |
| 35 | |
| 36 void HardlockPod(const AccountId& account_id) override { | |
| 37 ++hardlock_pod_count_; | |
| 38 } | |
| 39 | |
| 40 void RecordClickOnLockIcon(const AccountId& account_id) override { | |
| 41 ++record_click_on_lockicon_count_; | |
| 42 } | |
| 43 | |
| 32 int authentication_requests_count() const { | 44 int authentication_requests_count() const { |
| 33 return autentication_requests_count_; | 45 return autentication_requests_count_; |
| 34 } | 46 } |
| 35 | 47 |
| 48 int attempt_unlock_count() const { return attempt_unlock_count_; } | |
| 49 | |
| 50 int hardlock_pod_count() const { return hardlock_pod_count_; } | |
| 51 | |
| 52 int record_click_on_lockicon_count() const { | |
| 53 return record_click_on_lockicon_count_; | |
| 54 } | |
| 55 | |
| 36 private: | 56 private: |
| 37 mojo::Binding<ash::mojom::LockScreenClient> binding_; | 57 mojo::Binding<ash::mojom::LockScreenClient> binding_; |
| 38 int autentication_requests_count_ = 0; | 58 int autentication_requests_count_ = 0; |
| 59 int attempt_unlock_count_ = 0; | |
| 60 int hardlock_pod_count_ = 0; | |
| 61 int record_click_on_lockicon_count_ = 0; | |
| 39 | 62 |
| 40 DISALLOW_COPY_AND_ASSIGN(TestLockScreenClient); | 63 DISALLOW_COPY_AND_ASSIGN(TestLockScreenClient); |
| 41 }; | 64 }; |
| 42 | 65 |
| 43 using LockScreenControllerTest = test::AshTestBase; | 66 using LockScreenControllerTest = test::AshTestBase; |
| 44 | 67 |
| 45 } // namespace | 68 } // namespace |
| 46 | 69 |
| 47 TEST_F(LockScreenControllerTest, RequestAuthentication) { | 70 TEST_F(LockScreenControllerTest, RequestAuthentication) { |
| 48 LockScreenController* lock_screen_controller = | 71 LockScreenController* lock_screen_controller = |
| 49 Shell::Get()->lock_screen_controller(); | 72 Shell::Get()->lock_screen_controller(); |
| 50 TestLockScreenClient lock_screen_client; | 73 TestLockScreenClient lock_screen_client; |
| 51 lock_screen_controller->SetClient( | 74 lock_screen_controller->SetClient( |
| 52 lock_screen_client.CreateInterfacePtrAndBind()); | 75 lock_screen_client.CreateInterfacePtrAndBind()); |
| 53 EXPECT_EQ(0, lock_screen_client.authentication_requests_count()); | 76 EXPECT_EQ(0, lock_screen_client.authentication_requests_count()); |
| 54 | 77 |
| 55 AccountId id = AccountId::FromUserEmail("user1@test.com"); | 78 AccountId id = AccountId::FromUserEmail("user1@test.com"); |
| 56 lock_screen_controller->AuthenticateUser(id, std::string(), false); | 79 lock_screen_controller->AuthenticateUser(id, std::string(), false); |
| 57 base::RunLoop().RunUntilIdle(); | 80 base::RunLoop().RunUntilIdle(); |
| 58 EXPECT_EQ(1, lock_screen_client.authentication_requests_count()); | 81 EXPECT_EQ(1, lock_screen_client.authentication_requests_count()); |
| 59 } | 82 } |
| 60 | 83 |
| 84 TEST_F(LockScreenControllerTest, RequestEasyUnlock) { | |
|
jdufault
2017/05/26 18:59:10
This will need to rebased to use the mock
xiaoyinh(OOO Sep 11-29)
2017/05/30 22:23:50
Done.
| |
| 85 LockScreenController* lock_screen_controller = | |
| 86 Shell::Get()->lock_screen_controller(); | |
| 87 TestLockScreenClient lock_screen_client; | |
| 88 lock_screen_controller->SetClient( | |
| 89 lock_screen_client.CreateInterfacePtrAndBind()); | |
| 90 EXPECT_EQ(0, lock_screen_client.attempt_unlock_count()); | |
| 91 EXPECT_EQ(0, lock_screen_client.hardlock_pod_count()); | |
| 92 EXPECT_EQ(0, lock_screen_client.record_click_on_lockicon_count()); | |
| 93 | |
| 94 // Request attemp unlock. | |
| 95 AccountId id = AccountId::FromUserEmail("user1@test.com"); | |
| 96 lock_screen_controller->AttemptUnlock(id); | |
| 97 base::RunLoop().RunUntilIdle(); | |
| 98 EXPECT_EQ(1, lock_screen_client.attempt_unlock_count()); | |
| 99 EXPECT_EQ(0, lock_screen_client.hardlock_pod_count()); | |
| 100 EXPECT_EQ(0, lock_screen_client.record_click_on_lockicon_count()); | |
| 101 | |
| 102 // Request hard lock user pod. | |
| 103 lock_screen_controller->HardlockPod(id); | |
| 104 base::RunLoop().RunUntilIdle(); | |
| 105 EXPECT_EQ(1, lock_screen_client.attempt_unlock_count()); | |
| 106 EXPECT_EQ(1, lock_screen_client.hardlock_pod_count()); | |
| 107 EXPECT_EQ(0, lock_screen_client.record_click_on_lockicon_count()); | |
| 108 | |
| 109 // Request record clicks on the lock icon in the user pod. | |
| 110 lock_screen_controller->RecordClickOnLockIcon(id); | |
| 111 base::RunLoop().RunUntilIdle(); | |
| 112 EXPECT_EQ(1, lock_screen_client.attempt_unlock_count()); | |
| 113 EXPECT_EQ(1, lock_screen_client.hardlock_pod_count()); | |
| 114 EXPECT_EQ(1, lock_screen_client.record_click_on_lockicon_count()); | |
| 115 } | |
| 116 | |
| 61 } // namespace ash | 117 } // namespace ash |
| OLD | NEW |