Fix shell_apptest for android.
This CL introduces mojo/tools/embed/rules.gni that allows to embed a
file in the data section of an object file. It refactors icu_data to use
this, and uses it in shell_apptest to bundle the ping application.
R=abarth@chromium.org, davemoore@chromium.org
Review URL: https://codereview.chromium.org/979043003
diff --git a/shell/BUILD.gn b/shell/BUILD.gn
index e20c0e5..8e0e5ff 100644
--- a/shell/BUILD.gn
+++ b/shell/BUILD.gn
@@ -6,6 +6,7 @@
import("//mojo/public/mojo.gni")
import("//mojo/public/mojo_application.gni")
import("//mojo/public/tools/bindings/mojom.gni")
+import("//mojo/tools/embed/rules.gni")
import("//testing/test.gni")
# We don't support building in the component build since mojo apps are
@@ -507,6 +508,17 @@
}
}
+embed_file("embed_pingable") {
+ source = "$root_build_dir/pingable_app.mojo"
+ namespace = "mojo"
+ variable = "kPingable"
+ testonly = true
+
+ deps = [
+ "//shell/test:pingable_app",
+ ]
+}
+
mojo_native_application("apptests") {
output_name = "shell_apptests"
@@ -528,10 +540,8 @@
"//services/http_server/public",
"//services/http_server/public:util",
"//shell/test:bindings",
+ ":embed_pingable",
]
- data_deps = [
- "//services/http_server:http_server",
- "//shell/test:pingable_app",
- ]
+ data_deps = [ "//services/http_server:http_server" ]
}
diff --git a/shell/shell_apptest.cc b/shell/shell_apptest.cc
index 30f4fd7..7b610a7 100644
--- a/shell/shell_apptest.cc
+++ b/shell/shell_apptest.cc
@@ -18,8 +18,8 @@
#include "services/http_server/public/http_server.mojom.h"
#include "services/http_server/public/http_server_factory.mojom.h"
#include "services/http_server/public/http_server_util.h"
+#include "shell/kPingable.h"
#include "shell/test/pingable.mojom.h"
-
namespace mojo {
namespace {
@@ -34,9 +34,6 @@
public:
GetHandler(InterfaceRequest<http_server::HttpHandler> request, uint16_t port)
: binding_(this, request.Pass()), port_(port) {
- CHECK(PathService::Get(base::FILE_MODULE, &app_path_));
- app_path_ = app_path_.DirName().Append("pingable_app.mojo");
- CHECK(base::PathExists(app_path_));
}
~GetHandler() override {}
@@ -47,10 +44,8 @@
const Callback<void(http_server::HttpResponsePtr)>& callback) override {
http_server::HttpResponsePtr response;
if (StartsWithASCII(request->relative_url, "/app", true)) {
- // Super inefficient, but meh.
- std::string data;
- base::ReadFileToString(app_path_, &data);
- response = http_server::CreateHttpResponse(200, data);
+ response = http_server::CreateHttpResponse(
+ 200, std::string(kPingable.data, kPingable.size));
response->content_type = "application/octet-stream";
} else if (request->relative_url == "/redirect") {
response = http_server::HttpResponse::New();
@@ -64,7 +59,6 @@
}
Binding<http_server::HttpHandler> binding_;
- base::FilePath app_path_;
uint16_t port_;
MOJO_DISALLOW_COPY_AND_ASSIGN(GetHandler);
@@ -120,10 +114,6 @@
MOJO_DISALLOW_COPY_AND_ASSIGN(ShellHTTPAppTest);
};
-#if defined(OS_ANDROID)
-// These tests rely on data that needs to be bundled into the apptest binary in
-// order to work on Android.
-#else // !OS_ANDROID
// Test that we can load apps over http.
TEST_F(ShellHTTPAppTest, Http) {
InterfacePtr<Pingable> pingable;
@@ -188,7 +178,6 @@
pingable2->Ping("hello", callback);
base::RunLoop().Run();
}
-#endif // OS_ANDROID
// mojo: URLs can have querystrings too
TEST_F(ShellAppTest, MojoURLQueryHandling) {