Commit a4bd5ce4 authored by James Robinson's avatar James Robinson Committed by Commit Bot

[fuchsia][webrunner] Add integration / smoke test for webrunner

This adds a black-box test of the webrunner's functionality as a runner
for http:// URLs in Fuchsia. The test opens up a random port on the
device, instantiates web runner via launching a web URL, then verifies
that the URL is fetched and parsed.

Change-Id: If3084760eb96bdc9c609ab9beef1a3507ee77011
Reviewed-on: https://chromium-review.googlesource.com/c/1387813
Commit-Queue: James Robinson <jamesr@chromium.org>
Reviewed-by: default avatarFabrice de Gans-Riberi <fdegans@chromium.org>
Cr-Commit-Position: refs/heads/master@{#618403}
parent 491e2671
...@@ -10,6 +10,7 @@ ...@@ -10,6 +10,7 @@
"fuchsia.net.LegacySocketProvider", "fuchsia.net.LegacySocketProvider",
"fuchsia.netstack.Netstack", "fuchsia.netstack.Netstack",
"fuchsia.process.Launcher", "fuchsia.process.Launcher",
"fuchsia.sys.Launcher",
"fuchsia.ui.input.ImeService", "fuchsia.ui.input.ImeService",
"fuchsia.ui.input.ImeVisibilityService", "fuchsia.ui.input.ImeVisibilityService",
"fuchsia.ui.policy.Presenter", "fuchsia.ui.policy.Presenter",
......
...@@ -458,6 +458,31 @@ test("webrunner_unittests") { ...@@ -458,6 +458,31 @@ test("webrunner_unittests") {
] ]
} }
test("webrunner_smoketests") {
sources = [
"app/web/webrunner_smoke_test.cc",
]
deps = [
":test_common",
"//base",
"//base/test:run_all_unittests",
"//base/test:test_support",
"//net:test_support",
"//testing/gtest",
"//third_party/fuchsia-sdk/sdk:sys",
]
package_deps = [
[
":service_pkg",
"chromium",
],
[
":webrunner_pkg",
"web_runner",
],
]
}
fidl_library("web_fidl") { fidl_library("web_fidl") {
library_name = "web" library_name = "web"
namespace = "chromium" namespace = "chromium"
......
// Copyright 2018 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include <fuchsia/sys/cpp/fidl.h>
#include "base/fuchsia/component_context.h"
#include "base/threading/thread_task_runner_handle.h"
#include "net/test/embedded_test_server/embedded_test_server.h"
#include "net/test/embedded_test_server/http_request.h"
#include "net/test/embedded_test_server/http_response.h"
#include "testing/gtest/include/gtest/gtest.h"
#include "webrunner/common/test/run_with_timeout.h"
using net::test_server::HttpRequest;
using net::test_server::HttpResponse;
namespace webrunner {
namespace {
class WebRunnerSmokeTest : public testing::Test {
public:
void SetUp() final {
test_server_.RegisterRequestHandler(base::BindRepeating(
&WebRunnerSmokeTest::HandleRequest, base::Unretained(this)));
ASSERT_TRUE(test_server_.Start());
}
std::unique_ptr<HttpResponse> HandleRequest(const HttpRequest& request) {
GURL absolute_url = test_server_.GetURL(request.relative_url);
if (absolute_url.path() == "/test.html") {
EXPECT_FALSE(test_html_requested_);
test_html_requested_ = true;
auto http_response =
std::make_unique<net::test_server::BasicHttpResponse>();
http_response->set_code(net::HTTP_OK);
http_response->set_content("<!doctype html><img src=\"/img.png\">");
http_response->set_content_type("text/html");
return http_response;
} else if (absolute_url.path() == "/img.png") {
EXPECT_FALSE(test_image_requested_);
test_image_requested_ = true;
// All done!
run_loop_.Quit();
}
return nullptr;
}
protected:
bool test_html_requested_ = false;
bool test_image_requested_ = false;
base::MessageLoopForIO message_loop_;
net::EmbeddedTestServer test_server_;
base::RunLoop run_loop_;
};
TEST_F(WebRunnerSmokeTest, RequestHtmlAndImage) {
fuchsia::sys::LaunchInfo launch_info;
launch_info.url = test_server_.GetURL("/test.html").spec();
auto launcher = base::fuchsia::ComponentContext::GetDefault()
->ConnectToServiceSync<fuchsia::sys::Launcher>();
fuchsia::sys::ComponentControllerSyncPtr controller;
launcher->CreateComponent(std::move(launch_info), controller.NewRequest());
webrunner::CheckRunWithTimeout(&run_loop_);
EXPECT_TRUE(test_html_requested_);
EXPECT_TRUE(test_image_requested_);
}
} // anonymous namespace
} // namespace webrunner
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment