model_safe_worker_unittest.cc revision eb525c5499e34cc9c4b825d6d9e75bb07cc06ace
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 3// found in the LICENSE file. 4 5#include "sync/internal_api/public/engine/model_safe_worker.h" 6 7#include "base/memory/scoped_ptr.h" 8#include "base/values.h" 9#include "testing/gtest/include/gtest/gtest.h" 10 11namespace syncer { 12namespace { 13 14class ModelSafeWorkerTest : public ::testing::Test { 15}; 16 17TEST_F(ModelSafeWorkerTest, ModelSafeRoutingInfoToValue) { 18 ModelSafeRoutingInfo routing_info; 19 routing_info[BOOKMARKS] = GROUP_PASSIVE; 20 routing_info[NIGORI] = GROUP_UI; 21 routing_info[PREFERENCES] = GROUP_DB; 22 base::DictionaryValue expected_value; 23 expected_value.SetString("Bookmarks", "GROUP_PASSIVE"); 24 expected_value.SetString("Encryption keys", "GROUP_UI"); 25 expected_value.SetString("Preferences", "GROUP_DB"); 26 scoped_ptr<base::DictionaryValue> value( 27 ModelSafeRoutingInfoToValue(routing_info)); 28 EXPECT_TRUE(value->Equals(&expected_value)); 29} 30 31TEST_F(ModelSafeWorkerTest, ModelSafeRoutingInfoToString) { 32 ModelSafeRoutingInfo routing_info; 33 routing_info[BOOKMARKS] = GROUP_PASSIVE; 34 routing_info[NIGORI] = GROUP_UI; 35 routing_info[PREFERENCES] = GROUP_DB; 36 EXPECT_EQ( 37 "{\"Bookmarks\":\"GROUP_PASSIVE\",\"Encryption keys\":\"GROUP_UI\"," 38 "\"Preferences\":\"GROUP_DB\"}", 39 ModelSafeRoutingInfoToString(routing_info)); 40} 41 42TEST_F(ModelSafeWorkerTest, GetRoutingInfoTypes) { 43 ModelSafeRoutingInfo routing_info; 44 routing_info[BOOKMARKS] = GROUP_PASSIVE; 45 routing_info[NIGORI] = GROUP_UI; 46 routing_info[PREFERENCES] = GROUP_DB; 47 const ModelTypeSet expected_types(BOOKMARKS, NIGORI, PREFERENCES); 48 EXPECT_TRUE(GetRoutingInfoTypes(routing_info).Equals(expected_types)); 49} 50 51TEST_F(ModelSafeWorkerTest, ModelSafeRoutingInfoToInvalidationMap) { 52 std::string payload = "test"; 53 ModelSafeRoutingInfo routing_info; 54 routing_info[BOOKMARKS] = GROUP_PASSIVE; 55 routing_info[NIGORI] = GROUP_UI; 56 routing_info[PREFERENCES] = GROUP_DB; 57 ModelTypeInvalidationMap invalidation_map = 58 ModelSafeRoutingInfoToInvalidationMap(routing_info, payload); 59 ASSERT_EQ(routing_info.size(), invalidation_map.size()); 60 for (ModelSafeRoutingInfo::iterator iter = routing_info.begin(); 61 iter != routing_info.end(); 62 ++iter) { 63 EXPECT_EQ(payload, invalidation_map[iter->first].payload); 64 } 65} 66 67} // namespace 68} // namespace syncer 69