| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 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 | 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 "chrome/browser/sync/syncable/syncable.h" | 5 #include "chrome/browser/sync/syncable/syncable.h" |
| 6 | 6 |
| 7 #include <string> | 7 #include <string> |
| 8 | 8 |
| 9 #include "base/compiler_specific.h" | 9 #include "base/compiler_specific.h" |
| 10 #include "base/file_path.h" | 10 #include "base/file_path.h" |
| (...skipping 29 matching lines...) Expand all Loading... |
| 40 class SyncableKernelTest : public testing::Test {}; | 40 class SyncableKernelTest : public testing::Test {}; |
| 41 | 41 |
| 42 // TODO(akalin): Add unit tests for EntryKernel::ContainsString(). | 42 // TODO(akalin): Add unit tests for EntryKernel::ContainsString(). |
| 43 | 43 |
| 44 TEST_F(SyncableKernelTest, ToValue) { | 44 TEST_F(SyncableKernelTest, ToValue) { |
| 45 EntryKernel kernel; | 45 EntryKernel kernel; |
| 46 scoped_ptr<DictionaryValue> value(kernel.ToValue()); | 46 scoped_ptr<DictionaryValue> value(kernel.ToValue()); |
| 47 if (value.get()) { | 47 if (value.get()) { |
| 48 // Not much to check without repeating the ToValue() code. | 48 // Not much to check without repeating the ToValue() code. |
| 49 EXPECT_TRUE(value->HasKey("isDirty")); | 49 EXPECT_TRUE(value->HasKey("isDirty")); |
| 50 // The extra +2 is for "isDirty" and "serverModelType". | 50 // The extra +1 is for "isDirty". |
| 51 EXPECT_EQ(BIT_TEMPS_END - BEGIN_FIELDS + 2, | 51 EXPECT_EQ(BIT_TEMPS_END - BEGIN_FIELDS + 1, |
| 52 static_cast<int>(value->size())); | 52 static_cast<int>(value->size())); |
| 53 } else { | 53 } else { |
| 54 ADD_FAILURE(); | 54 ADD_FAILURE(); |
| 55 } | 55 } |
| 56 } | 56 } |
| 57 | 57 |
| 58 namespace { | 58 namespace { |
| 59 void PutDataAsBookmarkFavicon(WriteTransaction* wtrans, | 59 void PutDataAsBookmarkFavicon(WriteTransaction* wtrans, |
| 60 MutableEntry* e, | 60 MutableEntry* e, |
| 61 const char* bytes, | 61 const char* bytes, |
| (...skipping 301 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 363 { | 363 { |
| 364 WriteTransaction wtrans(FROM_HERE, UNITTEST, &dir); | 364 WriteTransaction wtrans(FROM_HERE, UNITTEST, &dir); |
| 365 MutableEntry me(&wtrans, CREATE, wtrans.root_id(), "new"); | 365 MutableEntry me(&wtrans, CREATE, wtrans.root_id(), "new"); |
| 366 ASSERT_TRUE(me.good()); | 366 ASSERT_TRUE(me.good()); |
| 367 me.Put(ID, id); | 367 me.Put(ID, id); |
| 368 me.Put(BASE_VERSION, 1); | 368 me.Put(BASE_VERSION, 1); |
| 369 | 369 |
| 370 scoped_ptr<DictionaryValue> value(me.ToValue()); | 370 scoped_ptr<DictionaryValue> value(me.ToValue()); |
| 371 ExpectDictBooleanValue(true, *value, "good"); | 371 ExpectDictBooleanValue(true, *value, "good"); |
| 372 EXPECT_TRUE(value->HasKey("kernel")); | 372 EXPECT_TRUE(value->HasKey("kernel")); |
| 373 ExpectDictStringValue("Unspecified", *value, "serverModelType"); |
| 373 ExpectDictStringValue("Unspecified", *value, "modelType"); | 374 ExpectDictStringValue("Unspecified", *value, "modelType"); |
| 374 ExpectDictBooleanValue(true, *value, "existsOnClientBecauseNameIsNonEmpty"); | 375 ExpectDictBooleanValue(true, *value, "existsOnClientBecauseNameIsNonEmpty"); |
| 375 ExpectDictBooleanValue(false, *value, "isRoot"); | 376 ExpectDictBooleanValue(false, *value, "isRoot"); |
| 376 } | 377 } |
| 377 | 378 |
| 378 dir.SaveChanges(); | 379 dir.SaveChanges(); |
| 379 } | 380 } |
| 380 | 381 |
| 381 // A Directory whose backing store always fails SaveChanges by returning false. | 382 // A Directory whose backing store always fails SaveChanges by returning false. |
| 382 class TestUnsaveableDirectory : public Directory { | 383 class TestUnsaveableDirectory : public Directory { |
| (...skipping 489 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 872 WriteTransaction trans(FROM_HERE, UNITTEST, dir_.get()); | 873 WriteTransaction trans(FROM_HERE, UNITTEST, dir_.get()); |
| 873 dir_->GetUnsyncedMetaHandles(&trans, &handles); | 874 dir_->GetUnsyncedMetaHandles(&trans, &handles); |
| 874 ASSERT_TRUE(1 == handles.size()); | 875 ASSERT_TRUE(1 == handles.size()); |
| 875 ASSERT_TRUE(handle2 == handles[0]); | 876 ASSERT_TRUE(handle2 == handles[0]); |
| 876 } | 877 } |
| 877 } | 878 } |
| 878 | 879 |
| 879 TEST_F(SyncableDirectoryTest, TestGetUnappliedUpdates) { | 880 TEST_F(SyncableDirectoryTest, TestGetUnappliedUpdates) { |
| 880 Directory::UnappliedUpdateMetaHandles handles; | 881 Directory::UnappliedUpdateMetaHandles handles; |
| 881 int64 handle1, handle2; | 882 int64 handle1, handle2; |
| 882 syncable::ModelTypeBitSet all_types; | |
| 883 all_types.set(); | |
| 884 { | 883 { |
| 885 WriteTransaction trans(FROM_HERE, UNITTEST, dir_.get()); | 884 WriteTransaction trans(FROM_HERE, UNITTEST, dir_.get()); |
| 886 | 885 |
| 887 dir_->GetUnappliedUpdateMetaHandles(&trans, all_types, &handles); | 886 dir_->GetUnappliedUpdateMetaHandles(&trans, &handles); |
| 888 ASSERT_TRUE(0 == handles.size()); | 887 ASSERT_TRUE(0 == handles.size()); |
| 889 | 888 |
| 890 MutableEntry e1(&trans, CREATE, trans.root_id(), "abba"); | 889 MutableEntry e1(&trans, CREATE, trans.root_id(), "abba"); |
| 891 ASSERT_TRUE(e1.good()); | 890 ASSERT_TRUE(e1.good()); |
| 892 handle1 = e1.Get(META_HANDLE); | 891 handle1 = e1.Get(META_HANDLE); |
| 893 e1.Put(IS_UNAPPLIED_UPDATE, false); | 892 e1.Put(IS_UNAPPLIED_UPDATE, false); |
| 894 e1.Put(BASE_VERSION, 1); | 893 e1.Put(BASE_VERSION, 1); |
| 895 e1.Put(ID, TestIdFactory::FromNumber(101)); | 894 e1.Put(ID, TestIdFactory::FromNumber(101)); |
| 896 e1.Put(IS_DIR, true); | 895 e1.Put(IS_DIR, true); |
| 897 | 896 |
| 898 MutableEntry e2(&trans, CREATE, e1.Get(ID), "bread"); | 897 MutableEntry e2(&trans, CREATE, e1.Get(ID), "bread"); |
| 899 ASSERT_TRUE(e2.good()); | 898 ASSERT_TRUE(e2.good()); |
| 900 handle2 = e2.Get(META_HANDLE); | 899 handle2 = e2.Get(META_HANDLE); |
| 901 e2.Put(IS_UNAPPLIED_UPDATE, false); | 900 e2.Put(IS_UNAPPLIED_UPDATE, false); |
| 902 e2.Put(BASE_VERSION, 1); | 901 e2.Put(BASE_VERSION, 1); |
| 903 e2.Put(ID, TestIdFactory::FromNumber(102)); | 902 e2.Put(ID, TestIdFactory::FromNumber(102)); |
| 904 } | 903 } |
| 905 dir_->SaveChanges(); | 904 dir_->SaveChanges(); |
| 906 { | 905 { |
| 907 WriteTransaction trans(FROM_HERE, UNITTEST, dir_.get()); | 906 WriteTransaction trans(FROM_HERE, UNITTEST, dir_.get()); |
| 908 | 907 |
| 909 dir_->GetUnappliedUpdateMetaHandles(&trans, all_types, &handles); | 908 dir_->GetUnappliedUpdateMetaHandles(&trans, &handles); |
| 910 ASSERT_TRUE(0 == handles.size()); | 909 ASSERT_TRUE(0 == handles.size()); |
| 911 | 910 |
| 912 MutableEntry e3(&trans, GET_BY_HANDLE, handle1); | 911 MutableEntry e3(&trans, GET_BY_HANDLE, handle1); |
| 913 ASSERT_TRUE(e3.good()); | 912 ASSERT_TRUE(e3.good()); |
| 914 e3.Put(IS_UNAPPLIED_UPDATE, true); | 913 e3.Put(IS_UNAPPLIED_UPDATE, true); |
| 915 } | 914 } |
| 916 dir_->SaveChanges(); | 915 dir_->SaveChanges(); |
| 917 { | 916 { |
| 918 WriteTransaction trans(FROM_HERE, UNITTEST, dir_.get()); | 917 WriteTransaction trans(FROM_HERE, UNITTEST, dir_.get()); |
| 919 dir_->GetUnappliedUpdateMetaHandles(&trans, all_types, &handles); | 918 dir_->GetUnappliedUpdateMetaHandles(&trans, &handles); |
| 920 ASSERT_TRUE(1 == handles.size()); | 919 ASSERT_TRUE(1 == handles.size()); |
| 921 ASSERT_TRUE(handle1 == handles[0]); | 920 ASSERT_TRUE(handle1 == handles[0]); |
| 922 | 921 |
| 923 MutableEntry e4(&trans, GET_BY_HANDLE, handle2); | 922 MutableEntry e4(&trans, GET_BY_HANDLE, handle2); |
| 924 ASSERT_TRUE(e4.good()); | 923 ASSERT_TRUE(e4.good()); |
| 925 e4.Put(IS_UNAPPLIED_UPDATE, true); | 924 e4.Put(IS_UNAPPLIED_UPDATE, true); |
| 926 } | 925 } |
| 927 dir_->SaveChanges(); | 926 dir_->SaveChanges(); |
| 928 { | 927 { |
| 929 WriteTransaction trans(FROM_HERE, UNITTEST, dir_.get()); | 928 WriteTransaction trans(FROM_HERE, UNITTEST, dir_.get()); |
| 930 dir_->GetUnappliedUpdateMetaHandles(&trans, all_types, &handles); | 929 dir_->GetUnappliedUpdateMetaHandles(&trans, &handles); |
| 931 ASSERT_TRUE(2 == handles.size()); | 930 ASSERT_TRUE(2 == handles.size()); |
| 932 if (handle1 == handles[0]) { | 931 if (handle1 == handles[0]) { |
| 933 ASSERT_TRUE(handle2 == handles[1]); | 932 ASSERT_TRUE(handle2 == handles[1]); |
| 934 } else { | 933 } else { |
| 935 ASSERT_TRUE(handle2 == handles[0]); | 934 ASSERT_TRUE(handle2 == handles[0]); |
| 936 ASSERT_TRUE(handle1 == handles[1]); | 935 ASSERT_TRUE(handle1 == handles[1]); |
| 937 } | 936 } |
| 938 | 937 |
| 939 MutableEntry e5(&trans, GET_BY_HANDLE, handle1); | 938 MutableEntry e5(&trans, GET_BY_HANDLE, handle1); |
| 940 ASSERT_TRUE(e5.good()); | 939 ASSERT_TRUE(e5.good()); |
| 941 e5.Put(IS_UNAPPLIED_UPDATE, false); | 940 e5.Put(IS_UNAPPLIED_UPDATE, false); |
| 942 } | 941 } |
| 943 dir_->SaveChanges(); | 942 dir_->SaveChanges(); |
| 944 { | 943 { |
| 945 WriteTransaction trans(FROM_HERE, UNITTEST, dir_.get()); | 944 WriteTransaction trans(FROM_HERE, UNITTEST, dir_.get()); |
| 946 dir_->GetUnappliedUpdateMetaHandles(&trans, all_types, &handles); | 945 dir_->GetUnappliedUpdateMetaHandles(&trans, &handles); |
| 947 ASSERT_TRUE(1 == handles.size()); | 946 ASSERT_TRUE(1 == handles.size()); |
| 948 ASSERT_TRUE(handle2 == handles[0]); | 947 ASSERT_TRUE(handle2 == handles[0]); |
| 949 } | 948 } |
| 950 } | 949 } |
| 951 | 950 |
| 952 | 951 |
| 953 TEST_F(SyncableDirectoryTest, DeleteBug_531383) { | 952 TEST_F(SyncableDirectoryTest, DeleteBug_531383) { |
| 954 // Try to evoke a check failure... | 953 // Try to evoke a check failure... |
| 955 TestIdFactory id_factory; | 954 TestIdFactory id_factory; |
| 956 int64 grandchild_handle; | 955 int64 grandchild_handle; |
| (...skipping 935 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1892 TEST_F(SyncableClientTagTest, TestClientTagIndexDuplicateServer) { | 1891 TEST_F(SyncableClientTagTest, TestClientTagIndexDuplicateServer) { |
| 1893 EXPECT_TRUE(CreateWithDefaultTag(factory_.NewServerId(), true)); | 1892 EXPECT_TRUE(CreateWithDefaultTag(factory_.NewServerId(), true)); |
| 1894 EXPECT_FALSE(CreateWithDefaultTag(factory_.NewServerId(), true)); | 1893 EXPECT_FALSE(CreateWithDefaultTag(factory_.NewServerId(), true)); |
| 1895 EXPECT_FALSE(CreateWithDefaultTag(factory_.NewServerId(), false)); | 1894 EXPECT_FALSE(CreateWithDefaultTag(factory_.NewServerId(), false)); |
| 1896 EXPECT_FALSE(CreateWithDefaultTag(factory_.NewLocalId(), false)); | 1895 EXPECT_FALSE(CreateWithDefaultTag(factory_.NewLocalId(), false)); |
| 1897 EXPECT_FALSE(CreateWithDefaultTag(factory_.NewLocalId(), true)); | 1896 EXPECT_FALSE(CreateWithDefaultTag(factory_.NewLocalId(), true)); |
| 1898 } | 1897 } |
| 1899 | 1898 |
| 1900 } // namespace | 1899 } // namespace |
| 1901 } // namespace syncable | 1900 } // namespace syncable |
| OLD | NEW |