File: test_user_share.cc

package info (click to toggle)
chromium-browser 57.0.2987.98-1~deb8u1
  • links: PTS, VCS
  • area: main
  • in suites: jessie
  • size: 2,637,852 kB
  • ctags: 2,544,394
  • sloc: cpp: 12,815,961; ansic: 3,676,222; python: 1,147,112; asm: 526,608; java: 523,212; xml: 286,794; perl: 92,654; sh: 86,408; objc: 73,271; makefile: 27,698; cs: 18,487; yacc: 13,031; tcl: 12,957; pascal: 4,875; ml: 4,716; lex: 3,904; sql: 3,862; ruby: 1,982; lisp: 1,508; php: 1,368; exp: 404; awk: 325; csh: 117; jsp: 39; sed: 37
file content (84 lines) | stat: -rw-r--r-- 2,811 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
// Copyright 2012 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#include "components/sync/syncable/test_user_share.h"

#include "base/compiler_specific.h"
#include "base/memory/ptr_util.h"
#include "components/sync/syncable/directory.h"
#include "components/sync/syncable/mutable_entry.h"
#include "components/sync/syncable/syncable_read_transaction.h"
#include "components/sync/syncable/syncable_write_transaction.h"
#include "components/sync/test/engine/test_directory_setter_upper.h"
#include "components/sync/test/engine/test_id_factory.h"
#include "components/sync/test/engine/test_syncable_utils.h"
#include "testing/gtest/include/gtest/gtest.h"

namespace syncer {

TestUserShare::TestUserShare() : dir_maker_(new TestDirectorySetterUpper()) {}

TestUserShare::~TestUserShare() {
  if (user_share_)
    ADD_FAILURE() << "Should have called TestUserShare::TearDown()";
}

void TestUserShare::SetUp() {
  user_share_ = base::MakeUnique<UserShare>();
  dir_maker_->SetUp();

  // The pointer is owned by dir_maker_, we should not be storing it in a
  // unique_ptr.  We must be careful to ensure the unique_ptr never deletes it.
  user_share_->directory.reset(dir_maker_->directory());
}

void TestUserShare::TearDown() {
  // Ensure the unique_ptr doesn't delete the memory we don't own.
  ignore_result(user_share_->directory.release());

  user_share_.reset();
  dir_maker_->TearDown();
}

bool TestUserShare::Reload() {
  if (!user_share_->directory->SaveChanges())
    return false;

  syncable::DirectoryBackingStore* saved_store =
      user_share_->directory->store_.release();

  // Ensure the unique_ptr doesn't delete the memory we don't own.
  ignore_result(user_share_->directory.release());
  user_share_ = base::MakeUnique<UserShare>();
  dir_maker_->SetUpWith(saved_store);
  user_share_->directory.reset(dir_maker_->directory());
  return true;
}

UserShare* TestUserShare::user_share() {
  return user_share_.get();
}

SyncEncryptionHandler* TestUserShare::encryption_handler() {
  return dir_maker_->encryption_handler();
}

syncable::TestTransactionObserver* TestUserShare::transaction_observer() {
  return dir_maker_->transaction_observer();
}

/* static */
bool TestUserShare::CreateRoot(ModelType model_type, UserShare* user_share) {
  syncable::Directory* directory = user_share->directory.get();
  syncable::WriteTransaction wtrans(FROM_HERE, syncable::UNITTEST, directory);
  CreateTypeRoot(&wtrans, directory, model_type);
  return true;
}

size_t TestUserShare::GetDeleteJournalSize() const {
  syncable::ReadTransaction trans(FROM_HERE, user_share_->directory.get());
  return user_share_->directory->delete_journal()->GetDeleteJournalSize(&trans);
}

}  // namespace syncer