Commit d3f959d3 authored by James Hawkins's avatar James Hawkins Committed by Commit Bot

Smart Lock: Remove SendAuthAttempt calls.

This method did nothing given that no event listener was registered for
the auth attempt listener in the WebUI.

R=hansberry@chromium.org

Bug: 899324
Test: none
Change-Id: I4f46d553ee95538a468b05a434f609ab60c7ca52
Reviewed-on: https://chromium-review.googlesource.com/c/1312300Reviewed-by: default avatarToni Baržić <tbarzic@chromium.org>
Reviewed-by: default avatarRyan Hansberry <hansberry@chromium.org>
Commit-Queue: James Hawkins <jhawkins@chromium.org>
Cr-Commit-Position: refs/heads/master@{#604625}
parent 5f2cc6d8
...@@ -39,7 +39,6 @@ class EasyUnlockAppManagerImpl : public EasyUnlockAppManager { ...@@ -39,7 +39,6 @@ class EasyUnlockAppManagerImpl : public EasyUnlockAppManager {
void EnsureReady(const base::Closure& ready_callback) override; void EnsureReady(const base::Closure& ready_callback) override;
void LoadApp() override; void LoadApp() override;
void DisableAppIfLoaded() override; void DisableAppIfLoaded() override;
bool SendAuthAttemptEvent() override;
private: private:
extensions::ExtensionSystem* extension_system_; extensions::ExtensionSystem* extension_system_;
...@@ -106,20 +105,6 @@ void EasyUnlockAppManagerImpl::DisableAppIfLoaded() { ...@@ -106,20 +105,6 @@ void EasyUnlockAppManagerImpl::DisableAppIfLoaded() {
app_id_, extensions::disable_reason::DISABLE_RELOAD); app_id_, extensions::disable_reason::DISABLE_RELOAD);
} }
bool EasyUnlockAppManagerImpl::SendAuthAttemptEvent() {
extensions::ExtensionService* extension_service =
extension_system_->extension_service();
if (!extension_service)
return false;
// TODO(tbarzic): Restrict this to EasyUnlock app.
extensions::ScreenlockPrivateEventRouter* screenlock_router =
extensions::ScreenlockPrivateEventRouter::GetFactoryInstance()->Get(
extension_service->profile());
return screenlock_router->OnAuthAttempted(
proximity_auth::mojom::AuthType::USER_CLICK, std::string());
}
} // namespace } // namespace
EasyUnlockAppManager::~EasyUnlockAppManager() {} EasyUnlockAppManager::~EasyUnlockAppManager() {}
......
...@@ -41,9 +41,6 @@ class EasyUnlockAppManager { ...@@ -41,9 +41,6 @@ class EasyUnlockAppManager {
// Disables Easy Unlock app. // Disables Easy Unlock app.
virtual void DisableAppIfLoaded() = 0; virtual void DisableAppIfLoaded() = 0;
// Sends screenlockPrivate.onAuthAttempted event to Easy Unlock app.
virtual bool SendAuthAttemptEvent() = 0;
}; };
} // namespace chromeos } // namespace chromeos
......
...@@ -17,7 +17,6 @@ ...@@ -17,7 +17,6 @@
#include "build/build_config.h" #include "build/build_config.h"
#include "chrome/browser/chromeos/login/users/scoped_test_user_manager.h" #include "chrome/browser/chromeos/login/users/scoped_test_user_manager.h"
#include "chrome/browser/chromeos/settings/scoped_cros_settings_test_helper.h" #include "chrome/browser/chromeos/settings/scoped_cros_settings_test_helper.h"
#include "chrome/browser/extensions/api/screenlock_private/screenlock_private_api.h"
#include "chrome/browser/extensions/component_loader.h" #include "chrome/browser/extensions/component_loader.h"
#include "chrome/browser/extensions/extension_service.h" #include "chrome/browser/extensions/extension_service.h"
#include "chrome/browser/extensions/test_extension_system.h" #include "chrome/browser/extensions/test_extension_system.h"
...@@ -33,15 +32,10 @@ ...@@ -33,15 +32,10 @@
#include "extensions/browser/extension_registry_observer.h" #include "extensions/browser/extension_registry_observer.h"
#include "extensions/browser/process_manager.h" #include "extensions/browser/process_manager.h"
#include "extensions/browser/process_manager_factory.h" #include "extensions/browser/process_manager_factory.h"
#include "extensions/browser/test_event_router.h"
#include "extensions/common/api/app_runtime.h" #include "extensions/common/api/app_runtime.h"
#include "extensions/common/extension.h" #include "extensions/common/extension.h"
#include "testing/gtest/include/gtest/gtest.h" #include "testing/gtest/include/gtest/gtest.h"
namespace easy_unlock_private_api = chrome_apps::api::easy_unlock_private;
namespace screenlock_private_api = extensions::api::screenlock_private;
namespace app_runtime_api = extensions::api::app_runtime;
namespace chromeos { namespace chromeos {
namespace { namespace {
...@@ -77,11 +71,6 @@ std::unique_ptr<KeyedService> CreateTestProcessManager( ...@@ -77,11 +71,6 @@ std::unique_ptr<KeyedService> CreateTestProcessManager(
return std::make_unique<TestProcessManager>(context); return std::make_unique<TestProcessManager>(context);
} }
std::unique_ptr<KeyedService> CreateScreenlockPrivateEventRouter(
content::BrowserContext* context) {
return std::make_unique<extensions::ScreenlockPrivateEventRouter>(context);
}
// Observes extension registry for unload and load events (in that order) of an // Observes extension registry for unload and load events (in that order) of an
// extension with the provided extension id. // extension with the provided extension id.
// Used to determine if an extension was reloaded. // Used to determine if an extension was reloaded.
...@@ -128,80 +117,6 @@ class ExtensionReloadTracker : public extensions::ExtensionRegistryObserver { ...@@ -128,80 +117,6 @@ class ExtensionReloadTracker : public extensions::ExtensionRegistryObserver {
DISALLOW_COPY_AND_ASSIGN(ExtensionReloadTracker); DISALLOW_COPY_AND_ASSIGN(ExtensionReloadTracker);
}; };
// Consumes events dispatched from test event router.
class EasyUnlockAppEventConsumer
: public extensions::TestEventRouter::EventObserver {
public:
EasyUnlockAppEventConsumer() = default;
~EasyUnlockAppEventConsumer() override = default;
// extensions::TestEventRouter::EventObserver:
void OnDispatchEventToExtension(const std::string& extension_id,
const extensions::Event& event) override {
if (event.event_name ==
screenlock_private_api::OnAuthAttempted::kEventName) {
ConsumeAuthAttempted(event.event_args.get());
} else {
ASSERT_EQ(app_runtime_api::OnLaunched::kEventName, event.event_name)
<< "Unexpected event: " << event.event_name;
}
}
void OnBroadcastEvent(const extensions::Event& event) override {
ASSERT_EQ(screenlock_private_api::OnAuthAttempted::kEventName,
event.event_name);
ConsumeAuthAttempted(event.event_args.get());
}
// The data carried by the last UserInfoUpdated event:
std::string user_id() const { return user_id_; }
bool user_logged_in() const { return user_logged_in_; }
bool user_data_ready() const { return user_data_ready_; }
private:
// Processes easyUnlockPrivate.onUserInfoUpdated event.
void ConsumeUserInfoUpdated(base::ListValue* args) {
if (!args) {
ADD_FAILURE() << "No argument list for onUserInfoUpdated event.";
return;
}
if (args->GetSize() != 1u) {
ADD_FAILURE()
<< "Invalid argument list size for onUserInfoUpdated event: "
<< args->GetSize() << " expected: " << 1u;
return;
}
base::DictionaryValue* user_info;
if (!args->GetDictionary(0u, &user_info) || !user_info) {
ADD_FAILURE() << "Unabled to get event argument as dictionary for "
<< "onUserInfoUpdated event.";
return;
}
EXPECT_TRUE(user_info->GetString("userId", &user_id_));
EXPECT_TRUE(user_info->GetBoolean("loggedIn", &user_logged_in_));
EXPECT_TRUE(user_info->GetBoolean("dataReady", &user_data_ready_));
}
// Processes screenlockPrivate.onAuthAttempted event.
void ConsumeAuthAttempted(base::ListValue* args) {
ASSERT_TRUE(args);
ASSERT_EQ(2u, args->GetSize());
std::string auth_type;
ASSERT_TRUE(args->GetString(0u, &auth_type));
EXPECT_EQ("userClick", auth_type);
}
std::string user_id_;
bool user_logged_in_;
bool user_data_ready_;
DISALLOW_COPY_AND_ASSIGN(EasyUnlockAppEventConsumer);
};
class EasyUnlockAppManagerTest : public testing::Test { class EasyUnlockAppManagerTest : public testing::Test {
public: public:
EasyUnlockAppManagerTest() : command_line_(base::CommandLine::NO_PROGRAM) {} EasyUnlockAppManagerTest() : command_line_(base::CommandLine::NO_PROGRAM) {}
...@@ -230,16 +145,6 @@ class EasyUnlockAppManagerTest : public testing::Test { ...@@ -230,16 +145,6 @@ class EasyUnlockAppManagerTest : public testing::Test {
.AppendASCII("easy_unlock"); .AppendASCII("easy_unlock");
} }
int AuthAttemptedCount() const {
return event_router_->GetEventCount(
screenlock_private_api::OnAuthAttempted::kEventName);
}
int AppLaunchedCount() const {
return event_router_->GetEventCount(
app_runtime_api::OnLaunched::kEventName);
}
private: private:
// Initializes test extension system. // Initializes test extension system.
extensions::ExtensionSystem* SetUpExtensionSystem() { extensions::ExtensionSystem* SetUpExtensionSystem() {
...@@ -252,14 +157,6 @@ class EasyUnlockAppManagerTest : public testing::Test { ...@@ -252,14 +157,6 @@ class EasyUnlockAppManagerTest : public testing::Test {
extensions::ProcessManagerFactory::GetInstance()->SetTestingFactory( extensions::ProcessManagerFactory::GetInstance()->SetTestingFactory(
&profile_, base::BindRepeating(&CreateTestProcessManager)); &profile_, base::BindRepeating(&CreateTestProcessManager));
extensions::ScreenlockPrivateEventRouter::GetFactoryInstance()
->SetTestingFactory(
&profile_,
base::BindRepeating(&CreateScreenlockPrivateEventRouter));
event_router_ = extensions::CreateAndUseTestEventRouter(&profile_);
event_router_->AddEventObserver(&event_consumer_);
event_router_->set_expected_extension_id(extension_misc::kEasyUnlockAppId);
extension_service_->component_loader()->set_ignore_whitelist_for_testing( extension_service_->component_loader()->set_ignore_whitelist_for_testing(
true); true);
...@@ -280,9 +177,7 @@ class EasyUnlockAppManagerTest : public testing::Test { ...@@ -280,9 +177,7 @@ class EasyUnlockAppManagerTest : public testing::Test {
TestingProfile profile_; TestingProfile profile_;
EasyUnlockAppEventConsumer event_consumer_;
extensions::ExtensionService* extension_service_; extensions::ExtensionService* extension_service_;
extensions::TestEventRouter* event_router_;
base::CommandLine command_line_; base::CommandLine command_line_;
...@@ -392,43 +287,5 @@ TEST_F(EasyUnlockAppManagerTest, EnsureReadyAfterExtesionSystemReady) { ...@@ -392,43 +287,5 @@ TEST_F(EasyUnlockAppManagerTest, EnsureReadyAfterExtesionSystemReady) {
ASSERT_TRUE(ready); ASSERT_TRUE(ready);
} }
TEST_F(EasyUnlockAppManagerTest, SendAuthAttempted) {
SetExtensionSystemReady();
app_manager_->LoadApp();
event_router_->AddLazyEventListener(
screenlock_private_api::OnAuthAttempted::kEventName,
extension_misc::kEasyUnlockAppId);
EXPECT_TRUE(app_manager_->SendAuthAttemptEvent());
EXPECT_EQ(1, AuthAttemptedCount());
}
TEST_F(EasyUnlockAppManagerTest, SendAuthAttemptedNoRegisteredListeners) {
SetExtensionSystemReady();
app_manager_->LoadApp();
ASSERT_EQ(0, AuthAttemptedCount());
EXPECT_FALSE(app_manager_->SendAuthAttemptEvent());
EXPECT_EQ(0, AuthAttemptedCount());
}
TEST_F(EasyUnlockAppManagerTest, SendAuthAttemptedAppDisabled) {
SetExtensionSystemReady();
app_manager_->LoadApp();
event_router_->AddLazyEventListener(
screenlock_private_api::OnAuthAttempted::kEventName,
extension_misc::kEasyUnlockAppId);
app_manager_->DisableAppIfLoaded();
ASSERT_EQ(0, AuthAttemptedCount());
EXPECT_FALSE(app_manager_->SendAuthAttemptEvent());
EXPECT_EQ(0, AuthAttemptedCount());
}
} // namespace } // namespace
} // namespace chromeos } // namespace chromeos
...@@ -8,7 +8,6 @@ ...@@ -8,7 +8,6 @@
#include "base/command_line.h" #include "base/command_line.h"
#include "base/logging.h" #include "base/logging.h"
#include "build/build_config.h" #include "build/build_config.h"
#include "chrome/browser/chromeos/login/easy_unlock/easy_unlock_app_manager.h"
#include "chrome/browser/chromeos/login/easy_unlock/easy_unlock_key_manager.h" #include "chrome/browser/chromeos/login/easy_unlock/easy_unlock_key_manager.h"
#include "chromeos/components/proximity_auth/screenlock_bridge.h" #include "chromeos/components/proximity_auth/screenlock_bridge.h"
#include "chromeos/components/proximity_auth/switches.h" #include "chromeos/components/proximity_auth/switches.h"
...@@ -81,13 +80,9 @@ void OnAuthAttemptFinalized(EasyUnlockAuthAttempt::Type auth_attempt_type, ...@@ -81,13 +80,9 @@ void OnAuthAttemptFinalized(EasyUnlockAuthAttempt::Type auth_attempt_type,
} // namespace } // namespace
EasyUnlockAuthAttempt::EasyUnlockAuthAttempt(EasyUnlockAppManager* app_manager, EasyUnlockAuthAttempt::EasyUnlockAuthAttempt(const AccountId& account_id,
const AccountId& account_id,
Type type) Type type)
: app_manager_(app_manager), : state_(STATE_IDLE), account_id_(account_id), type_(type) {}
state_(STATE_IDLE),
account_id_(account_id),
type_(type) {}
EasyUnlockAuthAttempt::~EasyUnlockAuthAttempt() { EasyUnlockAuthAttempt::~EasyUnlockAuthAttempt() {
if (state_ == STATE_RUNNING) if (state_ == STATE_RUNNING)
...@@ -111,17 +106,6 @@ bool EasyUnlockAuthAttempt::Start() { ...@@ -111,17 +106,6 @@ bool EasyUnlockAuthAttempt::Start() {
state_ = STATE_RUNNING; state_ = STATE_RUNNING;
// We need this workaround for ProximityAuthSystem, since we don't load the
// full background app anymore. The call to
// |app_manager_->SendAuthAttemptEvent()| returns false, as there is no
// observer registered for the |screenlock::OnAuthAttempted| event. As a
// result, the auth attempt will always fail.
// TODO(sacomoto): Clean this up when the background app is not needed
// anymore.
// TODO(jhawkins): Verify whether this method has important side effects or
// if it can be removed.
app_manager_->SendAuthAttemptEvent();
return true; return true;
} }
......
...@@ -13,8 +13,6 @@ ...@@ -13,8 +13,6 @@
namespace chromeos { namespace chromeos {
class EasyUnlockAppManager;
// Class responsible for handling easy unlock auth attempts (both for unlocking // Class responsible for handling easy unlock auth attempts (both for unlocking
// the screen and logging in). The auth protocol is started by calling |Start|, // the screen and logging in). The auth protocol is started by calling |Start|,
// which notifies the easy unlock app about auth attempt. When the auth result // which notifies the easy unlock app about auth attempt. When the auth result
...@@ -27,9 +25,7 @@ class EasyUnlockAuthAttempt { ...@@ -27,9 +25,7 @@ class EasyUnlockAuthAttempt {
// The auth type. // The auth type.
enum Type { TYPE_UNLOCK, TYPE_SIGNIN }; enum Type { TYPE_UNLOCK, TYPE_SIGNIN };
EasyUnlockAuthAttempt(EasyUnlockAppManager* app_manager, EasyUnlockAuthAttempt(const AccountId& account_id, Type type);
const AccountId& account_id,
Type type);
~EasyUnlockAuthAttempt(); ~EasyUnlockAuthAttempt();
// Starts the auth attempt by sending screenlockPrivate.onAuthAttempted event // Starts the auth attempt by sending screenlockPrivate.onAuthAttempted event
...@@ -57,7 +53,6 @@ class EasyUnlockAuthAttempt { ...@@ -57,7 +53,6 @@ class EasyUnlockAuthAttempt {
// Cancels the attempt. // Cancels the attempt.
void Cancel(const AccountId& account_id); void Cancel(const AccountId& account_id);
EasyUnlockAppManager* app_manager_;
State state_; State state_;
const AccountId account_id_; const AccountId account_id_;
Type type_; Type type_;
......
...@@ -9,7 +9,6 @@ ...@@ -9,7 +9,6 @@
#include "base/command_line.h" #include "base/command_line.h"
#include "base/macros.h" #include "base/macros.h"
#include "build/build_config.h" #include "build/build_config.h"
#include "chrome/browser/chromeos/login/easy_unlock/easy_unlock_app_manager.h"
#include "chrome/browser/chromeos/login/easy_unlock/easy_unlock_key_manager.h" #include "chrome/browser/chromeos/login/easy_unlock/easy_unlock_key_manager.h"
#include "chromeos/components/proximity_auth/screenlock_bridge.h" #include "chromeos/components/proximity_auth/screenlock_bridge.h"
#include "chromeos/components/proximity_auth/switches.h" #include "chromeos/components/proximity_auth/switches.h"
...@@ -50,40 +49,6 @@ std::string GetSessionKey() { ...@@ -50,40 +49,6 @@ std::string GetSessionKey() {
arraysize(kSessionKey)); arraysize(kSessionKey));
} }
// Fake app manager used by the EasyUnlockAuthAttempt during tests.
// It tracks screenlockPrivate.onAuthAttempted events.
class FakeAppManager : public EasyUnlockAppManager {
public:
FakeAppManager()
: auth_attempt_count_(0u), auth_attempt_should_fail_(false) {}
~FakeAppManager() override {}
void EnsureReady(const base::Closure& ready_callback) override {
ADD_FAILURE() << "Not reached";
}
void LoadApp() override { ADD_FAILURE() << "Not reached"; }
void DisableAppIfLoaded() override { ADD_FAILURE() << "Not reached"; }
bool SendAuthAttemptEvent() override {
++auth_attempt_count_;
return !auth_attempt_should_fail_;
}
size_t auth_attempt_count() const { return auth_attempt_count_; }
void set_auth_attempt_should_fail(bool value) {
auth_attempt_should_fail_ = value;
}
private:
size_t auth_attempt_count_;
bool auth_attempt_should_fail_;
DISALLOW_COPY_AND_ASSIGN(FakeAppManager);
};
// Fake lock handler to be used in these tests. // Fake lock handler to be used in these tests.
class TestLockHandler : public proximity_auth::ScreenlockBridge::LockHandler { class TestLockHandler : public proximity_auth::ScreenlockBridge::LockHandler {
public: public:
...@@ -196,10 +161,8 @@ class EasyUnlockAuthAttemptUnlockTest : public testing::Test { ...@@ -196,10 +161,8 @@ class EasyUnlockAuthAttemptUnlockTest : public testing::Test {
~EasyUnlockAuthAttemptUnlockTest() override {} ~EasyUnlockAuthAttemptUnlockTest() override {}
void SetUp() override { void SetUp() override {
app_manager_.reset(new FakeAppManager()); auth_attempt_.reset(new EasyUnlockAuthAttempt(
auth_attempt_.reset( test_account_id1_, EasyUnlockAuthAttempt::TYPE_UNLOCK));
new EasyUnlockAuthAttempt(app_manager_.get(), test_account_id1_,
EasyUnlockAuthAttempt::TYPE_UNLOCK));
} }
void TearDown() override { void TearDown() override {
...@@ -216,7 +179,6 @@ class EasyUnlockAuthAttemptUnlockTest : public testing::Test { ...@@ -216,7 +179,6 @@ class EasyUnlockAuthAttemptUnlockTest : public testing::Test {
} }
std::unique_ptr<EasyUnlockAuthAttempt> auth_attempt_; std::unique_ptr<EasyUnlockAuthAttempt> auth_attempt_;
std::unique_ptr<FakeAppManager> app_manager_;
std::unique_ptr<TestLockHandler> lock_handler_; std::unique_ptr<TestLockHandler> lock_handler_;
const AccountId test_account_id1_ = AccountId::FromUserEmail(kTestUser1); const AccountId test_account_id1_ = AccountId::FromUserEmail(kTestUser1);
...@@ -230,7 +192,6 @@ TEST_F(EasyUnlockAuthAttemptUnlockTest, StartWhenNotLocked) { ...@@ -230,7 +192,6 @@ TEST_F(EasyUnlockAuthAttemptUnlockTest, StartWhenNotLocked) {
ASSERT_FALSE(proximity_auth::ScreenlockBridge::Get()->IsLocked()); ASSERT_FALSE(proximity_auth::ScreenlockBridge::Get()->IsLocked());
EXPECT_FALSE(auth_attempt_->Start()); EXPECT_FALSE(auth_attempt_->Start());
EXPECT_EQ(0u, app_manager_->auth_attempt_count());
} }
TEST_F(EasyUnlockAuthAttemptUnlockTest, StartWhenAuthTypeIsPassword) { TEST_F(EasyUnlockAuthAttemptUnlockTest, StartWhenAuthTypeIsPassword) {
...@@ -243,7 +204,6 @@ TEST_F(EasyUnlockAuthAttemptUnlockTest, StartWhenAuthTypeIsPassword) { ...@@ -243,7 +204,6 @@ TEST_F(EasyUnlockAuthAttemptUnlockTest, StartWhenAuthTypeIsPassword) {
EXPECT_FALSE(auth_attempt_->Start()); EXPECT_FALSE(auth_attempt_->Start());
EXPECT_EQ(0u, app_manager_->auth_attempt_count());
EXPECT_EQ(TestLockHandler::STATE_UNLOCK_CANCELED, lock_handler_->state()); EXPECT_EQ(TestLockHandler::STATE_UNLOCK_CANCELED, lock_handler_->state());
} }
...@@ -254,7 +214,6 @@ TEST_F(EasyUnlockAuthAttemptUnlockTest, ResetBeforeFinalizeUnlock) { ...@@ -254,7 +214,6 @@ TEST_F(EasyUnlockAuthAttemptUnlockTest, ResetBeforeFinalizeUnlock) {
ASSERT_TRUE(auth_attempt_->Start()); ASSERT_TRUE(auth_attempt_->Start());
ASSERT_EQ(1u, app_manager_->auth_attempt_count());
EXPECT_EQ(TestLockHandler::STATE_ATTEMPTING_UNLOCK, lock_handler_->state()); EXPECT_EQ(TestLockHandler::STATE_ATTEMPTING_UNLOCK, lock_handler_->state());
auth_attempt_.reset(); auth_attempt_.reset();
...@@ -269,7 +228,6 @@ TEST_F(EasyUnlockAuthAttemptUnlockTest, FinalizeUnlockFailure) { ...@@ -269,7 +228,6 @@ TEST_F(EasyUnlockAuthAttemptUnlockTest, FinalizeUnlockFailure) {
ASSERT_TRUE(auth_attempt_->Start()); ASSERT_TRUE(auth_attempt_->Start());
ASSERT_EQ(1u, app_manager_->auth_attempt_count());
EXPECT_EQ(TestLockHandler::STATE_ATTEMPTING_UNLOCK, lock_handler_->state()); EXPECT_EQ(TestLockHandler::STATE_ATTEMPTING_UNLOCK, lock_handler_->state());
auth_attempt_->FinalizeUnlock(test_account_id1_, false); auth_attempt_->FinalizeUnlock(test_account_id1_, false);
...@@ -284,7 +242,6 @@ TEST_F(EasyUnlockAuthAttemptUnlockTest, FinalizeSigninCalled) { ...@@ -284,7 +242,6 @@ TEST_F(EasyUnlockAuthAttemptUnlockTest, FinalizeSigninCalled) {
ASSERT_TRUE(auth_attempt_->Start()); ASSERT_TRUE(auth_attempt_->Start());
ASSERT_EQ(1u, app_manager_->auth_attempt_count());
EXPECT_EQ(TestLockHandler::STATE_ATTEMPTING_UNLOCK, lock_handler_->state()); EXPECT_EQ(TestLockHandler::STATE_ATTEMPTING_UNLOCK, lock_handler_->state());
// Wrapped secret and key should be irrelevant in this case. // Wrapped secret and key should be irrelevant in this case.
...@@ -301,7 +258,6 @@ TEST_F(EasyUnlockAuthAttemptUnlockTest, UnlockSucceeds) { ...@@ -301,7 +258,6 @@ TEST_F(EasyUnlockAuthAttemptUnlockTest, UnlockSucceeds) {
ASSERT_TRUE(auth_attempt_->Start()); ASSERT_TRUE(auth_attempt_->Start());
ASSERT_EQ(1u, app_manager_->auth_attempt_count());
EXPECT_EQ(TestLockHandler::STATE_ATTEMPTING_UNLOCK, lock_handler_->state()); EXPECT_EQ(TestLockHandler::STATE_ATTEMPTING_UNLOCK, lock_handler_->state());
auth_attempt_->FinalizeUnlock(test_account_id1_, true); auth_attempt_->FinalizeUnlock(test_account_id1_, true);
...@@ -316,7 +272,6 @@ TEST_F(EasyUnlockAuthAttemptUnlockTest, FinalizeUnlockCalledForWrongUser) { ...@@ -316,7 +272,6 @@ TEST_F(EasyUnlockAuthAttemptUnlockTest, FinalizeUnlockCalledForWrongUser) {
ASSERT_TRUE(auth_attempt_->Start()); ASSERT_TRUE(auth_attempt_->Start());
ASSERT_EQ(1u, app_manager_->auth_attempt_count());
EXPECT_EQ(TestLockHandler::STATE_ATTEMPTING_UNLOCK, lock_handler_->state()); EXPECT_EQ(TestLockHandler::STATE_ATTEMPTING_UNLOCK, lock_handler_->state());
auth_attempt_->FinalizeUnlock(test_account_id2_, true); auth_attempt_->FinalizeUnlock(test_account_id2_, true);
...@@ -338,10 +293,8 @@ class EasyUnlockAuthAttemptSigninTest : public testing::Test { ...@@ -338,10 +293,8 @@ class EasyUnlockAuthAttemptSigninTest : public testing::Test {
~EasyUnlockAuthAttemptSigninTest() override {} ~EasyUnlockAuthAttemptSigninTest() override {}
void SetUp() override { void SetUp() override {
app_manager_.reset(new FakeAppManager()); auth_attempt_.reset(new EasyUnlockAuthAttempt(
auth_attempt_.reset( test_account_id1_, EasyUnlockAuthAttempt::TYPE_SIGNIN));
new EasyUnlockAuthAttempt(app_manager_.get(), test_account_id1_,
EasyUnlockAuthAttempt::TYPE_SIGNIN));
} }
void TearDown() override { void TearDown() override {
...@@ -358,7 +311,6 @@ class EasyUnlockAuthAttemptSigninTest : public testing::Test { ...@@ -358,7 +311,6 @@ class EasyUnlockAuthAttemptSigninTest : public testing::Test {
} }
std::unique_ptr<EasyUnlockAuthAttempt> auth_attempt_; std::unique_ptr<EasyUnlockAuthAttempt> auth_attempt_;
std::unique_ptr<FakeAppManager> app_manager_;
std::unique_ptr<TestLockHandler> lock_handler_; std::unique_ptr<TestLockHandler> lock_handler_;
const AccountId test_account_id1_ = AccountId::FromUserEmail(kTestUser1); const AccountId test_account_id1_ = AccountId::FromUserEmail(kTestUser1);
...@@ -372,7 +324,6 @@ TEST_F(EasyUnlockAuthAttemptSigninTest, StartWhenNotLocked) { ...@@ -372,7 +324,6 @@ TEST_F(EasyUnlockAuthAttemptSigninTest, StartWhenNotLocked) {
ASSERT_FALSE(proximity_auth::ScreenlockBridge::Get()->IsLocked()); ASSERT_FALSE(proximity_auth::ScreenlockBridge::Get()->IsLocked());
EXPECT_FALSE(auth_attempt_->Start()); EXPECT_FALSE(auth_attempt_->Start());
EXPECT_EQ(0u, app_manager_->auth_attempt_count());
} }
TEST_F(EasyUnlockAuthAttemptSigninTest, StartWhenAuthTypeIsPassword) { TEST_F(EasyUnlockAuthAttemptSigninTest, StartWhenAuthTypeIsPassword) {
...@@ -385,7 +336,6 @@ TEST_F(EasyUnlockAuthAttemptSigninTest, StartWhenAuthTypeIsPassword) { ...@@ -385,7 +336,6 @@ TEST_F(EasyUnlockAuthAttemptSigninTest, StartWhenAuthTypeIsPassword) {
EXPECT_FALSE(auth_attempt_->Start()); EXPECT_FALSE(auth_attempt_->Start());
EXPECT_EQ(0u, app_manager_->auth_attempt_count());
EXPECT_EQ(TestLockHandler::STATE_SIGNIN_CANCELED, lock_handler_->state()); EXPECT_EQ(TestLockHandler::STATE_SIGNIN_CANCELED, lock_handler_->state());
} }
...@@ -396,7 +346,6 @@ TEST_F(EasyUnlockAuthAttemptSigninTest, ResetBeforeFinalizeSignin) { ...@@ -396,7 +346,6 @@ TEST_F(EasyUnlockAuthAttemptSigninTest, ResetBeforeFinalizeSignin) {
ASSERT_TRUE(auth_attempt_->Start()); ASSERT_TRUE(auth_attempt_->Start());
ASSERT_EQ(1u, app_manager_->auth_attempt_count());
EXPECT_EQ(TestLockHandler::STATE_ATTEMPTING_SIGNIN, lock_handler_->state()); EXPECT_EQ(TestLockHandler::STATE_ATTEMPTING_SIGNIN, lock_handler_->state());
auth_attempt_.reset(); auth_attempt_.reset();
...@@ -411,7 +360,6 @@ TEST_F(EasyUnlockAuthAttemptSigninTest, FinalizeSigninWithEmtpySecret) { ...@@ -411,7 +360,6 @@ TEST_F(EasyUnlockAuthAttemptSigninTest, FinalizeSigninWithEmtpySecret) {
ASSERT_TRUE(auth_attempt_->Start()); ASSERT_TRUE(auth_attempt_->Start());
ASSERT_EQ(1u, app_manager_->auth_attempt_count());
EXPECT_EQ(TestLockHandler::STATE_ATTEMPTING_SIGNIN, lock_handler_->state()); EXPECT_EQ(TestLockHandler::STATE_ATTEMPTING_SIGNIN, lock_handler_->state());
auth_attempt_->FinalizeSignin(test_account_id1_, "", GetSessionKey()); auth_attempt_->FinalizeSignin(test_account_id1_, "", GetSessionKey());
...@@ -426,7 +374,6 @@ TEST_F(EasyUnlockAuthAttemptSigninTest, FinalizeSigninWithEmtpyKey) { ...@@ -426,7 +374,6 @@ TEST_F(EasyUnlockAuthAttemptSigninTest, FinalizeSigninWithEmtpyKey) {
ASSERT_TRUE(auth_attempt_->Start()); ASSERT_TRUE(auth_attempt_->Start());
ASSERT_EQ(1u, app_manager_->auth_attempt_count());
EXPECT_EQ(TestLockHandler::STATE_ATTEMPTING_SIGNIN, lock_handler_->state()); EXPECT_EQ(TestLockHandler::STATE_ATTEMPTING_SIGNIN, lock_handler_->state());
auth_attempt_->FinalizeSignin(test_account_id1_, GetWrappedSecret(), ""); auth_attempt_->FinalizeSignin(test_account_id1_, GetWrappedSecret(), "");
...@@ -441,7 +388,6 @@ TEST_F(EasyUnlockAuthAttemptSigninTest, SigninSuccess) { ...@@ -441,7 +388,6 @@ TEST_F(EasyUnlockAuthAttemptSigninTest, SigninSuccess) {
ASSERT_TRUE(auth_attempt_->Start()); ASSERT_TRUE(auth_attempt_->Start());
ASSERT_EQ(1u, app_manager_->auth_attempt_count());
EXPECT_EQ(TestLockHandler::STATE_ATTEMPTING_SIGNIN, lock_handler_->state()); EXPECT_EQ(TestLockHandler::STATE_ATTEMPTING_SIGNIN, lock_handler_->state());
lock_handler_->set_expected_secret(GetSecret()); lock_handler_->set_expected_secret(GetSecret());
...@@ -458,7 +404,6 @@ TEST_F(EasyUnlockAuthAttemptSigninTest, WrongWrappedSecret) { ...@@ -458,7 +404,6 @@ TEST_F(EasyUnlockAuthAttemptSigninTest, WrongWrappedSecret) {
ASSERT_TRUE(auth_attempt_->Start()); ASSERT_TRUE(auth_attempt_->Start());
ASSERT_EQ(1u, app_manager_->auth_attempt_count());
EXPECT_EQ(TestLockHandler::STATE_ATTEMPTING_SIGNIN, lock_handler_->state()); EXPECT_EQ(TestLockHandler::STATE_ATTEMPTING_SIGNIN, lock_handler_->state());
auth_attempt_->FinalizeSignin(test_account_id1_, "wrong_secret", auth_attempt_->FinalizeSignin(test_account_id1_, "wrong_secret",
...@@ -474,7 +419,6 @@ TEST_F(EasyUnlockAuthAttemptSigninTest, InvalidSessionKey) { ...@@ -474,7 +419,6 @@ TEST_F(EasyUnlockAuthAttemptSigninTest, InvalidSessionKey) {
ASSERT_TRUE(auth_attempt_->Start()); ASSERT_TRUE(auth_attempt_->Start());
ASSERT_EQ(1u, app_manager_->auth_attempt_count());
EXPECT_EQ(TestLockHandler::STATE_ATTEMPTING_SIGNIN, lock_handler_->state()); EXPECT_EQ(TestLockHandler::STATE_ATTEMPTING_SIGNIN, lock_handler_->state());
auth_attempt_->FinalizeSignin(test_account_id1_, GetWrappedSecret(), auth_attempt_->FinalizeSignin(test_account_id1_, GetWrappedSecret(),
...@@ -490,7 +434,6 @@ TEST_F(EasyUnlockAuthAttemptSigninTest, FinalizeUnlockCalled) { ...@@ -490,7 +434,6 @@ TEST_F(EasyUnlockAuthAttemptSigninTest, FinalizeUnlockCalled) {
ASSERT_TRUE(auth_attempt_->Start()); ASSERT_TRUE(auth_attempt_->Start());
ASSERT_EQ(1u, app_manager_->auth_attempt_count());
EXPECT_EQ(TestLockHandler::STATE_ATTEMPTING_SIGNIN, lock_handler_->state()); EXPECT_EQ(TestLockHandler::STATE_ATTEMPTING_SIGNIN, lock_handler_->state());
auth_attempt_->FinalizeUnlock(test_account_id1_, true); auth_attempt_->FinalizeUnlock(test_account_id1_, true);
...@@ -505,7 +448,6 @@ TEST_F(EasyUnlockAuthAttemptSigninTest, FinalizeSigninCalledForWrongUser) { ...@@ -505,7 +448,6 @@ TEST_F(EasyUnlockAuthAttemptSigninTest, FinalizeSigninCalledForWrongUser) {
ASSERT_TRUE(auth_attempt_->Start()); ASSERT_TRUE(auth_attempt_->Start());
ASSERT_EQ(1u, app_manager_->auth_attempt_count());
EXPECT_EQ(TestLockHandler::STATE_ATTEMPTING_SIGNIN, lock_handler_->state()); EXPECT_EQ(TestLockHandler::STATE_ATTEMPTING_SIGNIN, lock_handler_->state());
lock_handler_->set_expected_secret(GetSecret()); lock_handler_->set_expected_secret(GetSecret());
......
...@@ -392,8 +392,7 @@ void EasyUnlockService::AttemptAuth(const AccountId& account_id) { ...@@ -392,8 +392,7 @@ void EasyUnlockService::AttemptAuth(const AccountId& account_id) {
<< "Check failed: " << GetAccountId().Serialize() << " vs " << "Check failed: " << GetAccountId().Serialize() << " vs "
<< account_id.Serialize(); << account_id.Serialize();
auth_attempt_.reset(new EasyUnlockAuthAttempt(app_manager_.get(), account_id, auth_attempt_.reset(new EasyUnlockAuthAttempt(account_id, auth_attempt_type));
auth_attempt_type));
if (!auth_attempt_->Start()) if (!auth_attempt_->Start())
auth_attempt_.reset(); auth_attempt_.reset();
......
...@@ -110,11 +110,6 @@ class TestAppManager : public EasyUnlockAppManager { ...@@ -110,11 +110,6 @@ class TestAppManager : public EasyUnlockAppManager {
state_ = STATE_DISABLED; state_ = STATE_DISABLED;
} }
bool SendAuthAttemptEvent() override {
ADD_FAILURE() << "Not reached.";
return false;
}
private: private:
// The current app state. // The current app state.
State state_; State state_;
......
...@@ -22,34 +22,6 @@ namespace extensions { ...@@ -22,34 +22,6 @@ namespace extensions {
namespace screenlock = api::screenlock_private; namespace screenlock = api::screenlock_private;
namespace {
screenlock::AuthType FromLockHandlerAuthType(
proximity_auth::mojom::AuthType auth_type) {
switch (auth_type) {
case proximity_auth::mojom::AuthType::OFFLINE_PASSWORD:
return screenlock::AUTH_TYPE_OFFLINEPASSWORD;
case proximity_auth::mojom::AuthType::NUMERIC_PIN:
return screenlock::AUTH_TYPE_NUMERICPIN;
case proximity_auth::mojom::AuthType::USER_CLICK:
return screenlock::AUTH_TYPE_USERCLICK;
case proximity_auth::mojom::AuthType::ONLINE_SIGN_IN:
// Apps should treat forced online sign in same as system password.
return screenlock::AUTH_TYPE_OFFLINEPASSWORD;
case proximity_auth::mojom::AuthType::EXPAND_THEN_USER_CLICK:
// This type is used for public sessions, which do not support screen
// locking.
NOTREACHED();
return screenlock::AUTH_TYPE_NONE;
case proximity_auth::mojom::AuthType::FORCE_OFFLINE_PASSWORD:
return screenlock::AUTH_TYPE_OFFLINEPASSWORD;
}
NOTREACHED();
return screenlock::AUTH_TYPE_OFFLINEPASSWORD;
}
} // namespace
ScreenlockPrivateGetLockedFunction::ScreenlockPrivateGetLockedFunction() {} ScreenlockPrivateGetLockedFunction::ScreenlockPrivateGetLockedFunction() {}
ScreenlockPrivateGetLockedFunction::~ScreenlockPrivateGetLockedFunction() {} ScreenlockPrivateGetLockedFunction::~ScreenlockPrivateGetLockedFunction() {}
...@@ -151,23 +123,4 @@ ScreenlockPrivateEventRouter::GetFactoryInstance() { ...@@ -151,23 +123,4 @@ ScreenlockPrivateEventRouter::GetFactoryInstance() {
void ScreenlockPrivateEventRouter::Shutdown() { void ScreenlockPrivateEventRouter::Shutdown() {
proximity_auth::ScreenlockBridge::Get()->RemoveObserver(this); proximity_auth::ScreenlockBridge::Get()->RemoveObserver(this);
} }
bool ScreenlockPrivateEventRouter::OnAuthAttempted(
proximity_auth::mojom::AuthType auth_type,
const std::string& value) {
EventRouter* router = EventRouter::Get(browser_context_);
if (!router->HasEventListener(screenlock::OnAuthAttempted::kEventName))
return false;
std::unique_ptr<base::ListValue> args(new base::ListValue());
args->AppendString(screenlock::ToString(FromLockHandlerAuthType(auth_type)));
args->AppendString(value);
std::unique_ptr<Event> event(
new Event(events::SCREENLOCK_PRIVATE_ON_AUTH_ATTEMPTED,
screenlock::OnAuthAttempted::kEventName, std::move(args)));
router->BroadcastEvent(std::move(event));
return true;
}
} // namespace extensions } // namespace extensions
...@@ -60,9 +60,6 @@ class ScreenlockPrivateEventRouter ...@@ -60,9 +60,6 @@ class ScreenlockPrivateEventRouter
explicit ScreenlockPrivateEventRouter(content::BrowserContext* context); explicit ScreenlockPrivateEventRouter(content::BrowserContext* context);
~ScreenlockPrivateEventRouter() override; ~ScreenlockPrivateEventRouter() override;
bool OnAuthAttempted(proximity_auth::mojom::AuthType auth_type,
const std::string& value);
// BrowserContextKeyedAPI // BrowserContextKeyedAPI
static BrowserContextKeyedAPIFactory<ScreenlockPrivateEventRouter>* static BrowserContextKeyedAPIFactory<ScreenlockPrivateEventRouter>*
GetFactoryInstance(); GetFactoryInstance();
......
...@@ -113,10 +113,6 @@ IN_PROC_BROWSER_TEST_F(ScreenlockPrivateApiTest, MAYBE_LockUnlock) { ...@@ -113,10 +113,6 @@ IN_PROC_BROWSER_TEST_F(ScreenlockPrivateApiTest, MAYBE_LockUnlock) {
RunTest("screenlock_private/lock_unlock"); RunTest("screenlock_private/lock_unlock");
} }
IN_PROC_BROWSER_TEST_F(ScreenlockPrivateApiTest, AuthType) {
RunTest("screenlock_private/auth_type");
}
#endif // defined(OS_CHROMEOS) #endif // defined(OS_CHROMEOS)
} // namespace extensions } // namespace extensions
...@@ -33,11 +33,5 @@ namespace screenlockPrivate { ...@@ -33,11 +33,5 @@ namespace screenlockPrivate {
interface Events { interface Events {
// Fires whenever the screen is locked or unlocked. // Fires whenever the screen is locked or unlocked.
static void onChanged(boolean locked); static void onChanged(boolean locked);
// Fires when the user attempts to authenticate with the user's input.
// There will be at most one auth attempt active at any time.
// Call $(ref:acceptAuthAttempt)() to accept or reject this attempt.
// Note: Some authentication types will not have an input.
static void onAuthAttempted(AuthType type, DOMString input);
}; };
}; };
{"name":"screenlockPrivate API test for setting auth type",
"description":"screenlockPrivate API test",
"key":"MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAzw6Jj8oWCVA+04YVfiKl5Gq1eAhEfLoIUopf1JEohsAxOjR6DUq1RM5KHy+uepgFrvv3/t2GaMPhKZ4JA+S1nHQhOhCCf6DBEZyAeHVIqMPJVDovOO5xgzIJjbthaBN/P08jxVqvWiy6rGhjTwtS8Bl98LgSFlbezvlYE1qVwGyQ9mgUjw0Wv1+qi+yWQ5jSVmZisy/zy2AiMqu6dcQjp9cdmkuo5d+0o+a5yVzwfhuRfxEL2xhDvzVLwL/Y1s6IJj+FLirZ5K/SBZBhWRsqQ4aYbTFQge+KIVJflBpcRDpxxYaCbdnlzfBhRSCFV7X52KF0TyFJSsuKjFFpAQawGwIDAQAB",
"version":"1",
"manifest_version":2,
"permissions":["screenlockPrivate"],
"app":{"background":{"scripts":["test.js"]}}}
// Copyright 2014 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.
var authAttempted = false;
chrome.screenlockPrivate.onChanged.addListener(function(locked) {
if (locked && !authAttempted) {
chrome.test.sendMessage('attemptClickAuth');
} else if (!locked && authAttempted) {
chrome.test.succeed();
} else {
var action = locked ? "lock" : "unlock";
chrome.test.fail('Unexpected ' + action);
}
});
chrome.screenlockPrivate.onAuthAttempted.addListener(function(authType, input) {
chrome.test.assertEq('userClick', authType);
authAttempted = true;
chrome.screenlockPrivate.acceptAuthAttempt(true);
});
chrome.test.runTests([
function testAuthType() {
chrome.screenlockPrivate.setLocked(true);
}
]);
...@@ -359,7 +359,7 @@ enum HistogramValue { ...@@ -359,7 +359,7 @@ enum HistogramValue {
CAST_CHANNEL_ON_MESSAGE = 338, CAST_CHANNEL_ON_MESSAGE = 338,
CAST_CHANNEL_ON_ERROR = 339, CAST_CHANNEL_ON_ERROR = 339,
SCREENLOCK_PRIVATE_ON_CHANGED = 340, SCREENLOCK_PRIVATE_ON_CHANGED = 340,
SCREENLOCK_PRIVATE_ON_AUTH_ATTEMPTED = 341, DELETED_SCREENLOCK_PRIVATE_ON_AUTH_ATTEMPTED = 341,
TYPES_CHROME_SETTING_ON_CHANGE = 342, TYPES_CHROME_SETTING_ON_CHANGE = 342,
DELETED_TYPES_PRIVATE_CHROME_DIRECT_SETTING_ON_CHANGE = 343, DELETED_TYPES_PRIVATE_CHROME_DIRECT_SETTING_ON_CHANGE = 343,
WEB_VIEW_INTERNAL_ON_MESSAGE = 344, WEB_VIEW_INTERNAL_ON_MESSAGE = 344,
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment