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

Unified 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, 7 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « ash/BUILD.gn ('k') | ash/login/mock_lock_screen_client.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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
index cc3f8d45e43c2467b4a1d1703b27e42b957905d0..3e42c9ee679438c372efa3643aa090e7051d6d41 100644
--- a/ash/login/lock_screen_controller_unittest.cc
+++ b/ash/login/lock_screen_controller_unittest.cc
@@ -4,58 +4,38 @@
#include "ash/login/lock_screen_controller.h"
+#include "ash/login/mock_lock_screen_client.h"
#include "ash/shell.h"
#include "ash/test/ash_test_base.h"
#include "base/run_loop.h"
-#include "chromeos/cryptohome/system_salt_getter.h"
+
+using ::testing::_;
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_;
- }
-
- 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);
-};
-
using LockScreenControllerTest = test::AshTestBase;
-
} // 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());
+ LockScreenController* controller = Shell::Get()->lock_screen_controller();
+ std::unique_ptr<MockLockScreenClient> client = BindMockLockScreenClient();
AccountId id = AccountId::FromUserEmail("user1@test.com");
- lock_screen_controller->AuthenticateUser(id, std::string(), false);
+
+ // We hardcode the hashed password. This is fine because the password hash
+ // algorithm should never accidently change; if it does we will need to
+ // have cryptohome migration code and one failing test isn't a problem.
+ std::string password = "password";
+ std::string hashed_password = "40c7b00f3bccc7675ec5b732de4bfbe4";
+ EXPECT_NE(password, hashed_password);
+
+ // Verify AuthenticateUser mojo call is run with the same account id, a
+ // (hashed) password, and the correct PIN state.
+ EXPECT_CALL(*client, AuthenticateUser(id, hashed_password, false));
+ controller->AuthenticateUser(id, password, false);
+
base::RunLoop().RunUntilIdle();
- EXPECT_EQ(1, lock_screen_client.authentication_requests_count());
}
} // namespace ash
« 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