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

Side by Side Diff: chrome/browser/sync/engine/syncer_thread_unittest.cc

Issue 553015: Support for multiple sync ModelSafeWorkers.... (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 10 years, 11 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
« no previous file with comments | « chrome/browser/sync/engine/syncapi.cc ('k') | chrome/browser/sync/engine/syncer_types.h » ('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) 2009 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2009 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 #include <list> 5 #include <list>
6 #include <map> 6 #include <map>
7 #include <set> 7 #include <set>
8 8
9 #include "base/command_line.h" 9 #include "base/command_line.h"
10 #include "base/scoped_ptr.h" 10 #include "base/scoped_ptr.h"
11 #include "base/time.h" 11 #include "base/time.h"
12 #include "base/waitable_event.h" 12 #include "base/waitable_event.h"
13 #include "chrome/browser/sync/engine/model_safe_worker.h" 13 #include "chrome/browser/sync/engine/model_safe_worker.h"
14 #include "chrome/browser/sync/engine/syncer_thread.h" 14 #include "chrome/browser/sync/engine/syncer_thread.h"
15 #include "chrome/browser/sync/sessions/sync_session_context.h" 15 #include "chrome/browser/sync/sessions/sync_session_context.h"
16 #include "chrome/test/sync/engine/mock_server_connection.h" 16 #include "chrome/test/sync/engine/mock_server_connection.h"
17 #include "chrome/test/sync/engine/test_directory_setter_upper.h" 17 #include "chrome/test/sync/engine/test_directory_setter_upper.h"
18 #include "testing/gtest/include/gtest/gtest.h" 18 #include "testing/gtest/include/gtest/gtest.h"
19 19
20 using base::TimeTicks; 20 using base::TimeTicks;
21 using base::TimeDelta; 21 using base::TimeDelta;
22 22
23 namespace browser_sync { 23 namespace browser_sync {
24 using sessions::SyncSessionContext; 24 using sessions::SyncSessionContext;
25 25
26 typedef testing::Test SyncerThreadTest; 26 typedef testing::Test SyncerThreadTest;
27 typedef SyncerThread::WaitInterval WaitInterval; 27 typedef SyncerThread::WaitInterval WaitInterval;
28 28
29 class SyncerThreadWithSyncerTest : public testing::Test { 29 class SyncerThreadWithSyncerTest : public testing::Test,
30 public ModelSafeWorkerRegistrar {
30 public: 31 public:
31 SyncerThreadWithSyncerTest() : sync_cycle_ended_event_(false, false) {} 32 SyncerThreadWithSyncerTest() : sync_cycle_ended_event_(false, false) {}
32 virtual void SetUp() { 33 virtual void SetUp() {
33 metadb_.SetUp(); 34 metadb_.SetUp();
34 connection_.reset(new MockConnectionManager(metadb_.manager(), 35 connection_.reset(new MockConnectionManager(metadb_.manager(),
35 metadb_.name())); 36 metadb_.name()));
36 allstatus_.reset(new AllStatus()); 37 allstatus_.reset(new AllStatus());
38 worker_.reset(new ModelSafeWorker());
37 SyncSessionContext* context = new SyncSessionContext(connection_.get(), 39 SyncSessionContext* context = new SyncSessionContext(connection_.get(),
38 metadb_.manager(), new ModelSafeWorker()); 40 metadb_.manager(), this);
39 syncer_thread_ = new SyncerThread(context, allstatus_.get()); 41 syncer_thread_ = new SyncerThread(context, allstatus_.get());
40 syncer_event_hookup_.reset( 42 syncer_event_hookup_.reset(
41 NewEventListenerHookup(syncer_thread_->relay_channel(), this, 43 NewEventListenerHookup(syncer_thread_->relay_channel(), this,
42 &SyncerThreadWithSyncerTest::HandleSyncerEvent)); 44 &SyncerThreadWithSyncerTest::HandleSyncerEvent));
43 allstatus_->WatchSyncerThread(syncer_thread_); 45 allstatus_->WatchSyncerThread(syncer_thread_);
44 syncer_thread_->SetConnected(true); 46 syncer_thread_->SetConnected(true);
45 } 47 }
46 virtual void TearDown() { 48 virtual void TearDown() {
47 syncer_thread_ = NULL; 49 syncer_thread_ = NULL;
48 allstatus_.reset(); 50 allstatus_.reset();
49 connection_.reset(); 51 connection_.reset();
50 metadb_.TearDown(); 52 metadb_.TearDown();
51 } 53 }
52 54
55 // ModelSafeWorkerRegistrar implementation.
56 virtual void GetWorkers(std::vector<ModelSafeWorker*>* out) {
57 out->push_back(worker_.get());
58 }
59
60 virtual void GetModelSafeRoutingInfo(ModelSafeRoutingInfo* out) {
61 // We're just testing the sync engine here, so we shunt everything to
62 // the SyncerThread.
63 (*out)[syncable::BOOKMARKS] = GROUP_PASSIVE;
64 }
65
53 ManuallyOpenedTestDirectorySetterUpper* metadb() { return &metadb_; } 66 ManuallyOpenedTestDirectorySetterUpper* metadb() { return &metadb_; }
54 MockConnectionManager* connection() { return connection_.get(); } 67 MockConnectionManager* connection() { return connection_.get(); }
55 SyncerThread* syncer_thread() { return syncer_thread_; } 68 SyncerThread* syncer_thread() { return syncer_thread_; }
56 69
57 // Waits an indefinite amount of sync cycles for the syncer thread to become 70 // Waits an indefinite amount of sync cycles for the syncer thread to become
58 // throttled. Only call this if a throttle is supposed to occur! 71 // throttled. Only call this if a throttle is supposed to occur!
59 void WaitForThrottle() { 72 void WaitForThrottle() {
60 while (!syncer_thread()->IsSyncingCurrentlySilenced()) 73 while (!syncer_thread()->IsSyncingCurrentlySilenced())
61 sync_cycle_ended_event_.Wait(); 74 sync_cycle_ended_event_.Wait();
62 } 75 }
63 76
64 private: 77 private:
65 78
66 void HandleSyncerEvent(const SyncerEvent& event) { 79 void HandleSyncerEvent(const SyncerEvent& event) {
67 if (event.what_happened == SyncerEvent::SYNC_CYCLE_ENDED) 80 if (event.what_happened == SyncerEvent::SYNC_CYCLE_ENDED)
68 sync_cycle_ended_event_.Signal(); 81 sync_cycle_ended_event_.Signal();
69 } 82 }
70 83
71 ManuallyOpenedTestDirectorySetterUpper metadb_; 84 ManuallyOpenedTestDirectorySetterUpper metadb_;
72 scoped_ptr<MockConnectionManager> connection_; 85 scoped_ptr<MockConnectionManager> connection_;
73 scoped_ptr<AllStatus> allstatus_; 86 scoped_ptr<AllStatus> allstatus_;
74 scoped_refptr<SyncerThread> syncer_thread_; 87 scoped_refptr<SyncerThread> syncer_thread_;
88 scoped_ptr<ModelSafeWorker> worker_;
75 scoped_ptr<EventListenerHookup> syncer_event_hookup_; 89 scoped_ptr<EventListenerHookup> syncer_event_hookup_;
76 base::WaitableEvent sync_cycle_ended_event_; 90 base::WaitableEvent sync_cycle_ended_event_;
77 DISALLOW_COPY_AND_ASSIGN(SyncerThreadWithSyncerTest); 91 DISALLOW_COPY_AND_ASSIGN(SyncerThreadWithSyncerTest);
78 }; 92 };
79 93
80 class SyncShareIntercept : public MockConnectionManager::ThrottleRequestVisitor, 94 class SyncShareIntercept : public MockConnectionManager::ThrottleRequestVisitor,
81 public MockConnectionManager::MidCommitObserver { 95 public MockConnectionManager::MidCommitObserver {
82 public: 96 public:
83 SyncShareIntercept() : sync_occured_(false, false), 97 SyncShareIntercept() : sync_occured_(false, false),
84 allow_multiple_interceptions_(true) {} 98 allow_multiple_interceptions_(true) {}
(...skipping 534 matching lines...) Expand 10 before | Expand all | Expand 10 after
619 // Wait until the syncer thread reports that it is throttled. Any further 633 // Wait until the syncer thread reports that it is throttled. Any further
620 // sync share interceptions will result in failure. If things are broken, 634 // sync share interceptions will result in failure. If things are broken,
621 // we may never halt. 635 // we may never halt.
622 WaitForThrottle(); 636 WaitForThrottle();
623 EXPECT_TRUE(syncer_thread()->IsSyncingCurrentlySilenced()); 637 EXPECT_TRUE(syncer_thread()->IsSyncingCurrentlySilenced());
624 638
625 EXPECT_TRUE(syncer_thread()->Stop(2000)); 639 EXPECT_TRUE(syncer_thread()->Stop(2000));
626 } 640 }
627 641
628 } // namespace browser_sync 642 } // namespace browser_sync
OLDNEW
« no previous file with comments | « chrome/browser/sync/engine/syncapi.cc ('k') | chrome/browser/sync/engine/syncer_types.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698