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

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 compilation again 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
« no previous file with comments | « cc/trees/layer_tree_impl.cc ('k') | content/browser/devtools/protocol/page_handler.cc » ('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 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"
11 #include "cc/test/layer_tree_settings_for_testing.h" 11 #include "cc/test/layer_tree_settings_for_testing.h"
12 #include "cc/trees/clip_node.h" 12 #include "cc/trees/clip_node.h"
13 #include "cc/trees/draw_property_utils.h" 13 #include "cc/trees/draw_property_utils.h"
14 #include "cc/trees/layer_tree_host_common.h" 14 #include "cc/trees/layer_tree_host_common.h"
15 #include "cc/trees/layer_tree_host_impl.h" 15 #include "cc/trees/layer_tree_host_impl.h"
16 #include "testing/gmock/include/gmock/gmock.h"
16 #include "testing/gtest/include/gtest/gtest.h" 17 #include "testing/gtest/include/gtest/gtest.h"
17 18
18 namespace cc { 19 namespace cc {
19 namespace { 20 namespace {
20 21
21 class LayerTreeImplTestSettings : public LayerTreeSettingsForTesting { 22 class LayerTreeImplTestSettings : public LayerTreeSettingsForTesting {
22 public: 23 public:
23 LayerTreeImplTestSettings() { 24 LayerTreeImplTestSettings() {
24 layer_transforms_should_scale_layer_contents = true; 25 layer_transforms_should_scale_layer_contents = true;
25 } 26 }
(...skipping 2187 matching lines...) Expand 10 before | Expand all | Expand 10 after
2213 CHECK_EQ(1u, RenderSurfaceLayerList().size()); 2214 CHECK_EQ(1u, RenderSurfaceLayerList().size());
2214 2215
2215 gfx::PointF test_point = gfx::PointF(1.f, 1.f); 2216 gfx::PointF test_point = gfx::PointF(1.f, 1.f);
2216 LayerImpl* result_layer = 2217 LayerImpl* result_layer =
2217 host_impl().active_tree()->FindLayerThatIsHitByPoint(test_point); 2218 host_impl().active_tree()->FindLayerThatIsHitByPoint(test_point);
2218 2219
2219 CHECK(result_layer); 2220 CHECK(result_layer);
2220 EXPECT_EQ(2, result_layer->id()); 2221 EXPECT_EQ(2, result_layer->id());
2221 } 2222 }
2222 2223
2224 namespace {
2225
2226 class PersistentSwapPromise
2227 : public SwapPromise,
2228 public base::SupportsWeakPtr<PersistentSwapPromise> {
2229 public:
2230 PersistentSwapPromise() = default;
2231 ~PersistentSwapPromise() override = default;
2232
2233 void DidActivate() override {}
2234 MOCK_METHOD1(DidSwap, void(CompositorFrameMetadata* metadata));
2235
2236 DidNotSwapAction DidNotSwap(DidNotSwapReason reason) override {
2237 return DidNotSwapAction::KEEP_ACTIVE;
2238 }
2239
2240 void OnCommit() override {}
2241 int64_t TraceId() const override { return 0; }
2242 };
2243
2244 class NotPersistentSwapPromise
2245 : public SwapPromise,
2246 public base::SupportsWeakPtr<NotPersistentSwapPromise> {
2247 public:
2248 NotPersistentSwapPromise() = default;
2249 ~NotPersistentSwapPromise() override = default;
2250
2251 void DidActivate() override {}
2252 void DidSwap(CompositorFrameMetadata* metadata) override {}
2253
2254 DidNotSwapAction DidNotSwap(DidNotSwapReason reason) override {
2255 return DidNotSwapAction::BREAK_PROMISE;
2256 }
2257
2258 void OnCommit() override {}
2259 int64_t TraceId() const override { return 0; }
2260 };
2261
2262 } // namespace
2263
2264 TEST_F(LayerTreeImplTest, PersistentSwapPromisesAreKeptAlive) {
2265 const size_t promises_count = 2;
2266
2267 std::vector<base::WeakPtr<PersistentSwapPromise>> persistent_promises;
2268 std::vector<std::unique_ptr<PersistentSwapPromise>>
2269 persistent_promises_to_pass;
2270 for (size_t i = 0; i < promises_count; ++i) {
2271 persistent_promises_to_pass.push_back(
2272 base::MakeUnique<PersistentSwapPromise>());
2273 }
2274
2275 for (auto& promise : persistent_promises_to_pass) {
2276 persistent_promises.push_back(promise->AsWeakPtr());
2277 host_impl().active_tree()->QueueSwapPromise(std::move(promise));
2278 }
2279
2280 std::vector<std::unique_ptr<SwapPromise>> promises;
2281 host_impl().active_tree()->PassSwapPromises(std::move(promises));
2282 host_impl().active_tree()->BreakSwapPromises(
2283 SwapPromise::DidNotSwapReason::SWAP_FAILS);
2284
2285 ASSERT_EQ(promises_count, persistent_promises.size());
2286 for (size_t i = 0; i < persistent_promises.size(); ++i) {
2287 SCOPED_TRACE(testing::Message() << "While checking case #" << i);
2288 ASSERT_TRUE(persistent_promises[i]);
2289 EXPECT_CALL(*persistent_promises[i], DidSwap(testing::_));
2290 }
2291 host_impl().active_tree()->FinishSwapPromises(nullptr);
2292 }
2293
2294 TEST_F(LayerTreeImplTest, NotPersistentSwapPromisesAreDroppedWhenSwapFails) {
2295 const size_t promises_count = 2;
2296
2297 std::vector<base::WeakPtr<NotPersistentSwapPromise>> not_persistent_promises;
2298 std::vector<std::unique_ptr<NotPersistentSwapPromise>>
2299 not_persistent_promises_to_pass;
2300 for (size_t i = 0; i < promises_count; ++i) {
2301 not_persistent_promises_to_pass.push_back(
2302 base::MakeUnique<NotPersistentSwapPromise>());
2303 }
2304
2305 for (auto& promise : not_persistent_promises_to_pass) {
2306 not_persistent_promises.push_back(promise->AsWeakPtr());
2307 host_impl().active_tree()->QueueSwapPromise(std::move(promise));
2308 }
2309 std::vector<std::unique_ptr<SwapPromise>> promises;
2310 host_impl().active_tree()->PassSwapPromises(std::move(promises));
2311
2312 ASSERT_EQ(promises_count, not_persistent_promises.size());
2313 for (size_t i = 0; i < not_persistent_promises.size(); ++i) {
2314 EXPECT_FALSE(not_persistent_promises[i]) << "While checking case #" << i;
2315 }
2316
2317 // Finally, check that not persistent promise doesn't survive
2318 // |LayerTreeImpl::BreakSwapPromises|.
2319 {
2320 std::unique_ptr<NotPersistentSwapPromise> promise(
2321 new NotPersistentSwapPromise());
2322 auto weak_promise = promise->AsWeakPtr();
2323 host_impl().active_tree()->QueueSwapPromise(std::move(promise));
2324 host_impl().active_tree()->BreakSwapPromises(
2325 SwapPromise::DidNotSwapReason::SWAP_FAILS);
2326 EXPECT_FALSE(weak_promise);
2327 }
2328 }
2329
2223 } // namespace 2330 } // namespace
2224 } // namespace cc 2331 } // namespace cc
OLDNEW
« no previous file with comments | « cc/trees/layer_tree_impl.cc ('k') | content/browser/devtools/protocol/page_handler.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698