| OLD | NEW |
| (Empty) |
| 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 | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #include "sync/notifier/non_blocking_invalidation_notifier.h" | |
| 6 | |
| 7 #include "base/memory/ref_counted.h" | |
| 8 #include "base/memory/scoped_ptr.h" | |
| 9 #include "base/message_loop.h" | |
| 10 #include "base/threading/thread.h" | |
| 11 #include "google/cacheinvalidation/types.pb.h" | |
| 12 #include "jingle/notifier/base/fake_base_task.h" | |
| 13 #include "net/url_request/url_request_test_util.h" | |
| 14 #include "sync/internal_api/public/base/model_type.h" | |
| 15 #include "sync/internal_api/public/base/model_type_state_map.h" | |
| 16 #include "sync/internal_api/public/util/weak_handle.h" | |
| 17 #include "sync/notifier/fake_sync_notifier_observer.h" | |
| 18 #include "sync/notifier/invalidation_state_tracker.h" | |
| 19 #include "sync/notifier/object_id_state_map_test_util.h" | |
| 20 #include "testing/gmock/include/gmock/gmock.h" | |
| 21 #include "testing/gtest/include/gtest/gtest.h" | |
| 22 | |
| 23 namespace syncer { | |
| 24 | |
| 25 namespace { | |
| 26 | |
| 27 using ::testing::InSequence; | |
| 28 using ::testing::StrictMock; | |
| 29 | |
| 30 class NonBlockingInvalidationNotifierTest : public testing::Test { | |
| 31 public: | |
| 32 NonBlockingInvalidationNotifierTest() : io_thread_("Test IO thread") {} | |
| 33 | |
| 34 protected: | |
| 35 virtual void SetUp() { | |
| 36 base::Thread::Options options; | |
| 37 options.message_loop_type = MessageLoop::TYPE_IO; | |
| 38 io_thread_.StartWithOptions(options); | |
| 39 request_context_getter_ = | |
| 40 new TestURLRequestContextGetter(io_thread_.message_loop_proxy()); | |
| 41 notifier::NotifierOptions notifier_options; | |
| 42 notifier_options.request_context_getter = request_context_getter_; | |
| 43 invalidation_notifier_.reset( | |
| 44 new NonBlockingInvalidationNotifier( | |
| 45 notifier_options, | |
| 46 InvalidationVersionMap(), | |
| 47 std::string(), // initial_invalidation_state | |
| 48 MakeWeakHandle(base::WeakPtr<InvalidationStateTracker>()), | |
| 49 "fake_client_info")); | |
| 50 invalidation_notifier_->RegisterHandler(&fake_observer_); | |
| 51 } | |
| 52 | |
| 53 virtual void TearDown() { | |
| 54 invalidation_notifier_->UnregisterHandler(&fake_observer_); | |
| 55 invalidation_notifier_.reset(); | |
| 56 request_context_getter_ = NULL; | |
| 57 io_thread_.Stop(); | |
| 58 ui_loop_.RunAllPending(); | |
| 59 } | |
| 60 | |
| 61 MessageLoop ui_loop_; | |
| 62 base::Thread io_thread_; | |
| 63 scoped_refptr<net::URLRequestContextGetter> request_context_getter_; | |
| 64 scoped_ptr<NonBlockingInvalidationNotifier> invalidation_notifier_; | |
| 65 FakeSyncNotifierObserver fake_observer_; | |
| 66 notifier::FakeBaseTask fake_base_task_; | |
| 67 }; | |
| 68 | |
| 69 // TODO(akalin): Add real unit tests (http://crbug.com/140410). | |
| 70 | |
| 71 TEST_F(NonBlockingInvalidationNotifierTest, Basic) { | |
| 72 const ModelTypeSet models(PREFERENCES, BOOKMARKS, AUTOFILL); | |
| 73 const ObjectIdStateMap& id_state_map = | |
| 74 ModelTypeStateMapToObjectIdStateMap( | |
| 75 ModelTypeSetToStateMap(models, "payload")); | |
| 76 | |
| 77 invalidation_notifier_->UpdateRegisteredIds( | |
| 78 &fake_observer_, ModelTypeSetToObjectIdSet(models)); | |
| 79 | |
| 80 invalidation_notifier_->SetStateDeprecated("fake_state"); | |
| 81 invalidation_notifier_->SetUniqueId("fake_id"); | |
| 82 invalidation_notifier_->UpdateCredentials("foo@bar.com", "fake_token"); | |
| 83 | |
| 84 invalidation_notifier_->OnNotificationsEnabled(); | |
| 85 EXPECT_EQ(NO_NOTIFICATION_ERROR, | |
| 86 fake_observer_.GetNotificationsDisabledReason()); | |
| 87 | |
| 88 invalidation_notifier_->OnIncomingNotification( | |
| 89 id_state_map, REMOTE_NOTIFICATION); | |
| 90 EXPECT_THAT(id_state_map, | |
| 91 Eq(fake_observer_.GetLastNotificationIdStateMap())); | |
| 92 EXPECT_EQ(REMOTE_NOTIFICATION, fake_observer_.GetLastNotificationSource()); | |
| 93 | |
| 94 invalidation_notifier_->OnNotificationsDisabled( | |
| 95 TRANSIENT_NOTIFICATION_ERROR); | |
| 96 EXPECT_EQ(TRANSIENT_NOTIFICATION_ERROR, | |
| 97 fake_observer_.GetNotificationsDisabledReason()); | |
| 98 | |
| 99 invalidation_notifier_->OnNotificationsDisabled( | |
| 100 NOTIFICATION_CREDENTIALS_REJECTED); | |
| 101 EXPECT_EQ(NOTIFICATION_CREDENTIALS_REJECTED, | |
| 102 fake_observer_.GetNotificationsDisabledReason()); | |
| 103 | |
| 104 ui_loop_.RunAllPending(); | |
| 105 } | |
| 106 | |
| 107 } // namespace | |
| 108 | |
| 109 } // namespace syncer | |
| OLD | NEW |