Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(320)

Side by Side Diff: ash/login/lock_screen_controller_unittest.cc

Issue 2894193002: cros: Pull TestLockScreenClient into a separate MockLockScreenClient file. (Closed)
Patch Set: Rebase (remove parent dep) Created 3 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « ash/BUILD.gn ('k') | ash/login/mock_lock_screen_client.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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/login/mock_lock_screen_client.h"
7 #include "ash/shell.h" 8 #include "ash/shell.h"
8 #include "ash/test/ash_test_base.h" 9 #include "ash/test/ash_test_base.h"
9 #include "base/run_loop.h" 10 #include "base/run_loop.h"
10 #include "chromeos/cryptohome/system_salt_getter.h" 11
12 using ::testing::_;
11 13
12 namespace ash { 14 namespace ash {
13 15
14 namespace { 16 namespace {
15
16 class TestLockScreenClient : public mojom::LockScreenClient {
17 public:
18 TestLockScreenClient() : binding_(this) {}
19 ~TestLockScreenClient() override = default;
20
21 mojom::LockScreenClientPtr CreateInterfacePtrAndBind() {
22 return binding_.CreateInterfacePtrAndBind();
23 }
24
25 // mojom::LockScreenClient:
26 void AuthenticateUser(const AccountId& account_id,
27 const std::string& password,
28 bool authenticated_by_pin) override {
29 ++autentication_requests_count_;
30 }
31
32 int authentication_requests_count() const {
33 return autentication_requests_count_;
34 }
35
36 private:
37 mojo::Binding<ash::mojom::LockScreenClient> binding_;
38 int autentication_requests_count_ = 0;
39
40 DISALLOW_COPY_AND_ASSIGN(TestLockScreenClient);
41 };
42
43 using LockScreenControllerTest = test::AshTestBase; 17 using LockScreenControllerTest = test::AshTestBase;
44
45 } // namespace 18 } // namespace
46 19
47 TEST_F(LockScreenControllerTest, RequestAuthentication) { 20 TEST_F(LockScreenControllerTest, RequestAuthentication) {
48 LockScreenController* lock_screen_controller = 21 LockScreenController* controller = Shell::Get()->lock_screen_controller();
49 Shell::Get()->lock_screen_controller(); 22 std::unique_ptr<MockLockScreenClient> client = BindMockLockScreenClient();
50 TestLockScreenClient lock_screen_client;
51 lock_screen_controller->SetClient(
52 lock_screen_client.CreateInterfacePtrAndBind());
53 EXPECT_EQ(0, lock_screen_client.authentication_requests_count());
54 23
55 AccountId id = AccountId::FromUserEmail("user1@test.com"); 24 AccountId id = AccountId::FromUserEmail("user1@test.com");
56 lock_screen_controller->AuthenticateUser(id, std::string(), false); 25
26 // We hardcode the hashed password. This is fine because the password hash
27 // algorithm should never accidently change; if it does we will need to
28 // have cryptohome migration code and one failing test isn't a problem.
29 std::string password = "password";
30 std::string hashed_password = "40c7b00f3bccc7675ec5b732de4bfbe4";
31 EXPECT_NE(password, hashed_password);
32
33 // Verify AuthenticateUser mojo call is run with the same account id, a
34 // (hashed) password, and the correct PIN state.
35 EXPECT_CALL(*client, AuthenticateUser(id, hashed_password, false));
36 controller->AuthenticateUser(id, password, false);
37
57 base::RunLoop().RunUntilIdle(); 38 base::RunLoop().RunUntilIdle();
58 EXPECT_EQ(1, lock_screen_client.authentication_requests_count());
59 } 39 }
60 40
61 } // namespace ash 41 } // namespace ash
OLDNEW
« no previous file with comments | « ash/BUILD.gn ('k') | ash/login/mock_lock_screen_client.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698