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
23using namespace testing;
24using namespace testing::ext;
25
26namespace OHOS {
27namespace Rosen {
28namespace {
29constexpr HiviewDFX::HiLogLabel LABEL = {LOG_CORE, HILOG_DOMAIN_DISPLAY, "PrivateWindowTest"};
30}
31class PrivateWindowListener : public DisplayManager::IPrivateWindowListener {
32public:
33    virtual void OnPrivateWindow(bool hasPrivate)
34    {
35        WLOGFD("private window appeared.");
36    };
37};
38
39class PrivateWindowTest : public testing::Test {
40public:
41    static void SetUpTestCase();
42    static void TearDownTestCase();
43    void SetUp() override;
44    void TearDown() override;
45};
46
47void PrivateWindowTest::SetUpTestCase()
48{
49}
50
51void PrivateWindowTest::TearDownTestCase()
52{
53}
54
55void PrivateWindowTest::SetUp()
56{
57}
58
59void PrivateWindowTest::TearDown()
60{
61}
62
63namespace {
64/**
65 * @tc.name: RegisterPrivateWindowListener
66 * @tc.desc: Register private window listener test
67 * @tc.type: FUNC
68 */
69HWTEST_F(PrivateWindowTest, RegisterPrivateWindowListener, Function | MediumTest | Level2)
70{
71    auto& dm = DisplayManager::GetInstance();
72    sptr<PrivateWindowListener> listener_ = new PrivateWindowListener();
73    dm.RegisterPrivateWindowListener(listener_);
74    sptr<WindowOption> option = new WindowOption();
75    auto window = Window::Create("private", option);
76    if (window == nullptr) {
77        return;
78    }
79    window->SetPrivacyMode(true);
80    window->Show();
81    dm.UnregisterPrivateWindowListener(listener_);
82    window->Destroy();
83}
84} // namespace
85} // namespace Rosen
86} // namespace OHOS