OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include <deque> | 5 #include <deque> |
6 | 6 |
7 #include "content/browser/child_process_security_policy_impl.h" | 7 #include "content/browser/child_process_security_policy_impl.h" |
8 #include "content/browser/media/webrtc_identity_store.h" | 8 #include "content/browser/media/webrtc_identity_store.h" |
9 #include "content/browser/renderer_host/media/webrtc_identity_service_host.h" | 9 #include "content/browser/renderer_host/media/webrtc_identity_service_host.h" |
10 #include "content/common/media/webrtc_identity_messages.h" | 10 #include "content/common/media/webrtc_identity_messages.h" |
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
66 ChildProcessSecurityPolicyImpl::GetInstance(); | 66 ChildProcessSecurityPolicyImpl::GetInstance(); |
67 policy->Add(FAKE_RENDERER_ID); | 67 policy->Add(FAKE_RENDERER_ID); |
68 } | 68 } |
69 | 69 |
70 virtual bool Send(IPC::Message* message) OVERRIDE { | 70 virtual bool Send(IPC::Message* message) OVERRIDE { |
71 messages_.push_back(*message); | 71 messages_.push_back(*message); |
72 delete message; | 72 delete message; |
73 return true; | 73 return true; |
74 } | 74 } |
75 | 75 |
76 virtual bool OnMessageReceived(const IPC::Message& message, | 76 virtual bool OnMessageReceived(const IPC::Message& message) OVERRIDE { |
77 bool* message_was_ok) OVERRIDE { | 77 return WebRTCIdentityServiceHost::OnMessageReceived(message); |
78 return WebRTCIdentityServiceHost::OnMessageReceived(message, | |
79 message_was_ok); | |
80 } | 78 } |
81 | 79 |
82 IPC::Message GetLastMessage() { return messages_.back(); } | 80 IPC::Message GetLastMessage() { return messages_.back(); } |
83 | 81 |
84 int GetNumberOfMessages() { return messages_.size(); } | 82 int GetNumberOfMessages() { return messages_.size(); } |
85 | 83 |
86 void ClearMessages() { messages_.clear(); } | 84 void ClearMessages() { messages_.clear(); } |
87 | 85 |
88 private: | 86 private: |
89 virtual ~WebRTCIdentityServiceHostForTest() { | 87 virtual ~WebRTCIdentityServiceHostForTest() { |
90 ChildProcessSecurityPolicyImpl* policy = | 88 ChildProcessSecurityPolicyImpl* policy = |
91 ChildProcessSecurityPolicyImpl::GetInstance(); | 89 ChildProcessSecurityPolicyImpl::GetInstance(); |
92 policy->Remove(FAKE_RENDERER_ID); | 90 policy->Remove(FAKE_RENDERER_ID); |
93 } | 91 } |
94 | 92 |
95 std::deque<IPC::Message> messages_; | 93 std::deque<IPC::Message> messages_; |
96 }; | 94 }; |
97 | 95 |
98 class WebRTCIdentityServiceHostTest : public ::testing::Test { | 96 class WebRTCIdentityServiceHostTest : public ::testing::Test { |
99 public: | 97 public: |
100 WebRTCIdentityServiceHostTest() | 98 WebRTCIdentityServiceHostTest() |
101 : browser_thread_bundle_(TestBrowserThreadBundle::IO_MAINLOOP), | 99 : browser_thread_bundle_(TestBrowserThreadBundle::IO_MAINLOOP), |
102 store_(new MockWebRTCIdentityStore()), | 100 store_(new MockWebRTCIdentityStore()), |
103 host_(new WebRTCIdentityServiceHostForTest(store_.get())) {} | 101 host_(new WebRTCIdentityServiceHostForTest(store_.get())) {} |
104 | 102 |
105 void SendRequestToHost() { | 103 void SendRequestToHost() { |
106 bool ok; | |
107 host_->OnMessageReceived( | 104 host_->OnMessageReceived( |
108 WebRTCIdentityMsg_RequestIdentity(FAKE_SEQUENCE_NUMBER, | 105 WebRTCIdentityMsg_RequestIdentity(FAKE_SEQUENCE_NUMBER, |
109 GURL(FAKE_ORIGIN), | 106 GURL(FAKE_ORIGIN), |
110 FAKE_IDENTITY_NAME, | 107 FAKE_IDENTITY_NAME, |
111 FAKE_COMMON_NAME), | 108 FAKE_COMMON_NAME)); |
112 &ok); | |
113 ASSERT_TRUE(ok); | |
114 } | 109 } |
115 | 110 |
116 void SendCancelRequestToHost() { | 111 void SendCancelRequestToHost() { |
117 bool ok; | 112 host_->OnMessageReceived(WebRTCIdentityMsg_CancelRequest()); |
118 host_->OnMessageReceived(WebRTCIdentityMsg_CancelRequest(), &ok); | |
119 ASSERT_TRUE(ok); | |
120 } | 113 } |
121 | 114 |
122 void VerifyRequestFailedMessage(int error) { | 115 void VerifyRequestFailedMessage(int error) { |
123 EXPECT_EQ(1, host_->GetNumberOfMessages()); | 116 EXPECT_EQ(1, host_->GetNumberOfMessages()); |
124 IPC::Message ipc = host_->GetLastMessage(); | 117 IPC::Message ipc = host_->GetLastMessage(); |
125 EXPECT_EQ(ipc.type(), WebRTCIdentityHostMsg_RequestFailed::ID); | 118 EXPECT_EQ(ipc.type(), WebRTCIdentityHostMsg_RequestFailed::ID); |
126 | 119 |
127 Tuple2<int, int> error_in_message; | 120 Tuple2<int, int> error_in_message; |
128 WebRTCIdentityHostMsg_RequestFailed::Read(&ipc, &error_in_message); | 121 WebRTCIdentityHostMsg_RequestFailed::Read(&ipc, &error_in_message); |
129 EXPECT_EQ(FAKE_SEQUENCE_NUMBER, error_in_message.a); | 122 EXPECT_EQ(FAKE_SEQUENCE_NUMBER, error_in_message.a); |
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
189 } | 182 } |
190 | 183 |
191 // Verifies that we do not crash if we try to cancel a completed request. | 184 // Verifies that we do not crash if we try to cancel a completed request. |
192 TEST_F(WebRTCIdentityServiceHostTest, TestCancelAfterRequestCompleted) { | 185 TEST_F(WebRTCIdentityServiceHostTest, TestCancelAfterRequestCompleted) { |
193 SendRequestToHost(); | 186 SendRequestToHost(); |
194 store_->RunCompletionCallback(net::OK, FAKE_CERTIFICATE, FAKE_PRIVATE_KEY); | 187 store_->RunCompletionCallback(net::OK, FAKE_CERTIFICATE, FAKE_PRIVATE_KEY); |
195 SendCancelRequestToHost(); | 188 SendCancelRequestToHost(); |
196 } | 189 } |
197 | 190 |
198 } // namespace content | 191 } // namespace content |
OLD | NEW |