1 // Copyright (c) 2011 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 "chrome/browser/sync/js_arg_list.h" 6 7 #include "base/memory/scoped_ptr.h" 8 #include "testing/gtest/include/gtest/gtest.h" 9 10 namespace browser_sync { 11 namespace { 12 13 class JsArgListTest : public testing::Test {}; 14 15 TEST_F(JsArgListTest, EmptyList) { 16 JsArgList arg_list; 17 EXPECT_TRUE(arg_list.Get().empty()); 18 } 19 20 TEST_F(JsArgListTest, FromList) { 21 scoped_ptr<ListValue> list(new ListValue()); 22 list->Append(Value::CreateBooleanValue(false)); 23 list->Append(Value::CreateIntegerValue(5)); 24 DictionaryValue* dict = new DictionaryValue(); 25 list->Append(dict); 26 dict->SetString("foo", "bar"); 27 dict->Set("baz", new ListValue()); 28 29 JsArgList arg_list(*list); 30 31 // Make sure arg_list takes a deep copy. 32 scoped_ptr<ListValue> list_copy(list->DeepCopy()); 33 list.reset(); 34 EXPECT_TRUE(arg_list.Get().Equals(list_copy.get())); 35 } 36 37 TEST_F(JsArgListTest, FromVector) { 38 FundamentalValue bool_value(false); 39 FundamentalValue int_value(5); 40 DictionaryValue dict; 41 dict.SetString("foo", "bar"); 42 dict.Set("baz", new ListValue()); 43 44 std::vector<const Value*> vec; 45 vec.push_back(&bool_value); 46 vec.push_back(&int_value); 47 vec.push_back(&dict); 48 49 JsArgList arg_list(vec); 50 51 ListValue list; 52 list.Append(bool_value.DeepCopy()); 53 list.Append(int_value.DeepCopy()); 54 list.Append(dict.DeepCopy()); 55 56 // Make sure arg_list takes a deep copy. 57 vec.clear(); 58 dict.SetString("baz", "foo"); 59 EXPECT_TRUE(arg_list.Get().Equals(&list)); 60 } 61 62 } // namespace 63 } // namespace browser_sync 64