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

Side by Side Diff: components/copresence/rpc/rpc_handler_unittest.cc

Issue 764673003: Adding CopresenceState (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 6 years 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 | « components/copresence/rpc/rpc_handler.cc ('k') | components/copresence/tokens.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 2014 The Chromium Authors. All rights reserved. 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 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 "components/copresence/rpc/rpc_handler.h" 5 #include "components/copresence/rpc/rpc_handler.h"
6 6
7 #include <map> 7 #include <map>
8 #include <string> 8 #include <string>
9 #include <vector> 9 #include <vector>
10 10
11 #include "base/bind.h" 11 #include "base/bind.h"
12 #include "base/bind_helpers.h" 12 #include "base/bind_helpers.h"
13 #include "base/memory/scoped_vector.h" 13 #include "base/memory/scoped_vector.h"
14 #include "base/message_loop/message_loop.h" 14 #include "base/message_loop/message_loop.h"
15 #include "components/copresence/copresence_state_impl.h"
15 #include "components/copresence/handlers/directive_handler.h" 16 #include "components/copresence/handlers/directive_handler.h"
16 #include "components/copresence/mediums/audio/audio_manager.h" 17 #include "components/copresence/mediums/audio/audio_manager.h"
17 #include "components/copresence/proto/data.pb.h" 18 #include "components/copresence/proto/data.pb.h"
18 #include "components/copresence/proto/enums.pb.h" 19 #include "components/copresence/proto/enums.pb.h"
19 #include "components/copresence/proto/rpcs.pb.h" 20 #include "components/copresence/proto/rpcs.pb.h"
20 #include "components/copresence/test/fake_directive_handler.h" 21 #include "components/copresence/test/fake_directive_handler.h"
21 #include "components/copresence/test/stub_whispernet_client.h" 22 #include "components/copresence/test/stub_whispernet_client.h"
22 #include "net/http/http_status_code.h" 23 #include "net/http/http_status_code.h"
23 #include "testing/gmock/include/gmock/gmock.h" 24 #include "testing/gmock/include/gmock/gmock.h"
24 25
(...skipping 18 matching lines...) Expand all
43 message_proto->add_subscription_id(subscription_id); 44 message_proto->add_subscription_id(subscription_id);
44 } 45 }
45 } 46 }
46 47
47 } // namespace 48 } // namespace
48 49
49 class RpcHandlerTest : public testing::Test, public CopresenceDelegate { 50 class RpcHandlerTest : public testing::Test, public CopresenceDelegate {
50 public: 51 public:
51 RpcHandlerTest() 52 RpcHandlerTest()
52 : whispernet_client_(new StubWhispernetClient), 53 : whispernet_client_(new StubWhispernetClient),
54 // TODO(ckehoe): Use a FakeCopresenceState here
55 // and test that it gets called correctly.
56 state_(new CopresenceStateImpl),
53 rpc_handler_(this, 57 rpc_handler_(this,
58 state_.get(),
54 &directive_handler_, 59 &directive_handler_,
55 nullptr, 60 nullptr,
56 base::Bind(&RpcHandlerTest::CaptureHttpPost, 61 base::Bind(&RpcHandlerTest::CaptureHttpPost,
57 base::Unretained(this))), 62 base::Unretained(this))),
58 status_(SUCCESS) {} 63 status_(SUCCESS) {}
59 64
60 // CopresenceDelegate implementation 65 // CopresenceDelegate implementation
61 66
62 void HandleMessages(const std::string& /* app_id */, 67 void HandleMessages(const std::string& /* app_id */,
63 const std::string& subscription_id, 68 const std::string& subscription_id,
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after
147 152
148 bool TokenIsInvalid(const std::string& token) { 153 bool TokenIsInvalid(const std::string& token) {
149 return rpc_handler_.invalid_audio_token_cache_.HasKey(token); 154 return rpc_handler_.invalid_audio_token_cache_.HasKey(token);
150 } 155 }
151 156
152 // For rpc_handler_.invalid_audio_token_cache_ 157 // For rpc_handler_.invalid_audio_token_cache_
153 base::MessageLoop message_loop_; 158 base::MessageLoop message_loop_;
154 159
155 scoped_ptr<WhispernetClient> whispernet_client_; 160 scoped_ptr<WhispernetClient> whispernet_client_;
156 FakeDirectiveHandler directive_handler_; 161 FakeDirectiveHandler directive_handler_;
162 scoped_ptr<CopresenceStateImpl> state_;
157 RpcHandler rpc_handler_; 163 RpcHandler rpc_handler_;
158 164
159 CopresenceStatus status_; 165 CopresenceStatus status_;
160 std::string rpc_name_; 166 std::string rpc_name_;
161 std::string api_key_; 167 std::string api_key_;
162 std::string auth_token_; 168 std::string auth_token_;
163 ScopedVector<MessageLite> request_protos_; 169 ScopedVector<MessageLite> request_protos_;
164 std::map<std::string, std::vector<std::string>> messages_by_subscription_; 170 std::map<std::string, std::vector<std::string>> messages_by_subscription_;
165 171
166 private: 172 private:
(...skipping 182 matching lines...) Expand 10 before | Expand all | Expand 10 after
349 EXPECT_TRUE(TokenIsInvalid("bad token")); 355 EXPECT_TRUE(TokenIsInvalid("bad token"));
350 EXPECT_THAT(messages_by_subscription_["Subscription 1"], 356 EXPECT_THAT(messages_by_subscription_["Subscription 1"],
351 ElementsAre("Message A", "Message C")); 357 ElementsAre("Message A", "Message C"));
352 EXPECT_THAT(messages_by_subscription_["Subscription 2"], 358 EXPECT_THAT(messages_by_subscription_["Subscription 2"],
353 ElementsAre("Message B", "Message C")); 359 ElementsAre("Message B", "Message C"));
354 EXPECT_THAT(directive_handler_.added_directives(), 360 EXPECT_THAT(directive_handler_.added_directives(),
355 ElementsAre("Subscription 1", "Subscription 2")); 361 ElementsAre("Subscription 1", "Subscription 2"));
356 } 362 }
357 363
358 } // namespace copresence 364 } // namespace copresence
OLDNEW
« no previous file with comments | « components/copresence/rpc/rpc_handler.cc ('k') | components/copresence/tokens.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698