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

Side by Side Diff: chrome/browser/sync/glue/bridged_invalidator_unittest.cc

Issue 10875064: Rename SyncNotifier->Invalidator and SyncNotifierObserver->InvalidationHandler. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Merge to ToT for landing Created 8 years, 3 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/glue/bridged_sync_notifier.h" 5 #include "chrome/browser/sync/glue/bridged_invalidator.h"
6 6
7 #include <string> 7 #include <string>
8 8
9 #include "base/compiler_specific.h" 9 #include "base/compiler_specific.h"
10 #include "base/message_loop.h" 10 #include "base/message_loop.h"
11 #include "base/threading/thread.h" 11 #include "base/threading/thread.h"
12 #include "chrome/browser/sync/glue/chrome_sync_notification_bridge.h" 12 #include "chrome/browser/sync/glue/chrome_sync_notification_bridge.h"
13 #include "chrome/test/base/profile_mock.h" 13 #include "chrome/test/base/profile_mock.h"
14 #include "content/public/test/test_browser_thread.h" 14 #include "content/public/test/test_browser_thread.h"
15 #include "sync/internal_api/public/base/model_type.h" 15 #include "sync/internal_api/public/base/model_type.h"
16 #include "sync/internal_api/public/base/model_type_test_util.h" 16 #include "sync/internal_api/public/base/model_type_test_util.h"
17 #include "sync/notifier/fake_sync_notifier.h" 17 #include "sync/notifier/fake_invalidation_handler.h"
18 #include "sync/notifier/fake_sync_notifier_observer.h" 18 #include "sync/notifier/fake_invalidator.h"
19 #include "sync/notifier/sync_notifier.h" 19 #include "sync/notifier/invalidator.h"
20 #include "testing/gmock/include/gmock/gmock.h" 20 #include "testing/gmock/include/gmock/gmock.h"
21 #include "testing/gtest/include/gtest/gtest.h" 21 #include "testing/gtest/include/gtest/gtest.h"
22 22
23 namespace browser_sync { 23 namespace browser_sync {
24 namespace { 24 namespace {
25 25
26 using ::testing::NiceMock; 26 using ::testing::NiceMock;
27 using ::testing::StrictMock; 27 using ::testing::StrictMock;
28 using content::BrowserThread; 28 using content::BrowserThread;
29 using syncer::HasModelTypes; 29 using syncer::HasModelTypes;
30 30
31 class MockChromeSyncNotificationBridge : public ChromeSyncNotificationBridge { 31 class MockChromeSyncNotificationBridge : public ChromeSyncNotificationBridge {
32 public: 32 public:
33 MockChromeSyncNotificationBridge( 33 MockChromeSyncNotificationBridge(
34 const Profile* profile, 34 const Profile* profile,
35 const scoped_refptr<base::SequencedTaskRunner>& sync_task_runner) 35 const scoped_refptr<base::SequencedTaskRunner>& sync_task_runner)
36 : ChromeSyncNotificationBridge(profile, sync_task_runner) {} 36 : ChromeSyncNotificationBridge(profile, sync_task_runner) {}
37 virtual ~MockChromeSyncNotificationBridge() {} 37 virtual ~MockChromeSyncNotificationBridge() {}
38 38
39 MOCK_METHOD1(RegisterHandler, void(syncer::SyncNotifierObserver*)); 39 MOCK_METHOD1(RegisterHandler, void(syncer::InvalidationHandler*));
40 MOCK_METHOD2(UpdateRegisteredIds, 40 MOCK_METHOD2(UpdateRegisteredIds,
41 void(syncer::SyncNotifierObserver*, 41 void(syncer::InvalidationHandler*,
42 const syncer::ObjectIdSet&)); 42 const syncer::ObjectIdSet&));
43 MOCK_METHOD1(UnregisterHandler, void(syncer::SyncNotifierObserver*)); 43 MOCK_METHOD1(UnregisterHandler, void(syncer::InvalidationHandler*));
44 }; 44 };
45 45
46 // All tests just verify that each call is passed through to the delegate, with 46 // All tests just verify that each call is passed through to the delegate, with
47 // the exception of RegisterHandler, UnregisterHandler, and 47 // the exception of RegisterHandler, UnregisterHandler, and
48 // UpdateRegisteredIds, which also verifies the call is forwarded to the 48 // UpdateRegisteredIds, which also verifies the call is forwarded to the
49 // bridge. 49 // bridge.
50 class BridgedSyncNotifierTest : public testing::Test { 50 class BridgedInvalidatorTest : public testing::Test {
51 public: 51 public:
52 BridgedSyncNotifierTest() 52 BridgedInvalidatorTest()
53 : ui_thread_(BrowserThread::UI, &ui_loop_), 53 : ui_thread_(BrowserThread::UI, &ui_loop_),
54 mock_bridge_(&mock_profile_, ui_loop_.message_loop_proxy()), 54 mock_bridge_(&mock_profile_, ui_loop_.message_loop_proxy()),
55 // Owned by bridged_notifier_. 55 // Owned by bridged_invalidator_.
56 fake_delegate_(new syncer::FakeSyncNotifier()), 56 fake_delegate_(new syncer::FakeInvalidator()),
57 bridged_notifier_(&mock_bridge_, fake_delegate_) {} 57 bridged_invalidator_(&mock_bridge_, fake_delegate_) {}
58 virtual ~BridgedSyncNotifierTest() {} 58 virtual ~BridgedInvalidatorTest() {}
59 59
60 protected: 60 protected:
61 MessageLoop ui_loop_; 61 MessageLoop ui_loop_;
62 content::TestBrowserThread ui_thread_; 62 content::TestBrowserThread ui_thread_;
63 NiceMock<ProfileMock> mock_profile_; 63 NiceMock<ProfileMock> mock_profile_;
64 StrictMock<MockChromeSyncNotificationBridge> mock_bridge_; 64 StrictMock<MockChromeSyncNotificationBridge> mock_bridge_;
65 syncer::FakeSyncNotifier* fake_delegate_; 65 syncer::FakeInvalidator* fake_delegate_;
66 BridgedSyncNotifier bridged_notifier_; 66 BridgedInvalidator bridged_invalidator_;
67 }; 67 };
68 68
69 TEST_F(BridgedSyncNotifierTest, RegisterHandler) { 69 TEST_F(BridgedInvalidatorTest, RegisterHandler) {
70 const syncer::ObjectIdSet& ids = 70 const syncer::ObjectIdSet& ids =
71 syncer::ModelTypeSetToObjectIdSet( 71 syncer::ModelTypeSetToObjectIdSet(
72 syncer::ModelTypeSet(syncer::APPS, syncer::PREFERENCES)); 72 syncer::ModelTypeSet(syncer::APPS, syncer::PREFERENCES));
73 73
74 syncer::FakeSyncNotifierObserver observer; 74 syncer::FakeInvalidationHandler handler;
75 EXPECT_CALL(mock_bridge_, RegisterHandler(&observer)); 75 EXPECT_CALL(mock_bridge_, RegisterHandler(&handler));
76 EXPECT_CALL(mock_bridge_, UpdateRegisteredIds(&observer, ids)); 76 EXPECT_CALL(mock_bridge_, UpdateRegisteredIds(&handler, ids));
77 EXPECT_CALL(mock_bridge_, UnregisterHandler(&observer)); 77 EXPECT_CALL(mock_bridge_, UnregisterHandler(&handler));
78 78
79 bridged_notifier_.RegisterHandler(&observer); 79 bridged_invalidator_.RegisterHandler(&handler);
80 EXPECT_TRUE(fake_delegate_->IsHandlerRegistered(&observer)); 80 EXPECT_TRUE(fake_delegate_->IsHandlerRegistered(&handler));
81 81
82 bridged_notifier_.UpdateRegisteredIds(&observer, ids); 82 bridged_invalidator_.UpdateRegisteredIds(&handler, ids);
83 EXPECT_EQ(ids, fake_delegate_->GetRegisteredIds(&observer)); 83 EXPECT_EQ(ids, fake_delegate_->GetRegisteredIds(&handler));
84 84
85 bridged_notifier_.UnregisterHandler(&observer); 85 bridged_invalidator_.UnregisterHandler(&handler);
86 EXPECT_FALSE(fake_delegate_->IsHandlerRegistered(&observer)); 86 EXPECT_FALSE(fake_delegate_->IsHandlerRegistered(&handler));
87 } 87 }
88 88
89 TEST_F(BridgedSyncNotifierTest, SetUniqueId) { 89 TEST_F(BridgedInvalidatorTest, SetUniqueId) {
90 const std::string& unique_id = "unique id"; 90 const std::string& unique_id = "unique id";
91 bridged_notifier_.SetUniqueId(unique_id); 91 bridged_invalidator_.SetUniqueId(unique_id);
92 EXPECT_EQ(unique_id, fake_delegate_->GetUniqueId()); 92 EXPECT_EQ(unique_id, fake_delegate_->GetUniqueId());
93 } 93 }
94 94
95 TEST_F(BridgedSyncNotifierTest, SetStateDeprecated) { 95 TEST_F(BridgedInvalidatorTest, SetStateDeprecated) {
96 const std::string& state = "state"; 96 const std::string& state = "state";
97 bridged_notifier_.SetStateDeprecated(state); 97 bridged_invalidator_.SetStateDeprecated(state);
98 EXPECT_EQ(state, fake_delegate_->GetStateDeprecated()); 98 EXPECT_EQ(state, fake_delegate_->GetStateDeprecated());
99 } 99 }
100 100
101 TEST_F(BridgedSyncNotifierTest, UpdateCredentials) { 101 TEST_F(BridgedInvalidatorTest, UpdateCredentials) {
102 const std::string& email = "email"; 102 const std::string& email = "email";
103 const std::string& token = "token"; 103 const std::string& token = "token";
104 bridged_notifier_.UpdateCredentials(email, token); 104 bridged_invalidator_.UpdateCredentials(email, token);
105 EXPECT_EQ(email, fake_delegate_->GetCredentialsEmail()); 105 EXPECT_EQ(email, fake_delegate_->GetCredentialsEmail());
106 EXPECT_EQ(token, fake_delegate_->GetCredentialsToken()); 106 EXPECT_EQ(token, fake_delegate_->GetCredentialsToken());
107 } 107 }
108 108
109 TEST_F(BridgedSyncNotifierTest, SendNotification) { 109 TEST_F(BridgedInvalidatorTest, SendNotification) {
110 const syncer::ModelTypeSet changed_types( 110 const syncer::ModelTypeSet changed_types(
111 syncer::SESSIONS, syncer::EXTENSIONS); 111 syncer::SESSIONS, syncer::EXTENSIONS);
112 bridged_notifier_.SendNotification(changed_types); 112 bridged_invalidator_.SendNotification(changed_types);
113 EXPECT_TRUE(fake_delegate_->GetLastChangedTypes().Equals(changed_types)); 113 EXPECT_TRUE(fake_delegate_->GetLastChangedTypes().Equals(changed_types));
114 } 114 }
115 115
116 } // namespace 116 } // namespace
117 } // namespace browser_sync 117 } // namespace browser_sync
OLDNEW
« no previous file with comments | « chrome/browser/sync/glue/bridged_invalidator.cc ('k') | chrome/browser/sync/glue/bridged_sync_notifier.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698