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

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

Issue 10702074: Refactor sync-specific parts out of SyncNotifier/SyncNotifierObserver (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: FOR_THE_HORDE Created 8 years, 5 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/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 17 matching lines...) Expand all
38 new TestURLRequestContextGetter(io_thread_.message_loop_proxy()); 39 new TestURLRequestContextGetter(io_thread_.message_loop_proxy());
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 MakeWeakHandle(base::WeakPtr<InvalidationStateTracker>()), 47 MakeWeakHandle(base::WeakPtr<InvalidationStateTracker>()),
47 "fake_client_info")); 48 "fake_client_info"));
48 invalidation_notifier_->AddObserver(&mock_observer_);
49 } 49 }
50 50
51 virtual void TearDown() { 51 virtual void TearDown() {
52 invalidation_notifier_->RemoveObserver(&mock_observer_); 52 invalidation_notifier_->UpdateRegisteredIds(&mock_observer_, ObjectIdSet());
53 invalidation_notifier_.reset(); 53 invalidation_notifier_.reset();
54 request_context_getter_ = NULL; 54 request_context_getter_ = NULL;
55 io_thread_.Stop(); 55 io_thread_.Stop();
56 ui_loop_.RunAllPending(); 56 ui_loop_.RunAllPending();
57 } 57 }
58 58
59 MessageLoop ui_loop_; 59 MessageLoop ui_loop_;
60 base::Thread io_thread_; 60 base::Thread io_thread_;
61 scoped_refptr<net::URLRequestContextGetter> request_context_getter_; 61 scoped_refptr<net::URLRequestContextGetter> request_context_getter_;
62 scoped_ptr<NonBlockingInvalidationNotifier> invalidation_notifier_; 62 scoped_ptr<NonBlockingInvalidationNotifier> invalidation_notifier_;
63 StrictMock<MockSyncNotifierObserver> mock_observer_; 63 StrictMock<MockSyncNotifierObserver> mock_observer_;
64 notifier::FakeBaseTask fake_base_task_; 64 notifier::FakeBaseTask fake_base_task_;
65 }; 65 };
66 66
67 TEST_F(NonBlockingInvalidationNotifierTest, Basic) { 67 TEST_F(NonBlockingInvalidationNotifierTest, Basic) {
68 InSequence dummy; 68 InSequence dummy;
69 69
70 ModelTypePayloadMap type_payloads; 70 ModelTypeSet models(PREFERENCES,
71 type_payloads[PREFERENCES] = "payload"; 71 BOOKMARKS,
akalin 2012/07/21 01:09:47 one line?
dcheng 2012/07/21 14:06:53 Done.
72 type_payloads[BOOKMARKS] = ""; 72 AUTOFILL);
73 type_payloads[AUTOFILL] = ""; 73 invalidation_notifier_->UpdateRegisteredIds(
74 &mock_observer_, ModelTypeSetToObjectIdSet(models));
74 75
76 ModelTypePayloadMap type_payloads =
akalin 2012/07/21 01:09:47 const ref
dcheng 2012/07/21 14:06:53 Done.
77 ModelTypePayloadMapFromEnumSet(models, "payload");
75 EXPECT_CALL(mock_observer_, OnNotificationsEnabled()); 78 EXPECT_CALL(mock_observer_, OnNotificationsEnabled());
76 EXPECT_CALL(mock_observer_, 79 EXPECT_CALL(mock_observer_, OnIncomingNotification(
77 OnIncomingNotification(type_payloads, 80 ModelTypePayloadMapToObjectIdPayloadMap(type_payloads),
78 REMOTE_NOTIFICATION)); 81 REMOTE_NOTIFICATION));
79 EXPECT_CALL(mock_observer_, 82 EXPECT_CALL(mock_observer_,
80 OnNotificationsDisabled(TRANSIENT_NOTIFICATION_ERROR)); 83 OnNotificationsDisabled(TRANSIENT_NOTIFICATION_ERROR));
81 EXPECT_CALL(mock_observer_, 84 EXPECT_CALL(mock_observer_,
82 OnNotificationsDisabled(NOTIFICATION_CREDENTIALS_REJECTED)); 85 OnNotificationsDisabled(NOTIFICATION_CREDENTIALS_REJECTED));
83 86
84 invalidation_notifier_->SetStateDeprecated("fake_state"); 87 invalidation_notifier_->SetStateDeprecated("fake_state");
85 invalidation_notifier_->SetUniqueId("fake_id"); 88 invalidation_notifier_->SetUniqueId("fake_id");
86 invalidation_notifier_->UpdateCredentials("foo@bar.com", "fake_token"); 89 invalidation_notifier_->UpdateCredentials("foo@bar.com", "fake_token");
87 90
88 invalidation_notifier_->OnNotificationsEnabled(); 91 invalidation_notifier_->OnNotificationsEnabled();
89 invalidation_notifier_->OnIncomingNotification(type_payloads, 92 invalidation_notifier_->OnIncomingNotification(
90 REMOTE_NOTIFICATION); 93 ModelTypePayloadMapToObjectIdPayloadMap(type_payloads),
94 REMOTE_NOTIFICATION);
91 invalidation_notifier_->OnNotificationsDisabled( 95 invalidation_notifier_->OnNotificationsDisabled(
92 TRANSIENT_NOTIFICATION_ERROR); 96 TRANSIENT_NOTIFICATION_ERROR);
93 invalidation_notifier_->OnNotificationsDisabled( 97 invalidation_notifier_->OnNotificationsDisabled(
94 NOTIFICATION_CREDENTIALS_REJECTED); 98 NOTIFICATION_CREDENTIALS_REJECTED);
95 99
96 ui_loop_.RunAllPending(); 100 ui_loop_.RunAllPending();
97 } 101 }
98 102
99 } // namespace 103 } // namespace
100 104
101 } // namespace syncer 105 } // namespace syncer
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698