Commit 9ed55271 authored by Miguel Casas's avatar Miguel Casas Committed by Commit Bot

canvas test: Extract MockEmbeddedFrameSinkProvider onto a new file

This CL follows up on comments on crrev.com/c/1238798 and
splits MockEmbeddedFrameSinkProvider onto a file on its own.
It also adds a member to be passed to MockCompositorFrameSink
to signal the expected number of calls to SetNeedsBeginFrame.

Bug: 888122
Cq-Include-Trybots: luci.chromium.try:linux_layout_tests_slimming_paint_v2;master.tryserver.blink:linux_trusty_blink_rel
Change-Id: Iceb35a215c6a4b34b152d2d1be077ef2c14e0234
Reviewed-on: https://chromium-review.googlesource.com/c/1248627Reviewed-by: default avatarKentaro Hara <haraken@chromium.org>
Reviewed-by: default avatardanakj <danakj@chromium.org>
Commit-Queue: Miguel Casas <mcasas@chromium.org>
Cr-Commit-Position: refs/heads/master@{#597382}
parent a8674799
......@@ -18,6 +18,7 @@
#include "third_party/blink/renderer/core/offscreencanvas/offscreen_canvas.h"
#include "third_party/blink/renderer/core/testing/page_test_base.h"
#include "third_party/blink/renderer/platform/graphics/test/mock_compositor_frame_sink.h"
#include "third_party/blink/renderer/platform/graphics/test/mock_embedded_frame_sink_provider.h"
using ::testing::_;
using ::testing::Values;
......@@ -90,9 +91,12 @@ TEST_P(HTMLCanvasElementModuleTest, LowLatencyCanvasCompositorFrameOpacity) {
CanvasContextCreationAttributesCore attrs;
attrs.alpha = context_alpha;
attrs.low_latency = true;
// |context_| creation triggers a SurfaceLayerBridge creation which in turn
// connects to our MockEmbeddedFrameSinkProvider.
EXPECT_CALL(mock_embedded_frame_sink_provider, CreateCompositorFrameSink(_));
// |context_| creation triggers a SurfaceLayerBridge creation which connects
// to a MockEmbeddedFrameSinkProvider to create a new CompositorFrameSink,
// that will receive a SetNeedsBeginFrame() upon construction.
mock_embedded_frame_sink_provider
.set_num_expected_set_needs_begin_frame_on_sink_construction(1);
EXPECT_CALL(mock_embedded_frame_sink_provider, CreateCompositorFrameSink_(_));
context_ = canvas_element().GetCanvasRenderingContext(String("2d"), attrs);
EXPECT_EQ(context_->CreationAttributes().alpha, attrs.alpha);
EXPECT_TRUE(context_->CreationAttributes().low_latency);
......@@ -100,12 +104,12 @@ TEST_P(HTMLCanvasElementModuleTest, LowLatencyCanvasCompositorFrameOpacity) {
EXPECT_TRUE(canvas_element().SurfaceLayerBridge());
platform->RunUntilIdle();
// This call simulates having drawn something before FinalizeFrame()
// This call simulates having drawn something before FinalizeFrame().
canvas_element().DidDraw();
::testing::InSequence s;
EXPECT_CALL(*mock_embedded_frame_sink_provider.mock_compositor_frame_sink_,
DoSubmitCompositorFrameSync(_))
EXPECT_CALL(mock_embedded_frame_sink_provider.mock_compositor_frame_sink(),
SubmitCompositorFrameSync_(_))
.WillOnce(::testing::WithArg<0>(
::testing::Invoke([context_alpha](const viz::CompositorFrame* frame) {
ASSERT_EQ(frame->render_pass_list.size(), 1u);
......@@ -120,7 +124,7 @@ TEST_P(HTMLCanvasElementModuleTest, LowLatencyCanvasCompositorFrameOpacity) {
EXPECT_NE(shared_quad_state_list.front()->are_contents_opaque,
context_alpha);
})));
EXPECT_CALL(*mock_embedded_frame_sink_provider.mock_compositor_frame_sink_,
EXPECT_CALL(mock_embedded_frame_sink_provider.mock_compositor_frame_sink(),
DidAllocateSharedBitmap(_, _));
canvas_element().FinalizeFrame();
platform->RunUntilIdle();
......
......@@ -18,6 +18,7 @@
#include "third_party/blink/renderer/platform/graphics/test/fake_gles2_interface.h"
#include "third_party/blink/renderer/platform/graphics/test/fake_web_graphics_context_3d_provider.h"
#include "third_party/blink/renderer/platform/graphics/test/mock_compositor_frame_sink.h"
#include "third_party/blink/renderer/platform/graphics/test/mock_embedded_frame_sink_provider.h"
#include "third_party/blink/renderer/platform/testing/testing_platform_support.h"
using ::testing::_;
......@@ -117,9 +118,12 @@ TEST_P(OffscreenCanvasTest, CompositorFrameOpacity) {
// Call here DidDraw() to simulate having drawn something before PushFrame()/
// Commit(); DidDraw() will in turn cause a CanvasResourceDispatcher to be
// created and a CreateCompositorFrameSink() to be issued.
// created and a CreateCompositorFrameSink() to be issued; this sink will get
// a SetNeedsBeginFrame() message sent upon construction.
mock_embedded_frame_sink_provider
.set_num_expected_set_needs_begin_frame_on_sink_construction(1);
EXPECT_CALL(mock_embedded_frame_sink_provider,
CreateCompositorFrameSink(viz::FrameSinkId(kClientId, kSinkId)));
CreateCompositorFrameSink_(viz::FrameSinkId(kClientId, kSinkId)));
offscreen_canvas().DidDraw();
platform->RunUntilIdle();
......@@ -130,8 +134,8 @@ TEST_P(OffscreenCanvasTest, CompositorFrameOpacity) {
kLow_SkFilterQuality);
EXPECT_TRUE(!!canvas_resource);
EXPECT_CALL(*mock_embedded_frame_sink_provider.mock_compositor_frame_sink_,
DoSubmitCompositorFrame(_))
EXPECT_CALL(mock_embedded_frame_sink_provider.mock_compositor_frame_sink(),
SubmitCompositorFrame_(_))
.WillOnce(::testing::WithArg<0>(
::testing::Invoke([context_alpha](const viz::CompositorFrame* frame) {
ASSERT_EQ(frame->render_pass_list.size(), 1u);
......@@ -149,8 +153,8 @@ TEST_P(OffscreenCanvasTest, CompositorFrameOpacity) {
offscreen_canvas().PushFrame(canvas_resource, SkIRect::MakeWH(10, 10));
platform->RunUntilIdle();
EXPECT_CALL(*mock_embedded_frame_sink_provider.mock_compositor_frame_sink_,
DoSubmitCompositorFrameSync(_))
EXPECT_CALL(mock_embedded_frame_sink_provider.mock_compositor_frame_sink(),
SubmitCompositorFrameSync_(_))
.WillOnce(::testing::WithArg<0>(
::testing::Invoke([context_alpha](const viz::CompositorFrame* frame) {
ASSERT_EQ(frame->render_pass_list.size(), 1u);
......
......@@ -2122,6 +2122,7 @@ jumbo_source_set("unit_tests") {
"graphics/test/fake_gles2_interface.h",
"graphics/test/fake_web_graphics_context_3d_provider.h",
"graphics/test/mock_compositor_frame_sink.h",
"graphics/test/mock_embedded_frame_sink_provider.h",
"graphics/test/mock_image_decoder.h",
"graphics/test/mock_paint_canvas.h",
"graphics/test/stub_image.h",
......
......@@ -13,6 +13,7 @@
#include "third_party/blink/renderer/platform/graphics/canvas_resource.h"
#include "third_party/blink/renderer/platform/graphics/canvas_resource_provider.h"
#include "third_party/blink/renderer/platform/graphics/test/mock_compositor_frame_sink.h"
#include "third_party/blink/renderer/platform/graphics/test/mock_embedded_frame_sink_provider.h"
#include "third_party/blink/renderer/platform/testing/testing_platform_support.h"
#include "third_party/blink/renderer/platform/wtf/functional.h"
#include "third_party/skia/include/core/SkSurface.h"
......@@ -213,7 +214,7 @@ TEST_P(CanvasResourceDispatcherTest, DispatchFrame) {
// CanvasResourceDispatcher ctor will cause a CreateCompositorFrameSink() to
// be issued.
EXPECT_CALL(mock_embedded_frame_sink_provider,
CreateCompositorFrameSink(viz::FrameSinkId(kClientId, kSinkId)));
CreateCompositorFrameSink_(viz::FrameSinkId(kClientId, kSinkId)));
platform->RunUntilIdle();
auto canvas_resource = CanvasResourceSharedBitmap::Create(
......@@ -231,8 +232,8 @@ TEST_P(CanvasResourceDispatcherTest, DispatchFrame) {
ASSERT_LE(kDamageHeight, kHeight);
EXPECT_CALL(*(Dispatcher()), PostImageToPlaceholder(_, _));
EXPECT_CALL(*mock_embedded_frame_sink_provider.mock_compositor_frame_sink_,
DoSubmitCompositorFrame(_))
EXPECT_CALL(mock_embedded_frame_sink_provider.mock_compositor_frame_sink(),
SubmitCompositorFrame_(_))
.WillOnce(::testing::WithArg<0>(
::testing::Invoke([context_alpha](const viz::CompositorFrame* frame) {
const viz::RenderPass* render_pass =
......
......@@ -6,22 +6,23 @@
#define THIRD_PARTY_BLINK_RENDERER_PLATFORM_GRAPHICS_TEST_MOCK_COMPOSITOR_FRAME_SINK_H_
#include "components/viz/common/quads/compositor_frame.h"
#include "services/viz/public/interfaces/compositing/compositor_frame_sink.mojom-blink.h"
#include "testing/gmock/include/gmock/gmock.h"
#include "third_party/blink/public/platform/modules/frame_sinks/embedded_frame_sink.mojom-blink.h"
#include "third_party/blink/renderer/platform/testing/testing_platform_support.h"
#include "third_party/blink/renderer/platform/wtf/functional.h"
namespace blink {
// A CompositorFrameSink to be offered by an EmbeddedFrameSinkProvider, for
// inspecting the viz::CompositorFrame sent to SubmitcompositorFrame()
// or SubmitcompositorFrameSync();
// A CompositorFrameSink for inspecting the viz::CompositorFrame sent to
// SubmitcompositorFrame() or SubmitcompositorFrameSync(); an object of this
// class may be offered by a MockEmbeddedFrameSinkProvider.
class MockCompositorFrameSink : public viz::mojom::blink::CompositorFrameSink {
public:
explicit MockCompositorFrameSink(
viz::mojom::blink::CompositorFrameSinkRequest request)
MockCompositorFrameSink(
viz::mojom::blink::CompositorFrameSinkRequest request,
int num_expected_set_needs_begin_frame_on_construction)
: binding_(this, std::move(request)) {
EXPECT_CALL(*this, SetNeedsBeginFrame(true)).Times(::testing::AnyNumber());
EXPECT_CALL(*this, SetNeedsBeginFrame(true))
.Times(num_expected_set_needs_begin_frame_on_construction);
}
// viz::mojom::blink::CompositorFrameSink implementation
......@@ -31,18 +32,18 @@ class MockCompositorFrameSink : public viz::mojom::blink::CompositorFrameSink {
viz::CompositorFrame frame,
viz::mojom::blink::HitTestRegionListPtr,
uint64_t) {
DoSubmitCompositorFrame(&frame);
SubmitCompositorFrame_(&frame);
}
MOCK_METHOD1(DoSubmitCompositorFrame, void(viz::CompositorFrame*));
MOCK_METHOD1(SubmitCompositorFrame_, void(viz::CompositorFrame*));
void SubmitCompositorFrameSync(const viz::LocalSurfaceId&,
viz::CompositorFrame frame,
viz::mojom::blink::HitTestRegionListPtr,
uint64_t,
SubmitCompositorFrameSyncCallback cb) {
DoSubmitCompositorFrameSync(&frame);
SubmitCompositorFrameSync_(&frame);
std::move(cb).Run(WTF::Vector<viz::ReturnedResource>());
}
MOCK_METHOD1(DoSubmitCompositorFrameSync, void(viz::CompositorFrame*));
MOCK_METHOD1(SubmitCompositorFrameSync_, void(viz::CompositorFrame*));
MOCK_METHOD1(DidNotProduceFrame, void(const viz::BeginFrameAck&));
MOCK_METHOD2(DidAllocateSharedBitmap,
void(mojo::ScopedSharedBufferHandle,
......@@ -55,54 +56,6 @@ class MockCompositorFrameSink : public viz::mojom::blink::CompositorFrameSink {
DISALLOW_COPY_AND_ASSIGN(MockCompositorFrameSink);
};
// A Provider that creates and binds a MockCompositorFrameSink when requested.
class MockEmbeddedFrameSinkProvider
: public mojom::blink::EmbeddedFrameSinkProvider {
public:
// EmbeddedFrameSinkProvider implementation.
MOCK_METHOD3(RegisterEmbeddedFrameSink,
void(const viz::FrameSinkId&,
const viz::FrameSinkId&,
mojom::blink::EmbeddedFrameSinkClientPtr));
void CreateCompositorFrameSink(
const viz::FrameSinkId& frame_sink_id,
viz::mojom::blink::CompositorFrameSinkClientPtr client,
viz::mojom::blink::CompositorFrameSinkRequest sink) override {
mock_compositor_frame_sink_ =
std::make_unique<MockCompositorFrameSink>(std::move(sink));
CreateCompositorFrameSink(frame_sink_id);
}
MOCK_METHOD1(CreateCompositorFrameSink, void(const viz::FrameSinkId&));
MOCK_METHOD5(CreateSimpleCompositorFrameSink,
void(const viz::FrameSinkId&,
const viz::FrameSinkId&,
mojom::blink::EmbeddedFrameSinkClientPtr,
viz::mojom::blink::CompositorFrameSinkClientPtr,
viz::mojom::blink::CompositorFrameSinkRequest));
std::unique_ptr<MockCompositorFrameSink> mock_compositor_frame_sink_;
// Utility method to create a scoped EmbeddedFrameSinkProvider override.
std::unique_ptr<TestingPlatformSupport::ScopedOverrideMojoInterface>
CreateScopedOverrideMojoInterface(
mojo::Binding<mojom::blink::EmbeddedFrameSinkProvider>* binding) {
using mojom::blink::EmbeddedFrameSinkProvider;
using mojom::blink::EmbeddedFrameSinkProviderRequest;
return std::make_unique<
TestingPlatformSupport::ScopedOverrideMojoInterface>(WTF::BindRepeating(
[](mojo::Binding<EmbeddedFrameSinkProvider>* binding,
const char* interface_name, mojo::ScopedMessagePipeHandle pipe) {
if (strcmp(interface_name, EmbeddedFrameSinkProvider::Name_))
return;
if (binding->is_bound())
binding->Unbind();
binding->Bind(EmbeddedFrameSinkProviderRequest(std::move(pipe)));
},
WTF::Unretained(binding)));
}
};
} // namespace blink
#endif // THIRD_PARTY_BLINK_RENDERER_PLATFORM_GRAPHICS_TEST_MOCK_COMPOSITOR_FRAME_SINK_H_
// Copyright 2018 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 THIRD_PARTY_BLINK_RENDERER_PLATFORM_GRAPHICS_TEST_MOCK_EMBEDDED_FRAME_SINK_PROVIDER_H_
#define THIRD_PARTY_BLINK_RENDERER_PLATFORM_GRAPHICS_TEST_MOCK_EMBEDDED_FRAME_SINK_PROVIDER_H_
#include <memory>
#include "components/viz/common/surfaces/frame_sink_id.h"
#include "testing/gmock/include/gmock/gmock.h"
#include "third_party/blink/public/platform/modules/frame_sinks/embedded_frame_sink.mojom-blink.h"
#include "third_party/blink/renderer/platform/testing/testing_platform_support.h"
#include "third_party/blink/renderer/platform/wtf/functional.h"
namespace blink {
class MockCompositorFrameSink;
// A Provider that creates and binds a MockCompositorFrameSink when requested.
class MockEmbeddedFrameSinkProvider
: public mojom::blink::EmbeddedFrameSinkProvider {
public:
// EmbeddedFrameSinkProvider implementation.
MOCK_METHOD3(RegisterEmbeddedFrameSink,
void(const viz::FrameSinkId&,
const viz::FrameSinkId&,
mojom::blink::EmbeddedFrameSinkClientPtr));
void CreateCompositorFrameSink(
const viz::FrameSinkId& frame_sink_id,
viz::mojom::blink::CompositorFrameSinkClientPtr client,
viz::mojom::blink::CompositorFrameSinkRequest sink) override {
mock_compositor_frame_sink_ = std::make_unique<MockCompositorFrameSink>(
std::move(sink),
num_expected_set_needs_begin_frame_on_sink_construction_);
CreateCompositorFrameSink_(frame_sink_id);
}
MOCK_METHOD1(CreateCompositorFrameSink_, void(const viz::FrameSinkId&));
MOCK_METHOD5(CreateSimpleCompositorFrameSink,
void(const viz::FrameSinkId&,
const viz::FrameSinkId&,
mojom::blink::EmbeddedFrameSinkClientPtr,
viz::mojom::blink::CompositorFrameSinkClientPtr,
viz::mojom::blink::CompositorFrameSinkRequest));
// Utility method to create a scoped EmbeddedFrameSinkProvider override.
std::unique_ptr<TestingPlatformSupport::ScopedOverrideMojoInterface>
CreateScopedOverrideMojoInterface(
mojo::Binding<mojom::blink::EmbeddedFrameSinkProvider>* binding) {
using mojom::blink::EmbeddedFrameSinkProvider;
using mojom::blink::EmbeddedFrameSinkProviderRequest;
return std::make_unique<
TestingPlatformSupport::ScopedOverrideMojoInterface>(WTF::BindRepeating(
[](mojo::Binding<EmbeddedFrameSinkProvider>* binding,
const char* interface_name, mojo::ScopedMessagePipeHandle pipe) {
if (strcmp(interface_name, EmbeddedFrameSinkProvider::Name_))
return;
if (binding->is_bound())
binding->Unbind();
binding->Bind(EmbeddedFrameSinkProviderRequest(std::move(pipe)));
},
WTF::Unretained(binding)));
}
MockCompositorFrameSink& mock_compositor_frame_sink() const {
return *mock_compositor_frame_sink_;
}
void set_num_expected_set_needs_begin_frame_on_sink_construction(int value) {
num_expected_set_needs_begin_frame_on_sink_construction_ = value;
}
private:
std::unique_ptr<MockCompositorFrameSink> mock_compositor_frame_sink_;
// Amount of SetNeedsBeginFrame() calls to be expected by
// MockCompositorFrameSink, passed on its construction.
int num_expected_set_needs_begin_frame_on_sink_construction_ = 0;
};
} // namespace blink
#endif // THIRD_PARTY_BLINK_RENDERER_PLATFORM_GRAPHICS_TEST_MOCK_EMBEDDED_FRAME_SINK_PROVIDER_H_
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment