Chromium Code Reviews| 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 <string> | |
| 6 | |
| 7 #include "google_apis/gcm/engine/account_mapping.h" | |
|
Nicolas Zea
2014/08/06 19:10:12
nit: this is typically the first include in the fi
fgorski
2014/08/06 20:44:43
Done.
| |
| 8 #include "testing/gtest/include/gtest/gtest.h" | |
| 9 | |
| 10 namespace gcm { | |
| 11 | |
| 12 namespace { | |
| 13 | |
| 14 TEST(AccountMappingTest, SerializeAccountMapping) { | |
| 15 AccountMapping account_mapping; | |
| 16 account_mapping.account_id = "acc_id"; | |
| 17 account_mapping.email = "test@example.com"; | |
| 18 account_mapping.access_token = "access_token"; | |
| 19 account_mapping.status = AccountMapping::ADDING; | |
| 20 account_mapping.status_change_timestamp = | |
| 21 base::Time::FromInternalValue(1305797421259942LL); | |
| 22 account_mapping.last_message_id = "last_message_id_1"; | |
| 23 account_mapping.last_message_type = AccountMapping::MSG_ADD; | |
| 24 | |
| 25 EXPECT_EQ("test@example.com&adding&1305797421259942&add&last_message_id_1", | |
| 26 account_mapping.SerializeAsString()); | |
| 27 | |
| 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::REMOVING; | |
| 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; | |
| 36 | |
| 37 EXPECT_EQ("test@gmail.com&removing&1305797421259977&remove&last_message_id_2", | |
| 38 account_mapping.SerializeAsString()); | |
| 39 | |
| 40 account_mapping.status = AccountMapping::MAPPED; | |
| 41 account_mapping.last_message_type = AccountMapping::MSG_NONE; | |
| 42 | |
| 43 EXPECT_EQ("test@gmail.com&mapped&1305797421259977&none", | |
| 44 account_mapping.SerializeAsString()); | |
| 45 | |
| 46 account_mapping.status = AccountMapping::REMOVED; | |
| 47 | |
| 48 EXPECT_EQ("test@gmail.com&removed&1305797421259977&none", | |
| 49 account_mapping.SerializeAsString()); | |
| 50 | |
| 51 account_mapping.status = AccountMapping::NEW; | |
| 52 account_mapping.status_change_timestamp = base::Time(); | |
| 53 | |
| 54 EXPECT_EQ("test@gmail.com&new&0&none", account_mapping.SerializeAsString()); | |
| 55 } | |
| 56 | |
| 57 TEST(AccountMappingTest, DeserializeAccountMapping) { | |
| 58 AccountMapping account_mapping; | |
| 59 account_mapping.account_id = "acc_id"; | |
| 60 EXPECT_TRUE(account_mapping.ParseFromString( | |
| 61 "test@example.com&adding&1305797421259942&add&last_message_id_1")); | |
| 62 EXPECT_EQ("acc_id", account_mapping.account_id); | |
| 63 EXPECT_EQ("test@example.com", account_mapping.email); | |
| 64 EXPECT_TRUE(account_mapping.access_token.empty()); | |
| 65 EXPECT_EQ(AccountMapping::ADDING, account_mapping.status); | |
| 66 EXPECT_EQ(base::Time::FromInternalValue(1305797421259942LL), | |
| 67 account_mapping.status_change_timestamp); | |
| 68 EXPECT_EQ(AccountMapping::MSG_ADD, account_mapping.last_message_type); | |
| 69 EXPECT_EQ("last_message_id_1", account_mapping.last_message_id); | |
| 70 | |
| 71 EXPECT_TRUE(account_mapping.ParseFromString( | |
| 72 "test@gmail.com&removing&1305797421259977&remove&last_message_id_2")); | |
| 73 EXPECT_EQ("acc_id", account_mapping.account_id); | |
| 74 EXPECT_EQ("test@gmail.com", account_mapping.email); | |
| 75 EXPECT_TRUE(account_mapping.access_token.empty()); | |
| 76 EXPECT_EQ(AccountMapping::REMOVING, account_mapping.status); | |
| 77 EXPECT_EQ(base::Time::FromInternalValue(1305797421259977LL), | |
| 78 account_mapping.status_change_timestamp); | |
| 79 EXPECT_EQ(AccountMapping::MSG_REMOVE, account_mapping.last_message_type); | |
| 80 EXPECT_EQ("last_message_id_2", account_mapping.last_message_id); | |
| 81 | |
| 82 EXPECT_TRUE(account_mapping.ParseFromString( | |
| 83 "test@gmail.com&mapped&1305797421259977&none")); | |
| 84 EXPECT_EQ("acc_id", account_mapping.account_id); | |
| 85 EXPECT_EQ("test@gmail.com", account_mapping.email); | |
| 86 EXPECT_TRUE(account_mapping.access_token.empty()); | |
| 87 EXPECT_EQ(AccountMapping::MAPPED, account_mapping.status); | |
| 88 EXPECT_EQ(base::Time::FromInternalValue(1305797421259977LL), | |
| 89 account_mapping.status_change_timestamp); | |
| 90 EXPECT_EQ(AccountMapping::MSG_NONE, account_mapping.last_message_type); | |
| 91 EXPECT_EQ("", account_mapping.last_message_id); | |
| 92 | |
| 93 EXPECT_TRUE(account_mapping.ParseFromString( | |
| 94 "test@gmail.com&removed&1305797421259977&none")); | |
| 95 EXPECT_EQ("acc_id", account_mapping.account_id); | |
| 96 EXPECT_EQ("test@gmail.com", account_mapping.email); | |
| 97 EXPECT_TRUE(account_mapping.access_token.empty()); | |
| 98 EXPECT_EQ(AccountMapping::REMOVED, account_mapping.status); | |
| 99 EXPECT_EQ(base::Time::FromInternalValue(1305797421259977LL), | |
| 100 account_mapping.status_change_timestamp); | |
| 101 EXPECT_EQ(AccountMapping::MSG_NONE, account_mapping.last_message_type); | |
| 102 EXPECT_EQ("", account_mapping.last_message_id); | |
| 103 | |
| 104 EXPECT_TRUE(account_mapping.ParseFromString("test@gmail.com&new&0&none")); | |
| 105 EXPECT_EQ("acc_id", account_mapping.account_id); | |
| 106 EXPECT_EQ("test@gmail.com", account_mapping.email); | |
| 107 EXPECT_TRUE(account_mapping.access_token.empty()); | |
| 108 EXPECT_EQ(AccountMapping::NEW, account_mapping.status); | |
| 109 EXPECT_EQ(base::Time(), account_mapping.status_change_timestamp); | |
| 110 EXPECT_EQ(AccountMapping::MSG_NONE, account_mapping.last_message_type); | |
| 111 EXPECT_EQ("", account_mapping.last_message_id); | |
| 112 } | |
| 113 | |
| 114 TEST(AccountMappingTest, DeserializeAccountMappingInvalidInput) { | |
| 115 AccountMapping account_mapping; | |
| 116 account_mapping.account_id = "acc_id"; | |
| 117 // Too many agruments. | |
| 118 EXPECT_FALSE(account_mapping.ParseFromString( | |
| 119 "test@example.com&adding&1305797421259935" | |
| 120 "&add&last_message_id_1&stuff_here")); | |
| 121 // Too few arguments. | |
| 122 EXPECT_FALSE(account_mapping.ParseFromString( | |
| 123 "test@example.com&adding&1305797421259935&remove")); | |
| 124 // Too few arguments. | |
| 125 EXPECT_FALSE(account_mapping.ParseFromString( | |
| 126 "test@example.com&adding&1305797421259935")); | |
| 127 // Missing email. | |
| 128 EXPECT_FALSE(account_mapping.ParseFromString( | |
| 129 "&adding&1305797421259935&remove&last_message_id_2")); | |
| 130 // Missing mapping status. | |
| 131 EXPECT_FALSE(account_mapping.ParseFromString( | |
| 132 "test@gmail.com&&1305797421259935&remove&last_message_id_2")); | |
| 133 // Unknown mapping status. | |
| 134 EXPECT_FALSE(account_mapping.ParseFromString( | |
| 135 "test@gmail.com&random&1305797421259935&remove&last_message_id_2")); | |
| 136 // Missing mapping status change timestamp. | |
| 137 EXPECT_FALSE(account_mapping.ParseFromString( | |
| 138 "test@gmail.com&adding&&remove&last_message_id_2")); | |
| 139 // Last mapping status change timestamp not parseable. | |
| 140 EXPECT_FALSE(account_mapping.ParseFromString( | |
| 141 "test@gmail.com&removing&remove&asdfjkl&last_message_id_2")); | |
| 142 // Missing message type. | |
| 143 EXPECT_FALSE(account_mapping.ParseFromString( | |
| 144 "test@example.com&adding&1305797421259935&&last_message_id_2")); | |
| 145 // Unkown message type. | |
| 146 EXPECT_FALSE(account_mapping.ParseFromString( | |
| 147 "test@example.com&adding&1305797421259935&random&last_message_id_2")); | |
| 148 // Message type is none when message details specified. | |
| 149 EXPECT_FALSE(account_mapping.ParseFromString( | |
| 150 "test@example.com&adding&1305797421259935&none&last_message_id_2")); | |
| 151 // Message type is messed up. | |
| 152 EXPECT_FALSE(account_mapping.ParseFromString( | |
| 153 "test@example.com&adding&1305797421259935&random")); | |
| 154 // Missing last message ID. | |
| 155 EXPECT_FALSE(account_mapping.ParseFromString( | |
| 156 "test@example.com&adding&1305797421259935&remove&")); | |
| 157 } | |
| 158 | |
| 159 } // namespace | |
| 160 } // namespace gcm | |
| OLD | NEW |