diff options
author | akalin@chromium.org <akalin@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-12-08 08:35:23 +0000 |
---|---|---|
committer | akalin@chromium.org <akalin@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-12-08 08:35:23 +0000 |
commit | 7e4f13edad7e7962236d57b5bd3d080d057c3823 (patch) | |
tree | ba89df6131a43721cd3e3339feeba40dee781373 /jingle | |
parent | c4c1422594c6df6ca0de28ee3dbf727ffcf83b19 (diff) | |
download | chromium_src-7e4f13edad7e7962236d57b5bd3d080d057c3823.zip chromium_src-7e4f13edad7e7962236d57b5bd3d080d057c3823.tar.gz chromium_src-7e4f13edad7e7962236d57b5bd3d080d057c3823.tar.bz2 |
[Sync] Fixed crash on XMPP reconnection
Tied lifetime of invalidation packet callback to ChromeInvalidationClient.
Added some tests for ChromeInvalidationClient.
Created FakeBaseTask class for testing.
BUG=64652
TEST=New unittests
Review URL: http://codereview.chromium.org/5625010
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@68571 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'jingle')
-rw-r--r-- | jingle/jingle.gyp | 14 | ||||
-rw-r--r-- | jingle/notifier/base/fake_base_task.cc | 54 | ||||
-rw-r--r-- | jingle/notifier/base/fake_base_task.h | 38 |
3 files changed, 106 insertions, 0 deletions
diff --git a/jingle/jingle.gyp b/jingle/jingle.gyp index 939c9d0..61d9320 100644 --- a/jingle/jingle.gyp +++ b/jingle/jingle.gyp @@ -92,6 +92,19 @@ ], }, { + 'target_name': 'notifier_test_util', + 'type': '<(library)', + 'sources': [ + 'notifier/base/fake_base_task.cc', + 'notifier/base/fake_base_task.h', + ], + 'dependencies': [ + 'notifier', + '../base/base.gyp:base', + '../testing/gmock.gyp:gmock', + ], + }, + { 'target_name': 'notifier_unit_tests', 'type': 'executable', 'sources': [ @@ -113,6 +126,7 @@ ], 'dependencies': [ 'notifier', + 'notifier_test_util', '../base/base.gyp:base', '../base/base.gyp:test_support_base', '../net/net.gyp:net', diff --git a/jingle/notifier/base/fake_base_task.cc b/jingle/notifier/base/fake_base_task.cc new file mode 100644 index 0000000..255ae64 --- /dev/null +++ b/jingle/notifier/base/fake_base_task.cc @@ -0,0 +1,54 @@ +// Copyright (c) 2010 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. +// +// A simple wrapper around invalidation::InvalidationClient that +// handles all the startup/shutdown details and hookups. + +#include "base/message_loop.h" +#include "jingle/notifier/base/fake_base_task.h" +#include "jingle/notifier/base/weak_xmpp_client.h" +#include "talk/xmpp/asyncsocket.h" +#include "testing/gmock/include/gmock/gmock.h" + +namespace notifier { + +using ::testing::_; +using ::testing::Return; + +class MockAsyncSocket : public buzz::AsyncSocket { + public: + virtual ~MockAsyncSocket() {} + + MOCK_METHOD0(state, State()); + MOCK_METHOD0(error, Error()); + MOCK_METHOD0(GetError, int()); + MOCK_METHOD1(Connect, bool(const talk_base::SocketAddress&)); + MOCK_METHOD3(Read, bool(char*, size_t, size_t*)); + MOCK_METHOD2(Write, bool(const char*, size_t)); + MOCK_METHOD0(Close, bool()); + MOCK_METHOD1(StartTls, bool(const std::string&)); +}; + +FakeBaseTask::FakeBaseTask() { + // Owned by |task_pump_|. + notifier::WeakXmppClient* weak_xmpp_client = + new notifier::WeakXmppClient(&task_pump_); + + weak_xmpp_client->Start(); + buzz::XmppClientSettings settings; + // Owned by |weak_xmpp_client|. + MockAsyncSocket* mock_async_socket = new MockAsyncSocket(); + EXPECT_CALL(*mock_async_socket, Connect(_)).WillOnce(Return(true)); + weak_xmpp_client->Connect(settings, "en", mock_async_socket, NULL); + // Initialize the XMPP client. + MessageLoop::current()->RunAllPending(); + + base_task_ = weak_xmpp_client->AsWeakPtr(); +} + +base::WeakPtr<talk_base::Task> FakeBaseTask::AsWeakPtr() { + return base_task_; +} + +} // namespace notifier diff --git a/jingle/notifier/base/fake_base_task.h b/jingle/notifier/base/fake_base_task.h new file mode 100644 index 0000000..c165561 --- /dev/null +++ b/jingle/notifier/base/fake_base_task.h @@ -0,0 +1,38 @@ +// Copyright (c) 2010 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. +// +// A simple wrapper around invalidation::InvalidationClient that +// handles all the startup/shutdown details and hookups. + +#ifndef JINGLE_NOTIFIER_FAKE_XMPP_CLIENT_H_ +#define JINGLE_NOTIFIER_FAKE_XMPP_CLIENT_H_ +#pragma once + +#include "base/basictypes.h" +#include "base/weak_ptr.h" +#include "jingle/notifier/base/task_pump.h" + +namespace talk_base { +class Task; +} // namespace talk_base + +namespace notifier { + +// This class expects a message loop to exist on the current thread. +class FakeBaseTask { + public: + FakeBaseTask(); + + base::WeakPtr<talk_base::Task> AsWeakPtr(); + + private: + notifier::TaskPump task_pump_; + base::WeakPtr<talk_base::Task> base_task_; + + DISALLOW_COPY_AND_ASSIGN(FakeBaseTask); +}; + +} // namespace notifier + +#endif // JINGLE_NOTIFIER_FAKE_XMPP_CLIENT_H_ |