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/internal_api/public/test/test_user_share.h"
7 #include "base/compiler_specific.h"
8 #include "sync/syncable/directory.h"
9 #include "sync/syncable/mutable_entry.h"
10 #include "sync/syncable/syncable_read_transaction.h"
11 #include "sync/syncable/syncable_write_transaction.h"
12 #include "sync/test/engine/test_directory_setter_upper.h"
13 #include "sync/test/engine/test_id_factory.h"
14 #include "sync/test/engine/test_syncable_utils.h"
15 #include "testing/gtest/include/gtest/gtest.h"
19 TestUserShare::TestUserShare() : dir_maker_(new TestDirectorySetterUpper()) {}
21 TestUserShare::~TestUserShare() {
23 ADD_FAILURE() << "Should have called TestUserShare::TearDown()";
26 void TestUserShare::SetUp() {
27 user_share_
.reset(new UserShare());
30 // The pointer is owned by dir_maker_, we should not be storing it in a
31 // scoped_ptr. We must be careful to ensure the scoped_ptr never deletes it.
32 user_share_
->directory
.reset(dir_maker_
->directory());
35 void TestUserShare::TearDown() {
36 // Ensure the scoped_ptr doesn't delete the memory we don't own.
37 ignore_result(user_share_
->directory
.release());
40 dir_maker_
->TearDown();
43 bool TestUserShare::Reload() {
44 if (!user_share_
->directory
->SaveChanges())
47 syncer::syncable::DirectoryBackingStore
* saved_store
=
48 user_share_
->directory
->store_
.release();
50 // Ensure the scoped_ptr doesn't delete the memory we don't own.
51 ignore_result(user_share_
->directory
.release());
52 user_share_
.reset(new UserShare());
53 dir_maker_
->SetUpWith(saved_store
);
54 user_share_
->directory
.reset(dir_maker_
->directory());
58 UserShare
* TestUserShare::user_share() {
59 return user_share_
.get();
62 SyncEncryptionHandler
* TestUserShare::encryption_handler() {
63 return dir_maker_
->encryption_handler();
66 syncable::TestTransactionObserver
* TestUserShare::transaction_observer() {
67 return dir_maker_
->transaction_observer();
71 bool TestUserShare::CreateRoot(ModelType model_type
, UserShare
* user_share
) {
72 syncer::syncable::Directory
* directory
= user_share
->directory
.get();
73 syncable::WriteTransaction
wtrans(FROM_HERE
, syncable::UNITTEST
, directory
);
74 CreateTypeRoot(&wtrans
, directory
, model_type
);
78 size_t TestUserShare::GetDeleteJournalSize() const {
79 syncable::ReadTransaction
trans(FROM_HERE
, user_share_
->directory
.get());
80 return user_share_
->directory
->delete_journal()->GetDeleteJournalSize(&trans
);