Updating trunk VERSION from 2139.0 to 2140.0
[chromium-blink-merge.git] / google_apis / gcm / engine / account_mapping_unittest.cc
blob00ff7e1164428b59d61d2e99c80bfdc233265f8a
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.
5 #include "google_apis/gcm/engine/account_mapping.h"
7 #include <string>
9 #include "testing/gtest/include/gtest/gtest.h"
11 namespace gcm {
13 namespace {
15 TEST(AccountMappingTest, SerializeAccountMapping) {
16 AccountMapping account_mapping;
17 account_mapping.account_id = "acc_id";
18 account_mapping.email = "test@example.com";
19 account_mapping.access_token = "access_token";
20 account_mapping.status = AccountMapping::ADDING;
21 account_mapping.status_change_timestamp = base::Time();
22 account_mapping.last_message_id = "last_message_id_1";
23 account_mapping.last_message_type = AccountMapping::MSG_ADD;
25 EXPECT_EQ("test@example.com&0&add&last_message_id_1",
26 account_mapping.SerializeAsString());
28 account_mapping.account_id = "acc_id2";
29 account_mapping.email = "test@gmail.com";
30 account_mapping.access_token = "access_token"; // should be ignored.
31 account_mapping.status = AccountMapping::MAPPED; // should be ignored.
32 account_mapping.status_change_timestamp =
33 base::Time::FromInternalValue(1305797421259977LL);
34 account_mapping.last_message_id = "last_message_id_2";
35 account_mapping.last_message_type = AccountMapping::MSG_REMOVE;
37 EXPECT_EQ("test@gmail.com&1305797421259977&remove&last_message_id_2",
38 account_mapping.SerializeAsString());
40 account_mapping.last_message_type = AccountMapping::MSG_NONE;
42 EXPECT_EQ("test@gmail.com&1305797421259977&none",
43 account_mapping.SerializeAsString());
46 TEST(AccountMappingTest, DeserializeAccountMapping) {
47 AccountMapping account_mapping;
48 account_mapping.account_id = "acc_id";
49 EXPECT_TRUE(account_mapping.ParseFromString(
50 "test@example.com&0&add&last_message_id_1"));
51 EXPECT_EQ("acc_id", account_mapping.account_id);
52 EXPECT_EQ("test@example.com", account_mapping.email);
53 EXPECT_TRUE(account_mapping.access_token.empty());
54 EXPECT_EQ(AccountMapping::ADDING, account_mapping.status);
55 EXPECT_EQ(base::Time(), account_mapping.status_change_timestamp);
56 EXPECT_EQ(AccountMapping::MSG_ADD, account_mapping.last_message_type);
57 EXPECT_EQ("last_message_id_1", account_mapping.last_message_id);
59 EXPECT_TRUE(account_mapping.ParseFromString(
60 "test@gmail.com&1305797421259977&remove&last_message_id_2"));
61 EXPECT_EQ("acc_id", account_mapping.account_id);
62 EXPECT_EQ("test@gmail.com", account_mapping.email);
63 EXPECT_TRUE(account_mapping.access_token.empty());
64 EXPECT_EQ(AccountMapping::REMOVING, account_mapping.status);
65 EXPECT_EQ(base::Time::FromInternalValue(1305797421259977LL),
66 account_mapping.status_change_timestamp);
67 EXPECT_EQ(AccountMapping::MSG_REMOVE, account_mapping.last_message_type);
68 EXPECT_EQ("last_message_id_2", account_mapping.last_message_id);
70 EXPECT_TRUE(account_mapping.ParseFromString(
71 "test@gmail.com&1305797421259977&none"));
72 EXPECT_EQ("acc_id", account_mapping.account_id);
73 EXPECT_EQ("test@gmail.com", account_mapping.email);
74 EXPECT_TRUE(account_mapping.access_token.empty());
75 EXPECT_EQ(AccountMapping::MAPPED, account_mapping.status);
76 EXPECT_EQ(base::Time::FromInternalValue(1305797421259977LL),
77 account_mapping.status_change_timestamp);
78 EXPECT_EQ(AccountMapping::MSG_NONE, account_mapping.last_message_type);
79 EXPECT_EQ("", account_mapping.last_message_id);
82 TEST(AccountMappingTest, DeserializeAccountMappingInvalidInput) {
83 AccountMapping account_mapping;
84 account_mapping.account_id = "acc_id";
85 // Too many agruments.
86 EXPECT_FALSE(account_mapping.ParseFromString(
87 "test@example.com&1305797421259935"
88 "&add&last_message_id_1&stuff_here"));
89 // Too few arguments.
90 EXPECT_FALSE(account_mapping.ParseFromString(
91 "test@example.com&1305797421259935&remove"));
92 // Too few arguments.
93 EXPECT_FALSE(account_mapping.ParseFromString(
94 "test@example.com&1305797421259935"));
95 // Missing email.
96 EXPECT_FALSE(account_mapping.ParseFromString(
97 "&1305797421259935&remove&last_message_id_2"));
98 // Missing mapping status change timestamp.
99 EXPECT_FALSE(account_mapping.ParseFromString(
100 "test@gmail.com&&remove&last_message_id_2"));
101 // Last mapping status change timestamp not parseable.
102 EXPECT_FALSE(account_mapping.ParseFromString(
103 "test@gmail.com&remove&asdfjkl&last_message_id_2"));
104 // Missing message type.
105 EXPECT_FALSE(account_mapping.ParseFromString(
106 "test@example.com&1305797421259935&&last_message_id_2"));
107 // Unkown message type.
108 EXPECT_FALSE(account_mapping.ParseFromString(
109 "test@example.com&1305797421259935&random&last_message_id_2"));
110 // Message type is none when message details specified.
111 EXPECT_FALSE(account_mapping.ParseFromString(
112 "test@example.com&1305797421259935&none&last_message_id_2"));
113 // Message type is messed up.
114 EXPECT_FALSE(account_mapping.ParseFromString(
115 "test@example.com&1305797421259935&random"));
116 // Missing last message ID.
117 EXPECT_FALSE(account_mapping.ParseFromString(
118 "test@example.com&1305797421259935&remove&"));
121 } // namespace
122 } // namespace gcm