Commit e8b7bb54 authored by mkwst's avatar mkwst Committed by Commit bot

Credential Manager: Stub out call to PasswordStore.

This CL changes the ContentCredentialManagerDispatcher implementation of
requesting credentials to pass the request through the PasswordStore. We
don't yet use the result; we just verify that the callback is called and
passes data around correctly. Baby steps.

BUG=400674

Review URL: https://codereview.chromium.org/615863002

Cr-Commit-Position: refs/heads/master@{#297404}
parent 4fff1990
...@@ -10,6 +10,7 @@ ...@@ -10,6 +10,7 @@
#include "components/password_manager/content/common/credential_manager_messages.h" #include "components/password_manager/content/common/credential_manager_messages.h"
#include "components/password_manager/content/common/credential_manager_types.h" #include "components/password_manager/content/common/credential_manager_types.h"
#include "components/password_manager/core/browser/password_manager_client.h" #include "components/password_manager/core/browser/password_manager_client.h"
#include "components/password_manager/core/browser/password_store.h"
#include "content/public/browser/render_view_host.h" #include "content/public/browser/render_view_host.h"
#include "content/public/browser/web_contents.h" #include "content/public/browser/web_contents.h"
#include "ipc/ipc_message_macros.h" #include "ipc/ipc_message_macros.h"
...@@ -20,7 +21,8 @@ ContentCredentialManagerDispatcher::ContentCredentialManagerDispatcher( ...@@ -20,7 +21,8 @@ ContentCredentialManagerDispatcher::ContentCredentialManagerDispatcher(
content::WebContents* web_contents, content::WebContents* web_contents,
PasswordManagerClient* client) PasswordManagerClient* client)
: WebContentsObserver(web_contents), : WebContentsObserver(web_contents),
client_(client) { client_(client),
pending_request_id_(0) {
DCHECK(web_contents); DCHECK(web_contents);
} }
...@@ -70,17 +72,44 @@ void ContentCredentialManagerDispatcher::OnNotifySignedOut(int request_id) { ...@@ -70,17 +72,44 @@ void ContentCredentialManagerDispatcher::OnNotifySignedOut(int request_id) {
void ContentCredentialManagerDispatcher::OnRequestCredential( void ContentCredentialManagerDispatcher::OnRequestCredential(
int request_id, int request_id,
bool zero_click_only, bool /* zero_click_only */,
const std::vector<GURL>& federations) { const std::vector<GURL>& federations) {
// TODO(mkwst): This is a stub. DCHECK(request_id);
PasswordStore* store = GetPasswordStore();
if (pending_request_id_ || !store) {
// TODO(mkwst): Reject the promise if we can't get to the password store, or
// if we're already requesting credentials.
}
pending_request_id_ = request_id;
autofill::PasswordForm form;
form.scheme = autofill::PasswordForm::SCHEME_HTML;
form.origin = web_contents()->GetLastCommittedURL().GetOrigin();
form.signon_realm = form.origin.spec();
store->GetLogins(form, PasswordStore::DISALLOW_PROMPT, this);
}
void ContentCredentialManagerDispatcher::OnGetPasswordStoreResults(
const std::vector<autofill::PasswordForm*>& results) {
DCHECK(pending_request_id_);
// TODO(mkwst): This is a stub. We should be looking at |results| here. Baby
// steps.
password_manager::CredentialInfo info(base::ASCIIToUTF16("id"), password_manager::CredentialInfo info(base::ASCIIToUTF16("id"),
base::ASCIIToUTF16("name"), base::ASCIIToUTF16("name"),
GURL("https://example.com/image.png")); GURL("https://example.com/image.png"));
web_contents()->GetRenderViewHost()->Send( web_contents()->GetRenderViewHost()->Send(
new CredentialManagerMsg_SendCredential( new CredentialManagerMsg_SendCredential(
web_contents()->GetRenderViewHost()->GetRoutingID(), web_contents()->GetRenderViewHost()->GetRoutingID(),
request_id, pending_request_id_,
info)); info));
pending_request_id_ = 0;
}
PasswordStore* ContentCredentialManagerDispatcher::GetPasswordStore() {
return client_ ? client_->GetPasswordStore() : nullptr;
} }
} // namespace password_manager } // namespace password_manager
...@@ -7,10 +7,15 @@ ...@@ -7,10 +7,15 @@
#include "base/macros.h" #include "base/macros.h"
#include "components/password_manager/core/browser/credential_manager_dispatcher.h" #include "components/password_manager/core/browser/credential_manager_dispatcher.h"
#include "components/password_manager/core/browser/password_store_consumer.h"
#include "content/public/browser/web_contents_observer.h" #include "content/public/browser/web_contents_observer.h"
class GURL; class GURL;
namespace autofill {
struct PasswordForm;
}
namespace content { namespace content {
class WebContents; class WebContents;
} }
...@@ -18,10 +23,12 @@ class WebContents; ...@@ -18,10 +23,12 @@ class WebContents;
namespace password_manager { namespace password_manager {
class PasswordManagerClient; class PasswordManagerClient;
class PasswordStore;
struct CredentialInfo; struct CredentialInfo;
class ContentCredentialManagerDispatcher : public CredentialManagerDispatcher, class ContentCredentialManagerDispatcher : public CredentialManagerDispatcher,
public content::WebContentsObserver { public content::WebContentsObserver,
public PasswordStoreConsumer {
public: public:
// |client| isn't yet used by this class, but is necessary for the next step: // |client| isn't yet used by this class, but is necessary for the next step:
// wiring this up as a subclass of PasswordStoreConsumer. // wiring this up as a subclass of PasswordStoreConsumer.
...@@ -42,12 +49,23 @@ class ContentCredentialManagerDispatcher : public CredentialManagerDispatcher, ...@@ -42,12 +49,23 @@ class ContentCredentialManagerDispatcher : public CredentialManagerDispatcher,
bool zero_click_only, bool zero_click_only,
const std::vector<GURL>& federations) OVERRIDE; const std::vector<GURL>& federations) OVERRIDE;
// content::WebContentsObserver overrides. // content::WebContentsObserver implementation.
virtual bool OnMessageReceived(const IPC::Message& message) OVERRIDE; virtual bool OnMessageReceived(const IPC::Message& message) OVERRIDE;
// PasswordStoreConsumer implementation.
virtual void OnGetPasswordStoreResults(
const std::vector<autofill::PasswordForm*>& results) OVERRIDE;
private: private:
PasswordStore* GetPasswordStore();
PasswordManagerClient* client_; PasswordManagerClient* client_;
// When 'OnRequestCredential' is called, it in turn calls out to the
// PasswordStore; we store the request ID here in order to properly respond
// to the request once the PasswordStore gives us data.
int pending_request_id_;
DISALLOW_COPY_AND_ASSIGN(ContentCredentialManagerDispatcher); DISALLOW_COPY_AND_ASSIGN(ContentCredentialManagerDispatcher);
}; };
......
...@@ -5,10 +5,13 @@ ...@@ -5,10 +5,13 @@
#include "components/password_manager/content/browser/content_credential_manager_dispatcher.h" #include "components/password_manager/content/browser/content_credential_manager_dispatcher.h"
#include "base/command_line.h" #include "base/command_line.h"
#include "base/run_loop.h"
#include "base/strings/string16.h" #include "base/strings/string16.h"
#include "base/strings/utf_string_conversions.h" #include "base/strings/utf_string_conversions.h"
#include "components/password_manager/content/common/credential_manager_messages.h" #include "components/password_manager/content/common/credential_manager_messages.h"
#include "components/password_manager/content/common/credential_manager_types.h" #include "components/password_manager/content/common/credential_manager_types.h"
#include "components/password_manager/core/browser/stub_password_manager_client.h"
#include "components/password_manager/core/browser/test_password_store.h"
#include "content/public/test/mock_render_process_host.h" #include "content/public/test/mock_render_process_host.h"
#include "content/public/test/test_renderer_host.h" #include "content/public/test/test_renderer_host.h"
#include "testing/gmock/include/gmock/gmock.h" #include "testing/gmock/include/gmock/gmock.h"
...@@ -22,6 +25,28 @@ namespace { ...@@ -22,6 +25,28 @@ namespace {
// Chosen by fair dice roll. Guaranteed to be random. // Chosen by fair dice roll. Guaranteed to be random.
const int kRequestId = 4; const int kRequestId = 4;
class TestPasswordManagerClient
: public password_manager::StubPasswordManagerClient {
public:
TestPasswordManagerClient(password_manager::PasswordStore* store)
: store_(store) {}
virtual ~TestPasswordManagerClient() {}
virtual password_manager::PasswordStore* GetPasswordStore() OVERRIDE {
return store_;
}
private:
password_manager::PasswordStore* store_;
};
void RunAllPendingTasks() {
base::RunLoop run_loop;
base::MessageLoop::current()->PostTask(
FROM_HERE, base::MessageLoop::QuitWhenIdleClosure());
run_loop.Run();
}
} // namespace } // namespace
namespace password_manager { namespace password_manager {
...@@ -33,14 +58,23 @@ class ContentCredentialManagerDispatcherTest ...@@ -33,14 +58,23 @@ class ContentCredentialManagerDispatcherTest
virtual void SetUp() OVERRIDE { virtual void SetUp() OVERRIDE {
content::RenderViewHostTestHarness::SetUp(); content::RenderViewHostTestHarness::SetUp();
store_ = new TestPasswordStore;
client_.reset(new TestPasswordManagerClient(store_.get()));
dispatcher_.reset( dispatcher_.reset(
new ContentCredentialManagerDispatcher(web_contents(), nullptr)); new ContentCredentialManagerDispatcher(web_contents(), client_.get()));
}
virtual void TearDown() OVERRIDE {
store_->Shutdown();
content::RenderViewHostTestHarness::TearDown();
} }
ContentCredentialManagerDispatcher* dispatcher() { return dispatcher_.get(); } ContentCredentialManagerDispatcher* dispatcher() { return dispatcher_.get(); }
private: private:
scoped_refptr<TestPasswordStore> store_;
scoped_ptr<ContentCredentialManagerDispatcher> dispatcher_; scoped_ptr<ContentCredentialManagerDispatcher> dispatcher_;
scoped_ptr<TestPasswordManagerClient> client_;
}; };
TEST_F(ContentCredentialManagerDispatcherTest, TEST_F(ContentCredentialManagerDispatcherTest,
...@@ -87,6 +121,8 @@ TEST_F(ContentCredentialManagerDispatcherTest, ...@@ -87,6 +121,8 @@ TEST_F(ContentCredentialManagerDispatcherTest,
std::vector<GURL> federations; std::vector<GURL> federations;
dispatcher()->OnRequestCredential(kRequestId, false, federations); dispatcher()->OnRequestCredential(kRequestId, false, federations);
RunAllPendingTasks();
const uint32 kMsgID = CredentialManagerMsg_SendCredential::ID; const uint32 kMsgID = CredentialManagerMsg_SendCredential::ID;
const IPC::Message* message = const IPC::Message* message =
process()->sink().GetFirstMessageMatching(kMsgID); process()->sink().GetFirstMessageMatching(kMsgID);
......
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