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

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

Issue 713643002: Revert "Adding GCM support to the copresence component. The Copresence server can push directives (… (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@2214
Patch Set: Created 6 years, 1 month 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/handlers/gcm_handler.cc ('k') | components/copresence/proto/BUILD.gn » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(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 "components/copresence/handlers/gcm_handler.h"
6
7 #include "base/base64.h"
8 #include "base/memory/scoped_ptr.h"
9 #include "base/strings/string_util.h"
10 #include "components/copresence/proto/push_message.pb.h"
11 #include "components/copresence/test/fake_directive_handler.h"
12 #include "components/gcm_driver/fake_gcm_driver.h"
13 #include "components/gcm_driver/gcm_client.h"
14 #include "testing/gmock/include/gmock/gmock.h"
15
16 using gcm::GCMClient;
17
18 namespace {
19
20 // TODO(ckehoe): Move this to a central place.
21 std::string ToUrlSafe(std::string token) {
22 base::ReplaceChars(token, "+", "-", &token);
23 base::ReplaceChars(token, "/", "_", &token);
24 return token;
25 }
26
27 } // namespace
28
29
30 namespace copresence {
31
32 class GCMHandlerTest : public testing::Test {
33 public:
34 GCMHandlerTest()
35 : driver_(new gcm::FakeGCMDriver),
36 directive_handler_(new FakeDirectiveHandler),
37 gcm_handler_(driver_.get(), directive_handler_.get()) {
38 }
39
40 protected:
41 scoped_ptr<gcm::GCMDriver> driver_;
42 scoped_ptr<FakeDirectiveHandler> directive_handler_;
43 GCMHandler 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::Base64Encode(serialized_proto, &encoded_proto);
59
60 // Send it in a GCM message.
61 GCMClient::IncomingMessage gcm_message;
62 gcm_message.data[GCMHandler::kGcmMessageKey] = ToUrlSafe(encoded_proto);
63 gcm_handler_.OnMessage(GCMHandler::kCopresenceAppId, gcm_message);
64
65 // Check that the correct directives were passed along.
66 EXPECT_THAT(directive_handler_->added_directives(),
67 testing::ElementsAre("subscription 1", "subscription 2"));
68 }
69
70 } // namespace copresence
71
OLDNEW
« no previous file with comments | « components/copresence/handlers/gcm_handler.cc ('k') | components/copresence/proto/BUILD.gn » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698