blob: 08cdcb61bfcdf147f8b74572e0ca3e538f62adf5 (
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
|
// 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 "chrome/browser/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/v2/callback.h"
#include "google/cacheinvalidation/v2/system-resources.h"
#include "jingle/notifier/base/fake_base_task.h"
#include "testing/gmock/include/gmock/gmock.h"
#include "testing/gtest/include/gtest/gtest.h"
#include "talk/base/task.h"
#include "talk/xmpp/asyncsocket.h"
namespace sync_notifier {
using ::testing::_;
using ::testing::Return;
class MockMessageCallback {
public:
void StoreMessage(const std::string& message) {
last_message = message;
}
std::string last_message;
};
class CacheInvalidationPacketHandlerTest : public testing::Test {
public:
virtual ~CacheInvalidationPacketHandlerTest() {}
};
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";
{
CacheInvalidationPacketHandler handler(fake_base_task.AsWeakPtr());
handler.SetMessageReceiver(mock_message_callback);
// Take care of any tasks posted by the constructor.
message_loop.RunAllPending();
{
handler.HandleInboundPacket("bogus");
std::string inbound_message_encoded;
EXPECT_TRUE(
base::Base64Encode(kInboundMessage, &inbound_message_encoded));
handler.HandleInboundPacket(inbound_message_encoded);
}
// Take care of any tasks posted by HandleOutboundPacket().
message_loop.RunAllPending();
EXPECT_EQ(callback.last_message, kInboundMessage);
}
}
} // namespace sync_notifier
|