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/non_blocking_invalidation_notifier.h" | 5 #include "sync/notifier/non_blocking_invalidation_notifier.h" |
6 | 6 |
7 #include "base/memory/ref_counted.h" | 7 #include "base/memory/ref_counted.h" |
8 #include "base/memory/scoped_ptr.h" | 8 #include "base/memory/scoped_ptr.h" |
9 #include "base/message_loop.h" | 9 #include "base/message_loop.h" |
10 #include "base/threading/thread.h" | 10 #include "base/threading/thread.h" |
| 11 #include "google/cacheinvalidation/v2/types.pb.h" |
11 #include "jingle/notifier/base/fake_base_task.h" | 12 #include "jingle/notifier/base/fake_base_task.h" |
12 #include "net/url_request/url_request_test_util.h" | 13 #include "net/url_request/url_request_test_util.h" |
13 #include "sync/internal_api/public/base/model_type.h" | 14 #include "sync/internal_api/public/base/model_type.h" |
14 #include "sync/internal_api/public/base/model_type_payload_map.h" | 15 #include "sync/internal_api/public/base/model_type_payload_map.h" |
15 #include "sync/internal_api/public/util/weak_handle.h" | 16 #include "sync/internal_api/public/util/weak_handle.h" |
16 #include "sync/notifier/invalidation_state_tracker.h" | 17 #include "sync/notifier/invalidation_state_tracker.h" |
17 #include "sync/notifier/mock_sync_notifier_observer.h" | 18 #include "sync/notifier/mock_sync_notifier_observer.h" |
18 #include "testing/gmock/include/gmock/gmock.h" | 19 #include "testing/gmock/include/gmock/gmock.h" |
19 #include "testing/gtest/include/gtest/gtest.h" | 20 #include "testing/gtest/include/gtest/gtest.h" |
20 | 21 |
(...skipping 18 matching lines...) Expand all Loading... |
39 notifier::NotifierOptions notifier_options; | 40 notifier::NotifierOptions notifier_options; |
40 notifier_options.request_context_getter = request_context_getter_; | 41 notifier_options.request_context_getter = request_context_getter_; |
41 invalidation_notifier_.reset( | 42 invalidation_notifier_.reset( |
42 new NonBlockingInvalidationNotifier( | 43 new NonBlockingInvalidationNotifier( |
43 notifier_options, | 44 notifier_options, |
44 InvalidationVersionMap(), | 45 InvalidationVersionMap(), |
45 std::string(), // initial_invalidation_state | 46 std::string(), // initial_invalidation_state |
46 syncer::MakeWeakHandle( | 47 syncer::MakeWeakHandle( |
47 base::WeakPtr<syncer::InvalidationStateTracker>()), | 48 base::WeakPtr<syncer::InvalidationStateTracker>()), |
48 "fake_client_info")); | 49 "fake_client_info")); |
49 invalidation_notifier_->AddObserver(&mock_observer_); | |
50 } | 50 } |
51 | 51 |
52 virtual void TearDown() { | 52 virtual void TearDown() { |
53 invalidation_notifier_->RemoveObserver(&mock_observer_); | 53 invalidation_notifier_->UpdateRegisteredIds(&mock_observer_, ObjectIdSet()); |
54 invalidation_notifier_.reset(); | 54 invalidation_notifier_.reset(); |
55 request_context_getter_ = NULL; | 55 request_context_getter_ = NULL; |
56 io_thread_.Stop(); | 56 io_thread_.Stop(); |
57 ui_loop_.RunAllPending(); | 57 ui_loop_.RunAllPending(); |
58 } | 58 } |
59 | 59 |
60 MessageLoop ui_loop_; | 60 MessageLoop ui_loop_; |
61 base::Thread io_thread_; | 61 base::Thread io_thread_; |
62 scoped_refptr<net::URLRequestContextGetter> request_context_getter_; | 62 scoped_refptr<net::URLRequestContextGetter> request_context_getter_; |
63 scoped_ptr<NonBlockingInvalidationNotifier> invalidation_notifier_; | 63 scoped_ptr<NonBlockingInvalidationNotifier> invalidation_notifier_; |
64 StrictMock<MockSyncNotifierObserver> mock_observer_; | 64 StrictMock<MockSyncNotifierObserver> mock_observer_; |
65 notifier::FakeBaseTask fake_base_task_; | 65 notifier::FakeBaseTask fake_base_task_; |
66 }; | 66 }; |
67 | 67 |
68 TEST_F(NonBlockingInvalidationNotifierTest, Basic) { | 68 TEST_F(NonBlockingInvalidationNotifierTest, Basic) { |
69 InSequence dummy; | 69 InSequence dummy; |
70 | 70 |
71 syncer::ModelTypePayloadMap type_payloads; | 71 ModelTypeSet models(syncer::PREFERENCES, |
72 type_payloads[syncer::PREFERENCES] = "payload"; | 72 syncer::BOOKMARKS, |
73 type_payloads[syncer::BOOKMARKS] = ""; | 73 syncer::AUTOFILL); |
74 type_payloads[syncer::AUTOFILL] = ""; | 74 invalidation_notifier_->UpdateRegisteredIds( |
| 75 &mock_observer_, ModelTypeSetToObjectIdSet(models)); |
75 | 76 |
| 77 ModelTypePayloadMap type_payloads = |
| 78 ModelTypePayloadMapFromEnumSet(models, "payload"); |
76 EXPECT_CALL(mock_observer_, OnNotificationsEnabled()); | 79 EXPECT_CALL(mock_observer_, OnNotificationsEnabled()); |
77 EXPECT_CALL(mock_observer_, | 80 EXPECT_CALL(mock_observer_, OnIncomingNotification( |
78 OnIncomingNotification(type_payloads, | 81 ModelTypePayloadMapToObjectIdPayloadMap(type_payloads), |
79 REMOTE_NOTIFICATION)); | 82 REMOTE_NOTIFICATION)); |
80 EXPECT_CALL(mock_observer_, | 83 EXPECT_CALL(mock_observer_, |
81 OnNotificationsDisabled(TRANSIENT_NOTIFICATION_ERROR)); | 84 OnNotificationsDisabled(TRANSIENT_NOTIFICATION_ERROR)); |
82 EXPECT_CALL(mock_observer_, | 85 EXPECT_CALL(mock_observer_, |
83 OnNotificationsDisabled(NOTIFICATION_CREDENTIALS_REJECTED)); | 86 OnNotificationsDisabled(NOTIFICATION_CREDENTIALS_REJECTED)); |
84 | 87 |
85 invalidation_notifier_->SetStateDeprecated("fake_state"); | 88 invalidation_notifier_->SetStateDeprecated("fake_state"); |
86 invalidation_notifier_->SetUniqueId("fake_id"); | 89 invalidation_notifier_->SetUniqueId("fake_id"); |
87 invalidation_notifier_->UpdateCredentials("foo@bar.com", "fake_token"); | 90 invalidation_notifier_->UpdateCredentials("foo@bar.com", "fake_token"); |
88 | 91 |
89 invalidation_notifier_->OnNotificationsEnabled(); | 92 invalidation_notifier_->OnNotificationsEnabled(); |
90 invalidation_notifier_->OnIncomingNotification(type_payloads, | 93 invalidation_notifier_->OnIncomingNotification( |
91 REMOTE_NOTIFICATION); | 94 ModelTypePayloadMapToObjectIdPayloadMap(type_payloads), |
| 95 REMOTE_NOTIFICATION); |
92 invalidation_notifier_->OnNotificationsDisabled( | 96 invalidation_notifier_->OnNotificationsDisabled( |
93 TRANSIENT_NOTIFICATION_ERROR); | 97 TRANSIENT_NOTIFICATION_ERROR); |
94 invalidation_notifier_->OnNotificationsDisabled( | 98 invalidation_notifier_->OnNotificationsDisabled( |
95 NOTIFICATION_CREDENTIALS_REJECTED); | 99 NOTIFICATION_CREDENTIALS_REJECTED); |
96 | 100 |
97 ui_loop_.RunAllPending(); | 101 ui_loop_.RunAllPending(); |
98 } | 102 } |
99 | 103 |
100 } // namespace | 104 } // namespace |
101 | 105 |
102 } // namespace syncer | 106 } // namespace syncer |
OLD | NEW |