| OLD | NEW | 
|---|
|  | (Empty) | 
| 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 |  | 
| 3 // found in the LICENSE file. |  | 
| 4 |  | 
| 5 #include <memory> |  | 
| 6 |  | 
| 7 #include "base/base64url.h" |  | 
| 8 #include "components/copresence/handlers/gcm_handler_impl.h" |  | 
| 9 #include "components/copresence/proto/push_message.pb.h" |  | 
| 10 #include "components/copresence/test/fake_directive_handler.h" |  | 
| 11 #include "components/gcm_driver/fake_gcm_driver.h" |  | 
| 12 #include "components/gcm_driver/gcm_client.h" |  | 
| 13 #include "testing/gmock/include/gmock/gmock.h" |  | 
| 14 |  | 
| 15 namespace copresence { |  | 
| 16 |  | 
| 17 namespace { |  | 
| 18 |  | 
| 19 using google::protobuf::RepeatedPtrField; |  | 
| 20 void IgnoreMessages( |  | 
| 21     const RepeatedPtrField<SubscribedMessage>& /* messages */) {} |  | 
| 22 |  | 
| 23 }  // namespace |  | 
| 24 |  | 
| 25 |  | 
| 26 class GCMHandlerTest : public testing::Test { |  | 
| 27  public: |  | 
| 28   GCMHandlerTest() |  | 
| 29     : driver_(new gcm::FakeGCMDriver), |  | 
| 30       directive_handler_(new FakeDirectiveHandler), |  | 
| 31       gcm_handler_(driver_.get(), |  | 
| 32                    directive_handler_.get(), |  | 
| 33                    base::Bind(&IgnoreMessages)) { |  | 
| 34   } |  | 
| 35 |  | 
| 36  protected: |  | 
| 37   void ProcessMessage(const gcm::IncomingMessage& message) { |  | 
| 38     gcm_handler_.OnMessage(GCMHandlerImpl::kCopresenceAppId, message); |  | 
| 39   } |  | 
| 40 |  | 
| 41   std::unique_ptr<gcm::GCMDriver> driver_; |  | 
| 42   std::unique_ptr<FakeDirectiveHandler> directive_handler_; |  | 
| 43   GCMHandlerImpl gcm_handler_; |  | 
| 44 }; |  | 
| 45 |  | 
| 46 TEST_F(GCMHandlerTest, OnMessage) { |  | 
| 47   // Create a PushMessage. |  | 
| 48   PushMessage push_message; |  | 
| 49   push_message.set_type(PushMessage::REPORT); |  | 
| 50   Report* report = push_message.mutable_report(); |  | 
| 51   report->add_directive()->set_subscription_id("subscription 1"); |  | 
| 52   report->add_directive()->set_subscription_id("subscription 2"); |  | 
| 53 |  | 
| 54   // Encode it. |  | 
| 55   std::string serialized_proto; |  | 
| 56   std::string encoded_proto; |  | 
| 57   push_message.SerializeToString(&serialized_proto); |  | 
| 58   base::Base64UrlEncode(serialized_proto, |  | 
| 59                         base::Base64UrlEncodePolicy::INCLUDE_PADDING, |  | 
| 60                         &encoded_proto); |  | 
| 61 |  | 
| 62   // Send it in a GCM message. |  | 
| 63   gcm::IncomingMessage gcm_message; |  | 
| 64   gcm_message.data[GCMHandlerImpl::kGcmMessageKey] = encoded_proto; |  | 
| 65   ProcessMessage(gcm_message); |  | 
| 66 |  | 
| 67   // Check that the correct directives were passed along. |  | 
| 68   EXPECT_THAT(directive_handler_->added_directives(), |  | 
| 69               testing::ElementsAre("subscription 1", "subscription 2")); |  | 
| 70 } |  | 
| 71 |  | 
| 72 }  // namespace copresence |  | 
| OLD | NEW | 
|---|