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

Side by Side Diff: cc/output/gl_renderer_unittest.cc

Issue 2252163003: Update Context Client Visibility to use Scoped Pattern (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: cleanup 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 unified diff | Download patch
OLDNEW
1 // Copyright 2012 The Chromium Authors. All rights reserved. 1 // Copyright 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "cc/output/gl_renderer.h" 5 #include "cc/output/gl_renderer.h"
6 6
7 #include <stdint.h> 7 #include <stdint.h>
8 8
9 #include <set> 9 #include <set>
10 10
(...skipping 2080 matching lines...) Expand 10 before | Expand all | Expand 10 after
2091 TestWebGraphicsContext3D::Create()) {} 2091 TestWebGraphicsContext3D::Create()) {}
2092 2092
2093 MOCK_METHOD0(DeleteCachedResources, void()); 2093 MOCK_METHOD0(DeleteCachedResources, void());
2094 2094
2095 private: 2095 private:
2096 ~MockContextProvider() = default; 2096 ~MockContextProvider() = default;
2097 }; 2097 };
2098 2098
2099 class MockContextSupport : public TestContextSupport { 2099 class MockContextSupport : public TestContextSupport {
2100 public: 2100 public:
2101 using VisibilityToken = std::unique_ptr<ScopedVisibility>;
2101 MockContextSupport() {} 2102 MockContextSupport() {}
2102 MOCK_METHOD1(SetAggressivelyFreeResources, 2103 MOCK_METHOD1(SetAggressivelyFreeResources,
2103 void(bool aggressively_free_resources)); 2104 void(bool aggressively_free_resources));
2104 MOCK_METHOD2(SetClientVisible, void(int client_id, bool is_visible)); 2105 MOCK_METHOD0(ClientBecameVisible, VisibilityToken());
2106 MOCK_METHOD1(ClientBecameNotVisible_,
2107 void(VisibilityToken& visibility)); // NOLINT
2105 MOCK_CONST_METHOD0(AnyClientsVisible, bool()); 2108 MOCK_CONST_METHOD0(AnyClientsVisible, bool());
2109
2110 // Wrapper to allow mocking w/ move-only type.
2111 void ClientBecameNotVisible(VisibilityToken visibility) override {
2112 ClientBecameNotVisible_(visibility);
2113 }
2114
2115 // Wrappers to allow forwarding to super class implementation.
2116 void SuperClientBecameNotVisible(VisibilityToken& visibility) { // NOLINT
2117 TestContextSupport::ClientBecameNotVisible(std::move(visibility));
2118 }
2119 VisibilityToken SuperClientBecameVisible() {
2120 return TestContextSupport::ClientBecameVisible();
2121 }
2106 }; 2122 };
2107 2123
2108 void SetUp() override { 2124 void SetUp() override {
2109 auto context_support = base::MakeUnique<MockContextSupport>(); 2125 auto context_support = base::MakeUnique<MockContextSupport>();
2110 context_support_ptr_ = context_support.get(); 2126 context_support_ptr_ = context_support.get();
2111 context_provider_ = new MockContextProvider(std::move(context_support)); 2127 context_provider_ = new MockContextProvider(std::move(context_support));
2112 output_surface_ = FakeOutputSurface::Create3d(context_provider_); 2128 output_surface_ = FakeOutputSurface::Create3d(context_provider_);
2113 output_surface_->BindToClient(&output_surface_client_); 2129 output_surface_->BindToClient(&output_surface_client_);
2114 resource_provider_ = 2130 resource_provider_ =
2115 FakeResourceProvider::Create(output_surface_.get(), nullptr); 2131 FakeResourceProvider::Create(output_surface_.get(), nullptr);
(...skipping 10 matching lines...) Expand all
2126 std::unique_ptr<OutputSurface> output_surface_; 2142 std::unique_ptr<OutputSurface> output_surface_;
2127 std::unique_ptr<ResourceProvider> resource_provider_; 2143 std::unique_ptr<ResourceProvider> resource_provider_;
2128 std::unique_ptr<GLRenderer> renderer_; 2144 std::unique_ptr<GLRenderer> renderer_;
2129 }; 2145 };
2130 2146
2131 TEST_F(GLRendererWithMockContextTest, 2147 TEST_F(GLRendererWithMockContextTest,
2132 ContextPurgedWhenRendererBecomesInvisible) { 2148 ContextPurgedWhenRendererBecomesInvisible) {
2133 // Ensure our expectations run in order. 2149 // Ensure our expectations run in order.
2134 ::testing::InSequence s; 2150 ::testing::InSequence s;
2135 2151
2136 EXPECT_CALL(*context_support_ptr_, SetClientVisible(0, true)); 2152 EXPECT_CALL(*context_support_ptr_, ClientBecameVisible())
2153 .WillOnce(::testing::Invoke(
2154 context_support_ptr_, &MockContextSupport::SuperClientBecameVisible));
2137 EXPECT_CALL(*context_support_ptr_, AnyClientsVisible()) 2155 EXPECT_CALL(*context_support_ptr_, AnyClientsVisible())
2138 .WillOnce(Return(true)); 2156 .WillOnce(Return(true));
2139 EXPECT_CALL(*context_support_ptr_, SetAggressivelyFreeResources(false)); 2157 EXPECT_CALL(*context_support_ptr_, SetAggressivelyFreeResources(false));
2140 renderer_->SetVisible(true); 2158 renderer_->SetVisible(true);
2141 Mock::VerifyAndClearExpectations(context_support_ptr_); 2159 Mock::VerifyAndClearExpectations(context_support_ptr_);
2142 2160
2143 EXPECT_CALL(*context_support_ptr_, SetClientVisible(0, false)); 2161 EXPECT_CALL(*context_support_ptr_, ClientBecameNotVisible_(::testing::_))
danakj 2016/08/18 21:39:44 just _, we using'd it at the top
ericrk 2016/08/19 17:23:18 Done.
2162 .WillOnce(
2163 ::testing::Invoke(context_support_ptr_,
2164 &MockContextSupport::SuperClientBecameNotVisible));
2144 EXPECT_CALL(*context_support_ptr_, AnyClientsVisible()) 2165 EXPECT_CALL(*context_support_ptr_, AnyClientsVisible())
2145 .WillOnce(Return(false)); 2166 .WillOnce(Return(false));
2146 EXPECT_CALL(*context_provider_, DeleteCachedResources()); 2167 EXPECT_CALL(*context_provider_, DeleteCachedResources());
2147 EXPECT_CALL(*context_support_ptr_, SetAggressivelyFreeResources(true)); 2168 EXPECT_CALL(*context_support_ptr_, SetAggressivelyFreeResources(true));
2148 renderer_->SetVisible(false); 2169 renderer_->SetVisible(false);
2149 Mock::VerifyAndClearExpectations(context_support_ptr_); 2170 Mock::VerifyAndClearExpectations(context_support_ptr_);
2150 } 2171 }
2151 2172
2152 } // namespace 2173 } // namespace
2153 } // namespace cc 2174 } // namespace cc
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698