Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(288)

Side by Side Diff: chrome/browser/sync/notifier/sync_notifier_factory_unittest.cc

Issue 9512005: [Sync] Move BridgedSyncNotifier and ChromeSyncNotificationBridge to glue/ (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Sync to head Created 8 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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 "chrome/browser/sync/notifier/sync_notifier_factory.h" 5 #include "chrome/browser/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"
11 #include "base/memory/weak_ptr.h" 11 #include "base/memory/weak_ptr.h"
12 #include "base/message_loop.h" 12 #include "base/message_loop.h"
13 #include "base/threading/thread.h" 13 #include "base/threading/thread.h"
14 #include "chrome/browser/sync/notifier/invalidation_version_tracker.h" 14 #include "chrome/browser/sync/notifier/invalidation_version_tracker.h"
15 #include "chrome/browser/sync/notifier/mock_sync_notifier_observer.h" 15 #include "chrome/browser/sync/notifier/mock_sync_notifier_observer.h"
16 #include "chrome/browser/sync/notifier/sync_notifier.h" 16 #include "chrome/browser/sync/notifier/sync_notifier.h"
17 #include "chrome/browser/sync/syncable/model_type.h" 17 #include "chrome/browser/sync/syncable/model_type.h"
18 #include "chrome/browser/sync/syncable/model_type_payload_map.h" 18 #include "chrome/browser/sync/syncable/model_type_payload_map.h"
19 #include "chrome/common/chrome_notification_types.h"
20 #include "chrome/common/chrome_switches.h" 19 #include "chrome/common/chrome_switches.h"
21 #include "chrome/test/base/profile_mock.h"
22 #include "chrome/test/base/test_url_request_context_getter.h" 20 #include "chrome/test/base/test_url_request_context_getter.h"
23 #include "content/public/browser/notification_service.h"
24 #include "content/public/browser/notification_details.h"
25 #include "content/test/test_browser_thread.h" 21 #include "content/test/test_browser_thread.h"
26 #include "testing/gmock/include/gmock/gmock.h" 22 #include "testing/gmock/include/gmock/gmock.h"
27 #include "testing/gtest/include/gtest/gtest.h" 23 #include "testing/gtest/include/gtest/gtest.h"
28 24
29 namespace sync_notifier { 25 namespace sync_notifier {
30 namespace { 26 namespace {
31 27
32 using ::testing::Mock; 28 using ::testing::Mock;
33 using ::testing::NiceMock; 29 using ::testing::NiceMock;
34 using ::testing::StrictMock; 30 using ::testing::StrictMock;
35 using content::BrowserThread; 31 using content::BrowserThread;
36 32
37 class SyncNotifierFactoryTest : public testing::Test { 33 class SyncNotifierFactoryTest : public testing::Test {
38 public: 34 protected:
39 // TODO(zea): switch to using real io_thread instead of shared message loop.
40 SyncNotifierFactoryTest() 35 SyncNotifierFactoryTest()
41 : ui_thread_(BrowserThread::UI, &message_loop_), 36 : ui_thread_(BrowserThread::UI, &message_loop_),
42 io_thread_(BrowserThread::IO, &message_loop_), 37 io_thread_(BrowserThread::IO, &message_loop_),
43 command_line_(CommandLine::NO_PROGRAM) {} 38 command_line_(CommandLine::NO_PROGRAM) {}
44 virtual ~SyncNotifierFactoryTest() {} 39 virtual ~SyncNotifierFactoryTest() {}
45 40
46 protected:
47 virtual void SetUp() OVERRIDE { 41 virtual void SetUp() OVERRIDE {
48 request_context_getter_ = new TestURLRequestContextGetter; 42 request_context_getter_ = new TestURLRequestContextGetter;
49 factory_.reset(new SyncNotifierFactory( 43 factory_.reset(new SyncNotifierFactory(
50 &mock_profile_,
51 "fake_client_info", 44 "fake_client_info",
52 request_context_getter_, 45 request_context_getter_,
53 base::WeakPtr<sync_notifier::InvalidationVersionTracker>(), 46 base::WeakPtr<sync_notifier::InvalidationVersionTracker>(),
54 command_line_)); 47 command_line_));
55 message_loop_.RunAllPending(); 48 message_loop_.RunAllPending();
56 } 49 }
57 50
58 virtual void TearDown() OVERRIDE { 51 virtual void TearDown() OVERRIDE {
59 Mock::VerifyAndClearExpectations(&mock_profile_);
60 Mock::VerifyAndClearExpectations(&mock_observer_); 52 Mock::VerifyAndClearExpectations(&mock_observer_);
61 request_context_getter_ = NULL; 53 request_context_getter_ = NULL;
62 message_loop_.RunAllPending(); 54 message_loop_.RunAllPending();
63 command_line_ = CommandLine(CommandLine::NO_PROGRAM); 55 command_line_ = CommandLine(CommandLine::NO_PROGRAM);
64 } 56 }
65 57
66 void TriggerRefreshNotification() {
67 const syncable::ModelType type = syncable::SESSIONS;
68 content::NotificationService::current()->Notify(
69 chrome::NOTIFICATION_SYNC_REFRESH,
70 content::Source<Profile>(&mock_profile_),
71 content::Details<const syncable::ModelType>(&type));
72 }
73
74 MessageLoop message_loop_; 58 MessageLoop message_loop_;
75 content::TestBrowserThread ui_thread_; 59 content::TestBrowserThread ui_thread_;
76 content::TestBrowserThread io_thread_; 60 content::TestBrowserThread io_thread_;
77 NiceMock<ProfileMock> mock_profile_;
78 scoped_refptr<net::URLRequestContextGetter> request_context_getter_; 61 scoped_refptr<net::URLRequestContextGetter> request_context_getter_;
79 StrictMock<MockSyncNotifierObserver> mock_observer_; 62 StrictMock<MockSyncNotifierObserver> mock_observer_;
80 scoped_ptr<SyncNotifierFactory> factory_; 63 scoped_ptr<SyncNotifierFactory> factory_;
81 CommandLine command_line_; 64 CommandLine command_line_;
82 }; 65 };
83 66
84 // Test basic creation of a NonBlockingInvalidationNotifier. 67 // Test basic creation of a NonBlockingInvalidationNotifier.
85 TEST_F(SyncNotifierFactoryTest, Basic) { 68 TEST_F(SyncNotifierFactoryTest, Basic) {
86 scoped_ptr<SyncNotifier> notifier(factory_->CreateSyncNotifier()); 69 scoped_ptr<SyncNotifier> notifier(factory_->CreateSyncNotifier());
87 ASSERT_TRUE(notifier.get()); 70 ASSERT_TRUE(notifier.get());
88 notifier->AddObserver(&mock_observer_); 71 notifier->AddObserver(&mock_observer_);
89 notifier->RemoveObserver(&mock_observer_); 72 notifier->RemoveObserver(&mock_observer_);
90 } 73 }
91 74
92 // Test basic creation of a P2PNotifier. 75 // Test basic creation of a P2PNotifier.
93 TEST_F(SyncNotifierFactoryTest, Basic_P2P) { 76 TEST_F(SyncNotifierFactoryTest, Basic_P2P) {
94 command_line_.AppendSwitchASCII(switches::kSyncNotificationMethod, "p2p"); 77 command_line_.AppendSwitchASCII(switches::kSyncNotificationMethod, "p2p");
95 scoped_ptr<SyncNotifier> notifier(factory_->CreateSyncNotifier()); 78 scoped_ptr<SyncNotifier> notifier(factory_->CreateSyncNotifier());
96 ASSERT_TRUE(notifier.get()); 79 ASSERT_TRUE(notifier.get());
97 notifier->AddObserver(&mock_observer_); 80 notifier->AddObserver(&mock_observer_);
98 notifier->RemoveObserver(&mock_observer_); 81 notifier->RemoveObserver(&mock_observer_);
99 } 82 }
100 83
101 // Create a default sync notifier (NonBlockingInvalidationNotifier wrapped by a
102 // BridgedSyncNotifier) and then trigger a sync refresh notification. The
103 // observer should receive the notification as a LOCAL_NOTIFICATION.
104 TEST_F(SyncNotifierFactoryTest, ChromeSyncNotification) {
105 syncable::ModelTypePayloadMap type_payloads;
106 type_payloads[syncable::SESSIONS] = "";
107 EXPECT_CALL(mock_observer_,
108 OnIncomingNotification(type_payloads,
109 LOCAL_NOTIFICATION));
110
111 scoped_ptr<SyncNotifier> notifier(factory_->CreateSyncNotifier());
112 ASSERT_TRUE(notifier.get());
113 notifier->AddObserver(&mock_observer_);
114 TriggerRefreshNotification();
115 message_loop_.RunAllPending();
116 notifier->RemoveObserver(&mock_observer_);
117 }
118
119
120 // Create a P2P sync notifier (wrapped by a BridgedSyncNotifier)
121 // and then trigger a sync refresh notification. The observer should receive
122 // the notification as a LOCAL_NOTIFICATION.
123 TEST_F(SyncNotifierFactoryTest, ChromeSyncNotification_P2P) {
124 syncable::ModelTypePayloadMap type_payloads;
125 type_payloads[syncable::SESSIONS] = "";
126 EXPECT_CALL(mock_observer_,
127 OnIncomingNotification(type_payloads,
128 LOCAL_NOTIFICATION));
129
130 command_line_.AppendSwitchASCII(switches::kSyncNotificationMethod, "p2p");
131 scoped_ptr<SyncNotifier> notifier(factory_->CreateSyncNotifier());
132 ASSERT_TRUE(notifier.get());
133 notifier->AddObserver(&mock_observer_);
134 TriggerRefreshNotification();
135 message_loop_.RunAllPending();
136 notifier->RemoveObserver(&mock_observer_);
137 }
138
139 } // namespace 84 } // namespace
140 } // namespace sync_notifier 85 } // namespace sync_notifier
OLDNEW
« no previous file with comments | « chrome/browser/sync/notifier/sync_notifier_factory.cc ('k') | chrome/browser/sync/tools/sync_listen_notifications.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698