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

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

Issue 3303001: Basic user access check for chromoting host. (Closed)
Patch Set: - Created 10 years, 3 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/heartbeat_sender.h ('k') | remoting/host/host_config.h » ('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) 2010 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2010 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 "base/message_loop.h" 5 #include "base/message_loop.h"
6 #include "base/message_loop_proxy.h" 6 #include "base/message_loop_proxy.h"
7 #include "base/ref_counted.h" 7 #include "base/ref_counted.h"
8 #include "base/scoped_temp_dir.h"
9 #include "base/string_number_conversions.h" 8 #include "base/string_number_conversions.h"
10 #include "media/base/data_buffer.h" 9 #include "media/base/data_buffer.h"
11 #include "remoting/base/constants.h" 10 #include "remoting/base/constants.h"
12 #include "remoting/host/heartbeat_sender.h" 11 #include "remoting/host/heartbeat_sender.h"
13 #include "remoting/host/host_key_pair.h" 12 #include "remoting/host/host_key_pair.h"
14 #include "remoting/host/json_host_config.h" 13 #include "remoting/host/in_memory_host_config.h"
15 #include "remoting/host/test_key_pair.h" 14 #include "remoting/host/test_key_pair.h"
16 #include "remoting/jingle_glue/iq_request.h" 15 #include "remoting/jingle_glue/iq_request.h"
17 #include "remoting/jingle_glue/jingle_client.h" 16 #include "remoting/jingle_glue/jingle_client.h"
18 #include "remoting/jingle_glue/jingle_thread.h" 17 #include "remoting/jingle_glue/jingle_thread.h"
19 #include "testing/gmock/include/gmock/gmock.h" 18 #include "testing/gmock/include/gmock/gmock.h"
20 #include "testing/gtest/include/gtest/gtest.h" 19 #include "testing/gtest/include/gtest/gtest.h"
21 #include "third_party/libjingle/source/talk/xmllite/xmlelement.h" 20 #include "third_party/libjingle/source/talk/xmllite/xmlelement.h"
22 #include "third_party/libjingle/source/talk/xmpp/constants.h" 21 #include "third_party/libjingle/source/talk/xmpp/constants.h"
23 22
24 using testing::_; 23 using testing::_;
(...skipping 24 matching lines...) Expand all
49 MOCK_METHOD3(SendIq, void(const std::string& type, 48 MOCK_METHOD3(SendIq, void(const std::string& type,
50 const std::string& addressee, 49 const std::string& addressee,
51 buzz::XmlElement* iq_body)); 50 buzz::XmlElement* iq_body));
52 }; 51 };
53 52
54 class HeartbeatSenderTest : public testing::Test { 53 class HeartbeatSenderTest : public testing::Test {
55 protected: 54 protected:
56 class TestConfigUpdater : 55 class TestConfigUpdater :
57 public base::RefCountedThreadSafe<TestConfigUpdater> { 56 public base::RefCountedThreadSafe<TestConfigUpdater> {
58 public: 57 public:
59 void DoUpdate(scoped_refptr<JsonHostConfig> target) { 58 void DoUpdate(scoped_refptr<InMemoryHostConfig> target) {
60 target->SetString(kHostIdConfigPath, kHostId); 59 target->SetString(kHostIdConfigPath, kHostId);
61 target->SetString(kPrivateKeyConfigPath, kTestHostKeyPair); 60 target->SetString(kPrivateKeyConfigPath, kTestHostKeyPair);
62 } 61 }
63 }; 62 };
64 63
65 virtual void SetUp() { 64 virtual void SetUp() {
66 ASSERT_TRUE(test_dir_.CreateUniqueTempDir()); 65 config_ = new InMemoryHostConfig();
67 FilePath config_path = test_dir_.path().AppendASCII("test_config.json");
68 config_ = new JsonHostConfig(
69 config_path, base::MessageLoopProxy::CreateForCurrentThread());
70 scoped_refptr<TestConfigUpdater> config_updater(new TestConfigUpdater()); 66 scoped_refptr<TestConfigUpdater> config_updater(new TestConfigUpdater());
71 config_->Update( 67 config_->Update(
72 NewRunnableMethod(config_updater.get(), &TestConfigUpdater::DoUpdate, 68 NewRunnableMethod(config_updater.get(), &TestConfigUpdater::DoUpdate,
73 config_)); 69 config_));
74 70
75 // Run the message loop to save new config.
76 message_loop_.RunAllPending();
77
78 jingle_thread_.message_loop_ = &message_loop_; 71 jingle_thread_.message_loop_ = &message_loop_;
79 72
80 jingle_client_ = new MockJingleClient(&jingle_thread_); 73 jingle_client_ = new MockJingleClient(&jingle_thread_);
81 jingle_client_->full_jid_ = kTestJid; 74 jingle_client_->full_jid_ = kTestJid;
82 } 75 }
83 76
84 JingleThread jingle_thread_; 77 JingleThread jingle_thread_;
85 scoped_refptr<MockJingleClient> jingle_client_; 78 scoped_refptr<MockJingleClient> jingle_client_;
86 MessageLoop message_loop_; 79 MessageLoop message_loop_;
87 ScopedTempDir test_dir_; 80 scoped_refptr<InMemoryHostConfig> config_;
88 scoped_refptr<JsonHostConfig> config_;
89 }; 81 };
90 82
91 TEST_F(HeartbeatSenderTest, DoSendStanza) { 83 TEST_F(HeartbeatSenderTest, DoSendStanza) {
92 // This test calls Start() followed by Stop(), and makes sure an Iq 84 // This test calls Start() followed by Stop(), and makes sure an Iq
93 // stanza is being send. 85 // stanza is being send.
94 86
95 // |iq_request| is freed by HeartbeatSender. 87 // |iq_request| is freed by HeartbeatSender.
96 MockIqRequest* iq_request = new MockIqRequest(jingle_client_); 88 MockIqRequest* iq_request = new MockIqRequest(jingle_client_);
97 89
98 scoped_refptr<HeartbeatSender> heartbeat_sender = new HeartbeatSender(); 90 scoped_refptr<HeartbeatSender> heartbeat_sender = new HeartbeatSender();
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
142 EXPECT_GE(now, time); 134 EXPECT_GE(now, time);
143 135
144 HostKeyPair key_pair; 136 HostKeyPair key_pair;
145 key_pair.LoadFromString(kTestHostKeyPair); 137 key_pair.LoadFromString(kTestHostKeyPair);
146 std::string expected_signature = 138 std::string expected_signature =
147 key_pair.GetSignature(std::string(kTestJid) + ' ' + time_str); 139 key_pair.GetSignature(std::string(kTestJid) + ' ' + time_str);
148 EXPECT_EQ(expected_signature, signature->BodyText()); 140 EXPECT_EQ(expected_signature, signature->BodyText());
149 } 141 }
150 142
151 } // namespace remoting 143 } // namespace remoting
OLDNEW
« no previous file with comments | « remoting/host/heartbeat_sender.h ('k') | remoting/host/host_config.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698