Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1608)

Unified Diff: cc/output/gl_renderer_unittest.cc

Issue 2278283003: Refactor client visibility handling (Closed)
Patch Set: feedback Created 4 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: cc/output/gl_renderer_unittest.cc
diff --git a/cc/output/gl_renderer_unittest.cc b/cc/output/gl_renderer_unittest.cc
index 20054fc275762c7fa7e16224d96be094f73eb446..6f74784ea82f336d71bc003c5cb09290b493205d 100644
--- a/cc/output/gl_renderer_unittest.cc
+++ b/cc/output/gl_renderer_unittest.cc
@@ -2079,35 +2079,44 @@ TEST_F(GLRendererPartialSwapTest, NoPartialSwap) {
RunTest(false);
}
-class GLRendererWithMockContextTest : public ::testing::Test {
+class GLRendererWithMockContextCacheControllerTest : public ::testing::Test {
protected:
- class MockContextProvider : public TestContextProvider {
+ class MockContextCacheController : public ContextCacheController {
public:
- explicit MockContextProvider(std::unique_ptr<TestContextSupport> support)
- : TestContextProvider(std::move(support),
- base::MakeUnique<TestGLES2Interface>(),
- TestWebGraphicsContext3D::Create()) {}
+ explicit MockContextCacheController(gpu::ContextSupport* support)
+ : ContextCacheController(support) {}
+ MOCK_METHOD0(OnClientBecameVisible, void());
+ MOCK_METHOD0(OnClientBecameNotVisible, void());
+
+ std::unique_ptr<ScopedVisibility> ClientBecameVisible() {
+ if (num_visible_clients_ == 0)
+ OnClientBecameVisible();
+ ++num_visible_clients_;
+ return CreateScopedVisibilityForTesting();
danakj 2016/08/29 23:56:20 this could just call ContextCacheController::OnCli
ericrk 2016/08/30 18:18:58 Made un-virtual, so no longer an issue.
+ }
- MOCK_METHOD0(DeleteCachedResources, void());
+ void ClientBecameNotVisible(
+ std::unique_ptr<ScopedVisibility> scoped_visibility) {
+ --num_visible_clients_;
+ if (num_visible_clients_ == 0)
+ OnClientBecameNotVisible();
+ ReleaseScopedVisibilityForTesting(std::move(scoped_visibility));
+ }
private:
- ~MockContextProvider() = default;
- };
-
- class MockContextSupport : public TestContextSupport {
- public:
- MockContextSupport() {}
- MOCK_METHOD1(SetAggressivelyFreeResources,
- void(bool aggressively_free_resources));
- MOCK_METHOD2(SetClientVisible, void(int client_id, bool is_visible));
- MOCK_CONST_METHOD0(AnyClientsVisible, bool());
+ int num_visible_clients_ = 0;
};
void SetUp() override {
- auto context_support = base::MakeUnique<MockContextSupport>();
- context_support_ptr_ = context_support.get();
- context_provider_ = new MockContextProvider(std::move(context_support));
- output_surface_ = FakeOutputSurface::Create3d(context_provider_);
+ auto support = base::MakeUnique<TestContextSupport>();
+ auto context = TestWebGraphicsContext3D::Create();
+ auto cache_controller =
+ base::MakeUnique<::testing::StrictMock<MockContextCacheController>>(
+ support.get());
+ mock_cache_controller_ = cache_controller.get();
+ auto context_provider = TestContextProvider::Create(
+ std::move(context), std::move(support), std::move(cache_controller));
+ output_surface_ = FakeOutputSurface::Create3d(std::move(context_provider));
output_surface_->BindToClient(&output_surface_client_);
resource_provider_ =
FakeResourceProvider::Create(output_surface_.get(), nullptr);
@@ -2119,32 +2128,21 @@ class GLRendererWithMockContextTest : public ::testing::Test {
RendererSettings settings_;
FakeOutputSurfaceClient output_surface_client_;
- MockContextSupport* context_support_ptr_;
- scoped_refptr<MockContextProvider> context_provider_;
+ MockContextCacheController* mock_cache_controller_;
std::unique_ptr<OutputSurface> output_surface_;
std::unique_ptr<ResourceProvider> resource_provider_;
std::unique_ptr<GLRenderer> renderer_;
};
-TEST_F(GLRendererWithMockContextTest,
+TEST_F(GLRendererWithMockContextCacheControllerTest,
ContextPurgedWhenRendererBecomesInvisible) {
- // Ensure our expectations run in order.
- ::testing::InSequence s;
-
- EXPECT_CALL(*context_support_ptr_, SetClientVisible(0, true));
- EXPECT_CALL(*context_support_ptr_, AnyClientsVisible())
- .WillOnce(Return(true));
- EXPECT_CALL(*context_support_ptr_, SetAggressivelyFreeResources(false));
+ EXPECT_CALL(*mock_cache_controller_, OnClientBecameVisible());
renderer_->SetVisible(true);
- Mock::VerifyAndClearExpectations(context_support_ptr_);
+ Mock::VerifyAndClearExpectations(mock_cache_controller_);
- EXPECT_CALL(*context_support_ptr_, SetClientVisible(0, false));
- EXPECT_CALL(*context_support_ptr_, AnyClientsVisible())
- .WillOnce(Return(false));
- EXPECT_CALL(*context_provider_, DeleteCachedResources());
- EXPECT_CALL(*context_support_ptr_, SetAggressivelyFreeResources(true));
+ EXPECT_CALL(*mock_cache_controller_, OnClientBecameNotVisible());
renderer_->SetVisible(false);
- Mock::VerifyAndClearExpectations(context_support_ptr_);
+ Mock::VerifyAndClearExpectations(mock_cache_controller_);
}
} // namespace

Powered by Google App Engine
This is Rietveld 408576698