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