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

Side by Side Diff: chrome/browser/sync/internal_api/js_sync_manager_observer_unittest.cc

Issue 10147003: [Sync] Move 'syncapi_core' and 'sync_unit_tests' targets to sync/ (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fix Win update errors Created 8 years, 8 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
(Empty)
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
3 // found in the LICENSE file.
4
5 #include "chrome/browser/sync/internal_api/js_sync_manager_observer.h"
6
7 #include "base/basictypes.h"
8 #include "base/location.h"
9 #include "base/message_loop.h"
10 #include "base/values.h"
11 #include "sync/js/js_event_details.h"
12 #include "sync/js/js_test_util.h"
13 #include "sync/protocol/sync_protocol_error.h"
14 #include "sync/sessions/session_state.h"
15 #include "sync/syncable/model_type.h"
16 #include "sync/util/weak_handle.h"
17 #include "testing/gtest/include/gtest/gtest.h"
18
19 namespace browser_sync {
20 namespace {
21
22 using ::testing::InSequence;
23 using ::testing::StrictMock;
24
25 class JsSyncManagerObserverTest : public testing::Test {
26 protected:
27 JsSyncManagerObserverTest() {
28 js_sync_manager_observer_.SetJsEventHandler(
29 mock_js_event_handler_.AsWeakHandle());
30 }
31
32 private:
33 // This must be destroyed after the member variables below in order
34 // for WeakHandles to be destroyed properly.
35 MessageLoop message_loop_;
36
37 protected:
38 StrictMock<MockJsEventHandler> mock_js_event_handler_;
39 JsSyncManagerObserver js_sync_manager_observer_;
40
41 void PumpLoop() {
42 message_loop_.RunAllPending();
43 }
44 };
45
46 TEST_F(JsSyncManagerObserverTest, NoArgNotifiations) {
47 InSequence dummy;
48
49 EXPECT_CALL(mock_js_event_handler_,
50 HandleJsEvent("onInitializationComplete",
51 HasDetails(JsEventDetails())));
52 EXPECT_CALL(mock_js_event_handler_,
53 HandleJsEvent("onStopSyncingPermanently",
54 HasDetails(JsEventDetails())));
55 EXPECT_CALL(mock_js_event_handler_,
56 HandleJsEvent("onClearServerDataSucceeded",
57 HasDetails(JsEventDetails())));
58 EXPECT_CALL(mock_js_event_handler_,
59 HandleJsEvent("onClearServerDataFailed",
60 HasDetails(JsEventDetails())));
61 EXPECT_CALL(mock_js_event_handler_,
62 HandleJsEvent("onEncryptionComplete",
63 HasDetails(JsEventDetails())));
64
65 js_sync_manager_observer_.OnInitializationComplete(WeakHandle<JsBackend>(),
66 true);
67 js_sync_manager_observer_.OnStopSyncingPermanently();
68 js_sync_manager_observer_.OnClearServerDataSucceeded();
69 js_sync_manager_observer_.OnClearServerDataFailed();
70 js_sync_manager_observer_.OnEncryptionComplete();
71 PumpLoop();
72 }
73
74 TEST_F(JsSyncManagerObserverTest, OnSyncCycleCompleted) {
75 std::string download_progress_markers[syncable::MODEL_TYPE_COUNT];
76 sessions::SyncSessionSnapshot snapshot(sessions::SyncerStatus(),
77 sessions::ErrorCounters(),
78 100,
79 false,
80 syncable::ModelTypeSet(),
81 download_progress_markers,
82 false,
83 true,
84 100,
85 8,
86 5,
87 2,
88 7,
89 false,
90 sessions::SyncSourceInfo(),
91 false,
92 0,
93 base::Time::Now(),
94 false);
95 DictionaryValue expected_details;
96 expected_details.Set("snapshot", snapshot.ToValue());
97
98 EXPECT_CALL(mock_js_event_handler_,
99 HandleJsEvent("onSyncCycleCompleted",
100 HasDetailsAsDictionary(expected_details)));
101
102 js_sync_manager_observer_.OnSyncCycleCompleted(&snapshot);
103 PumpLoop();
104 }
105
106 TEST_F(JsSyncManagerObserverTest, OnActionableError) {
107 browser_sync::SyncProtocolError sync_error;
108 sync_error.action = browser_sync::CLEAR_USER_DATA_AND_RESYNC;
109 sync_error.error_type = browser_sync::TRANSIENT_ERROR;
110 DictionaryValue expected_details;
111 expected_details.Set("syncError", sync_error.ToValue());
112
113 EXPECT_CALL(mock_js_event_handler_,
114 HandleJsEvent("onActionableError",
115 HasDetailsAsDictionary(expected_details)));
116
117 js_sync_manager_observer_.OnActionableError(sync_error);
118 PumpLoop();
119 }
120
121
122 TEST_F(JsSyncManagerObserverTest, OnConnectionStatusChange) {
123 const sync_api::ConnectionStatus kStatus =
124 sync_api::CONNECTION_AUTH_ERROR;
125 DictionaryValue expected_details;
126 expected_details.SetString("status",
127 sync_api::ConnectionStatusToString(kStatus));
128
129 EXPECT_CALL(mock_js_event_handler_,
130 HandleJsEvent("onConnectionStatusChange",
131 HasDetailsAsDictionary(expected_details)));
132
133 js_sync_manager_observer_.OnConnectionStatusChange(kStatus);
134 PumpLoop();
135 }
136
137 TEST_F(JsSyncManagerObserverTest, OnPassphraseRequired) {
138 InSequence dummy;
139
140 DictionaryValue reason_passphrase_not_required_details;
141 DictionaryValue reason_encryption_details;
142 DictionaryValue reason_decryption_details;
143
144 reason_passphrase_not_required_details.SetString(
145 "reason",
146 sync_api::PassphraseRequiredReasonToString(
147 sync_api::REASON_PASSPHRASE_NOT_REQUIRED));
148 reason_encryption_details.SetString(
149 "reason",
150 sync_api::PassphraseRequiredReasonToString(sync_api::REASON_ENCRYPTION));
151 reason_decryption_details.SetString(
152 "reason",
153 sync_api::PassphraseRequiredReasonToString(sync_api::REASON_DECRYPTION));
154
155 EXPECT_CALL(mock_js_event_handler_,
156 HandleJsEvent("onPassphraseRequired",
157 HasDetailsAsDictionary(
158 reason_passphrase_not_required_details)));
159 EXPECT_CALL(mock_js_event_handler_,
160 HandleJsEvent("onPassphraseRequired",
161 HasDetailsAsDictionary(reason_encryption_details)));
162 EXPECT_CALL(mock_js_event_handler_,
163 HandleJsEvent("onPassphraseRequired",
164 HasDetailsAsDictionary(reason_decryption_details)));
165
166 js_sync_manager_observer_.OnPassphraseRequired(
167 sync_api::REASON_PASSPHRASE_NOT_REQUIRED,
168 sync_pb::EncryptedData());
169 js_sync_manager_observer_.OnPassphraseRequired(sync_api::REASON_ENCRYPTION,
170 sync_pb::EncryptedData());
171 js_sync_manager_observer_.OnPassphraseRequired(sync_api::REASON_DECRYPTION,
172 sync_pb::EncryptedData());
173 PumpLoop();
174 }
175
176 TEST_F(JsSyncManagerObserverTest, SensitiveNotifiations) {
177 DictionaryValue redacted_token_details;
178 redacted_token_details.SetString("token", "<redacted>");
179 DictionaryValue redacted_bootstrap_token_details;
180 redacted_bootstrap_token_details.SetString("bootstrapToken", "<redacted>");
181
182 EXPECT_CALL(mock_js_event_handler_,
183 HandleJsEvent("onUpdatedToken",
184 HasDetailsAsDictionary(redacted_token_details)));
185 EXPECT_CALL(mock_js_event_handler_,
186 HandleJsEvent(
187 "OnBootstrapTokenUpdated",
188 HasDetailsAsDictionary(redacted_bootstrap_token_details)));
189
190 js_sync_manager_observer_.OnUpdatedToken("sensitive_token");
191 js_sync_manager_observer_.OnBootstrapTokenUpdated("sensitive_token");
192 PumpLoop();
193 }
194
195 TEST_F(JsSyncManagerObserverTest, OnEncryptedTypesChanged) {
196 DictionaryValue expected_details;
197 ListValue* encrypted_type_values = new ListValue();
198 const bool encrypt_everything = false;
199 expected_details.Set("encryptedTypes", encrypted_type_values);
200 expected_details.SetBoolean("encryptEverything", encrypt_everything);
201 syncable::ModelTypeSet encrypted_types;
202
203 for (int i = syncable::FIRST_REAL_MODEL_TYPE;
204 i < syncable::MODEL_TYPE_COUNT; ++i) {
205 syncable::ModelType type = syncable::ModelTypeFromInt(i);
206 encrypted_types.Put(type);
207 encrypted_type_values->Append(Value::CreateStringValue(
208 syncable::ModelTypeToString(type)));
209 }
210
211 EXPECT_CALL(mock_js_event_handler_,
212 HandleJsEvent("onEncryptedTypesChanged",
213 HasDetailsAsDictionary(expected_details)));
214
215 js_sync_manager_observer_.OnEncryptedTypesChanged(
216 encrypted_types, encrypt_everything);
217 PumpLoop();
218 }
219
220 } // namespace
221 } // namespace browser_sync
OLDNEW
« no previous file with comments | « chrome/browser/sync/internal_api/js_sync_manager_observer.cc ('k') | chrome/browser/sync/internal_api/read_node.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698