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_client .h" | |
7 #include "components/password_manager/content/renderer/test_credential_manager_c lient.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/WebCredentialManagerClient.h" | |
14 | |
15 namespace password_manager { | |
16 | |
17 class CredentialManagerClientTest : public testing::Test { | |
18 public: | |
19 CredentialManagerClientTest() { | |
20 render_thread_.reset(new content::MockRenderThread()); | |
21 dispatcher_.reset(new TestCredentialManagerClient()); | |
Ilya Sherman
2014/08/21 00:11:21
nit: From the constructor, you can initialize thes
| |
22 } | |
23 | |
24 virtual ~CredentialManagerClientTest() {} | |
25 | |
26 static void SetUpTestCase() { content::SetUpBlinkTestEnvironment(); } | |
27 | |
28 static void TearDownTestCase() { content::TearDownBlinkTestEnvironment(); } | |
29 | |
30 IPC::TestSink& sink() { return render_thread_->sink(); } | |
31 | |
32 // Searches for a |message_id| message in the queue of sent IPC messages. If | |
33 // none is present, returns NULL, otherwise returns the message. Clears queue | |
34 // of sent messages upon return. | |
35 const IPC::Message* GetMessage(uint32 message_id) { | |
36 const IPC::Message* message = sink().GetFirstMessageMatching(message_id); | |
37 sink().ClearMessages(); | |
38 return message; | |
39 } | |
40 | |
41 protected: | |
42 scoped_ptr<content::MockRenderThread> render_thread_; | |
43 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.
| |
44 | |
45 DISALLOW_COPY_AND_ASSIGN(CredentialManagerClientTest); | |
46 }; | |
47 | |
48 TEST_F(CredentialManagerClientTest, SendNotifyFailedSignIn) { | |
49 EXPECT_FALSE(!!GetMessage(CredentialManagerHostMsg_NotifyFailedSignIn::ID)); | |
50 EXPECT_FALSE(dispatcher_->FailedSignInCallbacksWaiting()); | |
51 | |
52 blink::WebCredential credential( | |
53 "id", "user", GURL("https://example.com/img.png")); | |
54 scoped_ptr<blink::WebCredentialManagerClient::NotificationCallbacks> | |
55 callbacks(new blink::WebCredentialManagerClient::NotificationCallbacks()); | |
56 dispatcher_->dispatchFailedSignIn(credential, callbacks.release()); | |
57 | |
58 EXPECT_TRUE(!!GetMessage(CredentialManagerHostMsg_NotifyFailedSignIn::ID)); | |
59 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.
| |
60 } | |
61 | |
62 TEST_F(CredentialManagerClientTest, SendNotifySignedIn) { | |
63 EXPECT_FALSE(!!GetMessage(CredentialManagerHostMsg_NotifySignedIn::ID)); | |
64 EXPECT_FALSE(dispatcher_->SignedInCallbacksWaiting()); | |
65 | |
66 blink::WebCredential credential( | |
67 "id", "user", GURL("https://example.com/img.png")); | |
68 scoped_ptr<blink::WebCredentialManagerClient::NotificationCallbacks> | |
69 callbacks(new blink::WebCredentialManagerClient::NotificationCallbacks()); | |
70 dispatcher_->dispatchSignedIn(credential, callbacks.release()); | |
71 | |
72 EXPECT_TRUE(!!GetMessage(CredentialManagerHostMsg_NotifySignedIn::ID)); | |
73 EXPECT_TRUE(dispatcher_->SignedInCallbacksWaiting()); | |
74 } | |
75 | |
76 TEST_F(CredentialManagerClientTest, SendNotifySignedOut) { | |
77 EXPECT_FALSE(!!GetMessage(CredentialManagerHostMsg_NotifySignedOut::ID)); | |
78 EXPECT_FALSE(dispatcher_->SignedOutCallbacksWaiting()); | |
79 | |
80 scoped_ptr<blink::WebCredentialManagerClient::NotificationCallbacks> | |
81 callbacks(new blink::WebCredentialManagerClient::NotificationCallbacks()); | |
82 dispatcher_->dispatchSignedOut(callbacks.release()); | |
83 | |
84 EXPECT_TRUE(!!GetMessage(CredentialManagerHostMsg_NotifySignedOut::ID)); | |
85 EXPECT_TRUE(dispatcher_->SignedOutCallbacksWaiting()); | |
86 } | |
87 | |
88 TEST_F(CredentialManagerClientTest, SendRequestCredential) { | |
89 EXPECT_FALSE(!!GetMessage(CredentialManagerHostMsg_RequestCredential::ID)); | |
90 EXPECT_FALSE(dispatcher_->RequestCallbacksWaiting()); | |
91 | |
92 scoped_ptr<blink::WebCredentialManagerClient::RequestCallbacks> callbacks( | |
93 new blink::WebCredentialManagerClient::RequestCallbacks()); | |
94 std::vector<GURL> federations; | |
95 dispatcher_->dispatchRequest(false, federations, callbacks.release()); | |
96 | |
97 EXPECT_TRUE(!!GetMessage(CredentialManagerHostMsg_RequestCredential::ID)); | |
98 EXPECT_TRUE(dispatcher_->RequestCallbacksWaiting()); | |
99 } | |
100 | |
101 } // namespace password_manager | |
OLD | NEW |