Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(38)

Side by Side Diff: chrome/browser/sync/syncable/syncable_unittest.cc

Issue 8637006: [Sync] Make syncer commands avoid posting tasks on threads with no work to do (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Sync to head, fix windows compile Created 9 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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
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 +1 is for "isDirty". 50 // The extra +2 is for "isDirty" and "serverModelType".
51 EXPECT_EQ(BIT_TEMPS_END - BEGIN_FIELDS + 1, 51 EXPECT_EQ(BIT_TEMPS_END - BEGIN_FIELDS + 2,
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
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");
374 ExpectDictStringValue("Unspecified", *value, "modelType"); 373 ExpectDictStringValue("Unspecified", *value, "modelType");
375 ExpectDictBooleanValue(true, *value, "existsOnClientBecauseNameIsNonEmpty"); 374 ExpectDictBooleanValue(true, *value, "existsOnClientBecauseNameIsNonEmpty");
376 ExpectDictBooleanValue(false, *value, "isRoot"); 375 ExpectDictBooleanValue(false, *value, "isRoot");
377 } 376 }
378 377
379 dir.SaveChanges(); 378 dir.SaveChanges();
380 } 379 }
381 380
382 // A Directory whose backing store always fails SaveChanges by returning false. 381 // A Directory whose backing store always fails SaveChanges by returning false.
383 class TestUnsaveableDirectory : public Directory { 382 class TestUnsaveableDirectory : public Directory {
(...skipping 489 matching lines...) Expand 10 before | Expand all | Expand 10 after
873 WriteTransaction trans(FROM_HERE, UNITTEST, dir_.get()); 872 WriteTransaction trans(FROM_HERE, UNITTEST, dir_.get());
874 dir_->GetUnsyncedMetaHandles(&trans, &handles); 873 dir_->GetUnsyncedMetaHandles(&trans, &handles);
875 ASSERT_TRUE(1 == handles.size()); 874 ASSERT_TRUE(1 == handles.size());
876 ASSERT_TRUE(handle2 == handles[0]); 875 ASSERT_TRUE(handle2 == handles[0]);
877 } 876 }
878 } 877 }
879 878
880 TEST_F(SyncableDirectoryTest, TestGetUnappliedUpdates) { 879 TEST_F(SyncableDirectoryTest, TestGetUnappliedUpdates) {
881 Directory::UnappliedUpdateMetaHandles handles; 880 Directory::UnappliedUpdateMetaHandles handles;
882 int64 handle1, handle2; 881 int64 handle1, handle2;
882 syncable::ModelTypeBitSet all_types;
883 all_types.set();
883 { 884 {
884 WriteTransaction trans(FROM_HERE, UNITTEST, dir_.get()); 885 WriteTransaction trans(FROM_HERE, UNITTEST, dir_.get());
885 886
886 dir_->GetUnappliedUpdateMetaHandles(&trans, &handles); 887 dir_->GetUnappliedUpdateMetaHandles(&trans, all_types, &handles);
887 ASSERT_TRUE(0 == handles.size()); 888 ASSERT_TRUE(0 == handles.size());
888 889
889 MutableEntry e1(&trans, CREATE, trans.root_id(), "abba"); 890 MutableEntry e1(&trans, CREATE, trans.root_id(), "abba");
890 ASSERT_TRUE(e1.good()); 891 ASSERT_TRUE(e1.good());
891 handle1 = e1.Get(META_HANDLE); 892 handle1 = e1.Get(META_HANDLE);
892 e1.Put(IS_UNAPPLIED_UPDATE, false); 893 e1.Put(IS_UNAPPLIED_UPDATE, false);
893 e1.Put(BASE_VERSION, 1); 894 e1.Put(BASE_VERSION, 1);
894 e1.Put(ID, TestIdFactory::FromNumber(101)); 895 e1.Put(ID, TestIdFactory::FromNumber(101));
895 e1.Put(IS_DIR, true); 896 e1.Put(IS_DIR, true);
896 897
897 MutableEntry e2(&trans, CREATE, e1.Get(ID), "bread"); 898 MutableEntry e2(&trans, CREATE, e1.Get(ID), "bread");
898 ASSERT_TRUE(e2.good()); 899 ASSERT_TRUE(e2.good());
899 handle2 = e2.Get(META_HANDLE); 900 handle2 = e2.Get(META_HANDLE);
900 e2.Put(IS_UNAPPLIED_UPDATE, false); 901 e2.Put(IS_UNAPPLIED_UPDATE, false);
901 e2.Put(BASE_VERSION, 1); 902 e2.Put(BASE_VERSION, 1);
902 e2.Put(ID, TestIdFactory::FromNumber(102)); 903 e2.Put(ID, TestIdFactory::FromNumber(102));
903 } 904 }
904 dir_->SaveChanges(); 905 dir_->SaveChanges();
905 { 906 {
906 WriteTransaction trans(FROM_HERE, UNITTEST, dir_.get()); 907 WriteTransaction trans(FROM_HERE, UNITTEST, dir_.get());
907 908
908 dir_->GetUnappliedUpdateMetaHandles(&trans, &handles); 909 dir_->GetUnappliedUpdateMetaHandles(&trans, all_types, &handles);
909 ASSERT_TRUE(0 == handles.size()); 910 ASSERT_TRUE(0 == handles.size());
910 911
911 MutableEntry e3(&trans, GET_BY_HANDLE, handle1); 912 MutableEntry e3(&trans, GET_BY_HANDLE, handle1);
912 ASSERT_TRUE(e3.good()); 913 ASSERT_TRUE(e3.good());
913 e3.Put(IS_UNAPPLIED_UPDATE, true); 914 e3.Put(IS_UNAPPLIED_UPDATE, true);
914 } 915 }
915 dir_->SaveChanges(); 916 dir_->SaveChanges();
916 { 917 {
917 WriteTransaction trans(FROM_HERE, UNITTEST, dir_.get()); 918 WriteTransaction trans(FROM_HERE, UNITTEST, dir_.get());
918 dir_->GetUnappliedUpdateMetaHandles(&trans, &handles); 919 dir_->GetUnappliedUpdateMetaHandles(&trans, all_types, &handles);
919 ASSERT_TRUE(1 == handles.size()); 920 ASSERT_TRUE(1 == handles.size());
920 ASSERT_TRUE(handle1 == handles[0]); 921 ASSERT_TRUE(handle1 == handles[0]);
921 922
922 MutableEntry e4(&trans, GET_BY_HANDLE, handle2); 923 MutableEntry e4(&trans, GET_BY_HANDLE, handle2);
923 ASSERT_TRUE(e4.good()); 924 ASSERT_TRUE(e4.good());
924 e4.Put(IS_UNAPPLIED_UPDATE, true); 925 e4.Put(IS_UNAPPLIED_UPDATE, true);
925 } 926 }
926 dir_->SaveChanges(); 927 dir_->SaveChanges();
927 { 928 {
928 WriteTransaction trans(FROM_HERE, UNITTEST, dir_.get()); 929 WriteTransaction trans(FROM_HERE, UNITTEST, dir_.get());
929 dir_->GetUnappliedUpdateMetaHandles(&trans, &handles); 930 dir_->GetUnappliedUpdateMetaHandles(&trans, all_types, &handles);
930 ASSERT_TRUE(2 == handles.size()); 931 ASSERT_TRUE(2 == handles.size());
931 if (handle1 == handles[0]) { 932 if (handle1 == handles[0]) {
932 ASSERT_TRUE(handle2 == handles[1]); 933 ASSERT_TRUE(handle2 == handles[1]);
933 } else { 934 } else {
934 ASSERT_TRUE(handle2 == handles[0]); 935 ASSERT_TRUE(handle2 == handles[0]);
935 ASSERT_TRUE(handle1 == handles[1]); 936 ASSERT_TRUE(handle1 == handles[1]);
936 } 937 }
937 938
938 MutableEntry e5(&trans, GET_BY_HANDLE, handle1); 939 MutableEntry e5(&trans, GET_BY_HANDLE, handle1);
939 ASSERT_TRUE(e5.good()); 940 ASSERT_TRUE(e5.good());
940 e5.Put(IS_UNAPPLIED_UPDATE, false); 941 e5.Put(IS_UNAPPLIED_UPDATE, false);
941 } 942 }
942 dir_->SaveChanges(); 943 dir_->SaveChanges();
943 { 944 {
944 WriteTransaction trans(FROM_HERE, UNITTEST, dir_.get()); 945 WriteTransaction trans(FROM_HERE, UNITTEST, dir_.get());
945 dir_->GetUnappliedUpdateMetaHandles(&trans, &handles); 946 dir_->GetUnappliedUpdateMetaHandles(&trans, all_types, &handles);
946 ASSERT_TRUE(1 == handles.size()); 947 ASSERT_TRUE(1 == handles.size());
947 ASSERT_TRUE(handle2 == handles[0]); 948 ASSERT_TRUE(handle2 == handles[0]);
948 } 949 }
949 } 950 }
950 951
951 952
952 TEST_F(SyncableDirectoryTest, DeleteBug_531383) { 953 TEST_F(SyncableDirectoryTest, DeleteBug_531383) {
953 // Try to evoke a check failure... 954 // Try to evoke a check failure...
954 TestIdFactory id_factory; 955 TestIdFactory id_factory;
955 int64 grandchild_handle; 956 int64 grandchild_handle;
(...skipping 935 matching lines...) Expand 10 before | Expand all | Expand 10 after
1891 TEST_F(SyncableClientTagTest, TestClientTagIndexDuplicateServer) { 1892 TEST_F(SyncableClientTagTest, TestClientTagIndexDuplicateServer) {
1892 EXPECT_TRUE(CreateWithDefaultTag(factory_.NewServerId(), true)); 1893 EXPECT_TRUE(CreateWithDefaultTag(factory_.NewServerId(), true));
1893 EXPECT_FALSE(CreateWithDefaultTag(factory_.NewServerId(), true)); 1894 EXPECT_FALSE(CreateWithDefaultTag(factory_.NewServerId(), true));
1894 EXPECT_FALSE(CreateWithDefaultTag(factory_.NewServerId(), false)); 1895 EXPECT_FALSE(CreateWithDefaultTag(factory_.NewServerId(), false));
1895 EXPECT_FALSE(CreateWithDefaultTag(factory_.NewLocalId(), false)); 1896 EXPECT_FALSE(CreateWithDefaultTag(factory_.NewLocalId(), false));
1896 EXPECT_FALSE(CreateWithDefaultTag(factory_.NewLocalId(), true)); 1897 EXPECT_FALSE(CreateWithDefaultTag(factory_.NewLocalId(), true));
1897 } 1898 }
1898 1899
1899 } // namespace 1900 } // namespace
1900 } // namespace syncable 1901 } // namespace syncable
OLDNEW
« no previous file with comments | « chrome/browser/sync/syncable/syncable.cc ('k') | chrome/browser/sync/test/engine/fake_model_safe_worker_registrar.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698