Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(269)

Side by Side Diff: chrome/browser/sync/glue/chrome_sync_notification_bridge_unittest.cc

Issue 10824161: [Sync] Avoid unregistering object IDs on shutdown (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Address comments Created 8 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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>
msw 2012/08/03 23:30:46 nit/question: is it better practice to include thi
akalin 2012/08/07 07:25:19 i don't think basictypes.h makes any particular gu
8
7 #include "base/compiler_specific.h" 9 #include "base/compiler_specific.h"
8 #include "base/memory/ref_counted.h" 10 #include "base/memory/ref_counted.h"
9 #include "base/memory/scoped_ptr.h" 11 #include "base/memory/scoped_ptr.h"
10 #include "base/memory/weak_ptr.h" 12 #include "base/memory/weak_ptr.h"
11 #include "base/message_loop.h" 13 #include "base/message_loop.h"
12 #include "base/sequenced_task_runner.h" 14 #include "base/sequenced_task_runner.h"
13 #include "base/synchronization/waitable_event.h" 15 #include "base/synchronization/waitable_event.h"
14 #include "base/test/test_timeouts.h" 16 #include "base/test/test_timeouts.h"
15 #include "base/threading/thread.h" 17 #include "base/threading/thread.h"
16 #include "chrome/common/chrome_notification_types.h" 18 #include "chrome/common/chrome_notification_types.h"
17 #include "chrome/test/base/profile_mock.h" 19 #include "chrome/test/base/profile_mock.h"
18 #include "content/public/browser/notification_details.h" 20 #include "content/public/browser/notification_details.h"
19 #include "content/public/browser/notification_service.h" 21 #include "content/public/browser/notification_service.h"
20 #include "content/public/test/test_browser_thread.h" 22 #include "content/public/test/test_browser_thread.h"
21 #include "sync/internal_api/public/base/model_type.h" 23 #include "sync/internal_api/public/base/model_type.h"
22 #include "sync/internal_api/public/base/model_type_payload_map.h" 24 #include "sync/internal_api/public/base/model_type_payload_map.h"
23 #include "sync/notifier/sync_notifier_observer.h" 25 #include "sync/notifier/sync_notifier_observer.h"
24 #include "testing/gmock/include/gmock/gmock.h" 26 #include "testing/gmock/include/gmock/gmock.h"
25 #include "testing/gtest/include/gtest/gtest.h" 27 #include "testing/gtest/include/gtest/gtest.h"
26 28
27 namespace browser_sync { 29 namespace browser_sync {
28 namespace { 30 namespace {
29 31
30 using ::testing::Mock; 32 using ::testing::Mock;
31 using ::testing::NiceMock; 33 using ::testing::NiceMock;
32 using ::testing::StrictMock; 34 using ::testing::StrictMock;
33 using content::BrowserThread; 35 using content::BrowserThread;
34 36
37 const char kHandlerName[] = "FakeSyncNotifierObserver";
38
35 // Receives a ChromeSyncNotificationBridge to register to, and an expected 39 // Receives a ChromeSyncNotificationBridge to register to, and an expected
36 // ModelTypePayloadMap. ReceivedProperNotification() will return true only 40 // ModelTypePayloadMap. ReceivedProperNotification() will return true only
37 // if the observer has received a notification with the proper source and 41 // if the observer has received a notification with the proper source and
38 // payload. 42 // payload.
39 // Note: Because this object lives on the sync thread, we use a fake 43 // Note: Because this object lives on the sync thread, we use a fake
40 // (vs a mock) so we don't have to worry about possible thread safety 44 // (vs a mock) so we don't have to worry about possible thread safety
41 // issues within GTest/GMock. 45 // issues within GTest/GMock.
42 class FakeSyncNotifierObserver : public syncer::SyncNotifierObserver { 46 class FakeSyncNotifierObserver : public syncer::SyncNotifierObserver {
43 public: 47 public:
44 FakeSyncNotifierObserver( 48 FakeSyncNotifierObserver(
45 const scoped_refptr<base::SequencedTaskRunner>& sync_task_runner, 49 const scoped_refptr<base::SequencedTaskRunner>& sync_task_runner,
46 ChromeSyncNotificationBridge* bridge, 50 ChromeSyncNotificationBridge* bridge,
47 const syncer::ObjectIdPayloadMap& expected_payloads, 51 const syncer::ObjectIdPayloadMap& expected_payloads,
48 syncer::IncomingNotificationSource expected_source) 52 syncer::IncomingNotificationSource expected_source)
49 : sync_task_runner_(sync_task_runner), 53 : sync_task_runner_(sync_task_runner),
50 bridge_(bridge), 54 bridge_(bridge),
51 received_improper_notification_(false), 55 received_improper_notification_(false),
52 notification_count_(0), 56 notification_count_(0),
53 expected_payloads_(expected_payloads), 57 expected_payloads_(expected_payloads),
54 expected_source_(expected_source) { 58 expected_source_(expected_source) {
55 DCHECK(sync_task_runner_->RunsTasksOnCurrentThread()); 59 DCHECK(sync_task_runner_->RunsTasksOnCurrentThread());
60 bridge_->SetHandler(kHandlerName, this);
56 const syncer::ObjectIdSet& ids = 61 const syncer::ObjectIdSet& ids =
57 syncer::ObjectIdPayloadMapToSet(expected_payloads); 62 syncer::ObjectIdPayloadMapToSet(expected_payloads);
58 bridge_->UpdateRegisteredIds(this, ids); 63 bridge_->UpdateRegisteredIds(kHandlerName, ids);
59 } 64 }
60 65
61 virtual ~FakeSyncNotifierObserver() { 66 virtual ~FakeSyncNotifierObserver() {
62 DCHECK(sync_task_runner_->RunsTasksOnCurrentThread()); 67 DCHECK(sync_task_runner_->RunsTasksOnCurrentThread());
63 bridge_->UpdateRegisteredIds(this, syncer::ObjectIdSet()); 68 bridge_->SetHandler(kHandlerName, NULL);
64 } 69 }
65 70
66 // SyncNotifierObserver implementation. 71 // SyncNotifierObserver implementation.
67 virtual void OnIncomingNotification( 72 virtual void OnIncomingNotification(
68 const syncer::ObjectIdPayloadMap& id_payloads, 73 const syncer::ObjectIdPayloadMap& id_payloads,
69 syncer::IncomingNotificationSource source) OVERRIDE { 74 syncer::IncomingNotificationSource source) OVERRIDE {
70 DCHECK(sync_task_runner_->RunsTasksOnCurrentThread()); 75 DCHECK(sync_task_runner_->RunsTasksOnCurrentThread());
71 notification_count_++; 76 notification_count_++;
72 if (source != expected_source_) { 77 if (source != expected_source_) {
73 LOG(ERROR) << "Received notification with wrong source"; 78 LOG(ERROR) << "Received notification with wrong source";
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
113 118
114 protected: 119 protected:
115 virtual void SetUp() OVERRIDE { 120 virtual void SetUp() OVERRIDE {
116 ASSERT_TRUE(sync_thread_.Start()); 121 ASSERT_TRUE(sync_thread_.Start());
117 bridge_.reset( 122 bridge_.reset(
118 new ChromeSyncNotificationBridge( 123 new ChromeSyncNotificationBridge(
119 &mock_profile_, sync_thread_.message_loop_proxy())); 124 &mock_profile_, sync_thread_.message_loop_proxy()));
120 } 125 }
121 126
122 virtual void TearDown() OVERRIDE { 127 virtual void TearDown() OVERRIDE {
128 bridge_->StopForShutdown();
123 sync_thread_.Stop(); 129 sync_thread_.Stop();
124 // Must be reset only after the sync thread is stopped. 130 // Must be reset only after the sync thread is stopped.
125 bridge_.reset(); 131 bridge_.reset();
126 EXPECT_EQ(NULL, sync_observer_); 132 EXPECT_EQ(NULL, sync_observer_);
127 if (sync_observer_notification_failure_) 133 if (sync_observer_notification_failure_)
128 ADD_FAILURE() << "Sync Observer did not receive proper notification."; 134 ADD_FAILURE() << "Sync Observer did not receive proper notification.";
129 } 135 }
130 136
131 void VerifyAndDestroyObserver() { 137 void VerifyAndDestroyObserver() {
132 ASSERT_TRUE(sync_thread_.message_loop_proxy()->PostTask( 138 ASSERT_TRUE(sync_thread_.message_loop_proxy()->PostTask(
(...skipping 146 matching lines...) Expand 10 before | Expand all | Expand 10 after
279 CreateObserverWithExpectations( 285 CreateObserverWithExpectations(
280 enabled_types_payload_map, syncer::REMOTE_NOTIFICATION); 286 enabled_types_payload_map, syncer::REMOTE_NOTIFICATION);
281 UpdateBridgeEnabledTypes(enabled_types); 287 UpdateBridgeEnabledTypes(enabled_types);
282 TriggerRefreshNotification(chrome::NOTIFICATION_SYNC_REFRESH_REMOTE, 288 TriggerRefreshNotification(chrome::NOTIFICATION_SYNC_REFRESH_REMOTE,
283 syncer::ModelTypePayloadMap()); 289 syncer::ModelTypePayloadMap());
284 VerifyAndDestroyObserver(); 290 VerifyAndDestroyObserver();
285 } 291 }
286 292
287 } // namespace 293 } // namespace
288 } // namespace browser_sync 294 } // namespace browser_sync
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698