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.
5 #include "sync/notifier/sync_notifier_factory.h"
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/notifier/invalidation_state_tracker.h"
18 #include "sync/notifier/mock_sync_notifier_observer.h"
19 #include "sync/notifier/sync_notifier.h"
20 #include "sync/syncable/model_type.h"
21 #include "sync/syncable/model_type_payload_map.h"
22 #include "testing/gmock/include/gmock/gmock.h"
23 #include "testing/gtest/include/gtest/gtest.h"
25 namespace sync_notifier
{
28 using ::testing::Mock
;
29 using ::testing::NiceMock
;
30 using ::testing::StrictMock
;
32 class SyncNotifierFactoryTest
: public testing::Test
{
35 virtual void SetUp() OVERRIDE
{
36 notifier_options_
.request_context_getter
=
37 new TestURLRequestContextGetter(message_loop_
.message_loop_proxy());
40 virtual void TearDown() OVERRIDE
{
41 Mock::VerifyAndClearExpectations(&mock_observer_
);
42 message_loop_
.RunAllPending();
45 MessageLoop message_loop_
;
46 StrictMock
<MockSyncNotifierObserver
> mock_observer_
;
47 notifier::NotifierOptions notifier_options_
;
48 scoped_ptr
<SyncNotifierFactory
> factory_
;
51 // Test basic creation of a NonBlockingInvalidationNotifier.
52 TEST_F(SyncNotifierFactoryTest
, Basic
) {
53 notifier_options_
.notification_method
= notifier::NOTIFICATION_SERVER
;
54 SyncNotifierFactory
factory(
57 base::WeakPtr
<sync_notifier::InvalidationStateTracker
>());
58 scoped_ptr
<SyncNotifier
> notifier(factory
.CreateSyncNotifier());
59 #if defined(OS_ANDROID)
60 ASSERT_FALSE(notifier
.get());
62 ASSERT_TRUE(notifier
.get());
63 notifier
->AddObserver(&mock_observer_
);
64 notifier
->RemoveObserver(&mock_observer_
);
68 // Test basic creation of a P2PNotifier.
69 TEST_F(SyncNotifierFactoryTest
, Basic_P2P
) {
70 notifier_options_
.notification_method
= notifier::NOTIFICATION_P2P
;
71 SyncNotifierFactory
factory(
74 base::WeakPtr
<sync_notifier::InvalidationStateTracker
>());
75 scoped_ptr
<SyncNotifier
> notifier(factory
.CreateSyncNotifier());
76 #if defined(OS_ANDROID)
77 ASSERT_FALSE(notifier
.get());
79 ASSERT_TRUE(notifier
.get());
80 notifier
->AddObserver(&mock_observer_
);
81 notifier
->RemoveObserver(&mock_observer_
);
86 } // namespace sync_notifier