Roll WebRTC 7546:7549.
[chromium-blink-merge.git] / jingle / notifier / base / fake_base_task.cc
blobaf4ede05b23e38a2debec980a338dd1f7a42135a
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.
5 #include "base/compiler_specific.h"
6 #include "jingle/notifier/base/fake_base_task.h"
7 #include "jingle/notifier/base/weak_xmpp_client.h"
8 #include "testing/gmock/include/gmock/gmock.h"
9 #include "webrtc/libjingle/xmpp/asyncsocket.h"
11 namespace notifier {
13 using ::testing::_;
14 using ::testing::Return;
16 class MockAsyncSocket : public buzz::AsyncSocket {
17 public:
18 virtual ~MockAsyncSocket() {}
20 MOCK_METHOD0(state, State());
21 MOCK_METHOD0(error, Error());
22 MOCK_METHOD0(GetError, int());
23 MOCK_METHOD1(Connect, bool(const rtc::SocketAddress&));
24 MOCK_METHOD3(Read, bool(char*, size_t, size_t*));
25 MOCK_METHOD2(Write, bool(const char*, size_t));
26 MOCK_METHOD0(Close, bool());
27 MOCK_METHOD1(StartTls, bool(const std::string&));
30 } // namespace notifier
32 namespace {
34 // Extends WeakXmppClient to make jid() return a full jid, as required by
35 // PushNotificationsSubscribeTask.
36 class FakeWeakXmppClient : public notifier::WeakXmppClient {
37 public:
38 explicit FakeWeakXmppClient(rtc::TaskParent* parent)
39 : notifier::WeakXmppClient(parent),
40 jid_("test@example.com/testresource") {}
42 ~FakeWeakXmppClient() override {}
44 const buzz::Jid& jid() const override { return jid_; }
46 private:
47 buzz::Jid jid_;
50 } // namespace
52 namespace notifier {
54 FakeBaseTask::FakeBaseTask() {
55 // Owned by |task_pump_|.
56 FakeWeakXmppClient* weak_xmpp_client =
57 new FakeWeakXmppClient(&task_pump_);
59 weak_xmpp_client->Start();
60 buzz::XmppClientSettings settings;
61 // Owned by |weak_xmpp_client|.
62 MockAsyncSocket* mock_async_socket = new MockAsyncSocket();
63 EXPECT_CALL(*mock_async_socket, Connect(_)).WillOnce(Return(true));
64 weak_xmpp_client->Connect(settings, "en", mock_async_socket, NULL);
65 // Initialize the XMPP client.
66 task_pump_.RunTasks();
68 base_task_ = weak_xmpp_client->AsWeakPtr();
71 FakeBaseTask::~FakeBaseTask() {}
73 base::WeakPtr<buzz::XmppTaskParentInterface> FakeBaseTask::AsWeakPtr() {
74 return base_task_;
77 } // namespace notifier