Chromium Code Reviews| Index: cc/trees/layer_tree_host_impl_unittest.cc |
| diff --git a/cc/trees/layer_tree_host_impl_unittest.cc b/cc/trees/layer_tree_host_impl_unittest.cc |
| index 0c82caaabb1e02e0542ddcaa8b8170a11229d924..963cd6b6b5f9a2c192b8672c4a97b92f7829ba7d 100644 |
| --- a/cc/trees/layer_tree_host_impl_unittest.cc |
| +++ b/cc/trees/layer_tree_host_impl_unittest.cc |
| @@ -71,6 +71,7 @@ class LayerTreeHostImplTest : public testing::Test, |
| did_request_commit_(false), |
| did_request_redraw_(false), |
| did_upload_visible_tile_(false), |
| + did_lose_output_surface_(false), |
| reduce_memory_result_(true), |
| current_limit_bytes_(0), |
| current_priority_cutoff_value_(0) { |
| @@ -93,7 +94,9 @@ class LayerTreeHostImplTest : public testing::Test, |
| virtual void TearDown() OVERRIDE {} |
| - virtual void DidLoseOutputSurfaceOnImplThread() OVERRIDE {} |
| + virtual void DidLoseOutputSurfaceOnImplThread() OVERRIDE { |
| + did_lose_output_surface_ = true; |
| + } |
| virtual void OnSwapBuffersCompleteOnImplThread() OVERRIDE {} |
| virtual void BeginFrameOnImplThread(const BeginFrameArgs& args) |
| OVERRIDE {} |
| @@ -351,6 +354,7 @@ class LayerTreeHostImplTest : public testing::Test, |
| bool did_request_commit_; |
| bool did_request_redraw_; |
| bool did_upload_visible_tile_; |
| + bool did_lose_output_surface_; |
| bool reduce_memory_result_; |
| base::TimeDelta requested_scrollbar_animation_delay_; |
| size_t current_limit_bytes_; |
| @@ -6227,6 +6231,165 @@ TEST_F(LayerTreeHostImplTest, DeferredInitializeSmoke) { |
| DrawFrame(); |
| } |
| +TEST_F(LayerTreeHostImplTest, DeferredInitializeFails_OnscreenContext_0) { |
|
boliu
2013/08/28 03:48:17
output_surface_unittests should have a test simila
danakj
2013/08/28 15:36:09
Ya, OutputSurfaceTestInitializeNewContext3d.Client
|
| + set_reduce_memory_result(false); |
| + scoped_ptr<FakeOutputSurface> output_surface( |
| + FakeOutputSurface::CreateDeferredGL( |
| + scoped_ptr<SoftwareOutputDevice>(new CountingSoftwareDevice()))); |
| + FakeOutputSurface* output_surface_ptr = output_surface.get(); |
| + EXPECT_TRUE( |
| + host_impl_->InitializeRenderer(output_surface.PassAs<OutputSurface>())); |
| + |
| + scoped_ptr<SolidColorLayerImpl> root_layer = |
| + SolidColorLayerImpl::Create(host_impl_->active_tree(), 1); |
| + SetupRootLayerImpl(root_layer.PassAs<LayerImpl>()); |
| + |
| + // Software draw. |
| + DrawFrame(); |
| + |
| + scoped_refptr<TestContextProvider> onscreen_context_provider = |
| + TestContextProvider::Create(); |
| + scoped_refptr<TestContextProvider> offscreen_context_provider = |
| + TestContextProvider::Create(); |
| + |
| + // Fail initialization of the onscreen context before the OutputSurface binds |
| + // it to the thread. |
| + onscreen_context_provider->UnboundTestContext3d() |
| + ->set_times_make_current_succeeds(0); |
| + |
| + EXPECT_FALSE(host_impl_->output_surface()->context_provider()); |
| + EXPECT_FALSE(host_impl_->offscreen_context_provider()); |
| + EXPECT_FALSE(did_lose_output_surface_); |
| + |
| + // DeferredInitialize fails. |
| + EXPECT_FALSE(output_surface_ptr->InitializeAndSetContext3d( |
| + onscreen_context_provider, offscreen_context_provider)); |
| + EXPECT_FALSE(host_impl_->output_surface()->context_provider()); |
| + EXPECT_FALSE(host_impl_->offscreen_context_provider()); |
| + |
| + // Software draw again. |
| + DrawFrame(); |
| +} |
| + |
| +TEST_F(LayerTreeHostImplTest, DeferredInitializeFails_OnscreenContext_1) { |
| + set_reduce_memory_result(false); |
| + scoped_ptr<FakeOutputSurface> output_surface( |
| + FakeOutputSurface::CreateDeferredGL( |
| + scoped_ptr<SoftwareOutputDevice>(new CountingSoftwareDevice()))); |
| + FakeOutputSurface* output_surface_ptr = output_surface.get(); |
| + EXPECT_TRUE( |
| + host_impl_->InitializeRenderer(output_surface.PassAs<OutputSurface>())); |
| + |
| + scoped_ptr<SolidColorLayerImpl> root_layer = |
| + SolidColorLayerImpl::Create(host_impl_->active_tree(), 1); |
| + SetupRootLayerImpl(root_layer.PassAs<LayerImpl>()); |
| + |
| + // Software draw. |
| + DrawFrame(); |
| + |
| + scoped_refptr<TestContextProvider> onscreen_context_provider = |
| + TestContextProvider::Create(); |
| + scoped_refptr<TestContextProvider> offscreen_context_provider = |
| + TestContextProvider::Create(); |
| + |
| + // Fail initialization of the onscreen context after the OutputSurface binds |
| + // it to the thread. |
| + onscreen_context_provider->UnboundTestContext3d() |
| + ->set_times_make_current_succeeds(2); |
| + |
| + EXPECT_FALSE(host_impl_->output_surface()->context_provider()); |
| + EXPECT_FALSE(host_impl_->offscreen_context_provider()); |
| + EXPECT_FALSE(did_lose_output_surface_); |
| + |
| + // DeferredInitialize fails. |
| + EXPECT_FALSE(output_surface_ptr->InitializeAndSetContext3d( |
| + onscreen_context_provider, offscreen_context_provider)); |
| + EXPECT_FALSE(host_impl_->output_surface()->context_provider()); |
| + EXPECT_FALSE(host_impl_->offscreen_context_provider()); |
| + |
| + // We lose the output surface. |
| + EXPECT_TRUE(did_lose_output_surface_); |
| +} |
| + |
| +TEST_F(LayerTreeHostImplTest, DeferredInitializeFails_OnscreenContext_2) { |
| + set_reduce_memory_result(false); |
| + scoped_ptr<FakeOutputSurface> output_surface( |
| + FakeOutputSurface::CreateDeferredGL( |
| + scoped_ptr<SoftwareOutputDevice>(new CountingSoftwareDevice()))); |
| + FakeOutputSurface* output_surface_ptr = output_surface.get(); |
| + EXPECT_TRUE( |
| + host_impl_->InitializeRenderer(output_surface.PassAs<OutputSurface>())); |
| + |
| + scoped_ptr<SolidColorLayerImpl> root_layer = |
| + SolidColorLayerImpl::Create(host_impl_->active_tree(), 1); |
| + SetupRootLayerImpl(root_layer.PassAs<LayerImpl>()); |
| + |
| + // Software draw. |
| + DrawFrame(); |
| + |
| + scoped_refptr<TestContextProvider> onscreen_context_provider = |
| + TestContextProvider::Create(); |
| + scoped_refptr<TestContextProvider> offscreen_context_provider = |
| + TestContextProvider::Create(); |
| + |
| + // Fail initialization of the onscreen context after the OutputSurface binds |
| + // it to the thread and during renderer initialization. |
| + onscreen_context_provider->UnboundTestContext3d() |
| + ->set_times_make_current_succeeds(1); |
| + |
| + EXPECT_FALSE(host_impl_->output_surface()->context_provider()); |
| + EXPECT_FALSE(host_impl_->offscreen_context_provider()); |
| + EXPECT_FALSE(did_lose_output_surface_); |
| + |
| + // DeferredInitialize fails. |
| + EXPECT_FALSE(output_surface_ptr->InitializeAndSetContext3d( |
| + onscreen_context_provider, offscreen_context_provider)); |
| + EXPECT_FALSE(host_impl_->output_surface()->context_provider()); |
| + EXPECT_FALSE(host_impl_->offscreen_context_provider()); |
| + |
| + // We lose the output surface. |
| + EXPECT_TRUE(did_lose_output_surface_); |
| +} |
| + |
| +TEST_F(LayerTreeHostImplTest, DeferredInitializeFails_OffscreenContext) { |
|
boliu
2013/08/28 03:48:17
Load of duplicated code between these 4 tests. Eve
danakj
2013/08/28 15:36:09
Sure!
|
| + set_reduce_memory_result(false); |
| + scoped_ptr<FakeOutputSurface> output_surface( |
| + FakeOutputSurface::CreateDeferredGL( |
| + scoped_ptr<SoftwareOutputDevice>(new CountingSoftwareDevice()))); |
| + FakeOutputSurface* output_surface_ptr = output_surface.get(); |
| + EXPECT_TRUE( |
| + host_impl_->InitializeRenderer(output_surface.PassAs<OutputSurface>())); |
| + |
| + scoped_ptr<SolidColorLayerImpl> root_layer = |
| + SolidColorLayerImpl::Create(host_impl_->active_tree(), 1); |
| + SetupRootLayerImpl(root_layer.PassAs<LayerImpl>()); |
| + |
| + // Software draw. |
| + DrawFrame(); |
| + |
| + scoped_refptr<TestContextProvider> onscreen_context_provider = |
| + TestContextProvider::Create(); |
| + scoped_refptr<TestContextProvider> offscreen_context_provider = |
| + TestContextProvider::Create(); |
| + |
| + // Fail initialization of the offscreen context. |
| + offscreen_context_provider->UnboundTestContext3d() |
| + ->set_times_make_current_succeeds(0); |
| + |
| + EXPECT_FALSE(host_impl_->output_surface()->context_provider()); |
| + EXPECT_FALSE(host_impl_->offscreen_context_provider()); |
| + EXPECT_FALSE(did_lose_output_surface_); |
| + |
| + // DeferredInitialize fails. |
| + EXPECT_FALSE(output_surface_ptr->InitializeAndSetContext3d( |
| + onscreen_context_provider, offscreen_context_provider)); |
| + EXPECT_FALSE(host_impl_->output_surface()->context_provider()); |
| + EXPECT_FALSE(host_impl_->offscreen_context_provider()); |
| + |
| + // We lose the output surface. |
| + EXPECT_TRUE(did_lose_output_surface_); |
| +} |
| + |
| class ContextThatDoesNotSupportMemoryManagmentExtensions |
| : public TestWebGraphicsContext3D { |
| public: |