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

Side by Side Diff: components/proximity_auth/remote_status_update_unittest.cc

Issue 629183003: [Easy Unlock] Port RemoteStatusUpdate class to native code. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Pass base::DictionaryValue rather than std::string for deserializing Created 6 years, 2 months 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/proximity_auth/remote_status_update.cc ('k') | no next file » | 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/proximity_auth/remote_status_update.h"
6
7 #include "base/json/json_reader.h"
8 #include "base/values.h"
9 #include "testing/gtest/include/gtest/gtest.h"
10
11 namespace proximity_auth {
12 namespace {
13
14 // Parses the |json| into a DictionaryValue.
15 scoped_ptr<base::DictionaryValue> ParseJson(const std::string& json) {
16 base::DictionaryValue* as_dictionary;
17 base::JSONReader::Read(json)->GetAsDictionary(&as_dictionary);
18 return make_scoped_ptr(as_dictionary);
19 }
20
21 } // namespace
22
23 // Verify that all valid values can be parsed.
24 TEST(ProximityAuthRemoteStatusUpdateTest, Deserialize_ValidStatuses) {
25 {
26 const char kValidJson[] =
27 "{"
28 " \"type\": \"status_update\","
29 " \"user_presence\": \"present\","
30 " \"secure_screen_lock\": \"enabled\","
31 " \"trust_agent\": \"enabled\""
32 "}";
33 scoped_ptr<RemoteStatusUpdate> parsed_update =
34 RemoteStatusUpdate::Deserialize(*ParseJson(kValidJson));
35 ASSERT_TRUE(parsed_update);
36 EXPECT_EQ(USER_PRESENT, parsed_update->user_presence);
37 EXPECT_EQ(SECURE_SCREEN_LOCK_ENABLED,
38 parsed_update->secure_screen_lock_state);
39 EXPECT_EQ(TRUST_AGENT_ENABLED, parsed_update->trust_agent_state);
40 }
41
42 {
43 const char kValidJson[] =
44 "{"
45 " \"type\": \"status_update\","
46 " \"user_presence\": \"absent\","
47 " \"secure_screen_lock\": \"disabled\","
48 " \"trust_agent\": \"disabled\""
49 "}";
50 scoped_ptr<RemoteStatusUpdate> parsed_update =
51 RemoteStatusUpdate::Deserialize(*ParseJson(kValidJson));
52 ASSERT_TRUE(parsed_update);
53 EXPECT_EQ(USER_ABSENT, parsed_update->user_presence);
54 EXPECT_EQ(SECURE_SCREEN_LOCK_DISABLED,
55 parsed_update->secure_screen_lock_state);
56 EXPECT_EQ(TRUST_AGENT_DISABLED, parsed_update->trust_agent_state);
57 }
58
59 {
60 const char kValidJson[] =
61 "{"
62 " \"type\": \"status_update\","
63 " \"user_presence\": \"unknown\","
64 " \"secure_screen_lock\": \"unknown\","
65 " \"trust_agent\": \"unsupported\""
66 "}";
67 scoped_ptr<RemoteStatusUpdate> parsed_update =
68 RemoteStatusUpdate::Deserialize(*ParseJson(kValidJson));
69 ASSERT_TRUE(parsed_update);
70 EXPECT_EQ(USER_PRESENCE_UNKNOWN, parsed_update->user_presence);
71 EXPECT_EQ(SECURE_SCREEN_LOCK_STATE_UNKNOWN,
72 parsed_update->secure_screen_lock_state);
73 EXPECT_EQ(TRUST_AGENT_UNSUPPORTED, parsed_update->trust_agent_state);
74 }
75 }
76
77 TEST(ProximityAuthRemoteStatusUpdateTest, Deserialize_InvalidType) {
78 const char kJson[] =
79 "{"
80 " \"type\": \"garbage\","
81 " \"user_presence\": \"present\","
82 " \"secure_screen_lock\": \"enabled\","
83 " \"trust_agent\": \"enabled\""
84 "}";
85 scoped_ptr<RemoteStatusUpdate> parsed_update =
86 RemoteStatusUpdate::Deserialize(*ParseJson(kJson));
87 EXPECT_FALSE(parsed_update);
88 }
89
90 TEST(ProximityAuthRemoteStatusUpdateTest, Deserialize_MissingValue) {
91 {
92 const char kJson[] =
93 "{"
94 " \"type\": \"status_update\","
95 " \"secure_screen_lock\": \"enabled\","
96 " \"trust_agent\": \"enabled\""
97 "}";
98 scoped_ptr<RemoteStatusUpdate> parsed_update =
99 RemoteStatusUpdate::Deserialize(*ParseJson(kJson));
100 EXPECT_FALSE(parsed_update);
101 }
102
103 {
104 const char kJson[] =
105 "{"
106 " \"type\": \"status_update\","
107 " \"user_presence\": \"present\","
108 " \"trust_agent\": \"enabled\""
109 "}";
110 scoped_ptr<RemoteStatusUpdate> parsed_update =
111 RemoteStatusUpdate::Deserialize(*ParseJson(kJson));
112 EXPECT_FALSE(parsed_update);
113 }
114
115 {
116 const char kJson[] =
117 "{"
118 " \"type\": \"status_update\","
119 " \"user_presence\": \"present\","
120 " \"secure_screen_lock\": \"enabled\""
121 "}";
122 scoped_ptr<RemoteStatusUpdate> parsed_update =
123 RemoteStatusUpdate::Deserialize(*ParseJson(kJson));
124 EXPECT_FALSE(parsed_update);
125 }
126 }
127
128 TEST(ProximityAuthRemoteStatusUpdateTest, Deserialize_InvalidValues) {
129 {
130 const char kJson[] =
131 "{"
132 " \"type\": \"status_update\","
133 " \"user_presence\": \"garbage\","
134 " \"secure_screen_lock\": \"enabled\","
135 " \"trust_agent\": \"enabled\""
136 "}";
137 scoped_ptr<RemoteStatusUpdate> parsed_update =
138 RemoteStatusUpdate::Deserialize(*ParseJson(kJson));
139 EXPECT_FALSE(parsed_update);
140 }
141
142 {
143 const char kJson[] =
144 "{"
145 " \"type\": \"status_update\","
146 " \"user_presence\": \"present\","
147 " \"secure_screen_lock\": \"garbage\","
148 " \"trust_agent\": \"enabled\""
149 "}";
150 scoped_ptr<RemoteStatusUpdate> parsed_update =
151 RemoteStatusUpdate::Deserialize(*ParseJson(kJson));
152 EXPECT_FALSE(parsed_update);
153 }
154
155 {
156 const char kJson[] =
157 "{"
158 " \"type\": \"status_update\","
159 " \"user_presence\": \"present\","
160 " \"secure_screen_lock\": \"enabled\","
161 " \"trust_agent\": \"garbage\""
162 "}";
163 scoped_ptr<RemoteStatusUpdate> parsed_update =
164 RemoteStatusUpdate::Deserialize(*ParseJson(kJson));
165 EXPECT_FALSE(parsed_update);
166 }
167 }
168
169 // Verify that extra fields do not prevent parsing. This provides
170 // forward-compatibility.
171 TEST(ProximityAuthRemoteStatusUpdateTest,
172 Deserialize_ValidStatusWithExtraFields) {
173 const char kJson[] =
174 "{"
175 " \"type\": \"status_update\","
176 " \"user_presence\": \"present\","
177 " \"secure_screen_lock\": \"enabled\","
178 " \"trust_agent\": \"enabled\","
179 " \"secret_sauce\": \"chipotle\""
180 "}";
181 scoped_ptr<RemoteStatusUpdate> parsed_update =
182 RemoteStatusUpdate::Deserialize(*ParseJson(kJson));
183 ASSERT_TRUE(parsed_update);
184 EXPECT_EQ(USER_PRESENT, parsed_update->user_presence);
185 EXPECT_EQ(SECURE_SCREEN_LOCK_ENABLED,
186 parsed_update->secure_screen_lock_state);
187 EXPECT_EQ(TRUST_AGENT_ENABLED, parsed_update->trust_agent_state);
188 }
189
190 } // namespace proximity_auth
OLDNEW
« no previous file with comments | « components/proximity_auth/remote_status_update.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698