Chromium Code Reviews| Index: components/password_manager/content/renderer/credential_manager_client_unittest.cc |
| diff --git a/components/password_manager/content/renderer/credential_manager_client_unittest.cc b/components/password_manager/content/renderer/credential_manager_client_unittest.cc |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..c66601c419d9ebd152c851cfce60f4bfb4fb516d |
| --- /dev/null |
| +++ b/components/password_manager/content/renderer/credential_manager_client_unittest.cc |
| @@ -0,0 +1,101 @@ |
| +// 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. |
| + |
| +#include "components/password_manager/content/common/credential_manager_messages.h" |
| +#include "components/password_manager/content/renderer/credential_manager_client.h" |
| +#include "components/password_manager/content/renderer/test_credential_manager_client.h" |
| +#include "content/public/test/mock_render_thread.h" |
| +#include "content/test/blink_test_environment.h" |
| +#include "ipc/ipc_test_sink.h" |
| +#include "testing/gtest/include/gtest/gtest.h" |
| +#include "third_party/WebKit/public/platform/WebCredential.h" |
| +#include "third_party/WebKit/public/platform/WebCredentialManagerClient.h" |
| + |
| +namespace password_manager { |
| + |
| +class CredentialManagerClientTest : public testing::Test { |
| + public: |
| + CredentialManagerClientTest() { |
| + render_thread_.reset(new content::MockRenderThread()); |
| + dispatcher_.reset(new TestCredentialManagerClient()); |
|
Ilya Sherman
2014/08/21 00:11:21
nit: From the constructor, you can initialize thes
|
| + } |
| + |
| + virtual ~CredentialManagerClientTest() {} |
| + |
| + static void SetUpTestCase() { content::SetUpBlinkTestEnvironment(); } |
| + |
| + static void TearDownTestCase() { content::TearDownBlinkTestEnvironment(); } |
| + |
| + IPC::TestSink& sink() { return render_thread_->sink(); } |
| + |
| + // Searches for a |message_id| message in the queue of sent IPC messages. If |
| + // none is present, returns NULL, otherwise returns the message. Clears queue |
| + // of sent messages upon return. |
| + const IPC::Message* GetMessage(uint32 message_id) { |
| + const IPC::Message* message = sink().GetFirstMessageMatching(message_id); |
| + sink().ClearMessages(); |
| + return message; |
| + } |
| + |
| + protected: |
| + scoped_ptr<content::MockRenderThread> render_thread_; |
| + scoped_ptr<TestCredentialManagerClient> dispatcher_; |
|
Ilya Sherman
2014/08/21 00:11:21
nit: Please update this variable name.
Mike West
2014/08/21 10:20:47
Done.
|
| + |
| + DISALLOW_COPY_AND_ASSIGN(CredentialManagerClientTest); |
| +}; |
| + |
| +TEST_F(CredentialManagerClientTest, SendNotifyFailedSignIn) { |
| + EXPECT_FALSE(!!GetMessage(CredentialManagerHostMsg_NotifyFailedSignIn::ID)); |
| + EXPECT_FALSE(dispatcher_->FailedSignInCallbacksWaiting()); |
| + |
| + blink::WebCredential credential( |
| + "id", "user", GURL("https://example.com/img.png")); |
| + scoped_ptr<blink::WebCredentialManagerClient::NotificationCallbacks> |
| + callbacks(new blink::WebCredentialManagerClient::NotificationCallbacks()); |
| + dispatcher_->dispatchFailedSignIn(credential, callbacks.release()); |
| + |
| + EXPECT_TRUE(!!GetMessage(CredentialManagerHostMsg_NotifyFailedSignIn::ID)); |
| + EXPECT_TRUE(dispatcher_->FailedSignInCallbacksWaiting()); |
|
Ilya Sherman
2014/08/21 00:11:21
It seems like you could test this more directly by
Mike West
2014/08/21 10:20:47
I'll try to put something like that together.
|
| +} |
| + |
| +TEST_F(CredentialManagerClientTest, SendNotifySignedIn) { |
| + EXPECT_FALSE(!!GetMessage(CredentialManagerHostMsg_NotifySignedIn::ID)); |
| + EXPECT_FALSE(dispatcher_->SignedInCallbacksWaiting()); |
| + |
| + blink::WebCredential credential( |
| + "id", "user", GURL("https://example.com/img.png")); |
| + scoped_ptr<blink::WebCredentialManagerClient::NotificationCallbacks> |
| + callbacks(new blink::WebCredentialManagerClient::NotificationCallbacks()); |
| + dispatcher_->dispatchSignedIn(credential, callbacks.release()); |
| + |
| + EXPECT_TRUE(!!GetMessage(CredentialManagerHostMsg_NotifySignedIn::ID)); |
| + EXPECT_TRUE(dispatcher_->SignedInCallbacksWaiting()); |
| +} |
| + |
| +TEST_F(CredentialManagerClientTest, SendNotifySignedOut) { |
| + EXPECT_FALSE(!!GetMessage(CredentialManagerHostMsg_NotifySignedOut::ID)); |
| + EXPECT_FALSE(dispatcher_->SignedOutCallbacksWaiting()); |
| + |
| + scoped_ptr<blink::WebCredentialManagerClient::NotificationCallbacks> |
| + callbacks(new blink::WebCredentialManagerClient::NotificationCallbacks()); |
| + dispatcher_->dispatchSignedOut(callbacks.release()); |
| + |
| + EXPECT_TRUE(!!GetMessage(CredentialManagerHostMsg_NotifySignedOut::ID)); |
| + EXPECT_TRUE(dispatcher_->SignedOutCallbacksWaiting()); |
| +} |
| + |
| +TEST_F(CredentialManagerClientTest, SendRequestCredential) { |
| + EXPECT_FALSE(!!GetMessage(CredentialManagerHostMsg_RequestCredential::ID)); |
| + EXPECT_FALSE(dispatcher_->RequestCallbacksWaiting()); |
| + |
| + scoped_ptr<blink::WebCredentialManagerClient::RequestCallbacks> callbacks( |
| + new blink::WebCredentialManagerClient::RequestCallbacks()); |
| + std::vector<GURL> federations; |
| + dispatcher_->dispatchRequest(false, federations, callbacks.release()); |
| + |
| + EXPECT_TRUE(!!GetMessage(CredentialManagerHostMsg_RequestCredential::ID)); |
| + EXPECT_TRUE(dispatcher_->RequestCallbacksWaiting()); |
| +} |
| + |
| +} // namespace password_manager |