[Wallet] Delay unlock with dev-wallet-password (#36340)
This commit is contained in:
@@ -1096,7 +1096,10 @@ KeyringService::KeyringService(JsonRpcService* json_rpc_service,
|
||||
|
||||
enabled_keyrings_ = GetEnabledKeyrings();
|
||||
|
||||
MaybeUnlockWithCommandLine();
|
||||
// Delay unlock attempt until after initialization is done by caller.
|
||||
base::SequencedTaskRunner::GetCurrentDefault()->PostTask(
|
||||
FROM_HERE, base::BindOnce(&KeyringService::MaybeUnlockWithCommandLine,
|
||||
weak_ptr_factory_.GetWeakPtr()));
|
||||
}
|
||||
|
||||
KeyringService::~KeyringService() {
|
||||
|
||||
@@ -121,6 +121,13 @@ std::string GenerateBtcImportPayload(std::string_view private_key_hex) {
|
||||
return Base58EncodeWithCheck(buf);
|
||||
}
|
||||
|
||||
void WaitForPostedTask() {
|
||||
base::RunLoop run_loop;
|
||||
base::SingleThreadTaskRunner::GetCurrentDefault()->PostTask(
|
||||
FROM_HERE, run_loop.QuitClosure());
|
||||
run_loop.Run();
|
||||
}
|
||||
|
||||
} // namespace
|
||||
|
||||
class TestKeyringServiceObserver : public mojom::KeyringServiceObserver {
|
||||
@@ -4485,6 +4492,7 @@ TEST_F(KeyringServiceUnitTest, DevWalletPassword) {
|
||||
// Locked on start by default.
|
||||
{
|
||||
KeyringService service(json_rpc_service(), GetPrefs(), GetLocalState());
|
||||
WaitForPostedTask();
|
||||
EXPECT_TRUE(service.IsLockedSync());
|
||||
}
|
||||
|
||||
@@ -4492,6 +4500,7 @@ TEST_F(KeyringServiceUnitTest, DevWalletPassword) {
|
||||
{
|
||||
cmdline->AppendSwitchASCII(switches::kDevWalletPassword, "some_password");
|
||||
KeyringService service(json_rpc_service(), GetPrefs(), GetLocalState());
|
||||
WaitForPostedTask();
|
||||
EXPECT_FALSE(service.IsLockedSync());
|
||||
cmdline->RemoveSwitch(switches::kDevWalletPassword);
|
||||
}
|
||||
@@ -4500,6 +4509,7 @@ TEST_F(KeyringServiceUnitTest, DevWalletPassword) {
|
||||
{
|
||||
cmdline->AppendSwitchASCII(switches::kDevWalletPassword, "wrong_password");
|
||||
KeyringService service(json_rpc_service(), GetPrefs(), GetLocalState());
|
||||
WaitForPostedTask();
|
||||
EXPECT_TRUE(service.IsLockedSync());
|
||||
cmdline->RemoveSwitch(switches::kDevWalletPassword);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user