blob: 184c030c8797ef8e7e6f4cad3dba7883487fd54c (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
|
// Copyright (c) 2012 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "sync/notifier/cache_invalidation_packet_handler.h"
#include "base/base64.h"
#include "base/memory/weak_ptr.h"
#include "base/message_loop.h"
#include "google/cacheinvalidation/deps/callback.h"
#include "google/cacheinvalidation/include/system-resources.h"
#include "google/cacheinvalidation/v2/client_gateway.pb.h"
#include "jingle/notifier/base/fake_base_task.h"
#include "jingle/notifier/listener/notification_defines.h"
#include "talk/base/task.h"
#include "talk/xmpp/asyncsocket.h"
#include "testing/gtest/include/gtest/gtest.h"
namespace sync_notifier {
class MockMessageCallback {
public:
void StoreMessage(const std::string& message) {
last_message = message;
}
std::string last_message;
};
class CacheInvalidationPacketHandlerTest : public testing::Test {
public:
virtual ~CacheInvalidationPacketHandlerTest() {}
notifier::Notification MakeNotification(const std::string& data) {
notifier::Notification notification;
notification.channel = "tango_raw";
notification.data = data;
return notification;
}
};
TEST_F(CacheInvalidationPacketHandlerTest, Basic) {
MessageLoop message_loop;
notifier::FakeBaseTask fake_base_task;
std::string last_message;
MockMessageCallback callback;
invalidation::MessageCallback* mock_message_callback =
invalidation::NewPermanentCallback(
&callback, &MockMessageCallback::StoreMessage);
const char kInboundMessage[] = "non-bogus";
ipc::invalidation::ClientGatewayMessage envelope;
envelope.set_network_message(kInboundMessage);
std::string serialized;
envelope.SerializeToString(&serialized);
{
CacheInvalidationPacketHandler handler(fake_base_task.AsWeakPtr());
handler.SetMessageReceiver(mock_message_callback);
// Take care of any tasks posted by the constructor.
message_loop.RunAllPending();
{
handler.OnNotificationReceived(MakeNotification("bogus"));
handler.OnNotificationReceived(MakeNotification(serialized));
}
// Take care of any tasks posted by HandleOutboundPacket().
message_loop.RunAllPending();
EXPECT_EQ(callback.last_message, kInboundMessage);
}
}
} // namespace sync_notifier
|