Revert of Add button to add new FSP services to Files app. (patchset #8 id:140001...
[chromium-blink-merge.git] / chrome / browser / sync_file_system / file_change_unittest.cc
blob6a3df50eb99cc1dc6b3ffceb10a9ea983e9b7443
1 // Copyright 2013 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 "chrome/browser/sync_file_system/file_change.h"
7 #include "base/basictypes.h"
8 #include "base/logging.h"
9 #include "testing/gtest/include/gtest/gtest.h"
11 namespace sync_file_system {
13 namespace {
15 FileChange AddOrUpdateFile() {
16 return FileChange(FileChange::FILE_CHANGE_ADD_OR_UPDATE, SYNC_FILE_TYPE_FILE);
19 FileChange DeleteFile() {
20 return FileChange(FileChange::FILE_CHANGE_DELETE, SYNC_FILE_TYPE_FILE);
23 FileChange AddDirectory() {
24 return FileChange(FileChange::FILE_CHANGE_ADD_OR_UPDATE,
25 SYNC_FILE_TYPE_DIRECTORY);
28 FileChange DeleteDirectory() {
29 return FileChange(FileChange::FILE_CHANGE_DELETE, SYNC_FILE_TYPE_DIRECTORY);
32 template <size_t INPUT_SIZE>
33 void CreateList(FileChangeList* list, const FileChange (&inputs)[INPUT_SIZE]) {
34 list->clear();
35 for (size_t i = 0; i < INPUT_SIZE; ++i)
36 list->Update(inputs[i]);
39 template <size_t EXPECTED_SIZE>
40 void VerifyList(const FileChangeList& list,
41 const FileChange (&expected)[EXPECTED_SIZE]) {
42 SCOPED_TRACE(testing::Message() << "actual:" << list.DebugString());
43 ASSERT_EQ(EXPECTED_SIZE, list.size());
44 for (size_t i = 0; i < list.size(); ++i) {
45 SCOPED_TRACE(testing::Message() << i << ": "
46 << " expected:" << expected[i].DebugString()
47 << " actual:" << list.list().at(i).DebugString());
48 EXPECT_EQ(expected[i], list.list().at(i));
52 } // namespace
54 TEST(FileChangeListTest, UpdateSimple) {
55 FileChangeList list;
56 const FileChange kInput1[] = { AddOrUpdateFile() };
57 const FileChange kExpected1[] = { AddOrUpdateFile() };
58 CreateList(&list, kInput1);
59 VerifyList(list, kExpected1);
61 // AddOrUpdate + Delete -> Delete.
62 const FileChange kInput2[] = { AddOrUpdateFile(), DeleteFile() };
63 const FileChange kExpected2[] = { DeleteFile() };
64 CreateList(&list, kInput2);
65 VerifyList(list, kExpected2);
67 // Add + Delete -> empty (directory).
68 const FileChange kInput3[] = { AddDirectory(), DeleteDirectory() };
69 CreateList(&list, kInput3);
70 ASSERT_TRUE(list.empty());
72 // Delete + AddOrUpdate -> AddOrUpdate.
73 const FileChange kInput4[] = { DeleteFile(), AddOrUpdateFile() };
74 const FileChange kExpected4[] = { AddOrUpdateFile() };
75 CreateList(&list, kInput4);
76 VerifyList(list, kExpected4);
78 // Delete + Add -> Add (directory).
79 const FileChange kInput5[] = { DeleteDirectory(), AddDirectory() };
80 const FileChange kExpected5[] = { AddDirectory() };
81 CreateList(&list, kInput5);
82 VerifyList(list, kExpected5);
85 TEST(FileChangeListTest, UpdateCombined) {
86 FileChangeList list;
88 // Longer ones.
89 const FileChange kInput1[] = {
90 AddOrUpdateFile(),
91 AddOrUpdateFile(),
92 AddOrUpdateFile(),
93 AddOrUpdateFile(),
94 DeleteFile(),
95 AddDirectory(),
97 const FileChange kExpected1[] = { DeleteFile(), AddDirectory() };
98 CreateList(&list, kInput1);
99 VerifyList(list, kExpected1);
101 const FileChange kInput2[] = {
102 AddOrUpdateFile(),
103 DeleteFile(),
104 AddOrUpdateFile(),
105 AddOrUpdateFile(),
106 AddOrUpdateFile(),
108 const FileChange kExpected2[] = { AddOrUpdateFile() };
109 CreateList(&list, kInput2);
110 VerifyList(list, kExpected2);
112 const FileChange kInput3[] = {
113 AddDirectory(),
114 DeleteDirectory(),
115 AddOrUpdateFile(),
116 AddOrUpdateFile(),
117 AddOrUpdateFile(),
119 const FileChange kExpected3[] = { AddOrUpdateFile() };
120 CreateList(&list, kInput3);
121 VerifyList(list, kExpected3);
123 const FileChange kInput4[] = {
124 AddDirectory(),
125 DeleteDirectory(),
126 AddOrUpdateFile(),
127 DeleteFile(),
128 AddOrUpdateFile(),
129 DeleteFile(),
131 const FileChange kExpected4[] = { DeleteFile() };
132 CreateList(&list, kInput4);
133 VerifyList(list, kExpected4);
136 } // namespace sync_file_system