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

Side by Side Diff: sync/syncable/directory_unittest.cc

Issue 1275743002: [Sync] Remove backend unrecoverable error handler (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fix leak Created 5 years, 4 months 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
« no previous file with comments | « sync/syncable/directory_unittest.h ('k') | sync/syncable/syncable_unittest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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/syncable/directory_unittest.h" 5 #include "sync/syncable/directory_unittest.h"
6 6
7 #include "base/run_loop.h"
7 #include "base/strings/stringprintf.h" 8 #include "base/strings/stringprintf.h"
8 #include "base/test/values_test_util.h" 9 #include "base/test/values_test_util.h"
9 #include "sync/internal_api/public/base/attachment_id_proto.h" 10 #include "sync/internal_api/public/base/attachment_id_proto.h"
10 #include "sync/syncable/syncable_proto_util.h" 11 #include "sync/syncable/syncable_proto_util.h"
11 #include "sync/syncable/syncable_util.h" 12 #include "sync/syncable/syncable_util.h"
12 #include "sync/syncable/syncable_write_transaction.h" 13 #include "sync/syncable/syncable_write_transaction.h"
13 #include "sync/test/engine/test_syncable_utils.h" 14 #include "sync/test/engine/test_syncable_utils.h"
14 #include "sync/test/test_directory_backing_store.h" 15 #include "sync/test/test_directory_backing_store.h"
15 #include "sync/util/mock_unrecoverable_error_handler.h" 16 #include "sync/util/mock_unrecoverable_error_handler.h"
16 17
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
66 void SyncableDirectoryTest::TearDown() { 67 void SyncableDirectoryTest::TearDown() {
67 if (dir_) 68 if (dir_)
68 dir_->SaveChanges(); 69 dir_->SaveChanges();
69 dir_.reset(); 70 dir_.reset();
70 } 71 }
71 72
72 DirOpenResult SyncableDirectoryTest::ReopenDirectory() { 73 DirOpenResult SyncableDirectoryTest::ReopenDirectory() {
73 // Use a TestDirectoryBackingStore and sql::Connection so we can have test 74 // Use a TestDirectoryBackingStore and sql::Connection so we can have test
74 // data persist across Directory object lifetimes while getting the 75 // data persist across Directory object lifetimes while getting the
75 // performance benefits of not writing to disk. 76 // performance benefits of not writing to disk.
76 dir_.reset( 77 dir_.reset(new Directory(
77 new Directory(new TestDirectoryBackingStore(kDirectoryName, &connection_), 78 new TestDirectoryBackingStore(kDirectoryName, &connection_),
78 &handler_, base::Closure(), NULL, NULL)); 79 MakeWeakHandle(handler_.GetWeakPtr()), base::Closure(), NULL, NULL));
79 80
80 DirOpenResult open_result = 81 DirOpenResult open_result =
81 dir_->Open(kDirectoryName, &delegate_, NullTransactionObserver()); 82 dir_->Open(kDirectoryName, &delegate_, NullTransactionObserver());
82 83
83 if (open_result != OPENED) { 84 if (open_result != OPENED) {
84 dir_.reset(); 85 dir_.reset();
85 } 86 }
86 87
87 return open_result; 88 return open_result;
88 } 89 }
(...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after
197 } 198 }
198 199
199 DirectoryChangeDelegate* SyncableDirectoryTest::directory_change_delegate() { 200 DirectoryChangeDelegate* SyncableDirectoryTest::directory_change_delegate() {
200 return &delegate_; 201 return &delegate_;
201 } 202 }
202 203
203 Encryptor* SyncableDirectoryTest::encryptor() { 204 Encryptor* SyncableDirectoryTest::encryptor() {
204 return &encryptor_; 205 return &encryptor_;
205 } 206 }
206 207
207 UnrecoverableErrorHandler* 208
209 TestUnrecoverableErrorHandler*
208 SyncableDirectoryTest::unrecoverable_error_handler() { 210 SyncableDirectoryTest::unrecoverable_error_handler() {
209 return &handler_; 211 return &handler_;
210 } 212 }
211 213
212 void SyncableDirectoryTest::ValidateEntry(BaseTransaction* trans, 214 void SyncableDirectoryTest::ValidateEntry(BaseTransaction* trans,
213 int64 id, 215 int64 id,
214 bool check_name, 216 bool check_name,
215 const std::string& name, 217 const std::string& name,
216 int64 base_version, 218 int64 base_version,
217 int64 server_version, 219 int64 server_version,
(...skipping 1812 matching lines...) Expand 10 before | Expand all | Expand 10 after
2030 snapshot.delete_journals_to_purge.insert(1); 2032 snapshot.delete_journals_to_purge.insert(1);
2031 EXPECT_TRUE(snapshot.HasUnsavedMetahandleChanges()); 2033 EXPECT_TRUE(snapshot.HasUnsavedMetahandleChanges());
2032 snapshot.delete_journals_to_purge.clear(); 2034 snapshot.delete_journals_to_purge.clear();
2033 } 2035 }
2034 2036
2035 // Verify that Directory triggers an unrecoverable error when a catastrophic 2037 // Verify that Directory triggers an unrecoverable error when a catastrophic
2036 // DirectoryBackingStore error is detected. 2038 // DirectoryBackingStore error is detected.
2037 TEST_F(SyncableDirectoryTest, CatastrophicError) { 2039 TEST_F(SyncableDirectoryTest, CatastrophicError) {
2038 MockUnrecoverableErrorHandler unrecoverable_error_handler; 2040 MockUnrecoverableErrorHandler unrecoverable_error_handler;
2039 Directory dir(new InMemoryDirectoryBackingStore("catastrophic_error"), 2041 Directory dir(new InMemoryDirectoryBackingStore("catastrophic_error"),
2040 &unrecoverable_error_handler, base::Closure(), nullptr, 2042 MakeWeakHandle(unrecoverable_error_handler.GetWeakPtr()),
2041 nullptr); 2043 base::Closure(), nullptr, nullptr);
2042 ASSERT_EQ(OPENED, dir.Open(kDirectoryName, directory_change_delegate(), 2044 ASSERT_EQ(OPENED, dir.Open(kDirectoryName, directory_change_delegate(),
2043 NullTransactionObserver())); 2045 NullTransactionObserver()));
2044 ASSERT_EQ(0, unrecoverable_error_handler.invocation_count()); 2046 ASSERT_EQ(0, unrecoverable_error_handler.invocation_count());
2045 2047
2046 // Fire off two catastrophic errors. Call it twice to ensure Directory is 2048 // Fire off two catastrophic errors. Call it twice to ensure Directory is
2047 // tolerant of multiple invocations since that may happen in the real world. 2049 // tolerant of multiple invocations since that may happen in the real world.
2048 dir.OnCatastrophicError(); 2050 dir.OnCatastrophicError();
2049 dir.OnCatastrophicError(); 2051 dir.OnCatastrophicError();
2050 2052
2053 base::RunLoop().RunUntilIdle();
2054
2051 // See that the unrecoverable error handler has been invoked twice. 2055 // See that the unrecoverable error handler has been invoked twice.
2052 ASSERT_EQ(2, unrecoverable_error_handler.invocation_count()); 2056 ASSERT_EQ(2, unrecoverable_error_handler.invocation_count());
2053 } 2057 }
2054 2058
2055 bool EntitySpecificsValuesAreSame(const sync_pb::EntitySpecifics& v1, 2059 bool EntitySpecificsValuesAreSame(const sync_pb::EntitySpecifics& v1,
2056 const sync_pb::EntitySpecifics& v2) { 2060 const sync_pb::EntitySpecifics& v2) {
2057 return &v1 == &v2; 2061 return &v1 == &v2;
2058 } 2062 }
2059 2063
2060 // Verifies that server and client specifics are shared when their values 2064 // Verifies that server and client specifics are shared when their values
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
2102 EXPECT_FALSE(EntitySpecificsValuesAreSame(item.GetServerSpecifics(), 2106 EXPECT_FALSE(EntitySpecificsValuesAreSame(item.GetServerSpecifics(),
2103 item.GetBaseServerSpecifics())); 2107 item.GetBaseServerSpecifics()));
2104 item.PutBaseServerSpecifics(specifics3); 2108 item.PutBaseServerSpecifics(specifics3);
2105 EXPECT_TRUE(EntitySpecificsValuesAreSame(item.GetServerSpecifics(), 2109 EXPECT_TRUE(EntitySpecificsValuesAreSame(item.GetServerSpecifics(),
2106 item.GetBaseServerSpecifics())); 2110 item.GetBaseServerSpecifics()));
2107 } 2111 }
2108 2112
2109 } // namespace syncable 2113 } // namespace syncable
2110 2114
2111 } // namespace syncer 2115 } // namespace syncer
OLDNEW
« no previous file with comments | « sync/syncable/directory_unittest.h ('k') | sync/syncable/syncable_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698