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

Side by Side Diff: sync/notifier/invalidator_registrar_unittest.cc

Issue 11046008: [Invalidations] Require there to be no registered handlers on Invalidator destruction (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Sync to HEAD Created 8 years, 2 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
« no previous file with comments | « sync/notifier/invalidator_registrar.cc ('k') | sync/notifier/invalidator_test_template.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 "base/basictypes.h" 5 #include "base/basictypes.h"
6 #include "base/compiler_specific.h" 6 #include "base/compiler_specific.h"
7 #include "base/memory/scoped_ptr.h" 7 #include "base/memory/scoped_ptr.h"
8 #include "google/cacheinvalidation/types.pb.h" 8 #include "google/cacheinvalidation/types.pb.h"
9 #include "sync/notifier/fake_invalidation_handler.h" 9 #include "sync/notifier/fake_invalidation_handler.h"
10 #include "sync/notifier/invalidator_registrar.h" 10 #include "sync/notifier/invalidator_registrar.h"
(...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after
117 private: 117 private:
118 scoped_ptr<RegistrarInvalidator> invalidator_; 118 scoped_ptr<RegistrarInvalidator> invalidator_;
119 }; 119 };
120 120
121 INSTANTIATE_TYPED_TEST_CASE_P( 121 INSTANTIATE_TYPED_TEST_CASE_P(
122 RegistrarInvalidatorTest, InvalidatorTest, 122 RegistrarInvalidatorTest, InvalidatorTest,
123 RegistrarInvalidatorTestDelegate); 123 RegistrarInvalidatorTestDelegate);
124 124
125 class InvalidatorRegistrarTest : public testing::Test {}; 125 class InvalidatorRegistrarTest : public testing::Test {};
126 126
127 // Technically the tests below can be part of InvalidatorTest, but we
128 // want to keep the number of death tests down.
129
130 // When we expect a death via CHECK(), we can't match against the
131 // CHECK() message since they are removed in official builds.
132
133 // Having registered handlers on destruction should cause a CHECK.
134 TEST_F(InvalidatorRegistrarTest, RegisteredHandlerOnDestruction) {
135 scoped_ptr<InvalidatorRegistrar> registrar(new InvalidatorRegistrar());
136 FakeInvalidationHandler handler;
137
138 registrar->RegisterHandler(&handler);
139
140 EXPECT_DEATH({ registrar.reset(); }, "");
141
142 ASSERT_TRUE(registrar.get());
143 registrar->UnregisterHandler(&handler);
144 }
145
127 // Multiple registrations by different handlers on the same object ID should 146 // Multiple registrations by different handlers on the same object ID should
128 // cause a CHECK. 147 // cause a CHECK.
129 //
130 // Technically this can be part of InvalidatorTest, but we want to keep the
131 // number of death tests down.
132 TEST_F(InvalidatorRegistrarTest, MultipleRegistration) { 148 TEST_F(InvalidatorRegistrarTest, MultipleRegistration) {
133 const invalidation::ObjectId id1(ipc::invalidation::ObjectSource::TEST, "a"); 149 const invalidation::ObjectId id1(ipc::invalidation::ObjectSource::TEST, "a");
134 const invalidation::ObjectId id2(ipc::invalidation::ObjectSource::TEST, "a"); 150 const invalidation::ObjectId id2(ipc::invalidation::ObjectSource::TEST, "a");
135 151
136 InvalidatorRegistrar registrar; 152 InvalidatorRegistrar registrar;
137 153
138 FakeInvalidationHandler handler1; 154 FakeInvalidationHandler handler1;
139 registrar.RegisterHandler(&handler1); 155 registrar.RegisterHandler(&handler1);
140 156
141 FakeInvalidationHandler handler2; 157 FakeInvalidationHandler handler2;
142 registrar.RegisterHandler(&handler2); 158 registrar.RegisterHandler(&handler2);
143 159
144 ObjectIdSet ids; 160 ObjectIdSet ids;
145 ids.insert(id1); 161 ids.insert(id1);
146 ids.insert(id2); 162 ids.insert(id2);
147 registrar.UpdateRegisteredIds(&handler1, ids); 163 registrar.UpdateRegisteredIds(&handler1, ids);
148 164
149 registrar.DetachFromThreadForTest(); 165 registrar.DetachFromThreadForTest();
150 // We expect a death via CHECK(). We can't match against the CHECK() message
151 // though since they are removed in official builds.
152 EXPECT_DEATH({ registrar.UpdateRegisteredIds(&handler2, ids); }, ""); 166 EXPECT_DEATH({ registrar.UpdateRegisteredIds(&handler2, ids); }, "");
167
168 registrar.UnregisterHandler(&handler2);
169 registrar.UnregisterHandler(&handler1);
153 } 170 }
154 171
155 } // namespace 172 } // namespace
156 173
157 } // namespace syncer 174 } // namespace syncer
OLDNEW
« no previous file with comments | « sync/notifier/invalidator_registrar.cc ('k') | sync/notifier/invalidator_test_template.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698