| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "sync/internal_api/public/engine/model_safe_worker.h" | 5 #include "sync/internal_api/public/engine/model_safe_worker.h" |
| 6 | 6 |
| 7 #include "base/memory/scoped_ptr.h" | 7 #include "base/memory/scoped_ptr.h" |
| 8 #include "base/values.h" | 8 #include "base/values.h" |
| 9 #include "testing/gtest/include/gtest/gtest.h" | 9 #include "testing/gtest/include/gtest/gtest.h" |
| 10 | 10 |
| 11 namespace syncer { | 11 namespace syncer { |
| 12 namespace { | 12 namespace { |
| 13 | 13 |
| 14 class ModelSafeWorkerTest : public ::testing::Test { | 14 class ModelSafeWorkerTest : public ::testing::Test { |
| 15 }; | 15 }; |
| 16 | 16 |
| 17 TEST_F(ModelSafeWorkerTest, ModelSafeRoutingInfoToValue) { | 17 TEST_F(ModelSafeWorkerTest, ModelSafeRoutingInfoToValue) { |
| 18 ModelSafeRoutingInfo routing_info; | 18 ModelSafeRoutingInfo routing_info; |
| 19 routing_info[syncer::BOOKMARKS] = GROUP_PASSIVE; | 19 routing_info[BOOKMARKS] = GROUP_PASSIVE; |
| 20 routing_info[syncer::NIGORI] = GROUP_UI; | 20 routing_info[NIGORI] = GROUP_UI; |
| 21 routing_info[syncer::PREFERENCES] = GROUP_DB; | 21 routing_info[PREFERENCES] = GROUP_DB; |
| 22 DictionaryValue expected_value; | 22 DictionaryValue expected_value; |
| 23 expected_value.SetString("Bookmarks", "GROUP_PASSIVE"); | 23 expected_value.SetString("Bookmarks", "GROUP_PASSIVE"); |
| 24 expected_value.SetString("Encryption keys", "GROUP_UI"); | 24 expected_value.SetString("Encryption keys", "GROUP_UI"); |
| 25 expected_value.SetString("Preferences", "GROUP_DB"); | 25 expected_value.SetString("Preferences", "GROUP_DB"); |
| 26 scoped_ptr<DictionaryValue> value( | 26 scoped_ptr<DictionaryValue> value( |
| 27 ModelSafeRoutingInfoToValue(routing_info)); | 27 ModelSafeRoutingInfoToValue(routing_info)); |
| 28 EXPECT_TRUE(value->Equals(&expected_value)); | 28 EXPECT_TRUE(value->Equals(&expected_value)); |
| 29 } | 29 } |
| 30 | 30 |
| 31 TEST_F(ModelSafeWorkerTest, ModelSafeRoutingInfoToString) { | 31 TEST_F(ModelSafeWorkerTest, ModelSafeRoutingInfoToString) { |
| 32 ModelSafeRoutingInfo routing_info; | 32 ModelSafeRoutingInfo routing_info; |
| 33 routing_info[syncer::BOOKMARKS] = GROUP_PASSIVE; | 33 routing_info[BOOKMARKS] = GROUP_PASSIVE; |
| 34 routing_info[syncer::NIGORI] = GROUP_UI; | 34 routing_info[NIGORI] = GROUP_UI; |
| 35 routing_info[syncer::PREFERENCES] = GROUP_DB; | 35 routing_info[PREFERENCES] = GROUP_DB; |
| 36 EXPECT_EQ( | 36 EXPECT_EQ( |
| 37 "{\"Bookmarks\":\"GROUP_PASSIVE\",\"Encryption keys\":\"GROUP_UI\"," | 37 "{\"Bookmarks\":\"GROUP_PASSIVE\",\"Encryption keys\":\"GROUP_UI\"," |
| 38 "\"Preferences\":\"GROUP_DB\"}", | 38 "\"Preferences\":\"GROUP_DB\"}", |
| 39 ModelSafeRoutingInfoToString(routing_info)); | 39 ModelSafeRoutingInfoToString(routing_info)); |
| 40 } | 40 } |
| 41 | 41 |
| 42 TEST_F(ModelSafeWorkerTest, GetRoutingInfoTypes) { | 42 TEST_F(ModelSafeWorkerTest, GetRoutingInfoTypes) { |
| 43 ModelSafeRoutingInfo routing_info; | 43 ModelSafeRoutingInfo routing_info; |
| 44 routing_info[syncer::BOOKMARKS] = GROUP_PASSIVE; | 44 routing_info[BOOKMARKS] = GROUP_PASSIVE; |
| 45 routing_info[syncer::NIGORI] = GROUP_UI; | 45 routing_info[NIGORI] = GROUP_UI; |
| 46 routing_info[syncer::PREFERENCES] = GROUP_DB; | 46 routing_info[PREFERENCES] = GROUP_DB; |
| 47 const syncer::ModelTypeSet expected_types( | 47 const ModelTypeSet expected_types(BOOKMARKS, NIGORI, PREFERENCES); |
| 48 syncer::BOOKMARKS, | |
| 49 syncer::NIGORI, | |
| 50 syncer::PREFERENCES); | |
| 51 EXPECT_TRUE(GetRoutingInfoTypes(routing_info).Equals(expected_types)); | 48 EXPECT_TRUE(GetRoutingInfoTypes(routing_info).Equals(expected_types)); |
| 52 } | 49 } |
| 53 | 50 |
| 54 TEST_F(ModelSafeWorkerTest, ModelSafeRoutingInfoToPayloadMap) { | 51 TEST_F(ModelSafeWorkerTest, ModelSafeRoutingInfoToPayloadMap) { |
| 55 std::string payload = "test"; | 52 std::string payload = "test"; |
| 56 ModelSafeRoutingInfo routing_info; | 53 ModelSafeRoutingInfo routing_info; |
| 57 routing_info[syncer::BOOKMARKS] = GROUP_PASSIVE; | 54 routing_info[BOOKMARKS] = GROUP_PASSIVE; |
| 58 routing_info[syncer::NIGORI] = GROUP_UI; | 55 routing_info[NIGORI] = GROUP_UI; |
| 59 routing_info[syncer::PREFERENCES] = GROUP_DB; | 56 routing_info[PREFERENCES] = GROUP_DB; |
| 60 syncer::ModelTypePayloadMap types_with_payloads = | 57 ModelTypePayloadMap types_with_payloads = |
| 61 ModelSafeRoutingInfoToPayloadMap(routing_info, payload); | 58 ModelSafeRoutingInfoToPayloadMap(routing_info, payload); |
| 62 ASSERT_EQ(routing_info.size(), types_with_payloads.size()); | 59 ASSERT_EQ(routing_info.size(), types_with_payloads.size()); |
| 63 for (ModelSafeRoutingInfo::iterator iter = routing_info.begin(); | 60 for (ModelSafeRoutingInfo::iterator iter = routing_info.begin(); |
| 64 iter != routing_info.end(); | 61 iter != routing_info.end(); |
| 65 ++iter) { | 62 ++iter) { |
| 66 EXPECT_EQ(payload, types_with_payloads[iter->first]); | 63 EXPECT_EQ(payload, types_with_payloads[iter->first]); |
| 67 } | 64 } |
| 68 } | 65 } |
| 69 | 66 |
| 70 } // namespace | 67 } // namespace |
| 71 } // namespace syncer | 68 } // namespace syncer |
| OLD | NEW |