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

Unified Diff: sky/shell/testing/test_runner.cc

Issue 1218633003: Make it possible to run a test in sky_shell (Closed) Base URL: git@github.com:domokit/mojo.git@master
Patch Set: Moar EOF Created 5 years, 6 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « sky/shell/testing/test_runner.h ('k') | sky/tests/resources/unit.dart » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: sky/shell/testing/test_runner.cc
diff --git a/sky/shell/testing/test_runner.cc b/sky/shell/testing/test_runner.cc
new file mode 100644
index 0000000000000000000000000000000000000000..a065399560ad371a6fdf5e44de2c51d1fcaa8c0b
--- /dev/null
+++ b/sky/shell/testing/test_runner.cc
@@ -0,0 +1,125 @@
+// 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.
+
+#include "sky/shell/testing/test_runner.h"
+
+#include <iostream>
+
+#include "base/bind.h"
+#include "base/message_loop/message_loop.h"
+#include "base/strings/string_util.h"
+#include "sky/shell/platform_view.h"
+#include "sky/shell/shell.h"
+#include "sky/shell/shell_view.h"
+
+namespace sky {
+namespace shell {
+namespace {
+
+struct UrlData {
+ std::string url;
+ std::string expected_pixel_hash;
+ bool enable_pixel_dumping = false;
+};
+
+void WaitForURL(UrlData& data) {
eseidel 2015/06/29 16:53:59 This code is banana pants. file://path/to/test?ha
+ // 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;
+}
+
+const char kFileUrlPrefix[] = "file://";
+static TestRunner* g_test_runner = nullptr;
+
+} // namespace
+
+TestRunner::TestRunner()
+ : shell_view_(new ShellView(Shell::Shared())),
+ weak_ptr_factory_(this) {
+ CHECK(!g_test_runner) << "Only create one TestRunner.";
+
+ shell_view_->view()->ConnectToViewportObserver(GetProxy(&viewport_observer_));
+ viewport_observer_->OnViewportMetricsChanged(320, 640, 1.0);
eseidel 2015/06/29 16:53:59 How did we standardize on sub-VGA?
abarth-chromium 2015/06/30 21:38:31 We can change this to be whatever you like. This
+}
+
+TestRunner::~TestRunner() {
+}
+
+TestRunner& TestRunner::Shared() {
+ if (!g_test_runner)
+ g_test_runner = new TestRunner();
+ return *g_test_runner;
+}
+
+void TestRunner::Start(const std::string& single_test_url) {
+ single_test_url_ = single_test_url;
+ std::cout << "#READY\n";
eseidel 2015/06/29 16:53:59 You're gonna want a helper for all these flush-eve
+ std::cout.flush();
+ 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";
+ std::cout << "#EOF\n";
eseidel 2015/06/29 16:53:58 Comments here as to what goes between the various
+ std::cout << "#EOF\n";
+ std::cout.flush();
+ std::cerr << "#EOF\n";
+ std::cerr.flush();
+ bindings_.CloseAllBindings();
+
+ if (single_test_url_.length())
+ 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_url_.length()) {
+ data.url = single_test_url_;
+ } else {
+ WaitForURL(data);
+ }
+
+ std::cout << "#BEGIN\n";
+ std::cout.flush();
+
+ if (StartsWithASCII(data.url, kFileUrlPrefix, true))
+ ReplaceFirstSubstringAfterOffset(&data.url, 0, kFileUrlPrefix, "");
+ viewport_observer_->RunFromFile(data.url, package_root_);
+}
+
+} // namespace shell
+} // namespace sky
« no previous file with comments | « sky/shell/testing/test_runner.h ('k') | sky/tests/resources/unit.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698