Revert "Fix broken channel icon in chrome://help on CrOS" and try again
[chromium-blink-merge.git] / sync / internal_api / js_sync_manager_observer_unittest.cc
blob6062403188125bcfb8e75ccf14f916a3fe9455f8
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/sessions/sync_session_snapshot.h"
13 #include "sync/internal_api/public/util/sync_string_conversions.h"
14 #include "sync/internal_api/public/util/weak_handle.h"
15 #include "sync/js/js_event_details.h"
16 #include "sync/js/js_test_util.h"
17 #include "sync/protocol/sync_protocol_error.h"
18 #include "testing/gtest/include/gtest/gtest.h"
20 namespace syncer {
21 namespace {
23 using ::testing::InSequence;
24 using ::testing::StrictMock;
26 class JsSyncManagerObserverTest : public testing::Test {
27 protected:
28 JsSyncManagerObserverTest() {
29 js_sync_manager_observer_.SetJsEventHandler(
30 mock_js_event_handler_.AsWeakHandle());
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_;
38 protected:
39 StrictMock<MockJsEventHandler> mock_js_event_handler_;
40 JsSyncManagerObserver js_sync_manager_observer_;
42 void PumpLoop() {
43 base::RunLoop().RunUntilIdle();
47 TEST_F(JsSyncManagerObserverTest, OnInitializationComplete) {
48 base::DictionaryValue expected_details;
49 syncer::ModelTypeSet restored_types;
50 restored_types.Put(BOOKMARKS);
51 restored_types.Put(NIGORI);
52 expected_details.Set("restoredTypes", ModelTypeSetToValue(restored_types));
54 EXPECT_CALL(mock_js_event_handler_,
55 HandleJsEvent("onInitializationComplete",
56 HasDetailsAsDictionary(expected_details)));
58 js_sync_manager_observer_.OnInitializationComplete(
59 WeakHandle<JsBackend>(),
60 WeakHandle<DataTypeDebugInfoListener>(),
61 true,
62 restored_types);
63 PumpLoop();
66 TEST_F(JsSyncManagerObserverTest, OnSyncCycleCompleted) {
67 sessions::SyncSessionSnapshot snapshot(
68 sessions::ModelNeutralState(),
69 ProgressMarkerMap(),
70 false,
74 false,
76 base::Time::Now(),
77 base::Time::Now(),
78 std::vector<int>(MODEL_TYPE_COUNT, 0),
79 std::vector<int>(MODEL_TYPE_COUNT, 0),
80 sync_pb::GetUpdatesCallerInfo::UNKNOWN);
81 base::DictionaryValue expected_details;
82 expected_details.Set("snapshot", snapshot.ToValue());
84 EXPECT_CALL(mock_js_event_handler_,
85 HandleJsEvent("onSyncCycleCompleted",
86 HasDetailsAsDictionary(expected_details)));
88 js_sync_manager_observer_.OnSyncCycleCompleted(snapshot);
89 PumpLoop();
92 TEST_F(JsSyncManagerObserverTest, OnActionableError) {
93 SyncProtocolError sync_error;
94 sync_error.action = CLEAR_USER_DATA_AND_RESYNC;
95 sync_error.error_type = TRANSIENT_ERROR;
96 base::DictionaryValue expected_details;
97 expected_details.Set("syncError", sync_error.ToValue());
99 EXPECT_CALL(mock_js_event_handler_,
100 HandleJsEvent("onActionableError",
101 HasDetailsAsDictionary(expected_details)));
103 js_sync_manager_observer_.OnActionableError(sync_error);
104 PumpLoop();
108 TEST_F(JsSyncManagerObserverTest, OnConnectionStatusChange) {
109 const ConnectionStatus kStatus = CONNECTION_AUTH_ERROR;
110 base::DictionaryValue expected_details;
111 expected_details.SetString("status",
112 ConnectionStatusToString(kStatus));
114 EXPECT_CALL(mock_js_event_handler_,
115 HandleJsEvent("onConnectionStatusChange",
116 HasDetailsAsDictionary(expected_details)));
118 js_sync_manager_observer_.OnConnectionStatusChange(kStatus);
119 PumpLoop();
122 } // namespace
123 } // namespace syncer