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

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

Issue 10436013: [Sync] Make InvalidationNotifier use PushClient (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Sync to head Created 8 years, 7 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
(Empty)
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
3 // found in the LICENSE file.
4
5 #include "sync/notifier/cache_invalidation_packet_handler.h"
6
7 #include "base/base64.h"
8 #include "base/memory/weak_ptr.h"
9 #include "base/message_loop.h"
10 #include "google/cacheinvalidation/deps/callback.h"
11 #include "google/cacheinvalidation/include/system-resources.h"
12 #include "google/cacheinvalidation/v2/client_gateway.pb.h"
13 #include "jingle/notifier/base/fake_base_task.h"
14 #include "jingle/notifier/listener/notification_defines.h"
15 #include "talk/base/task.h"
16 #include "talk/xmpp/asyncsocket.h"
17 #include "testing/gtest/include/gtest/gtest.h"
18
19 namespace sync_notifier {
20
21 class MockMessageCallback {
22 public:
23 void StoreMessage(const std::string& message) {
24 last_message = message;
25 }
26
27 std::string last_message;
28 };
29
30 class CacheInvalidationPacketHandlerTest : public testing::Test {
31 public:
32 virtual ~CacheInvalidationPacketHandlerTest() {}
33
34 notifier::Notification MakeNotification(const std::string& data) {
35 notifier::Notification notification;
36 notification.channel = "tango_raw";
37 notification.data = data;
38 return notification;
39 }
40 };
41
42 TEST_F(CacheInvalidationPacketHandlerTest, Basic) {
43 MessageLoop message_loop;
44
45 notifier::FakeBaseTask fake_base_task;
46
47 std::string last_message;
48 MockMessageCallback callback;
49 invalidation::MessageCallback* mock_message_callback =
50 invalidation::NewPermanentCallback(
51 &callback, &MockMessageCallback::StoreMessage);
52
53 const char kInboundMessage[] = "non-bogus";
54 ipc::invalidation::ClientGatewayMessage envelope;
55 envelope.set_network_message(kInboundMessage);
56 std::string serialized;
57 envelope.SerializeToString(&serialized);
58 {
59 CacheInvalidationPacketHandler handler(fake_base_task.AsWeakPtr());
60 handler.SetMessageReceiver(mock_message_callback);
61
62 // Take care of any tasks posted by the constructor.
63 message_loop.RunAllPending();
64
65 {
66 handler.OnNotificationReceived(MakeNotification("bogus"));
67 handler.OnNotificationReceived(MakeNotification(serialized));
68 }
69
70 // Take care of any tasks posted by HandleOutboundPacket().
71 message_loop.RunAllPending();
72
73 EXPECT_EQ(callback.last_message, kInboundMessage);
74 }
75 }
76
77 } // namespace sync_notifier
OLDNEW
« no previous file with comments | « sync/notifier/cache_invalidation_packet_handler.cc ('k') | sync/notifier/chrome_invalidation_client.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698