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 "mojo/shell/shell_test_base.h" | 5 #include "mojo/shell/shell_test_base.h" |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/i18n/time_formatting.h" | 8 #include "base/i18n/time_formatting.h" |
9 #include "base/macros.h" | 9 #include "base/macros.h" |
10 #include "base/message_loop/message_loop.h" | 10 #include "base/message_loop/message_loop.h" |
(...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
101 EXPECT_FALSE(service.encountered_error()); | 101 EXPECT_FALSE(service.encountered_error()); |
102 | 102 |
103 service.reset(); | 103 service.reset(); |
104 | 104 |
105 // This will run until the test app has actually quit (which it will, | 105 // This will run until the test app has actually quit (which it will, |
106 // since we killed the only connection to it). | 106 // since we killed the only connection to it). |
107 message_loop()->Run(); | 107 message_loop()->Run(); |
108 } | 108 } |
109 | 109 |
110 // Tests that trying to connect to a service fails properly if the service | 110 // Tests that trying to connect to a service fails properly if the service |
111 // doesn't exist. | 111 // doesn't exist. Implicit in this test is verification that the shell |
| 112 // terminates if no services are running. |
112 TEST_F(ShellTestBaseTest, ConnectInvalidService) { | 113 TEST_F(ShellTestBaseTest, ConnectInvalidService) { |
113 InterfacePtr<TestService> test_service; | 114 InterfacePtr<TestService> test_service; |
114 test_service.Bind(ConnectToService(GURL("mojo:non_existent_service"), | 115 test_service.Bind(ConnectToService(GURL("mojo:non_existent_service"), |
115 TestService::Name_).Pass()); | 116 TestService::Name_).Pass()); |
116 | 117 |
117 bool was_run = false; | 118 bool was_run = false; |
118 test_service->Ping(SetAndQuit<bool>(&was_run, true)); | 119 test_service->Ping(SetAndQuit<bool>(&was_run, true)); |
119 | 120 |
120 // This will quit because there's nothing running. | 121 // This will quit because there's nothing running. |
121 message_loop()->Run(); | 122 message_loop()->Run(); |
122 EXPECT_FALSE(was_run); | 123 EXPECT_FALSE(was_run); |
123 | 124 |
124 // It may have quit before an error was processed. | 125 // It may have quit before an error was processed. |
125 if (!test_service.encountered_error()) { | 126 if (!test_service.encountered_error()) { |
126 QuitMessageLoopErrorHandler quitter; | 127 QuitMessageLoopErrorHandler quitter; |
127 test_service.set_error_handler(&quitter); | 128 test_service.set_error_handler(&quitter); |
128 message_loop()->Run(); | 129 message_loop()->Run(); |
129 EXPECT_TRUE(test_service.encountered_error()); | 130 EXPECT_TRUE(test_service.encountered_error()); |
130 } | 131 } |
131 | 132 |
132 test_service.reset(); | 133 test_service.reset(); |
133 } | 134 } |
134 | 135 |
| 136 // Tests that we can connect to a single service within a single app using |
| 137 // a network based loader instead of local files. |
| 138 // TODO(tim): Bug 394477. NetworkService doesn't currently terminate. |
| 139 TEST_F(ShellTestBaseTest, DISABLED_ConnectBasicNetwork) { |
| 140 InterfacePtr<TestService> service; |
| 141 service.Bind(ConnectToServiceViaNetwork( |
| 142 test_app_url(), TestService::Name_).Pass()); |
| 143 |
| 144 bool was_run = false; |
| 145 service->Ping(SetAndQuit<bool>(&was_run, true)); |
| 146 message_loop()->Run(); |
| 147 EXPECT_TRUE(was_run); |
| 148 EXPECT_FALSE(service.encountered_error()); |
| 149 |
| 150 // Note that use of the network service is implicit in this test. |
| 151 // Since TestService is not the only service in use, the shell won't auto |
| 152 // magically exit when TestService is destroyed (unlike ConnectBasic). |
| 153 // Tearing down the shell context will kill connections. The shell loop will |
| 154 // exit as soon as no more apps are connected. |
| 155 shell_context()->Shutdown(); |
| 156 message_loop()->Run(); |
| 157 } |
| 158 |
| 159 // Tests that trying to connect to a service over network fails preoprly |
| 160 // if the service doesn't exist. |
| 161 // TODO(tim): Bug 394477. NetworkService doesn't currently terminate. |
| 162 TEST_F(ShellTestBaseTest, DISABLED_ConnectInvalidServiceNetwork) { |
| 163 InterfacePtr<TestService> test_service; |
| 164 test_service.Bind(ConnectToServiceViaNetwork( |
| 165 GURL("mojo:non_existent_service"), TestService::Name_).Pass()); |
| 166 QuitMessageLoopErrorHandler quitter; |
| 167 test_service.set_error_handler(&quitter); |
| 168 bool was_run = false; |
| 169 test_service->Ping(SetAndQuit<bool>(&was_run, true)); |
| 170 message_loop()->Run(); |
| 171 EXPECT_TRUE(test_service.encountered_error()); |
| 172 |
| 173 shell_context()->Shutdown(); |
| 174 message_loop()->Run(); |
| 175 } |
| 176 |
135 // Similar to ConnectBasic, but causes the app to instantiate multiple | 177 // Similar to ConnectBasic, but causes the app to instantiate multiple |
136 // service implementation objects and verifies the shell can reach both. | 178 // service implementation objects and verifies the shell can reach both. |
137 TEST_F(ShellTestBaseTest, ConnectMultipleInstancesPerApp) { | 179 TEST_F(ShellTestBaseTest, ConnectMultipleInstancesPerApp) { |
138 { | 180 { |
139 TestServicePtr service1, service2; | 181 TestServicePtr service1, service2; |
140 service1.Bind(ConnectToService(test_app_url(), TestService::Name_).Pass()); | 182 service1.Bind(ConnectToService(test_app_url(), TestService::Name_).Pass()); |
141 service2.Bind(ConnectToService(test_app_url(), TestService::Name_).Pass()); | 183 service2.Bind(ConnectToService(test_app_url(), TestService::Name_).Pass()); |
142 | 184 |
143 bool was_run1 = false; | 185 bool was_run1 = false; |
144 bool was_run2 = false; | 186 bool was_run2 = false; |
(...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
259 EXPECT_EQ(TestTimeService::Name_, reports[1].service_name); | 301 EXPECT_EQ(TestTimeService::Name_, reports[1].service_name); |
260 EXPECT_EQ(1U, reports[1].total_requests); | 302 EXPECT_EQ(1U, reports[1].total_requests); |
261 EXPECT_EQ(TestTimeService::Name_, reports[2].service_name); | 303 EXPECT_EQ(TestTimeService::Name_, reports[2].service_name); |
262 EXPECT_EQ(20U, reports[2].total_requests); | 304 EXPECT_EQ(20U, reports[2].total_requests); |
263 } | 305 } |
264 | 306 |
265 } // namespace | 307 } // namespace |
266 } // namespace test | 308 } // namespace test |
267 } // namespace shell | 309 } // namespace shell |
268 } // namespace mojo | 310 } // namespace mojo |
OLD | NEW |