| OLD | NEW |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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/base_paths.h" | 5 #include "base/base_paths.h" |
| 6 #include "base/bind.h" | 6 #include "base/bind.h" |
| 7 #include "base/files/file_path.h" | 7 #include "base/files/file_path.h" |
| 8 #include "base/files/file_util.h" | 8 #include "base/files/file_util.h" |
| 9 #include "base/path_service.h" | 9 #include "base/path_service.h" |
| 10 #include "base/run_loop.h" | 10 #include "base/run_loop.h" |
| 11 #include "base/strings/string_util.h" | 11 #include "base/strings/string_util.h" |
| 12 #include "base/strings/stringprintf.h" | 12 #include "base/strings/stringprintf.h" |
| 13 #include "mojo/converters/base/base_type_converters.h" | 13 #include "mojo/converters/base/base_type_converters.h" |
| 14 #include "mojo/data_pipe_utils/data_pipe_utils.h" | 14 #include "mojo/data_pipe_utils/data_pipe_utils.h" |
| 15 #include "mojo/public/cpp/application/application_impl.h" | |
| 16 #include "mojo/public/cpp/application/application_test_base.h" | 15 #include "mojo/public/cpp/application/application_test_base.h" |
| 17 #include "mojo/public/cpp/application/connect.h" | 16 #include "mojo/public/cpp/application/connect.h" |
| 17 #include "mojo/public/cpp/bindings/binding.h" |
| 18 #include "mojo/public/cpp/bindings/synchronous_interface_ptr.h" | 18 #include "mojo/public/cpp/bindings/synchronous_interface_ptr.h" |
| 19 #include "mojo/public/cpp/system/macros.h" | 19 #include "mojo/public/cpp/system/macros.h" |
| 20 #include "mojo/public/interfaces/application/application_connector.mojom.h" | 20 #include "mojo/public/interfaces/application/application_connector.mojom.h" |
| 21 #include "mojo/services/http_server/cpp/http_server_util.h" | 21 #include "mojo/services/http_server/cpp/http_server_util.h" |
| 22 #include "mojo/services/http_server/interfaces/http_server.mojom-sync.h" | 22 #include "mojo/services/http_server/interfaces/http_server.mojom-sync.h" |
| 23 #include "mojo/services/http_server/interfaces/http_server_factory.mojom.h" | 23 #include "mojo/services/http_server/interfaces/http_server_factory.mojom.h" |
| 24 #include "mojo/services/network/interfaces/net_address.mojom.h" | 24 #include "mojo/services/network/interfaces/net_address.mojom.h" |
| 25 #include "shell/kPingable.h" | 25 #include "shell/kPingable.h" |
| 26 #include "shell/test/pingable.mojom.h" | 26 #include "shell/test/pingable.mojom.h" |
| 27 | 27 |
| (...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 74 | 74 |
| 75 class ShellHTTPAppTest : public ShellAppTest { | 75 class ShellHTTPAppTest : public ShellAppTest { |
| 76 public: | 76 public: |
| 77 ShellHTTPAppTest() {} | 77 ShellHTTPAppTest() {} |
| 78 ~ShellHTTPAppTest() override {} | 78 ~ShellHTTPAppTest() override {} |
| 79 | 79 |
| 80 protected: | 80 protected: |
| 81 void SetUp() override { | 81 void SetUp() override { |
| 82 ShellAppTest::SetUp(); | 82 ShellAppTest::SetUp(); |
| 83 | 83 |
| 84 mojo::ConnectToService(application_impl()->shell(), "mojo:http_server", | 84 mojo::ConnectToService(shell(), "mojo:http_server", |
| 85 GetProxy(&http_server_factory_)); | 85 GetProxy(&http_server_factory_)); |
| 86 | 86 |
| 87 mojo::NetAddressPtr local_address(mojo::NetAddress::New()); | 87 mojo::NetAddressPtr local_address(mojo::NetAddress::New()); |
| 88 local_address->family = mojo::NetAddressFamily::IPV4; | 88 local_address->family = mojo::NetAddressFamily::IPV4; |
| 89 local_address->ipv4 = mojo::NetAddressIPv4::New(); | 89 local_address->ipv4 = mojo::NetAddressIPv4::New(); |
| 90 local_address->ipv4->addr.resize(4); | 90 local_address->ipv4->addr.resize(4); |
| 91 local_address->ipv4->addr[0] = 127; | 91 local_address->ipv4->addr[0] = 127; |
| 92 local_address->ipv4->addr[1] = 0; | 92 local_address->ipv4->addr[1] = 0; |
| 93 local_address->ipv4->addr[2] = 0; | 93 local_address->ipv4->addr[2] = 0; |
| 94 local_address->ipv4->addr[3] = 1; | 94 local_address->ipv4->addr[3] = 1; |
| (...skipping 17 matching lines...) Expand all Loading... |
| 112 scoped_ptr<GetHandler> handler_; | 112 scoped_ptr<GetHandler> handler_; |
| 113 uint16_t port_; | 113 uint16_t port_; |
| 114 | 114 |
| 115 private: | 115 private: |
| 116 MOJO_DISALLOW_COPY_AND_ASSIGN(ShellHTTPAppTest); | 116 MOJO_DISALLOW_COPY_AND_ASSIGN(ShellHTTPAppTest); |
| 117 }; | 117 }; |
| 118 | 118 |
| 119 // Test that we can load apps over http. | 119 // Test that we can load apps over http. |
| 120 TEST_F(ShellHTTPAppTest, Http) { | 120 TEST_F(ShellHTTPAppTest, Http) { |
| 121 PingablePtr pingable; | 121 PingablePtr pingable; |
| 122 mojo::ConnectToService(application_impl()->shell(), GetURL("app"), | 122 mojo::ConnectToService(shell(), GetURL("app"), GetProxy(&pingable)); |
| 123 GetProxy(&pingable)); | |
| 124 pingable->Ping("hello", | 123 pingable->Ping("hello", |
| 125 [this](const String& app_url, const String& connection_url, | 124 [this](const String& app_url, const String& connection_url, |
| 126 const String& message) { | 125 const String& message) { |
| 127 EXPECT_EQ(GetURL("app"), app_url); | 126 EXPECT_EQ(GetURL("app"), app_url); |
| 128 EXPECT_EQ(GetURL("app"), connection_url); | 127 EXPECT_EQ(GetURL("app"), connection_url); |
| 129 EXPECT_EQ("hello", message); | 128 EXPECT_EQ("hello", message); |
| 130 base::MessageLoop::current()->Quit(); | 129 base::MessageLoop::current()->Quit(); |
| 131 }); | 130 }); |
| 132 base::RunLoop().Run(); | 131 base::RunLoop().Run(); |
| 133 } | 132 } |
| 134 | 133 |
| 135 // Test that redirects work. | 134 // Test that redirects work. |
| 136 // TODO(aa): Test that apps receive the correct URL parameters. | 135 // TODO(aa): Test that apps receive the correct URL parameters. |
| 137 TEST_F(ShellHTTPAppTest, Redirect) { | 136 TEST_F(ShellHTTPAppTest, Redirect) { |
| 138 PingablePtr pingable; | 137 PingablePtr pingable; |
| 139 mojo::ConnectToService(application_impl()->shell(), GetURL("redirect"), | 138 mojo::ConnectToService(shell(), GetURL("redirect"), GetProxy(&pingable)); |
| 140 GetProxy(&pingable)); | |
| 141 pingable->Ping("hello", | 139 pingable->Ping("hello", |
| 142 [this](const String& app_url, const String& connection_url, | 140 [this](const String& app_url, const String& connection_url, |
| 143 const String& message) { | 141 const String& message) { |
| 144 EXPECT_EQ(GetURL("app"), app_url); | 142 EXPECT_EQ(GetURL("app"), app_url); |
| 145 EXPECT_EQ(GetURL("app"), connection_url); | 143 EXPECT_EQ(GetURL("app"), connection_url); |
| 146 EXPECT_EQ("hello", message); | 144 EXPECT_EQ("hello", message); |
| 147 base::MessageLoop::current()->Quit(); | 145 base::MessageLoop::current()->Quit(); |
| 148 }); | 146 }); |
| 149 base::RunLoop().Run(); | 147 base::RunLoop().Run(); |
| 150 } | 148 } |
| 151 | 149 |
| 152 // Test that querystring is not considered when resolving http applications. | 150 // Test that querystring is not considered when resolving http applications. |
| 153 // TODO(aa|qsr): Fix this test on Linux ASAN http://crbug.com/463662 | 151 // TODO(aa|qsr): Fix this test on Linux ASAN http://crbug.com/463662 |
| 154 #if defined(ADDRESS_SANITIZER) | 152 #if defined(ADDRESS_SANITIZER) |
| 155 #define MAYBE_QueryHandling DISABLED_QueryHandling | 153 #define MAYBE_QueryHandling DISABLED_QueryHandling |
| 156 #else | 154 #else |
| 157 #define MAYBE_QueryHandling QueryHandling | 155 #define MAYBE_QueryHandling QueryHandling |
| 158 #endif // ADDRESS_SANITIZER | 156 #endif // ADDRESS_SANITIZER |
| 159 TEST_F(ShellHTTPAppTest, MAYBE_QueryHandling) { | 157 TEST_F(ShellHTTPAppTest, MAYBE_QueryHandling) { |
| 160 PingablePtr pingable1; | 158 PingablePtr pingable1; |
| 161 PingablePtr pingable2; | 159 PingablePtr pingable2; |
| 162 mojo::ConnectToService(application_impl()->shell(), GetURL("app?foo"), | 160 mojo::ConnectToService(shell(), GetURL("app?foo"), GetProxy(&pingable1)); |
| 163 GetProxy(&pingable1)); | 161 mojo::ConnectToService(shell(), GetURL("app?bar"), GetProxy(&pingable2)); |
| 164 mojo::ConnectToService(application_impl()->shell(), GetURL("app?bar"), | |
| 165 GetProxy(&pingable2)); | |
| 166 | 162 |
| 167 int num_responses = 0; | 163 int num_responses = 0; |
| 168 auto callbacks_builder = [this, &num_responses](int query_index) { | 164 auto callbacks_builder = [this, &num_responses](int query_index) { |
| 169 return [this, &num_responses, query_index](const String& app_url, | 165 return [this, &num_responses, query_index](const String& app_url, |
| 170 const String& connection_url, | 166 const String& connection_url, |
| 171 const String& message) { | 167 const String& message) { |
| 172 EXPECT_EQ(GetURL("app"), app_url); | 168 EXPECT_EQ(GetURL("app"), app_url); |
| 173 EXPECT_EQ("hello", message); | 169 EXPECT_EQ("hello", message); |
| 174 if (query_index == 1) { | 170 if (query_index == 1) { |
| 175 EXPECT_EQ(GetURL("app?foo"), connection_url); | 171 EXPECT_EQ(GetURL("app?foo"), connection_url); |
| 176 } else if (query_index == 2) { | 172 } else if (query_index == 2) { |
| 177 EXPECT_EQ(GetURL("app?bar"), connection_url); | 173 EXPECT_EQ(GetURL("app?bar"), connection_url); |
| 178 } else { | 174 } else { |
| 179 CHECK(false); | 175 CHECK(false); |
| 180 } | 176 } |
| 181 ++num_responses; | 177 ++num_responses; |
| 182 if (num_responses == 2) | 178 if (num_responses == 2) |
| 183 base::MessageLoop::current()->Quit(); | 179 base::MessageLoop::current()->Quit(); |
| 184 }; | 180 }; |
| 185 }; | 181 }; |
| 186 pingable1->Ping("hello", callbacks_builder(1)); | 182 pingable1->Ping("hello", callbacks_builder(1)); |
| 187 pingable2->Ping("hello", callbacks_builder(2)); | 183 pingable2->Ping("hello", callbacks_builder(2)); |
| 188 base::RunLoop().Run(); | 184 base::RunLoop().Run(); |
| 189 } | 185 } |
| 190 | 186 |
| 191 // mojo: URLs can have querystrings too | 187 // mojo: URLs can have querystrings too |
| 192 TEST_F(ShellAppTest, MojoURLQueryHandling) { | 188 TEST_F(ShellAppTest, MojoURLQueryHandling) { |
| 193 PingablePtr pingable; | 189 PingablePtr pingable; |
| 194 mojo::ConnectToService(application_impl()->shell(), "mojo:pingable_app?foo", | 190 mojo::ConnectToService(shell(), "mojo:pingable_app?foo", GetProxy(&pingable)); |
| 195 GetProxy(&pingable)); | |
| 196 auto callback = [](const String& app_url, const String& connection_url, | 191 auto callback = [](const String& app_url, const String& connection_url, |
| 197 const String& message) { | 192 const String& message) { |
| 198 EXPECT_TRUE(base::EndsWith(app_url.To<base::StringPiece>(), | 193 EXPECT_TRUE(base::EndsWith(app_url.To<base::StringPiece>(), |
| 199 "/pingable_app.mojo", | 194 "/pingable_app.mojo", |
| 200 base::CompareCase::SENSITIVE)); | 195 base::CompareCase::SENSITIVE)); |
| 201 EXPECT_EQ(app_url.To<std::string>() + "?foo", connection_url); | 196 EXPECT_EQ(app_url.To<std::string>() + "?foo", connection_url); |
| 202 EXPECT_EQ("hello", message); | 197 EXPECT_EQ("hello", message); |
| 203 base::MessageLoop::current()->Quit(); | 198 base::MessageLoop::current()->Quit(); |
| 204 }; | 199 }; |
| 205 pingable->Ping("hello", callback); | 200 pingable->Ping("hello", callback); |
| (...skipping 11 matching lines...) Expand all Loading... |
| 217 EXPECT_EQ(app_url, connection_url); | 212 EXPECT_EQ(app_url, connection_url); |
| 218 EXPECT_EQ("hello", message); | 213 EXPECT_EQ("hello", message); |
| 219 base::MessageLoop::current()->Quit(); | 214 base::MessageLoop::current()->Quit(); |
| 220 }; | 215 }; |
| 221 pingable->Ping("hello", callback); | 216 pingable->Ping("hello", callback); |
| 222 base::RunLoop().Run(); | 217 base::RunLoop().Run(); |
| 223 } | 218 } |
| 224 | 219 |
| 225 TEST_F(ShellAppTest, ApplicationConnector) { | 220 TEST_F(ShellAppTest, ApplicationConnector) { |
| 226 mojo::ApplicationConnectorPtr app_connector; | 221 mojo::ApplicationConnectorPtr app_connector; |
| 227 app_connector.Bind( | 222 app_connector.Bind(mojo::CreateApplicationConnector(shell())); |
| 228 mojo::CreateApplicationConnector(application_impl()->shell())); | |
| 229 TestApplicationConnector(app_connector.get()); | 223 TestApplicationConnector(app_connector.get()); |
| 230 } | 224 } |
| 231 | 225 |
| 232 TEST_F(ShellAppTest, ApplicationConnectorDuplicate) { | 226 TEST_F(ShellAppTest, ApplicationConnectorDuplicate) { |
| 233 mojo::ApplicationConnectorPtr app_connector1; | 227 mojo::ApplicationConnectorPtr app_connector1; |
| 234 app_connector1.Bind( | 228 app_connector1.Bind(mojo::CreateApplicationConnector(shell())); |
| 235 mojo::CreateApplicationConnector(application_impl()->shell())); | |
| 236 { | 229 { |
| 237 SCOPED_TRACE("app_connector1"); | 230 SCOPED_TRACE("app_connector1"); |
| 238 TestApplicationConnector(app_connector1.get()); | 231 TestApplicationConnector(app_connector1.get()); |
| 239 } | 232 } |
| 240 | 233 |
| 241 mojo::ApplicationConnectorPtr app_connector2; | 234 mojo::ApplicationConnectorPtr app_connector2; |
| 242 app_connector1->Duplicate(GetProxy(&app_connector2)); | 235 app_connector1->Duplicate(GetProxy(&app_connector2)); |
| 243 { | 236 { |
| 244 SCOPED_TRACE("app_connector2"); | 237 SCOPED_TRACE("app_connector2"); |
| 245 TestApplicationConnector(app_connector2.get()); | 238 TestApplicationConnector(app_connector2.get()); |
| 246 } | 239 } |
| 247 | 240 |
| 248 // The first one should still work. | 241 // The first one should still work. |
| 249 { | 242 { |
| 250 SCOPED_TRACE("app_connector1 again"); | 243 SCOPED_TRACE("app_connector1 again"); |
| 251 TestApplicationConnector(app_connector1.get()); | 244 TestApplicationConnector(app_connector1.get()); |
| 252 } | 245 } |
| 253 } | 246 } |
| 254 | 247 |
| 255 } // namespace | 248 } // namespace |
| OLD | NEW |