Finish refactoring of DomCodeToUsLayoutKeyboardCode().
[chromium-blink-merge.git] / sync / test / engine / test_directory_setter_upper.cc
blob85e8aa39c8819dfa8cd9ec7901c3cd35fae965bc
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
3 // found in the LICENSE file.
5 #include "sync/test/engine/test_directory_setter_upper.h"
7 #include "base/compiler_specific.h"
8 #include "base/files/file_util.h"
9 #include "base/location.h"
10 #include "base/strings/string_util.h"
11 #include "sync/syncable/directory.h"
12 #include "sync/syncable/in_memory_directory_backing_store.h"
13 #include "sync/syncable/mutable_entry.h"
14 #include "sync/syncable/syncable_read_transaction.h"
15 #include "sync/syncable/syncable_write_transaction.h"
16 #include "sync/test/test_transaction_observer.h"
17 #include "testing/gtest/include/gtest/gtest.h"
19 namespace syncer {
21 TestDirectorySetterUpper::TestDirectorySetterUpper() : name_("Test") {}
23 TestDirectorySetterUpper::~TestDirectorySetterUpper() {}
25 void TestDirectorySetterUpper::SetUp() {
26 test_transaction_observer_.reset(new syncable::TestTransactionObserver());
27 WeakHandle<syncable::TransactionObserver> transaction_observer =
28 MakeWeakHandle(test_transaction_observer_->AsWeakPtr());
30 directory_.reset(new syncable::Directory(
31 new syncable::InMemoryDirectoryBackingStore(name_), &handler_,
32 base::Closure(), &encryption_handler_,
33 encryption_handler_.cryptographer()));
34 ASSERT_EQ(syncable::OPENED, directory_->Open(
35 name_, &delegate_, transaction_observer));
38 void TestDirectorySetterUpper::SetUpWith(
39 syncer::syncable::DirectoryBackingStore* directory_store) {
40 CHECK(directory_store);
41 test_transaction_observer_.reset(new syncable::TestTransactionObserver());
42 WeakHandle<syncable::TransactionObserver> transaction_observer =
43 MakeWeakHandle(test_transaction_observer_->AsWeakPtr());
45 directory_.reset(new syncable::Directory(
46 directory_store, &handler_, base::Closure(), &encryption_handler_,
47 encryption_handler_.cryptographer()));
48 ASSERT_EQ(syncable::OPENED, directory_->Open(
49 name_, &delegate_, transaction_observer));
52 void TestDirectorySetterUpper::TearDown() {
53 if (!directory()->good())
54 return;
56 RunInvariantCheck();
57 directory()->SaveChanges();
58 RunInvariantCheck();
59 directory()->SaveChanges();
61 directory_.reset();
64 void TestDirectorySetterUpper::RunInvariantCheck() {
65 // Check invariants for all items.
66 syncable::ReadTransaction trans(FROM_HERE, directory());
68 // The TestUnrecoverableErrorHandler that this directory was constructed with
69 // will handle error reporting, so we can safely ignore the return value.
70 directory()->FullyCheckTreeInvariants(&trans);
73 } // namespace syncer