diff options
author | ericrk <ericrk@chromium.org> | 2015-06-24 17:01:13 -0700 |
---|---|---|
committer | Commit bot <commit-bot@chromium.org> | 2015-06-25 00:02:04 +0000 |
commit | 7909d0ed08708948f45aec5f97bb77dd8c0e0ced (patch) | |
tree | fffb5d043b035d0ba203736ef030d4f47ce9a8f3 /cc | |
parent | 1a19a6c7fe4876222caee046622f866ffa18fdb6 (diff) | |
download | chromium_src-7909d0ed08708948f45aec5f97bb77dd8c0e0ced.zip chromium_src-7909d0ed08708948f45aec5f97bb77dd8c0e0ced.tar.gz chromium_src-7909d0ed08708948f45aec5f97bb77dd8c0e0ced.tar.bz2 |
Convert LayerTreeHostAreAllTileTasksCompleted test to TileManager test
Less variables so the test will run predictably without flakiness.
R=vmpstr@chromium.org,danakj@chromium.org
BUG=504099
CQ_INCLUDE_TRYBOTS=tryserver.blink:linux_blink_rel
Review URL: https://codereview.chromium.org/1200323008
Cr-Commit-Position: refs/heads/master@{#336042}
Diffstat (limited to 'cc')
-rw-r--r-- | cc/tiles/tile_manager_unittest.cc | 55 | ||||
-rw-r--r-- | cc/trees/layer_tree_host_unittest.cc | 95 |
2 files changed, 55 insertions, 95 deletions
diff --git a/cc/tiles/tile_manager_unittest.cc b/cc/tiles/tile_manager_unittest.cc index db1e5d7..4a663ce 100644 --- a/cc/tiles/tile_manager_unittest.cc +++ b/cc/tiles/tile_manager_unittest.cc @@ -2,6 +2,7 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. +#include "base/run_loop.h" #include "base/thread_task_runner_handle.h" #include "cc/resources/resource_pool.h" #include "cc/test/begin_frame_args_test.h" @@ -22,6 +23,7 @@ #include "cc/tiles/tile_priority.h" #include "cc/tiles/tiling_set_raster_queue_all.h" #include "cc/trees/layer_tree_impl.h" +#include "testing/gmock/include/gmock/gmock.h" #include "testing/gtest/include/gtest/gtest.h" namespace cc { @@ -1462,5 +1464,58 @@ TEST_F(TileManagerTilePriorityQueueTest, RasterQueueAllUsesCorrectTileBounds) { } } +class TileManagerTest : public testing::Test { + public: + TileManagerTest() + : host_impl_(&proxy_, &shared_bitmap_manager_, &task_graph_runner_) {} + + protected: + // MockLayerTreeHostImpl allows us to intercept tile manager callbacks. + class MockLayerTreeHostImpl : public FakeLayerTreeHostImpl { + public: + MockLayerTreeHostImpl(Proxy* proxy, + SharedBitmapManager* manager, + TaskGraphRunner* task_graph_runner) + : FakeLayerTreeHostImpl(proxy, manager, task_graph_runner) { + InitializeRenderer(FakeOutputSurface::Create3d()); + } + + MOCK_METHOD0(NotifyAllTileTasksCompleted, void()); + }; + + TestSharedBitmapManager shared_bitmap_manager_; + TestTaskGraphRunner task_graph_runner_; + FakeImplProxy proxy_; + MockLayerTreeHostImpl host_impl_; +}; + +// Test to ensure that we call NotifyAllTileTasksCompleted when PrepareTiles is +// called. +TEST_F(TileManagerTest, AllWorkFinishedTest) { + // Check with no tile work enqueued. + { + base::RunLoop run_loop; + EXPECT_FALSE(host_impl_.tile_manager()->HasScheduledTileTasksForTesting()); + EXPECT_CALL(host_impl_, NotifyAllTileTasksCompleted()) + .WillOnce(testing::Invoke([&run_loop]() { run_loop.Quit(); })); + host_impl_.tile_manager()->PrepareTiles(host_impl_.global_tile_state()); + EXPECT_TRUE(host_impl_.tile_manager()->HasScheduledTileTasksForTesting()); + run_loop.Run(); + } + + // Check that the "schedule more work" path also triggers the expected + // callback. + { + base::RunLoop run_loop; + EXPECT_FALSE(host_impl_.tile_manager()->HasScheduledTileTasksForTesting()); + EXPECT_CALL(host_impl_, NotifyAllTileTasksCompleted()) + .WillOnce(testing::Invoke([&run_loop]() { run_loop.Quit(); })); + host_impl_.tile_manager()->PrepareTiles(host_impl_.global_tile_state()); + host_impl_.tile_manager()->SetMoreTilesNeedToBeRasterizedForTesting(); + EXPECT_TRUE(host_impl_.tile_manager()->HasScheduledTileTasksForTesting()); + run_loop.Run(); + } +} + } // namespace } // namespace cc diff --git a/cc/trees/layer_tree_host_unittest.cc b/cc/trees/layer_tree_host_unittest.cc index 8c6633a..4e194fd 100644 --- a/cc/trees/layer_tree_host_unittest.cc +++ b/cc/trees/layer_tree_host_unittest.cc @@ -272,101 +272,6 @@ class LayerTreeHostTestReadyToDrawNonEmpty // single threaded mode. SINGLE_THREAD_TEST_F(LayerTreeHostTestReadyToDrawNonEmpty); -// Test if the LTHI successfully recieves the NotifyAllTileTasksCompleted -// callback for a call of PrepareTiles. -class LayerTreeHostNotifyAllTileTasksCompletedOnPrepareTiles - : public LayerTreeHostTest { - public: - LayerTreeHostNotifyAllTileTasksCompletedOnPrepareTiles() - : notify_all_tile_tasks_completed_called_(false) {} - void BeginTest() override { - // Logic is handled in InitializedRendererOnThread to ensure that our - // LTHI is fully set up. - } - - void AfterTest() override { - EXPECT_TRUE(notify_all_tile_tasks_completed_called_); - } - - void InitializedRendererOnThread(LayerTreeHostImpl* host_impl, - bool success) override { - host_impl->PrepareTiles(); - } - - void NotifyAllTileTasksCompleted(LayerTreeHostImpl* host_impl) override { - // We only expect this to be called once. - DCHECK(!notify_all_tile_tasks_completed_called_); - notify_all_tile_tasks_completed_called_ = true; - EndTest(); - } - - private: - bool notify_all_tile_tasks_completed_called_; -}; - -SINGLE_AND_MULTI_THREAD_TEST_F( - LayerTreeHostNotifyAllTileTasksCompletedOnPrepareTiles); - -// Test if the LTHI successfully recieves the NotifyAllTileTasksCompleted -// callback for a call of PrepareTiles while using the "needs more work" path. -class LayerTreeHostNotifyAllTileTasksCompletedOnPrepareMoreTiles - : public LayerTreeHostNotifyAllTileTasksCompletedOnPrepareTiles { - public: - void InitializedRendererOnThread(LayerTreeHostImpl* host_impl, - bool success) override { - host_impl->PrepareTiles(); - host_impl->tile_manager()->SetMoreTilesNeedToBeRasterizedForTesting(); - } -}; - -SINGLE_AND_MULTI_THREAD_TEST_F( - LayerTreeHostNotifyAllTileTasksCompletedOnPrepareMoreTiles); - -// Test that AreAllTileTasksCompleted returnes the expected values before and -// after PrepareTiles. -class LayerTreeHostAreAllTileTasksCompleted : public LayerTreeHostTest { - public: - LayerTreeHostAreAllTileTasksCompleted() : got_notify_(false) {} - - void SetupTree() override { - client_.set_fill_with_nonsolid_color(true); - scoped_refptr<FakePictureLayer> root_layer = - FakePictureLayer::Create(layer_settings(), &client_); - root_layer->SetBounds(gfx::Size(1500, 1500)); - root_layer->SetIsDrawable(true); - - layer_tree_host()->SetRootLayer(root_layer); - layer_tree_host()->SetViewportSize(gfx::Size(16, 16)); - LayerTreeHostTest::SetupTree(); - } - - void BeginTest() override { PostSetNeedsCommitToMainThread(); } - - void AfterTest() override { EXPECT_TRUE(got_notify_); } - - void BeginCommitOnThread(LayerTreeHostImpl* host_impl) override { - // Before commit, we should have no work. - EXPECT_FALSE(host_impl->tile_manager()->HasScheduledTileTasksForTesting()); - } - - void CommitCompleteOnThread(LayerTreeHostImpl* host_impl) override { - // Immediately after commit, we should have enqueued work. - EXPECT_TRUE(host_impl->tile_manager()->HasScheduledTileTasksForTesting()); - } - - void NotifyAllTileTasksCompleted(LayerTreeHostImpl* host_impl) override { - EXPECT_FALSE(host_impl->tile_manager()->HasScheduledTileTasksForTesting()); - got_notify_ = true; - EndTest(); - } - - private: - FakeContentLayerClient client_; - bool got_notify_; -}; - -SINGLE_AND_MULTI_THREAD_TEST_F(LayerTreeHostAreAllTileTasksCompleted); - class LayerTreeHostFreeWorkerContextResourcesTest : public LayerTreeHostTest { public: scoped_ptr<FakeOutputSurface> CreateFakeOutputSurface() override { |