OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "base/files/file_path.h" | 5 #include "base/files/file_path.h" |
6 #include "base/files/file_util.h" | 6 #include "base/files/file_util.h" |
7 #include "base/files/scoped_temp_dir.h" | 7 #include "base/files/scoped_temp_dir.h" |
8 #include "base/message_loop/message_loop.h" | 8 #include "base/message_loop/message_loop.h" |
9 #include "base/run_loop.h" | 9 #include "base/run_loop.h" |
10 #include "mojo/embedder/channel_init.h" | 10 #include "mojo/embedder/channel_init.h" |
11 #include "mojo/embedder/platform_channel_pair.h" | 11 #include "mojo/embedder/platform_channel_pair.h" |
12 #include "mojo/shell/external_application_registrar_connection.h" | 12 #include "mojo/shell/external_application_registrar_connection.h" |
13 #include "mojo/shell/incoming_connection_listener_posix.h" | 13 #include "mojo/shell/incoming_connection_listener_posix.h" |
14 #include "net/base/net_errors.h" | 14 #include "net/base/net_errors.h" |
15 #include "net/base/test_completion_callback.h" | 15 #include "net/base/test_completion_callback.h" |
16 #include "net/socket/socket_descriptor.h" | 16 #include "net/socket/socket_descriptor.h" |
17 #include "net/socket/unix_domain_client_socket_posix.h" | 17 #include "net/socket/unix_domain_client_socket_posix.h" |
18 #include "testing/gtest/include/gtest/gtest.h" | 18 #include "testing/gtest/include/gtest/gtest.h" |
19 | 19 |
20 namespace mojo { | 20 namespace mojo { |
21 namespace shell { | 21 namespace shell { |
22 namespace { | 22 namespace { |
23 // Delegate implementation that expects success. | 23 // Delegate implementation that expects success. |
24 class TestDelegate : public IncomingConnectionListenerPosix::Delegate { | 24 class TestDelegate : public IncomingConnectionListenerPosix::Delegate { |
25 public: | 25 public: |
26 TestDelegate() {} | 26 TestDelegate() {} |
27 virtual ~TestDelegate() {} | 27 virtual ~TestDelegate() {} |
28 | 28 |
29 virtual void OnListening(int rv) MOJO_OVERRIDE { EXPECT_EQ(net::OK, rv); } | 29 virtual void OnListening(int rv) override { EXPECT_EQ(net::OK, rv); } |
30 virtual void OnConnection(net::SocketDescriptor incoming) MOJO_OVERRIDE { | 30 virtual void OnConnection(net::SocketDescriptor incoming) override { |
31 EXPECT_NE(net::kInvalidSocket, incoming); | 31 EXPECT_NE(net::kInvalidSocket, incoming); |
32 } | 32 } |
33 }; | 33 }; |
34 | 34 |
35 // Delegate implementation that expects a (configurable) failure to listen. | 35 // Delegate implementation that expects a (configurable) failure to listen. |
36 class ListeningFailsDelegate | 36 class ListeningFailsDelegate |
37 : public IncomingConnectionListenerPosix::Delegate { | 37 : public IncomingConnectionListenerPosix::Delegate { |
38 public: | 38 public: |
39 explicit ListeningFailsDelegate(int expected) : expected_error_(expected) {} | 39 explicit ListeningFailsDelegate(int expected) : expected_error_(expected) {} |
40 virtual ~ListeningFailsDelegate() {} | 40 virtual ~ListeningFailsDelegate() {} |
41 | 41 |
42 virtual void OnListening(int rv) MOJO_OVERRIDE { | 42 virtual void OnListening(int rv) override { EXPECT_EQ(expected_error_, rv); } |
43 EXPECT_EQ(expected_error_, rv); | 43 virtual void OnConnection(net::SocketDescriptor incoming) override { |
44 } | |
45 virtual void OnConnection(net::SocketDescriptor incoming) MOJO_OVERRIDE { | |
46 FAIL() << "No connection should be attempted."; | 44 FAIL() << "No connection should be attempted."; |
47 } | 45 } |
48 | 46 |
49 private: | 47 private: |
50 const int expected_error_; | 48 const int expected_error_; |
51 }; | 49 }; |
52 | 50 |
53 // For ExternalApplicationRegistrarConnection::Connect() callbacks. | 51 // For ExternalApplicationRegistrarConnection::Connect() callbacks. |
54 void OnConnect(base::Closure quit_callback, int rv) { | 52 void OnConnect(base::Closure quit_callback, int rv) { |
55 EXPECT_EQ(net::OK, rv); | 53 EXPECT_EQ(net::OK, rv); |
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
115 | 113 |
116 ListeningFailsDelegate fail_delegate(net::ERR_FILE_NOT_FOUND); | 114 ListeningFailsDelegate fail_delegate(net::ERR_FILE_NOT_FOUND); |
117 IncomingConnectionListenerPosix listener(nonexistent_dir, &fail_delegate); | 115 IncomingConnectionListenerPosix listener(nonexistent_dir, &fail_delegate); |
118 | 116 |
119 // The listener should fail to start up. | 117 // The listener should fail to start up. |
120 listener.StartListening(); | 118 listener.StartListening(); |
121 } | 119 } |
122 | 120 |
123 } // namespace shell | 121 } // namespace shell |
124 } // namespace mojo | 122 } // namespace mojo |
OLD | NEW |