Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(27)

Side by Side Diff: remoting/host/register_support_host_request_unittest.cc

Issue 12316083: Move HostKeyPair into protocol::KeyPair. (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: Rebase Created 7 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « remoting/host/register_support_host_request.cc ('k') | remoting/host/remoting_me2me_host.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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 "remoting/host/register_support_host_request.h" 5 #include "remoting/host/register_support_host_request.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/memory/ref_counted.h" 8 #include "base/memory/ref_counted.h"
9 #include "base/message_loop.h" 9 #include "base/message_loop.h"
10 #include "base/observer_list.h" 10 #include "base/observer_list.h"
11 #include "base/string_number_conversions.h" 11 #include "base/string_number_conversions.h"
12 #include "remoting/base/constants.h" 12 #include "remoting/base/constants.h"
13 #include "remoting/host/host_key_pair.h" 13 #include "remoting/base/rsa_key_pair.h"
14 #include "remoting/base/test_rsa_key_pair.h"
14 #include "remoting/host/in_memory_host_config.h" 15 #include "remoting/host/in_memory_host_config.h"
15 #include "remoting/host/test_key_pair.h"
16 #include "remoting/jingle_glue/iq_sender.h" 16 #include "remoting/jingle_glue/iq_sender.h"
17 #include "remoting/jingle_glue/mock_objects.h" 17 #include "remoting/jingle_glue/mock_objects.h"
18 #include "testing/gmock/include/gmock/gmock.h" 18 #include "testing/gmock/include/gmock/gmock.h"
19 #include "testing/gtest/include/gtest/gtest.h" 19 #include "testing/gtest/include/gtest/gtest.h"
20 #include "third_party/libjingle/source/talk/xmllite/xmlelement.h" 20 #include "third_party/libjingle/source/talk/xmllite/xmlelement.h"
21 #include "third_party/libjingle/source/talk/xmpp/constants.h" 21 #include "third_party/libjingle/source/talk/xmpp/constants.h"
22 22
23 using buzz::QName; 23 using buzz::QName;
24 using buzz::XmlElement; 24 using buzz::XmlElement;
25 25
(...skipping 25 matching lines...) Expand all
51 MOCK_METHOD3(OnResponse, void(bool result, const std::string& support_id, 51 MOCK_METHOD3(OnResponse, void(bool result, const std::string& support_id,
52 const base::TimeDelta& lifetime)); 52 const base::TimeDelta& lifetime));
53 }; 53 };
54 54
55 } // namespace 55 } // namespace
56 56
57 class RegisterSupportHostRequestTest : public testing::Test { 57 class RegisterSupportHostRequestTest : public testing::Test {
58 public: 58 public:
59 protected: 59 protected:
60 virtual void SetUp() { 60 virtual void SetUp() {
61 ASSERT_TRUE(key_pair_.LoadFromString(kTestHostKeyPair)); 61 key_pair_ = RsaKeyPair::FromString(kTestRsaKeyPair);
62 ASSERT_TRUE(key_pair_);
62 63
63 EXPECT_CALL(signal_strategy_, AddListener(NotNull())) 64 EXPECT_CALL(signal_strategy_, AddListener(NotNull()))
64 .WillRepeatedly(AddListener(&signal_strategy_listeners_)); 65 .WillRepeatedly(AddListener(&signal_strategy_listeners_));
65 EXPECT_CALL(signal_strategy_, RemoveListener(NotNull())) 66 EXPECT_CALL(signal_strategy_, RemoveListener(NotNull()))
66 .WillRepeatedly(RemoveListener(&signal_strategy_listeners_)); 67 .WillRepeatedly(RemoveListener(&signal_strategy_listeners_));
67 EXPECT_CALL(signal_strategy_, GetLocalJid()) 68 EXPECT_CALL(signal_strategy_, GetLocalJid())
68 .WillRepeatedly(Return(kTestJid)); 69 .WillRepeatedly(Return(kTestJid));
69 } 70 }
70 71
71 MessageLoop message_loop_; 72 MessageLoop message_loop_;
72 MockSignalStrategy signal_strategy_; 73 MockSignalStrategy signal_strategy_;
73 ObserverList<SignalStrategy::Listener, true> signal_strategy_listeners_; 74 ObserverList<SignalStrategy::Listener, true> signal_strategy_listeners_;
74 HostKeyPair key_pair_; 75 scoped_refptr<RsaKeyPair> key_pair_;
75 MockCallback callback_; 76 MockCallback callback_;
76 }; 77 };
77 78
78 TEST_F(RegisterSupportHostRequestTest, Send) { 79 TEST_F(RegisterSupportHostRequestTest, Send) {
79 // |iq_request| is freed by RegisterSupportHostRequest. 80 // |iq_request| is freed by RegisterSupportHostRequest.
80 int64 start_time = static_cast<int64>(base::Time::Now().ToDoubleT()); 81 int64 start_time = static_cast<int64>(base::Time::Now().ToDoubleT());
81 82
82 scoped_ptr<RegisterSupportHostRequest> request( 83 scoped_ptr<RegisterSupportHostRequest> request(
83 new RegisterSupportHostRequest(&signal_strategy_, &key_pair_, 84 new RegisterSupportHostRequest(&signal_strategy_, key_pair_,
84 kTestBotJid, 85 kTestBotJid,
85 base::Bind(&MockCallback::OnResponse, 86 base::Bind(&MockCallback::OnResponse,
86 base::Unretained(&callback_)))); 87 base::Unretained(&callback_))));
87 88
88 XmlElement* sent_iq = NULL; 89 XmlElement* sent_iq = NULL;
89 EXPECT_CALL(signal_strategy_, GetNextId()) 90 EXPECT_CALL(signal_strategy_, GetNextId())
90 .WillOnce(Return(kStanzaId)); 91 .WillOnce(Return(kStanzaId));
91 EXPECT_CALL(signal_strategy_, SendStanzaPtr(NotNull())) 92 EXPECT_CALL(signal_strategy_, SendStanzaPtr(NotNull()))
92 .WillOnce(DoAll(SaveArg<0>(&sent_iq), Return(true))); 93 .WillOnce(DoAll(SaveArg<0>(&sent_iq), Return(true)));
93 94
(...skipping 17 matching lines...) Expand all
111 EXPECT_TRUE(stanza->NextNamed(signature_tag) == NULL); 112 EXPECT_TRUE(stanza->NextNamed(signature_tag) == NULL);
112 113
113 std::string time_str = 114 std::string time_str =
114 signature->Attr(QName(kChromotingXmlNamespace, "time")); 115 signature->Attr(QName(kChromotingXmlNamespace, "time"));
115 int64 time; 116 int64 time;
116 EXPECT_TRUE(base::StringToInt64(time_str, &time)); 117 EXPECT_TRUE(base::StringToInt64(time_str, &time));
117 int64 now = static_cast<int64>(base::Time::Now().ToDoubleT()); 118 int64 now = static_cast<int64>(base::Time::Now().ToDoubleT());
118 EXPECT_LE(start_time, time); 119 EXPECT_LE(start_time, time);
119 EXPECT_GE(now, time); 120 EXPECT_GE(now, time);
120 121
121 HostKeyPair key_pair; 122 scoped_refptr<RsaKeyPair> key_pair = RsaKeyPair::FromString(kTestRsaKeyPair);
122 key_pair.LoadFromString(kTestHostKeyPair); 123 ASSERT_TRUE(key_pair);
124
123 std::string expected_signature = 125 std::string expected_signature =
124 key_pair.GetSignature(std::string(kTestJid) + ' ' + time_str); 126 key_pair->SignMessage(std::string(kTestJid) + ' ' + time_str);
125 EXPECT_EQ(expected_signature, signature->BodyText()); 127 EXPECT_EQ(expected_signature, signature->BodyText());
126 128
127 // Generate response and verify that callback is called. 129 // Generate response and verify that callback is called.
128 EXPECT_CALL(callback_, OnResponse(true, kSupportId, 130 EXPECT_CALL(callback_, OnResponse(true, kSupportId,
129 base::TimeDelta::FromSeconds(300))); 131 base::TimeDelta::FromSeconds(300)));
130 132
131 scoped_ptr<XmlElement> response(new XmlElement(buzz::QN_IQ)); 133 scoped_ptr<XmlElement> response(new XmlElement(buzz::QN_IQ));
132 response->AddAttr(QName("", "from"), kTestBotJid); 134 response->AddAttr(QName("", "from"), kTestBotJid);
133 response->AddAttr(QName("", "type"), "result"); 135 response->AddAttr(QName("", "type"), "result");
134 response->AddAttr(QName("", "id"), kStanzaId); 136 response->AddAttr(QName("", "id"), kStanzaId);
(...skipping 19 matching lines...) Expand all
154 while ((listener = it.GetNext()) != NULL) { 156 while ((listener = it.GetNext()) != NULL) {
155 if (listener->OnSignalStrategyIncomingStanza(response.get())) 157 if (listener->OnSignalStrategyIncomingStanza(response.get()))
156 consumed++; 158 consumed++;
157 } 159 }
158 EXPECT_EQ(1, consumed); 160 EXPECT_EQ(1, consumed);
159 161
160 message_loop_.RunUntilIdle(); 162 message_loop_.RunUntilIdle();
161 } 163 }
162 164
163 } // namespace remoting 165 } // namespace remoting
OLDNEW
« no previous file with comments | « remoting/host/register_support_host_request.cc ('k') | remoting/host/remoting_me2me_host.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698