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

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

Issue 2130453004: [Sync] Move //sync to //components/sync. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Rebase. Created 4 years, 4 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
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 "sync/internal_api/js_sync_manager_observer.h"
6
7 #include <vector>
8
9 #include "base/location.h"
10 #include "base/run_loop.h"
11 #include "base/values.h"
12 #include "sync/internal_api/public/base/model_type.h"
13 #include "sync/internal_api/public/connection_status.h"
14 #include "sync/internal_api/public/sessions/sync_session_snapshot.h"
15 #include "sync/internal_api/public/util/sync_string_conversions.h"
16 #include "sync/internal_api/public/util/weak_handle.h"
17 #include "sync/js/js_event_details.h"
18 #include "sync/js/js_test_util.h"
19 #include "sync/protocol/sync_protocol_error.h"
20 #include "testing/gtest/include/gtest/gtest.h"
21
22 namespace syncer {
23 namespace {
24
25 using ::testing::InSequence;
26 using ::testing::StrictMock;
27
28 class JsSyncManagerObserverTest : public testing::Test {
29 protected:
30 JsSyncManagerObserverTest() {
31 js_sync_manager_observer_.SetJsEventHandler(
32 mock_js_event_handler_.AsWeakHandle());
33 }
34
35 private:
36 // This must be destroyed after the member variables below in order
37 // for WeakHandles to be destroyed properly.
38 base::MessageLoop message_loop_;
39
40 protected:
41 StrictMock<MockJsEventHandler> mock_js_event_handler_;
42 JsSyncManagerObserver js_sync_manager_observer_;
43
44 void PumpLoop() {
45 base::RunLoop().RunUntilIdle();
46 }
47 };
48
49 TEST_F(JsSyncManagerObserverTest, OnInitializationComplete) {
50 base::DictionaryValue expected_details;
51 syncer::ModelTypeSet restored_types;
52 restored_types.Put(BOOKMARKS);
53 restored_types.Put(NIGORI);
54 expected_details.Set("restoredTypes", ModelTypeSetToValue(restored_types));
55
56 EXPECT_CALL(mock_js_event_handler_,
57 HandleJsEvent("onInitializationComplete",
58 HasDetailsAsDictionary(expected_details)));
59
60 js_sync_manager_observer_.OnInitializationComplete(
61 WeakHandle<JsBackend>(),
62 WeakHandle<DataTypeDebugInfoListener>(),
63 true,
64 restored_types);
65 PumpLoop();
66 }
67
68 TEST_F(JsSyncManagerObserverTest, OnSyncCycleCompleted) {
69 sessions::SyncSessionSnapshot snapshot(
70 sessions::ModelNeutralState(),
71 ProgressMarkerMap(),
72 false,
73 5,
74 2,
75 7,
76 false,
77 0,
78 base::Time::Now(),
79 base::Time::Now(),
80 std::vector<int>(MODEL_TYPE_COUNT, 0),
81 std::vector<int>(MODEL_TYPE_COUNT, 0),
82 sync_pb::GetUpdatesCallerInfo::UNKNOWN);
83 base::DictionaryValue expected_details;
84 expected_details.Set("snapshot", snapshot.ToValue());
85
86 EXPECT_CALL(mock_js_event_handler_,
87 HandleJsEvent("onSyncCycleCompleted",
88 HasDetailsAsDictionary(expected_details)));
89
90 js_sync_manager_observer_.OnSyncCycleCompleted(snapshot);
91 PumpLoop();
92 }
93
94 TEST_F(JsSyncManagerObserverTest, OnActionableError) {
95 SyncProtocolError sync_error;
96 sync_error.action = CLEAR_USER_DATA_AND_RESYNC;
97 sync_error.error_type = TRANSIENT_ERROR;
98 base::DictionaryValue expected_details;
99 expected_details.Set("syncError", sync_error.ToValue());
100
101 EXPECT_CALL(mock_js_event_handler_,
102 HandleJsEvent("onActionableError",
103 HasDetailsAsDictionary(expected_details)));
104
105 js_sync_manager_observer_.OnActionableError(sync_error);
106 PumpLoop();
107 }
108
109
110 TEST_F(JsSyncManagerObserverTest, OnConnectionStatusChange) {
111 const ConnectionStatus kStatus = CONNECTION_AUTH_ERROR;
112 base::DictionaryValue expected_details;
113 expected_details.SetString("status",
114 ConnectionStatusToString(kStatus));
115
116 EXPECT_CALL(mock_js_event_handler_,
117 HandleJsEvent("onConnectionStatusChange",
118 HasDetailsAsDictionary(expected_details)));
119
120 js_sync_manager_observer_.OnConnectionStatusChange(kStatus);
121 PumpLoop();
122 }
123
124 } // namespace
125 } // namespace syncer
OLDNEW
« no previous file with comments | « sync/internal_api/js_sync_manager_observer.cc ('k') | sync/internal_api/model_type_connector.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698