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

Unified Diff: remoting/jingle_glue/jingle_client_unittest.cc

Issue 3167047: Jingle_glue bugfixes. (Closed)
Patch Set: - Created 10 years, 4 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 | « remoting/jingle_glue/jingle_client.cc ('k') | remoting/jingle_glue/jingle_test_client.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: remoting/jingle_glue/jingle_client_unittest.cc
diff --git a/remoting/jingle_glue/jingle_client_unittest.cc b/remoting/jingle_glue/jingle_client_unittest.cc
new file mode 100644
index 0000000000000000000000000000000000000000..4d6d55fe4389e264da24581bd5095a4bc8e93266
--- /dev/null
+++ b/remoting/jingle_glue/jingle_client_unittest.cc
@@ -0,0 +1,108 @@
+// 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.
+
+#include "base/waitable_event.h"
+#include "remoting/jingle_glue/jingle_client.h"
+#include "remoting/jingle_glue/jingle_thread.h"
+#include "testing/gmock/include/gmock/gmock.h"
+#include "testing/gtest/include/gtest/gtest.h"
+
+using testing::_;
+
+namespace remoting {
+
+class MockJingleClientCallback : public JingleClient::Callback {
+ public:
+ ~MockJingleClientCallback() { }
+
+ MOCK_METHOD2(OnStateChange, void(JingleClient*, JingleClient::State));
+ MOCK_METHOD3(OnAcceptConnection, bool(
+ JingleClient*, const std::string&,
+ JingleChannel::Callback**_callback));
+ MOCK_METHOD2(OnNewConnection, void(
+ JingleClient*, scoped_refptr<JingleChannel>));
+};
+
+class JingleClientTest : public testing::Test {
+ public:
+ virtual ~JingleClientTest() { }
+
+ static void OnClosed(bool* called) {
+ *called = true;
+ }
+
+ // A helper that calls OnConnectionStateChanged(). Need this because we want
+ // to call it on the jingle thread.
+ static void ChangeState(JingleClient* client, buzz::XmppEngine::State state,
+ base::WaitableEvent* done_event) {
+ client->OnConnectionStateChanged(state);
+ if (done_event)
+ done_event->Signal();
+ }
+
+ protected:
+ virtual void SetUp() {
+ client_ = new JingleClient(&thread_);
+ // Fake initialization
+ client_->initialized_ = true;
+ client_->callback_ = &callback_;
+ }
+
+ JingleThread thread_;
+ scoped_refptr<JingleClient> client_;
+ MockJingleClientCallback callback_;
+};
+
+TEST_F(JingleClientTest, OnStateChanged) {
+ EXPECT_CALL(callback_, OnStateChange(_, JingleClient::CONNECTING))
+ .Times(1);
+
+ thread_.Start();
+
+ base::WaitableEvent state_changed_event(true, false);
+ thread_.message_loop()->PostTask(FROM_HERE, NewRunnableFunction(
+ &JingleClientTest::ChangeState, client_.get(),
+ buzz::XmppEngine::STATE_OPENING, &state_changed_event));
+ state_changed_event.Wait();
+
+ client_->Close();
+
+ thread_.Stop();
+}
+
+TEST_F(JingleClientTest, Close) {
+ EXPECT_CALL(callback_, OnStateChange(_, _))
+ .Times(0);
+ thread_.Start();
+ client_->Close();
+ // Verify that the channel doesn't call callback anymore.
+ thread_.message_loop()->PostTask(FROM_HERE, NewRunnableFunction(
+ &JingleClientTest::ChangeState, client_.get(),
+ buzz::XmppEngine::STATE_OPENING,
+ static_cast<base::WaitableEvent*>(NULL)));
+ thread_.Stop();
+}
+
+TEST_F(JingleClientTest, ClosedTask) {
+ thread_.Start();
+ bool closed = false;
+ client_->Close(NewRunnableFunction(&JingleClientTest::OnClosed,
+ &closed));
+ thread_.Stop();
+ EXPECT_TRUE(closed);
+}
+
+TEST_F(JingleClientTest, DoubleClose) {
+ thread_.Start();
+ bool closed1 = false;
+ client_->Close(NewRunnableFunction(&JingleClientTest::OnClosed,
+ &closed1));
+ bool closed2 = false;
+ client_->Close(NewRunnableFunction(&JingleClientTest::OnClosed,
+ &closed2));
+ thread_.Stop();
+ EXPECT_TRUE(closed1 && closed2);
+}
+
+} // namespace remoting
« no previous file with comments | « remoting/jingle_glue/jingle_client.cc ('k') | remoting/jingle_glue/jingle_test_client.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698