Index: components/proximity_auth/remote_status_update_unittest.cc |
diff --git a/components/proximity_auth/remote_status_update_unittest.cc b/components/proximity_auth/remote_status_update_unittest.cc |
new file mode 100644 |
index 0000000000000000000000000000000000000000..092c7e5075fb083d4df655704f7752c7db587653 |
--- /dev/null |
+++ b/components/proximity_auth/remote_status_update_unittest.cc |
@@ -0,0 +1,170 @@ |
+// Copyright 2014 The Chromium Authors. All rights reserved. |
+// Use of this source code is governed by a BSD-style license that can be |
+// found in the LICENSE file. |
+ |
+#include "components/proximity_auth/remote_status_update.h" |
+ |
+#include "testing/gtest/include/gtest/gtest.h" |
+ |
+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.
|
+ |
+// Verify that all valid values can be parsed. |
+TEST(ProximityAuthRemoteStatusUpdateTest, FromJson_ValidStatuses) { |
+ { |
+ const char kValidJson[] = |
+ "{" |
+ " \"type\": \"status_update\"," |
+ " \"user_presence\": \"present\"," |
+ " \"secure_screen_lock\": \"enabled\"," |
+ " \"trust_agent\": \"enabled\"" |
+ "}"; |
+ scoped_ptr<RemoteStatusUpdate> parsed_update = |
+ RemoteStatusUpdate::FromJson(kValidJson); |
+ ASSERT_TRUE(parsed_update); |
+ EXPECT_EQ(USER_PRESENT, parsed_update->user_presence); |
+ EXPECT_EQ(SECURE_SCREEN_LOCK_ENABLED, |
+ parsed_update->secure_screen_lock_state); |
+ EXPECT_EQ(TRUST_AGENT_ENABLED, parsed_update->trust_agent_state); |
+ } |
+ |
+ { |
+ const char kValidJson[] = |
+ "{" |
+ " \"type\": \"status_update\"," |
+ " \"user_presence\": \"absent\"," |
+ " \"secure_screen_lock\": \"disabled\"," |
+ " \"trust_agent\": \"disabled\"" |
+ "}"; |
+ scoped_ptr<RemoteStatusUpdate> parsed_update = |
+ RemoteStatusUpdate::FromJson(kValidJson); |
+ ASSERT_TRUE(parsed_update); |
+ EXPECT_EQ(USER_ABSENT, parsed_update->user_presence); |
+ EXPECT_EQ(SECURE_SCREEN_LOCK_DISABLED, |
+ parsed_update->secure_screen_lock_state); |
+ EXPECT_EQ(TRUST_AGENT_DISABLED, parsed_update->trust_agent_state); |
+ } |
+ |
+ { |
+ const char kValidJson[] = |
+ "{" |
+ " \"type\": \"status_update\"," |
+ " \"user_presence\": \"unknown\"," |
+ " \"secure_screen_lock\": \"unknown\"," |
+ " \"trust_agent\": \"unsupported\"" |
+ "}"; |
+ scoped_ptr<RemoteStatusUpdate> parsed_update = |
+ RemoteStatusUpdate::FromJson(kValidJson); |
+ ASSERT_TRUE(parsed_update); |
+ EXPECT_EQ(USER_PRESENCE_UNKNOWN, parsed_update->user_presence); |
+ EXPECT_EQ(SECURE_SCREEN_LOCK_STATE_UNKNOWN, |
+ parsed_update->secure_screen_lock_state); |
+ EXPECT_EQ(TRUST_AGENT_UNSUPPORTED, parsed_update->trust_agent_state); |
+ } |
+} |
+ |
+TEST(ProximityAuthRemoteStatusUpdateTest, FromJson_InvalidJson) { |
+ const char kJson[] = |
+ "{" |
+ " \"type\": \"status_update\"," |
+ " \"user_presence\": \"present\"," |
+ " \"secure_screen_lock\": \"enabled\"," |
+ " \"trust_agent\": \"enabled\"," // Note the invalid trailing comma. |
+ "}"; |
+ scoped_ptr<RemoteStatusUpdate> parsed_update = |
+ RemoteStatusUpdate::FromJson(kJson); |
+ EXPECT_FALSE(parsed_update); |
+} |
+ |
+TEST(ProximityAuthRemoteStatusUpdateTest, FromJson_InvalidType) { |
+ const char kJson[] = |
+ "{" |
+ " \"type\": \"garbage\"," |
+ " \"user_presence\": \"present\"," |
+ " \"secure_screen_lock\": \"enabled\"," |
+ " \"trust_agent\": \"enabled\"" |
+ "}"; |
+ scoped_ptr<RemoteStatusUpdate> parsed_update = |
+ RemoteStatusUpdate::FromJson(kJson); |
+ EXPECT_FALSE(parsed_update); |
+} |
+ |
+TEST(ProximityAuthRemoteStatusUpdateTest, FromJson_MissingValue) { |
+ { |
+ const char kJson[] = |
+ "{" |
+ " \"type\": \"status_update\"," |
+ " \"secure_screen_lock\": \"enabled\"," |
+ " \"trust_agent\": \"enabled\"" |
+ "}"; |
+ scoped_ptr<RemoteStatusUpdate> parsed_update = |
+ RemoteStatusUpdate::FromJson(kJson); |
+ EXPECT_FALSE(parsed_update); |
+ } |
+ |
+ { |
+ const char kJson[] = |
+ "{" |
+ " \"type\": \"status_update\"," |
+ " \"user_presence\": \"present\"," |
+ " \"trust_agent\": \"enabled\"" |
+ "}"; |
+ scoped_ptr<RemoteStatusUpdate> parsed_update = |
+ RemoteStatusUpdate::FromJson(kJson); |
+ EXPECT_FALSE(parsed_update); |
+ } |
+ |
+ { |
+ const char kJson[] = |
+ "{" |
+ " \"type\": \"status_update\"," |
+ " \"user_presence\": \"present\"," |
+ " \"secure_screen_lock\": \"enabled\"" |
+ "}"; |
+ scoped_ptr<RemoteStatusUpdate> parsed_update = |
+ RemoteStatusUpdate::FromJson(kJson); |
+ EXPECT_FALSE(parsed_update); |
+ } |
+} |
+ |
+TEST(ProximityAuthRemoteStatusUpdateTest, FromJson_InvalidValues) { |
+ { |
+ const char kJson[] = |
+ "{" |
+ " \"type\": \"status_update\"," |
+ " \"user_presence\": \"garbage\"," |
+ " \"secure_screen_lock\": \"enabled\"," |
+ " \"trust_agent\": \"enabled\"" |
+ "}"; |
+ scoped_ptr<RemoteStatusUpdate> parsed_update = |
+ RemoteStatusUpdate::FromJson(kJson); |
+ EXPECT_FALSE(parsed_update); |
+ } |
+ |
+ { |
+ const char kJson[] = |
+ "{" |
+ " \"type\": \"status_update\"," |
+ " \"user_presence\": \"present\"," |
+ " \"secure_screen_lock\": \"garbage\"," |
+ " \"trust_agent\": \"enabled\"" |
+ "}"; |
+ scoped_ptr<RemoteStatusUpdate> parsed_update = |
+ RemoteStatusUpdate::FromJson(kJson); |
+ EXPECT_FALSE(parsed_update); |
+ } |
+ |
+ { |
+ const char kJson[] = |
+ "{" |
+ " \"type\": \"status_update\"," |
+ " \"user_presence\": \"present\"," |
+ " \"secure_screen_lock\": \"enabled\"," |
+ " \"trust_agent\": \"garbage\"" |
+ "}"; |
+ scoped_ptr<RemoteStatusUpdate> parsed_update = |
+ RemoteStatusUpdate::FromJson(kJson); |
+ EXPECT_FALSE(parsed_update); |
+ } |
+} |
+ |
+} // namespace proximity_auth |