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

Unified Diff: jingle/notifier/listener/push_client_unittest.cc

Issue 10388227: Revert 138216 - [Sync] Turn notifier::PushClient into an interface (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « jingle/notifier/listener/push_client_observer.cc ('k') | jingle/notifier/listener/xmpp_push_client.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: jingle/notifier/listener/push_client_unittest.cc
===================================================================
--- jingle/notifier/listener/push_client_unittest.cc (revision 138220)
+++ jingle/notifier/listener/push_client_unittest.cc (working copy)
@@ -4,20 +4,31 @@
#include "jingle/notifier/listener/push_client.h"
-#include "base/bind_helpers.h"
#include "base/compiler_specific.h"
-#include "base/location.h"
#include "base/memory/scoped_ptr.h"
#include "base/message_loop.h"
-#include "base/threading/thread.h"
+#include "jingle/notifier/base/fake_base_task.h"
#include "jingle/notifier/base/notifier_options.h"
#include "net/url_request/url_request_test_util.h"
+#include "testing/gmock/include/gmock/gmock.h"
#include "testing/gtest/include/gtest/gtest.h"
namespace notifier {
namespace {
+using ::testing::_;
+using ::testing::Mock;
+using ::testing::StrictMock;
+
+class MockObserver : public PushClient::Observer {
+ public:
+ MOCK_METHOD1(OnNotificationStateChange, void(bool));
+ MOCK_METHOD1(OnIncomingNotification, void(const Notification&));
+};
+
+} // namespace
+
class PushClientTest : public testing::Test {
protected:
PushClientTest() {
@@ -27,28 +38,68 @@
virtual ~PushClientTest() {}
+ virtual void SetUp() OVERRIDE {
+ push_client_.reset(new PushClient(notifier_options_));
+ push_client_->AddObserver(&mock_observer_);
+ }
+
+ virtual void TearDown() OVERRIDE {
+ // Clear out any messages posted by PushClient.
+ message_loop_.RunAllPending();
+ push_client_->RemoveObserver(&mock_observer_);
+ push_client_.reset();
+ }
+
// The sockets created by the XMPP code expect an IO loop.
MessageLoopForIO message_loop_;
NotifierOptions notifier_options_;
+ StrictMock<MockObserver> mock_observer_;
+ scoped_ptr<PushClient> push_client_;
+ FakeBaseTask fake_base_task_;
};
-// Make sure calling CreateDefault on the IO thread doesn't blow up.
-TEST_F(PushClientTest, OnIOThread) {
- const scoped_ptr<PushClient> push_client(
- PushClient::CreateDefault(notifier_options_));
+TEST_F(PushClientTest, OnIncomingNotification) {
+ EXPECT_CALL(mock_observer_, OnIncomingNotification(_));
+ push_client_->SimulateOnNotificationReceivedForTest(Notification());
}
-// Make sure calling CreateDefault on a non-IO thread doesn't blow up.
-TEST_F(PushClientTest, OffIOThread) {
- base::Thread thread("Non-IO thread");
- EXPECT_TRUE(thread.Start());
- thread.message_loop()->PostTask(
- FROM_HERE,
- base::Bind(base::IgnoreResult(&PushClient::CreateDefault),
- notifier_options_));
- thread.Stop();
+TEST_F(PushClientTest, ConnectAndSubscribe) {
+ EXPECT_CALL(mock_observer_, OnNotificationStateChange(true));
+ push_client_->SimulateConnectAndSubscribeForTest(
+ fake_base_task_.AsWeakPtr());
}
-} // namespace
+TEST_F(PushClientTest, Disconnect) {
+ EXPECT_CALL(mock_observer_, OnNotificationStateChange(false));
+ push_client_->SimulateDisconnectForTest();
+}
+TEST_F(PushClientTest, SubscriptionError) {
+ EXPECT_CALL(mock_observer_, OnNotificationStateChange(false));
+ push_client_->SimulateSubscriptionErrorForTest();
+}
+
+TEST_F(PushClientTest, SendNotification) {
+ EXPECT_CALL(mock_observer_, OnNotificationStateChange(true));
+ EXPECT_CALL(mock_observer_, OnIncomingNotification(_));
+
+ push_client_->SimulateConnectAndSubscribeForTest(
+ fake_base_task_.AsWeakPtr());
+ push_client_->ReflectSentNotificationsForTest();
+ push_client_->SendNotification(Notification());
+}
+
+TEST_F(PushClientTest, SendNotificationPending) {
+ push_client_->ReflectSentNotificationsForTest();
+ push_client_->SendNotification(Notification());
+
+ Mock::VerifyAndClearExpectations(&mock_observer_);
+
+ EXPECT_CALL(mock_observer_, OnNotificationStateChange(true));
+ EXPECT_CALL(mock_observer_, OnIncomingNotification(_));
+
+ push_client_->SimulateConnectAndSubscribeForTest(
+ fake_base_task_.AsWeakPtr());
+}
+
} // namespace notifier
« no previous file with comments | « jingle/notifier/listener/push_client_observer.cc ('k') | jingle/notifier/listener/xmpp_push_client.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698