OLD | NEW |
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 "sync/notifier/sync_notifier_factory.h" | 5 #include "sync/notifier/sync_notifier_factory.h" |
6 | 6 |
7 #include "base/command_line.h" | 7 #include "base/command_line.h" |
8 #include "base/compiler_specific.h" | 8 #include "base/compiler_specific.h" |
9 #include "base/memory/ref_counted.h" | 9 #include "base/memory/ref_counted.h" |
10 #include "base/memory/scoped_ptr.h" | 10 #include "base/memory/scoped_ptr.h" |
(...skipping 11 matching lines...) Expand all Loading... |
22 #include "testing/gmock/include/gmock/gmock.h" | 22 #include "testing/gmock/include/gmock/gmock.h" |
23 #include "testing/gtest/include/gtest/gtest.h" | 23 #include "testing/gtest/include/gtest/gtest.h" |
24 | 24 |
25 namespace syncer { | 25 namespace syncer { |
26 namespace { | 26 namespace { |
27 | 27 |
28 using ::testing::Mock; | 28 using ::testing::Mock; |
29 using ::testing::NiceMock; | 29 using ::testing::NiceMock; |
30 using ::testing::StrictMock; | 30 using ::testing::StrictMock; |
31 | 31 |
| 32 const char kHandlerName[] = "MockObserver"; |
| 33 |
32 class SyncNotifierFactoryTest : public testing::Test { | 34 class SyncNotifierFactoryTest : public testing::Test { |
33 protected: | 35 protected: |
34 | 36 |
35 virtual void SetUp() OVERRIDE { | 37 virtual void SetUp() OVERRIDE { |
36 notifier_options_.request_context_getter = | 38 notifier_options_.request_context_getter = |
37 new TestURLRequestContextGetter(message_loop_.message_loop_proxy()); | 39 new TestURLRequestContextGetter(message_loop_.message_loop_proxy()); |
38 } | 40 } |
39 | 41 |
40 virtual void TearDown() OVERRIDE { | 42 virtual void TearDown() OVERRIDE { |
41 Mock::VerifyAndClearExpectations(&mock_observer_); | 43 Mock::VerifyAndClearExpectations(&mock_observer_); |
(...skipping 12 matching lines...) Expand all Loading... |
54 SyncNotifierFactory factory( | 56 SyncNotifierFactory factory( |
55 notifier_options_, | 57 notifier_options_, |
56 "test client info", | 58 "test client info", |
57 base::WeakPtr<InvalidationStateTracker>()); | 59 base::WeakPtr<InvalidationStateTracker>()); |
58 scoped_ptr<SyncNotifier> notifier(factory.CreateSyncNotifier()); | 60 scoped_ptr<SyncNotifier> notifier(factory.CreateSyncNotifier()); |
59 #if defined(OS_ANDROID) | 61 #if defined(OS_ANDROID) |
60 ASSERT_FALSE(notifier.get()); | 62 ASSERT_FALSE(notifier.get()); |
61 #else | 63 #else |
62 ASSERT_TRUE(notifier.get()); | 64 ASSERT_TRUE(notifier.get()); |
63 ObjectIdSet ids = ModelTypeSetToObjectIdSet(ModelTypeSet(syncer::BOOKMARKS)); | 65 ObjectIdSet ids = ModelTypeSetToObjectIdSet(ModelTypeSet(syncer::BOOKMARKS)); |
64 notifier->UpdateRegisteredIds(&mock_observer_, ids); | 66 notifier->SetHandler(kHandlerName, &mock_observer_); |
65 notifier->UpdateRegisteredIds(&mock_observer_, ObjectIdSet()); | 67 notifier->UpdateRegisteredIds(kHandlerName, ids); |
| 68 notifier->SetHandler(kHandlerName, NULL); |
66 #endif | 69 #endif |
67 } | 70 } |
68 | 71 |
69 // Test basic creation of a P2PNotifier. | 72 // Test basic creation of a P2PNotifier. |
70 TEST_F(SyncNotifierFactoryTest, Basic_P2P) { | 73 TEST_F(SyncNotifierFactoryTest, Basic_P2P) { |
71 notifier_options_.notification_method = notifier::NOTIFICATION_P2P; | 74 notifier_options_.notification_method = notifier::NOTIFICATION_P2P; |
72 SyncNotifierFactory factory( | 75 SyncNotifierFactory factory( |
73 notifier_options_, | 76 notifier_options_, |
74 "test client info", | 77 "test client info", |
75 base::WeakPtr<InvalidationStateTracker>()); | 78 base::WeakPtr<InvalidationStateTracker>()); |
76 scoped_ptr<SyncNotifier> notifier(factory.CreateSyncNotifier()); | 79 scoped_ptr<SyncNotifier> notifier(factory.CreateSyncNotifier()); |
77 #if defined(OS_ANDROID) | 80 #if defined(OS_ANDROID) |
78 ASSERT_FALSE(notifier.get()); | 81 ASSERT_FALSE(notifier.get()); |
79 #else | 82 #else |
80 ASSERT_TRUE(notifier.get()); | 83 ASSERT_TRUE(notifier.get()); |
81 ObjectIdSet ids = ModelTypeSetToObjectIdSet(ModelTypeSet(syncer::BOOKMARKS)); | 84 ObjectIdSet ids = ModelTypeSetToObjectIdSet(ModelTypeSet(syncer::BOOKMARKS)); |
82 notifier->UpdateRegisteredIds(&mock_observer_, ids); | 85 notifier->SetHandler(kHandlerName, &mock_observer_); |
83 notifier->UpdateRegisteredIds(&mock_observer_, ObjectIdSet()); | 86 notifier->UpdateRegisteredIds(kHandlerName, ids); |
| 87 notifier->SetHandler(kHandlerName, NULL); |
84 #endif | 88 #endif |
85 } | 89 } |
86 | 90 |
87 } // namespace | 91 } // namespace |
88 } // namespace syncer | 92 } // namespace syncer |
OLD | NEW |