| 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/tools/tester/test_runner.h" | 5 #include "sky/tools/tester/test_runner.h" |
| 6 | 6 |
| 7 #include <iostream> | 7 #include <iostream> |
| 8 #include "base/bind.h" | 8 #include "base/bind.h" |
| 9 #include "mojo/public/cpp/application/connect.h" | 9 #include "mojo/public/cpp/application/connect.h" |
| 10 #include "mojo/public/cpp/application/service_provider_impl.h" | 10 #include "mojo/public/cpp/application/service_provider_impl.h" |
| 11 #include "mojo/services/view_manager/public/cpp/view.h" | 11 #include "mojo/services/view_manager/public/cpp/view.h" |
| 12 | 12 |
| 13 namespace sky { | 13 namespace sky { |
| 14 namespace tester { | 14 namespace tester { |
| 15 | 15 |
| 16 TestRunnerClient::~TestRunnerClient() { | 16 TestRunnerClient::~TestRunnerClient() { |
| 17 } | 17 } |
| 18 | 18 |
| 19 TestRunner::TestRunner(TestRunnerClient* client, mojo::View* container, | 19 TestRunner::TestRunner(TestRunnerClient* client, mojo::View* container, |
| 20 const std::string& url) | 20 const std::string& url, bool enable_pixel_dumping) |
| 21 : test_harness_factory_(this), | 21 : test_harness_factory_(this), |
| 22 client_(client), | 22 client_(client), |
| 23 weak_ptr_factory_(this) { | 23 weak_ptr_factory_(this), |
| 24 enable_pixel_dumping_(enable_pixel_dumping) { |
| 24 CHECK(client); | 25 CHECK(client); |
| 25 | 26 |
| 26 scoped_ptr<mojo::ServiceProviderImpl> exported_services( | 27 scoped_ptr<mojo::ServiceProviderImpl> exported_services( |
| 27 new mojo::ServiceProviderImpl()); | 28 new mojo::ServiceProviderImpl()); |
| 28 exported_services->AddService(&test_harness_factory_); | 29 exported_services->AddService(&test_harness_factory_); |
| 29 | 30 |
| 30 container->Embed(url, exported_services.Pass()); | 31 container->Embed(url, exported_services.Pass()); |
| 31 } | 32 } |
| 32 | 33 |
| 33 TestRunner::~TestRunner() { | 34 TestRunner::~TestRunner() { |
| 34 } | 35 } |
| 35 | 36 |
| 36 base::WeakPtr<TestRunner> TestRunner::GetWeakPtr() { | 37 base::WeakPtr<TestRunner> TestRunner::GetWeakPtr() { |
| 37 return weak_ptr_factory_.GetWeakPtr(); | 38 return weak_ptr_factory_.GetWeakPtr(); |
| 38 } | 39 } |
| 39 | 40 |
| 40 void TestRunner::OnTestStart() { | 41 void TestRunner::OnTestStart() { |
| 41 std::cout << "#BEGIN\n"; | 42 std::cout << "#BEGIN\n"; |
| 42 std::cout.flush(); | 43 std::cout.flush(); |
| 43 } | 44 } |
| 44 | 45 |
| 45 void TestRunner::OnTestComplete(const std::string& test_result) { | 46 void TestRunner::OnTestComplete(const std::string& test_result, |
| 47 const std::string& pixels) { |
| 46 std::cout << "Content-Type: text/plain\n"; | 48 std::cout << "Content-Type: text/plain\n"; |
| 47 std::cout << test_result << "\n"; | 49 std::cout << test_result << "\n"; |
| 48 std::cout << "#EOF\n"; | 50 std::cout << "#EOF\n"; |
| 51 |
| 52 // TODO(ojan): Don't generate the pixels if enable_pixel_dumping_ is false. |
| 53 if (enable_pixel_dumping_) { |
| 54 // TODO(ojan): Add real hashes here once we want to do pixel tests. |
| 55 std::cout << "\nActualHash: FAKEHASHSTUB\n"; |
| 56 std::cout << "Content-Type: image/png\n"; |
| 57 std::cout << "Content-Length: " << pixels.size() << "\n"; |
| 58 std::cout << pixels << "\n"; |
| 59 } |
| 60 |
| 49 std::cout << "#EOF\n"; | 61 std::cout << "#EOF\n"; |
| 50 std::cout.flush(); | 62 std::cout.flush(); |
| 51 std::cerr << "#EOF\n"; | 63 std::cerr << "#EOF\n"; |
| 52 std::cerr.flush(); | 64 std::cerr.flush(); |
| 53 | 65 |
| 54 client_->OnTestComplete(); | 66 client_->OnTestComplete(); |
| 55 } | 67 } |
| 56 | 68 |
| 57 } // namespace tester | 69 } // namespace tester |
| 58 } // namespace sky | 70 } // namespace sky |
| OLD | NEW |