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. 4 5#include "jingle/notifier/listener/push_client.h" 6 7#include "base/bind_helpers.h" 8#include "base/compiler_specific.h" 9#include "base/location.h" 10#include "base/memory/scoped_ptr.h" 11#include "base/message_loop/message_loop.h" 12#include "base/threading/thread.h" 13#include "jingle/notifier/base/notifier_options.h" 14#include "net/url_request/url_request_test_util.h" 15#include "testing/gtest/include/gtest/gtest.h" 16 17namespace notifier { 18 19namespace { 20 21class PushClientTest : public testing::Test { 22 protected: 23 PushClientTest() { 24 notifier_options_.request_context_getter = 25 new net::TestURLRequestContextGetter( 26 message_loop_.message_loop_proxy()); 27 } 28 29 virtual ~PushClientTest() {} 30 31 // The sockets created by the XMPP code expect an IO loop. 32 base::MessageLoopForIO message_loop_; 33 NotifierOptions notifier_options_; 34}; 35 36// Make sure calling CreateDefault on the IO thread doesn't blow up. 37TEST_F(PushClientTest, CreateDefaultOnIOThread) { 38 const scoped_ptr<PushClient> push_client( 39 PushClient::CreateDefault(notifier_options_)); 40} 41 42// Make sure calling CreateDefault on a non-IO thread doesn't blow up. 43TEST_F(PushClientTest, CreateDefaultOffIOThread) { 44 base::Thread thread("Non-IO thread"); 45 EXPECT_TRUE(thread.Start()); 46 thread.message_loop()->PostTask( 47 FROM_HERE, 48 base::Bind(base::IgnoreResult(&PushClient::CreateDefault), 49 notifier_options_)); 50 thread.Stop(); 51} 52 53// Make sure calling CreateDefaultOnIOThread on the IO thread doesn't 54// blow up. 55TEST_F(PushClientTest, CreateDefaultOnIOThreadOnIOThread) { 56 const scoped_ptr<PushClient> push_client( 57 PushClient::CreateDefaultOnIOThread(notifier_options_)); 58} 59 60} // namespace 61 62} // namespace notifier 63