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

Unified Diff: chrome/browser/extensions/api/socket/udp_socket_unittest.cc

Issue 10134008: Add bind(), recvFrom(), sendTo() for UDP socket. (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: Update Created 8 years, 8 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 | « chrome/browser/extensions/api/socket/udp_socket.cc ('k') | chrome/chrome_tests.gypi » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/browser/extensions/api/socket/udp_socket_unittest.cc
diff --git a/chrome/browser/extensions/api/socket/udp_socket_unittest.cc b/chrome/browser/extensions/api/socket/udp_socket_unittest.cc
deleted file mode 100644
index b8c50a1d8e68ef99621b254d0cd257a9bf431074..0000000000000000000000000000000000000000
--- a/chrome/browser/extensions/api/socket/udp_socket_unittest.cc
+++ /dev/null
@@ -1,104 +0,0 @@
-// 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 "chrome/browser/extensions/api/socket/udp_socket.h"
-
-#include "base/memory/scoped_ptr.h"
-#include "chrome/browser/extensions/api/api_resource_event_notifier.h"
-#include "net/base/completion_callback.h"
-#include "net/base/io_buffer.h"
-#include "net/base/net_errors.h"
-#include "net/base/rand_callback.h"
-#include "net/udp/udp_client_socket.h"
-#include "testing/gmock/include/gmock/gmock.h"
-
-using testing::_;
-using testing::DoAll;
-using testing::Return;
-using testing::SaveArg;
-
-namespace extensions {
-
-class MockUDPSocket : public net::UDPClientSocket {
- public:
- MockUDPSocket()
- : net::UDPClientSocket(net::DatagramSocket::DEFAULT_BIND,
- net::RandIntCallback(),
- NULL,
- net::NetLog::Source()) {}
-
- MOCK_METHOD3(Read, int(net::IOBuffer* buf, int buf_len,
- const net::CompletionCallback& callback));
- MOCK_METHOD3(Write, int(net::IOBuffer* buf, int buf_len,
- const net::CompletionCallback& callback));
- private:
- DISALLOW_COPY_AND_ASSIGN(MockUDPSocket);
-};
-
-class MockAPIResourceEventNotifier : public APIResourceEventNotifier {
- public:
- MockAPIResourceEventNotifier() : APIResourceEventNotifier(NULL, NULL,
- std::string(),
- 0, GURL()) {}
-
- MOCK_METHOD2(OnReadComplete, void(int result_code,
- const std::string& message));
- MOCK_METHOD1(OnWriteComplete, void(int result_code));
-};
-
-TEST(SocketTest, TestUDPSocketRead) {
- MockUDPSocket* udp_client_socket = new MockUDPSocket();
- APIResourceEventNotifier* notifier = new MockAPIResourceEventNotifier();
-
- scoped_ptr<UDPSocket> socket(UDPSocket::CreateSocketForTesting(
- udp_client_socket, "1.2.3.4", 1, notifier));
-
- EXPECT_CALL(*udp_client_socket, Read(_, _, _))
- .Times(1);
-
- scoped_refptr<net::IOBufferWithSize> io_buffer(
- new net::IOBufferWithSize(512));
- socket->Read(io_buffer.get(), io_buffer->size());
-}
-
-TEST(SocketTest, TestUDPSocketWrite) {
- MockUDPSocket* udp_client_socket = new MockUDPSocket();
- APIResourceEventNotifier* notifier = new MockAPIResourceEventNotifier();
-
- scoped_ptr<UDPSocket> socket(UDPSocket::CreateSocketForTesting(
- udp_client_socket, "1.2.3.4", 1, notifier));
-
- EXPECT_CALL(*udp_client_socket, Write(_, _, _))
- .Times(1);
-
- scoped_refptr<net::IOBufferWithSize> io_buffer(
- new net::IOBufferWithSize(512));
- socket->Write(io_buffer.get(), io_buffer->size());
-}
-
-TEST(SocketTest, TestUDPSocketBlockedWrite) {
- MockUDPSocket* udp_client_socket = new MockUDPSocket();
- MockAPIResourceEventNotifier* notifier = new MockAPIResourceEventNotifier();
-
- scoped_ptr<UDPSocket> socket(UDPSocket::CreateSocketForTesting(
- udp_client_socket, "1.2.3.4", 1, notifier));
-
- net::CompletionCallback callback;
- EXPECT_CALL(*udp_client_socket, Write(_, _, _))
- .Times(1)
- .WillOnce(testing::DoAll(SaveArg<2>(&callback),
- Return(net::ERR_IO_PENDING)));
-
- scoped_refptr<net::IOBufferWithSize> io_buffer(new net::IOBufferWithSize(1));
- ASSERT_EQ(net::ERR_IO_PENDING, socket->Write(io_buffer.get(),
- io_buffer->size()));
-
- // Good. Original call came back unable to complete. Now pretend the socket
- // finished, and confirm that we passed the error back.
- EXPECT_CALL(*notifier, OnWriteComplete(42))
- .Times(1);
- callback.Run(42);
-}
-
-} // namespace extensions
« no previous file with comments | « chrome/browser/extensions/api/socket/udp_socket.cc ('k') | chrome/chrome_tests.gypi » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698