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

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

Issue 7982049: [Sync] Move some code into new class JsMutationEventObserver (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fix deps Created 9 years, 3 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
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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 "chrome/browser/sync/js/js_sync_manager_observer.h" 5 #include "chrome/browser/sync/js/js_sync_manager_observer.h"
6 6
7 #include "base/basictypes.h" 7 #include "base/basictypes.h"
8 #include "base/location.h" 8 #include "base/location.h"
9 #include "base/message_loop.h" 9 #include "base/message_loop.h"
10 #include "base/values.h" 10 #include "base/values.h"
11 #include "chrome/browser/sync/js/js_arg_list.h"
12 #include "chrome/browser/sync/js/js_event_details.h" 11 #include "chrome/browser/sync/js/js_event_details.h"
13 #include "chrome/browser/sync/js/js_test_util.h" 12 #include "chrome/browser/sync/js/js_test_util.h"
14 #include "chrome/browser/sync/protocol/sync_protocol_error.h" 13 #include "chrome/browser/sync/protocol/sync_protocol_error.h"
15 #include "chrome/browser/sync/sessions/session_state.h" 14 #include "chrome/browser/sync/sessions/session_state.h"
16 #include "chrome/browser/sync/syncable/model_type.h" 15 #include "chrome/browser/sync/syncable/model_type.h"
17 #include "chrome/browser/sync/util/weak_handle.h" 16 #include "chrome/browser/sync/util/weak_handle.h"
18 #include "testing/gtest/include/gtest/gtest.h" 17 #include "testing/gtest/include/gtest/gtest.h"
19 18
20 namespace browser_sync { 19 namespace browser_sync {
21 namespace { 20 namespace {
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
61 HasDetails(JsEventDetails()))); 60 HasDetails(JsEventDetails())));
62 61
63 js_sync_manager_observer_.OnInitializationComplete(WeakHandle<JsBackend>(), 62 js_sync_manager_observer_.OnInitializationComplete(WeakHandle<JsBackend>(),
64 true); 63 true);
65 js_sync_manager_observer_.OnStopSyncingPermanently(); 64 js_sync_manager_observer_.OnStopSyncingPermanently();
66 js_sync_manager_observer_.OnClearServerDataSucceeded(); 65 js_sync_manager_observer_.OnClearServerDataSucceeded();
67 js_sync_manager_observer_.OnClearServerDataFailed(); 66 js_sync_manager_observer_.OnClearServerDataFailed();
68 PumpLoop(); 67 PumpLoop();
69 } 68 }
70 69
71 TEST_F(JsSyncManagerObserverTest, OnChangesComplete) {
72 InSequence dummy;
73
74 for (int i = syncable::FIRST_REAL_MODEL_TYPE;
75 i < syncable::MODEL_TYPE_COUNT; ++i) {
76 DictionaryValue expected_details;
77 expected_details.SetString(
78 "modelType",
79 syncable::ModelTypeToString(syncable::ModelTypeFromInt(i)));
80 EXPECT_CALL(mock_js_event_handler_,
81 HandleJsEvent("onChangesComplete",
82 HasDetailsAsDictionary(expected_details)));
83 }
84
85 for (int i = syncable::FIRST_REAL_MODEL_TYPE;
86 i < syncable::MODEL_TYPE_COUNT; ++i) {
87 js_sync_manager_observer_.OnChangesComplete(syncable::ModelTypeFromInt(i));
88 }
89 PumpLoop();
90 }
91
92 TEST_F(JsSyncManagerObserverTest, OnSyncCycleCompleted) { 70 TEST_F(JsSyncManagerObserverTest, OnSyncCycleCompleted) {
93 std::string download_progress_markers[syncable::MODEL_TYPE_COUNT]; 71 std::string download_progress_markers[syncable::MODEL_TYPE_COUNT];
94 sessions::SyncSessionSnapshot snapshot(sessions::SyncerStatus(), 72 sessions::SyncSessionSnapshot snapshot(sessions::SyncerStatus(),
95 sessions::ErrorCounters(), 73 sessions::ErrorCounters(),
96 100, 74 100,
97 false, 75 false,
98 syncable::ModelTypeBitSet(), 76 syncable::ModelTypeBitSet(),
99 download_progress_markers, 77 download_progress_markers,
100 false, 78 false,
101 true, 79 true,
(...skipping 125 matching lines...) Expand 10 before | Expand all | Expand 10 after
227 } 205 }
228 206
229 EXPECT_CALL(mock_js_event_handler_, 207 EXPECT_CALL(mock_js_event_handler_,
230 HandleJsEvent("onEncryptionComplete", 208 HandleJsEvent("onEncryptionComplete",
231 HasDetailsAsDictionary(expected_details))); 209 HasDetailsAsDictionary(expected_details)));
232 210
233 js_sync_manager_observer_.OnEncryptionComplete(encrypted_types); 211 js_sync_manager_observer_.OnEncryptionComplete(encrypted_types);
234 PumpLoop(); 212 PumpLoop();
235 } 213 }
236 214
237 TEST_F(JsSyncManagerObserverTest, OnChangesApplied) {
238 InSequence dummy;
239
240 // We don't test with passwords as that requires additional setup.
241
242 // Build a list of example ChangeRecords.
243 sync_api::ChangeRecord changes[syncable::MODEL_TYPE_COUNT];
244 for (int i = syncable::AUTOFILL_PROFILE;
245 i < syncable::MODEL_TYPE_COUNT; ++i) {
246 changes[i].id = i;
247 switch (i % 3) {
248 case 0:
249 changes[i].action =
250 sync_api::ChangeRecord::ACTION_ADD;
251 break;
252 case 1:
253 changes[i].action =
254 sync_api::ChangeRecord::ACTION_UPDATE;
255 break;
256 default:
257 changes[i].action =
258 sync_api::ChangeRecord::ACTION_DELETE;
259 break;
260 }
261 }
262
263 // For each i, we call OnChangesApplied() with the first arg equal
264 // to i cast to ModelType and the second argument with the changes
265 // starting from changes[i].
266
267 // Set expectations for each data type.
268 for (int i = syncable::AUTOFILL_PROFILE;
269 i < syncable::MODEL_TYPE_COUNT; ++i) {
270 const std::string& model_type_str =
271 syncable::ModelTypeToString(syncable::ModelTypeFromInt(i));
272 DictionaryValue expected_details;
273 expected_details.SetString("modelType", model_type_str);
274 expected_details.SetString("writeTransactionId", "0");
275 ListValue* expected_changes = new ListValue();
276 expected_details.Set("changes", expected_changes);
277 for (int j = i; j < syncable::MODEL_TYPE_COUNT; ++j) {
278 expected_changes->Append(changes[j].ToValue());
279 }
280 EXPECT_CALL(mock_js_event_handler_,
281 HandleJsEvent("onChangesApplied",
282 HasDetailsAsDictionary(expected_details)));
283 }
284
285 // Fire OnChangesApplied() for each data type.
286 for (int i = syncable::AUTOFILL_PROFILE;
287 i < syncable::MODEL_TYPE_COUNT; ++i) {
288 sync_api::ChangeRecordList
289 local_changes(changes + i, changes + arraysize(changes));
290 js_sync_manager_observer_.OnChangesApplied(
291 syncable::ModelTypeFromInt(i),
292 0, sync_api::ImmutableChangeRecordList(&local_changes));
293 }
294
295 PumpLoop();
296 }
297
298 } // namespace 215 } // namespace
299 } // namespace browser_sync 216 } // namespace browser_sync
OLDNEW
« no previous file with comments | « chrome/browser/sync/js/js_sync_manager_observer.cc ('k') | chrome/browser/sync/js/js_transaction_observer.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698