Chromium Code Reviews| Index: cc/trees/layer_tree_host_unittest_no_message_loop.cc |
| diff --git a/cc/trees/layer_tree_host_unittest_no_message_loop.cc b/cc/trees/layer_tree_host_unittest_no_message_loop.cc |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..42c3e2464840546d79993ef5f45873759e73f21b |
| --- /dev/null |
| +++ b/cc/trees/layer_tree_host_unittest_no_message_loop.cc |
| @@ -0,0 +1,134 @@ |
| +// 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 "base/message_loop/message_loop_proxy.h" |
| +#include "base/threading/simple_thread.h" |
| +#include "cc/layers/delegated_renderer_layer.h" |
| +#include "cc/layers/layer.h" |
| +#include "cc/layers/solid_color_layer.h" |
| +#include "cc/output/output_surface.h" |
| +#include "cc/output/output_surface_client.h" |
| +#include "cc/test/test_context_provider.h" |
| +#include "cc/trees/layer_tree_host.h" |
| +#include "cc/trees/layer_tree_host_client.h" |
| +#include "cc/trees/layer_tree_host_single_thread_client.h" |
| +#include "testing/gtest/include/gtest/gtest.h" |
| +#include "third_party/skia/include/core/SkColor.h" |
| +#include "ui/gfx/frame_time.h" |
| + |
| +namespace cc { |
| +namespace { |
| + |
| +class NoMessageLoopOutputSurface : public OutputSurface { |
| + public: |
| + NoMessageLoopOutputSurface() : OutputSurface(TestContextProvider::Create()) {} |
| + virtual ~NoMessageLoopOutputSurface() {} |
| + |
| + // OutputSurface overrides. |
| + virtual void SwapBuffers(CompositorFrame* frame) OVERRIDE { |
| + DCHECK(client_); |
| + client_->DidSwapBuffers(); |
| + client_->DidSwapBuffersComplete(); |
| + } |
| +}; |
| + |
| +class LayerTreeHostNoMessageLoopTest : public testing::Test, |
| + public base::SimpleThread, |
|
piman
2014/05/22 20:53:30
multiple implementation inheritance is unfortunate
boliu
2014/05/22 23:17:37
Done
|
| + public LayerTreeHostClient, |
| + public LayerTreeHostSingleThreadClient { |
| + public: |
| + LayerTreeHostNoMessageLoopTest() |
| + : base::SimpleThread("LayerTreeHostNoMessageLoopTest"), |
| + did_initialize_output_surface_(false), |
| + did_commit_(false), |
| + did_commit_and_draw_frame_(false) {} |
| + virtual ~LayerTreeHostNoMessageLoopTest() {} |
| + |
| + // LayerTreeHostClient overrides. |
| + virtual void WillBeginMainFrame(int frame_id) OVERRIDE {} |
| + virtual void DidBeginMainFrame() OVERRIDE {} |
| + virtual void Animate(base::TimeTicks frame_begin_time) OVERRIDE {} |
| + virtual void Layout() OVERRIDE {} |
| + virtual void ApplyScrollAndScale(const gfx::Vector2d& scroll_delta, |
| + float page_scale) OVERRIDE {} |
| + virtual scoped_ptr<OutputSurface> CreateOutputSurface( |
| + bool fallback) OVERRIDE { |
| + return make_scoped_ptr<OutputSurface>(new NoMessageLoopOutputSurface); |
| + } |
| + virtual void DidInitializeOutputSurface() OVERRIDE { |
| + did_initialize_output_surface_ = true; |
| + } |
| + virtual void WillCommit() OVERRIDE {} |
| + virtual void DidCommit() OVERRIDE { did_commit_ = true; } |
| + virtual void DidCommitAndDrawFrame() OVERRIDE { |
| + did_commit_and_draw_frame_ = true; |
| + } |
| + virtual void DidCompleteSwapBuffers() OVERRIDE {} |
| + |
| + // LayerTreeHostSingleThreadClient overrides. |
| + virtual void ScheduleComposite() OVERRIDE {} |
| + virtual void ScheduleAnimation() OVERRIDE {} |
| + virtual void DidPostSwapBuffers() OVERRIDE {} |
| + virtual void DidAbortSwapBuffers() OVERRIDE {} |
| + |
| + void RunTest() { |
| + Start(); |
| + Join(); |
| + } |
| + |
| + // base::SimpleThread override. |
| + virtual void Run() OVERRIDE { |
| + ASSERT_FALSE(base::MessageLoopProxy::current()); |
| + RunTestWithoutMessageLoop(); |
| + EXPECT_FALSE(base::MessageLoopProxy::current()); |
| + } |
| + |
| + virtual void RunTestWithoutMessageLoop() = 0; |
| + |
| + protected: |
| + // All member variables accessed only on SimpleThread with no MessageLoop. |
| + bool did_initialize_output_surface_; |
| + bool did_commit_; |
| + bool did_commit_and_draw_frame_; |
| +}; |
| + |
| +class LayerTreeHostNoMessageLoopSmokeTest |
| + : public LayerTreeHostNoMessageLoopTest { |
| + virtual void RunTestWithoutMessageLoop() OVERRIDE { |
| + did_initialize_output_surface_ = false; |
| + gfx::Size size(100, 100); |
| + |
| + // Set up LayerTreeHost. |
| + LayerTreeSettings settings; |
| + scoped_ptr<LayerTreeHost> layer_tree_host = |
| + LayerTreeHost::CreateSingleThreaded(this, this, NULL, settings); |
| + layer_tree_host->SetViewportSize(size); |
| + |
| + // Set up root layer. |
| + scoped_refptr<SolidColorLayer> root_layer = SolidColorLayer::Create(); |
| + root_layer->SetBackgroundColor(SK_ColorRED); |
| + root_layer->SetBounds(size); |
| + root_layer->SetIsDrawable(true); |
| + layer_tree_host->SetRootLayer(root_layer); |
| + |
| + // Composite. |
| + did_commit_ = false; |
| + did_commit_and_draw_frame_ = false; |
| + layer_tree_host->Composite(gfx::FrameTime::Now()); |
| + EXPECT_TRUE(did_initialize_output_surface_); |
| + EXPECT_TRUE(did_commit_); |
| + EXPECT_TRUE(did_commit_and_draw_frame_); |
| + |
| + // Explicit teardown to make failures easier to debug. |
| + layer_tree_host.reset(); |
| + root_layer = NULL; |
| + } |
| +}; |
| + |
| +TEST_F(LayerTreeHostNoMessageLoopSmokeTest, SmokeTest) { |
| + RunTest(); |
| +} |
| + |
| +} // namespace |
| +} // namespace cc |