Chromium Code Reviews| 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 TEST_F(ShellTestBaseTest, ConnectBasicNetwork) { | |
| 139 InterfacePtr<TestService> service; | |
| 140 service.Bind(ConnectToServiceViaNetwork( | |
|
darin (slow to review)
2014/07/15 22:15:15
does this rely on a web server running or is it no
tim (not reviewing)
2014/07/15 22:23:56
ConnectToServiceViaNetwork configures the MojoURLR
| |
| 141 test_app_url(), TestService::Name_).Pass()); | |
| 142 | |
| 143 bool was_run = false; | |
| 144 service->Ping(SetAndQuit<bool>(&was_run, true)); | |
| 145 message_loop()->Run(); | |
| 146 EXPECT_TRUE(was_run); | |
| 147 EXPECT_FALSE(service.encountered_error()); | |
| 148 | |
| 149 // Note that use of the network service is implicit in this test. | |
| 150 // Since TestService is not the only service in use, the shell won't auto | |
| 151 // magically exit when TestService is destroyed (unlike ConnectBasic). | |
| 152 } | |
| 153 | |
| 154 // Tests that trying to connect to a service over network fails preoprly | |
| 155 // if the service doesn't exist. | |
| 156 TEST_F(ShellTestBaseTest, ConnectInvalidServiceNetwork) { | |
| 157 InterfacePtr<TestService> test_service; | |
| 158 test_service.Bind(ConnectToServiceViaNetwork( | |
| 159 GURL("mojo:non_existent_service"), TestService::Name_).Pass()); | |
| 160 QuitMessageLoopErrorHandler quitter; | |
| 161 test_service.set_error_handler(&quitter); | |
| 162 bool was_run = false; | |
| 163 test_service->Ping(SetAndQuit<bool>(&was_run, true)); | |
| 164 message_loop()->Run(); | |
| 165 EXPECT_TRUE(test_service.encountered_error()); | |
| 166 } | |
| 167 | |
| 135 // Similar to ConnectBasic, but causes the app to instantiate multiple | 168 // Similar to ConnectBasic, but causes the app to instantiate multiple |
| 136 // service implementation objects and verifies the shell can reach both. | 169 // service implementation objects and verifies the shell can reach both. |
| 137 TEST_F(ShellTestBaseTest, ConnectMultipleInstancesPerApp) { | 170 TEST_F(ShellTestBaseTest, ConnectMultipleInstancesPerApp) { |
| 138 { | 171 { |
| 139 TestServicePtr service1, service2; | 172 TestServicePtr service1, service2; |
| 140 service1.Bind(ConnectToService(test_app_url(), TestService::Name_).Pass()); | 173 service1.Bind(ConnectToService(test_app_url(), TestService::Name_).Pass()); |
| 141 service2.Bind(ConnectToService(test_app_url(), TestService::Name_).Pass()); | 174 service2.Bind(ConnectToService(test_app_url(), TestService::Name_).Pass()); |
| 142 | 175 |
| 143 bool was_run1 = false; | 176 bool was_run1 = false; |
| 144 bool was_run2 = false; | 177 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); | 292 EXPECT_EQ(TestTimeService::Name_, reports[1].service_name); |
| 260 EXPECT_EQ(1U, reports[1].total_requests); | 293 EXPECT_EQ(1U, reports[1].total_requests); |
| 261 EXPECT_EQ(TestTimeService::Name_, reports[2].service_name); | 294 EXPECT_EQ(TestTimeService::Name_, reports[2].service_name); |
| 262 EXPECT_EQ(20U, reports[2].total_requests); | 295 EXPECT_EQ(20U, reports[2].total_requests); |
| 263 } | 296 } |
| 264 | 297 |
| 265 } // namespace | 298 } // namespace |
| 266 } // namespace test | 299 } // namespace test |
| 267 } // namespace shell | 300 } // namespace shell |
| 268 } // namespace mojo | 301 } // namespace mojo |
| OLD | NEW |