This source file includes following definitions.
- SetUp
- TearDown
- TEST_F
- TEST_F
- TEST_F
- TEST_F
- TEST_F
- TEST_F
- TEST_F
- TEST_F
#include "jingle/notifier/listener/xmpp_push_client.h"
#include "base/compiler_specific.h"
#include "base/memory/scoped_ptr.h"
#include "base/message_loop/message_loop.h"
#include "jingle/notifier/base/fake_base_task.h"
#include "jingle/notifier/base/notifier_options.h"
#include "jingle/notifier/listener/push_client_observer.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 PushClientObserver {
public:
MOCK_METHOD0(OnNotificationsEnabled, void());
MOCK_METHOD1(OnNotificationsDisabled, void(NotificationsDisabledReason));
MOCK_METHOD1(OnIncomingNotification, void(const Notification&));
MOCK_METHOD0(OnPingResponse, void());
};
class XmppPushClientTest : public testing::Test {
protected:
XmppPushClientTest() {
notifier_options_.request_context_getter =
new net::TestURLRequestContextGetter(
message_loop_.message_loop_proxy());
}
virtual ~XmppPushClientTest() {}
virtual void SetUp() OVERRIDE {
xmpp_push_client_.reset(new XmppPushClient(notifier_options_));
xmpp_push_client_->AddObserver(&mock_observer_);
}
virtual void TearDown() OVERRIDE {
message_loop_.RunUntilIdle();
xmpp_push_client_->RemoveObserver(&mock_observer_);
xmpp_push_client_.reset();
}
base::MessageLoopForIO message_loop_;
NotifierOptions notifier_options_;
StrictMock<MockObserver> mock_observer_;
scoped_ptr<XmppPushClient> xmpp_push_client_;
FakeBaseTask fake_base_task_;
};
TEST_F(XmppPushClientTest, OnIncomingNotification) {
EXPECT_CALL(mock_observer_, OnIncomingNotification(_));
xmpp_push_client_->OnNotificationReceived(Notification());
}
TEST_F(XmppPushClientTest, ConnectAndSubscribe) {
EXPECT_CALL(mock_observer_, OnNotificationsEnabled());
xmpp_push_client_->OnConnect(fake_base_task_.AsWeakPtr());
xmpp_push_client_->OnSubscribed();
}
TEST_F(XmppPushClientTest, Disconnect) {
EXPECT_CALL(mock_observer_,
OnNotificationsDisabled(TRANSIENT_NOTIFICATION_ERROR));
xmpp_push_client_->OnTransientDisconnection();
}
TEST_F(XmppPushClientTest, RejectCredentials) {
EXPECT_CALL(mock_observer_,
OnNotificationsDisabled(NOTIFICATION_CREDENTIALS_REJECTED));
xmpp_push_client_->OnCredentialsRejected();
}
TEST_F(XmppPushClientTest, SubscriptionError) {
EXPECT_CALL(mock_observer_,
OnNotificationsDisabled(TRANSIENT_NOTIFICATION_ERROR));
xmpp_push_client_->OnSubscriptionError();
}
TEST_F(XmppPushClientTest, SendNotification) {
EXPECT_CALL(mock_observer_, OnNotificationsEnabled());
xmpp_push_client_->OnConnect(fake_base_task_.AsWeakPtr());
xmpp_push_client_->OnSubscribed();
xmpp_push_client_->SendNotification(Notification());
}
TEST_F(XmppPushClientTest, SendPing) {
EXPECT_CALL(mock_observer_, OnNotificationsEnabled());
xmpp_push_client_->OnConnect(fake_base_task_.AsWeakPtr());
xmpp_push_client_->OnSubscribed();
xmpp_push_client_->SendPing();
}
TEST_F(XmppPushClientTest, SendNotificationPending) {
xmpp_push_client_->SendNotification(Notification());
Mock::VerifyAndClearExpectations(&mock_observer_);
EXPECT_CALL(mock_observer_, OnNotificationsEnabled());
xmpp_push_client_->OnConnect(fake_base_task_.AsWeakPtr());
xmpp_push_client_->OnSubscribed();
}
}
}