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

Side by Side Diff: sync/notifier/non_blocking_invalidation_notifier_unittest.cc

Issue 10824161: [Sync] Avoid unregistering object IDs on shutdown (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Remove now-unneeded param Created 8 years, 4 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 "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/types.pb.h" 11 #include "google/cacheinvalidation/types.pb.h"
12 #include "jingle/notifier/base/fake_base_task.h" 12 #include "jingle/notifier/base/fake_base_task.h"
13 #include "net/url_request/url_request_test_util.h" 13 #include "net/url_request/url_request_test_util.h"
14 #include "sync/internal_api/public/base/model_type.h" 14 #include "sync/internal_api/public/base/model_type.h"
15 #include "sync/internal_api/public/base/model_type_payload_map.h" 15 #include "sync/internal_api/public/base/model_type_payload_map.h"
16 #include "sync/internal_api/public/util/weak_handle.h" 16 #include "sync/internal_api/public/util/weak_handle.h"
17 #include "sync/notifier/invalidation_state_tracker.h" 17 #include "sync/notifier/invalidation_state_tracker.h"
18 #include "sync/notifier/mock_sync_notifier_observer.h" 18 #include "sync/notifier/mock_sync_notifier_observer.h"
19 #include "testing/gmock/include/gmock/gmock.h" 19 #include "testing/gmock/include/gmock/gmock.h"
20 #include "testing/gtest/include/gtest/gtest.h" 20 #include "testing/gtest/include/gtest/gtest.h"
21 21
22 namespace syncer { 22 namespace syncer {
23 23
24 namespace { 24 namespace {
25 25
26 using ::testing::InSequence; 26 using ::testing::InSequence;
27 using ::testing::StrictMock; 27 using ::testing::StrictMock;
28 28
29 const char kHandlerName[] = "MockObserver";
30
29 class NonBlockingInvalidationNotifierTest : public testing::Test { 31 class NonBlockingInvalidationNotifierTest : public testing::Test {
30 public: 32 public:
31 NonBlockingInvalidationNotifierTest() : io_thread_("Test IO thread") {} 33 NonBlockingInvalidationNotifierTest() : io_thread_("Test IO thread") {}
32 34
33 protected: 35 protected:
34 virtual void SetUp() { 36 virtual void SetUp() {
35 base::Thread::Options options; 37 base::Thread::Options options;
36 options.message_loop_type = MessageLoop::TYPE_IO; 38 options.message_loop_type = MessageLoop::TYPE_IO;
37 io_thread_.StartWithOptions(options); 39 io_thread_.StartWithOptions(options);
38 request_context_getter_ = 40 request_context_getter_ =
39 new TestURLRequestContextGetter(io_thread_.message_loop_proxy()); 41 new TestURLRequestContextGetter(io_thread_.message_loop_proxy());
40 notifier::NotifierOptions notifier_options; 42 notifier::NotifierOptions notifier_options;
41 notifier_options.request_context_getter = request_context_getter_; 43 notifier_options.request_context_getter = request_context_getter_;
42 invalidation_notifier_.reset( 44 invalidation_notifier_.reset(
43 new NonBlockingInvalidationNotifier( 45 new NonBlockingInvalidationNotifier(
44 notifier_options, 46 notifier_options,
45 InvalidationVersionMap(), 47 InvalidationVersionMap(),
46 std::string(), // initial_invalidation_state 48 std::string(), // initial_invalidation_state
47 MakeWeakHandle(base::WeakPtr<InvalidationStateTracker>()), 49 MakeWeakHandle(base::WeakPtr<InvalidationStateTracker>()),
48 "fake_client_info")); 50 "fake_client_info"));
49 } 51 }
50 52
51 virtual void TearDown() { 53 virtual void TearDown() {
52 invalidation_notifier_->UpdateRegisteredIds(&mock_observer_, ObjectIdSet()); 54 invalidation_notifier_->SetHandler(kHandlerName, NULL);
53 invalidation_notifier_.reset(); 55 invalidation_notifier_.reset();
54 request_context_getter_ = NULL; 56 request_context_getter_ = NULL;
55 io_thread_.Stop(); 57 io_thread_.Stop();
56 ui_loop_.RunAllPending(); 58 ui_loop_.RunAllPending();
57 } 59 }
58 60
59 MessageLoop ui_loop_; 61 MessageLoop ui_loop_;
60 base::Thread io_thread_; 62 base::Thread io_thread_;
61 scoped_refptr<net::URLRequestContextGetter> request_context_getter_; 63 scoped_refptr<net::URLRequestContextGetter> request_context_getter_;
62 scoped_ptr<NonBlockingInvalidationNotifier> invalidation_notifier_; 64 scoped_ptr<NonBlockingInvalidationNotifier> invalidation_notifier_;
63 StrictMock<MockSyncNotifierObserver> mock_observer_; 65 StrictMock<MockSyncNotifierObserver> mock_observer_;
64 notifier::FakeBaseTask fake_base_task_; 66 notifier::FakeBaseTask fake_base_task_;
65 }; 67 };
66 68
69 // TODO(akalin): Add real unit tests (http://crbug.com/140410).
70
67 TEST_F(NonBlockingInvalidationNotifierTest, Basic) { 71 TEST_F(NonBlockingInvalidationNotifierTest, Basic) {
68 InSequence dummy; 72 InSequence dummy;
69 73
70 ModelTypeSet models(PREFERENCES, BOOKMARKS, AUTOFILL); 74 const ModelTypeSet models(PREFERENCES, BOOKMARKS, AUTOFILL);
71 invalidation_notifier_->UpdateRegisteredIds(
72 &mock_observer_, ModelTypeSetToObjectIdSet(models));
73
74 const ModelTypePayloadMap& type_payloads = 75 const ModelTypePayloadMap& type_payloads =
75 ModelTypePayloadMapFromEnumSet(models, "payload"); 76 ModelTypePayloadMapFromEnumSet(models, "payload");
76 EXPECT_CALL(mock_observer_, OnNotificationsEnabled()); 77 EXPECT_CALL(mock_observer_, OnNotificationsEnabled());
77 EXPECT_CALL(mock_observer_, OnIncomingNotification( 78 EXPECT_CALL(mock_observer_, OnIncomingNotification(
78 ModelTypePayloadMapToObjectIdPayloadMap(type_payloads), 79 ModelTypePayloadMapToObjectIdPayloadMap(type_payloads),
79 REMOTE_NOTIFICATION)); 80 REMOTE_NOTIFICATION));
80 EXPECT_CALL(mock_observer_, 81 EXPECT_CALL(mock_observer_,
81 OnNotificationsDisabled(TRANSIENT_NOTIFICATION_ERROR)); 82 OnNotificationsDisabled(TRANSIENT_NOTIFICATION_ERROR));
82 EXPECT_CALL(mock_observer_, 83 EXPECT_CALL(mock_observer_,
83 OnNotificationsDisabled(NOTIFICATION_CREDENTIALS_REJECTED)); 84 OnNotificationsDisabled(NOTIFICATION_CREDENTIALS_REJECTED));
84 85
86 invalidation_notifier_->SetHandler(kHandlerName, &mock_observer_);
87
88 invalidation_notifier_->UpdateRegisteredIds(
89 kHandlerName, ModelTypeSetToObjectIdSet(models));
90
85 invalidation_notifier_->SetStateDeprecated("fake_state"); 91 invalidation_notifier_->SetStateDeprecated("fake_state");
86 invalidation_notifier_->SetUniqueId("fake_id"); 92 invalidation_notifier_->SetUniqueId("fake_id");
87 invalidation_notifier_->UpdateCredentials("foo@bar.com", "fake_token"); 93 invalidation_notifier_->UpdateCredentials("foo@bar.com", "fake_token");
88 94
89 invalidation_notifier_->OnNotificationsEnabled(); 95 invalidation_notifier_->OnNotificationsEnabled();
90 invalidation_notifier_->OnIncomingNotification( 96 invalidation_notifier_->OnIncomingNotification(
91 ModelTypePayloadMapToObjectIdPayloadMap(type_payloads), 97 ModelTypePayloadMapToObjectIdPayloadMap(type_payloads),
92 REMOTE_NOTIFICATION); 98 REMOTE_NOTIFICATION);
93 invalidation_notifier_->OnNotificationsDisabled( 99 invalidation_notifier_->OnNotificationsDisabled(
94 TRANSIENT_NOTIFICATION_ERROR); 100 TRANSIENT_NOTIFICATION_ERROR);
95 invalidation_notifier_->OnNotificationsDisabled( 101 invalidation_notifier_->OnNotificationsDisabled(
96 NOTIFICATION_CREDENTIALS_REJECTED); 102 NOTIFICATION_CREDENTIALS_REJECTED);
97 103
98 ui_loop_.RunAllPending(); 104 ui_loop_.RunAllPending();
99 } 105 }
100 106
101 } // namespace 107 } // namespace
102 108
103 } // namespace syncer 109 } // namespace syncer
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698