Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(53)

Side by Side Diff: chrome/browser/sync/profile_sync_service_bookmark_unittest.cc

Issue 7918001: [Sync] Move ChangeRecord into its own file (change_record.{h,cc}) (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Address comments Created 9 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 // TODO(akalin): This file is basically just a unit test for 5 // TODO(akalin): This file is basically just a unit test for
6 // BookmarkChangeProcessor. Write unit tests for 6 // BookmarkChangeProcessor. Write unit tests for
7 // BookmarkModelAssociator separately. 7 // BookmarkModelAssociator separately.
8 8
9 #include <stack> 9 #include <stack>
10 #include <vector> 10 #include <vector>
11 11
12 #include "base/command_line.h" 12 #include "base/command_line.h"
13 #include "base/file_path.h" 13 #include "base/file_path.h"
14 #include "base/file_util.h" 14 #include "base/file_util.h"
15 #include "base/memory/scoped_ptr.h" 15 #include "base/memory/scoped_ptr.h"
16 #include "base/message_loop.h" 16 #include "base/message_loop.h"
17 #include "base/string16.h" 17 #include "base/string16.h"
18 #include "base/string_number_conversions.h" 18 #include "base/string_number_conversions.h"
19 #include "base/string_util.h" 19 #include "base/string_util.h"
20 #include "base/tracked.h" 20 #include "base/tracked.h"
21 #include "base/utf_string_conversions.h" 21 #include "base/utf_string_conversions.h"
22 #include "chrome/browser/bookmarks/bookmark_model.h" 22 #include "chrome/browser/bookmarks/bookmark_model.h"
23 #include "chrome/browser/sync/abstract_profile_sync_service_test.h" 23 #include "chrome/browser/sync/abstract_profile_sync_service_test.h"
24 #include "chrome/browser/sync/api/sync_error.h" 24 #include "chrome/browser/sync/api/sync_error.h"
25 #include "chrome/browser/sync/glue/bookmark_change_processor.h" 25 #include "chrome/browser/sync/glue/bookmark_change_processor.h"
26 #include "chrome/browser/sync/glue/bookmark_model_associator.h" 26 #include "chrome/browser/sync/glue/bookmark_model_associator.h"
27 #include "chrome/browser/sync/internal_api/change_record.h"
27 #include "chrome/browser/sync/internal_api/read_node.h" 28 #include "chrome/browser/sync/internal_api/read_node.h"
28 #include "chrome/browser/sync/internal_api/read_transaction.h" 29 #include "chrome/browser/sync/internal_api/read_transaction.h"
29 #include "chrome/browser/sync/internal_api/sync_manager.h"
30 #include "chrome/browser/sync/internal_api/write_node.h" 30 #include "chrome/browser/sync/internal_api/write_node.h"
31 #include "chrome/browser/sync/internal_api/write_transaction.h" 31 #include "chrome/browser/sync/internal_api/write_transaction.h"
32 #include "chrome/browser/sync/syncable/directory_manager.h" 32 #include "chrome/browser/sync/syncable/directory_manager.h"
33 #include "chrome/browser/sync/test/engine/test_id_factory.h" 33 #include "chrome/browser/sync/test/engine/test_id_factory.h"
34 #include "chrome/browser/sync/test/engine/test_user_share.h" 34 #include "chrome/browser/sync/test/engine/test_user_share.h"
35 #include "chrome/common/chrome_switches.h" 35 #include "chrome/common/chrome_switches.h"
36 #include "chrome/test/base/testing_profile.h" 36 #include "chrome/test/base/testing_profile.h"
37 #include "content/browser/browser_thread.h" 37 #include "content/browser/browser_thread.h"
38 #include "testing/gmock/include/gmock/gmock.h" 38 #include "testing/gmock/include/gmock/gmock.h"
39 #include "testing/gtest/include/gtest/gtest.h" 39 #include "testing/gtest/include/gtest/gtest.h"
(...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after
153 EXPECT_EQ(predecessor.GetParentId(), parent.GetId()); 153 EXPECT_EQ(predecessor.GetParentId(), parent.GetId());
154 EXPECT_TRUE(node.InitByCreation(syncable::BOOKMARKS, parent, 154 EXPECT_TRUE(node.InitByCreation(syncable::BOOKMARKS, parent,
155 &predecessor)); 155 &predecessor));
156 } 156 }
157 EXPECT_EQ(node.GetPredecessorId(), predecessor_id); 157 EXPECT_EQ(node.GetPredecessorId(), predecessor_id);
158 EXPECT_EQ(node.GetParentId(), parent_id); 158 EXPECT_EQ(node.GetParentId(), parent_id);
159 node.SetIsFolder(is_folder); 159 node.SetIsFolder(is_folder);
160 node.SetTitle(title); 160 node.SetTitle(title);
161 if (!is_folder) 161 if (!is_folder)
162 node.SetURL(GURL(url)); 162 node.SetURL(GURL(url));
163 sync_api::SyncManager::ChangeRecord record; 163 sync_api::ChangeRecord record;
164 record.action = sync_api::SyncManager::ChangeRecord::ACTION_ADD; 164 record.action = sync_api::ChangeRecord::ACTION_ADD;
165 record.id = node.GetId(); 165 record.id = node.GetId();
166 changes_.push_back(record); 166 changes_.push_back(record);
167 return node.GetId(); 167 return node.GetId();
168 } 168 }
169 169
170 // Add a bookmark folder. 170 // Add a bookmark folder.
171 int64 AddFolder(const std::wstring& title, 171 int64 AddFolder(const std::wstring& title,
172 int64 parent_id, 172 int64 parent_id,
173 int64 predecessor_id) { 173 int64 predecessor_id) {
174 return Add(title, std::string(), true, parent_id, predecessor_id); 174 return Add(title, std::string(), true, parent_id, predecessor_id);
(...skipping 15 matching lines...) Expand all
190 EXPECT_TRUE(node.InitByIdLookup(id)); 190 EXPECT_TRUE(node.InitByIdLookup(id));
191 EXPECT_FALSE(node.GetFirstChildId()); 191 EXPECT_FALSE(node.GetFirstChildId());
192 node.Remove(); 192 node.Remove();
193 } 193 }
194 { 194 {
195 // Verify the deletion. 195 // Verify the deletion.
196 sync_api::ReadNode node(trans_); 196 sync_api::ReadNode node(trans_);
197 EXPECT_FALSE(node.InitByIdLookup(id)); 197 EXPECT_FALSE(node.InitByIdLookup(id));
198 } 198 }
199 199
200 sync_api::SyncManager::ChangeRecord record; 200 sync_api::ChangeRecord record;
201 record.action = sync_api::SyncManager::ChangeRecord::ACTION_DELETE; 201 record.action = sync_api::ChangeRecord::ACTION_DELETE;
202 record.id = id; 202 record.id = id;
203 // Deletions are always first in the changelist, but we can't actually do 203 // Deletions are always first in the changelist, but we can't actually do
204 // WriteNode::Remove() on the node until its children are moved. So, as 204 // WriteNode::Remove() on the node until its children are moved. So, as
205 // a practical matter, users of FakeServerChange must move or delete 205 // a practical matter, users of FakeServerChange must move or delete
206 // children before parents. Thus, we must insert the deletion record 206 // children before parents. Thus, we must insert the deletion record
207 // at the front of the vector. 207 // at the front of the vector.
208 changes_.insert(changes_.begin(), record); 208 changes_.insert(changes_.begin(), record);
209 } 209 }
210 210
211 // Set a new title value, and return the old value. 211 // Set a new title value, and return the old value.
(...skipping 22 matching lines...) Expand all
234 EXPECT_TRUE(predecessor.InitByIdLookup(predecessor_id)); 234 EXPECT_TRUE(predecessor.InitByIdLookup(predecessor_id));
235 EXPECT_EQ(predecessor.GetParentId(), parent.GetId()); 235 EXPECT_EQ(predecessor.GetParentId(), parent.GetId());
236 EXPECT_TRUE(node.SetPosition(parent, &predecessor)); 236 EXPECT_TRUE(node.SetPosition(parent, &predecessor));
237 } 237 }
238 SetModified(id); 238 SetModified(id);
239 return old_parent_id; 239 return old_parent_id;
240 } 240 }
241 241
242 // Pass the fake change list to |service|. 242 // Pass the fake change list to |service|.
243 void ApplyPendingChanges(ChangeProcessor* processor) { 243 void ApplyPendingChanges(ChangeProcessor* processor) {
244 processor->ApplyChangesFromSyncModel(trans_, 244 processor->ApplyChangesFromSyncModel(
245 changes_.size() ? &changes_[0] : NULL, changes_.size()); 245 trans_, sync_api::ImmutableChangeRecordList(&changes_));
246 } 246 }
247 247
248 const std::vector<sync_api::SyncManager::ChangeRecord>& changes() { 248 const sync_api::ChangeRecordList& changes() {
249 return changes_; 249 return changes_;
250 } 250 }
251 251
252 private: 252 private:
253 // Helper function to push an ACTION_UPDATE record onto the back 253 // Helper function to push an ACTION_UPDATE record onto the back
254 // of the changelist. 254 // of the changelist.
255 void SetModified(int64 id) { 255 void SetModified(int64 id) {
256 // Coalesce multi-property edits. 256 // Coalesce multi-property edits.
257 if (!changes_.empty() && changes_.back().id == id && 257 if (!changes_.empty() && changes_.back().id == id &&
258 changes_.back().action == 258 changes_.back().action ==
259 sync_api::SyncManager::ChangeRecord::ACTION_UPDATE) 259 sync_api::ChangeRecord::ACTION_UPDATE)
260 return; 260 return;
261 sync_api::SyncManager::ChangeRecord record; 261 sync_api::ChangeRecord record;
262 record.action = sync_api::SyncManager::ChangeRecord::ACTION_UPDATE; 262 record.action = sync_api::ChangeRecord::ACTION_UPDATE;
263 record.id = id; 263 record.id = id;
264 changes_.push_back(record); 264 changes_.push_back(record);
265 } 265 }
266 266
267 // The transaction on which everything happens. 267 // The transaction on which everything happens.
268 sync_api::WriteTransaction *trans_; 268 sync_api::WriteTransaction *trans_;
269 269
270 // The change list we construct. 270 // The change list we construct.
271 std::vector<sync_api::SyncManager::ChangeRecord> changes_; 271 sync_api::ChangeRecordList changes_;
272 }; 272 };
273 273
274 class MockUnrecoverableErrorHandler : public UnrecoverableErrorHandler { 274 class MockUnrecoverableErrorHandler : public UnrecoverableErrorHandler {
275 public: 275 public:
276 MOCK_METHOD2(OnUnrecoverableError, 276 MOCK_METHOD2(OnUnrecoverableError,
277 void(const tracked_objects::Location&, const std::string&)); 277 void(const tracked_objects::Location&, const std::string&));
278 }; 278 };
279 279
280 class ProfileSyncServiceBookmarkTest : public testing::Test { 280 class ProfileSyncServiceBookmarkTest : public testing::Test {
281 protected: 281 protected:
(...skipping 329 matching lines...) Expand 10 before | Expand all | Expand 10 after
611 // u5 tests an empty-string title. 611 // u5 tests an empty-string title.
612 std::string javascript_url( 612 std::string javascript_url(
613 "javascript:(function(){var w=window.open(" \ 613 "javascript:(function(){var w=window.open(" \
614 "'about:blank','gnotesWin','location=0,menubar=0," \ 614 "'about:blank','gnotesWin','location=0,menubar=0," \
615 "scrollbars=0,status=0,toolbar=0,width=300," \ 615 "scrollbars=0,status=0,toolbar=0,width=300," \
616 "height=300,resizable');});"); 616 "height=300,resizable');});");
617 adds.AddURL(L"", javascript_url, other_bookmarks_id(), 0); 617 adds.AddURL(L"", javascript_url, other_bookmarks_id(), 0);
618 int64 u6 = adds.AddURL(L"Sync1", "http://www.syncable.edu/", 618 int64 u6 = adds.AddURL(L"Sync1", "http://www.syncable.edu/",
619 synced_bookmarks_id(), 0); 619 synced_bookmarks_id(), 0);
620 620
621 std::vector<sync_api::SyncManager::ChangeRecord>::const_iterator it; 621 sync_api::ChangeRecordList::const_iterator it;
622 // The bookmark model shouldn't yet have seen any of the nodes of |adds|. 622 // The bookmark model shouldn't yet have seen any of the nodes of |adds|.
623 for (it = adds.changes().begin(); it != adds.changes().end(); ++it) 623 for (it = adds.changes().begin(); it != adds.changes().end(); ++it)
624 ExpectBrowserNodeUnknown(it->id); 624 ExpectBrowserNodeUnknown(it->id);
625 625
626 adds.ApplyPendingChanges(change_processor_.get()); 626 adds.ApplyPendingChanges(change_processor_.get());
627 627
628 // Make sure the bookmark model received all of the nodes in |adds|. 628 // Make sure the bookmark model received all of the nodes in |adds|.
629 for (it = adds.changes().begin(); it != adds.changes().end(); ++it) 629 for (it = adds.changes().begin(); it != adds.changes().end(); ++it)
630 ExpectBrowserNodeMatching(&trans, it->id); 630 ExpectBrowserNodeMatching(&trans, it->id);
631 ExpectModelMatch(&trans); 631 ExpectModelMatch(&trans);
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after
700 FakeServerChange adds(&trans); 700 FakeServerChange adds(&trans);
701 int64 f0 = other_bookmarks_id(); // + other_node 701 int64 f0 = other_bookmarks_id(); // + other_node
702 int64 f1 = adds.AddFolder(L"f1", f0, 0); // + f1 702 int64 f1 = adds.AddFolder(L"f1", f0, 0); // + f1
703 int64 f2 = adds.AddFolder(L"f2", f1, 0); // + f2 703 int64 f2 = adds.AddFolder(L"f2", f1, 0); // + f2
704 int64 u3 = adds.AddURL( L"u3", url, f2, 0); // + u3 NOLINT 704 int64 u3 = adds.AddURL( L"u3", url, f2, 0); // + u3 NOLINT
705 int64 u4 = adds.AddURL( L"u4", url, f2, u3); // + u4 NOLINT 705 int64 u4 = adds.AddURL( L"u4", url, f2, u3); // + u4 NOLINT
706 int64 u5 = adds.AddURL( L"u5", url, f1, f2); // + u5 NOLINT 706 int64 u5 = adds.AddURL( L"u5", url, f1, f2); // + u5 NOLINT
707 int64 f6 = adds.AddFolder(L"f6", f1, u5); // + f6 707 int64 f6 = adds.AddFolder(L"f6", f1, u5); // + f6
708 int64 u7 = adds.AddURL( L"u7", url, f0, f1); // + u7 NOLINT 708 int64 u7 = adds.AddURL( L"u7", url, f0, f1); // + u7 NOLINT
709 709
710 std::vector<sync_api::SyncManager::ChangeRecord>::const_iterator it; 710 sync_api::ChangeRecordList::const_iterator it;
711 // The bookmark model shouldn't yet have seen any of the nodes of |adds|. 711 // The bookmark model shouldn't yet have seen any of the nodes of |adds|.
712 for (it = adds.changes().begin(); it != adds.changes().end(); ++it) 712 for (it = adds.changes().begin(); it != adds.changes().end(); ++it)
713 ExpectBrowserNodeUnknown(it->id); 713 ExpectBrowserNodeUnknown(it->id);
714 714
715 adds.ApplyPendingChanges(change_processor_.get()); 715 adds.ApplyPendingChanges(change_processor_.get());
716 716
717 // Make sure the bookmark model received all of the nodes in |adds|. 717 // Make sure the bookmark model received all of the nodes in |adds|.
718 for (it = adds.changes().begin(); it != adds.changes().end(); ++it) 718 for (it = adds.changes().begin(); it != adds.changes().end(); ++it)
719 ExpectBrowserNodeMatching(&trans, it->id); 719 ExpectBrowserNodeMatching(&trans, it->id);
720 ExpectModelMatch(&trans); 720 ExpectModelMatch(&trans);
(...skipping 710 matching lines...) Expand 10 before | Expand all | Expand 10 after
1431 // Make sure we're back in sync. In real life, the user would need 1431 // Make sure we're back in sync. In real life, the user would need
1432 // to reauthenticate before this happens, but in the test, authentication 1432 // to reauthenticate before this happens, but in the test, authentication
1433 // is sidestepped. 1433 // is sidestepped.
1434 ExpectBookmarkModelMatchesTestData(); 1434 ExpectBookmarkModelMatchesTestData();
1435 ExpectModelMatch(); 1435 ExpectModelMatch();
1436 } 1436 }
1437 1437
1438 } // namespace 1438 } // namespace
1439 1439
1440 } // namespace browser_sync 1440 } // namespace browser_sync
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698