Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(202)

Side by Side Diff: shell/shell_apptest.cc

Issue 1919313002: ApplicationImpl::ConnectToServiceDeprecated() -> mojo::ConnectToService() conversion, part 3. (Closed) Base URL: https://github.com/domokit/mojo.git@master
Patch Set: Created 4 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « shell/android/nfc_apptest.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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"
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after
73 73
74 class ShellHTTPAppTest : public ShellAppTest { 74 class ShellHTTPAppTest : public ShellAppTest {
75 public: 75 public:
76 ShellHTTPAppTest() {} 76 ShellHTTPAppTest() {}
77 ~ShellHTTPAppTest() override {} 77 ~ShellHTTPAppTest() override {}
78 78
79 protected: 79 protected:
80 void SetUp() override { 80 void SetUp() override {
81 ShellAppTest::SetUp(); 81 ShellAppTest::SetUp();
82 82
83 application_impl()->ConnectToServiceDeprecated("mojo:http_server", 83 mojo::ConnectToService(application_impl()->shell(), "mojo:http_server",
84 &http_server_factory_); 84 GetProxy(&http_server_factory_));
85 85
86 mojo::NetAddressPtr local_address(mojo::NetAddress::New()); 86 mojo::NetAddressPtr local_address(mojo::NetAddress::New());
87 local_address->family = mojo::NetAddressFamily::IPV4; 87 local_address->family = mojo::NetAddressFamily::IPV4;
88 local_address->ipv4 = mojo::NetAddressIPv4::New(); 88 local_address->ipv4 = mojo::NetAddressIPv4::New();
89 local_address->ipv4->addr.resize(4); 89 local_address->ipv4->addr.resize(4);
90 local_address->ipv4->addr[0] = 127; 90 local_address->ipv4->addr[0] = 127;
91 local_address->ipv4->addr[1] = 0; 91 local_address->ipv4->addr[1] = 0;
92 local_address->ipv4->addr[2] = 0; 92 local_address->ipv4->addr[2] = 0;
93 local_address->ipv4->addr[3] = 1; 93 local_address->ipv4->addr[3] = 1;
94 local_address->ipv4->port = 0; 94 local_address->ipv4->port = 0;
(...skipping 17 matching lines...) Expand all
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 application_impl()->ConnectToServiceDeprecated(GetURL("app"), &pingable); 122 mojo::ConnectToService(application_impl()->shell(), GetURL("app"),
123 GetProxy(&pingable));
123 pingable->Ping("hello", 124 pingable->Ping("hello",
124 [this](const String& app_url, const String& connection_url, 125 [this](const String& app_url, const String& connection_url,
125 const String& message) { 126 const String& message) {
126 EXPECT_EQ(GetURL("app"), app_url); 127 EXPECT_EQ(GetURL("app"), app_url);
127 EXPECT_EQ(GetURL("app"), connection_url); 128 EXPECT_EQ(GetURL("app"), connection_url);
128 EXPECT_EQ("hello", message); 129 EXPECT_EQ("hello", message);
129 base::MessageLoop::current()->Quit(); 130 base::MessageLoop::current()->Quit();
130 }); 131 });
131 base::RunLoop().Run(); 132 base::RunLoop().Run();
132 } 133 }
133 134
134 // Test that redirects work. 135 // Test that redirects work.
135 // TODO(aa): Test that apps receive the correct URL parameters. 136 // TODO(aa): Test that apps receive the correct URL parameters.
136 TEST_F(ShellHTTPAppTest, Redirect) { 137 TEST_F(ShellHTTPAppTest, Redirect) {
137 PingablePtr pingable; 138 PingablePtr pingable;
138 application_impl()->ConnectToServiceDeprecated(GetURL("redirect"), &pingable); 139 mojo::ConnectToService(application_impl()->shell(), GetURL("redirect"),
140 GetProxy(&pingable));
139 pingable->Ping("hello", 141 pingable->Ping("hello",
140 [this](const String& app_url, const String& connection_url, 142 [this](const String& app_url, const String& connection_url,
141 const String& message) { 143 const String& message) {
142 EXPECT_EQ(GetURL("app"), app_url); 144 EXPECT_EQ(GetURL("app"), app_url);
143 EXPECT_EQ(GetURL("app"), connection_url); 145 EXPECT_EQ(GetURL("app"), connection_url);
144 EXPECT_EQ("hello", message); 146 EXPECT_EQ("hello", message);
145 base::MessageLoop::current()->Quit(); 147 base::MessageLoop::current()->Quit();
146 }); 148 });
147 base::RunLoop().Run(); 149 base::RunLoop().Run();
148 } 150 }
149 151
150 // Test that querystring is not considered when resolving http applications. 152 // Test that querystring is not considered when resolving http applications.
151 // TODO(aa|qsr): Fix this test on Linux ASAN http://crbug.com/463662 153 // TODO(aa|qsr): Fix this test on Linux ASAN http://crbug.com/463662
152 #if defined(ADDRESS_SANITIZER) 154 #if defined(ADDRESS_SANITIZER)
153 #define MAYBE_QueryHandling DISABLED_QueryHandling 155 #define MAYBE_QueryHandling DISABLED_QueryHandling
154 #else 156 #else
155 #define MAYBE_QueryHandling QueryHandling 157 #define MAYBE_QueryHandling QueryHandling
156 #endif // ADDRESS_SANITIZER 158 #endif // ADDRESS_SANITIZER
157 TEST_F(ShellHTTPAppTest, MAYBE_QueryHandling) { 159 TEST_F(ShellHTTPAppTest, MAYBE_QueryHandling) {
158 PingablePtr pingable1; 160 PingablePtr pingable1;
159 PingablePtr pingable2; 161 PingablePtr pingable2;
160 application_impl()->ConnectToServiceDeprecated(GetURL("app?foo"), &pingable1); 162 mojo::ConnectToService(application_impl()->shell(), GetURL("app?foo"),
161 application_impl()->ConnectToServiceDeprecated(GetURL("app?bar"), &pingable2); 163 GetProxy(&pingable1));
164 mojo::ConnectToService(application_impl()->shell(), GetURL("app?bar"),
165 GetProxy(&pingable2));
162 166
163 int num_responses = 0; 167 int num_responses = 0;
164 auto callbacks_builder = [this, &num_responses](int query_index) { 168 auto callbacks_builder = [this, &num_responses](int query_index) {
165 return [this, &num_responses, query_index](const String& app_url, 169 return [this, &num_responses, query_index](const String& app_url,
166 const String& connection_url, 170 const String& connection_url,
167 const String& message) { 171 const String& message) {
168 EXPECT_EQ(GetURL("app"), app_url); 172 EXPECT_EQ(GetURL("app"), app_url);
169 EXPECT_EQ("hello", message); 173 EXPECT_EQ("hello", message);
170 if (query_index == 1) { 174 if (query_index == 1) {
171 EXPECT_EQ(GetURL("app?foo"), connection_url); 175 EXPECT_EQ(GetURL("app?foo"), connection_url);
172 } else if (query_index == 2) { 176 } else if (query_index == 2) {
173 EXPECT_EQ(GetURL("app?bar"), connection_url); 177 EXPECT_EQ(GetURL("app?bar"), connection_url);
174 } else { 178 } else {
175 CHECK(false); 179 CHECK(false);
176 } 180 }
177 ++num_responses; 181 ++num_responses;
178 if (num_responses == 2) 182 if (num_responses == 2)
179 base::MessageLoop::current()->Quit(); 183 base::MessageLoop::current()->Quit();
180 }; 184 };
181 }; 185 };
182 pingable1->Ping("hello", callbacks_builder(1)); 186 pingable1->Ping("hello", callbacks_builder(1));
183 pingable2->Ping("hello", callbacks_builder(2)); 187 pingable2->Ping("hello", callbacks_builder(2));
184 base::RunLoop().Run(); 188 base::RunLoop().Run();
185 } 189 }
186 190
187 // mojo: URLs can have querystrings too 191 // mojo: URLs can have querystrings too
188 TEST_F(ShellAppTest, MojoURLQueryHandling) { 192 TEST_F(ShellAppTest, MojoURLQueryHandling) {
189 PingablePtr pingable; 193 PingablePtr pingable;
190 application_impl()->ConnectToServiceDeprecated("mojo:pingable_app?foo", 194 mojo::ConnectToService(application_impl()->shell(), "mojo:pingable_app?foo",
191 &pingable); 195 GetProxy(&pingable));
192 auto callback = [](const String& app_url, const String& connection_url, 196 auto callback = [](const String& app_url, const String& connection_url,
193 const String& message) { 197 const String& message) {
194 EXPECT_TRUE(base::EndsWith(app_url.To<base::StringPiece>(), 198 EXPECT_TRUE(base::EndsWith(app_url.To<base::StringPiece>(),
195 "/pingable_app.mojo", 199 "/pingable_app.mojo",
196 base::CompareCase::SENSITIVE)); 200 base::CompareCase::SENSITIVE));
197 EXPECT_EQ(app_url.To<std::string>() + "?foo", connection_url); 201 EXPECT_EQ(app_url.To<std::string>() + "?foo", connection_url);
198 EXPECT_EQ("hello", message); 202 EXPECT_EQ("hello", message);
199 base::MessageLoop::current()->Quit(); 203 base::MessageLoop::current()->Quit();
200 }; 204 };
201 pingable->Ping("hello", callback); 205 pingable->Ping("hello", callback);
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
240 } 244 }
241 245
242 // The first one should still work. 246 // The first one should still work.
243 { 247 {
244 SCOPED_TRACE("app_connector1 again"); 248 SCOPED_TRACE("app_connector1 again");
245 TestApplicationConnector(app_connector1.get()); 249 TestApplicationConnector(app_connector1.get());
246 } 250 }
247 } 251 }
248 252
249 } // namespace 253 } // namespace
OLDNEW
« no previous file with comments | « shell/android/nfc_apptest.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698