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

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

Issue 292008: Fix ProfileSyncService unit test. (Closed)
Patch Set: Created 11 years, 2 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
« no previous file with comments | « chrome/browser/sync/glue/sync_backend_host.cc ('k') | chrome/chrome.gyp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2006-2008 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 #if defined(BROWSER_SYNC) 5 #if defined(BROWSER_SYNC)
6 6
7 #include <stack> 7 #include <stack>
8 #include <vector> 8 #include <vector>
9 9
10 #include "testing/gtest/include/gtest/gtest.h" 10 #include "testing/gtest/include/gtest/gtest.h"
11 11
12 #include "base/command_line.h" 12 #include "base/command_line.h"
13 #include "base/string_util.h" 13 #include "base/string_util.h"
14 #include "base/string16.h" 14 #include "base/string16.h"
15 #include "chrome/browser/bookmarks/bookmark_model.h" 15 #include "chrome/browser/bookmarks/bookmark_model.h"
16 #include "chrome/browser/profile.h" 16 #include "chrome/browser/profile.h"
17 #include "chrome/browser/sync/engine/syncapi.h" 17 #include "chrome/browser/sync/engine/syncapi.h"
18 #include "chrome/browser/sync/glue/model_associator.h" 18 #include "chrome/browser/sync/glue/model_associator.h"
19 #include "chrome/browser/sync/glue/sync_backend_host.h" 19 #include "chrome/browser/sync/glue/sync_backend_host.h"
20 #include "chrome/browser/sync/profile_sync_service.h" 20 #include "chrome/browser/sync/profile_sync_service.h"
21 #include "chrome/common/chrome_switches.h" 21 #include "chrome/common/chrome_switches.h"
22 #include "chrome/test/testing_profile.h" 22 #include "chrome/test/testing_profile.h"
23 #include "chrome/test/sync/test_http_bridge_factory.h"
23 24
24 using std::vector; 25 using std::vector;
25 using browser_sync::ChangeProcessingInterface; 26 using browser_sync::ChangeProcessingInterface;
26 using browser_sync::ModelAssociator; 27 using browser_sync::ModelAssociator;
27 using browser_sync::SyncBackendHost; 28 using browser_sync::SyncBackendHost;
29 using browser_sync::TestHttpBridgeFactory;
28 30
29 class TestModelAssociator : public ModelAssociator { 31 class TestModelAssociator : public ModelAssociator {
30 public: 32 public:
31 explicit TestModelAssociator(ProfileSyncService* service) 33 explicit TestModelAssociator(ProfileSyncService* service)
32 : ModelAssociator(service) { 34 : ModelAssociator(service) {
33 } 35 }
34 36
35 virtual bool GetSyncIdForTaggedNode(const string16& tag, int64* sync_id) { 37 virtual bool GetSyncIdForTaggedNode(const string16& tag, int64* sync_id) {
36 sync_api::WriteTransaction trans( 38 sync_api::WriteTransaction trans(
37 sync_service()->backend()->GetUserShareHandle()); 39 sync_service()->backend()->GetUserShareHandle());
38 sync_api::ReadNode root(&trans); 40 sync_api::ReadNode root(&trans);
39 root.InitByRootLookup(); 41 root.InitByRootLookup();
40 42
41 // First, try to find a node with the title among the root's children. 43 // First, try to find a node with the title among the root's children.
42 // This will be the case if we are testing model persistence, and 44 // This will be the case if we are testing model persistence, and
43 // are reloading a sync repository created earlier in the test. 45 // are reloading a sync repository created earlier in the test.
46 int64 last_child_id = sync_api::kInvalidId;
44 for (int64 id = root.GetFirstChildId(); id != sync_api::kInvalidId; /***/) { 47 for (int64 id = root.GetFirstChildId(); id != sync_api::kInvalidId; /***/) {
45 sync_api::ReadNode child(&trans); 48 sync_api::ReadNode child(&trans);
46 if (!child.InitByIdLookup(id)) { 49 child.InitByIdLookup(id);
47 NOTREACHED(); 50 last_child_id = id;
48 break;
49 }
50 if (tag == child.GetTitle()) { 51 if (tag == child.GetTitle()) {
51 *sync_id = id; 52 *sync_id = id;
52 return true; 53 return true;
53 } 54 }
54 id = child.GetSuccessorId(); 55 id = child.GetSuccessorId();
55 } 56 }
56 57
58 sync_api::ReadNode predecessor_node(&trans);
59 sync_api::ReadNode* predecessor = NULL;
60 if (last_child_id != sync_api::kInvalidId) {
61 predecessor_node.InitByIdLookup(last_child_id);
62 predecessor = &predecessor_node;
63 }
57 sync_api::WriteNode node(&trans); 64 sync_api::WriteNode node(&trans);
58 if (!node.InitByCreation(root, NULL)) 65 // Create new fake tagged nodes at the end of the ordering.
59 return false; 66 node.InitByCreation(root, predecessor);
60 node.SetIsFolder(true); 67 node.SetIsFolder(true);
61 node.SetTitle(tag.c_str()); 68 node.SetTitle(tag.c_str());
62 node.SetExternalId(0); 69 node.SetExternalId(0);
63 *sync_id = node.GetId(); 70 *sync_id = node.GetId();
64 return true; 71 return true;
65 } 72 }
66 }; 73 };
67 74
68 class TestProfileSyncService : public ProfileSyncService { 75 class TestProfileSyncService : public ProfileSyncService {
69 public: 76 public:
70 explicit TestProfileSyncService(Profile* profile) 77 explicit TestProfileSyncService(Profile* profile)
71 : ProfileSyncService(profile) { 78 : ProfileSyncService(profile) {
72 RegisterPreferences(); 79 RegisterPreferences();
73 SetSyncSetupCompleted(); 80 SetSyncSetupCompleted();
81
74 } 82 }
75 virtual ~TestProfileSyncService() { 83 virtual ~TestProfileSyncService() {
76 } 84 }
77 85
78 virtual void InitializeBackend() { 86 virtual void InitializeBackend() {
79 set_model_associator(new TestModelAssociator(this)); 87 set_model_associator(new TestModelAssociator(this));
80 backend()->InitializeForTestMode(L"testuser"); 88 TestHttpBridgeFactory* factory = new TestHttpBridgeFactory();
89 TestHttpBridgeFactory* factory2 = new TestHttpBridgeFactory();
90 backend()->InitializeForTestMode(L"testuser", factory, factory2);
81 // The SyncBackend posts a task to the current loop when initialization 91 // The SyncBackend posts a task to the current loop when initialization
82 // completes. 92 // completes.
83 MessageLoop::current()->Run(); 93 MessageLoop::current()->Run();
84 // Initialization is synchronous for test mode, so we should be good to go. 94 // Initialization is synchronous for test mode, so we should be good to go.
85 DCHECK(sync_initialized()); 95 DCHECK(sync_initialized());
86 } 96 }
87 97
88 virtual void OnBackendInitialized() { 98 virtual void OnBackendInitialized() {
89 ProfileSyncService::OnBackendInitialized(); 99 ProfileSyncService::OnBackendInitialized();
90 MessageLoop::current()->Quit(); 100 MessageLoop::current()->Quit();
(...skipping 1176 matching lines...) Expand 10 before | Expand all | Expand 10 after
1267 StartSyncService(); 1277 StartSyncService();
1268 1278
1269 // Make sure we're back in sync. In real life, the user would need 1279 // Make sure we're back in sync. In real life, the user would need
1270 // to reauthenticate before this happens, but in the test, authentication 1280 // to reauthenticate before this happens, but in the test, authentication
1271 // is sidestepped. 1281 // is sidestepped.
1272 ExpectBookmarkModelMatchesTestData(); 1282 ExpectBookmarkModelMatchesTestData();
1273 ExpectModelMatch(); 1283 ExpectModelMatch();
1274 } 1284 }
1275 1285
1276 #endif // defined(BROWSER_SYNC) 1286 #endif // defined(BROWSER_SYNC)
OLDNEW
« no previous file with comments | « chrome/browser/sync/glue/sync_backend_host.cc ('k') | chrome/chrome.gyp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698