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/common/data_pipe_utils.h" | 13 #include "mojo/common/data_pipe_utils.h" |
14 #include "mojo/public/cpp/application/application_impl.h" | 14 #include "mojo/public/cpp/application/application_impl.h" |
15 #include "mojo/public/cpp/application/application_test_base.h" | 15 #include "mojo/public/cpp/application/application_test_base.h" |
16 #include "mojo/public/cpp/system/macros.h" | 16 #include "mojo/public/cpp/system/macros.h" |
17 #include "mojo/services/http_server/public/cpp/http_server_util.h" | 17 #include "mojo/services/http_server/public/cpp/http_server_util.h" |
18 #include "mojo/services/http_server/public/interfaces/http_server.mojom.h" | 18 #include "mojo/services/http_server/public/interfaces/http_server.mojom.h" |
19 #include "mojo/services/http_server/public/interfaces/http_server_factory.mojom.
h" | 19 #include "mojo/services/http_server/public/interfaces/http_server_factory.mojom.
h" |
20 #include "mojo/services/network/public/interfaces/net_address.mojom.h" | 20 #include "mojo/services/network/public/interfaces/net_address.mojom.h" |
21 #include "shell/kPingable.h" | 21 #include "shell/kPingable.h" |
22 #include "shell/test/pingable.mojom.h" | 22 #include "shell/test/pingable.mojom.h" |
23 | 23 |
| 24 using mojo::String; |
| 25 |
24 namespace { | 26 namespace { |
25 | 27 |
26 std::string GetURL(uint16_t port, const std::string& path) { | 28 std::string GetURL(uint16_t port, const std::string& path) { |
27 return base::StringPrintf("http://127.0.0.1:%u/%s", | 29 return base::StringPrintf("http://127.0.0.1:%u/%s", |
28 static_cast<unsigned>(port), path.c_str()); | 30 static_cast<unsigned>(port), path.c_str()); |
29 } | 31 } |
30 | 32 |
31 class GetHandler : public http_server::HttpHandler { | 33 class GetHandler : public http_server::HttpHandler { |
32 public: | 34 public: |
33 GetHandler(mojo::InterfaceRequest<http_server::HttpHandler> request, | 35 GetHandler(mojo::InterfaceRequest<http_server::HttpHandler> request, |
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
107 uint16_t port_; | 109 uint16_t port_; |
108 | 110 |
109 private: | 111 private: |
110 MOJO_DISALLOW_COPY_AND_ASSIGN(ShellHTTPAppTest); | 112 MOJO_DISALLOW_COPY_AND_ASSIGN(ShellHTTPAppTest); |
111 }; | 113 }; |
112 | 114 |
113 // Test that we can load apps over http. | 115 // Test that we can load apps over http. |
114 TEST_F(ShellHTTPAppTest, Http) { | 116 TEST_F(ShellHTTPAppTest, Http) { |
115 PingablePtr pingable; | 117 PingablePtr pingable; |
116 application_impl()->ConnectToService(GetURL("app"), &pingable); | 118 application_impl()->ConnectToService(GetURL("app"), &pingable); |
117 pingable->Ping("hello", [this](const mojo::String& app_url, | 119 pingable->Ping("hello", |
118 const mojo::String& connection_url, | 120 [this](const String& app_url, const String& connection_url, |
119 const mojo::String& message) { | 121 const String& message) { |
120 EXPECT_EQ(GetURL("app"), app_url); | 122 EXPECT_EQ(GetURL("app"), app_url); |
121 EXPECT_EQ(GetURL("app"), connection_url); | 123 EXPECT_EQ(GetURL("app"), connection_url); |
122 EXPECT_EQ("hello", message); | 124 EXPECT_EQ("hello", message); |
123 base::MessageLoop::current()->Quit(); | 125 base::MessageLoop::current()->Quit(); |
124 }); | 126 }); |
125 base::RunLoop().Run(); | 127 base::RunLoop().Run(); |
126 } | 128 } |
127 | 129 |
128 // Test that redirects work. | 130 // Test that redirects work. |
129 // TODO(aa): Test that apps receive the correct URL parameters. | 131 // TODO(aa): Test that apps receive the correct URL parameters. |
130 TEST_F(ShellHTTPAppTest, Redirect) { | 132 TEST_F(ShellHTTPAppTest, Redirect) { |
131 PingablePtr pingable; | 133 PingablePtr pingable; |
132 application_impl()->ConnectToService(GetURL("redirect"), &pingable); | 134 application_impl()->ConnectToService(GetURL("redirect"), &pingable); |
133 pingable->Ping("hello", [this](const mojo::String& app_url, | 135 pingable->Ping("hello", |
134 const mojo::String& connection_url, | 136 [this](const String& app_url, const String& connection_url, |
135 const mojo::String& message) { | 137 const String& message) { |
136 EXPECT_EQ(GetURL("app"), app_url); | 138 EXPECT_EQ(GetURL("app"), app_url); |
137 EXPECT_EQ(GetURL("app"), connection_url); | 139 EXPECT_EQ(GetURL("app"), connection_url); |
138 EXPECT_EQ("hello", message); | 140 EXPECT_EQ("hello", message); |
139 base::MessageLoop::current()->Quit(); | 141 base::MessageLoop::current()->Quit(); |
140 }); | 142 }); |
141 base::RunLoop().Run(); | 143 base::RunLoop().Run(); |
142 } | 144 } |
143 | 145 |
144 // Test that querystring is not considered when resolving http applications. | 146 // Test that querystring is not considered when resolving http applications. |
145 // TODO(aa|qsr): Fix this test on Linux ASAN http://crbug.com/463662 | 147 // TODO(aa|qsr): Fix this test on Linux ASAN http://crbug.com/463662 |
146 #if defined(ADDRESS_SANITIZER) | 148 #if defined(ADDRESS_SANITIZER) |
147 #define MAYBE_QueryHandling DISABLED_QueryHandling | 149 #define MAYBE_QueryHandling DISABLED_QueryHandling |
148 #else | 150 #else |
149 #define MAYBE_QueryHandling QueryHandling | 151 #define MAYBE_QueryHandling QueryHandling |
150 #endif // ADDRESS_SANITIZER | 152 #endif // ADDRESS_SANITIZER |
151 TEST_F(ShellHTTPAppTest, MAYBE_QueryHandling) { | 153 TEST_F(ShellHTTPAppTest, MAYBE_QueryHandling) { |
152 PingablePtr pingable1; | 154 PingablePtr pingable1; |
153 PingablePtr pingable2; | 155 PingablePtr pingable2; |
154 application_impl()->ConnectToService(GetURL("app?foo"), &pingable1); | 156 application_impl()->ConnectToService(GetURL("app?foo"), &pingable1); |
155 application_impl()->ConnectToService(GetURL("app?bar"), &pingable2); | 157 application_impl()->ConnectToService(GetURL("app?bar"), &pingable2); |
156 | 158 |
157 int num_responses = 0; | 159 int num_responses = 0; |
158 auto callback = [this, &num_responses](const mojo::String& app_url, | 160 auto callback = [this, &num_responses](const String& app_url, |
159 const mojo::String& connection_url, | 161 const String& connection_url, |
160 const mojo::String& message) { | 162 const String& message) { |
161 EXPECT_EQ(GetURL("app"), app_url); | 163 EXPECT_EQ(GetURL("app"), app_url); |
162 EXPECT_EQ("hello", message); | 164 EXPECT_EQ("hello", message); |
163 ++num_responses; | 165 ++num_responses; |
164 if (num_responses == 1) { | 166 if (num_responses == 1) { |
165 EXPECT_EQ(GetURL("app?foo"), connection_url); | 167 EXPECT_EQ(GetURL("app?foo"), connection_url); |
166 } else if (num_responses == 2) { | 168 } else if (num_responses == 2) { |
167 EXPECT_EQ(GetURL("app?bar"), connection_url); | 169 EXPECT_EQ(GetURL("app?bar"), connection_url); |
168 base::MessageLoop::current()->Quit(); | 170 base::MessageLoop::current()->Quit(); |
169 } else { | 171 } else { |
170 CHECK(false); | 172 CHECK(false); |
171 } | 173 } |
172 }; | 174 }; |
173 pingable1->Ping("hello", callback); | 175 pingable1->Ping("hello", callback); |
174 pingable2->Ping("hello", callback); | 176 pingable2->Ping("hello", callback); |
175 base::RunLoop().Run(); | 177 base::RunLoop().Run(); |
176 } | 178 } |
177 | 179 |
178 // mojo: URLs can have querystrings too | 180 // mojo: URLs can have querystrings too |
179 TEST_F(ShellAppTest, MojoURLQueryHandling) { | 181 TEST_F(ShellAppTest, MojoURLQueryHandling) { |
180 PingablePtr pingable; | 182 PingablePtr pingable; |
181 application_impl()->ConnectToService("mojo:pingable_app?foo", &pingable); | 183 application_impl()->ConnectToService("mojo:pingable_app?foo", &pingable); |
182 auto callback = | 184 auto callback = [this](const String& app_url, const String& connection_url, |
183 [this](const mojo::String& app_url, const mojo::String& connection_url, | 185 const String& message) { |
184 const mojo::String& message) { | 186 EXPECT_TRUE(EndsWith(app_url, "/pingable_app.mojo", true)); |
185 EXPECT_TRUE(EndsWith(app_url, "/pingable_app.mojo", true)); | 187 EXPECT_EQ(app_url.To<std::string>() + "?foo", connection_url); |
186 EXPECT_EQ(app_url.To<std::string>() + "?foo", connection_url); | 188 EXPECT_EQ("hello", message); |
187 EXPECT_EQ("hello", message); | 189 base::MessageLoop::current()->Quit(); |
188 base::MessageLoop::current()->Quit(); | 190 }; |
189 }; | |
190 pingable->Ping("hello", callback); | 191 pingable->Ping("hello", callback); |
191 base::RunLoop().Run(); | 192 base::RunLoop().Run(); |
192 } | 193 } |
193 | 194 |
194 } // namespace | 195 } // namespace |
OLD | NEW |