mirror of
https://github.com/flutter/flutter.git
synced 2026-02-20 02:29:02 +08:00
Merge pull request #1192 from abarth/simplify_test_runner
Simplify TestRunner now that we don't have test_sky
This commit is contained in:
commit
8f8e955bb0
@ -27,9 +27,6 @@ Internals* GetInternals() {
|
||||
return static_cast<Internals*>(state->GetUserData(&kInternalsKey));
|
||||
}
|
||||
|
||||
void NotifyTestComplete(Dart_NativeArguments args) {
|
||||
}
|
||||
|
||||
void TakeRootBundleHandle(Dart_NativeArguments args) {
|
||||
Dart_SetIntegerReturnValue(args,
|
||||
GetInternals()->TakeRootBundleHandle().value());
|
||||
@ -56,7 +53,6 @@ void TakeServiceRegistry(Dart_NativeArguments args) {
|
||||
}
|
||||
|
||||
const DartBuiltin::Natives kNativeFunctions[] = {
|
||||
{"notifyTestComplete", NotifyTestComplete, 1},
|
||||
{"takeRootBundleHandle", TakeRootBundleHandle, 0},
|
||||
{"takeServiceRegistry", TakeServiceRegistry, 0},
|
||||
{"takeServicesProvidedByEmbedder", TakeServicesProvidedByEmbedder, 0},
|
||||
|
||||
@ -6,8 +6,6 @@ library sky.internals;
|
||||
|
||||
// TODO(abarth): Move these functions into dart:sky
|
||||
|
||||
void notifyTestComplete(String test_result) native "notifyTestComplete";
|
||||
|
||||
int takeRootBundleHandle() native "takeRootBundleHandle";
|
||||
int takeServiceRegistry() native "takeServiceRegistry";
|
||||
int takeServicesProvidedByEmbedder() native "takeServicesProvidedByEmbedder";
|
||||
|
||||
@ -25,7 +25,6 @@ dart_pkg("sky_services") {
|
||||
":copy_sky_services_license",
|
||||
"//sky/services/activity:interfaces",
|
||||
"//sky/services/media:interfaces",
|
||||
"//sky/services/testing:interfaces",
|
||||
"//sky/services/vsync:interfaces",
|
||||
]
|
||||
}
|
||||
|
||||
@ -1,17 +0,0 @@
|
||||
# Copyright 2014 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.
|
||||
|
||||
import("//mojo/public/tools/bindings/mojom.gni")
|
||||
|
||||
mojom("interfaces") {
|
||||
sources = [
|
||||
"test_harness.mojom",
|
||||
]
|
||||
|
||||
import_dirs = [ get_path_info("../../../mojo/services", "abspath") ]
|
||||
|
||||
deps = [
|
||||
"//mojo/services/input_events/public/interfaces",
|
||||
]
|
||||
}
|
||||
@ -1,13 +0,0 @@
|
||||
// Copyright 2014 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.
|
||||
|
||||
[DartPackage="sky_services"]
|
||||
module sky;
|
||||
|
||||
import "mojo/services/input_events/public/interfaces/input_events.mojom";
|
||||
|
||||
interface TestHarness {
|
||||
OnTestComplete(string test_result, array<uint8>? pixels);
|
||||
DispatchInputEvent(mojo.Event event);
|
||||
};
|
||||
@ -256,7 +256,6 @@ if (is_android) {
|
||||
deps = common_deps + [
|
||||
":common",
|
||||
"//mojo/common",
|
||||
"//sky/services/testing:interfaces",
|
||||
]
|
||||
}
|
||||
} else if (is_mac) {
|
||||
@ -282,7 +281,6 @@ if (is_android) {
|
||||
":common",
|
||||
"//mojo/common",
|
||||
"//sky/services/ns_net",
|
||||
"//sky/services/testing:interfaces",
|
||||
]
|
||||
}
|
||||
|
||||
|
||||
@ -29,8 +29,11 @@ int main(int argc, const char* argv[]) {
|
||||
sky::shell::Shell::Init(make_scoped_ptr(
|
||||
new sky::shell::ServiceProviderContext(message_loop.task_runner())));
|
||||
|
||||
message_loop.PostTask(FROM_HERE, base::Bind(&sky::shell::InitForTesting));
|
||||
message_loop.Run();
|
||||
if (!sky::shell::InitForTesting()) {
|
||||
sky::shell::switches::PrintUsage("sky_shell");
|
||||
return 1;
|
||||
}
|
||||
|
||||
message_loop.Run();
|
||||
return 0;
|
||||
}
|
||||
|
||||
@ -23,10 +23,6 @@ class PlatformServiceProvider : public mojo::ServiceProvider {
|
||||
|
||||
void ConnectToService(const mojo::String& service_name,
|
||||
mojo::ScopedMessagePipeHandle client_handle) override {
|
||||
if (service_name == TestHarness::Name_) {
|
||||
TestRunner::Shared().Create(nullptr,
|
||||
mojo::MakeRequest<TestHarness>(client_handle.Pass()));
|
||||
}
|
||||
}
|
||||
|
||||
private:
|
||||
|
||||
@ -40,9 +40,9 @@ int main(int argc, const char* argv[]) {
|
||||
}
|
||||
|
||||
if (command_line.HasSwitch(sky::shell::switches::kNonInteractive)) {
|
||||
auto loop = base::MessageLoop::current();
|
||||
loop->PostTask(FROM_HERE, base::Bind(&sky::shell::InitForTesting));
|
||||
loop->Run();
|
||||
if (!sky::shell::InitForTesting())
|
||||
return 1;
|
||||
base::MessageLoop::current()->Run();
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
|
||||
|
||||
@ -54,12 +54,6 @@ class PlatformServiceProvider : public mojo::ServiceProvider {
|
||||
vsync_.Create(nullptr, mojo::MakeRequest<::vsync::VSyncProvider>(
|
||||
client_handle.Pass()));
|
||||
}
|
||||
#endif
|
||||
#if !TARGET_OS_IPHONE
|
||||
if (service_name == TestHarness::Name_) {
|
||||
TestRunner::Shared().Create(
|
||||
nullptr, mojo::MakeRequest<TestHarness>(client_handle.Pass()));
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
@ -17,41 +17,6 @@ namespace sky {
|
||||
namespace shell {
|
||||
namespace {
|
||||
|
||||
struct UrlData {
|
||||
std::string url;
|
||||
std::string expected_pixel_hash;
|
||||
bool enable_pixel_dumping = false;
|
||||
bool is_snapshot = false;
|
||||
};
|
||||
|
||||
void WaitForURL(UrlData& data) {
|
||||
// A test name is formated like file:///path/to/test'--pixel-test'pixelhash
|
||||
std::cin >> data.url;
|
||||
|
||||
std::string pixel_switch;
|
||||
std::string::size_type separator_position = data.url.find('\'');
|
||||
if (separator_position != std::string::npos) {
|
||||
pixel_switch = data.url.substr(separator_position + 1);
|
||||
data.url.erase(separator_position);
|
||||
}
|
||||
|
||||
std::string pixel_hash;
|
||||
separator_position = pixel_switch.find('\'');
|
||||
if (separator_position != std::string::npos) {
|
||||
pixel_hash = pixel_switch.substr(separator_position + 1);
|
||||
pixel_switch.erase(separator_position);
|
||||
}
|
||||
|
||||
data.enable_pixel_dumping = pixel_switch == "--pixel-test";
|
||||
data.expected_pixel_hash = pixel_hash;
|
||||
}
|
||||
|
||||
void PrintAndFlush(const std::string& value) {
|
||||
std::cout << value;
|
||||
std::cout.flush();
|
||||
}
|
||||
|
||||
const char kFileUrlPrefix[] = "file://";
|
||||
static TestRunner* g_test_runner = nullptr;
|
||||
|
||||
} // namespace
|
||||
@ -77,60 +42,11 @@ TestRunner& TestRunner::Shared() {
|
||||
return *g_test_runner;
|
||||
}
|
||||
|
||||
void TestRunner::Start(scoped_ptr<SingleTest> single_test) {
|
||||
single_test_ = single_test.Pass();
|
||||
PrintAndFlush("#READY\n");
|
||||
ScheduleRun();
|
||||
}
|
||||
|
||||
void TestRunner::OnTestComplete(const mojo::String& test_result,
|
||||
const mojo::Array<uint8_t> pixels) {
|
||||
std::cout << "Content-Type: text/plain\n";
|
||||
std::cout << test_result << "\n";
|
||||
PrintAndFlush("#EOF\n"); // Text result complete
|
||||
PrintAndFlush("#EOF\n"); // Pixel result complete
|
||||
std::cerr << "#EOF\n";
|
||||
std::cerr.flush();
|
||||
bindings_.CloseAllBindings();
|
||||
|
||||
if (single_test_)
|
||||
exit(0);
|
||||
ScheduleRun();
|
||||
}
|
||||
|
||||
void TestRunner::DispatchInputEvent(mojo::EventPtr event) {
|
||||
// TODO(abarth): Not implemented.
|
||||
}
|
||||
|
||||
void TestRunner::Create(mojo::ApplicationConnection* app,
|
||||
mojo::InterfaceRequest<TestHarness> request) {
|
||||
bindings_.AddBinding(this, request.Pass());
|
||||
}
|
||||
|
||||
void TestRunner::ScheduleRun() {
|
||||
base::MessageLoop::current()->PostTask(FROM_HERE,
|
||||
base::Bind(&TestRunner::Run, weak_ptr_factory_.GetWeakPtr()));
|
||||
}
|
||||
|
||||
void TestRunner::Run() {
|
||||
UrlData data;
|
||||
if (single_test_) {
|
||||
data.url = single_test_->path;
|
||||
data.is_snapshot = single_test_->is_snapshot;
|
||||
} else {
|
||||
WaitForURL(data);
|
||||
}
|
||||
|
||||
std::cout << "#BEGIN\n";
|
||||
std::cout.flush();
|
||||
|
||||
if (base::StartsWithASCII(data.url, kFileUrlPrefix, true))
|
||||
base::ReplaceFirstSubstringAfterOffset(&data.url, 0, kFileUrlPrefix, "");
|
||||
|
||||
if (data.is_snapshot)
|
||||
sky_engine_->RunFromSnapshot(data.url);
|
||||
void TestRunner::Run(const TestDescriptor& test) {
|
||||
if (test.is_snapshot)
|
||||
sky_engine_->RunFromSnapshot(test.path);
|
||||
else
|
||||
sky_engine_->RunFromFile(data.url, package_root_);
|
||||
sky_engine_->RunFromFile(test.path, test.package_root);
|
||||
}
|
||||
|
||||
} // namespace shell
|
||||
|
||||
@ -12,50 +12,30 @@
|
||||
#include "mojo/common/binding_set.h"
|
||||
#include "mojo/public/cpp/application/interface_factory_impl.h"
|
||||
#include "sky/services/engine/sky_engine.mojom.h"
|
||||
#include "sky/services/testing/test_harness.mojom.h"
|
||||
|
||||
namespace sky {
|
||||
namespace shell {
|
||||
class ShellView;
|
||||
|
||||
class TestRunner : public mojo::InterfaceFactory<TestHarness>,
|
||||
public TestHarness {
|
||||
class TestRunner {
|
||||
public:
|
||||
static TestRunner& Shared();
|
||||
|
||||
void set_package_root(const std::string& package_root) {
|
||||
package_root_ = package_root;
|
||||
}
|
||||
|
||||
struct SingleTest {
|
||||
struct TestDescriptor {
|
||||
std::string path;
|
||||
std::string package_root;
|
||||
bool is_snapshot = false;
|
||||
};
|
||||
|
||||
void Start(scoped_ptr<SingleTest> single_test);
|
||||
|
||||
// mojo::InterfaceFactory<TestHarness> implementation:
|
||||
void Create(mojo::ApplicationConnection* app,
|
||||
mojo::InterfaceRequest<TestHarness> request) override;
|
||||
void Run(const TestDescriptor& test);
|
||||
|
||||
private:
|
||||
// TestHarness implementation:
|
||||
void OnTestComplete(const mojo::String& test_result,
|
||||
const mojo::Array<uint8_t> pixels) override;
|
||||
void DispatchInputEvent(mojo::EventPtr event) override;
|
||||
|
||||
TestRunner();
|
||||
~TestRunner() override;
|
||||
void ScheduleRun();
|
||||
void Run();
|
||||
~TestRunner();
|
||||
|
||||
std::string package_root_;
|
||||
scoped_ptr<ShellView> shell_view_;
|
||||
SkyEnginePtr sky_engine_;
|
||||
|
||||
scoped_ptr<SingleTest> single_test_;
|
||||
mojo::BindingSet<TestHarness> bindings_;
|
||||
|
||||
base::WeakPtrFactory<TestRunner> weak_ptr_factory_;
|
||||
|
||||
DISALLOW_COPY_AND_ASSIGN(TestRunner);
|
||||
|
||||
@ -12,32 +12,26 @@
|
||||
namespace sky {
|
||||
namespace shell {
|
||||
|
||||
void InitForTesting() {
|
||||
bool InitForTesting() {
|
||||
base::CommandLine& command_line = *base::CommandLine::ForCurrentProcess();
|
||||
blink::WebRuntimeFeatures::enableObservatory(
|
||||
!command_line.HasSwitch(switches::kNonInteractive));
|
||||
|
||||
// Explicitly boot the shared test runner.
|
||||
TestRunner& runner = TestRunner::Shared();
|
||||
TestRunner::TestDescriptor test;
|
||||
test.package_root = command_line.GetSwitchValueASCII(switches::kPackageRoot);
|
||||
|
||||
std::string package_root =
|
||||
command_line.GetSwitchValueASCII(switches::kPackageRoot);
|
||||
runner.set_package_root(package_root);
|
||||
|
||||
scoped_ptr<TestRunner::SingleTest> single_test;
|
||||
if (command_line.HasSwitch(switches::kSnapshot)) {
|
||||
single_test.reset(new TestRunner::SingleTest);
|
||||
single_test->path = command_line.GetSwitchValueASCII(switches::kSnapshot);
|
||||
single_test->is_snapshot = true;
|
||||
test.path = command_line.GetSwitchValueASCII(switches::kSnapshot);
|
||||
test.is_snapshot = true;
|
||||
} else {
|
||||
auto args = command_line.GetArgs();
|
||||
if (!args.empty()) {
|
||||
single_test.reset(new TestRunner::SingleTest);
|
||||
single_test->path = args[0];
|
||||
}
|
||||
if (args.empty())
|
||||
return false;
|
||||
test.path = args[0];
|
||||
}
|
||||
|
||||
runner.Start(single_test.Pass());
|
||||
TestRunner::Shared().Run(test);
|
||||
return true;
|
||||
}
|
||||
|
||||
} // namespace shell
|
||||
|
||||
@ -8,7 +8,7 @@
|
||||
namespace sky {
|
||||
namespace shell {
|
||||
|
||||
void InitForTesting();
|
||||
bool InitForTesting();
|
||||
|
||||
} // namespace shell
|
||||
} // namespace sky
|
||||
|
||||
@ -26,9 +26,6 @@ Internals* GetInternals() {
|
||||
return static_cast<Internals*>(state->GetUserData(&kInternalsKey));
|
||||
}
|
||||
|
||||
void NotifyTestComplete(Dart_NativeArguments args) {
|
||||
}
|
||||
|
||||
void TakeRootBundleHandle(Dart_NativeArguments args) {
|
||||
Dart_SetIntegerReturnValue(
|
||||
args, GetInternals()->TakeRootBundleHandle().value());
|
||||
@ -52,7 +49,6 @@ void TakeServiceRegistry(Dart_NativeArguments args) {
|
||||
}
|
||||
|
||||
const DartBuiltin::Natives kNativeFunctions[] = {
|
||||
{"notifyTestComplete", NotifyTestComplete, 1},
|
||||
{"takeRootBundleHandle", TakeRootBundleHandle, 0},
|
||||
{"takeServiceRegistry", TakeServiceRegistry, 0},
|
||||
{"takeServicesProvidedByEmbedder", TakeServicesProvidedByEmbedder, 0},
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user