Chromium Code Reviews| Index: cc/trees/layer_tree_host_unittest_context.cc |
| diff --git a/cc/trees/layer_tree_host_unittest_context.cc b/cc/trees/layer_tree_host_unittest_context.cc |
| index 44347d3e88493e6e617298c1b1cda2ac18812b4d..3c3e83355d0af62219cd11db1b44fa8b58d27dfe 100644 |
| --- a/cc/trees/layer_tree_host_unittest_context.cc |
| +++ b/cc/trees/layer_tree_host_unittest_context.cc |
| @@ -409,6 +409,31 @@ class LayerTreeHostContextTestLostContextSucceeds |
| SINGLE_AND_MULTI_THREAD_TEST_F(LayerTreeHostContextTestLostContextSucceeds); |
| +class LayerTreeHostClientNotReadyDoesNotCreateOutputSurface |
| + : public LayerTreeHostContextTest { |
| + public: |
| + LayerTreeHostClientNotReadyDoesNotCreateOutputSurface() |
| + : LayerTreeHostContextTest() {} |
| + |
| + virtual void WillBeginTest() OVERRIDE { |
| + // Override and do not signal SetLayerTreeHostClientReady. |
| + } |
| + |
| + virtual void BeginTest() OVERRIDE { |
| + PostSetNeedsCommitToMainThread(); |
| + EndTest(); |
| + } |
| + |
| + virtual void DidInitializeOutputSurface(bool succeeded) OVERRIDE { |
| + GTEST_FAIL(); |
| + } |
| + |
| + virtual void AfterTest() OVERRIDE { |
| + } |
| +}; |
| + |
| +MULTI_THREAD_TEST_F(LayerTreeHostClientNotReadyDoesNotCreateOutputSurface); |
| + |
| class LayerTreeHostContextTestLostContextSucceedsWithContent |
| : public LayerTreeHostContextTestLostContextSucceeds { |
| public: |
| @@ -527,6 +552,96 @@ TEST_F(LayerTreeHostContextTestLostContextSucceedsWithContent, |
| RunTest(true, false, false); |
| } |
| +class LayerTreeHostContextTestCreateOutputSurfaceFails |
| + : public LayerTreeHostContextTest { |
| + public: |
| + // Run a test that initially fails OutputSurface creation |times_to_fail| |
| + // times. If |expect_fallback_attempt| is |true|, an attempt to create a |
| + // fallback/software OutputSurface is expected to occur. |
| + LayerTreeHostContextTestCreateOutputSurfaceFails(int times_to_fail, |
| + bool expect_fallback_attempt, |
| + bool expect_to_give_up) |
| + : times_to_fail_(times_to_fail), |
| + expect_fallback_attempt_(expect_fallback_attempt), |
| + expect_to_give_up_(expect_to_give_up), |
| + did_attempt_fallback_(false), |
| + times_initialized_(0) {} |
| + |
| + virtual void BeginTest() OVERRIDE { |
| + times_to_fail_create_ = times_to_fail_; |
| + PostSetNeedsCommitToMainThread(); |
| + } |
| + |
| + virtual scoped_ptr<OutputSurface> CreateOutputSurface(bool fallback) |
| + OVERRIDE { |
| + scoped_ptr<OutputSurface> surface = |
| + LayerTreeHostContextTest::CreateOutputSurface(fallback); |
| + |
| + if (surface) |
| + EXPECT_EQ(times_to_fail_, times_create_failed_); |
| + |
| + did_attempt_fallback_ = fallback; |
| + return surface.Pass(); |
| + } |
| + |
| + virtual void DidInitializeOutputSurface(bool succeeded) OVERRIDE { |
| + if (succeeded) |
| + times_initialized_++; |
| + else |
| + EndTest(); |
| + } |
| + |
| + virtual void DrawLayersOnThread(LayerTreeHostImpl* host_impl) OVERRIDE { |
| + EndTest(); |
| + } |
| + |
| + virtual void AfterTest() OVERRIDE { |
| + EXPECT_EQ(times_to_fail_, times_create_failed_); |
| + EXPECT_EQ(expect_to_give_up_, times_initialized_ == 0); |
| + EXPECT_EQ(expect_fallback_attempt_, did_attempt_fallback_); |
| + } |
| + |
| + private: |
| + int times_to_fail_; |
| + bool expect_fallback_attempt_; |
| + bool expect_to_give_up_; |
| + bool did_attempt_fallback_; |
| + int times_initialized_; |
| +}; |
| + |
| +class LayerTreeHostContextTestCreateOutputSurfaceFailsOnce |
| + : public LayerTreeHostContextTestCreateOutputSurfaceFails { |
| + public: |
| + LayerTreeHostContextTestCreateOutputSurfaceFailsOnce() |
| + : LayerTreeHostContextTestCreateOutputSurfaceFails(1, false, false) {} |
| +}; |
| + |
| +SINGLE_AND_MULTI_THREAD_TEST_F( |
| + LayerTreeHostContextTestCreateOutputSurfaceFailsOnce); |
| + |
| +// After 4 failures we expect an attempt to create a fallback/sw OutputSurface |
|
danakj
2013/12/02 14:53:02
nit: spell out software. period at end of sentence
|
| +class LayerTreeHostContextTestCreateOutputSurfaceFailsWithFallback |
| + : public LayerTreeHostContextTestCreateOutputSurfaceFails { |
| + public: |
| + LayerTreeHostContextTestCreateOutputSurfaceFailsWithFallback() |
| + : LayerTreeHostContextTestCreateOutputSurfaceFails(4, true, false) {} |
| +}; |
| + |
| +SINGLE_AND_MULTI_THREAD_TEST_F( |
| + LayerTreeHostContextTestCreateOutputSurfaceFailsWithFallback); |
| + |
| +// If we fail that often, we should be giving up cleanly. |
| +class LayerTreeHostContextTestCreateOutputSurfaceIsHopeless |
| + : public LayerTreeHostContextTestCreateOutputSurfaceFails { |
| + public: |
| + LayerTreeHostContextTestCreateOutputSurfaceIsHopeless() |
| + : LayerTreeHostContextTestCreateOutputSurfaceFails(5, true, true) {} |
| +}; |
| + |
| +SINGLE_AND_MULTI_THREAD_TEST_F( |
| + LayerTreeHostContextTestCreateOutputSurfaceIsHopeless); |
| + |
| + |
| class LayerTreeHostContextTestOffscreenContextFails |
| : public LayerTreeHostContextTest { |
| public: |
| @@ -1286,7 +1401,11 @@ class LayerTreeHostContextTestDontUseLostResources |
| virtual scoped_ptr<OutputSurface> CreateOutputSurface( |
| bool fallback) OVERRIDE { |
| - if (layer_tree_host()) { |
| + // This will get called twice: |
| + // First when we create the initial output surface... |
| + if (layer_tree_host()->source_frame_number() > 0) { |
| + // ... and then again after we forced the context to be lost on the third |
| + // frame. Verify this assumption here. |
| lost_context_ = true; |
| EXPECT_EQ(layer_tree_host()->source_frame_number(), 3); |
| } |
| @@ -1762,43 +1881,6 @@ class LayerTreeHostContextTestFailsToCreateSurface |
| SINGLE_AND_MULTI_THREAD_TEST_F( |
| LayerTreeHostContextTestFailsToCreateSurface); |
| -// Not reusing LayerTreeTest because it expects creating LTH to always succeed. |
| -class LayerTreeHostTestCannotCreateIfCannotCreateOutputSurface |
| - : public testing::Test, |
| - public FakeLayerTreeHostClient { |
| - public: |
| - LayerTreeHostTestCannotCreateIfCannotCreateOutputSurface() |
| - : FakeLayerTreeHostClient(FakeLayerTreeHostClient::DIRECT_3D) {} |
| - |
| - // FakeLayerTreeHostClient implementation. |
| - virtual scoped_ptr<OutputSurface> CreateOutputSurface(bool fallback) |
| - OVERRIDE { |
| - return scoped_ptr<OutputSurface>(); |
| - } |
| - |
| - void RunTest(bool threaded, |
| - bool delegating_renderer, |
| - bool impl_side_painting) { |
| - LayerTreeSettings settings; |
| - settings.impl_side_painting = impl_side_painting; |
| - if (threaded) { |
| - scoped_ptr<base::Thread> impl_thread(new base::Thread("LayerTreeTest")); |
| - ASSERT_TRUE(impl_thread->Start()); |
| - ASSERT_TRUE(impl_thread->message_loop_proxy().get()); |
| - scoped_ptr<LayerTreeHost> layer_tree_host = LayerTreeHost::CreateThreaded( |
| - this, NULL, settings, impl_thread->message_loop_proxy()); |
| - EXPECT_FALSE(layer_tree_host); |
| - } else { |
| - scoped_ptr<LayerTreeHost> layer_tree_host = |
| - LayerTreeHost::CreateSingleThreaded(this, this, NULL, settings); |
| - EXPECT_FALSE(layer_tree_host); |
| - } |
| - } |
| -}; |
| - |
| -SINGLE_AND_MULTI_THREAD_TEST_F( |
| - LayerTreeHostTestCannotCreateIfCannotCreateOutputSurface); |
| - |
| class UIResourceLostTest : public LayerTreeHostContextTest { |
| public: |
| UIResourceLostTest() : time_step_(0) {} |