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

Side by Side 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: address reviewer comments Created 5 years, 5 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
« no previous file with comments | « sky/shell/testing/test_runner.h ('k') | sky/tests/resources/unit.dart » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #include "sky/shell/testing/test_runner.h"
6
7 #include <iostream>
8
9 #include "base/bind.h"
10 #include "base/message_loop/message_loop.h"
11 #include "base/strings/string_util.h"
12 #include "sky/shell/platform_view.h"
13 #include "sky/shell/shell.h"
14 #include "sky/shell/shell_view.h"
15
16 namespace sky {
17 namespace shell {
18 namespace {
19
20 struct UrlData {
21 std::string url;
22 std::string expected_pixel_hash;
23 bool enable_pixel_dumping = false;
24 };
25
26 void WaitForURL(UrlData& data) {
27 // A test name is formated like file:///path/to/test'--pixel-test'pixelhash
28 std::cin >> data.url;
29
30 std::string pixel_switch;
31 std::string::size_type separator_position = data.url.find('\'');
32 if (separator_position != std::string::npos) {
33 pixel_switch = data.url.substr(separator_position + 1);
34 data.url.erase(separator_position);
35 }
36
37 std::string pixel_hash;
38 separator_position = pixel_switch.find('\'');
39 if (separator_position != std::string::npos) {
40 pixel_hash = pixel_switch.substr(separator_position + 1);
41 pixel_switch.erase(separator_position);
42 }
43
44 data.enable_pixel_dumping = pixel_switch == "--pixel-test";
45 data.expected_pixel_hash = pixel_hash;
46 }
47
48 void PrintAndFlush(const std::string& value) {
49 std::cout << value;
50 std::cout.flush();
51 }
52
53 const char kFileUrlPrefix[] = "file://";
54 static TestRunner* g_test_runner = nullptr;
55
56 } // namespace
57
58 TestRunner::TestRunner()
59 : shell_view_(new ShellView(Shell::Shared())),
60 weak_ptr_factory_(this) {
61 CHECK(!g_test_runner) << "Only create one TestRunner.";
62
63 shell_view_->view()->ConnectToViewportObserver(GetProxy(&viewport_observer_));
64 viewport_observer_->OnViewportMetricsChanged(320, 640, 1.0);
65 }
66
67 TestRunner::~TestRunner() {
68 }
69
70 TestRunner& TestRunner::Shared() {
71 if (!g_test_runner)
72 g_test_runner = new TestRunner();
73 return *g_test_runner;
74 }
75
76 void TestRunner::Start(const std::string& single_test_url) {
77 single_test_url_ = single_test_url;
78 PrintAndFlush("#READY\n");
79 ScheduleRun();
80 }
81
82 void TestRunner::OnTestComplete(const mojo::String& test_result,
83 const mojo::Array<uint8_t> pixels) {
84 std::cout << "Content-Type: text/plain\n";
85 std::cout << test_result << "\n";
86 PrintAndFlush("#EOF\n"); // Text result complete
87 PrintAndFlush("#EOF\n"); // Pixel result complete
88 std::cerr << "#EOF\n";
89 std::cerr.flush();
90 bindings_.CloseAllBindings();
91
92 if (single_test_url_.length())
93 exit(0);
94 ScheduleRun();
95 }
96
97 void TestRunner::DispatchInputEvent(mojo::EventPtr event) {
98 // TODO(abarth): Not implemented.
99 }
100
101 void TestRunner::Create(mojo::ApplicationConnection* app,
102 mojo::InterfaceRequest<TestHarness> request) {
103 bindings_.AddBinding(this, request.Pass());
104 }
105
106 void TestRunner::ScheduleRun() {
107 base::MessageLoop::current()->PostTask(FROM_HERE,
108 base::Bind(&TestRunner::Run, weak_ptr_factory_.GetWeakPtr()));
109 }
110
111 void TestRunner::Run() {
112 UrlData data;
113 if (single_test_url_.length()) {
114 data.url = single_test_url_;
115 } else {
116 WaitForURL(data);
117 }
118
119 std::cout << "#BEGIN\n";
120 std::cout.flush();
121
122 if (StartsWithASCII(data.url, kFileUrlPrefix, true))
123 ReplaceFirstSubstringAfterOffset(&data.url, 0, kFileUrlPrefix, "");
124 viewport_observer_->RunFromFile(data.url, package_root_);
125 }
126
127 } // namespace shell
128 } // namespace sky
OLDNEW
« 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