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

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

Issue 10907070: [Sync] Rename classes in sync/ that start with Chrome (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Rename var 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
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 <cstddef> 5 #include <cstddef>
6 #include <set> 6 #include <set>
7 #include <string> 7 #include <string>
8 8
9 #include "base/compiler_specific.h" 9 #include "base/compiler_specific.h"
10 #include "base/message_loop.h" 10 #include "base/message_loop.h"
11 #include "google/cacheinvalidation/include/invalidation-client.h" 11 #include "google/cacheinvalidation/include/invalidation-client.h"
12 #include "google/cacheinvalidation/include/types.h" 12 #include "google/cacheinvalidation/include/types.h"
13 #include "jingle/notifier/listener/fake_push_client.h" 13 #include "jingle/notifier/listener/fake_push_client.h"
14 #include "sync/internal_api/public/util/weak_handle.h" 14 #include "sync/internal_api/public/util/weak_handle.h"
15 #include "sync/notifier/chrome_invalidation_client.h"
16 #include "sync/notifier/fake_invalidation_state_tracker.h" 15 #include "sync/notifier/fake_invalidation_state_tracker.h"
17 #include "sync/notifier/invalidation_util.h" 16 #include "sync/notifier/invalidation_util.h"
17 #include "sync/notifier/sync_invalidation_client.h"
18 #include "testing/gtest/include/gtest/gtest.h" 18 #include "testing/gtest/include/gtest/gtest.h"
19 19
20 namespace syncer { 20 namespace syncer {
21 21
22 namespace { 22 namespace {
23 23
24 using invalidation::AckHandle; 24 using invalidation::AckHandle;
25 using invalidation::ObjectId; 25 using invalidation::ObjectId;
26 26
27 const char kClientId[] = "client_id"; 27 const char kClientId[] = "client_id";
(...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after
122 } 122 }
123 123
124 private: 124 private:
125 bool started_; 125 bool started_;
126 ObjectIdSet registered_ids_; 126 ObjectIdSet registered_ids_;
127 AckHandleSet acked_handles_; 127 AckHandleSet acked_handles_;
128 }; 128 };
129 129
130 // Fake listener tkat keeps track of invalidation counts, payloads, 130 // Fake listener tkat keeps track of invalidation counts, payloads,
131 // and state. 131 // and state.
132 class FakeListener : public ChromeInvalidationClient::Listener { 132 class FakeListener : public SyncInvalidationClient::Listener {
133 public: 133 public:
134 FakeListener() : reason_(TRANSIENT_NOTIFICATION_ERROR) {} 134 FakeListener() : reason_(TRANSIENT_NOTIFICATION_ERROR) {}
135 virtual ~FakeListener() {} 135 virtual ~FakeListener() {}
136 136
137 int GetInvalidationCount(const ObjectId& id) const { 137 int GetInvalidationCount(const ObjectId& id) const {
138 ObjectIdCountMap::const_iterator it = invalidation_counts_.find(id); 138 ObjectIdCountMap::const_iterator it = invalidation_counts_.find(id);
139 return (it == invalidation_counts_.end()) ? 0 : it->second; 139 return (it == invalidation_counts_.end()) ? 0 : it->second;
140 } 140 }
141 141
142 std::string GetPayload(const ObjectId& id) const { 142 std::string GetPayload(const ObjectId& id) const {
143 ObjectIdStateMap::const_iterator it = states_.find(id); 143 ObjectIdStateMap::const_iterator it = states_.find(id);
144 return (it == states_.end()) ? "" : it->second.payload; 144 return (it == states_.end()) ? "" : it->second.payload;
145 } 145 }
146 146
147 // NO_NOTIFICATION_ERROR is the enabled state. 147 // NO_NOTIFICATION_ERROR is the enabled state.
148 NotificationsDisabledReason GetNotificationsDisabledReason() const { 148 NotificationsDisabledReason GetNotificationsDisabledReason() const {
149 return reason_; 149 return reason_;
150 } 150 }
151 151
152 // ChromeInvalidationClient::Listener implementation. 152 // SyncInvalidationClient::Listener implementation.
153 153
154 virtual void OnInvalidate(const ObjectIdStateMap& id_state_map) OVERRIDE { 154 virtual void OnInvalidate(const ObjectIdStateMap& id_state_map) OVERRIDE {
155 for (ObjectIdStateMap::const_iterator it = id_state_map.begin(); 155 for (ObjectIdStateMap::const_iterator it = id_state_map.begin();
156 it != id_state_map.end(); ++it) { 156 it != id_state_map.end(); ++it) {
157 ++invalidation_counts_[it->first]; 157 ++invalidation_counts_[it->first];
158 states_[it->first] = it->second; 158 states_[it->first] = it->second;
159 } 159 }
160 } 160 }
161 161
162 virtual void OnNotificationsEnabled() { 162 virtual void OnNotificationsEnabled() {
(...skipping 15 matching lines...) Expand all
178 FakeInvalidationClient** fake_invalidation_client, 178 FakeInvalidationClient** fake_invalidation_client,
179 invalidation::SystemResources* resources, 179 invalidation::SystemResources* resources,
180 int client_type, 180 int client_type,
181 const invalidation::string& client_name, 181 const invalidation::string& client_name,
182 const invalidation::string& application_name, 182 const invalidation::string& application_name,
183 invalidation::InvalidationListener* listener) { 183 invalidation::InvalidationListener* listener) {
184 *fake_invalidation_client = new FakeInvalidationClient(); 184 *fake_invalidation_client = new FakeInvalidationClient();
185 return *fake_invalidation_client; 185 return *fake_invalidation_client;
186 } 186 }
187 187
188 class ChromeInvalidationClientTest : public testing::Test { 188 class SyncInvalidationClientTest : public testing::Test {
189 protected: 189 protected:
190 ChromeInvalidationClientTest() 190 SyncInvalidationClientTest()
191 : kBookmarksId_(kChromeSyncSourceId, "BOOKMARK"), 191 : kBookmarksId_(kChromeSyncSourceId, "BOOKMARK"),
192 kPreferencesId_(kChromeSyncSourceId, "PREFERENCE"), 192 kPreferencesId_(kChromeSyncSourceId, "PREFERENCE"),
193 kExtensionsId_(kChromeSyncSourceId, "EXTENSION"), 193 kExtensionsId_(kChromeSyncSourceId, "EXTENSION"),
194 kAppsId_(kChromeSyncSourceId, "APP"), 194 kAppsId_(kChromeSyncSourceId, "APP"),
195 fake_push_client_(new notifier::FakePushClient()), 195 fake_push_client_(new notifier::FakePushClient()),
196 fake_invalidation_client_(NULL), 196 fake_invalidation_client_(NULL),
197 client_(scoped_ptr<notifier::PushClient>(fake_push_client_)) {} 197 client_(scoped_ptr<notifier::PushClient>(fake_push_client_)) {}
198 198
199 virtual void SetUp() { 199 virtual void SetUp() {
200 StartClient(); 200 StartClient();
(...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after
320 320
321 MessageLoop message_loop_; 321 MessageLoop message_loop_;
322 322
323 FakeListener fake_listener_; 323 FakeListener fake_listener_;
324 FakeInvalidationStateTracker fake_tracker_; 324 FakeInvalidationStateTracker fake_tracker_;
325 notifier::FakePushClient* const fake_push_client_; 325 notifier::FakePushClient* const fake_push_client_;
326 326
327 protected: 327 protected:
328 // Tests need to access these directly. 328 // Tests need to access these directly.
329 FakeInvalidationClient* fake_invalidation_client_; 329 FakeInvalidationClient* fake_invalidation_client_;
330 ChromeInvalidationClient client_; 330 SyncInvalidationClient client_;
331 }; 331 };
332 332
333 // Write a new state to the client. It should propagate to the 333 // Write a new state to the client. It should propagate to the
334 // tracker. 334 // tracker.
335 TEST_F(ChromeInvalidationClientTest, WriteState) { 335 TEST_F(SyncInvalidationClientTest, WriteState) {
336 WriteState(kNewState); 336 WriteState(kNewState);
337 337
338 EXPECT_EQ(kNewState, GetInvalidationState()); 338 EXPECT_EQ(kNewState, GetInvalidationState());
339 } 339 }
340 340
341 // Invalidation tests. 341 // Invalidation tests.
342 342
343 // Fire an invalidation without a payload. It should be processed, 343 // Fire an invalidation without a payload. It should be processed,
344 // the payload should remain empty, and the version should be updated. 344 // the payload should remain empty, and the version should be updated.
345 TEST_F(ChromeInvalidationClientTest, InvalidateNoPayload) { 345 TEST_F(SyncInvalidationClientTest, InvalidateNoPayload) {
346 const ObjectId& id = kBookmarksId_; 346 const ObjectId& id = kBookmarksId_;
347 347
348 FireInvalidate(id, kVersion1, NULL); 348 FireInvalidate(id, kVersion1, NULL);
349 349
350 EXPECT_EQ(1, GetInvalidationCount(id)); 350 EXPECT_EQ(1, GetInvalidationCount(id));
351 EXPECT_EQ("", GetPayload(id)); 351 EXPECT_EQ("", GetPayload(id));
352 EXPECT_EQ(kVersion1, GetMaxVersion(id)); 352 EXPECT_EQ(kVersion1, GetMaxVersion(id));
353 } 353 }
354 354
355 // Fire an invalidation with an empty payload. It should be 355 // Fire an invalidation with an empty payload. It should be
356 // processed, the payload should remain empty, and the version should 356 // processed, the payload should remain empty, and the version should
357 // be updated. 357 // be updated.
358 TEST_F(ChromeInvalidationClientTest, InvalidateEmptyPayload) { 358 TEST_F(SyncInvalidationClientTest, InvalidateEmptyPayload) {
359 const ObjectId& id = kBookmarksId_; 359 const ObjectId& id = kBookmarksId_;
360 360
361 FireInvalidate(id, kVersion1, ""); 361 FireInvalidate(id, kVersion1, "");
362 362
363 EXPECT_EQ(1, GetInvalidationCount(id)); 363 EXPECT_EQ(1, GetInvalidationCount(id));
364 EXPECT_EQ("", GetPayload(id)); 364 EXPECT_EQ("", GetPayload(id));
365 EXPECT_EQ(kVersion1, GetMaxVersion(id)); 365 EXPECT_EQ(kVersion1, GetMaxVersion(id));
366 } 366 }
367 367
368 // Fire an invalidation with a payload. It should be processed, and 368 // Fire an invalidation with a payload. It should be processed, and
369 // both the payload and the version should be updated. 369 // both the payload and the version should be updated.
370 TEST_F(ChromeInvalidationClientTest, InvalidateWithPayload) { 370 TEST_F(SyncInvalidationClientTest, InvalidateWithPayload) {
371 const ObjectId& id = kPreferencesId_; 371 const ObjectId& id = kPreferencesId_;
372 372
373 FireInvalidate(id, kVersion1, kPayload1); 373 FireInvalidate(id, kVersion1, kPayload1);
374 374
375 EXPECT_EQ(1, GetInvalidationCount(id)); 375 EXPECT_EQ(1, GetInvalidationCount(id));
376 EXPECT_EQ(kPayload1, GetPayload(id)); 376 EXPECT_EQ(kPayload1, GetPayload(id));
377 EXPECT_EQ(kVersion1, GetMaxVersion(id)); 377 EXPECT_EQ(kVersion1, GetMaxVersion(id));
378 } 378 }
379 379
380 // Fire an invalidation with a payload. It should still be processed, 380 // Fire an invalidation with a payload. It should still be processed,
381 // and both the payload and the version should be updated. 381 // and both the payload and the version should be updated.
382 TEST_F(ChromeInvalidationClientTest, InvalidateUnregistered) { 382 TEST_F(SyncInvalidationClientTest, InvalidateUnregistered) {
383 const ObjectId kUnregisteredId( 383 const ObjectId kUnregisteredId(
384 kChromeSyncSourceId, "unregistered"); 384 kChromeSyncSourceId, "unregistered");
385 const ObjectId& id = kUnregisteredId; 385 const ObjectId& id = kUnregisteredId;
386 386
387 EXPECT_EQ(0, GetInvalidationCount(id)); 387 EXPECT_EQ(0, GetInvalidationCount(id));
388 EXPECT_EQ("", GetPayload(id)); 388 EXPECT_EQ("", GetPayload(id));
389 EXPECT_EQ(kMinVersion, GetMaxVersion(id)); 389 EXPECT_EQ(kMinVersion, GetMaxVersion(id));
390 390
391 FireInvalidate(id, kVersion1, NULL); 391 FireInvalidate(id, kVersion1, NULL);
392 392
393 EXPECT_EQ(1, GetInvalidationCount(id)); 393 EXPECT_EQ(1, GetInvalidationCount(id));
394 EXPECT_EQ("", GetPayload(id)); 394 EXPECT_EQ("", GetPayload(id));
395 EXPECT_EQ(kVersion1, GetMaxVersion(id)); 395 EXPECT_EQ(kVersion1, GetMaxVersion(id));
396 } 396 }
397 397
398 // Fire an invalidation, then fire another one with a lower version. 398 // Fire an invalidation, then fire another one with a lower version.
399 // The first one should be processed and should update the payload and 399 // The first one should be processed and should update the payload and
400 // version, but the second one shouldn't. 400 // version, but the second one shouldn't.
401 TEST_F(ChromeInvalidationClientTest, InvalidateVersion) { 401 TEST_F(SyncInvalidationClientTest, InvalidateVersion) {
402 const ObjectId& id = kPreferencesId_; 402 const ObjectId& id = kPreferencesId_;
403 403
404 FireInvalidate(id, kVersion2, kPayload2); 404 FireInvalidate(id, kVersion2, kPayload2);
405 405
406 EXPECT_EQ(1, GetInvalidationCount(id)); 406 EXPECT_EQ(1, GetInvalidationCount(id));
407 EXPECT_EQ(kPayload2, GetPayload(id)); 407 EXPECT_EQ(kPayload2, GetPayload(id));
408 EXPECT_EQ(kVersion2, GetMaxVersion(id)); 408 EXPECT_EQ(kVersion2, GetMaxVersion(id));
409 409
410 FireInvalidate(id, kVersion1, kPayload1); 410 FireInvalidate(id, kVersion1, kPayload1);
411 411
412 EXPECT_EQ(1, GetInvalidationCount(id)); 412 EXPECT_EQ(1, GetInvalidationCount(id));
413 EXPECT_EQ(kPayload2, GetPayload(id)); 413 EXPECT_EQ(kPayload2, GetPayload(id));
414 EXPECT_EQ(kVersion2, GetMaxVersion(id)); 414 EXPECT_EQ(kVersion2, GetMaxVersion(id));
415 } 415 }
416 416
417 // Fire an invalidation with an unknown version twice. It shouldn't 417 // Fire an invalidation with an unknown version twice. It shouldn't
418 // update the payload or version either time, but it should still be 418 // update the payload or version either time, but it should still be
419 // processed. 419 // processed.
420 TEST_F(ChromeInvalidationClientTest, InvalidateUnknownVersion) { 420 TEST_F(SyncInvalidationClientTest, InvalidateUnknownVersion) {
421 const ObjectId& id = kBookmarksId_; 421 const ObjectId& id = kBookmarksId_;
422 422
423 FireInvalidateUnknownVersion(id); 423 FireInvalidateUnknownVersion(id);
424 424
425 EXPECT_EQ(1, GetInvalidationCount(id)); 425 EXPECT_EQ(1, GetInvalidationCount(id));
426 EXPECT_EQ("", GetPayload(id)); 426 EXPECT_EQ("", GetPayload(id));
427 EXPECT_EQ(kMinVersion, GetMaxVersion(id)); 427 EXPECT_EQ(kMinVersion, GetMaxVersion(id));
428 428
429 FireInvalidateUnknownVersion(id); 429 FireInvalidateUnknownVersion(id);
430 430
431 EXPECT_EQ(2, GetInvalidationCount(id)); 431 EXPECT_EQ(2, GetInvalidationCount(id));
432 EXPECT_EQ("", GetPayload(id)); 432 EXPECT_EQ("", GetPayload(id));
433 EXPECT_EQ(kMinVersion, GetMaxVersion(id)); 433 EXPECT_EQ(kMinVersion, GetMaxVersion(id));
434 } 434 }
435 435
436 // Fire an invalidation for all enabled IDs. It shouldn't update the 436 // Fire an invalidation for all enabled IDs. It shouldn't update the
437 // payload or version, but it should still invalidate the IDs. 437 // payload or version, but it should still invalidate the IDs.
438 TEST_F(ChromeInvalidationClientTest, InvalidateAll) { 438 TEST_F(SyncInvalidationClientTest, InvalidateAll) {
439 FireInvalidateAll(); 439 FireInvalidateAll();
440 440
441 for (ObjectIdSet::const_iterator it = registered_ids_.begin(); 441 for (ObjectIdSet::const_iterator it = registered_ids_.begin();
442 it != registered_ids_.end(); ++it) { 442 it != registered_ids_.end(); ++it) {
443 EXPECT_EQ(1, GetInvalidationCount(*it)); 443 EXPECT_EQ(1, GetInvalidationCount(*it));
444 EXPECT_EQ("", GetPayload(*it)); 444 EXPECT_EQ("", GetPayload(*it));
445 EXPECT_EQ(kMinVersion, GetMaxVersion(*it)); 445 EXPECT_EQ(kMinVersion, GetMaxVersion(*it));
446 } 446 }
447 } 447 }
448 448
449 // Comprehensive test of various scenarios for multiple IDs. 449 // Comprehensive test of various scenarios for multiple IDs.
450 TEST_F(ChromeInvalidationClientTest, InvalidateMultipleIds) { 450 TEST_F(SyncInvalidationClientTest, InvalidateMultipleIds) {
451 FireInvalidate(kBookmarksId_, 3, NULL); 451 FireInvalidate(kBookmarksId_, 3, NULL);
452 452
453 EXPECT_EQ(1, GetInvalidationCount(kBookmarksId_)); 453 EXPECT_EQ(1, GetInvalidationCount(kBookmarksId_));
454 EXPECT_EQ("", GetPayload(kBookmarksId_)); 454 EXPECT_EQ("", GetPayload(kBookmarksId_));
455 EXPECT_EQ(3, GetMaxVersion(kBookmarksId_)); 455 EXPECT_EQ(3, GetMaxVersion(kBookmarksId_));
456 456
457 FireInvalidate(kExtensionsId_, 2, NULL); 457 FireInvalidate(kExtensionsId_, 2, NULL);
458 458
459 EXPECT_EQ(1, GetInvalidationCount(kExtensionsId_)); 459 EXPECT_EQ(1, GetInvalidationCount(kExtensionsId_));
460 EXPECT_EQ("", GetPayload(kExtensionsId_)); 460 EXPECT_EQ("", GetPayload(kExtensionsId_));
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
506 EXPECT_EQ(3, GetInvalidationCount(kBookmarksId_)); 506 EXPECT_EQ(3, GetInvalidationCount(kBookmarksId_));
507 EXPECT_EQ("", GetPayload(kBookmarksId_)); 507 EXPECT_EQ("", GetPayload(kBookmarksId_));
508 EXPECT_EQ(4, GetMaxVersion(kBookmarksId_)); 508 EXPECT_EQ(4, GetMaxVersion(kBookmarksId_));
509 } 509 }
510 510
511 // Registration tests. 511 // Registration tests.
512 512
513 // With IDs already registered, enable notifications then ready the 513 // With IDs already registered, enable notifications then ready the
514 // client. The IDs should be registered only after the client is 514 // client. The IDs should be registered only after the client is
515 // readied. 515 // readied.
516 TEST_F(ChromeInvalidationClientTest, RegisterEnableReady) { 516 TEST_F(SyncInvalidationClientTest, RegisterEnableReady) {
517 EXPECT_TRUE(GetRegisteredIds().empty()); 517 EXPECT_TRUE(GetRegisteredIds().empty());
518 518
519 EnableNotifications(); 519 EnableNotifications();
520 520
521 EXPECT_TRUE(GetRegisteredIds().empty()); 521 EXPECT_TRUE(GetRegisteredIds().empty());
522 522
523 client_.Ready(fake_invalidation_client_); 523 client_.Ready(fake_invalidation_client_);
524 524
525 EXPECT_EQ(registered_ids_, GetRegisteredIds()); 525 EXPECT_EQ(registered_ids_, GetRegisteredIds());
526 } 526 }
527 527
528 // With IDs already registered, ready the client then enable 528 // With IDs already registered, ready the client then enable
529 // notifications. The IDs should be registered after the client is 529 // notifications. The IDs should be registered after the client is
530 // readied. 530 // readied.
531 TEST_F(ChromeInvalidationClientTest, RegisterReadyEnable) { 531 TEST_F(SyncInvalidationClientTest, RegisterReadyEnable) {
532 EXPECT_TRUE(GetRegisteredIds().empty()); 532 EXPECT_TRUE(GetRegisteredIds().empty());
533 533
534 client_.Ready(fake_invalidation_client_); 534 client_.Ready(fake_invalidation_client_);
535 535
536 EXPECT_EQ(registered_ids_, GetRegisteredIds()); 536 EXPECT_EQ(registered_ids_, GetRegisteredIds());
537 537
538 EnableNotifications(); 538 EnableNotifications();
539 539
540 EXPECT_EQ(registered_ids_, GetRegisteredIds()); 540 EXPECT_EQ(registered_ids_, GetRegisteredIds());
541 } 541 }
542 542
543 // Unregister the IDs, enable notifications, re-register the IDs, then 543 // Unregister the IDs, enable notifications, re-register the IDs, then
544 // ready the client. The IDs should be registered only after the 544 // ready the client. The IDs should be registered only after the
545 // client is readied. 545 // client is readied.
546 TEST_F(ChromeInvalidationClientTest, EnableRegisterReady) { 546 TEST_F(SyncInvalidationClientTest, EnableRegisterReady) {
547 client_.UpdateRegisteredIds(ObjectIdSet()); 547 client_.UpdateRegisteredIds(ObjectIdSet());
548 548
549 EXPECT_TRUE(GetRegisteredIds().empty()); 549 EXPECT_TRUE(GetRegisteredIds().empty());
550 550
551 EnableNotifications(); 551 EnableNotifications();
552 552
553 EXPECT_TRUE(GetRegisteredIds().empty()); 553 EXPECT_TRUE(GetRegisteredIds().empty());
554 554
555 client_.UpdateRegisteredIds(registered_ids_); 555 client_.UpdateRegisteredIds(registered_ids_);
556 556
557 EXPECT_TRUE(GetRegisteredIds().empty()); 557 EXPECT_TRUE(GetRegisteredIds().empty());
558 558
559 client_.Ready(fake_invalidation_client_); 559 client_.Ready(fake_invalidation_client_);
560 560
561 EXPECT_EQ(registered_ids_, GetRegisteredIds()); 561 EXPECT_EQ(registered_ids_, GetRegisteredIds());
562 } 562 }
563 563
564 // Unregister the IDs, enable notifications, ready the client, then 564 // Unregister the IDs, enable notifications, ready the client, then
565 // re-register the IDs. The IDs should be registered only after the 565 // re-register the IDs. The IDs should be registered only after the
566 // client is readied. 566 // client is readied.
567 TEST_F(ChromeInvalidationClientTest, EnableReadyRegister) { 567 TEST_F(SyncInvalidationClientTest, EnableReadyRegister) {
568 client_.UpdateRegisteredIds(ObjectIdSet()); 568 client_.UpdateRegisteredIds(ObjectIdSet());
569 569
570 EXPECT_TRUE(GetRegisteredIds().empty()); 570 EXPECT_TRUE(GetRegisteredIds().empty());
571 571
572 EnableNotifications(); 572 EnableNotifications();
573 573
574 EXPECT_TRUE(GetRegisteredIds().empty()); 574 EXPECT_TRUE(GetRegisteredIds().empty());
575 575
576 client_.Ready(fake_invalidation_client_); 576 client_.Ready(fake_invalidation_client_);
577 577
578 EXPECT_TRUE(GetRegisteredIds().empty()); 578 EXPECT_TRUE(GetRegisteredIds().empty());
579 579
580 client_.UpdateRegisteredIds(registered_ids_); 580 client_.UpdateRegisteredIds(registered_ids_);
581 581
582 EXPECT_EQ(registered_ids_, GetRegisteredIds()); 582 EXPECT_EQ(registered_ids_, GetRegisteredIds());
583 } 583 }
584 584
585 // Unregister the IDs, ready the client, enable notifications, then 585 // Unregister the IDs, ready the client, enable notifications, then
586 // re-register the IDs. The IDs should be registered only after the 586 // re-register the IDs. The IDs should be registered only after the
587 // client is readied. 587 // client is readied.
588 TEST_F(ChromeInvalidationClientTest, ReadyEnableRegister) { 588 TEST_F(SyncInvalidationClientTest, ReadyEnableRegister) {
589 client_.UpdateRegisteredIds(ObjectIdSet()); 589 client_.UpdateRegisteredIds(ObjectIdSet());
590 590
591 EXPECT_TRUE(GetRegisteredIds().empty()); 591 EXPECT_TRUE(GetRegisteredIds().empty());
592 592
593 EnableNotifications(); 593 EnableNotifications();
594 594
595 EXPECT_TRUE(GetRegisteredIds().empty()); 595 EXPECT_TRUE(GetRegisteredIds().empty());
596 596
597 client_.Ready(fake_invalidation_client_); 597 client_.Ready(fake_invalidation_client_);
598 598
599 EXPECT_TRUE(GetRegisteredIds().empty()); 599 EXPECT_TRUE(GetRegisteredIds().empty());
600 600
601 client_.UpdateRegisteredIds(registered_ids_); 601 client_.UpdateRegisteredIds(registered_ids_);
602 602
603 EXPECT_EQ(registered_ids_, GetRegisteredIds()); 603 EXPECT_EQ(registered_ids_, GetRegisteredIds());
604 } 604 }
605 605
606 // Unregister the IDs, ready the client, re-register the IDs, then 606 // Unregister the IDs, ready the client, re-register the IDs, then
607 // enable notifications. The IDs should be registered only after the 607 // enable notifications. The IDs should be registered only after the
608 // client is readied. 608 // client is readied.
609 // 609 //
610 // This test is important: see http://crbug.com/139424. 610 // This test is important: see http://crbug.com/139424.
611 TEST_F(ChromeInvalidationClientTest, ReadyRegisterEnable) { 611 TEST_F(SyncInvalidationClientTest, ReadyRegisterEnable) {
612 client_.UpdateRegisteredIds(ObjectIdSet()); 612 client_.UpdateRegisteredIds(ObjectIdSet());
613 613
614 EXPECT_TRUE(GetRegisteredIds().empty()); 614 EXPECT_TRUE(GetRegisteredIds().empty());
615 615
616 client_.Ready(fake_invalidation_client_); 616 client_.Ready(fake_invalidation_client_);
617 617
618 EXPECT_TRUE(GetRegisteredIds().empty()); 618 EXPECT_TRUE(GetRegisteredIds().empty());
619 619
620 client_.UpdateRegisteredIds(registered_ids_); 620 client_.UpdateRegisteredIds(registered_ids_);
621 621
622 EXPECT_EQ(registered_ids_, GetRegisteredIds()); 622 EXPECT_EQ(registered_ids_, GetRegisteredIds());
623 623
624 EnableNotifications(); 624 EnableNotifications();
625 625
626 EXPECT_EQ(registered_ids_, GetRegisteredIds()); 626 EXPECT_EQ(registered_ids_, GetRegisteredIds());
627 } 627 }
628 628
629 // With IDs already registered, ready the client, restart the client, 629 // With IDs already registered, ready the client, restart the client,
630 // then re-ready it. The IDs should still be registered. 630 // then re-ready it. The IDs should still be registered.
631 TEST_F(ChromeInvalidationClientTest, RegisterTypesPreserved) { 631 TEST_F(SyncInvalidationClientTest, RegisterTypesPreserved) {
632 EXPECT_TRUE(GetRegisteredIds().empty()); 632 EXPECT_TRUE(GetRegisteredIds().empty());
633 633
634 client_.Ready(fake_invalidation_client_); 634 client_.Ready(fake_invalidation_client_);
635 635
636 EXPECT_EQ(registered_ids_, GetRegisteredIds()); 636 EXPECT_EQ(registered_ids_, GetRegisteredIds());
637 637
638 RestartClient(); 638 RestartClient();
639 639
640 EXPECT_TRUE(GetRegisteredIds().empty()); 640 EXPECT_TRUE(GetRegisteredIds().empty());
641 641
642 client_.Ready(fake_invalidation_client_); 642 client_.Ready(fake_invalidation_client_);
643 643
644 EXPECT_EQ(registered_ids_, GetRegisteredIds()); 644 EXPECT_EQ(registered_ids_, GetRegisteredIds());
645 } 645 }
646 646
647 // Without readying the client, disable notifications, then enable 647 // Without readying the client, disable notifications, then enable
648 // them. The listener should still think notifications are disabled. 648 // them. The listener should still think notifications are disabled.
649 TEST_F(ChromeInvalidationClientTest, EnableNotificationsNotReady) { 649 TEST_F(SyncInvalidationClientTest, EnableNotificationsNotReady) {
650 EXPECT_EQ(TRANSIENT_NOTIFICATION_ERROR, 650 EXPECT_EQ(TRANSIENT_NOTIFICATION_ERROR,
651 GetNotificationsDisabledReason()); 651 GetNotificationsDisabledReason());
652 652
653 DisableNotifications( 653 DisableNotifications(
654 notifier::TRANSIENT_NOTIFICATION_ERROR); 654 notifier::TRANSIENT_NOTIFICATION_ERROR);
655 655
656 EXPECT_EQ(TRANSIENT_NOTIFICATION_ERROR, 656 EXPECT_EQ(TRANSIENT_NOTIFICATION_ERROR,
657 GetNotificationsDisabledReason()); 657 GetNotificationsDisabledReason());
658 658
659 DisableNotifications( 659 DisableNotifications(
660 notifier::NOTIFICATION_CREDENTIALS_REJECTED); 660 notifier::NOTIFICATION_CREDENTIALS_REJECTED);
661 661
662 EXPECT_EQ(NOTIFICATION_CREDENTIALS_REJECTED, 662 EXPECT_EQ(NOTIFICATION_CREDENTIALS_REJECTED,
663 GetNotificationsDisabledReason()); 663 GetNotificationsDisabledReason());
664 664
665 EnableNotifications(); 665 EnableNotifications();
666 666
667 EXPECT_EQ(TRANSIENT_NOTIFICATION_ERROR, 667 EXPECT_EQ(TRANSIENT_NOTIFICATION_ERROR,
668 GetNotificationsDisabledReason()); 668 GetNotificationsDisabledReason());
669 } 669 }
670 670
671 // Enable notifications then Ready the invalidation client. The 671 // Enable notifications then Ready the invalidation client. The
672 // listener should then be ready. 672 // listener should then be ready.
673 TEST_F(ChromeInvalidationClientTest, EnableNotificationsThenReady) { 673 TEST_F(SyncInvalidationClientTest, EnableNotificationsThenReady) {
674 EXPECT_EQ(TRANSIENT_NOTIFICATION_ERROR, GetNotificationsDisabledReason()); 674 EXPECT_EQ(TRANSIENT_NOTIFICATION_ERROR, GetNotificationsDisabledReason());
675 675
676 EnableNotifications(); 676 EnableNotifications();
677 677
678 EXPECT_EQ(TRANSIENT_NOTIFICATION_ERROR, GetNotificationsDisabledReason()); 678 EXPECT_EQ(TRANSIENT_NOTIFICATION_ERROR, GetNotificationsDisabledReason());
679 679
680 client_.Ready(fake_invalidation_client_); 680 client_.Ready(fake_invalidation_client_);
681 681
682 EXPECT_EQ(NO_NOTIFICATION_ERROR, GetNotificationsDisabledReason()); 682 EXPECT_EQ(NO_NOTIFICATION_ERROR, GetNotificationsDisabledReason());
683 } 683 }
684 684
685 // Ready the invalidation client then enable notifications. The 685 // Ready the invalidation client then enable notifications. The
686 // listener should then be ready. 686 // listener should then be ready.
687 TEST_F(ChromeInvalidationClientTest, ReadyThenEnableNotifications) { 687 TEST_F(SyncInvalidationClientTest, ReadyThenEnableNotifications) {
688 EXPECT_EQ(TRANSIENT_NOTIFICATION_ERROR, GetNotificationsDisabledReason()); 688 EXPECT_EQ(TRANSIENT_NOTIFICATION_ERROR, GetNotificationsDisabledReason());
689 689
690 client_.Ready(fake_invalidation_client_); 690 client_.Ready(fake_invalidation_client_);
691 691
692 EXPECT_EQ(TRANSIENT_NOTIFICATION_ERROR, GetNotificationsDisabledReason()); 692 EXPECT_EQ(TRANSIENT_NOTIFICATION_ERROR, GetNotificationsDisabledReason());
693 693
694 EnableNotifications(); 694 EnableNotifications();
695 695
696 EXPECT_EQ(NO_NOTIFICATION_ERROR, GetNotificationsDisabledReason()); 696 EXPECT_EQ(NO_NOTIFICATION_ERROR, GetNotificationsDisabledReason());
697 } 697 }
698 698
699 // Enable notifications and ready the client. Then disable 699 // Enable notifications and ready the client. Then disable
700 // notifications with an auth error and re-enable notifications. The 700 // notifications with an auth error and re-enable notifications. The
701 // listener should go into an auth error mode and then back out. 701 // listener should go into an auth error mode and then back out.
702 TEST_F(ChromeInvalidationClientTest, PushClientAuthError) { 702 TEST_F(SyncInvalidationClientTest, PushClientAuthError) {
703 EnableNotifications(); 703 EnableNotifications();
704 client_.Ready(fake_invalidation_client_); 704 client_.Ready(fake_invalidation_client_);
705 705
706 EXPECT_EQ(NO_NOTIFICATION_ERROR, GetNotificationsDisabledReason()); 706 EXPECT_EQ(NO_NOTIFICATION_ERROR, GetNotificationsDisabledReason());
707 707
708 DisableNotifications( 708 DisableNotifications(
709 notifier::NOTIFICATION_CREDENTIALS_REJECTED); 709 notifier::NOTIFICATION_CREDENTIALS_REJECTED);
710 710
711 EXPECT_EQ(NOTIFICATION_CREDENTIALS_REJECTED, 711 EXPECT_EQ(NOTIFICATION_CREDENTIALS_REJECTED,
712 GetNotificationsDisabledReason()); 712 GetNotificationsDisabledReason());
713 713
714 EnableNotifications(); 714 EnableNotifications();
715 715
716 EXPECT_EQ(NO_NOTIFICATION_ERROR, GetNotificationsDisabledReason()); 716 EXPECT_EQ(NO_NOTIFICATION_ERROR, GetNotificationsDisabledReason());
717 } 717 }
718 718
719 // Enable notifications and ready the client. Then simulate an auth 719 // Enable notifications and ready the client. Then simulate an auth
720 // error from the invalidation client. Simulate some notification 720 // error from the invalidation client. Simulate some notification
721 // events, then re-ready the client. The listener should go into an 721 // events, then re-ready the client. The listener should go into an
722 // auth error mode and come out of it only after the client is ready. 722 // auth error mode and come out of it only after the client is ready.
723 TEST_F(ChromeInvalidationClientTest, InvalidationClientAuthError) { 723 TEST_F(SyncInvalidationClientTest, InvalidationClientAuthError) {
724 EnableNotifications(); 724 EnableNotifications();
725 client_.Ready(fake_invalidation_client_); 725 client_.Ready(fake_invalidation_client_);
726 726
727 EXPECT_EQ(NO_NOTIFICATION_ERROR, GetNotificationsDisabledReason()); 727 EXPECT_EQ(NO_NOTIFICATION_ERROR, GetNotificationsDisabledReason());
728 728
729 client_.InformError( 729 client_.InformError(
730 fake_invalidation_client_, 730 fake_invalidation_client_,
731 invalidation::ErrorInfo( 731 invalidation::ErrorInfo(
732 invalidation::ErrorReason::AUTH_FAILURE, 732 invalidation::ErrorReason::AUTH_FAILURE,
733 false /* is_transient */, 733 false /* is_transient */,
(...skipping 21 matching lines...) Expand all
755 GetNotificationsDisabledReason()); 755 GetNotificationsDisabledReason());
756 756
757 client_.Ready(fake_invalidation_client_); 757 client_.Ready(fake_invalidation_client_);
758 758
759 EXPECT_EQ(NO_NOTIFICATION_ERROR, GetNotificationsDisabledReason()); 759 EXPECT_EQ(NO_NOTIFICATION_ERROR, GetNotificationsDisabledReason());
760 } 760 }
761 761
762 } // namespace 762 } // namespace
763 763
764 } // namespace syncer 764 } // namespace syncer
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698