OLD | NEW |
1 // Copyright 2012 The Chromium Authors. All rights reserved. | 1 // Copyright 2012 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 "components/sync/test/engine/test_directory_setter_upper.h" | 5 #include "components/sync/test/engine/test_directory_setter_upper.h" |
6 | 6 |
7 #include "base/files/file_util.h" | 7 #include "base/files/file_util.h" |
8 #include "base/location.h" | 8 #include "base/location.h" |
| 9 #include "base/memory/ptr_util.h" |
9 #include "base/strings/string_util.h" | 10 #include "base/strings/string_util.h" |
10 #include "components/sync/syncable/directory.h" | 11 #include "components/sync/syncable/directory.h" |
11 #include "components/sync/syncable/in_memory_directory_backing_store.h" | 12 #include "components/sync/syncable/in_memory_directory_backing_store.h" |
12 #include "components/sync/syncable/mutable_entry.h" | 13 #include "components/sync/syncable/mutable_entry.h" |
13 #include "components/sync/syncable/syncable_read_transaction.h" | 14 #include "components/sync/syncable/syncable_read_transaction.h" |
14 #include "components/sync/syncable/syncable_write_transaction.h" | 15 #include "components/sync/syncable/syncable_write_transaction.h" |
15 #include "components/sync/test/test_transaction_observer.h" | 16 #include "components/sync/test/test_transaction_observer.h" |
16 #include "testing/gtest/include/gtest/gtest.h" | 17 #include "testing/gtest/include/gtest/gtest.h" |
17 | 18 |
18 namespace syncer { | 19 namespace syncer { |
19 | 20 |
20 TestDirectorySetterUpper::TestDirectorySetterUpper() : name_("Test") {} | 21 TestDirectorySetterUpper::TestDirectorySetterUpper() : name_("Test") {} |
21 | 22 |
22 TestDirectorySetterUpper::~TestDirectorySetterUpper() {} | 23 TestDirectorySetterUpper::~TestDirectorySetterUpper() {} |
23 | 24 |
24 void TestDirectorySetterUpper::SetUp() { | 25 void TestDirectorySetterUpper::SetUp() { |
25 test_transaction_observer_.reset(new syncable::TestTransactionObserver()); | 26 test_transaction_observer_ = |
| 27 base::MakeUnique<syncable::TestTransactionObserver>(); |
26 WeakHandle<syncable::TransactionObserver> transaction_observer = | 28 WeakHandle<syncable::TransactionObserver> transaction_observer = |
27 MakeWeakHandle(test_transaction_observer_->AsWeakPtr()); | 29 MakeWeakHandle(test_transaction_observer_->AsWeakPtr()); |
28 | 30 |
29 directory_.reset(new syncable::Directory( | 31 directory_ = base::MakeUnique<syncable::Directory>( |
30 new syncable::InMemoryDirectoryBackingStore(name_), | 32 new syncable::InMemoryDirectoryBackingStore(name_), |
31 MakeWeakHandle(handler_.GetWeakPtr()), base::Closure(), | 33 MakeWeakHandle(handler_.GetWeakPtr()), base::Closure(), |
32 &encryption_handler_, encryption_handler_.cryptographer())); | 34 &encryption_handler_, encryption_handler_.cryptographer()); |
33 ASSERT_EQ(syncable::OPENED, | 35 ASSERT_EQ(syncable::OPENED, |
34 directory_->Open(name_, &delegate_, transaction_observer)); | 36 directory_->Open(name_, &delegate_, transaction_observer)); |
35 } | 37 } |
36 | 38 |
37 void TestDirectorySetterUpper::SetUpWith( | 39 void TestDirectorySetterUpper::SetUpWith( |
38 syncable::DirectoryBackingStore* directory_store) { | 40 syncable::DirectoryBackingStore* directory_store) { |
39 CHECK(directory_store); | 41 CHECK(directory_store); |
40 test_transaction_observer_.reset(new syncable::TestTransactionObserver()); | 42 test_transaction_observer_ = |
| 43 base::MakeUnique<syncable::TestTransactionObserver>(); |
41 WeakHandle<syncable::TransactionObserver> transaction_observer = | 44 WeakHandle<syncable::TransactionObserver> transaction_observer = |
42 MakeWeakHandle(test_transaction_observer_->AsWeakPtr()); | 45 MakeWeakHandle(test_transaction_observer_->AsWeakPtr()); |
43 | 46 |
44 directory_.reset(new syncable::Directory( | 47 directory_ = base::MakeUnique<syncable::Directory>( |
45 directory_store, MakeWeakHandle(handler_.GetWeakPtr()), base::Closure(), | 48 directory_store, MakeWeakHandle(handler_.GetWeakPtr()), base::Closure(), |
46 &encryption_handler_, encryption_handler_.cryptographer())); | 49 &encryption_handler_, encryption_handler_.cryptographer()); |
47 ASSERT_EQ(syncable::OPENED, | 50 ASSERT_EQ(syncable::OPENED, |
48 directory_->Open(name_, &delegate_, transaction_observer)); | 51 directory_->Open(name_, &delegate_, transaction_observer)); |
49 } | 52 } |
50 | 53 |
51 void TestDirectorySetterUpper::TearDown() { | 54 void TestDirectorySetterUpper::TearDown() { |
52 if (!directory()->good()) | 55 if (!directory()->good()) |
53 return; | 56 return; |
54 | 57 |
55 RunInvariantCheck(); | 58 RunInvariantCheck(); |
56 directory()->SaveChanges(); | 59 directory()->SaveChanges(); |
57 RunInvariantCheck(); | 60 RunInvariantCheck(); |
58 directory()->SaveChanges(); | 61 directory()->SaveChanges(); |
59 | 62 |
60 directory_.reset(); | 63 directory_.reset(); |
61 } | 64 } |
62 | 65 |
63 void TestDirectorySetterUpper::RunInvariantCheck() { | 66 void TestDirectorySetterUpper::RunInvariantCheck() { |
64 // Check invariants for all items. | 67 // Check invariants for all items. |
65 syncable::ReadTransaction trans(FROM_HERE, directory()); | 68 syncable::ReadTransaction trans(FROM_HERE, directory()); |
66 | 69 |
67 // The TestUnrecoverableErrorHandler that this directory was constructed with | 70 // The TestUnrecoverableErrorHandler that this directory was constructed with |
68 // will handle error reporting, so we can safely ignore the return value. | 71 // will handle error reporting, so we can safely ignore the return value. |
69 directory()->FullyCheckTreeInvariants(&trans); | 72 directory()->FullyCheckTreeInvariants(&trans); |
70 } | 73 } |
71 | 74 |
72 } // namespace syncer | 75 } // namespace syncer |
OLD | NEW |