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/invalidator_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_invalidation_handler.h" | |
19 #include "sync/notifier/invalidation_state_tracker.h" | |
20 #include "sync/notifier/invalidator.h" | |
21 #include "testing/gtest/include/gtest/gtest.h" | |
22 | |
23 namespace syncer { | |
24 namespace { | |
25 | |
26 class InvalidatorFactoryTest : public testing::Test { | |
27 protected: | |
28 | |
29 virtual void SetUp() OVERRIDE { | |
30 notifier_options_.request_context_getter = | |
31 new net::TestURLRequestContextGetter( | |
32 message_loop_.message_loop_proxy()); | |
33 } | |
34 | |
35 virtual void TearDown() OVERRIDE { | |
36 message_loop_.RunUntilIdle(); | |
37 EXPECT_EQ(0, fake_handler_.GetInvalidationCount()); | |
38 } | |
39 | |
40 base::MessageLoop message_loop_; | |
41 FakeInvalidationHandler fake_handler_; | |
42 notifier::NotifierOptions notifier_options_; | |
43 scoped_ptr<InvalidatorFactory> factory_; | |
44 }; | |
45 | |
46 // Test basic creation of a NonBlockingInvalidationNotifier. | |
47 TEST_F(InvalidatorFactoryTest, Basic) { | |
48 notifier_options_.notification_method = notifier::NOTIFICATION_SERVER; | |
49 InvalidatorFactory factory( | |
50 notifier_options_, | |
51 "test client info", | |
52 base::WeakPtr<InvalidationStateTracker>()); | |
53 scoped_ptr<Invalidator> invalidator(factory.CreateInvalidator()); | |
54 #if defined(OS_ANDROID) | |
55 ASSERT_FALSE(invalidator.get()); | |
56 #else | |
57 ASSERT_TRUE(invalidator.get()); | |
58 ObjectIdSet ids = ModelTypeSetToObjectIdSet(ModelTypeSet(syncer::BOOKMARKS)); | |
59 invalidator->RegisterHandler(&fake_handler_); | |
60 invalidator->UpdateRegisteredIds(&fake_handler_, ids); | |
61 invalidator->UnregisterHandler(&fake_handler_); | |
62 #endif | |
63 } | |
64 | |
65 // Test basic creation of a P2PNotifier. | |
66 TEST_F(InvalidatorFactoryTest, Basic_P2P) { | |
67 notifier_options_.notification_method = notifier::NOTIFICATION_P2P; | |
68 InvalidatorFactory factory( | |
69 notifier_options_, | |
70 "test client info", | |
71 base::WeakPtr<InvalidationStateTracker>()); | |
72 scoped_ptr<Invalidator> invalidator(factory.CreateInvalidator()); | |
73 #if defined(OS_ANDROID) | |
74 ASSERT_FALSE(invalidator.get()); | |
75 #else | |
76 ASSERT_TRUE(invalidator.get()); | |
77 ObjectIdSet ids = ModelTypeSetToObjectIdSet(ModelTypeSet(syncer::BOOKMARKS)); | |
78 invalidator->RegisterHandler(&fake_handler_); | |
79 invalidator->UpdateRegisteredIds(&fake_handler_, ids); | |
80 invalidator->UnregisterHandler(&fake_handler_); | |
81 #endif | |
82 } | |
83 | |
84 } // namespace | |
85 } // namespace syncer | |
OLD | NEW |