Linux: Depend on liberation-fonts package for RPMs.
[chromium-blink-merge.git] / sync / internal_api / js_sync_manager_observer_unittest.cc
blob3c65e2903d9f84064a3df9432e21ddb789cf084e
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.
5 #include "sync/internal_api/js_sync_manager_observer.h"
7 #include "base/basictypes.h"
8 #include "base/location.h"
9 #include "base/run_loop.h"
10 #include "base/values.h"
11 #include "sync/internal_api/public/base/model_type.h"
12 #include "sync/internal_api/public/connection_status.h"
13 #include "sync/internal_api/public/sessions/sync_session_snapshot.h"
14 #include "sync/internal_api/public/util/sync_string_conversions.h"
15 #include "sync/internal_api/public/util/weak_handle.h"
16 #include "sync/js/js_event_details.h"
17 #include "sync/js/js_test_util.h"
18 #include "sync/protocol/sync_protocol_error.h"
19 #include "testing/gtest/include/gtest/gtest.h"
21 namespace syncer {
22 namespace {
24 using ::testing::InSequence;
25 using ::testing::StrictMock;
27 class JsSyncManagerObserverTest : public testing::Test {
28 protected:
29 JsSyncManagerObserverTest() {
30 js_sync_manager_observer_.SetJsEventHandler(
31 mock_js_event_handler_.AsWeakHandle());
34 private:
35 // This must be destroyed after the member variables below in order
36 // for WeakHandles to be destroyed properly.
37 base::MessageLoop message_loop_;
39 protected:
40 StrictMock<MockJsEventHandler> mock_js_event_handler_;
41 JsSyncManagerObserver js_sync_manager_observer_;
43 void PumpLoop() {
44 base::RunLoop().RunUntilIdle();
48 TEST_F(JsSyncManagerObserverTest, OnInitializationComplete) {
49 base::DictionaryValue expected_details;
50 syncer::ModelTypeSet restored_types;
51 restored_types.Put(BOOKMARKS);
52 restored_types.Put(NIGORI);
53 expected_details.Set("restoredTypes", ModelTypeSetToValue(restored_types));
55 EXPECT_CALL(mock_js_event_handler_,
56 HandleJsEvent("onInitializationComplete",
57 HasDetailsAsDictionary(expected_details)));
59 js_sync_manager_observer_.OnInitializationComplete(
60 WeakHandle<JsBackend>(),
61 WeakHandle<DataTypeDebugInfoListener>(),
62 true,
63 restored_types);
64 PumpLoop();
67 TEST_F(JsSyncManagerObserverTest, OnSyncCycleCompleted) {
68 sessions::SyncSessionSnapshot snapshot(
69 sessions::ModelNeutralState(),
70 ProgressMarkerMap(),
71 false,
75 false,
77 base::Time::Now(),
78 base::Time::Now(),
79 std::vector<int>(MODEL_TYPE_COUNT, 0),
80 std::vector<int>(MODEL_TYPE_COUNT, 0),
81 sync_pb::GetUpdatesCallerInfo::UNKNOWN);
82 base::DictionaryValue expected_details;
83 expected_details.Set("snapshot", snapshot.ToValue());
85 EXPECT_CALL(mock_js_event_handler_,
86 HandleJsEvent("onSyncCycleCompleted",
87 HasDetailsAsDictionary(expected_details)));
89 js_sync_manager_observer_.OnSyncCycleCompleted(snapshot);
90 PumpLoop();
93 TEST_F(JsSyncManagerObserverTest, OnActionableError) {
94 SyncProtocolError sync_error;
95 sync_error.action = CLEAR_USER_DATA_AND_RESYNC;
96 sync_error.error_type = TRANSIENT_ERROR;
97 base::DictionaryValue expected_details;
98 expected_details.Set("syncError", sync_error.ToValue());
100 EXPECT_CALL(mock_js_event_handler_,
101 HandleJsEvent("onActionableError",
102 HasDetailsAsDictionary(expected_details)));
104 js_sync_manager_observer_.OnActionableError(sync_error);
105 PumpLoop();
109 TEST_F(JsSyncManagerObserverTest, OnConnectionStatusChange) {
110 const ConnectionStatus kStatus = CONNECTION_AUTH_ERROR;
111 base::DictionaryValue expected_details;
112 expected_details.SetString("status",
113 ConnectionStatusToString(kStatus));
115 EXPECT_CALL(mock_js_event_handler_,
116 HandleJsEvent("onConnectionStatusChange",
117 HasDetailsAsDictionary(expected_details)));
119 js_sync_manager_observer_.OnConnectionStatusChange(kStatus);
120 PumpLoop();
123 } // namespace
124 } // namespace syncer