Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | |
| 2 // Use of this source code is governed by a BSD-style license that can be | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #include "components/password_manager/content/common/credential_manager_messages .h" | |
| 6 #include "components/password_manager/content/renderer/credential_manager_dispat cher.h" | |
| 7 #include "components/password_manager/content/renderer/test_credential_manager_d ispatcher.h" | |
| 8 #include "content/public/test/mock_render_thread.h" | |
| 9 #include "content/test/blink_test_environment.h" | |
| 10 #include "ipc/ipc_test_sink.h" | |
| 11 #include "testing/gtest/include/gtest/gtest.h" | |
| 12 #include "third_party/WebKit/public/platform/WebCredential.h" | |
| 13 #include "third_party/WebKit/public/platform/WebCredentialManager.h" | |
| 14 | |
| 15 namespace password_manager { | |
| 16 | |
| 17 class CredentialManagerDispatcherTest : public testing::Test { | |
| 18 public: | |
| 19 CredentialManagerDispatcherTest() {} | |
| 20 | |
| 21 virtual ~CredentialManagerDispatcherTest() {} | |
| 22 | |
| 23 static void SetUpTestCase() { content::SetUpBlinkTestEnvironment(); } | |
| 24 | |
| 25 static void TearDownTestCase() { content::TearDownBlinkTestEnvironment(); } | |
| 26 | |
| 27 virtual void SetUp() OVERRIDE { | |
| 28 testing::Test::SetUp(); | |
|
Ilya Sherman
2014/08/19 23:55:53
Is this not empty? It's surprising to see this ca
Mike West
2014/08/20 13:17:20
Done.
| |
| 29 render_thread_.reset(new content::MockRenderThread()); | |
| 30 dispatcher_.reset(new TestCredentialManagerDispatcher()); | |
|
Ilya Sherman
2014/08/19 23:55:53
Why not do this in the constructor?
Mike West
2014/08/20 13:17:20
Why not indeed! I think this might cause some prob
| |
| 31 } | |
| 32 | |
| 33 virtual void TearDown() OVERRIDE { | |
| 34 dispatcher_.reset(); | |
| 35 render_thread_.reset(); | |
|
Ilya Sherman
2014/08/19 23:55:53
If this happens (automatically) in the destructor,
Mike West
2014/08/20 13:17:20
Let's find out!
| |
| 36 } | |
| 37 | |
| 38 TestCredentialManagerDispatcher* dispatcher() { return dispatcher_.get(); } | |
|
Ilya Sherman
2014/08/19 23:55:53
nit: What code is this exposed for? |dispatcher_|
Mike West
2014/08/20 13:17:20
Done.
| |
| 39 | |
| 40 IPC::TestSink& sink() { return render_thread_->sink(); } | |
| 41 | |
| 42 // Searches for a |message_id| message in the queue of sent IPC messages. If | |
| 43 // none is present, returns NULL, otherwise returns the message. Clears queue | |
| 44 // of sent messages upon return. | |
| 45 const IPC::Message* GetMessage(uint32 messageID) { | |
|
Ilya Sherman
2014/08/19 23:55:53
nit: hacker_case
Mike West
2014/08/20 13:17:20
Done.
| |
| 46 const IPC::Message* message = sink().GetFirstMessageMatching(messageID); | |
| 47 sink().ClearMessages(); | |
| 48 return message; | |
| 49 } | |
| 50 | |
| 51 protected: | |
| 52 scoped_ptr<content::MockRenderThread> render_thread_; | |
| 53 scoped_ptr<TestCredentialManagerDispatcher> dispatcher_; | |
| 54 | |
| 55 DISALLOW_COPY_AND_ASSIGN(CredentialManagerDispatcherTest); | |
| 56 }; | |
| 57 | |
| 58 TEST_F(CredentialManagerDispatcherTest, SendNotifyFailedSignIn) { | |
| 59 EXPECT_FALSE(!!GetMessage(CredentialManagerHostMsg_NotifyFailedSignIn::ID)); | |
| 60 EXPECT_TRUE(dispatcher()->failed_sign_in_map()->IsEmpty()); | |
|
Ilya Sherman
2014/08/19 23:55:53
Can you avoid accessing the internal state of the
Mike West
2014/08/20 13:17:20
I've restructured this to have the class expose mo
| |
| 61 | |
| 62 blink::WebCredential credential( | |
| 63 "id", "user", GURL("https://example.com/img.png")); | |
| 64 scoped_ptr<blink::WebCredentialManager::NotificationCallbacks> callbacks( | |
| 65 new blink::WebCredentialManager::NotificationCallbacks()); | |
| 66 dispatcher()->dispatchFailedSignIn(credential, callbacks.release()); | |
| 67 | |
| 68 EXPECT_TRUE(!!GetMessage(CredentialManagerHostMsg_NotifyFailedSignIn::ID)); | |
| 69 EXPECT_EQ(1UL, dispatcher()->failed_sign_in_map()->size()); | |
| 70 } | |
| 71 | |
| 72 TEST_F(CredentialManagerDispatcherTest, SendNotifySignedIn) { | |
| 73 EXPECT_FALSE(!!GetMessage(CredentialManagerHostMsg_NotifySignedIn::ID)); | |
| 74 EXPECT_TRUE(dispatcher()->signed_in_map()->IsEmpty()); | |
| 75 | |
| 76 blink::WebCredential credential( | |
| 77 "id", "user", GURL("https://example.com/img.png")); | |
| 78 scoped_ptr<blink::WebCredentialManager::NotificationCallbacks> callbacks( | |
| 79 new blink::WebCredentialManager::NotificationCallbacks()); | |
| 80 dispatcher()->dispatchSignedIn(credential, callbacks.release()); | |
| 81 | |
| 82 EXPECT_TRUE(!!GetMessage(CredentialManagerHostMsg_NotifySignedIn::ID)); | |
| 83 EXPECT_EQ(1UL, dispatcher()->signed_in_map()->size()); | |
| 84 } | |
| 85 | |
| 86 TEST_F(CredentialManagerDispatcherTest, SendNotifySignedOut) { | |
| 87 EXPECT_FALSE(!!GetMessage(CredentialManagerHostMsg_NotifySignedOut::ID)); | |
| 88 EXPECT_TRUE(dispatcher()->signed_out_map()->IsEmpty()); | |
| 89 | |
| 90 scoped_ptr<blink::WebCredentialManager::NotificationCallbacks> callbacks( | |
| 91 new blink::WebCredentialManager::NotificationCallbacks()); | |
| 92 dispatcher()->dispatchSignedOut(callbacks.release()); | |
| 93 | |
| 94 EXPECT_TRUE(!!GetMessage(CredentialManagerHostMsg_NotifySignedOut::ID)); | |
| 95 EXPECT_EQ(1UL, dispatcher()->signed_out_map()->size()); | |
| 96 } | |
| 97 | |
| 98 TEST_F(CredentialManagerDispatcherTest, SendRequestCredential) { | |
| 99 EXPECT_FALSE(!!GetMessage(CredentialManagerHostMsg_RequestCredentials::ID)); | |
| 100 EXPECT_TRUE(dispatcher()->request_credentials_map()->IsEmpty()); | |
| 101 | |
| 102 scoped_ptr<blink::WebCredentialManager::RequestCallbacks> callbacks( | |
| 103 new blink::WebCredentialManager::RequestCallbacks()); | |
| 104 std::vector<GURL> federations; | |
| 105 dispatcher()->dispatchRequest(false, federations, callbacks.release()); | |
| 106 | |
| 107 EXPECT_TRUE(!!GetMessage(CredentialManagerHostMsg_RequestCredentials::ID)); | |
| 108 EXPECT_EQ(1UL, dispatcher()->request_credentials_map()->size()); | |
| 109 } | |
| 110 | |
| 111 } // namespace password_manager | |
| OLD | NEW |