Index: content/browser/compositor/reflector_impl_unittest.cc |
diff --git a/content/browser/compositor/reflector_impl_unittest.cc b/content/browser/compositor/reflector_impl_unittest.cc |
new file mode 100644 |
index 0000000000000000000000000000000000000000..2bd9aa532863a9e03fbc0de15a3ef13cbb57563d |
--- /dev/null |
+++ b/content/browser/compositor/reflector_impl_unittest.cc |
@@ -0,0 +1,123 @@ |
+// Copyright 2015 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 "base/message_loop/message_loop.h" |
+#include "cc/test/fake_output_surface_client.h" |
+#include "cc/test/test_context_provider.h" |
+#include "cc/test/test_web_graphics_context_3d.h" |
+#include "content/browser/compositor/browser_compositor_output_surface.h" |
+#include "content/browser/compositor/reflector_impl.h" |
+#include "content/browser/compositor/test/no_transport_image_transport_factory.h" |
+#include "testing/gtest/include/gtest/gtest.h" |
+#include "ui/compositor/compositor.h" |
+#include "ui/compositor/layer.h" |
+#include "ui/compositor/test/context_factories_for_test.h" |
+ |
+namespace content { |
+namespace { |
+class TestOutputSurface : public BrowserCompositorOutputSurface { |
+ public: |
+ TestOutputSurface( |
+ const scoped_refptr<cc::ContextProvider>& context_provider, |
+ int surface_id, |
+ IDMap<BrowserCompositorOutputSurface>* output_surface_map, |
+ const scoped_refptr<ui::CompositorVSyncManager>& vsync_manager) |
+ : BrowserCompositorOutputSurface(context_provider, |
+ surface_id, |
+ output_surface_map, |
+ vsync_manager) {} |
+ |
+ void SetFlip(bool flip) { capabilities_.flipped_output_surface = flip; } |
danakj
2015/01/22 01:04:20
can you override BindToCurrentThread() and set thi
achaulk
2015/01/23 16:45:52
BindToCurrentThread is in the context provider tho
danakj
2015/01/23 17:48:29
Argh right sorry. Fuzzy head.
|
+ |
+ void SwapBuffers(cc::CompositorFrame* frame) override {} |
+}; |
+ |
+const gfx::Size size = gfx::Size(256, 256); |
danakj
2015/01/22 01:04:20
kSomeDescriptiveNameSize?
achaulk
2015/01/23 16:45:53
Done.
|
+} // namespace |
danakj
2015/01/22 01:04:21
normally i think we just wrap the whole file in a
achaulk
2015/01/23 16:45:52
ReflectorImplTest is a friend of ReflectorImpl
|
+ |
+class ReflectorImplTest : public testing::Test { |
+ public: |
+ void SetUp() override { |
+ bool enable_pixel_output = false; |
+ ui::ContextFactory* context_factory = |
+ ui::InitializeContextFactoryForTests(enable_pixel_output); |
+ ImageTransportFactory::InitializeForUnitTests( |
+ scoped_ptr<ImageTransportFactory>( |
+ new NoTransportImageTransportFactory)); |
+ message_loop_.reset(new base::MessageLoop()); |
+ proxy_ = message_loop_->message_loop_proxy(); |
+ compositor_.reset(new ui::Compositor(gfx::kNullAcceleratedWidget, |
+ context_factory, proxy_.get())); |
+ context_provider_ = cc::TestContextProvider::Create( |
+ cc::TestWebGraphicsContext3D::Create().Pass()); |
+ output_surface_ = |
+ scoped_ptr<TestOutputSurface>( |
+ new TestOutputSurface(context_provider_, 1, &surface_map_, |
+ compositor_->vsync_manager())).Pass(); |
+ CHECK(output_surface_->BindToClient(&output_surface_client_)); |
+ |
+ mirroring_layer_.reset(new ui::Layer()); |
+ mirroring_layer_->SetBounds(gfx::Rect(size.width(), size.height())); |
+ |
+ int32 surface_id = 1; |
+ reflector_ = new ReflectorImpl(compositor_.get(), mirroring_layer_.get(), |
+ &surface_map_, proxy_.get(), surface_id); |
+ } |
+ |
+ ~ReflectorImplTest() override { |
danakj
2015/01/22 01:04:20
I think you want these in Shutdown() rather than t
achaulk
2015/01/23 16:45:52
Done.
|
+ cc::TextureMailbox mailbox; |
+ scoped_ptr<cc::SingleReleaseCallback> release; |
+ if (mirroring_layer_->PrepareTextureMailbox(&mailbox, &release, false)) { |
+ release->Run(0, false); |
+ } |
+ compositor_.reset(); |
+ ui::TerminateContextFactoryForTests(); |
+ ImageTransportFactory::Terminate(); |
+ } |
+ |
+ void Init() { |
+ gpu::Mailbox mailbox; |
+ context_provider_->ContextGL()->GenMailboxCHROMIUM(mailbox.name); |
+ reflector_->AttachToOutputSurfaceOnImplThread( |
+ gpu::MailboxHolder(mailbox, GL_TEXTURE_2D, 0 /* sync_point */), |
+ output_surface_.get()); |
+ } |
+ |
+ void UpdateTexture() { |
+ reflector_->UpdateSubBufferOnMainThread(size, gfx::Rect(0, 0, 64, 64)); |
+ } |
+ |
+ protected: |
+ IDMap<BrowserCompositorOutputSurface> surface_map_; |
+ scoped_refptr<cc::ContextProvider> context_provider_; |
+ cc::FakeOutputSurfaceClient output_surface_client_; |
+ scoped_ptr<base::MessageLoop> message_loop_; |
+ scoped_refptr<base::MessageLoopProxy> proxy_; |
+ scoped_ptr<ui::Compositor> compositor_; |
+ scoped_ptr<ui::Layer> mirroring_layer_; |
+ scoped_refptr<ReflectorImpl> reflector_; |
+ scoped_ptr<TestOutputSurface> output_surface_; |
+}; |
+ |
+namespace { |
+TEST_F(ReflectorImplTest, CheckNormalOutputSurface) { |
+ output_surface_->SetFlip(false); |
+ Init(); |
+ UpdateTexture(); |
+ EXPECT_TRUE(mirroring_layer_->TextureFlipped()); |
+ EXPECT_EQ(SkRegion(SkIRect::MakeXYWH(0, size.height() - 64, 64, 64)), |
+ mirroring_layer_->damaged_region()); |
+} |
+ |
+TEST_F(ReflectorImplTest, CheckInvertedOutputSurface) { |
+ output_surface_->SetFlip(true); |
+ Init(); |
+ UpdateTexture(); |
+ EXPECT_FALSE(mirroring_layer_->TextureFlipped()); |
+ EXPECT_EQ(SkRegion(SkIRect::MakeXYWH(0, 0, 64, 64)), |
+ mirroring_layer_->damaged_region()); |
+} |
+ |
+} // namespace |
+} // namespace content |