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

Side by Side Diff: components/copresence/handlers/gcm_handler_unittest.cc

Issue 813553002: Adding support for pre-sent messages (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@state
Patch Set: Created 5 years, 11 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
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 "base/base64.h" 5 #include "base/base64.h"
6 #include "base/memory/scoped_ptr.h" 6 #include "base/memory/scoped_ptr.h"
7 #include "base/strings/string_util.h" 7 #include "base/strings/string_util.h"
8 #include "components/copresence/handlers/gcm_handler_impl.h" 8 #include "components/copresence/handlers/gcm_handler_impl.h"
9 #include "components/copresence/proto/push_message.pb.h" 9 #include "components/copresence/proto/push_message.pb.h"
10 #include "components/copresence/test/fake_directive_handler.h" 10 #include "components/copresence/test/fake_directive_handler.h"
11 #include "components/gcm_driver/fake_gcm_driver.h" 11 #include "components/gcm_driver/fake_gcm_driver.h"
12 #include "components/gcm_driver/gcm_client.h" 12 #include "components/gcm_driver/gcm_client.h"
13 #include "testing/gmock/include/gmock/gmock.h" 13 #include "testing/gmock/include/gmock/gmock.h"
14 14
15 using gcm::GCMClient; 15 using gcm::GCMClient;
16 16
17 namespace copresence {
18
17 namespace { 19 namespace {
18 20
19 // TODO(ckehoe): Move this to a central place. 21 // TODO(ckehoe): Move this to a central place.
20 std::string ToUrlSafe(std::string token) { 22 std::string ToUrlSafe(std::string token) {
21 base::ReplaceChars(token, "+", "-", &token); 23 base::ReplaceChars(token, "+", "-", &token);
22 base::ReplaceChars(token, "/", "_", &token); 24 base::ReplaceChars(token, "/", "_", &token);
23 return token; 25 return token;
24 } 26 }
25 27
28 using google::protobuf::RepeatedPtrField;
29 void IgnoreMessages(
30 const RepeatedPtrField<SubscribedMessage>& /* messages */) {}
31
26 } // namespace 32 } // namespace
27 33
28 34
29 namespace copresence {
30
31 class GCMHandlerTest : public testing::Test { 35 class GCMHandlerTest : public testing::Test {
32 public: 36 public:
33 GCMHandlerTest() 37 GCMHandlerTest()
34 : driver_(new gcm::FakeGCMDriver), 38 : driver_(new gcm::FakeGCMDriver),
35 directive_handler_(new FakeDirectiveHandler), 39 directive_handler_(new FakeDirectiveHandler),
36 gcm_handler_(driver_.get(), directive_handler_.get()) { 40 gcm_handler_(driver_.get(),
41 directive_handler_.get(),
42 base::Bind(&IgnoreMessages)) {
37 } 43 }
38 44
39 protected: 45 protected:
40 void ProcessMessage(const GCMClient::IncomingMessage& message) { 46 void ProcessMessage(const GCMClient::IncomingMessage& message) {
41 gcm_handler_.OnMessage(GCMHandlerImpl::kCopresenceAppId, message); 47 gcm_handler_.OnMessage(GCMHandlerImpl::kCopresenceAppId, message);
42 } 48 }
43 49
44 scoped_ptr<gcm::GCMDriver> driver_; 50 scoped_ptr<gcm::GCMDriver> driver_;
45 scoped_ptr<FakeDirectiveHandler> directive_handler_; 51 scoped_ptr<FakeDirectiveHandler> directive_handler_;
46 GCMHandlerImpl gcm_handler_; 52 GCMHandlerImpl gcm_handler_;
(...skipping 17 matching lines...) Expand all
64 GCMClient::IncomingMessage gcm_message; 70 GCMClient::IncomingMessage gcm_message;
65 gcm_message.data[GCMHandlerImpl::kGcmMessageKey] = ToUrlSafe(encoded_proto); 71 gcm_message.data[GCMHandlerImpl::kGcmMessageKey] = ToUrlSafe(encoded_proto);
66 ProcessMessage(gcm_message); 72 ProcessMessage(gcm_message);
67 73
68 // Check that the correct directives were passed along. 74 // Check that the correct directives were passed along.
69 EXPECT_THAT(directive_handler_->added_directives(), 75 EXPECT_THAT(directive_handler_->added_directives(),
70 testing::ElementsAre("subscription 1", "subscription 2")); 76 testing::ElementsAre("subscription 1", "subscription 2"));
71 } 77 }
72 78
73 } // namespace copresence 79 } // namespace copresence
OLDNEW
« no previous file with comments | « components/copresence/handlers/gcm_handler_impl.cc ('k') | components/copresence/proto/data.proto » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698