OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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/location.h" | 15 #include "base/location.h" |
16 #include "base/memory/scoped_ptr.h" | 16 #include "base/memory/scoped_ptr.h" |
17 #include "base/message_loop.h" | 17 #include "base/message_loop.h" |
18 #include "base/string16.h" | 18 #include "base/string16.h" |
19 #include "base/string_number_conversions.h" | 19 #include "base/string_number_conversions.h" |
20 #include "base/string_util.h" | 20 #include "base/string_util.h" |
21 #include "base/utf_string_conversions.h" | 21 #include "base/utf_string_conversions.h" |
22 #include "chrome/browser/bookmarks/base_bookmark_model_observer.h" | 22 #include "chrome/browser/bookmarks/base_bookmark_model_observer.h" |
23 #include "chrome/browser/bookmarks/bookmark_model.h" | 23 #include "chrome/browser/bookmarks/bookmark_model.h" |
24 #include "chrome/browser/bookmarks/bookmark_model_factory.h" | 24 #include "chrome/browser/bookmarks/bookmark_model_factory.h" |
25 #include "chrome/browser/sync/abstract_profile_sync_service_test.h" | |
26 #include "chrome/browser/sync/glue/bookmark_change_processor.h" | 25 #include "chrome/browser/sync/glue/bookmark_change_processor.h" |
27 #include "chrome/browser/sync/glue/bookmark_model_associator.h" | 26 #include "chrome/browser/sync/glue/bookmark_model_associator.h" |
28 #include "chrome/browser/sync/glue/data_type_error_handler.h" | 27 #include "chrome/browser/sync/glue/data_type_error_handler.h" |
29 #include "chrome/browser/sync/glue/data_type_error_handler_mock.h" | 28 #include "chrome/browser/sync/glue/data_type_error_handler_mock.h" |
30 #include "chrome/common/chrome_switches.h" | 29 #include "chrome/common/chrome_switches.h" |
31 #include "chrome/test/base/testing_profile.h" | 30 #include "chrome/test/base/testing_profile.h" |
32 #include "content/public/test/test_browser_thread.h" | 31 #include "content/public/test/test_browser_thread.h" |
33 #include "sync/api/sync_error.h" | 32 #include "sync/api/sync_error.h" |
34 #include "sync/internal_api/public/change_record.h" | 33 #include "sync/internal_api/public/change_record.h" |
35 #include "sync/internal_api/public/read_node.h" | 34 #include "sync/internal_api/public/read_node.h" |
36 #include "sync/internal_api/public/read_transaction.h" | 35 #include "sync/internal_api/public/read_transaction.h" |
37 #include "sync/internal_api/public/test/test_user_share.h" | 36 #include "sync/internal_api/public/test/test_user_share.h" |
38 #include "sync/internal_api/public/write_node.h" | 37 #include "sync/internal_api/public/write_node.h" |
39 #include "sync/internal_api/public/write_transaction.h" | 38 #include "sync/internal_api/public/write_transaction.h" |
40 #include "sync/syncable/mutable_entry.h" // TODO(tim): Remove. Bug 131130. | 39 #include "sync/syncable/mutable_entry.h" // TODO(tim): Remove. Bug 131130. |
41 #include "sync/test/engine/test_id_factory.h" | |
42 #include "testing/gmock/include/gmock/gmock.h" | 40 #include "testing/gmock/include/gmock/gmock.h" |
43 #include "testing/gtest/include/gtest/gtest.h" | 41 #include "testing/gtest/include/gtest/gtest.h" |
44 | 42 |
45 namespace browser_sync { | 43 namespace browser_sync { |
46 | 44 |
47 using content::BrowserThread; | 45 using content::BrowserThread; |
48 using syncer::BaseNode; | 46 using syncer::BaseNode; |
49 using testing::_; | 47 using testing::_; |
50 using testing::InvokeWithoutArgs; | 48 using testing::InvokeWithoutArgs; |
51 using testing::Mock; | 49 using testing::Mock; |
(...skipping 22 matching lines...) Expand all Loading... |
74 virtual bool GetSyncIdForTaggedNode(const std::string& tag, int64* sync_id) { | 72 virtual bool GetSyncIdForTaggedNode(const std::string& tag, int64* sync_id) { |
75 std::string tag_str = std::string(tag.c_str(), tag.length()); | 73 std::string tag_str = std::string(tag.c_str(), tag.length()); |
76 bool root_exists = false; | 74 bool root_exists = false; |
77 syncer::ModelType type = model_type(); | 75 syncer::ModelType type = model_type(); |
78 { | 76 { |
79 syncer::WriteTransaction trans(FROM_HERE, user_share_); | 77 syncer::WriteTransaction trans(FROM_HERE, user_share_); |
80 syncer::ReadNode uber_root(&trans); | 78 syncer::ReadNode uber_root(&trans); |
81 uber_root.InitByRootLookup(); | 79 uber_root.InitByRootLookup(); |
82 | 80 |
83 syncer::ReadNode root(&trans); | 81 syncer::ReadNode root(&trans); |
84 root_exists = root.InitByTagLookup( | 82 root_exists = (root.InitByTagLookup(syncer::ModelTypeToRootTag(type)) == |
85 ProfileSyncServiceTestHelper::GetTagForType(type)) == | 83 BaseNode::INIT_OK); |
86 BaseNode::INIT_OK; | |
87 } | 84 } |
88 | 85 |
89 if (!root_exists) { | 86 if (!root_exists) { |
90 bool created = ProfileSyncServiceTestHelper::CreateRoot( | 87 if (!syncer::TestUserShare::CreateRoot(type, user_share_)) |
91 type, | |
92 user_share_, | |
93 &id_factory_); | |
94 if (!created) | |
95 return false; | 88 return false; |
96 } | 89 } |
97 | 90 |
98 syncer::WriteTransaction trans(FROM_HERE, user_share_); | 91 syncer::WriteTransaction trans(FROM_HERE, user_share_); |
99 syncer::ReadNode root(&trans); | 92 syncer::ReadNode root(&trans); |
100 EXPECT_EQ(BaseNode::INIT_OK, root.InitByTagLookup( | 93 EXPECT_EQ(BaseNode::INIT_OK, root.InitByTagLookup( |
101 ProfileSyncServiceTestHelper::GetTagForType(type))); | 94 syncer::ModelTypeToRootTag(type))); |
102 | 95 |
103 // First, try to find a node with the title among the root's children. | 96 // First, try to find a node with the title among the root's children. |
104 // This will be the case if we are testing model persistence, and | 97 // This will be the case if we are testing model persistence, and |
105 // are reloading a sync repository created earlier in the test. | 98 // are reloading a sync repository created earlier in the test. |
106 int64 last_child_id = syncer::kInvalidId; | 99 int64 last_child_id = syncer::kInvalidId; |
107 for (int64 id = root.GetFirstChildId(); id != syncer::kInvalidId; /***/) { | 100 for (int64 id = root.GetFirstChildId(); id != syncer::kInvalidId; /***/) { |
108 syncer::ReadNode child(&trans); | 101 syncer::ReadNode child(&trans); |
109 EXPECT_EQ(BaseNode::INIT_OK, child.InitByIdLookup(id)); | 102 EXPECT_EQ(BaseNode::INIT_OK, child.InitByIdLookup(id)); |
110 last_child_id = id; | 103 last_child_id = id; |
111 if (tag_str == child.GetTitle()) { | 104 if (tag_str == child.GetTitle()) { |
(...skipping 17 matching lines...) Expand all Loading... |
129 node.GetMutableEntryForTest()->Put( | 122 node.GetMutableEntryForTest()->Put( |
130 syncer::syncable::UNIQUE_SERVER_TAG, tag); | 123 syncer::syncable::UNIQUE_SERVER_TAG, tag); |
131 node.SetTitle(UTF8ToWide(tag_str)); | 124 node.SetTitle(UTF8ToWide(tag_str)); |
132 node.SetExternalId(0); | 125 node.SetExternalId(0); |
133 *sync_id = node.GetId(); | 126 *sync_id = node.GetId(); |
134 return true; | 127 return true; |
135 } | 128 } |
136 | 129 |
137 private: | 130 private: |
138 syncer::UserShare* user_share_; | 131 syncer::UserShare* user_share_; |
139 syncer::TestIdFactory id_factory_; | |
140 }; | 132 }; |
141 | 133 |
142 namespace { | 134 namespace { |
143 | 135 |
144 // FakeServerChange constructs a list of syncer::ChangeRecords while modifying | 136 // FakeServerChange constructs a list of syncer::ChangeRecords while modifying |
145 // the sync model, and can pass the ChangeRecord list to a | 137 // the sync model, and can pass the ChangeRecord list to a |
146 // syncer::SyncObserver (i.e., the ProfileSyncService) to test the client | 138 // syncer::SyncObserver (i.e., the ProfileSyncService) to test the client |
147 // change-application behavior. | 139 // change-application behavior. |
148 // Tests using FakeServerChange should be careful to avoid back-references, | 140 // Tests using FakeServerChange should be careful to avoid back-references, |
149 // since FakeServerChange will send the edits in the order specified. | 141 // since FakeServerChange will send the edits in the order specified. |
(...skipping 1348 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1498 EXPECT_EQ(1, observer.get_started()); | 1490 EXPECT_EQ(1, observer.get_started()); |
1499 EXPECT_EQ(0, observer.get_completed_count_at_started()); | 1491 EXPECT_EQ(0, observer.get_completed_count_at_started()); |
1500 EXPECT_EQ(1, observer.get_completed()); | 1492 EXPECT_EQ(1, observer.get_completed()); |
1501 | 1493 |
1502 model_->RemoveObserver(&observer); | 1494 model_->RemoveObserver(&observer); |
1503 } | 1495 } |
1504 | 1496 |
1505 } // namespace | 1497 } // namespace |
1506 | 1498 |
1507 } // namespace browser_sync | 1499 } // namespace browser_sync |
OLD | NEW |