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)27TEST_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 // Destroying the display commits a display transaction. 41 EXPECT_CALL(*mFlinger.scheduler(), scheduleFrame()).Times(1); 42 43 // -------------------------------------------------------------------- 44 // Invocation 45 46 mFlinger.destroyDisplay(existing.token()); 47 48 // -------------------------------------------------------------------- 49 // Postconditions 50 51 // The display should have been removed from the current state 52 EXPECT_FALSE(hasCurrentDisplayState(existing.token())); 53 54 // Ths display should still exist in the drawing state 55 EXPECT_TRUE(hasDrawingDisplayState(existing.token())); 56 57 // The display transaction needed flasg should be set 58 EXPECT_TRUE(hasTransactionFlagSet(eDisplayTransactionNeeded)); 59 } 60 TEST_F(DestroyDisplayTest,destroyDisplayHandlesUnknownDisplay)61TEST_F(DestroyDisplayTest, destroyDisplayHandlesUnknownDisplay) { 62 // -------------------------------------------------------------------- 63 // Preconditions 64 65 sp<BBinder> displayToken = sp<BBinder>::make(); 66 67 // -------------------------------------------------------------------- 68 // Invocation 69 70 mFlinger.destroyDisplay(displayToken); 71 } 72 73 } // namespace 74 } // namespace android 75