| 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/sync_notifier_factory.h" | |
| 6 | |
| 7 #include "base/command_line.h" | |
| 8 #include "base/compiler_specific.h" | |
| 9 #include "base/memory/ref_counted.h" | |
| 10 #include "base/memory/scoped_ptr.h" | |
| 11 #include "base/memory/weak_ptr.h" | |
| 12 #include "base/message_loop.h" | |
| 13 #include "base/threading/thread.h" | |
| 14 #include "jingle/notifier/base/notification_method.h" | |
| 15 #include "jingle/notifier/base/notifier_options.h" | |
| 16 #include "net/url_request/url_request_test_util.h" | |
| 17 #include "sync/internal_api/public/base/model_type.h" | |
| 18 #include "sync/notifier/fake_sync_notifier_observer.h" | |
| 19 #include "sync/notifier/invalidation_state_tracker.h" | |
| 20 #include "sync/notifier/sync_notifier.h" | |
| 21 #include "testing/gtest/include/gtest/gtest.h" | |
| 22 | |
| 23 namespace syncer { | |
| 24 namespace { | |
| 25 | |
| 26 class SyncNotifierFactoryTest : public testing::Test { | |
| 27 protected: | |
| 28 | |
| 29 virtual void SetUp() OVERRIDE { | |
| 30 notifier_options_.request_context_getter = | |
| 31 new TestURLRequestContextGetter(message_loop_.message_loop_proxy()); | |
| 32 } | |
| 33 | |
| 34 virtual void TearDown() OVERRIDE { | |
| 35 message_loop_.RunAllPending(); | |
| 36 EXPECT_EQ(0, fake_observer_.GetNotificationCount()); | |
| 37 } | |
| 38 | |
| 39 MessageLoop message_loop_; | |
| 40 FakeSyncNotifierObserver fake_observer_; | |
| 41 notifier::NotifierOptions notifier_options_; | |
| 42 scoped_ptr<SyncNotifierFactory> factory_; | |
| 43 }; | |
| 44 | |
| 45 // Test basic creation of a NonBlockingInvalidationNotifier. | |
| 46 TEST_F(SyncNotifierFactoryTest, Basic) { | |
| 47 notifier_options_.notification_method = notifier::NOTIFICATION_SERVER; | |
| 48 SyncNotifierFactory factory( | |
| 49 notifier_options_, | |
| 50 "test client info", | |
| 51 base::WeakPtr<InvalidationStateTracker>()); | |
| 52 scoped_ptr<SyncNotifier> notifier(factory.CreateSyncNotifier()); | |
| 53 #if defined(OS_ANDROID) | |
| 54 ASSERT_FALSE(notifier.get()); | |
| 55 #else | |
| 56 ASSERT_TRUE(notifier.get()); | |
| 57 ObjectIdSet ids = ModelTypeSetToObjectIdSet(ModelTypeSet(syncer::BOOKMARKS)); | |
| 58 notifier->RegisterHandler(&fake_observer_); | |
| 59 notifier->UpdateRegisteredIds(&fake_observer_, ids); | |
| 60 notifier->UnregisterHandler(&fake_observer_); | |
| 61 #endif | |
| 62 } | |
| 63 | |
| 64 // Test basic creation of a P2PNotifier. | |
| 65 TEST_F(SyncNotifierFactoryTest, Basic_P2P) { | |
| 66 notifier_options_.notification_method = notifier::NOTIFICATION_P2P; | |
| 67 SyncNotifierFactory factory( | |
| 68 notifier_options_, | |
| 69 "test client info", | |
| 70 base::WeakPtr<InvalidationStateTracker>()); | |
| 71 scoped_ptr<SyncNotifier> notifier(factory.CreateSyncNotifier()); | |
| 72 #if defined(OS_ANDROID) | |
| 73 ASSERT_FALSE(notifier.get()); | |
| 74 #else | |
| 75 ASSERT_TRUE(notifier.get()); | |
| 76 ObjectIdSet ids = ModelTypeSetToObjectIdSet(ModelTypeSet(syncer::BOOKMARKS)); | |
| 77 notifier->RegisterHandler(&fake_observer_); | |
| 78 notifier->UpdateRegisteredIds(&fake_observer_, ids); | |
| 79 notifier->UnregisterHandler(&fake_observer_); | |
| 80 #endif | |
| 81 } | |
| 82 | |
| 83 } // namespace | |
| 84 } // namespace syncer | |
| OLD | NEW |