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

Side by Side Diff: chrome/browser/extensions/api/synced_notifications_private/synced_notifications_shim_unittest.cc

Issue 411463003: [Sync] Trigger refresh for synced notifications on context change (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Self review Created 6 years, 5 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 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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/extensions/api/synced_notifications_private/synced_noti fications_shim.h" 5 #include "chrome/browser/extensions/api/synced_notifications_private/synced_noti fications_shim.h"
6 6
7 #include "base/json/json_writer.h" 7 #include "base/json/json_writer.h"
8 #include "extensions/browser/event_router.h" 8 #include "extensions/browser/event_router.h"
9 #include "sync/api/fake_sync_change_processor.h" 9 #include "sync/api/fake_sync_change_processor.h"
10 #include "sync/api/sync_change.h" 10 #include "sync/api/sync_change.h"
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after
74 virtual ~SyncedNotificationsShimTest(); 74 virtual ~SyncedNotificationsShimTest();
75 75
76 // Starts sync for both sync types. 76 // Starts sync for both sync types.
77 void StartSync(); 77 void StartSync();
78 // Starts sync for the specified datatype |type|. 78 // Starts sync for the specified datatype |type|.
79 void StartSync(syncer::ModelType type); 79 void StartSync(syncer::ModelType type);
80 80
81 // Transfers ownership of the last event received. 81 // Transfers ownership of the last event received.
82 scoped_ptr<Event> GetLastEvent(); 82 scoped_ptr<Event> GetLastEvent();
83 83
84 // Records that a refresh has been requested.
85 void RequestRefresh();
86
84 SyncedNotificationsShim* shim() { return &shim_; } 87 SyncedNotificationsShim* shim() { return &shim_; }
85 syncer::FakeSyncChangeProcessor* notification_processor() { 88 syncer::FakeSyncChangeProcessor* notification_processor() {
86 return notification_processor_; 89 return notification_processor_;
87 } 90 }
88 syncer::FakeSyncChangeProcessor* app_info_processor() { 91 syncer::FakeSyncChangeProcessor* app_info_processor() {
89 return app_info_processor_; 92 return app_info_processor_;
90 } 93 }
94 bool refresh_requested() const { return refresh_requested_; }
91 95
92 private: 96 private:
93 void EventCallback(scoped_ptr<Event> event); 97 void EventCallback(scoped_ptr<Event> event);
94 98
95 // Shim being tested. 99 // Shim being tested.
96 SyncedNotificationsShim shim_; 100 SyncedNotificationsShim shim_;
97 101
98 syncer::FakeSyncChangeProcessor* notification_processor_; 102 syncer::FakeSyncChangeProcessor* notification_processor_;
99 syncer::FakeSyncChangeProcessor* app_info_processor_; 103 syncer::FakeSyncChangeProcessor* app_info_processor_;
100 104
101 // The last event fired by the shim. 105 // The last event fired by the shim.
102 scoped_ptr<Event> last_event_fired_; 106 scoped_ptr<Event> last_event_fired_;
107
108 // Whether a refresh has been requested;
109 bool refresh_requested_;
103 }; 110 };
104 111
105 SyncedNotificationsShimTest::SyncedNotificationsShimTest() 112 SyncedNotificationsShimTest::SyncedNotificationsShimTest()
106 : shim_(base::Bind(&SyncedNotificationsShimTest::EventCallback, 113 : shim_(base::Bind(&SyncedNotificationsShimTest::EventCallback,
114 base::Unretained(this)),
115 base::Bind(&SyncedNotificationsShimTest::RequestRefresh,
107 base::Unretained(this))), 116 base::Unretained(this))),
108 notification_processor_(NULL), 117 notification_processor_(NULL),
109 app_info_processor_(NULL) {} 118 app_info_processor_(NULL),
119 refresh_requested_(false) {}
110 120
111 SyncedNotificationsShimTest::~SyncedNotificationsShimTest() {} 121 SyncedNotificationsShimTest::~SyncedNotificationsShimTest() {}
112 122
113 void SyncedNotificationsShimTest::EventCallback(scoped_ptr<Event> event) { 123 void SyncedNotificationsShimTest::EventCallback(scoped_ptr<Event> event) {
114 ASSERT_FALSE(last_event_fired_); 124 ASSERT_FALSE(last_event_fired_);
115 last_event_fired_ = event.Pass(); 125 last_event_fired_ = event.Pass();
116 } 126 }
117 127
128 void SyncedNotificationsShimTest::RequestRefresh() {
129 ASSERT_FALSE(refresh_requested_);
130 refresh_requested_ = true;
131 }
132
118 scoped_ptr<Event> SyncedNotificationsShimTest::GetLastEvent() { 133 scoped_ptr<Event> SyncedNotificationsShimTest::GetLastEvent() {
119 return last_event_fired_.Pass(); 134 return last_event_fired_.Pass();
120 } 135 }
121 136
122 void SyncedNotificationsShimTest::StartSync() { 137 void SyncedNotificationsShimTest::StartSync() {
123 StartSync(syncer::SYNCED_NOTIFICATIONS); 138 StartSync(syncer::SYNCED_NOTIFICATIONS);
124 StartSync(syncer::SYNCED_NOTIFICATION_APP_INFO); 139 StartSync(syncer::SYNCED_NOTIFICATION_APP_INFO);
125 GetLastEvent(); 140 GetLastEvent();
126 } 141 }
127 142
(...skipping 185 matching lines...) Expand 10 before | Expand all | Expand 10 after
313 .GetSpecifics() 328 .GetSpecifics()
314 .synced_notification() 329 .synced_notification()
315 .SerializeAsString()); 330 .SerializeAsString());
316 } 331 }
317 332
318 // Verify that SetRenderContext updates the datatype context properly. 333 // Verify that SetRenderContext updates the datatype context properly.
319 TEST_F(SyncedNotificationsShimTest, SetRenderContext) { 334 TEST_F(SyncedNotificationsShimTest, SetRenderContext) {
320 const std::string kContext = "context"; 335 const std::string kContext = "context";
321 EXPECT_FALSE(shim()->SetRenderContext( 336 EXPECT_FALSE(shim()->SetRenderContext(
322 synced_notifications_private::REFRESH_REQUEST_REFRESH_NEEDED, kContext)); 337 synced_notifications_private::REFRESH_REQUEST_REFRESH_NEEDED, kContext));
338 EXPECT_FALSE(refresh_requested());
323 339
324 StartSync(); 340 StartSync();
325 341
326 EXPECT_TRUE(shim()->SetRenderContext( 342 EXPECT_TRUE(shim()->SetRenderContext(
327 synced_notifications_private::REFRESH_REQUEST_REFRESH_NEEDED, kContext)); 343 synced_notifications_private::REFRESH_REQUEST_REFRESH_NEEDED, kContext));
328 EXPECT_EQ(kContext, notification_processor()->context()); 344 EXPECT_EQ(kContext, notification_processor()->context());
345 EXPECT_TRUE(refresh_requested());
329 } 346 }
330 347
331 } // namespace 348 } // namespace
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698