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 <stdint.h> | 5 #include <stdint.h> |
6 | 6 |
7 #include "base/base_paths.h" | 7 #include "base/base_paths.h" |
8 #include "base/bind.h" | 8 #include "base/bind.h" |
9 #include "base/files/file_path.h" | 9 #include "base/files/file_path.h" |
10 #include "base/files/file_util.h" | 10 #include "base/files/file_util.h" |
11 #include "base/path_service.h" | 11 #include "base/path_service.h" |
12 #include "base/run_loop.h" | 12 #include "base/run_loop.h" |
13 #include "base/strings/string_util.h" | 13 #include "base/strings/string_util.h" |
14 #include "base/strings/stringprintf.h" | 14 #include "base/strings/stringprintf.h" |
15 #include "mojo/common/data_pipe_utils.h" | 15 #include "mojo/common/data_pipe_utils.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 "mojo/shell/public/cpp/application_impl.h" | |
22 #include "mojo/shell/public/cpp/application_test_base.h" | 21 #include "mojo/shell/public/cpp/application_test_base.h" |
| 22 #include "mojo/shell/public/cpp/shell.h" |
23 #include "mojo/shell/standalone/kPingable.h" | 23 #include "mojo/shell/standalone/kPingable.h" |
24 #include "mojo/shell/standalone/test/pingable.mojom.h" | 24 #include "mojo/shell/standalone/test/pingable.mojom.h" |
25 | 25 |
26 namespace mojo { | 26 namespace mojo { |
27 namespace { | 27 namespace { |
28 | 28 |
29 std::string GetURL(uint16_t port, const std::string& path) { | 29 std::string GetURL(uint16_t port, const std::string& path) { |
30 return base::StringPrintf("http://127.0.0.1:%u/%s", | 30 return base::StringPrintf("http://127.0.0.1:%u/%s", |
31 static_cast<unsigned>(port), path.c_str()); | 31 static_cast<unsigned>(port), path.c_str()); |
32 } | 32 } |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
70 class ShellHTTPAppTest : public test::ApplicationTestBase { | 70 class ShellHTTPAppTest : public test::ApplicationTestBase { |
71 public: | 71 public: |
72 ShellHTTPAppTest() : ApplicationTestBase() {} | 72 ShellHTTPAppTest() : ApplicationTestBase() {} |
73 ~ShellHTTPAppTest() override {} | 73 ~ShellHTTPAppTest() override {} |
74 | 74 |
75 protected: | 75 protected: |
76 // ApplicationTestBase: | 76 // ApplicationTestBase: |
77 void SetUp() override { | 77 void SetUp() override { |
78 ApplicationTestBase::SetUp(); | 78 ApplicationTestBase::SetUp(); |
79 | 79 |
80 application_impl()->ConnectToService("mojo:http_server", | 80 shell()->ConnectToService("mojo:http_server", &http_server_factory_); |
81 &http_server_factory_); | |
82 | 81 |
83 NetAddressPtr local_address(NetAddress::New()); | 82 NetAddressPtr local_address(NetAddress::New()); |
84 local_address->family = NET_ADDRESS_FAMILY_IPV4; | 83 local_address->family = NET_ADDRESS_FAMILY_IPV4; |
85 local_address->ipv4 = NetAddressIPv4::New(); | 84 local_address->ipv4 = NetAddressIPv4::New(); |
86 local_address->ipv4->addr.resize(4); | 85 local_address->ipv4->addr.resize(4); |
87 local_address->ipv4->addr[0] = 127; | 86 local_address->ipv4->addr[0] = 127; |
88 local_address->ipv4->addr[1] = 0; | 87 local_address->ipv4->addr[1] = 0; |
89 local_address->ipv4->addr[2] = 0; | 88 local_address->ipv4->addr[2] = 0; |
90 local_address->ipv4->addr[3] = 1; | 89 local_address->ipv4->addr[3] = 1; |
91 local_address->ipv4->port = 0; | 90 local_address->ipv4->port = 0; |
(...skipping 19 matching lines...) Expand all Loading... |
111 scoped_ptr<GetHandler> handler_; | 110 scoped_ptr<GetHandler> handler_; |
112 uint16_t port_; | 111 uint16_t port_; |
113 | 112 |
114 private: | 113 private: |
115 MOJO_DISALLOW_COPY_AND_ASSIGN(ShellHTTPAppTest); | 114 MOJO_DISALLOW_COPY_AND_ASSIGN(ShellHTTPAppTest); |
116 }; | 115 }; |
117 | 116 |
118 // Test that we can load apps over http. | 117 // Test that we can load apps over http. |
119 TEST_F(ShellHTTPAppTest, Http) { | 118 TEST_F(ShellHTTPAppTest, Http) { |
120 InterfacePtr<Pingable> pingable; | 119 InterfacePtr<Pingable> pingable; |
121 application_impl()->ConnectToService(GetURL("app"), &pingable); | 120 shell()->ConnectToService(GetURL("app"), &pingable); |
122 pingable->Ping("hello", | 121 pingable->Ping("hello", |
123 [this](const String& app_url, const String& connection_url, | 122 [this](const String& app_url, const String& connection_url, |
124 const String& message) { | 123 const String& message) { |
125 EXPECT_EQ(GetURL("app"), app_url); | 124 EXPECT_EQ(GetURL("app"), app_url); |
126 EXPECT_EQ(GetURL("app"), connection_url); | 125 EXPECT_EQ(GetURL("app"), connection_url); |
127 EXPECT_EQ("hello", message); | 126 EXPECT_EQ("hello", message); |
128 base::MessageLoop::current()->QuitWhenIdle(); | 127 base::MessageLoop::current()->QuitWhenIdle(); |
129 }); | 128 }); |
130 base::RunLoop().Run(); | 129 base::RunLoop().Run(); |
131 } | 130 } |
132 | 131 |
133 // Test that redirects work. | 132 // Test that redirects work. |
134 // TODO(aa): Test that apps receive the correct URL parameters. | 133 // TODO(aa): Test that apps receive the correct URL parameters. |
135 TEST_F(ShellHTTPAppTest, Redirect) { | 134 TEST_F(ShellHTTPAppTest, Redirect) { |
136 InterfacePtr<Pingable> pingable; | 135 InterfacePtr<Pingable> pingable; |
137 application_impl()->ConnectToService(GetURL("redirect"), &pingable); | 136 shell()->ConnectToService(GetURL("redirect"), &pingable); |
138 pingable->Ping("hello", | 137 pingable->Ping("hello", |
139 [this](const String& app_url, const String& connection_url, | 138 [this](const String& app_url, const String& connection_url, |
140 const String& message) { | 139 const String& message) { |
141 EXPECT_EQ(GetURL("app"), app_url); | 140 EXPECT_EQ(GetURL("app"), app_url); |
142 EXPECT_EQ(GetURL("app"), connection_url); | 141 EXPECT_EQ(GetURL("app"), connection_url); |
143 EXPECT_EQ("hello", message); | 142 EXPECT_EQ("hello", message); |
144 base::MessageLoop::current()->QuitWhenIdle(); | 143 base::MessageLoop::current()->QuitWhenIdle(); |
145 }); | 144 }); |
146 base::RunLoop().Run(); | 145 base::RunLoop().Run(); |
147 } | 146 } |
148 | 147 |
149 // Test that querystring is not considered when resolving http applications. | 148 // Test that querystring is not considered when resolving http applications. |
150 // TODO(aa|qsr): Fix this test on Linux ASAN http://crbug.com/463662 | 149 // TODO(aa|qsr): Fix this test on Linux ASAN http://crbug.com/463662 |
151 #if defined(ADDRESS_SANITIZER) | 150 #if defined(ADDRESS_SANITIZER) |
152 #define MAYBE_QueryHandling DISABLED_QueryHandling | 151 #define MAYBE_QueryHandling DISABLED_QueryHandling |
153 #else | 152 #else |
154 #define MAYBE_QueryHandling QueryHandling | 153 #define MAYBE_QueryHandling QueryHandling |
155 #endif // ADDRESS_SANITIZER | 154 #endif // ADDRESS_SANITIZER |
156 TEST_F(ShellHTTPAppTest, MAYBE_QueryHandling) { | 155 TEST_F(ShellHTTPAppTest, MAYBE_QueryHandling) { |
157 InterfacePtr<Pingable> pingable1; | 156 InterfacePtr<Pingable> pingable1; |
158 InterfacePtr<Pingable> pingable2; | 157 InterfacePtr<Pingable> pingable2; |
159 application_impl()->ConnectToService(GetURL("app?foo"), &pingable1); | 158 shell()->ConnectToService(GetURL("app?foo"), &pingable1); |
160 application_impl()->ConnectToService(GetURL("app?bar"), &pingable2); | 159 shell()->ConnectToService(GetURL("app?bar"), &pingable2); |
161 | 160 |
162 int num_responses = 0; | 161 int num_responses = 0; |
163 auto callback = [this, &num_responses](const String& app_url, | 162 auto callback = [this, &num_responses](const String& app_url, |
164 const String& connection_url, | 163 const String& connection_url, |
165 const String& message) { | 164 const String& message) { |
166 EXPECT_EQ(GetURL("app"), app_url); | 165 EXPECT_EQ(GetURL("app"), app_url); |
167 EXPECT_EQ("hello", message); | 166 EXPECT_EQ("hello", message); |
168 ++num_responses; | 167 ++num_responses; |
169 if (num_responses == 1) { | 168 if (num_responses == 1) { |
170 EXPECT_EQ(GetURL("app?foo"), connection_url); | 169 EXPECT_EQ(GetURL("app?foo"), connection_url); |
171 } else if (num_responses == 2) { | 170 } else if (num_responses == 2) { |
172 EXPECT_EQ(GetURL("app?bar"), connection_url); | 171 EXPECT_EQ(GetURL("app?bar"), connection_url); |
173 base::MessageLoop::current()->QuitWhenIdle(); | 172 base::MessageLoop::current()->QuitWhenIdle(); |
174 } else { | 173 } else { |
175 CHECK(false); | 174 CHECK(false); |
176 } | 175 } |
177 }; | 176 }; |
178 pingable1->Ping("hello", callback); | 177 pingable1->Ping("hello", callback); |
179 pingable2->Ping("hello", callback); | 178 pingable2->Ping("hello", callback); |
180 base::RunLoop().Run(); | 179 base::RunLoop().Run(); |
181 } | 180 } |
182 | 181 |
183 // mojo: URLs can have querystrings too | 182 // mojo: URLs can have querystrings too |
184 TEST_F(ShellAppTest, MojoURLQueryHandling) { | 183 TEST_F(ShellAppTest, MojoURLQueryHandling) { |
185 InterfacePtr<Pingable> pingable; | 184 InterfacePtr<Pingable> pingable; |
186 application_impl()->ConnectToService("mojo:pingable_app?foo", &pingable); | 185 shell()->ConnectToService("mojo:pingable_app?foo", &pingable); |
187 auto callback = [this](const String& app_url, const String& connection_url, | 186 auto callback = [this](const String& app_url, const String& connection_url, |
188 const String& message) { | 187 const String& message) { |
189 EXPECT_TRUE(base::EndsWith(app_url, "/pingable_app.mojo", | 188 EXPECT_TRUE(base::EndsWith(app_url, "/pingable_app.mojo", |
190 base::CompareCase::SENSITIVE)); | 189 base::CompareCase::SENSITIVE)); |
191 EXPECT_EQ(app_url.To<std::string>() + "?foo", connection_url); | 190 EXPECT_EQ(app_url.To<std::string>() + "?foo", connection_url); |
192 EXPECT_EQ("hello", message); | 191 EXPECT_EQ("hello", message); |
193 base::MessageLoop::current()->QuitWhenIdle(); | 192 base::MessageLoop::current()->QuitWhenIdle(); |
194 }; | 193 }; |
195 pingable->Ping("hello", callback); | 194 pingable->Ping("hello", callback); |
196 base::RunLoop().Run(); | 195 base::RunLoop().Run(); |
197 } | 196 } |
198 | 197 |
199 } // namespace | 198 } // namespace |
200 } // namespace mojo | 199 } // namespace mojo |
OLD | NEW |