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" |
(...skipping 59 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 shell()->ConnectToService("mojo:http_server", &http_server_factory_); | 80 shell()->ConnectToInterface("mojo:http_server", &http_server_factory_); |
81 | 81 |
82 NetAddressPtr local_address(NetAddress::New()); | 82 NetAddressPtr local_address(NetAddress::New()); |
83 local_address->family = NET_ADDRESS_FAMILY_IPV4; | 83 local_address->family = NET_ADDRESS_FAMILY_IPV4; |
84 local_address->ipv4 = NetAddressIPv4::New(); | 84 local_address->ipv4 = NetAddressIPv4::New(); |
85 local_address->ipv4->addr.resize(4); | 85 local_address->ipv4->addr.resize(4); |
86 local_address->ipv4->addr[0] = 127; | 86 local_address->ipv4->addr[0] = 127; |
87 local_address->ipv4->addr[1] = 0; | 87 local_address->ipv4->addr[1] = 0; |
88 local_address->ipv4->addr[2] = 0; | 88 local_address->ipv4->addr[2] = 0; |
89 local_address->ipv4->addr[3] = 1; | 89 local_address->ipv4->addr[3] = 1; |
90 local_address->ipv4->port = 0; | 90 local_address->ipv4->port = 0; |
(...skipping 19 matching lines...) Expand all Loading... |
110 scoped_ptr<GetHandler> handler_; | 110 scoped_ptr<GetHandler> handler_; |
111 uint16_t port_; | 111 uint16_t port_; |
112 | 112 |
113 private: | 113 private: |
114 MOJO_DISALLOW_COPY_AND_ASSIGN(ShellHTTPAppTest); | 114 MOJO_DISALLOW_COPY_AND_ASSIGN(ShellHTTPAppTest); |
115 }; | 115 }; |
116 | 116 |
117 // Test that we can load apps over http. | 117 // Test that we can load apps over http. |
118 TEST_F(ShellHTTPAppTest, Http) { | 118 TEST_F(ShellHTTPAppTest, Http) { |
119 InterfacePtr<Pingable> pingable; | 119 InterfacePtr<Pingable> pingable; |
120 shell()->ConnectToService(GetURL("app"), &pingable); | 120 shell()->ConnectToInterface(GetURL("app"), &pingable); |
121 pingable->Ping("hello", | 121 pingable->Ping("hello", |
122 [this](const String& app_url, const String& connection_url, | 122 [this](const String& app_url, const String& connection_url, |
123 const String& message) { | 123 const String& message) { |
124 EXPECT_EQ(GetURL("app"), app_url); | 124 EXPECT_EQ(GetURL("app"), app_url); |
125 EXPECT_EQ(GetURL("app"), connection_url); | 125 EXPECT_EQ(GetURL("app"), connection_url); |
126 EXPECT_EQ("hello", message); | 126 EXPECT_EQ("hello", message); |
127 base::MessageLoop::current()->QuitWhenIdle(); | 127 base::MessageLoop::current()->QuitWhenIdle(); |
128 }); | 128 }); |
129 base::RunLoop().Run(); | 129 base::RunLoop().Run(); |
130 } | 130 } |
131 | 131 |
132 // Test that redirects work. | 132 // Test that redirects work. |
133 // TODO(aa): Test that apps receive the correct URL parameters. | 133 // TODO(aa): Test that apps receive the correct URL parameters. |
134 TEST_F(ShellHTTPAppTest, Redirect) { | 134 TEST_F(ShellHTTPAppTest, Redirect) { |
135 InterfacePtr<Pingable> pingable; | 135 InterfacePtr<Pingable> pingable; |
136 shell()->ConnectToService(GetURL("redirect"), &pingable); | 136 shell()->ConnectToInterface(GetURL("redirect"), &pingable); |
137 pingable->Ping("hello", | 137 pingable->Ping("hello", |
138 [this](const String& app_url, const String& connection_url, | 138 [this](const String& app_url, const String& connection_url, |
139 const String& message) { | 139 const String& message) { |
140 EXPECT_EQ(GetURL("app"), app_url); | 140 EXPECT_EQ(GetURL("app"), app_url); |
141 EXPECT_EQ(GetURL("app"), connection_url); | 141 EXPECT_EQ(GetURL("app"), connection_url); |
142 EXPECT_EQ("hello", message); | 142 EXPECT_EQ("hello", message); |
143 base::MessageLoop::current()->QuitWhenIdle(); | 143 base::MessageLoop::current()->QuitWhenIdle(); |
144 }); | 144 }); |
145 base::RunLoop().Run(); | 145 base::RunLoop().Run(); |
146 } | 146 } |
147 | 147 |
148 // Test that querystring is not considered when resolving http applications. | 148 // Test that querystring is not considered when resolving http applications. |
149 // 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 |
150 #if defined(ADDRESS_SANITIZER) | 150 #if defined(ADDRESS_SANITIZER) |
151 #define MAYBE_QueryHandling DISABLED_QueryHandling | 151 #define MAYBE_QueryHandling DISABLED_QueryHandling |
152 #else | 152 #else |
153 #define MAYBE_QueryHandling QueryHandling | 153 #define MAYBE_QueryHandling QueryHandling |
154 #endif // ADDRESS_SANITIZER | 154 #endif // ADDRESS_SANITIZER |
155 TEST_F(ShellHTTPAppTest, MAYBE_QueryHandling) { | 155 TEST_F(ShellHTTPAppTest, MAYBE_QueryHandling) { |
156 InterfacePtr<Pingable> pingable1; | 156 InterfacePtr<Pingable> pingable1; |
157 InterfacePtr<Pingable> pingable2; | 157 InterfacePtr<Pingable> pingable2; |
158 shell()->ConnectToService(GetURL("app?foo"), &pingable1); | 158 shell()->ConnectToInterface(GetURL("app?foo"), &pingable1); |
159 shell()->ConnectToService(GetURL("app?bar"), &pingable2); | 159 shell()->ConnectToInterface(GetURL("app?bar"), &pingable2); |
160 | 160 |
161 int num_responses = 0; | 161 int num_responses = 0; |
162 auto callback = [this, &num_responses](const String& app_url, | 162 auto callback = [this, &num_responses](const String& app_url, |
163 const String& connection_url, | 163 const String& connection_url, |
164 const String& message) { | 164 const String& message) { |
165 EXPECT_EQ(GetURL("app"), app_url); | 165 EXPECT_EQ(GetURL("app"), app_url); |
166 EXPECT_EQ("hello", message); | 166 EXPECT_EQ("hello", message); |
167 ++num_responses; | 167 ++num_responses; |
168 if (num_responses == 1) { | 168 if (num_responses == 1) { |
169 EXPECT_EQ(GetURL("app?foo"), connection_url); | 169 EXPECT_EQ(GetURL("app?foo"), connection_url); |
170 } else if (num_responses == 2) { | 170 } else if (num_responses == 2) { |
171 EXPECT_EQ(GetURL("app?bar"), connection_url); | 171 EXPECT_EQ(GetURL("app?bar"), connection_url); |
172 base::MessageLoop::current()->QuitWhenIdle(); | 172 base::MessageLoop::current()->QuitWhenIdle(); |
173 } else { | 173 } else { |
174 CHECK(false); | 174 CHECK(false); |
175 } | 175 } |
176 }; | 176 }; |
177 pingable1->Ping("hello", callback); | 177 pingable1->Ping("hello", callback); |
178 pingable2->Ping("hello", callback); | 178 pingable2->Ping("hello", callback); |
179 base::RunLoop().Run(); | 179 base::RunLoop().Run(); |
180 } | 180 } |
181 | 181 |
182 // mojo: URLs can have querystrings too | 182 // mojo: URLs can have querystrings too |
183 TEST_F(ShellAppTest, MojoURLQueryHandling) { | 183 TEST_F(ShellAppTest, MojoURLQueryHandling) { |
184 InterfacePtr<Pingable> pingable; | 184 InterfacePtr<Pingable> pingable; |
185 shell()->ConnectToService("mojo:pingable_app?foo", &pingable); | 185 shell()->ConnectToInterface("mojo:pingable_app?foo", &pingable); |
186 auto callback = [this](const String& app_url, const String& connection_url, | 186 auto callback = [this](const String& app_url, const String& connection_url, |
187 const String& message) { | 187 const String& message) { |
188 EXPECT_TRUE(base::EndsWith(app_url, "/pingable_app.mojo", | 188 EXPECT_TRUE(base::EndsWith(app_url, "/pingable_app.mojo", |
189 base::CompareCase::SENSITIVE)); | 189 base::CompareCase::SENSITIVE)); |
190 EXPECT_EQ(app_url.To<std::string>() + "?foo", connection_url); | 190 EXPECT_EQ(app_url.To<std::string>() + "?foo", connection_url); |
191 EXPECT_EQ("hello", message); | 191 EXPECT_EQ("hello", message); |
192 base::MessageLoop::current()->QuitWhenIdle(); | 192 base::MessageLoop::current()->QuitWhenIdle(); |
193 }; | 193 }; |
194 pingable->Ping("hello", callback); | 194 pingable->Ping("hello", callback); |
195 base::RunLoop().Run(); | 195 base::RunLoop().Run(); |
196 } | 196 } |
197 | 197 |
198 } // namespace | 198 } // namespace |
199 } // namespace mojo | 199 } // namespace mojo |
OLD | NEW |