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 "chrome/browser/sync/glue/chrome_sync_notification_bridge.h" | 5 #include "chrome/browser/sync/glue/chrome_sync_notification_bridge.h" |
6 | 6 |
7 #include <cstddef> | |
8 | |
9 #include "base/compiler_specific.h" | 7 #include "base/compiler_specific.h" |
10 #include "base/memory/ref_counted.h" | 8 #include "base/memory/ref_counted.h" |
11 #include "base/memory/scoped_ptr.h" | 9 #include "base/memory/scoped_ptr.h" |
12 #include "base/memory/weak_ptr.h" | 10 #include "base/memory/weak_ptr.h" |
13 #include "base/message_loop.h" | 11 #include "base/message_loop.h" |
14 #include "base/sequenced_task_runner.h" | 12 #include "base/sequenced_task_runner.h" |
15 #include "base/synchronization/waitable_event.h" | 13 #include "base/synchronization/waitable_event.h" |
16 #include "base/test/test_timeouts.h" | 14 #include "base/test/test_timeouts.h" |
17 #include "base/threading/thread.h" | 15 #include "base/threading/thread.h" |
18 #include "chrome/common/chrome_notification_types.h" | 16 #include "chrome/common/chrome_notification_types.h" |
(...skipping 29 matching lines...) Expand all Loading... |
48 ChromeSyncNotificationBridge* bridge, | 46 ChromeSyncNotificationBridge* bridge, |
49 const syncer::ObjectIdPayloadMap& expected_payloads, | 47 const syncer::ObjectIdPayloadMap& expected_payloads, |
50 syncer::IncomingNotificationSource expected_source) | 48 syncer::IncomingNotificationSource expected_source) |
51 : sync_task_runner_(sync_task_runner), | 49 : sync_task_runner_(sync_task_runner), |
52 bridge_(bridge), | 50 bridge_(bridge), |
53 received_improper_notification_(false), | 51 received_improper_notification_(false), |
54 notification_count_(0), | 52 notification_count_(0), |
55 expected_payloads_(expected_payloads), | 53 expected_payloads_(expected_payloads), |
56 expected_source_(expected_source) { | 54 expected_source_(expected_source) { |
57 DCHECK(sync_task_runner_->RunsTasksOnCurrentThread()); | 55 DCHECK(sync_task_runner_->RunsTasksOnCurrentThread()); |
58 bridge_->RegisterHandler(this); | |
59 const syncer::ObjectIdSet& ids = | 56 const syncer::ObjectIdSet& ids = |
60 syncer::ObjectIdPayloadMapToSet(expected_payloads); | 57 syncer::ObjectIdPayloadMapToSet(expected_payloads); |
61 bridge_->UpdateRegisteredIds(this, ids); | 58 bridge_->UpdateRegisteredIds(this, ids); |
62 } | 59 } |
63 | 60 |
64 virtual ~FakeSyncNotifierObserver() { | 61 virtual ~FakeSyncNotifierObserver() { |
65 DCHECK(sync_task_runner_->RunsTasksOnCurrentThread()); | 62 DCHECK(sync_task_runner_->RunsTasksOnCurrentThread()); |
66 bridge_->UnregisterHandler(this); | 63 bridge_->UpdateRegisteredIds(this, syncer::ObjectIdSet()); |
67 } | 64 } |
68 | 65 |
69 // SyncNotifierObserver implementation. | 66 // SyncNotifierObserver implementation. |
70 virtual void OnIncomingNotification( | 67 virtual void OnIncomingNotification( |
71 const syncer::ObjectIdPayloadMap& id_payloads, | 68 const syncer::ObjectIdPayloadMap& id_payloads, |
72 syncer::IncomingNotificationSource source) OVERRIDE { | 69 syncer::IncomingNotificationSource source) OVERRIDE { |
73 DCHECK(sync_task_runner_->RunsTasksOnCurrentThread()); | 70 DCHECK(sync_task_runner_->RunsTasksOnCurrentThread()); |
74 notification_count_++; | 71 notification_count_++; |
75 if (source != expected_source_) { | 72 if (source != expected_source_) { |
76 LOG(ERROR) << "Received notification with wrong source"; | 73 LOG(ERROR) << "Received notification with wrong source"; |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
116 | 113 |
117 protected: | 114 protected: |
118 virtual void SetUp() OVERRIDE { | 115 virtual void SetUp() OVERRIDE { |
119 ASSERT_TRUE(sync_thread_.Start()); | 116 ASSERT_TRUE(sync_thread_.Start()); |
120 bridge_.reset( | 117 bridge_.reset( |
121 new ChromeSyncNotificationBridge( | 118 new ChromeSyncNotificationBridge( |
122 &mock_profile_, sync_thread_.message_loop_proxy())); | 119 &mock_profile_, sync_thread_.message_loop_proxy())); |
123 } | 120 } |
124 | 121 |
125 virtual void TearDown() OVERRIDE { | 122 virtual void TearDown() OVERRIDE { |
126 bridge_->StopForShutdown(); | |
127 sync_thread_.Stop(); | 123 sync_thread_.Stop(); |
128 // Must be reset only after the sync thread is stopped. | 124 // Must be reset only after the sync thread is stopped. |
129 bridge_.reset(); | 125 bridge_.reset(); |
130 EXPECT_EQ(NULL, sync_observer_); | 126 EXPECT_EQ(NULL, sync_observer_); |
131 if (sync_observer_notification_failure_) | 127 if (sync_observer_notification_failure_) |
132 ADD_FAILURE() << "Sync Observer did not receive proper notification."; | 128 ADD_FAILURE() << "Sync Observer did not receive proper notification."; |
133 } | 129 } |
134 | 130 |
135 void VerifyAndDestroyObserver() { | 131 void VerifyAndDestroyObserver() { |
136 ASSERT_TRUE(sync_thread_.message_loop_proxy()->PostTask( | 132 ASSERT_TRUE(sync_thread_.message_loop_proxy()->PostTask( |
(...skipping 146 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
283 CreateObserverWithExpectations( | 279 CreateObserverWithExpectations( |
284 enabled_types_payload_map, syncer::REMOTE_NOTIFICATION); | 280 enabled_types_payload_map, syncer::REMOTE_NOTIFICATION); |
285 UpdateBridgeEnabledTypes(enabled_types); | 281 UpdateBridgeEnabledTypes(enabled_types); |
286 TriggerRefreshNotification(chrome::NOTIFICATION_SYNC_REFRESH_REMOTE, | 282 TriggerRefreshNotification(chrome::NOTIFICATION_SYNC_REFRESH_REMOTE, |
287 syncer::ModelTypePayloadMap()); | 283 syncer::ModelTypePayloadMap()); |
288 VerifyAndDestroyObserver(); | 284 VerifyAndDestroyObserver(); |
289 } | 285 } |
290 | 286 |
291 } // namespace | 287 } // namespace |
292 } // namespace browser_sync | 288 } // namespace browser_sync |
OLD | NEW |