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 "components/proximity_auth/remote_status_update.h" | |
| 6 | |
| 7 #include "testing/gtest/include/gtest/gtest.h" | |
| 8 | |
| 9 namespace proximity_auth { | |
|
Tim Song
2014/10/09 19:07:30
Can you add one more test for when the JSON is val
Ilya Sherman
2014/10/09 22:52:33
Done.
| |
| 10 | |
| 11 // Verify that all valid values can be parsed. | |
| 12 TEST(ProximityAuthRemoteStatusUpdateTest, FromJson_ValidStatuses) { | |
| 13 { | |
| 14 const char kValidJson[] = | |
| 15 "{" | |
| 16 " \"type\": \"status_update\"," | |
| 17 " \"user_presence\": \"present\"," | |
| 18 " \"secure_screen_lock\": \"enabled\"," | |
| 19 " \"trust_agent\": \"enabled\"" | |
| 20 "}"; | |
| 21 scoped_ptr<RemoteStatusUpdate> parsed_update = | |
| 22 RemoteStatusUpdate::FromJson(kValidJson); | |
| 23 ASSERT_TRUE(parsed_update); | |
| 24 EXPECT_EQ(USER_PRESENT, parsed_update->user_presence); | |
| 25 EXPECT_EQ(SECURE_SCREEN_LOCK_ENABLED, | |
| 26 parsed_update->secure_screen_lock_state); | |
| 27 EXPECT_EQ(TRUST_AGENT_ENABLED, parsed_update->trust_agent_state); | |
| 28 } | |
| 29 | |
| 30 { | |
| 31 const char kValidJson[] = | |
| 32 "{" | |
| 33 " \"type\": \"status_update\"," | |
| 34 " \"user_presence\": \"absent\"," | |
| 35 " \"secure_screen_lock\": \"disabled\"," | |
| 36 " \"trust_agent\": \"disabled\"" | |
| 37 "}"; | |
| 38 scoped_ptr<RemoteStatusUpdate> parsed_update = | |
| 39 RemoteStatusUpdate::FromJson(kValidJson); | |
| 40 ASSERT_TRUE(parsed_update); | |
| 41 EXPECT_EQ(USER_ABSENT, parsed_update->user_presence); | |
| 42 EXPECT_EQ(SECURE_SCREEN_LOCK_DISABLED, | |
| 43 parsed_update->secure_screen_lock_state); | |
| 44 EXPECT_EQ(TRUST_AGENT_DISABLED, parsed_update->trust_agent_state); | |
| 45 } | |
| 46 | |
| 47 { | |
| 48 const char kValidJson[] = | |
| 49 "{" | |
| 50 " \"type\": \"status_update\"," | |
| 51 " \"user_presence\": \"unknown\"," | |
| 52 " \"secure_screen_lock\": \"unknown\"," | |
| 53 " \"trust_agent\": \"unsupported\"" | |
| 54 "}"; | |
| 55 scoped_ptr<RemoteStatusUpdate> parsed_update = | |
| 56 RemoteStatusUpdate::FromJson(kValidJson); | |
| 57 ASSERT_TRUE(parsed_update); | |
| 58 EXPECT_EQ(USER_PRESENCE_UNKNOWN, parsed_update->user_presence); | |
| 59 EXPECT_EQ(SECURE_SCREEN_LOCK_STATE_UNKNOWN, | |
| 60 parsed_update->secure_screen_lock_state); | |
| 61 EXPECT_EQ(TRUST_AGENT_UNSUPPORTED, parsed_update->trust_agent_state); | |
| 62 } | |
| 63 } | |
| 64 | |
| 65 TEST(ProximityAuthRemoteStatusUpdateTest, FromJson_InvalidJson) { | |
| 66 const char kJson[] = | |
| 67 "{" | |
| 68 " \"type\": \"status_update\"," | |
| 69 " \"user_presence\": \"present\"," | |
| 70 " \"secure_screen_lock\": \"enabled\"," | |
| 71 " \"trust_agent\": \"enabled\"," // Note the invalid trailing comma. | |
| 72 "}"; | |
| 73 scoped_ptr<RemoteStatusUpdate> parsed_update = | |
| 74 RemoteStatusUpdate::FromJson(kJson); | |
| 75 EXPECT_FALSE(parsed_update); | |
| 76 } | |
| 77 | |
| 78 TEST(ProximityAuthRemoteStatusUpdateTest, FromJson_InvalidType) { | |
| 79 const char kJson[] = | |
| 80 "{" | |
| 81 " \"type\": \"garbage\"," | |
| 82 " \"user_presence\": \"present\"," | |
| 83 " \"secure_screen_lock\": \"enabled\"," | |
| 84 " \"trust_agent\": \"enabled\"" | |
| 85 "}"; | |
| 86 scoped_ptr<RemoteStatusUpdate> parsed_update = | |
| 87 RemoteStatusUpdate::FromJson(kJson); | |
| 88 EXPECT_FALSE(parsed_update); | |
| 89 } | |
| 90 | |
| 91 TEST(ProximityAuthRemoteStatusUpdateTest, FromJson_MissingValue) { | |
| 92 { | |
| 93 const char kJson[] = | |
| 94 "{" | |
| 95 " \"type\": \"status_update\"," | |
| 96 " \"secure_screen_lock\": \"enabled\"," | |
| 97 " \"trust_agent\": \"enabled\"" | |
| 98 "}"; | |
| 99 scoped_ptr<RemoteStatusUpdate> parsed_update = | |
| 100 RemoteStatusUpdate::FromJson(kJson); | |
| 101 EXPECT_FALSE(parsed_update); | |
| 102 } | |
| 103 | |
| 104 { | |
| 105 const char kJson[] = | |
| 106 "{" | |
| 107 " \"type\": \"status_update\"," | |
| 108 " \"user_presence\": \"present\"," | |
| 109 " \"trust_agent\": \"enabled\"" | |
| 110 "}"; | |
| 111 scoped_ptr<RemoteStatusUpdate> parsed_update = | |
| 112 RemoteStatusUpdate::FromJson(kJson); | |
| 113 EXPECT_FALSE(parsed_update); | |
| 114 } | |
| 115 | |
| 116 { | |
| 117 const char kJson[] = | |
| 118 "{" | |
| 119 " \"type\": \"status_update\"," | |
| 120 " \"user_presence\": \"present\"," | |
| 121 " \"secure_screen_lock\": \"enabled\"" | |
| 122 "}"; | |
| 123 scoped_ptr<RemoteStatusUpdate> parsed_update = | |
| 124 RemoteStatusUpdate::FromJson(kJson); | |
| 125 EXPECT_FALSE(parsed_update); | |
| 126 } | |
| 127 } | |
| 128 | |
| 129 TEST(ProximityAuthRemoteStatusUpdateTest, FromJson_InvalidValues) { | |
| 130 { | |
| 131 const char kJson[] = | |
| 132 "{" | |
| 133 " \"type\": \"status_update\"," | |
| 134 " \"user_presence\": \"garbage\"," | |
| 135 " \"secure_screen_lock\": \"enabled\"," | |
| 136 " \"trust_agent\": \"enabled\"" | |
| 137 "}"; | |
| 138 scoped_ptr<RemoteStatusUpdate> parsed_update = | |
| 139 RemoteStatusUpdate::FromJson(kJson); | |
| 140 EXPECT_FALSE(parsed_update); | |
| 141 } | |
| 142 | |
| 143 { | |
| 144 const char kJson[] = | |
| 145 "{" | |
| 146 " \"type\": \"status_update\"," | |
| 147 " \"user_presence\": \"present\"," | |
| 148 " \"secure_screen_lock\": \"garbage\"," | |
| 149 " \"trust_agent\": \"enabled\"" | |
| 150 "}"; | |
| 151 scoped_ptr<RemoteStatusUpdate> parsed_update = | |
| 152 RemoteStatusUpdate::FromJson(kJson); | |
| 153 EXPECT_FALSE(parsed_update); | |
| 154 } | |
| 155 | |
| 156 { | |
| 157 const char kJson[] = | |
| 158 "{" | |
| 159 " \"type\": \"status_update\"," | |
| 160 " \"user_presence\": \"present\"," | |
| 161 " \"secure_screen_lock\": \"enabled\"," | |
| 162 " \"trust_agent\": \"garbage\"" | |
| 163 "}"; | |
| 164 scoped_ptr<RemoteStatusUpdate> parsed_update = | |
| 165 RemoteStatusUpdate::FromJson(kJson); | |
| 166 EXPECT_FALSE(parsed_update); | |
| 167 } | |
| 168 } | |
| 169 | |
| 170 } // namespace proximity_auth | |
| OLD | NEW |