Merge Chromium + Blink git repositories
[chromium-blink-merge.git] / google_apis / gcm / base / mcs_message_unittest.cc
blob4dd52d6adde07d8e5c15787253633e1d5f0d548f
1 // Copyright 2013 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.
5 #include "google_apis/gcm/base/mcs_message.h"
7 #include "base/logging.h"
8 #include "base/test/test_simple_task_runner.h"
9 #include "base/thread_task_runner_handle.h"
10 #include "google_apis/gcm/base/mcs_util.h"
11 #include "google_apis/gcm/protocol/mcs.pb.h"
12 #include "testing/gtest/include/gtest/gtest.h"
14 namespace gcm {
16 const uint64 kAndroidId = 12345;
17 const uint64 kSecret = 54321;
19 class MCSMessageTest : public testing::Test {
20 public:
21 MCSMessageTest();
22 ~MCSMessageTest() override;
24 private:
25 scoped_refptr<base::TestSimpleTaskRunner> task_runner_;
26 base::ThreadTaskRunnerHandle task_runner_handle_;
29 MCSMessageTest::MCSMessageTest()
30 : task_runner_(new base::TestSimpleTaskRunner()),
31 task_runner_handle_(task_runner_) {
34 MCSMessageTest::~MCSMessageTest() {
37 TEST_F(MCSMessageTest, Invalid) {
38 MCSMessage message;
39 EXPECT_FALSE(message.IsValid());
42 TEST_F(MCSMessageTest, InitInferTag) {
43 scoped_ptr<mcs_proto::LoginRequest> login_request(
44 BuildLoginRequest(kAndroidId, kSecret, ""));
45 scoped_ptr<google::protobuf::MessageLite> login_copy(
46 new mcs_proto::LoginRequest(*login_request));
47 MCSMessage message(*login_copy);
48 login_copy.reset();
49 ASSERT_TRUE(message.IsValid());
50 EXPECT_EQ(kLoginRequestTag, message.tag());
51 EXPECT_EQ(login_request->ByteSize(), message.size());
52 EXPECT_EQ(login_request->SerializeAsString(), message.SerializeAsString());
53 EXPECT_EQ(login_request->SerializeAsString(),
54 message.GetProtobuf().SerializeAsString());
55 login_copy = message.CloneProtobuf();
56 EXPECT_EQ(login_request->SerializeAsString(),
57 login_copy->SerializeAsString());
60 TEST_F(MCSMessageTest, InitWithTag) {
61 scoped_ptr<mcs_proto::LoginRequest> login_request(
62 BuildLoginRequest(kAndroidId, kSecret, ""));
63 scoped_ptr<google::protobuf::MessageLite> login_copy(
64 new mcs_proto::LoginRequest(*login_request));
65 MCSMessage message(kLoginRequestTag, *login_copy);
66 login_copy.reset();
67 ASSERT_TRUE(message.IsValid());
68 EXPECT_EQ(kLoginRequestTag, message.tag());
69 EXPECT_EQ(login_request->ByteSize(), message.size());
70 EXPECT_EQ(login_request->SerializeAsString(), message.SerializeAsString());
71 EXPECT_EQ(login_request->SerializeAsString(),
72 message.GetProtobuf().SerializeAsString());
73 login_copy = message.CloneProtobuf();
74 EXPECT_EQ(login_request->SerializeAsString(),
75 login_copy->SerializeAsString());
78 TEST_F(MCSMessageTest, InitPassOwnership) {
79 scoped_ptr<mcs_proto::LoginRequest> login_request(
80 BuildLoginRequest(kAndroidId, kSecret, ""));
81 scoped_ptr<google::protobuf::MessageLite> login_copy(
82 new mcs_proto::LoginRequest(*login_request));
83 MCSMessage message(kLoginRequestTag, login_copy.Pass());
84 EXPECT_FALSE(login_copy.get());
85 ASSERT_TRUE(message.IsValid());
86 EXPECT_EQ(kLoginRequestTag, message.tag());
87 EXPECT_EQ(login_request->ByteSize(), message.size());
88 EXPECT_EQ(login_request->SerializeAsString(), message.SerializeAsString());
89 EXPECT_EQ(login_request->SerializeAsString(),
90 message.GetProtobuf().SerializeAsString());
91 login_copy = message.CloneProtobuf();
92 EXPECT_EQ(login_request->SerializeAsString(),
93 login_copy->SerializeAsString());
96 } // namespace gcm