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

Side by Side Diff: cc/trees/layer_tree_impl_unittest.cc

Issue 2185823005: Make RenderViewImpl::OnForceRedraw more robust (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fix comments and add tests 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 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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/trees/layer_tree_impl.h" 5 #include "cc/trees/layer_tree_impl.h"
6 6
7 #include "cc/layers/heads_up_display_layer_impl.h" 7 #include "cc/layers/heads_up_display_layer_impl.h"
8 #include "cc/test/fake_layer_tree_host_impl.h" 8 #include "cc/test/fake_layer_tree_host_impl.h"
9 #include "cc/test/geometry_test_utils.h" 9 #include "cc/test/geometry_test_utils.h"
10 #include "cc/test/layer_test_common.h" 10 #include "cc/test/layer_test_common.h"
(...skipping 2202 matching lines...) Expand 10 before | Expand all | Expand 10 after
2213 CHECK_EQ(1u, RenderSurfaceLayerList().size()); 2213 CHECK_EQ(1u, RenderSurfaceLayerList().size());
2214 2214
2215 gfx::PointF test_point = gfx::PointF(1.f, 1.f); 2215 gfx::PointF test_point = gfx::PointF(1.f, 1.f);
2216 LayerImpl* result_layer = 2216 LayerImpl* result_layer =
2217 host_impl().active_tree()->FindLayerThatIsHitByPoint(test_point); 2217 host_impl().active_tree()->FindLayerThatIsHitByPoint(test_point);
2218 2218
2219 CHECK(result_layer); 2219 CHECK(result_layer);
2220 EXPECT_EQ(2, result_layer->id()); 2220 EXPECT_EQ(2, result_layer->id());
2221 } 2221 }
2222 2222
2223 namespace {
2224
2225 class CC_EXPORT PersistentSwapPromise
2226 : public SwapPromise,
2227 public base::SupportsWeakPtr<PersistentSwapPromise> {
2228 public:
2229 PersistentSwapPromise() = default;
2230 ~PersistentSwapPromise() override = default;
2231
2232 void DidActivate() override {}
2233 void DidSwap(CompositorFrameMetadata* metadata) override {}
2234
2235 DidNotSwapAction DidNotSwap(DidNotSwapReason reason) override {
2236 return DidNotSwapAction::KEEP_ACTIVE;
2237 }
2238
2239 void OnCommit() override {}
2240 int64_t TraceId() const override { return 0; }
2241 };
2242
2243 class CC_EXPORT NotPersistentSwapPromise
2244 : public SwapPromise,
2245 public base::SupportsWeakPtr<NotPersistentSwapPromise> {
2246 public:
2247 NotPersistentSwapPromise() = default;
2248 ~NotPersistentSwapPromise() override = default;
2249
2250 void DidActivate() override {}
2251 void DidSwap(CompositorFrameMetadata* metadata) override {}
2252
2253 DidNotSwapAction DidNotSwap(DidNotSwapReason reason) override {
2254 return DidNotSwapAction::DEFAULT_ACTION;
2255 }
2256
2257 void OnCommit() override {}
2258 int64_t TraceId() const override { return 0; }
2259 };
2260
2261 } // namespace
2262
2263 TEST_F(LayerTreeImplTest, PersistentSwapPromisesAreKeptAlive) {
2264 const size_t promises_count = 2;
2265
2266 std::vector<base::WeakPtr<PersistentSwapPromise>> persistent_promises;
2267 std::vector<std::unique_ptr<PersistentSwapPromise>>
2268 persistent_promises_to_pass;
2269 for (size_t i = 0; i < promises_count; ++i) {
2270 persistent_promises_to_pass.push_back(
2271 base::WrapUnique(new PersistentSwapPromise()));
2272 }
2273
2274 for (auto& promise : persistent_promises_to_pass) {
2275 persistent_promises.push_back(promise->AsWeakPtr());
2276 host_impl().active_tree()->QueueSwapPromise(std::move(promise));
2277 }
2278
2279 std::vector<std::unique_ptr<SwapPromise>> promises;
2280 host_impl().active_tree()->PassSwapPromises(&promises);
2281 host_impl().active_tree()->BreakSwapPromises(
2282 SwapPromise::DidNotSwapReason::SWAP_FAILS);
2283
2284 ASSERT_EQ(promises_count, persistent_promises.size());
2285 for (size_t i = 0; i < persistent_promises.size(); ++i) {
2286 EXPECT_TRUE(persistent_promises[i]) << "While checking case #" << i;
danakj 2016/08/10 01:04:15 Instead of checking the destructor didn't run (wha
svartmetal 2016/08/10 17:38:22 Reasonable. Made EXPECT_CALL for DidSwap.
2287 }
2288 }
2289
2290 TEST_F(LayerTreeImplTest, NotPersistentSwapPromisesAreDroppedWhenSwapFails) {
2291 const size_t promises_count = 2;
2292
2293 std::vector<base::WeakPtr<NotPersistentSwapPromise>> not_persistent_promises;
2294 std::vector<std::unique_ptr<NotPersistentSwapPromise>>
2295 not_persistent_promises_to_pass;
2296 for (size_t i = 0; i < promises_count; ++i) {
2297 not_persistent_promises_to_pass.push_back(
2298 base::WrapUnique(new NotPersistentSwapPromise()));
2299 }
2300
2301 for (auto& promise : not_persistent_promises_to_pass) {
2302 not_persistent_promises.push_back(promise->AsWeakPtr());
2303 host_impl().active_tree()->QueueSwapPromise(std::move(promise));
2304 }
2305 std::vector<std::unique_ptr<SwapPromise>> promises;
2306 host_impl().active_tree()->PassSwapPromises(&promises);
2307
2308 ASSERT_EQ(promises_count, not_persistent_promises.size());
2309 for (size_t i = 0; i < not_persistent_promises.size(); ++i) {
2310 EXPECT_FALSE(not_persistent_promises[i]) << "While checking case #" << i;
2311 }
2312
2313 // Finally, check that not persistent promise doesn't survive
2314 // |LayerTreeImpl::BreakSwapPromises|.
2315 {
2316 std::unique_ptr<NotPersistentSwapPromise> promise(
2317 new NotPersistentSwapPromise());
2318 auto weak_promise = promise->AsWeakPtr();
2319 host_impl().active_tree()->QueueSwapPromise(std::move(promise));
2320
2321 host_impl().active_tree()->BreakSwapPromises(
2322 SwapPromise::DidNotSwapReason::SWAP_FAILS);
2323 EXPECT_FALSE(weak_promise);
2324 }
2325 }
2326
2223 } // namespace 2327 } // namespace
2224 } // namespace cc 2328 } // namespace cc
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698