OLD | NEW |
---|---|
(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) { | |
eseidel
2015/06/29 16:53:59
This code is banana pants. file://path/to/test?ha
| |
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 const char kFileUrlPrefix[] = "file://"; | |
49 static TestRunner* g_test_runner = nullptr; | |
50 | |
51 } // namespace | |
52 | |
53 TestRunner::TestRunner() | |
54 : shell_view_(new ShellView(Shell::Shared())), | |
55 weak_ptr_factory_(this) { | |
56 CHECK(!g_test_runner) << "Only create one TestRunner."; | |
57 | |
58 shell_view_->view()->ConnectToViewportObserver(GetProxy(&viewport_observer_)); | |
59 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
| |
60 } | |
61 | |
62 TestRunner::~TestRunner() { | |
63 } | |
64 | |
65 TestRunner& TestRunner::Shared() { | |
66 if (!g_test_runner) | |
67 g_test_runner = new TestRunner(); | |
68 return *g_test_runner; | |
69 } | |
70 | |
71 void TestRunner::Start(const std::string& single_test_url) { | |
72 single_test_url_ = single_test_url; | |
73 std::cout << "#READY\n"; | |
eseidel
2015/06/29 16:53:59
You're gonna want a helper for all these flush-eve
| |
74 std::cout.flush(); | |
75 ScheduleRun(); | |
76 } | |
77 | |
78 void TestRunner::OnTestComplete(const mojo::String& test_result, | |
79 const mojo::Array<uint8_t> pixels) { | |
80 std::cout << "Content-Type: text/plain\n"; | |
81 std::cout << test_result << "\n"; | |
82 std::cout << "#EOF\n"; | |
eseidel
2015/06/29 16:53:58
Comments here as to what goes between the various
| |
83 std::cout << "#EOF\n"; | |
84 std::cout.flush(); | |
85 std::cerr << "#EOF\n"; | |
86 std::cerr.flush(); | |
87 bindings_.CloseAllBindings(); | |
88 | |
89 if (single_test_url_.length()) | |
90 exit(0); | |
91 ScheduleRun(); | |
92 } | |
93 | |
94 void TestRunner::DispatchInputEvent(mojo::EventPtr event) { | |
95 // TODO(abarth): Not implemented. | |
96 } | |
97 | |
98 void TestRunner::Create(mojo::ApplicationConnection* app, | |
99 mojo::InterfaceRequest<TestHarness> request) { | |
100 bindings_.AddBinding(this, request.Pass()); | |
101 } | |
102 | |
103 void TestRunner::ScheduleRun() { | |
104 base::MessageLoop::current()->PostTask(FROM_HERE, | |
105 base::Bind(&TestRunner::Run, weak_ptr_factory_.GetWeakPtr())); | |
106 } | |
107 | |
108 void TestRunner::Run() { | |
109 UrlData data; | |
110 if (single_test_url_.length()) { | |
111 data.url = single_test_url_; | |
112 } else { | |
113 WaitForURL(data); | |
114 } | |
115 | |
116 std::cout << "#BEGIN\n"; | |
117 std::cout.flush(); | |
118 | |
119 if (StartsWithASCII(data.url, kFileUrlPrefix, true)) | |
120 ReplaceFirstSubstringAfterOffset(&data.url, 0, kFileUrlPrefix, ""); | |
121 viewport_observer_->RunFromFile(data.url, package_root_); | |
122 } | |
123 | |
124 } // namespace shell | |
125 } // namespace sky | |
OLD | NEW |