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

Unified Diff: remoting/host/gnubby_advertiser_unittest.cc

Issue 138753005: Add gnubby authentication to remoting host (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 6 years, 11 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
Index: remoting/host/gnubby_advertiser_unittest.cc
diff --git a/remoting/host/gnubby_advertiser_unittest.cc b/remoting/host/gnubby_advertiser_unittest.cc
new file mode 100644
index 0000000000000000000000000000000000000000..e1d8279e74e72d862f47f5a113f4bc0f727c2408
--- /dev/null
+++ b/remoting/host/gnubby_advertiser_unittest.cc
@@ -0,0 +1,75 @@
+// Copyright 2014 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/test/test_simple_task_runner.h"
+#include "net/base/net_errors.h"
+#include "net/socket/socket_test_util.h"
+#include "remoting/host/gnubby_advertiser.h"
+#include "testing/gtest/include/gtest/gtest.h"
+
+namespace remoting {
+
+class GnubbyAdvertiserTest : public testing::Test {
+ public:
+ GnubbyAdvertiserTest() {}
+
+ virtual void SetUp() OVERRIDE;
+ virtual void TearDown() OVERRIDE;
+
+ protected:
+ // Returns mock sockets.
+ scoped_ptr<net::MockClientSocketFactory> client_socket_factory_;
+
+ // GnubbyAdvertiser instance under test.
+ scoped_refptr<GnubbyAdvertiser> gnubby_advertiser_;
+};
+
+void GnubbyAdvertiserTest::SetUp() {
+ scoped_refptr<base::SingleThreadTaskRunner> task_runner =
+ new base::TestSimpleTaskRunner();
+
+ client_socket_factory_.reset(new net::MockClientSocketFactory());
+
+ gnubby_advertiser_ =
+ new GnubbyAdvertiser(task_runner, client_socket_factory_.get());
+}
+
+void GnubbyAdvertiserTest::TearDown() {
+ EXPECT_TRUE(gnubby_advertiser_->HasOneRef());
+}
+
+TEST_F(GnubbyAdvertiserTest, ConnectFailed) {
+ net::StaticSocketDataProvider socket_data(NULL, 0, NULL, 0);
+ socket_data.set_connect_data(
+ net::MockConnect(net::SYNCHRONOUS, net::ERR_FAILED));
+
+ client_socket_factory_->AddSocketDataProvider(&socket_data);
+
+ gnubby_advertiser_->Advertise(80);
+}
+
+TEST_F(GnubbyAdvertiserTest, WriteFailed) {
+ net::MockWrite write_fail(net::SYNCHRONOUS, net::ERR_FAILED);
+
+ net::StaticSocketDataProvider socket_data(NULL, 0, &write_fail, 1);
+ socket_data.set_connect_data(net::MockConnect(net::SYNCHRONOUS, net::OK));
+
+ client_socket_factory_->AddSocketDataProvider(&socket_data);
+
+ gnubby_advertiser_->Advertise(80);
+}
+
+TEST_F(GnubbyAdvertiserTest, ReadFailed) {
+ net::MockRead read_fail(net::SYNCHRONOUS, net::ERR_FAILED);
+ net::MockWrite write(net::SYNCHRONOUS, net::OK);
+
+ net::StaticSocketDataProvider socket_data(&read_fail, 1, &write, 1);
+ socket_data.set_connect_data(net::MockConnect(net::SYNCHRONOUS, net::OK));
+
+ client_socket_factory_->AddSocketDataProvider(&socket_data);
+
+ gnubby_advertiser_->Advertise(80);
+}
+
+} // namespace remoting

Powered by Google App Engine
This is Rietveld 408576698