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

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: fix webview Created 4 years, 3 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
« no previous file with comments | « cc/output/gl_renderer.cc ('k') | cc/test/test_context_support.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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_METHOD0(ClientBecameVisible, VisibilityToken());
2103 void(bool aggressively_free_resources)); 2104 MOCK_METHOD1(ClientBecameNotVisible_,
2104 MOCK_METHOD2(SetClientVisible, void(int client_id, bool is_visible)); 2105 void(VisibilityToken& visibility)); // NOLINT
2105 MOCK_CONST_METHOD0(AnyClientsVisible, bool()); 2106 MOCK_CONST_METHOD0(AnyClientsVisible, bool());
2107
2108 // Wrapper to allow mocking w/ move-only type.
2109 void ClientBecameNotVisible(VisibilityToken visibility) override {
2110 ClientBecameNotVisible_(visibility);
2111 }
2112
2113 // Wrappers to allow forwarding to super class implementation.
2114 void SuperClientBecameNotVisible(VisibilityToken& visibility) { // NOLINT
2115 TestContextSupport::ClientBecameNotVisible(std::move(visibility));
2116 }
2117 VisibilityToken SuperClientBecameVisible() {
2118 return TestContextSupport::ClientBecameVisible();
2119 }
2106 }; 2120 };
2107 2121
2108 void SetUp() override { 2122 void SetUp() override {
2109 auto context_support = base::MakeUnique<MockContextSupport>(); 2123 auto context_support = base::MakeUnique<MockContextSupport>();
2110 context_support_ptr_ = context_support.get(); 2124 context_support_ptr_ = context_support.get();
2111 context_provider_ = new MockContextProvider(std::move(context_support)); 2125 context_provider_ = new MockContextProvider(std::move(context_support));
2112 output_surface_ = FakeOutputSurface::Create3d(context_provider_); 2126 output_surface_ = FakeOutputSurface::Create3d(context_provider_);
2113 output_surface_->BindToClient(&output_surface_client_); 2127 output_surface_->BindToClient(&output_surface_client_);
2114 resource_provider_ = 2128 resource_provider_ =
2115 FakeResourceProvider::Create(output_surface_.get(), nullptr); 2129 FakeResourceProvider::Create(output_surface_.get(), nullptr);
(...skipping 10 matching lines...) Expand all
2126 std::unique_ptr<OutputSurface> output_surface_; 2140 std::unique_ptr<OutputSurface> output_surface_;
2127 std::unique_ptr<ResourceProvider> resource_provider_; 2141 std::unique_ptr<ResourceProvider> resource_provider_;
2128 std::unique_ptr<GLRenderer> renderer_; 2142 std::unique_ptr<GLRenderer> renderer_;
2129 }; 2143 };
2130 2144
2131 TEST_F(GLRendererWithMockContextTest, 2145 TEST_F(GLRendererWithMockContextTest,
2132 ContextPurgedWhenRendererBecomesInvisible) { 2146 ContextPurgedWhenRendererBecomesInvisible) {
2133 // Ensure our expectations run in order. 2147 // Ensure our expectations run in order.
2134 ::testing::InSequence s; 2148 ::testing::InSequence s;
2135 2149
2136 EXPECT_CALL(*context_support_ptr_, SetClientVisible(0, true)); 2150 EXPECT_CALL(*context_support_ptr_, ClientBecameVisible())
2151 .WillOnce(::testing::Invoke(
2152 context_support_ptr_, &MockContextSupport::SuperClientBecameVisible));
2137 EXPECT_CALL(*context_support_ptr_, AnyClientsVisible()) 2153 EXPECT_CALL(*context_support_ptr_, AnyClientsVisible())
2138 .WillOnce(Return(true)); 2154 .WillOnce(Return(true));
2139 EXPECT_CALL(*context_support_ptr_, SetAggressivelyFreeResources(false));
2140 renderer_->SetVisible(true); 2155 renderer_->SetVisible(true);
2141 Mock::VerifyAndClearExpectations(context_support_ptr_); 2156 Mock::VerifyAndClearExpectations(context_support_ptr_);
2142 2157
2143 EXPECT_CALL(*context_support_ptr_, SetClientVisible(0, false)); 2158 EXPECT_CALL(*context_support_ptr_, ClientBecameNotVisible_(_))
2159 .WillOnce(
2160 ::testing::Invoke(context_support_ptr_,
2161 &MockContextSupport::SuperClientBecameNotVisible));
2144 EXPECT_CALL(*context_support_ptr_, AnyClientsVisible()) 2162 EXPECT_CALL(*context_support_ptr_, AnyClientsVisible())
2145 .WillOnce(Return(false)); 2163 .WillOnce(Return(false));
2146 EXPECT_CALL(*context_provider_, DeleteCachedResources()); 2164 EXPECT_CALL(*context_provider_, DeleteCachedResources());
2147 EXPECT_CALL(*context_support_ptr_, SetAggressivelyFreeResources(true));
2148 renderer_->SetVisible(false); 2165 renderer_->SetVisible(false);
2149 Mock::VerifyAndClearExpectations(context_support_ptr_); 2166 Mock::VerifyAndClearExpectations(context_support_ptr_);
2150 } 2167 }
2151 2168
2152 } // namespace 2169 } // namespace
2153 } // namespace cc 2170 } // namespace cc
OLDNEW
« no previous file with comments | « cc/output/gl_renderer.cc ('k') | cc/test/test_context_support.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698