1 /*
2 * Copyright (c) 2022-2023 Huawei Device Co., Ltd.
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
6 *
7 * http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 */
15
16 #include <cinttypes>
17 #include <gtest/gtest.h>
18
19 #include "display_manager.h"
20 #include "window_manager_hilog.h"
21 #include "window.h"
22
23 using namespace testing;
24 using namespace testing::ext;
25
26 namespace OHOS {
27 namespace Rosen {
28 namespace {
29 constexpr HiviewDFX::HiLogLabel LABEL = {LOG_CORE, HILOG_DOMAIN_DISPLAY, "PrivateWindowTest"};
30 }
31 class PrivateWindowListener : public DisplayManager::IPrivateWindowListener {
32 public:
OnPrivateWindow(bool hasPrivate)33 virtual void OnPrivateWindow(bool hasPrivate)
34 {
35 WLOGFD("private window appeared.");
36 };
37 };
38
39 class PrivateWindowTest : public testing::Test {
40 public:
41 static void SetUpTestCase();
42 static void TearDownTestCase();
43 void SetUp() override;
44 void TearDown() override;
45 };
46
SetUpTestCase()47 void PrivateWindowTest::SetUpTestCase()
48 {
49 }
50
TearDownTestCase()51 void PrivateWindowTest::TearDownTestCase()
52 {
53 }
54
SetUp()55 void PrivateWindowTest::SetUp()
56 {
57 }
58
TearDown()59 void PrivateWindowTest::TearDown()
60 {
61 }
62
63 namespace {
64 /**
65 * @tc.name: RegisterPrivateWindowListener
66 * @tc.desc: Register private window listener test
67 * @tc.type: FUNC
68 */
69 HWTEST_F(PrivateWindowTest, RegisterPrivateWindowListener, Function | MediumTest | Level2)
70 {
71 auto& dm = DisplayManager::GetInstance();
72 sptr<PrivateWindowListener> listener_ = new PrivateWindowListener();
73 auto ret = dm.RegisterPrivateWindowListener(listener_);
74 ASSERT_EQ(DMError::DM_OK, ret);
75 sptr<WindowOption> option = new WindowOption();
76 auto window = Window::Create("private", option);
77 if (window == nullptr) {
78 return;
79 }
80 window->SetPrivacyMode(true);
81 window->Show();
82 auto ret1 = dm.UnregisterPrivateWindowListener(listener_);
83 ASSERT_EQ(DMError::DM_OK, ret1);
84 window->Destroy();
85 }
86 } // namespace
87 } // namespace Rosen
88 } // namespace OHOS