1 /*
2  * Copyright 2020 The Android Open Source Project
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 #undef LOG_TAG
18 #define LOG_TAG "LibSurfaceFlingerUnittests"
19 
20 #include "DisplayTransactionTestHelpers.h"
21 
22 namespace android {
23 namespace {
24 
25 class DestroyDisplayTest : public DisplayTransactionTest {};
26 
TEST_F(DestroyDisplayTest,destroyDisplayClearsCurrentStateForDisplay)27 TEST_F(DestroyDisplayTest, destroyDisplayClearsCurrentStateForDisplay) {
28     using Case = NonHwcVirtualDisplayCase;
29 
30     // --------------------------------------------------------------------
31     // Preconditions
32 
33     // A virtual display exists
34     auto existing = Case::Display::makeFakeExistingDisplayInjector(this);
35     existing.inject();
36 
37     // --------------------------------------------------------------------
38     // Call Expectations
39 
40     // The call should notify the interceptor that a display was created.
41     EXPECT_CALL(*mSurfaceInterceptor, saveDisplayDeletion(_)).Times(1);
42 
43     // Destroying the display invalidates the display state.
44     EXPECT_CALL(*mMessageQueue, invalidate()).Times(1);
45 
46     // --------------------------------------------------------------------
47     // Invocation
48 
49     mFlinger.destroyDisplay(existing.token());
50 
51     // --------------------------------------------------------------------
52     // Postconditions
53 
54     // The display should have been removed from the current state
55     EXPECT_FALSE(hasCurrentDisplayState(existing.token()));
56 
57     // Ths display should still exist in the drawing state
58     EXPECT_TRUE(hasDrawingDisplayState(existing.token()));
59 
60     // The display transaction needed flasg should be set
61     EXPECT_TRUE(hasTransactionFlagSet(eDisplayTransactionNeeded));
62 }
63 
TEST_F(DestroyDisplayTest,destroyDisplayHandlesUnknownDisplay)64 TEST_F(DestroyDisplayTest, destroyDisplayHandlesUnknownDisplay) {
65     // --------------------------------------------------------------------
66     // Preconditions
67 
68     sp<BBinder> displayToken = new BBinder();
69 
70     // --------------------------------------------------------------------
71     // Invocation
72 
73     mFlinger.destroyDisplay(displayToken);
74 }
75 
76 } // namespace
77 } // namespace android
78