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 11 matching lines...) Expand all Loading... |
22 const char FAKE_COMMON_NAME[] = "fake common name"; | 22 const char FAKE_COMMON_NAME[] = "fake common name"; |
23 const char FAKE_CERTIFICATE[] = "fake cert"; | 23 const char FAKE_CERTIFICATE[] = "fake cert"; |
24 const char FAKE_PRIVATE_KEY[] = "fake private key"; | 24 const char FAKE_PRIVATE_KEY[] = "fake private key"; |
25 const int FAKE_RENDERER_ID = 10; | 25 const int FAKE_RENDERER_ID = 10; |
26 const int FAKE_SEQUENCE_NUMBER = 1; | 26 const int FAKE_SEQUENCE_NUMBER = 1; |
27 | 27 |
28 class MockWebRTCIdentityStore : public WebRTCIdentityStore { | 28 class MockWebRTCIdentityStore : public WebRTCIdentityStore { |
29 public: | 29 public: |
30 MockWebRTCIdentityStore() : WebRTCIdentityStore(base::FilePath(), NULL) {} | 30 MockWebRTCIdentityStore() : WebRTCIdentityStore(base::FilePath(), NULL) {} |
31 | 31 |
32 virtual base::Closure RequestIdentity( | 32 base::Closure RequestIdentity(const GURL& origin, |
33 const GURL& origin, | 33 const std::string& identity_name, |
34 const std::string& identity_name, | 34 const std::string& common_name, |
35 const std::string& common_name, | 35 const CompletionCallback& callback) override { |
36 const CompletionCallback& callback) override { | |
37 EXPECT_TRUE(callback_.is_null()); | 36 EXPECT_TRUE(callback_.is_null()); |
38 | 37 |
39 callback_ = callback; | 38 callback_ = callback; |
40 return base::Bind(&MockWebRTCIdentityStore::OnCancel, | 39 return base::Bind(&MockWebRTCIdentityStore::OnCancel, |
41 base::Unretained(this)); | 40 base::Unretained(this)); |
42 } | 41 } |
43 | 42 |
44 bool HasPendingRequest() const { return !callback_.is_null(); } | 43 bool HasPendingRequest() const { return !callback_.is_null(); } |
45 | 44 |
46 void RunCompletionCallback(int error, | 45 void RunCompletionCallback(int error, |
47 const std::string& cert, | 46 const std::string& cert, |
48 const std::string& key) { | 47 const std::string& key) { |
49 callback_.Run(error, cert, key); | 48 callback_.Run(error, cert, key); |
50 callback_.Reset(); | 49 callback_.Reset(); |
51 } | 50 } |
52 | 51 |
53 private: | 52 private: |
54 virtual ~MockWebRTCIdentityStore() {} | 53 ~MockWebRTCIdentityStore() override {} |
55 | 54 |
56 void OnCancel() { callback_.Reset(); } | 55 void OnCancel() { callback_.Reset(); } |
57 | 56 |
58 CompletionCallback callback_; | 57 CompletionCallback callback_; |
59 }; | 58 }; |
60 | 59 |
61 class WebRTCIdentityServiceHostForTest : public WebRTCIdentityServiceHost { | 60 class WebRTCIdentityServiceHostForTest : public WebRTCIdentityServiceHost { |
62 public: | 61 public: |
63 explicit WebRTCIdentityServiceHostForTest(WebRTCIdentityStore* identity_store) | 62 explicit WebRTCIdentityServiceHostForTest(WebRTCIdentityStore* identity_store) |
64 : WebRTCIdentityServiceHost(FAKE_RENDERER_ID, identity_store) { | 63 : WebRTCIdentityServiceHost(FAKE_RENDERER_ID, identity_store) { |
65 ChildProcessSecurityPolicyImpl* policy = | 64 ChildProcessSecurityPolicyImpl* policy = |
66 ChildProcessSecurityPolicyImpl::GetInstance(); | 65 ChildProcessSecurityPolicyImpl::GetInstance(); |
67 policy->Add(FAKE_RENDERER_ID); | 66 policy->Add(FAKE_RENDERER_ID); |
68 } | 67 } |
69 | 68 |
70 virtual bool Send(IPC::Message* message) override { | 69 bool Send(IPC::Message* message) override { |
71 messages_.push_back(*message); | 70 messages_.push_back(*message); |
72 delete message; | 71 delete message; |
73 return true; | 72 return true; |
74 } | 73 } |
75 | 74 |
76 virtual bool OnMessageReceived(const IPC::Message& message) override { | 75 bool OnMessageReceived(const IPC::Message& message) override { |
77 return WebRTCIdentityServiceHost::OnMessageReceived(message); | 76 return WebRTCIdentityServiceHost::OnMessageReceived(message); |
78 } | 77 } |
79 | 78 |
80 IPC::Message GetLastMessage() { return messages_.back(); } | 79 IPC::Message GetLastMessage() { return messages_.back(); } |
81 | 80 |
82 int GetNumberOfMessages() { return messages_.size(); } | 81 int GetNumberOfMessages() { return messages_.size(); } |
83 | 82 |
84 void ClearMessages() { messages_.clear(); } | 83 void ClearMessages() { messages_.clear(); } |
85 | 84 |
86 private: | 85 private: |
87 virtual ~WebRTCIdentityServiceHostForTest() { | 86 ~WebRTCIdentityServiceHostForTest() override { |
88 ChildProcessSecurityPolicyImpl* policy = | 87 ChildProcessSecurityPolicyImpl* policy = |
89 ChildProcessSecurityPolicyImpl::GetInstance(); | 88 ChildProcessSecurityPolicyImpl::GetInstance(); |
90 policy->Remove(FAKE_RENDERER_ID); | 89 policy->Remove(FAKE_RENDERER_ID); |
91 } | 90 } |
92 | 91 |
93 std::deque<IPC::Message> messages_; | 92 std::deque<IPC::Message> messages_; |
94 }; | 93 }; |
95 | 94 |
96 class WebRTCIdentityServiceHostTest : public ::testing::Test { | 95 class WebRTCIdentityServiceHostTest : public ::testing::Test { |
97 public: | 96 public: |
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
182 } | 181 } |
183 | 182 |
184 // Verifies that we do not crash if we try to cancel a completed request. | 183 // Verifies that we do not crash if we try to cancel a completed request. |
185 TEST_F(WebRTCIdentityServiceHostTest, TestCancelAfterRequestCompleted) { | 184 TEST_F(WebRTCIdentityServiceHostTest, TestCancelAfterRequestCompleted) { |
186 SendRequestToHost(); | 185 SendRequestToHost(); |
187 store_->RunCompletionCallback(net::OK, FAKE_CERTIFICATE, FAKE_PRIVATE_KEY); | 186 store_->RunCompletionCallback(net::OK, FAKE_CERTIFICATE, FAKE_PRIVATE_KEY); |
188 SendCancelRequestToHost(); | 187 SendCancelRequestToHost(); |
189 } | 188 } |
190 | 189 |
191 } // namespace content | 190 } // namespace content |
OLD | NEW |