Chromium Code Reviews| Index: cc/trees/layer_tree_host_unittest.cc |
| diff --git a/cc/trees/layer_tree_host_unittest.cc b/cc/trees/layer_tree_host_unittest.cc |
| index eb81d5b8e8a200dfb9e353a878cca21e998877a2..68913b8973ccb2c3d293c062694a348b7b6fece4 100644 |
| --- a/cc/trees/layer_tree_host_unittest.cc |
| +++ b/cc/trees/layer_tree_host_unittest.cc |
| @@ -3093,6 +3093,103 @@ class LayerTreeHostTestDeferredInitialize : public LayerTreeHostTest { |
| MULTI_THREAD_TEST_F(LayerTreeHostTestDeferredInitialize); |
| +class LayerTreeHostTestAbortFrameOnStaleRendererCapabilities |
| + : public LayerTreeHostTest { |
| + public: |
| + virtual void InitializeSettings(LayerTreeSettings* settings) OVERRIDE { |
| + settings->impl_side_painting = true; |
| + } |
| + |
| + virtual void SetupTree() OVERRIDE { |
| + layer_ = FakePictureLayer::Create(&client_); |
| + // Make sure commits are not aborted due to no update. |
| + layer_->set_always_update_resources(true); |
| + layer_tree_host()->SetRootLayer(layer_); |
| + LayerTreeHostTest::SetupTree(); |
| + } |
| + |
| + virtual scoped_ptr<FakeOutputSurface> CreateFakeOutputSurface(bool fallback) |
| + OVERRIDE { |
| + scoped_ptr<TestWebGraphicsContext3D> context3d( |
|
danakj
2014/02/11 19:58:59
unused?
boliu
2014/02/11 21:44:07
Done.
|
| + TestWebGraphicsContext3D::Create()); |
| + |
| + return FakeOutputSurface::CreateDeferredGL( |
| + scoped_ptr<SoftwareOutputDevice>(new SoftwareOutputDevice)); |
| + } |
| + |
| + virtual void BeginTest() OVERRIDE { |
| + aborted_frame_ = true; |
| + main_frame_attempts_ = 0; |
| + PostSetNeedsCommitToMainThread(); |
| + } |
| + |
| + virtual void WillBeginMainFrame() OVERRIDE { |
| + int frame_number = layer_tree_host()->source_frame_number(); |
| + EXPECT_EQ(0, frame_number); // Only one frame. |
| + main_frame_attempts_++; |
| + // Main frame should only be aborted once. |
| + EXPECT_LE(main_frame_attempts_, 2); |
| + |
| + if (main_frame_attempts_ == 1) { |
| + // Capabilities updated once on first renderer init. |
| + EXPECT_EQ(static_cast<size_t>(1), |
|
danakj
2014/02/11 19:58:59
"1u" instead of static_cast<size_t>(1)
boliu
2014/02/11 21:44:07
Done.
|
| + layer_->renderer_capabilities_changed_count()); |
| + layer_->reset_renderer_capabilities_changed_count(); |
| + |
| + // Make sure first main frame attemp gets aborted due to stale renderer |
|
danakj
2014/02/11 19:58:59
attempt
boliu
2014/02/11 21:44:07
Done.
|
| + // capabilities by synchronously updating renderer capabilities on impl |
| + // thread. |
| + CompletionEvent completion; |
| + ImplThreadTaskRunner()->PostTask( |
| + FROM_HERE, |
| + base::Bind(&LayerTreeHostTestAbortFrameOnStaleRendererCapabilities:: |
| + UpdateRendererCapabilities, |
| + base::Unretained(this), |
| + &completion)); |
| + completion.Wait(); |
| + } else { |
| + // Capabilities updated again before second attempt of first frame. |
| + EXPECT_EQ(static_cast<size_t>(1), |
|
danakj
2014/02/11 19:58:59
1u
boliu
2014/02/11 21:44:07
Done.
|
| + layer_->renderer_capabilities_changed_count()); |
| + layer_->reset_renderer_capabilities_changed_count(); |
| + } |
| + } |
| + |
| + void UpdateRendererCapabilities(CompletionEvent* completion) { |
| + // Change renderer capabilities by switching renderers. |
| + scoped_refptr<TestContextProvider> context_provider = |
| + TestContextProvider::Create(); |
| + EXPECT_TRUE( |
| + output_surface()->InitializeAndSetContext3d(context_provider, NULL)); |
| + completion->Signal(); |
| + } |
| + |
| + virtual void BeginMainFrameAbortedOnThread(LayerTreeHostImpl* host_impl, |
| + bool did_handle) OVERRIDE { |
| + EXPECT_TRUE(did_handle); |
| + aborted_frame_ = true; |
|
danakj
2014/02/11 19:58:59
use an int instead so you can test the number of t
boliu
2014/02/11 21:44:07
Done.
|
| + } |
| + |
| + virtual void DrawLayersOnThread(LayerTreeHostImpl* host_impl) OVERRIDE { |
| + EndTest(); |
| + } |
| + |
| + virtual void AfterTest() OVERRIDE { |
| + // First main frame should have been attempted twice. |
| + EXPECT_EQ(2, main_frame_attempts_); |
| + // First attempted should have been aborted. |
|
danakj
2014/02/11 19:58:59
attempt
boliu
2014/02/11 21:44:07
Done.
|
| + EXPECT_TRUE(aborted_frame_); |
| + } |
| + |
| + private: |
| + FakeContentLayerClient client_; |
| + scoped_refptr<FakePictureLayer> layer_; |
| + int main_frame_attempts_; |
| + bool aborted_frame_; |
| +}; |
| + |
| +MULTI_THREAD_TEST_F(LayerTreeHostTestAbortFrameOnStaleRendererCapabilities); |
| + |
| // Test for UI Resource management. |
| class LayerTreeHostTestUIResource : public LayerTreeHostTest { |
| public: |