| Index: jingle/notifier/listener/push_client_unittest.cc
|
| diff --git a/jingle/notifier/listener/push_client_unittest.cc b/jingle/notifier/listener/push_client_unittest.cc
|
| new file mode 100644
|
| index 0000000000000000000000000000000000000000..e65b2a89b7219cf8913e364b2424c42d46b3746d
|
| --- /dev/null
|
| +++ b/jingle/notifier/listener/push_client_unittest.cc
|
| @@ -0,0 +1,96 @@
|
| +// 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 "jingle/notifier/listener/push_client.h"
|
| +
|
| +#include "base/compiler_specific.h"
|
| +#include "base/memory/scoped_ptr.h"
|
| +#include "base/message_loop.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::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() {
|
| + notifier_options_.request_context_getter =
|
| + new TestURLRequestContextGetter(message_loop_.message_loop_proxy());
|
| + }
|
| +
|
| + virtual ~PushClientTest() {}
|
| +
|
| + virtual void SetUp() OVERRIDE {
|
| + mediator_thread_.reset(new PushClient(notifier_options_));
|
| + mediator_thread_->AddObserver(&mock_observer_);
|
| + }
|
| +
|
| + virtual void TearDown() OVERRIDE {
|
| + // Clear out any messages posted by PushClient's
|
| + // destructor.
|
| + message_loop_.RunAllPending();
|
| + mediator_thread_->RemoveObserver(&mock_observer_);
|
| + mediator_thread_.reset();
|
| + }
|
| +
|
| + MessageLoop message_loop_;
|
| + NotifierOptions notifier_options_;
|
| + StrictMock<MockObserver> mock_observer_;
|
| + scoped_ptr<PushClient> mediator_thread_;
|
| + FakeBaseTask fake_base_task_;
|
| +};
|
| +
|
| +TEST_F(PushClientTest, OnIncomingNotification) {
|
| + EXPECT_CALL(mock_observer_, OnIncomingNotification(_));
|
| + mediator_thread_->SimulateOnNotificationReceivedForTest(Notification());
|
| +}
|
| +
|
| +TEST_F(PushClientTest, ConnectAndSubscribe) {
|
| + EXPECT_CALL(mock_observer_, OnNotificationStateChange(true));
|
| + mediator_thread_->SimulateConnectAndSubscribeForTest(
|
| + fake_base_task_.AsWeakPtr());
|
| +}
|
| +
|
| +TEST_F(PushClientTest, Disconnect) {
|
| + EXPECT_CALL(mock_observer_, OnNotificationStateChange(false));
|
| + mediator_thread_->SimulateDisconnectForTest();
|
| +}
|
| +
|
| +TEST_F(PushClientTest, SubscriptionError) {
|
| + EXPECT_CALL(mock_observer_, OnNotificationStateChange(false));
|
| + mediator_thread_->SimulateSubscriptionErrorForTest();
|
| +}
|
| +
|
| +TEST_F(PushClientTest, SendNotification) {
|
| + EXPECT_CALL(mock_observer_, OnNotificationStateChange(true));
|
| + mediator_thread_->SimulateConnectAndSubscribeForTest(
|
| + fake_base_task_.AsWeakPtr());
|
| + // TODO(akalin): Figure out how to check that the notification was
|
| + // actually sent.
|
| + mediator_thread_->SendNotification(Notification());
|
| +}
|
| +
|
| +TEST_F(PushClientTest, SendNotificationPending) {
|
| + // TODO(akalin): Figure out how to check that the notification was
|
| + // actually marked pending.
|
| + mediator_thread_->SendNotification(Notification());
|
| +}
|
| +
|
| +} // namespace notifier
|
|
|