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

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

Issue 10916131: [Invalidations] Add GetInvalidatorState() to Invalidator{,Frontend} (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fix android Created 8 years, 3 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_state.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/compiler_specific.h" 6 #include "base/compiler_specific.h"
6 #include "base/memory/scoped_ptr.h" 7 #include "base/memory/scoped_ptr.h"
7 #include "google/cacheinvalidation/types.pb.h" 8 #include "google/cacheinvalidation/types.pb.h"
8 #include "sync/notifier/fake_invalidation_handler.h" 9 #include "sync/notifier/fake_invalidation_handler.h"
9 #include "sync/notifier/invalidator_registrar.h" 10 #include "sync/notifier/invalidator_registrar.h"
10 #include "sync/notifier/invalidator_test_template.h" 11 #include "sync/notifier/invalidator_test_template.h"
11 #include "sync/notifier/object_id_state_map_test_util.h" 12 #include "sync/notifier/object_id_state_map_test_util.h"
12 #include "testing/gtest/include/gtest/gtest.h" 13 #include "testing/gtest/include/gtest/gtest.h"
13 14
14 namespace syncer { 15 namespace syncer {
15 16
16 namespace { 17 namespace {
17 18
18 // We test InvalidatorRegistrar by wrapping it in an Invalidator and 19 // We test InvalidatorRegistrar by wrapping it in an Invalidator and
19 // running the usual Invalidator tests. 20 // running the usual Invalidator tests.
20 21
21 // Thin Invalidator wrapper around InvalidatorRegistrar. 22 // Thin Invalidator wrapper around InvalidatorRegistrar.
22 class RegistrarInvalidator : public Invalidator { 23 class RegistrarInvalidator : public Invalidator {
23 public: 24 public:
25 RegistrarInvalidator() {}
24 virtual ~RegistrarInvalidator() {} 26 virtual ~RegistrarInvalidator() {}
25 27
26 InvalidatorRegistrar* GetRegistrar() { 28 InvalidatorRegistrar* GetRegistrar() {
27 return &registrar_; 29 return &registrar_;
28 } 30 }
29 31
30 // Invalidator implementation. 32 // Invalidator implementation.
31 virtual void RegisterHandler(InvalidationHandler* handler) OVERRIDE { 33 virtual void RegisterHandler(InvalidationHandler* handler) OVERRIDE {
32 registrar_.RegisterHandler(handler); 34 registrar_.RegisterHandler(handler);
33 } 35 }
34 36
35 virtual void UpdateRegisteredIds(InvalidationHandler* handler, 37 virtual void UpdateRegisteredIds(InvalidationHandler* handler,
36 const ObjectIdSet& ids) OVERRIDE { 38 const ObjectIdSet& ids) OVERRIDE {
37 registrar_.UpdateRegisteredIds(handler, ids); 39 registrar_.UpdateRegisteredIds(handler, ids);
38 } 40 }
39 41
40 virtual void UnregisterHandler(InvalidationHandler* handler) OVERRIDE { 42 virtual void UnregisterHandler(InvalidationHandler* handler) OVERRIDE {
41 registrar_.UnregisterHandler(handler); 43 registrar_.UnregisterHandler(handler);
42 } 44 }
43 45
46 virtual InvalidatorState GetInvalidatorState() const OVERRIDE {
47 return registrar_.GetInvalidatorState();
48 }
49
44 virtual void SetUniqueId(const std::string& unique_id) OVERRIDE { 50 virtual void SetUniqueId(const std::string& unique_id) OVERRIDE {
45 // Do nothing. 51 // Do nothing.
46 } 52 }
47 53
48 virtual void SetStateDeprecated(const std::string& state) OVERRIDE { 54 virtual void SetStateDeprecated(const std::string& state) OVERRIDE {
49 // Do nothing. 55 // Do nothing.
50 } 56 }
51 57
52 virtual void UpdateCredentials( 58 virtual void UpdateCredentials(
53 const std::string& email, const std::string& token) OVERRIDE { 59 const std::string& email, const std::string& token) OVERRIDE {
54 // Do nothing. 60 // Do nothing.
55 } 61 }
56 62
57 virtual void SendNotification( 63 virtual void SendInvalidation(const ObjectIdStateMap& id_state_map) OVERRIDE {
58 const ObjectIdStateMap& id_state_map) OVERRIDE {
59 // Do nothing. 64 // Do nothing.
60 } 65 }
61 66
62 private: 67 private:
63 InvalidatorRegistrar registrar_; 68 InvalidatorRegistrar registrar_;
69
70 DISALLOW_COPY_AND_ASSIGN(RegistrarInvalidator);
64 }; 71 };
65 72
66 class RegistrarInvalidatorTestDelegate { 73 class RegistrarInvalidatorTestDelegate {
67 public: 74 public:
68 RegistrarInvalidatorTestDelegate() {} 75 RegistrarInvalidatorTestDelegate() {}
69 76
70 ~RegistrarInvalidatorTestDelegate() { 77 ~RegistrarInvalidatorTestDelegate() {
71 DestroyInvalidator(); 78 DestroyInvalidator();
72 } 79 }
73 80
(...skipping 10 matching lines...) Expand all
84 } 91 }
85 92
86 void DestroyInvalidator() { 93 void DestroyInvalidator() {
87 invalidator_.reset(); 94 invalidator_.reset();
88 } 95 }
89 96
90 void WaitForInvalidator() { 97 void WaitForInvalidator() {
91 // Do nothing. 98 // Do nothing.
92 } 99 }
93 100
94 void TriggerOnNotificationsEnabled() { 101 void TriggerOnInvalidatorStateChange(InvalidatorState state) {
95 invalidator_->GetRegistrar()->EmitOnNotificationsEnabled(); 102 invalidator_->GetRegistrar()->UpdateInvalidatorState(state);
96 } 103 }
97 104
98 void TriggerOnIncomingNotification(const ObjectIdStateMap& id_state_map, 105 void TriggerOnIncomingInvalidation(const ObjectIdStateMap& id_state_map,
99 IncomingNotificationSource source) { 106 IncomingInvalidationSource source) {
100 invalidator_->GetRegistrar()->DispatchInvalidationsToHandlers( 107 invalidator_->GetRegistrar()->DispatchInvalidationsToHandlers(
101 id_state_map, source); 108 id_state_map, source);
102 } 109 }
103 110
104 void TriggerOnNotificationsDisabled(NotificationsDisabledReason reason) {
105 invalidator_->GetRegistrar()->EmitOnNotificationsDisabled(reason);
106 }
107
108 static bool InvalidatorHandlesDeprecatedState() { 111 static bool InvalidatorHandlesDeprecatedState() {
109 return false; 112 return false;
110 } 113 }
111 114
112 private: 115 private:
113 scoped_ptr<RegistrarInvalidator> invalidator_; 116 scoped_ptr<RegistrarInvalidator> invalidator_;
114 }; 117 };
115 118
116 INSTANTIATE_TYPED_TEST_CASE_P( 119 INSTANTIATE_TYPED_TEST_CASE_P(
117 RegistrarInvalidatorTest, InvalidatorTest, 120 RegistrarInvalidatorTest, InvalidatorTest,
(...skipping 25 matching lines...) Expand all
143 146
144 registrar.DetachFromThreadForTest(); 147 registrar.DetachFromThreadForTest();
145 // We expect a death via CHECK(). We can't match against the CHECK() message 148 // We expect a death via CHECK(). We can't match against the CHECK() message
146 // though since they are removed in official builds. 149 // though since they are removed in official builds.
147 EXPECT_DEATH({ registrar.UpdateRegisteredIds(&handler2, ids); }, ""); 150 EXPECT_DEATH({ registrar.UpdateRegisteredIds(&handler2, ids); }, "");
148 } 151 }
149 152
150 } // namespace 153 } // namespace
151 154
152 } // namespace syncer 155 } // namespace syncer
OLDNEW
« no previous file with comments | « sync/notifier/invalidator_registrar.cc ('k') | sync/notifier/invalidator_state.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698