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

Side by Side Diff: shell/shell_apptest.cc

Issue 979043003: Fix shell_apptest for android. (Closed) Base URL: https://github.com/domokit/mojo.git@master
Patch Set: Created 5 years, 9 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
« mojo/tools/embed/embed_data.py ('K') | « shell/BUILD.gn ('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"
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/network/public/interfaces/net_address.mojom.h" 17 #include "mojo/services/network/public/interfaces/net_address.mojom.h"
18 #include "services/http_server/public/http_server.mojom.h" 18 #include "services/http_server/public/http_server.mojom.h"
19 #include "services/http_server/public/http_server_factory.mojom.h" 19 #include "services/http_server/public/http_server_factory.mojom.h"
20 #include "services/http_server/public/http_server_util.h" 20 #include "services/http_server/public/http_server_util.h"
21 #include "shell/test/pingable.mojom.h" 21 #include "shell/test/pingable.mojom.h"
22 #include "shell/kPingable.h"
23
24 using embed::kPingable;
22 25
23 namespace mojo { 26 namespace mojo {
24 27
25 namespace { 28 namespace {
26 29
27 std::string GetURL(uint16_t port, const std::string& path) { 30 std::string GetURL(uint16_t port, const std::string& path) {
28 return base::StringPrintf("http://127.0.0.1:%u/%s", port, path.c_str()); 31 return base::StringPrintf("http://127.0.0.1:%u/%s", port, path.c_str());
29 } 32 }
30 33
31 } // namespace 34 } // namespace
32 35
33 class GetHandler : public http_server::HttpHandler { 36 class GetHandler : public http_server::HttpHandler {
34 public: 37 public:
35 GetHandler(InterfaceRequest<http_server::HttpHandler> request, uint16_t port) 38 GetHandler(InterfaceRequest<http_server::HttpHandler> request, uint16_t port)
36 : binding_(this, request.Pass()), port_(port) { 39 : binding_(this, request.Pass()), port_(port) {
37 CHECK(PathService::Get(base::FILE_MODULE, &app_path_));
38 app_path_ = app_path_.DirName().Append("pingable_app.mojo");
39 CHECK(base::PathExists(app_path_));
40 } 40 }
41 ~GetHandler() override {} 41 ~GetHandler() override {}
42 42
43 private: 43 private:
44 // http_server::HttpHandler: 44 // http_server::HttpHandler:
45 void HandleRequest( 45 void HandleRequest(
46 http_server::HttpRequestPtr request, 46 http_server::HttpRequestPtr request,
47 const Callback<void(http_server::HttpResponsePtr)>& callback) override { 47 const Callback<void(http_server::HttpResponsePtr)>& callback) override {
48 http_server::HttpResponsePtr response; 48 http_server::HttpResponsePtr response;
49 if (StartsWithASCII(request->relative_url, "/app", true)) { 49 if (StartsWithASCII(request->relative_url, "/app", true)) {
50 // Super inefficient, but meh. 50 response = http_server::CreateHttpResponse(
51 std::string data; 51 200, std::string(kPingable.data, kPingable.size));
52 base::ReadFileToString(app_path_, &data);
53 response = http_server::CreateHttpResponse(200, data);
54 response->content_type = "application/octet-stream"; 52 response->content_type = "application/octet-stream";
55 } else if (request->relative_url == "/redirect") { 53 } else if (request->relative_url == "/redirect") {
56 response = http_server::HttpResponse::New(); 54 response = http_server::HttpResponse::New();
57 response->status_code = 302; 55 response->status_code = 302;
58 response->custom_headers.insert("Location", GetURL(port_, "app")); 56 response->custom_headers.insert("Location", GetURL(port_, "app"));
59 } else { 57 } else {
60 NOTREACHED(); 58 NOTREACHED();
61 } 59 }
62 60
63 callback.Run(response.Pass()); 61 callback.Run(response.Pass());
64 } 62 }
65 63
66 Binding<http_server::HttpHandler> binding_; 64 Binding<http_server::HttpHandler> binding_;
67 base::FilePath app_path_;
68 uint16_t port_; 65 uint16_t port_;
69 66
70 MOJO_DISALLOW_COPY_AND_ASSIGN(GetHandler); 67 MOJO_DISALLOW_COPY_AND_ASSIGN(GetHandler);
71 }; 68 };
72 69
73 typedef test::ApplicationTestBase ShellAppTest; 70 typedef test::ApplicationTestBase ShellAppTest;
74 71
75 class ShellHTTPAppTest : public test::ApplicationTestBase { 72 class ShellHTTPAppTest : public test::ApplicationTestBase {
76 public: 73 public:
77 ShellHTTPAppTest() : ApplicationTestBase() {} 74 ShellHTTPAppTest() : ApplicationTestBase() {}
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
113 110
114 http_server::HttpServerFactoryPtr http_server_factory_; 111 http_server::HttpServerFactoryPtr http_server_factory_;
115 http_server::HttpServerPtr http_server_; 112 http_server::HttpServerPtr http_server_;
116 scoped_ptr<GetHandler> handler_; 113 scoped_ptr<GetHandler> handler_;
117 uint16_t port_; 114 uint16_t port_;
118 115
119 private: 116 private:
120 MOJO_DISALLOW_COPY_AND_ASSIGN(ShellHTTPAppTest); 117 MOJO_DISALLOW_COPY_AND_ASSIGN(ShellHTTPAppTest);
121 }; 118 };
122 119
123 #if defined(OS_ANDROID)
124 // These tests rely on data that needs to be bundled into the apptest binary in
125 // order to work on Android.
126 #else // !OS_ANDROID
127 // Test that we can load apps over http. 120 // Test that we can load apps over http.
128 TEST_F(ShellHTTPAppTest, Http) { 121 TEST_F(ShellHTTPAppTest, Http) {
129 InterfacePtr<Pingable> pingable; 122 InterfacePtr<Pingable> pingable;
130 application_impl()->ConnectToService(GetURL("app"), &pingable); 123 application_impl()->ConnectToService(GetURL("app"), &pingable);
131 pingable->Ping("hello", 124 pingable->Ping("hello",
132 [this](const String& app_url, const String& connection_url, 125 [this](const String& app_url, const String& connection_url,
133 const String& message) { 126 const String& message) {
134 EXPECT_EQ(GetURL("app"), app_url); 127 EXPECT_EQ(GetURL("app"), app_url);
135 EXPECT_EQ(GetURL("app"), connection_url); 128 EXPECT_EQ(GetURL("app"), connection_url);
136 EXPECT_EQ("hello", message); 129 EXPECT_EQ("hello", message);
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
181 EXPECT_EQ(GetURL("app?bar"), connection_url); 174 EXPECT_EQ(GetURL("app?bar"), connection_url);
182 base::MessageLoop::current()->Quit(); 175 base::MessageLoop::current()->Quit();
183 } else { 176 } else {
184 CHECK(false); 177 CHECK(false);
185 } 178 }
186 }; 179 };
187 pingable1->Ping("hello", callback); 180 pingable1->Ping("hello", callback);
188 pingable2->Ping("hello", callback); 181 pingable2->Ping("hello", callback);
189 base::RunLoop().Run(); 182 base::RunLoop().Run();
190 } 183 }
191 #endif // OS_ANDROID
192 184
193 // mojo: URLs can have querystrings too 185 // mojo: URLs can have querystrings too
194 TEST_F(ShellAppTest, MojoURLQueryHandling) { 186 TEST_F(ShellAppTest, MojoURLQueryHandling) {
195 InterfacePtr<Pingable> pingable; 187 InterfacePtr<Pingable> pingable;
196 application_impl()->ConnectToService("mojo:pingable_app?foo", &pingable); 188 application_impl()->ConnectToService("mojo:pingable_app?foo", &pingable);
197 auto callback = [this](const String& app_url, const String& connection_url, 189 auto callback = [this](const String& app_url, const String& connection_url,
198 const String& message) { 190 const String& message) {
199 EXPECT_TRUE(EndsWith(app_url, "/pingable_app.mojo", true)); 191 EXPECT_TRUE(EndsWith(app_url, "/pingable_app.mojo", true));
200 EXPECT_EQ(app_url.To<std::string>() + "?foo", connection_url); 192 EXPECT_EQ(app_url.To<std::string>() + "?foo", connection_url);
201 EXPECT_EQ("hello", message); 193 EXPECT_EQ("hello", message);
202 base::MessageLoop::current()->Quit(); 194 base::MessageLoop::current()->Quit();
203 }; 195 };
204 pingable->Ping("hello", callback); 196 pingable->Ping("hello", callback);
205 base::RunLoop().Run(); 197 base::RunLoop().Run();
206 } 198 }
207 199
208 } // namespace mojo 200 } // namespace mojo
OLDNEW
« mojo/tools/embed/embed_data.py ('K') | « shell/BUILD.gn ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698