OLD | NEW |
| (Empty) |
1 // Copyright 2012 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. | |
4 | |
5 #include "sync/sessions/sync_session.h" | |
6 | |
7 #include "base/compiler_specific.h" | |
8 #include "base/location.h" | |
9 #include "base/memory/ref_counted.h" | |
10 #include "base/message_loop/message_loop.h" | |
11 #include "sync/engine/syncer_types.h" | |
12 #include "sync/internal_api/public/base/model_type.h" | |
13 #include "sync/sessions/status_controller.h" | |
14 #include "sync/syncable/syncable_id.h" | |
15 #include "sync/syncable/syncable_write_transaction.h" | |
16 #include "sync/test/engine/fake_model_worker.h" | |
17 #include "sync/test/engine/test_directory_setter_upper.h" | |
18 #include "sync/util/extensions_activity.h" | |
19 #include "testing/gtest/include/gtest/gtest.h" | |
20 | |
21 namespace syncer { | |
22 | |
23 using syncable::WriteTransaction; | |
24 | |
25 namespace sessions { | |
26 namespace { | |
27 | |
28 class SyncSessionTest : public testing::Test, | |
29 public SyncSession::Delegate { | |
30 public: | |
31 SyncSessionTest() : controller_invocations_allowed_(false) {} | |
32 | |
33 SyncSession* MakeSession() { | |
34 return SyncSession::Build(context_.get(), this); | |
35 } | |
36 | |
37 virtual void SetUp() { | |
38 extensions_activity_ = new ExtensionsActivity(); | |
39 | |
40 routes_.clear(); | |
41 routes_[BOOKMARKS] = GROUP_UI; | |
42 routes_[AUTOFILL] = GROUP_DB; | |
43 scoped_refptr<ModelSafeWorker> passive_worker( | |
44 new FakeModelWorker(GROUP_PASSIVE)); | |
45 scoped_refptr<ModelSafeWorker> ui_worker( | |
46 new FakeModelWorker(GROUP_UI)); | |
47 scoped_refptr<ModelSafeWorker> db_worker( | |
48 new FakeModelWorker(GROUP_DB)); | |
49 workers_.clear(); | |
50 workers_.push_back(passive_worker); | |
51 workers_.push_back(ui_worker); | |
52 workers_.push_back(db_worker); | |
53 | |
54 context_.reset( | |
55 new SyncSessionContext( | |
56 NULL, | |
57 NULL, | |
58 workers_, | |
59 extensions_activity_.get(), | |
60 std::vector<SyncEngineEventListener*>(), | |
61 NULL, | |
62 NULL, | |
63 true, // enable keystore encryption | |
64 false, // force enable pre-commit GU avoidance experiment | |
65 "fake_invalidator_client_id")); | |
66 context_->set_routing_info(routes_); | |
67 | |
68 session_.reset(MakeSession()); | |
69 } | |
70 virtual void TearDown() { | |
71 session_.reset(); | |
72 context_.reset(); | |
73 } | |
74 | |
75 virtual void OnThrottled(const base::TimeDelta& throttle_duration) OVERRIDE { | |
76 FailControllerInvocationIfDisabled("OnThrottled"); | |
77 } | |
78 virtual void OnTypesThrottled( | |
79 ModelTypeSet types, | |
80 const base::TimeDelta& throttle_duration) OVERRIDE { | |
81 FailControllerInvocationIfDisabled("OnTypesThrottled"); | |
82 } | |
83 virtual bool IsCurrentlyThrottled() OVERRIDE { | |
84 FailControllerInvocationIfDisabled("IsSyncingCurrentlySilenced"); | |
85 return false; | |
86 } | |
87 virtual void OnReceivedLongPollIntervalUpdate( | |
88 const base::TimeDelta& new_interval) OVERRIDE { | |
89 FailControllerInvocationIfDisabled("OnReceivedLongPollIntervalUpdate"); | |
90 } | |
91 virtual void OnReceivedShortPollIntervalUpdate( | |
92 const base::TimeDelta& new_interval) OVERRIDE { | |
93 FailControllerInvocationIfDisabled("OnReceivedShortPollIntervalUpdate"); | |
94 } | |
95 virtual void OnReceivedSessionsCommitDelay( | |
96 const base::TimeDelta& new_delay) OVERRIDE { | |
97 FailControllerInvocationIfDisabled("OnReceivedSessionsCommitDelay"); | |
98 } | |
99 virtual void OnReceivedClientInvalidationHintBufferSize( | |
100 int size) OVERRIDE { | |
101 FailControllerInvocationIfDisabled( | |
102 "OnReceivedClientInvalidationHintBufferSize"); | |
103 } | |
104 virtual void OnSyncProtocolError( | |
105 const sessions::SyncSessionSnapshot& snapshot) OVERRIDE { | |
106 FailControllerInvocationIfDisabled("SyncProtocolError"); | |
107 } | |
108 | |
109 void GetModelSafeRoutingInfo(ModelSafeRoutingInfo* out) const { | |
110 *out = routes_; | |
111 } | |
112 | |
113 StatusController* status() { return session_->mutable_status_controller(); } | |
114 protected: | |
115 void FailControllerInvocationIfDisabled(const std::string& msg) { | |
116 if (!controller_invocations_allowed_) | |
117 FAIL() << msg; | |
118 } | |
119 | |
120 ModelTypeSet ParamsMeaningAllEnabledTypes() { | |
121 ModelTypeSet request_params(BOOKMARKS, AUTOFILL); | |
122 return request_params; | |
123 } | |
124 | |
125 ModelTypeSet ParamsMeaningJustOneEnabledType() { | |
126 return ModelTypeSet(AUTOFILL); | |
127 } | |
128 | |
129 base::MessageLoop message_loop_; | |
130 bool controller_invocations_allowed_; | |
131 scoped_ptr<SyncSession> session_; | |
132 scoped_ptr<SyncSessionContext> context_; | |
133 std::vector<scoped_refptr<ModelSafeWorker> > workers_; | |
134 ModelSafeRoutingInfo routes_; | |
135 scoped_refptr<ExtensionsActivity> extensions_activity_; | |
136 }; | |
137 | |
138 } // namespace | |
139 } // namespace sessions | |
140 } // namespace syncer | |
OLD | NEW |