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
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
|
// Copyright (c) 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 "base/location.h"
#include "sync/engine/verify_updates_command.h"
#include "sync/protocol/bookmark_specifics.pb.h"
#include "sync/sessions/session_state.h"
#include "sync/sessions/sync_session.h"
#include "sync/syncable/mutable_entry.h"
#include "sync/syncable/syncable_id.h"
#include "sync/test/engine/fake_model_worker.h"
#include "sync/test/engine/syncer_command_test.h"
#include "testing/gtest/include/gtest/gtest.h"
namespace csync {
using sessions::StatusController;
using std::string;
using syncable::Id;
using syncable::MutableEntry;
using syncable::UNITTEST;
using syncable::WriteTransaction;
class VerifyUpdatesCommandTest : public SyncerCommandTest {
public:
virtual void SetUp() {
workers()->clear();
mutable_routing_info()->clear();
workers()->push_back(make_scoped_refptr(new FakeModelWorker(GROUP_DB)));
workers()->push_back(make_scoped_refptr(new FakeModelWorker(GROUP_UI)));
(*mutable_routing_info())[syncable::PREFERENCES] = GROUP_UI;
(*mutable_routing_info())[syncable::BOOKMARKS] = GROUP_UI;
(*mutable_routing_info())[syncable::AUTOFILL] = GROUP_DB;
SyncerCommandTest::SetUp();
}
void CreateLocalItem(const std::string& item_id,
const std::string& parent_id,
const syncable::ModelType& type) {
WriteTransaction trans(FROM_HERE, UNITTEST, directory());
MutableEntry entry(&trans, syncable::CREATE_NEW_UPDATE_ITEM,
Id::CreateFromServerId(item_id));
ASSERT_TRUE(entry.good());
entry.Put(syncable::BASE_VERSION, 1);
entry.Put(syncable::SERVER_VERSION, 1);
entry.Put(syncable::NON_UNIQUE_NAME, item_id);
entry.Put(syncable::PARENT_ID, Id::CreateFromServerId(parent_id));
sync_pb::EntitySpecifics default_specifics;
AddDefaultFieldValue(type, &default_specifics);
entry.Put(syncable::SERVER_SPECIFICS, default_specifics);
}
void AddUpdate(GetUpdatesResponse* updates,
const std::string& id, const std::string& parent,
const syncable::ModelType& type) {
sync_pb::SyncEntity* e = updates->add_entries();
e->set_id_string("b1");
e->set_parent_id_string(parent);
e->set_non_unique_name("b1");
e->set_name("b1");
AddDefaultFieldValue(type, e->mutable_specifics());
}
VerifyUpdatesCommand command_;
};
TEST_F(VerifyUpdatesCommandTest, AllVerified) {
string root = syncable::GetNullId().GetServerId();
CreateLocalItem("b1", root, syncable::BOOKMARKS);
CreateLocalItem("b2", root, syncable::BOOKMARKS);
CreateLocalItem("p1", root, syncable::PREFERENCES);
CreateLocalItem("a1", root, syncable::AUTOFILL);
ExpectNoGroupsToChange(command_);
GetUpdatesResponse* updates = session()->mutable_status_controller()->
mutable_updates_response()->mutable_get_updates();
AddUpdate(updates, "b1", root, syncable::BOOKMARKS);
AddUpdate(updates, "b2", root, syncable::BOOKMARKS);
AddUpdate(updates, "p1", root, syncable::PREFERENCES);
AddUpdate(updates, "a1", root, syncable::AUTOFILL);
ExpectGroupsToChange(command_, GROUP_UI, GROUP_DB);
command_.ExecuteImpl(session());
StatusController* status = session()->mutable_status_controller();
{
sessions::ScopedModelSafeGroupRestriction r(status, GROUP_UI);
ASSERT_TRUE(status->update_progress());
EXPECT_EQ(3, status->update_progress()->VerifiedUpdatesSize());
}
{
sessions::ScopedModelSafeGroupRestriction r(status, GROUP_DB);
ASSERT_TRUE(status->update_progress());
EXPECT_EQ(1, status->update_progress()->VerifiedUpdatesSize());
}
{
sessions::ScopedModelSafeGroupRestriction r(status, GROUP_PASSIVE);
EXPECT_FALSE(status->update_progress());
}
}
}
|