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