| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "sky/shell/testing/test_runner.h" | 5 #include "sky/shell/testing/test_runner.h" |
| 6 | 6 |
| 7 #include <iostream> | 7 #include <iostream> |
| 8 | 8 |
| 9 #include "base/bind.h" | 9 #include "base/bind.h" |
| 10 #include "base/message_loop/message_loop.h" | 10 #include "base/message_loop/message_loop.h" |
| 11 #include "base/strings/string_util.h" | 11 #include "base/strings/string_util.h" |
| 12 #include "sky/shell/platform_view.h" | 12 #include "sky/shell/platform_view.h" |
| 13 #include "sky/shell/shell.h" | 13 #include "sky/shell/shell.h" |
| 14 #include "sky/shell/shell_view.h" | 14 #include "sky/shell/shell_view.h" |
| 15 | 15 |
| 16 namespace sky { | 16 namespace sky { |
| 17 namespace shell { | 17 namespace shell { |
| 18 namespace { | 18 namespace { |
| 19 | 19 |
| 20 struct UrlData { | 20 struct UrlData { |
| 21 std::string url; | 21 std::string url; |
| 22 std::string expected_pixel_hash; | 22 std::string expected_pixel_hash; |
| 23 bool enable_pixel_dumping = false; | 23 bool enable_pixel_dumping = false; |
| 24 bool is_snapshot = false; |
| 24 }; | 25 }; |
| 25 | 26 |
| 26 void WaitForURL(UrlData& data) { | 27 void WaitForURL(UrlData& data) { |
| 27 // A test name is formated like file:///path/to/test'--pixel-test'pixelhash | 28 // A test name is formated like file:///path/to/test'--pixel-test'pixelhash |
| 28 std::cin >> data.url; | 29 std::cin >> data.url; |
| 29 | 30 |
| 30 std::string pixel_switch; | 31 std::string pixel_switch; |
| 31 std::string::size_type separator_position = data.url.find('\''); | 32 std::string::size_type separator_position = data.url.find('\''); |
| 32 if (separator_position != std::string::npos) { | 33 if (separator_position != std::string::npos) { |
| 33 pixel_switch = data.url.substr(separator_position + 1); | 34 pixel_switch = data.url.substr(separator_position + 1); |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 69 | 70 |
| 70 TestRunner::~TestRunner() { | 71 TestRunner::~TestRunner() { |
| 71 } | 72 } |
| 72 | 73 |
| 73 TestRunner& TestRunner::Shared() { | 74 TestRunner& TestRunner::Shared() { |
| 74 if (!g_test_runner) | 75 if (!g_test_runner) |
| 75 g_test_runner = new TestRunner(); | 76 g_test_runner = new TestRunner(); |
| 76 return *g_test_runner; | 77 return *g_test_runner; |
| 77 } | 78 } |
| 78 | 79 |
| 79 void TestRunner::Start(const std::string& single_test_url) { | 80 void TestRunner::Start(scoped_ptr<SingleTest> single_test) { |
| 80 single_test_url_ = single_test_url; | 81 single_test_ = single_test.Pass(); |
| 81 PrintAndFlush("#READY\n"); | 82 PrintAndFlush("#READY\n"); |
| 82 ScheduleRun(); | 83 ScheduleRun(); |
| 83 } | 84 } |
| 84 | 85 |
| 85 void TestRunner::OnTestComplete(const mojo::String& test_result, | 86 void TestRunner::OnTestComplete(const mojo::String& test_result, |
| 86 const mojo::Array<uint8_t> pixels) { | 87 const mojo::Array<uint8_t> pixels) { |
| 87 std::cout << "Content-Type: text/plain\n"; | 88 std::cout << "Content-Type: text/plain\n"; |
| 88 std::cout << test_result << "\n"; | 89 std::cout << test_result << "\n"; |
| 89 PrintAndFlush("#EOF\n"); // Text result complete | 90 PrintAndFlush("#EOF\n"); // Text result complete |
| 90 PrintAndFlush("#EOF\n"); // Pixel result complete | 91 PrintAndFlush("#EOF\n"); // Pixel result complete |
| 91 std::cerr << "#EOF\n"; | 92 std::cerr << "#EOF\n"; |
| 92 std::cerr.flush(); | 93 std::cerr.flush(); |
| 93 bindings_.CloseAllBindings(); | 94 bindings_.CloseAllBindings(); |
| 94 | 95 |
| 95 if (single_test_url_.length()) | 96 if (single_test_) |
| 96 exit(0); | 97 exit(0); |
| 97 ScheduleRun(); | 98 ScheduleRun(); |
| 98 } | 99 } |
| 99 | 100 |
| 100 void TestRunner::DispatchInputEvent(mojo::EventPtr event) { | 101 void TestRunner::DispatchInputEvent(mojo::EventPtr event) { |
| 101 // TODO(abarth): Not implemented. | 102 // TODO(abarth): Not implemented. |
| 102 } | 103 } |
| 103 | 104 |
| 104 void TestRunner::Create(mojo::ApplicationConnection* app, | 105 void TestRunner::Create(mojo::ApplicationConnection* app, |
| 105 mojo::InterfaceRequest<TestHarness> request) { | 106 mojo::InterfaceRequest<TestHarness> request) { |
| 106 bindings_.AddBinding(this, request.Pass()); | 107 bindings_.AddBinding(this, request.Pass()); |
| 107 } | 108 } |
| 108 | 109 |
| 109 void TestRunner::ScheduleRun() { | 110 void TestRunner::ScheduleRun() { |
| 110 base::MessageLoop::current()->PostTask(FROM_HERE, | 111 base::MessageLoop::current()->PostTask(FROM_HERE, |
| 111 base::Bind(&TestRunner::Run, weak_ptr_factory_.GetWeakPtr())); | 112 base::Bind(&TestRunner::Run, weak_ptr_factory_.GetWeakPtr())); |
| 112 } | 113 } |
| 113 | 114 |
| 114 void TestRunner::Run() { | 115 void TestRunner::Run() { |
| 115 UrlData data; | 116 UrlData data; |
| 116 if (single_test_url_.length()) { | 117 if (single_test_) { |
| 117 data.url = single_test_url_; | 118 data.url = single_test_->path; |
| 119 data.is_snapshot = single_test_->is_snapshot; |
| 118 } else { | 120 } else { |
| 119 WaitForURL(data); | 121 WaitForURL(data); |
| 120 } | 122 } |
| 121 | 123 |
| 122 std::cout << "#BEGIN\n"; | 124 std::cout << "#BEGIN\n"; |
| 123 std::cout.flush(); | 125 std::cout.flush(); |
| 124 | 126 |
| 125 if (StartsWithASCII(data.url, kFileUrlPrefix, true)) | 127 if (StartsWithASCII(data.url, kFileUrlPrefix, true)) |
| 126 ReplaceFirstSubstringAfterOffset(&data.url, 0, kFileUrlPrefix, ""); | 128 ReplaceFirstSubstringAfterOffset(&data.url, 0, kFileUrlPrefix, ""); |
| 127 sky_engine_->RunFromFile(data.url, package_root_); | 129 |
| 130 if (data.is_snapshot) |
| 131 sky_engine_->RunFromSnapshot(data.url); |
| 132 else |
| 133 sky_engine_->RunFromFile(data.url, package_root_); |
| 128 } | 134 } |
| 129 | 135 |
| 130 } // namespace shell | 136 } // namespace shell |
| 131 } // namespace sky | 137 } // namespace sky |
| OLD | NEW |