Make reftests work for sky.
-Add a --testing flag to sky_viewer and cause it to paint into an
SkBitmap instead of a ganesh surface so we can get the pixels out.
-Add GetPixelsForTesting to layer.cc to actually grab out the pixels.
-Add a reftest and a mismatch reftest. They need a setTimeout after
the load event. Unclear why or what the right fix is. Maybe we should
give internals some way to force the paint? If we don't have the
setTimeout, we paint a white page (so we do a paint, but with no
content).
-Add a DisplayDelegate to Layer so that Viewer can decide whether
to use the real ganesh backend or the SkBitmap one without littering
the whole code-base with is_testing bools and logic.
R=esprehn@chromium.org
Review URL: https://codereview.chromium.org/797063002
diff --git a/examples/sky_compositor_app/sky_compositor_app.cc b/examples/sky_compositor_app/sky_compositor_app.cc
index 6d6342b..9bb7974 100644
--- a/examples/sky_compositor_app/sky_compositor_app.cc
+++ b/examples/sky_compositor_app/sky_compositor_app.cc
@@ -12,6 +12,7 @@
#include "mojo/services/view_manager/public/cpp/view_manager.h"
#include "mojo/services/view_manager/public/cpp/view_manager_client_factory.h"
#include "mojo/services/view_manager/public/cpp/view_manager_delegate.h"
+#include "sky/compositor/display_delegate_ganesh.h"
#include "sky/compositor/layer.h"
#include "sky/compositor/layer_host.h"
#include "third_party/skia/include/core/SkCanvas.h"
@@ -40,6 +41,9 @@
shell_ = app->shell();
view_manager_client_factory_.reset(
new mojo::ViewManagerClientFactory(app->shell(), this));
+
+ sky::DisplayDelegate::setDisplayDelegateCreateFunction(
+ sky::DisplayDelegateGanesh::create);
}
bool ConfigureIncomingConnection(
diff --git a/sky/compositor/BUILD.gn b/sky/compositor/BUILD.gn
index 2e03d45..71a4888 100644
--- a/sky/compositor/BUILD.gn
+++ b/sky/compositor/BUILD.gn
@@ -4,6 +4,12 @@
source_set("compositor") {
sources = [
+ "display_delegate.cc",
+ "display_delegate.h",
+ "display_delegate_bitmap.cc",
+ "display_delegate_bitmap.h",
+ "display_delegate_ganesh.cc",
+ "display_delegate_ganesh.h",
"layer.cc",
"layer.h",
"layer_client.cc",
diff --git a/sky/compositor/display_delegate.cc b/sky/compositor/display_delegate.cc
new file mode 100644
index 0000000..c868558
--- /dev/null
+++ b/sky/compositor/display_delegate.cc
@@ -0,0 +1,24 @@
+// 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/compositor/display_delegate.h"
+
+namespace sky {
+
+static CreateDisplayDelegate createDisplayDelegateFunction = 0;
+
+void DisplayDelegate::setDisplayDelegateCreateFunction(CreateDisplayDelegate createFunction)
+{
+ DCHECK(createFunction);
+ DCHECK(!createDisplayDelegateFunction);
+ createDisplayDelegateFunction = createFunction;
+}
+
+DisplayDelegate* DisplayDelegate::create(LayerClient* client)
+{
+ DCHECK(createDisplayDelegateFunction);
+ return createDisplayDelegateFunction(client);
+}
+
+} // namespace sky
diff --git a/sky/compositor/display_delegate.h b/sky/compositor/display_delegate.h
new file mode 100644
index 0000000..800e4c7
--- /dev/null
+++ b/sky/compositor/display_delegate.h
@@ -0,0 +1,43 @@
+// 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.
+
+#ifndef SKY_COMPOSITOR_DISPLAY_DELEGATE_H_
+#define SKY_COMPOSITOR_DISPLAY_DELEGATE_H_
+
+#include <vector>
+
+#include "mojo/skia/ganesh_surface.h"
+
+class SkCanvas;
+
+namespace gfx {
+class Rect;
+}
+
+namespace sky {
+
+class DisplayDelegate;
+class LayerClient;
+
+typedef DisplayDelegate* (*CreateDisplayDelegate)(LayerClient*);
+
+class DisplayDelegate {
+ public:
+ DisplayDelegate() {}
+ virtual ~DisplayDelegate() {}
+
+ static DisplayDelegate* create(LayerClient*);
+ static void setDisplayDelegateCreateFunction(CreateDisplayDelegate);
+
+ virtual void GetPixelsForTesting(std::vector<unsigned char>* pixels) = 0;
+ virtual void Paint(mojo::GaneshSurface& surface, const gfx::Rect& size) = 0;
+
+ DISALLOW_COPY_AND_ASSIGN(DisplayDelegate);
+};
+
+
+
+} // namespace sky
+
+#endif // SKY_COMPOSITOR_DISPLAY_DELEGATE_H_
diff --git a/sky/compositor/display_delegate_bitmap.cc b/sky/compositor/display_delegate_bitmap.cc
new file mode 100644
index 0000000..571eda1
--- /dev/null
+++ b/sky/compositor/display_delegate_bitmap.cc
@@ -0,0 +1,39 @@
+// 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/compositor/display_delegate_bitmap.h"
+
+#include "sky/compositor/layer_client.h"
+#include "third_party/skia/include/core/SkBitmapDevice.h"
+#include "third_party/skia/include/core/SkCanvas.h"
+#include "ui/gfx/codec/png_codec.h"
+#include "ui/gfx/geometry/rect.h"
+
+namespace sky {
+
+DisplayDelegateBitmap::DisplayDelegateBitmap(LayerClient* client)
+ : client_(client) {}
+
+DisplayDelegateBitmap::~DisplayDelegateBitmap() {}
+
+DisplayDelegate* DisplayDelegateBitmap::create(LayerClient* client) {
+ return new DisplayDelegateBitmap(client);
+}
+
+void DisplayDelegateBitmap::GetPixelsForTesting(std::vector<unsigned char>* pixels) {
+ gfx::PNGCodec::EncodeBGRASkBitmap(bitmap_, false, pixels);
+}
+
+void DisplayDelegateBitmap::Paint(mojo::GaneshSurface& surface, const gfx::Rect& size) {
+ bitmap_.allocN32Pixels(size.width(), size.height());
+ SkBitmapDevice device(bitmap_);
+ SkCanvas canvas(&device);
+ // Draw red so we can see when we fail to paint.
+ canvas.drawColor(SK_ColorRED);
+
+ client_->PaintContents(&canvas, size);
+ canvas.flush();
+}
+
+} // namespace sky
diff --git a/sky/compositor/display_delegate_bitmap.h b/sky/compositor/display_delegate_bitmap.h
new file mode 100644
index 0000000..4df1cf9
--- /dev/null
+++ b/sky/compositor/display_delegate_bitmap.h
@@ -0,0 +1,33 @@
+// 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.
+
+#ifndef SKY_COMPOSITOR_DISPLAY_DELEGATE_BITMAP_H_
+#define SKY_COMPOSITOR_DISPLAY_DELEGATE_BITMAP_H_
+
+#include "sky/compositor/display_delegate.h"
+
+namespace sky {
+
+class LayerClient;
+
+class DisplayDelegateBitmap final : public DisplayDelegate {
+ public:
+ explicit DisplayDelegateBitmap(LayerClient* client);
+ ~DisplayDelegateBitmap() override;
+
+ static DisplayDelegate* create(LayerClient* client);
+
+ void GetPixelsForTesting(std::vector<unsigned char>* pixels) override;
+ void Paint(mojo::GaneshSurface& surface, const gfx::Rect& size) override;
+
+ private:
+ SkBitmap bitmap_;
+ LayerClient* client_;
+
+ DISALLOW_COPY_AND_ASSIGN(DisplayDelegateBitmap);
+};
+
+} // namespace sky
+
+#endif // SKY_COMPOSITOR_DISPLAY_DELEGATE_BITMAP_H_
diff --git a/sky/compositor/display_delegate_ganesh.cc b/sky/compositor/display_delegate_ganesh.cc
new file mode 100644
index 0000000..0d93c96
--- /dev/null
+++ b/sky/compositor/display_delegate_ganesh.cc
@@ -0,0 +1,27 @@
+// 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/compositor/display_delegate_ganesh.h"
+
+#include "sky/compositor/layer_client.h"
+#include "third_party/skia/include/core/SkCanvas.h"
+
+namespace sky {
+
+DisplayDelegate* DisplayDelegateGanesh::create(LayerClient* client) {
+ return new DisplayDelegateGanesh(client);
+}
+
+void DisplayDelegateGanesh::GetPixelsForTesting(std::vector<unsigned char>* pixels) {
+ // TODO(ojan): When we change notifyTestComplete to only GetPixelsForTesting
+ // in pixel/ref tests, add a NOTREACHED() here.
+}
+
+void DisplayDelegateGanesh::Paint(mojo::GaneshSurface& surface, const gfx::Rect& size) {
+ SkCanvas* canvas = surface.canvas();
+ client_->PaintContents(canvas, size);
+ canvas->flush();
+}
+
+} // namespace sky
diff --git a/sky/compositor/display_delegate_ganesh.h b/sky/compositor/display_delegate_ganesh.h
new file mode 100644
index 0000000..1b2deb5
--- /dev/null
+++ b/sky/compositor/display_delegate_ganesh.h
@@ -0,0 +1,31 @@
+// 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.
+
+#ifndef SKY_COMPOSITOR_DISPLAY_DELEGATE_GANESH_H_
+#define SKY_COMPOSITOR_DISPLAY_DELEGATE_GANESH_H_
+
+#include "sky/compositor/display_delegate.h"
+
+namespace sky {
+
+class LayerClient;
+
+class DisplayDelegateGanesh final : public DisplayDelegate {
+ public:
+ explicit DisplayDelegateGanesh(LayerClient* client) : client_(client) {}
+ ~DisplayDelegateGanesh() override {}
+
+ static DisplayDelegate* create(LayerClient* client);
+
+ void GetPixelsForTesting(std::vector<unsigned char>* pixels) override;
+ void Paint(mojo::GaneshSurface& surface, const gfx::Rect& size) override;
+
+ private:
+ LayerClient* client_;
+ DISALLOW_COPY_AND_ASSIGN(DisplayDelegateGanesh);
+};
+
+} // namespace sky
+
+#endif // SKY_COMPOSITOR_DISPLAY_DELEGATE_GANESH_H_
diff --git a/sky/compositor/layer.cc b/sky/compositor/layer.cc
index 8d2ec8b..1142093 100644
--- a/sky/compositor/layer.cc
+++ b/sky/compositor/layer.cc
@@ -6,25 +6,29 @@
#include "base/debug/trace_event.h"
#include "mojo/skia/ganesh_surface.h"
+#include "sky/compositor/display_delegate.h"
#include "sky/compositor/layer_host.h"
#include "third_party/skia/include/core/SkCanvas.h"
namespace sky {
-Layer::Layer(LayerClient* client) : client_(client), host_(nullptr) {
+Layer::Layer(LayerClient* client)
+ : client_(client),
+ host_(nullptr) {
+ delegate_.reset(DisplayDelegate::create(client));
}
Layer::~Layer() {
}
-void Layer::ClearClient() {
- client_ = nullptr;
-}
-
void Layer::SetSize(const gfx::Size& size) {
size_ = size;
}
+void Layer::GetPixelsForTesting(std::vector<unsigned char>* pixels) {
+ delegate_->GetPixelsForTesting(pixels);
+}
+
void Layer::Display() {
TRACE_EVENT0("sky", "Layer::Display");
@@ -33,11 +37,8 @@
mojo::GaneshSurface surface(host_->ganesh_context(),
host_->resource_manager()->CreateTexture(size_));
- SkCanvas* canvas = surface.canvas();
-
gfx::Rect rect(size_);
- client_->PaintContents(canvas, rect);
- canvas->flush();
+ delegate_->Paint(surface, rect);
texture_ = surface.TakeTexture();
}
diff --git a/sky/compositor/layer.h b/sky/compositor/layer.h
index 9492527..0f478bb 100644
--- a/sky/compositor/layer.h
+++ b/sky/compositor/layer.h
@@ -11,15 +11,16 @@
#include "ui/gfx/geometry/rect.h"
namespace sky {
+
+class DisplayDelegate;
class LayerHost;
class Layer : public base::RefCounted<Layer> {
public:
explicit Layer(LayerClient* client);
- void ClearClient();
-
void SetSize(const gfx::Size& size);
+ void GetPixelsForTesting(std::vector<unsigned char>* pixels);
void Display();
scoped_ptr<mojo::GLTexture> GetTexture();
@@ -35,8 +36,8 @@
LayerClient* client_;
LayerHost* host_;
gfx::Size size_;
-
scoped_ptr<mojo::GLTexture> texture_;
+ scoped_ptr<DisplayDelegate> delegate_;
DISALLOW_COPY_AND_ASSIGN(Layer);
};
diff --git a/sky/compositor/layer_host.cc b/sky/compositor/layer_host.cc
index 36b3ec2..1739c78 100644
--- a/sky/compositor/layer_host.cc
+++ b/sky/compositor/layer_host.cc
@@ -42,6 +42,10 @@
root_layer_->set_host(this);
}
+void LayerHost::GetPixelsForTesting(std::vector<unsigned char>* pixels) {
+ return root_layer_->GetPixelsForTesting(pixels);
+}
+
void LayerHost::OnSurfaceConnectionCreated() {
DCHECK_EQ(state_, kWaitingForSurfaceService);
state_ = kReadyForFrame;
diff --git a/sky/compositor/layer_host.h b/sky/compositor/layer_host.h
index 0b9616c..390bc84 100644
--- a/sky/compositor/layer_host.h
+++ b/sky/compositor/layer_host.h
@@ -41,6 +41,8 @@
void SetNeedsAnimate();
void SetRootLayer(scoped_refptr<Layer> layer);
+ void GetPixelsForTesting(std::vector<unsigned char>* pixels);
+
private:
enum State {
kWaitingForSurfaceService,
diff --git a/sky/services/testing/test_harness.mojom b/sky/services/testing/test_harness.mojom
index 0b8d375..0b735b8 100644
--- a/sky/services/testing/test_harness.mojom
+++ b/sky/services/testing/test_harness.mojom
@@ -7,6 +7,6 @@
import "mojo/services/input_events/public/interfaces/input_events.mojom";
interface TestHarness {
- OnTestComplete(string test_result);
+ OnTestComplete(string test_result, array<uint8>? pixels);
DispatchInputEvent(mojo.Event event);
};
diff --git a/sky/tests/harness/reftest-expected.sky b/sky/tests/harness/reftest-expected.sky
new file mode 100644
index 0000000..7a7e586
--- /dev/null
+++ b/sky/tests/harness/reftest-expected.sky
@@ -0,0 +1,12 @@
+<foo>
+This is a reftest.
+<script>
+window.addEventListener('load', function() {
+ // TODO(ojan): requestAnimationFrame once we properly pump frames.
+ // https://github.com/domokit/mojo/issues/32
+ setTimeout(function() {
+ internals.notifyTestComplete("");
+ }, 100);
+})
+</script>
+</foo>
diff --git a/sky/tests/harness/reftest-mismatch-expected-mismatch.sky b/sky/tests/harness/reftest-mismatch-expected-mismatch.sky
new file mode 100644
index 0000000..25e46f8
--- /dev/null
+++ b/sky/tests/harness/reftest-mismatch-expected-mismatch.sky
@@ -0,0 +1,12 @@
+<foo>
+This is a mismatch reftest.
+<script>
+window.addEventListener('load', function() {
+ // TODO(ojan): requestAnimationFrame once we properly pump frames.
+ // https://github.com/domokit/mojo/issues/32
+ setTimeout(function() {
+ internals.notifyTestComplete("");
+ }, 100);
+})
+</script>
+</foo>
diff --git a/sky/tests/harness/reftest-mismatch.sky b/sky/tests/harness/reftest-mismatch.sky
new file mode 100644
index 0000000..a016a24
--- /dev/null
+++ b/sky/tests/harness/reftest-mismatch.sky
@@ -0,0 +1,12 @@
+<foo>
+This is a mismatch reftest. Should not match.
+<script>
+window.addEventListener('load', function() {
+ // TODO(ojan): requestAnimationFrame once we properly pump frames.
+ // https://github.com/domokit/mojo/issues/32
+ setTimeout(function() {
+ internals.notifyTestComplete("");
+ }, 100);
+})
+</script>
+</foo>
diff --git a/sky/tests/harness/reftest.sky b/sky/tests/harness/reftest.sky
new file mode 100644
index 0000000..7a7e586
--- /dev/null
+++ b/sky/tests/harness/reftest.sky
@@ -0,0 +1,12 @@
+<foo>
+This is a reftest.
+<script>
+window.addEventListener('load', function() {
+ // TODO(ojan): requestAnimationFrame once we properly pump frames.
+ // https://github.com/domokit/mojo/issues/32
+ setTimeout(function() {
+ internals.notifyTestComplete("");
+ }, 100);
+})
+</script>
+</foo>
diff --git a/sky/tools/tester/test_harness_impl.cc b/sky/tools/tester/test_harness_impl.cc
index 79a3f75..882aff3 100644
--- a/sky/tools/tester/test_harness_impl.cc
+++ b/sky/tools/tester/test_harness_impl.cc
@@ -20,9 +20,10 @@
TestHarnessImpl::~TestHarnessImpl() {
}
-void TestHarnessImpl::OnTestComplete(const mojo::String& test_result) {
+void TestHarnessImpl::OnTestComplete(const mojo::String& test_result,
+ const mojo::Array<uint8_t> pixels) {
if (test_runner_)
- test_runner_->OnTestComplete(test_result);
+ test_runner_->OnTestComplete(test_result, pixels);
}
void TestHarnessImpl::DispatchInputEvent(mojo::EventPtr event) {
diff --git a/sky/tools/tester/test_harness_impl.h b/sky/tools/tester/test_harness_impl.h
index 01d0c75..8a59703 100644
--- a/sky/tools/tester/test_harness_impl.h
+++ b/sky/tools/tester/test_harness_impl.h
@@ -21,7 +21,8 @@
private:
// TestHarness implementation.
- void OnTestComplete(const mojo::String& test_result) override;
+ void OnTestComplete(const mojo::String& test_result,
+ const mojo::Array<uint8_t> pixels) override;
void DispatchInputEvent(mojo::EventPtr event) override;
base::WeakPtr<TestRunner> test_runner_;
diff --git a/sky/tools/tester/test_runner.cc b/sky/tools/tester/test_runner.cc
index 78125ee..4f948be 100644
--- a/sky/tools/tester/test_runner.cc
+++ b/sky/tools/tester/test_runner.cc
@@ -17,10 +17,11 @@
}
TestRunner::TestRunner(TestRunnerClient* client, mojo::View* container,
- const std::string& url)
+ const std::string& url, bool enable_pixel_dumping)
: test_harness_factory_(this),
client_(client),
- weak_ptr_factory_(this) {
+ weak_ptr_factory_(this),
+ enable_pixel_dumping_(enable_pixel_dumping) {
CHECK(client);
scoped_ptr<mojo::ServiceProviderImpl> exported_services(
@@ -42,10 +43,22 @@
std::cout.flush();
}
-void TestRunner::OnTestComplete(const std::string& test_result) {
+void TestRunner::OnTestComplete(const std::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";
+
+ // TODO(ojan): Don't generate the pixels if enable_pixel_dumping_ is false.
+ if (enable_pixel_dumping_) {
+ // TODO(ojan): Add real hashes here once we want to do pixel tests.
+ std::cout << "\nActualHash: FAKEHASHSTUB\n";
+ std::cout << "Content-Type: image/png\n";
+ std::cout << "Content-Length: " << pixels.size() << "\n";
+ std::cout.write(
+ reinterpret_cast<const char*>(&pixels[0]), pixels.size());
+ }
+
std::cout << "#EOF\n";
std::cout.flush();
std::cerr << "#EOF\n";
diff --git a/sky/tools/tester/test_runner.h b/sky/tools/tester/test_runner.h
index 3c52f85..7e2d45b 100644
--- a/sky/tools/tester/test_runner.h
+++ b/sky/tools/tester/test_runner.h
@@ -27,7 +27,7 @@
class TestRunner {
public:
TestRunner(TestRunnerClient* client, mojo::View* container,
- const std::string& url);
+ const std::string& url, bool enable_pixel_dumping);
virtual ~TestRunner();
TestRunnerClient* client() const { return client_; }
@@ -35,12 +35,14 @@
base::WeakPtr<TestRunner> GetWeakPtr();
void OnTestStart();
- void OnTestComplete(const std::string& test_result);
+ void OnTestComplete(const std::string& test_result,
+ const mojo::Array<uint8_t>& pixels);
private:
TestHarnessFactory test_harness_factory_;
TestRunnerClient* client_;
base::WeakPtrFactory<TestRunner> weak_ptr_factory_;
+ bool enable_pixel_dumping_;
MOJO_DISALLOW_COPY_AND_ASSIGN(TestRunner);
};
diff --git a/sky/tools/tester/tester.cc b/sky/tools/tester/tester.cc
index 19f0db8..4ee889e 100644
--- a/sky/tools/tester/tester.cc
+++ b/sky/tools/tester/tester.cc
@@ -23,10 +23,32 @@
namespace tester {
namespace {
-std::string WaitForURL() {
+struct UrlData {
std::string url;
- std::cin >> url;
- return url;
+ std::string expected_pixel_hash;
+ bool enable_pixel_dumping = false;
+};
+
+void WaitForURL(UrlData& data) {
+ // 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;
}
} // namespace
@@ -110,8 +132,16 @@
void Run() {
DCHECK(!test_runner_);
- std::string url = url_from_args_.length() ? url_from_args_ : WaitForURL();
- test_runner_.reset(new TestRunner(this, content_, url));
+
+ UrlData data;
+ if (url_from_args_.length()) {
+ data.url = url_from_args_;
+ } else {
+ WaitForURL(data);
+ }
+
+ test_runner_.reset(new TestRunner(this, content_, data.url,
+ data.enable_pixel_dumping));
}
void OnTestComplete() override {
diff --git a/sky/tools/webkitpy/layout_tests/port/base.py b/sky/tools/webkitpy/layout_tests/port/base.py
index efcfa6f..8ab13b1 100644
--- a/sky/tools/webkitpy/layout_tests/port/base.py
+++ b/sky/tools/webkitpy/layout_tests/port/base.py
@@ -229,6 +229,7 @@
if driver_name == self.MOJO_SHELL_NAME:
return [
'--args-for=mojo:native_viewport_service --use-headless-config --use-osmesa',
+ '--args-for=mojo:sky_viewer --testing',
'--content-handlers=text/sky,mojo:sky_viewer',
'--url-mappings=mojo:window_manager=mojo:sky_tester',
'mojo:window_manager',
diff --git a/sky/viewer/document_view.cc b/sky/viewer/document_view.cc
index 51eae14..722a935 100644
--- a/sky/viewer/document_view.cc
+++ b/sky/viewer/document_view.cc
@@ -80,8 +80,8 @@
root_(NULL),
view_manager_client_factory_(shell_, this),
inspector_service_factory_(this),
- debugger_id_(s_next_debugger_id++),
- weak_factory_(this) {
+ weak_factory_(this),
+ debugger_id_(s_next_debugger_id++) {
exported_services_.AddService(&view_manager_client_factory_);
mojo::WeakBindToPipe(&exported_services_, provider.PassMessagePipe());
}
@@ -135,6 +135,10 @@
layer_host_->SetRootLayer(root_layer_);
}
+void DocumentView::GetPixelsForTesting(std::vector<unsigned char>* pixels) {
+ return layer_host_->GetPixelsForTesting(pixels);
+}
+
mojo::Shell* DocumentView::GetShell() {
return shell_;
}
diff --git a/sky/viewer/document_view.h b/sky/viewer/document_view.h
index b580c5f..0d4006c 100644
--- a/sky/viewer/document_view.h
+++ b/sky/viewer/document_view.h
@@ -70,6 +70,8 @@
void StartDebuggerInspectorBackend();
+ void GetPixelsForTesting(std::vector<unsigned char>* pixels);
+
private:
// WebWidgetClient methods:
void initializeLayerTreeView() override;
@@ -129,9 +131,9 @@
scoped_ptr<ScriptRunner> script_runner_;
scoped_ptr<InspectorHostImpl> inspector_host_;
scoped_ptr<inspector::InspectorBackendMojo> inspector_backend_;
+ base::WeakPtrFactory<DocumentView> weak_factory_;
int debugger_id_;
- base::WeakPtrFactory<DocumentView> weak_factory_;
DISALLOW_COPY_AND_ASSIGN(DocumentView);
};
diff --git a/sky/viewer/internals.cc b/sky/viewer/internals.cc
index 0288b9c..99e8c3b 100644
--- a/sky/viewer/internals.cc
+++ b/sky/viewer/internals.cc
@@ -8,6 +8,7 @@
#include "mojo/edk/js/handle.h"
#include "mojo/edk/js/support.h"
#include "mojo/public/cpp/application/connect.h"
+#include "mojo/public/cpp/bindings/array.h"
#include "mojo/public/interfaces/application/shell.mojom.h"
#include "sky/engine/public/web/WebDocument.h"
#include "sky/engine/public/web/WebFrame.h"
@@ -65,7 +66,10 @@
}
void Internals::NotifyTestComplete(const std::string& test_result) {
- test_harness_->OnTestComplete(test_result);
+ std::vector<unsigned char> pixels;
+ document_view_->GetPixelsForTesting(&pixels);
+ test_harness_->OnTestComplete(test_result,
+ mojo::Array<uint8_t>::From(pixels));
}
mojo::Handle Internals::ConnectToService(
diff --git a/sky/viewer/viewer.cc b/sky/viewer/viewer.cc
index eb5b6d0..4c5dd74 100644
--- a/sky/viewer/viewer.cc
+++ b/sky/viewer/viewer.cc
@@ -13,6 +13,8 @@
#include "mojo/public/cpp/application/application_impl.h"
#include "mojo/public/cpp/application/interface_factory_impl.h"
#include "mojo/services/content_handler/public/interfaces/content_handler.mojom.h"
+#include "sky/compositor/display_delegate_bitmap.h"
+#include "sky/compositor/display_delegate_ganesh.h"
#include "sky/engine/public/web/Sky.h"
#include "sky/viewer/content_handler_impl.h"
#include "sky/viewer/document_view.h"
@@ -24,6 +26,9 @@
namespace sky {
+// Load the viewer in testing mode so we can dump pixels.
+const char kTesting[] = "--testing";
+
class Viewer : public mojo::ApplicationDelegate,
public mojo::InterfaceFactory<mojo::ContentHandler> {
public:
@@ -34,6 +39,14 @@
private:
// Overridden from ApplicationDelegate:
virtual void Initialize(mojo::ApplicationImpl* app) override {
+ if (app->HasArg(kTesting)) {
+ DisplayDelegate::setDisplayDelegateCreateFunction(
+ DisplayDelegateBitmap::create);
+ } else {
+ DisplayDelegate::setDisplayDelegateCreateFunction(
+ DisplayDelegateGanesh::create);
+ }
+
platform_impl_.reset(new PlatformImpl(app));
blink::initialize(platform_impl_.get());
base::i18n::InitializeICU();