Remove object schema parsing in state definition

State definition schema is no longer parsed by libweave for semantic
understanding. We just keep it around for clients who explicitly
as for it, but we no longer use the schema to validate the state
values. They are now stored as an opaque JSON object.

BUG: 25841230

Change-Id: Ib54b3d1f52dd8c63e9fa74afc174adeb5ca56d4d
Reviewed-on: https://weave-review.googlesource.com/1627
Reviewed-by: Vitaly Buka <vitalybuka@google.com>
diff --git a/src/states/state_change_queue_unittest.cc b/src/states/state_change_queue_unittest.cc
index 9f26071..5fbc012 100644
--- a/src/states/state_change_queue_unittest.cc
+++ b/src/states/state_change_queue_unittest.cc
@@ -11,6 +11,8 @@
 
 namespace weave {
 
+using test::CreateDictionaryValue;
+
 class StateChangeQueueTest : public ::testing::Test {
  public:
   void SetUp() override { queue_.reset(new StateChangeQueue(100)); }
@@ -27,43 +29,39 @@
 }
 
 TEST_F(StateChangeQueueTest, UpdateOne) {
-  StateChange change{base::Time::Now(),
-                     ValueMap{{"prop.name", test::make_int_prop_value(23)}}};
-  ASSERT_TRUE(queue_->NotifyPropertiesUpdated(change.timestamp,
-                                              change.changed_properties));
+  auto timestamp = base::Time::Now();
+  ASSERT_TRUE(queue_->NotifyPropertiesUpdated(
+      timestamp, CreateDictionaryValue("{'prop': {'name': 23}}")));
   EXPECT_FALSE(queue_->IsEmpty());
   EXPECT_EQ(1, queue_->GetLastStateChangeId());
   auto changes = queue_->GetAndClearRecordedStateChanges();
   EXPECT_EQ(1, queue_->GetLastStateChangeId());
   ASSERT_EQ(1, changes.size());
-  EXPECT_EQ(change.timestamp, changes.front().timestamp);
-  EXPECT_EQ(change.changed_properties, changes.front().changed_properties);
+  EXPECT_EQ(timestamp, changes.front().timestamp);
+  EXPECT_JSON_EQ("{'prop':{'name': 23}}", *changes.front().changed_properties);
   EXPECT_TRUE(queue_->IsEmpty());
   EXPECT_TRUE(queue_->GetAndClearRecordedStateChanges().empty());
 }
 
-// TODO(vitalybuka): Fix flakiness.
-TEST_F(StateChangeQueueTest, DISABLED_UpdateMany) {
-  StateChange change1{base::Time::Now(),
-                      ValueMap{{"prop.name1", test::make_int_prop_value(23)}}};
-  ASSERT_TRUE(queue_->NotifyPropertiesUpdated(change1.timestamp,
-                                              change1.changed_properties));
-  StateChange change2{base::Time::Now(),
-                      ValueMap{
-                          {"prop.name1", test::make_int_prop_value(17)},
-                          {"prop.name2", test::make_double_prop_value(1.0)},
-                          {"prop.name3", test::make_bool_prop_value(false)},
-                      }};
-  ASSERT_TRUE(queue_->NotifyPropertiesUpdated(change2.timestamp,
-                                              change2.changed_properties));
+TEST_F(StateChangeQueueTest, UpdateMany) {
+  auto timestamp1 = base::Time::Now();
+  const std::string state1 = "{'prop': {'name1': 23}}";
+  auto timestamp2 = timestamp1 + base::TimeDelta::FromSeconds(1);
+  const std::string state2 =
+      "{'prop': {'name1': 17, 'name2': 1.0, 'name3': false}}";
+  ASSERT_TRUE(queue_->NotifyPropertiesUpdated(
+      timestamp1, CreateDictionaryValue(state1)));
+  ASSERT_TRUE(queue_->NotifyPropertiesUpdated(
+      timestamp2, CreateDictionaryValue(state2)));
+
   EXPECT_EQ(2, queue_->GetLastStateChangeId());
   EXPECT_FALSE(queue_->IsEmpty());
   auto changes = queue_->GetAndClearRecordedStateChanges();
   ASSERT_EQ(2, changes.size());
-  EXPECT_EQ(change1.timestamp, changes[0].timestamp);
-  EXPECT_EQ(change1.changed_properties, changes[0].changed_properties);
-  EXPECT_EQ(change2.timestamp, changes[1].timestamp);
-  EXPECT_EQ(change2.changed_properties, changes[1].changed_properties);
+  EXPECT_EQ(timestamp1, changes[0].timestamp);
+  EXPECT_JSON_EQ(state1, *changes[0].changed_properties);
+  EXPECT_EQ(timestamp2, changes[1].timestamp);
+  EXPECT_JSON_EQ(state2, *changes[1].changed_properties);
   EXPECT_TRUE(queue_->IsEmpty());
   EXPECT_TRUE(queue_->GetAndClearRecordedStateChanges().empty());
 }
@@ -73,33 +71,27 @@
   base::TimeDelta time_delta = base::TimeDelta::FromMinutes(1);
 
   ASSERT_TRUE(queue_->NotifyPropertiesUpdated(
-      timestamp, ValueMap{{"prop.name1", test::make_int_prop_value(1)}}));
+      timestamp, CreateDictionaryValue("{'prop': {'name1': 1}}")));
 
   ASSERT_TRUE(queue_->NotifyPropertiesUpdated(
-      timestamp, ValueMap{{"prop.name2", test::make_int_prop_value(2)}}));
+      timestamp, CreateDictionaryValue("{'prop': {'name2': 2}}")));
 
   ASSERT_TRUE(queue_->NotifyPropertiesUpdated(
-      timestamp, ValueMap{{"prop.name1", test::make_int_prop_value(3)}}));
+      timestamp, CreateDictionaryValue("{'prop': {'name1': 3}}")));
 
   ASSERT_TRUE(queue_->NotifyPropertiesUpdated(
-      timestamp + time_delta,
-      ValueMap{{"prop.name1", test::make_int_prop_value(4)}}));
+      timestamp + time_delta, CreateDictionaryValue("{'prop': {'name1': 4}}")));
 
   auto changes = queue_->GetAndClearRecordedStateChanges();
   EXPECT_EQ(4, queue_->GetLastStateChangeId());
   ASSERT_EQ(2, changes.size());
 
-  ValueMap expected1{
-      {"prop.name1", test::make_int_prop_value(3)},
-      {"prop.name2", test::make_int_prop_value(2)},
-  };
-  ValueMap expected2{
-      {"prop.name1", test::make_int_prop_value(4)},
-  };
+  const std::string expected1 = "{'prop': {'name1': 3, 'name2': 2}}";
+  const std::string expected2 = "{'prop': {'name1': 4}}";
   EXPECT_EQ(timestamp, changes[0].timestamp);
-  EXPECT_EQ(expected1, changes[0].changed_properties);
+  EXPECT_JSON_EQ(expected1, *changes[0].changed_properties);
   EXPECT_EQ(timestamp + time_delta, changes[1].timestamp);
-  EXPECT_EQ(expected2, changes[1].changed_properties);
+  EXPECT_JSON_EQ(expected2, *changes[1].changed_properties);
 }
 
 TEST_F(StateChangeQueueTest, MaxQueueSize) {
@@ -109,43 +101,29 @@
   base::TimeDelta time_delta2 = base::TimeDelta::FromMinutes(3);
 
   ASSERT_TRUE(queue_->NotifyPropertiesUpdated(
-      start_time, ValueMap{
-                      {"prop.name1", test::make_int_prop_value(1)},
-                      {"prop.name2", test::make_int_prop_value(2)},
-                  }));
+      start_time, CreateDictionaryValue("{'prop': {'name1': 1, 'name2': 2}}")));
 
   ASSERT_TRUE(queue_->NotifyPropertiesUpdated(
       start_time + time_delta1,
-      ValueMap{
-          {"prop.name1", test::make_int_prop_value(3)},
-          {"prop.name3", test::make_int_prop_value(4)},
-      }));
+      CreateDictionaryValue("{'prop': {'name1': 3, 'name3': 4}}")));
 
   ASSERT_TRUE(queue_->NotifyPropertiesUpdated(
       start_time + time_delta2,
-      ValueMap{
-          {"prop.name10", test::make_int_prop_value(10)},
-          {"prop.name11", test::make_int_prop_value(11)},
-      }));
+      CreateDictionaryValue("{'prop': {'name10': 10, 'name11': 11}}")));
 
   EXPECT_EQ(3, queue_->GetLastStateChangeId());
   auto changes = queue_->GetAndClearRecordedStateChanges();
   ASSERT_EQ(2, changes.size());
 
-  ValueMap expected1{
-      {"prop.name1", test::make_int_prop_value(3)},
-      {"prop.name2", test::make_int_prop_value(2)},
-      {"prop.name3", test::make_int_prop_value(4)},
-  };
+  const std::string expected1 =
+      "{'prop': {'name1': 3, 'name2': 2, 'name3': 4}}";
   EXPECT_EQ(start_time + time_delta1, changes[0].timestamp);
-  EXPECT_EQ(expected1, changes[0].changed_properties);
+  EXPECT_JSON_EQ(expected1, *changes[0].changed_properties);
 
-  ValueMap expected2{
-      {"prop.name10", test::make_int_prop_value(10)},
-      {"prop.name11", test::make_int_prop_value(11)},
-  };
+  const std::string expected2 =
+      "{'prop': {'name10': 10, 'name11': 11}}";
   EXPECT_EQ(start_time + time_delta2, changes[1].timestamp);
-  EXPECT_EQ(expected2, changes[1].changed_properties);
+  EXPECT_JSON_EQ(expected2, *changes[1].changed_properties);
 }
 
 TEST_F(StateChangeQueueTest, ImmediateStateChangeNotification) {
@@ -161,10 +139,8 @@
 TEST_F(StateChangeQueueTest, DelayedStateChangeNotification) {
   // When queue is not empty, registering a new callback will not trigger it.
   ASSERT_TRUE(queue_->NotifyPropertiesUpdated(
-      base::Time::Now(), ValueMap{
-                             {"prop.name1", test::make_int_prop_value(1)},
-                             {"prop.name2", test::make_int_prop_value(2)},
-                         }));
+      base::Time::Now(),
+      CreateDictionaryValue("{'prop': {'name1': 1, 'name3': 2}}")));
 
   auto callback = [](StateChangeQueueInterface::UpdateID id) {
     FAIL() << "This should not be called";