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

Side by Side Diff: cc/surfaces/surface_manager_ref_unittest.cc

Issue 2716553004: Add temporary reference ownership to SurfaceManager. (Closed)
Patch Set: Rebase Created 3 years, 9 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/surfaces/surface_manager.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2016 The Chromium Authors. All rights reserved. 1 // Copyright 2016 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 <stddef.h> 5 #include <stddef.h>
6 6
7 #include <unordered_map> 7 #include <unordered_map>
8 #include <vector> 8 #include <vector>
9 9
10 #include "base/memory/ptr_util.h" 10 #include "base/memory/ptr_util.h"
(...skipping 413 matching lines...) Expand 10 before | Expand all | Expand 10 after
424 DestroySurface(id2); 424 DestroySurface(id2);
425 RemoveSurfaceReference(manager().GetRootSurfaceId(), id1); 425 RemoveSurfaceReference(manager().GetRootSurfaceId(), id1);
426 426
427 // |id1| is destroyed and has no references, so it's deleted. 427 // |id1| is destroyed and has no references, so it's deleted.
428 EXPECT_EQ(nullptr, manager().GetSurfaceForId(id1)); 428 EXPECT_EQ(nullptr, manager().GetSurfaceForId(id1));
429 429
430 // |id2| is destroyed but has a temporary reference, it's not deleted. 430 // |id2| is destroyed but has a temporary reference, it's not deleted.
431 EXPECT_NE(nullptr, manager().GetSurfaceForId(id2)); 431 EXPECT_NE(nullptr, manager().GetSurfaceForId(id2));
432 } 432 }
433 433
434 // Checks that when a temporary reference is assigned an owner, if the owner is
435 // invalidated then the temporary reference is also removed.
436 TEST_F(SurfaceManagerRefTest, InvalidateTempReferenceOwnerRemovesReference) {
437 // Surface |id1| should have a temporary reference on creation.
438 const SurfaceId id1 = CreateSurface(kFrameSink2, 1);
439 ASSERT_THAT(GetAllTempReferences(), UnorderedElementsAre(id1));
440
441 // |id1| should have a temporary reference after an owner is assigned.
442 manager().AssignTemporaryReference(id1, kFrameSink1);
443 ASSERT_THAT(GetAllTempReferences(), UnorderedElementsAre(id1));
444
445 // When |kFrameSink1| is invalidated the temporary reference will be removed.
446 manager().InvalidateFrameSinkId(kFrameSink1);
447 ASSERT_THAT(GetAllTempReferences(), IsEmpty());
448 }
449
450 // Checks that adding a surface reference clears the temporary reference and
451 // ownership. Invalidating the old owner shouldn't do anything.
452 TEST_F(SurfaceManagerRefTest, InvalidateHasNoEffectOnSurfaceReferences) {
453 const SurfaceId parent_id = CreateSurface(kFrameSink1, 1);
454 AddSurfaceReference(manager().GetRootSurfaceId(), parent_id);
455
456 const SurfaceId id1 = CreateSurface(kFrameSink2, 1);
457 manager().AssignTemporaryReference(id1, kFrameSink1);
458 ASSERT_THAT(GetAllTempReferences(), UnorderedElementsAre(id1));
459
460 // Adding a real surface reference will remove the temporary reference.
461 AddSurfaceReference(parent_id, id1);
462 ASSERT_THAT(GetAllTempReferences(), IsEmpty());
463 ASSERT_THAT(GetReferencesFor(id1), UnorderedElementsAre(parent_id));
464
465 // When |kFrameSink1| is invalidated it shouldn't change the surface
466 // references.
467 manager().InvalidateFrameSinkId(kFrameSink1);
468 ASSERT_THAT(GetReferencesFor(id1), UnorderedElementsAre(parent_id));
469 }
470
471 TEST_F(SurfaceManagerRefTest, CheckDropTemporaryReferenceWorks) {
472 const SurfaceId id1 = CreateSurface(kFrameSink1, 1);
473 ASSERT_THAT(GetAllTempReferences(), UnorderedElementsAre(id1));
474
475 // An example of why this could happen is the window server doesn't know the
476 // owner, maybe it has crashed and been cleanup already, and asks to drop the
477 // temporary reference.
478 manager().DropTemporaryReference(id1);
479 ASSERT_THAT(GetAllTempReferences(), IsEmpty());
480 }
481
482 // Checks that we handle ownership and temporary references correctly when there
483 // are multiple temporary references. This tests something like the parent
484 // client crashing, so it's
485 TEST_F(SurfaceManagerRefTest, TempReferencesWithClientCrash) {
486 const SurfaceId parent_id = CreateSurface(kFrameSink1, 1);
487 AddSurfaceReference(manager().GetRootSurfaceId(), parent_id);
488
489 const SurfaceId id1a = CreateSurface(kFrameSink2, 1);
490 const SurfaceId id1b = CreateSurface(kFrameSink2, 2);
491
492 ASSERT_THAT(GetAllTempReferences(), UnorderedElementsAre(id1a, id1b));
493
494 // Assign |id1a| to |kFrameSink1|. This doesn't change the temporary
495 // reference, it just assigns as owner to it.
496 manager().AssignTemporaryReference(id1a, kFrameSink1);
497 ASSERT_THAT(GetAllTempReferences(), UnorderedElementsAre(id1a, id1b));
498
499 // If the parent client crashes then the CompositorFrameSink connection will
500 // be closed and the FrameSinkId invalidated. The temporary reference
501 // |kFrameSink1| owns to |id2a| will be removed.
502 manager().InvalidateFrameSinkId(kFrameSink1);
503 ASSERT_THAT(GetAllTempReferences(), UnorderedElementsAre(id1b));
504
505 // If the parent has crashed then the window server will have already removed
506 // it from the ServerWindow hierarchy and won't have an owner for |id2b|. The
507 // window server will ask to drop the reference instead.
508 manager().DropTemporaryReference(id1b);
509 ASSERT_THAT(GetAllTempReferences(), IsEmpty());
510 }
511
434 } // namespace cc 512 } // namespace cc
OLDNEW
« no previous file with comments | « cc/surfaces/surface_manager.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698