• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 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 <gtest/gtest.h>
17 
18 #include "extension_window_impl.h"
19 #include "mock_window_extension_session_impl.h"
20 #include "modifier_render_thread/rs_modifiers_draw_thread.h"
21 
22 using namespace testing;
23 using namespace testing::ext;
24 
25 namespace OHOS {
26 namespace Rosen {
27 class ExtensionWindowImplTest : public testing::Test {
28 public:
29     static void SetUpTestCase();
30     static void TearDownTestCase();
31     void SetUp() override;
32     void TearDown() override;
33 };
34 
SetUpTestCase()35 void ExtensionWindowImplTest::SetUpTestCase() {}
36 
TearDownTestCase()37 void ExtensionWindowImplTest::TearDownTestCase()
38 {
39 #ifdef RS_ENABLE_VK
40     RSModifiersDrawThread::Destroy();
41 #endif
42 }
43 
SetUp()44 void ExtensionWindowImplTest::SetUp() {}
45 
TearDown()46 void ExtensionWindowImplTest::TearDown() {}
47 
48 namespace {
49 /**
50  * @tc.name: GetAvoidAreaByType
51  * @tc.desc: GetAvoidAreaByType Test
52  * @tc.type: FUNC
53  */
54 HWTEST_F(ExtensionWindowImplTest, GetAvoidAreaByType, TestSize.Level1)
55 {
56     sptr<Window> window = new Window();
57     ExtensionWindowImpl extensionWindowImpl(window);
58     AvoidAreaType type = AvoidAreaType::TYPE_SYSTEM;
59     AvoidArea avoidArea;
60     ASSERT_EQ(WMError::WM_OK, extensionWindowImpl.GetAvoidAreaByType(type, avoidArea));
61     ASSERT_EQ(WMError::WM_OK, window->Destroy());
62 }
63 
64 /**
65  * @tc.name: GetWindow
66  * @tc.desc: GetWindow Test
67  * @tc.type: FUNC
68  */
69 HWTEST_F(ExtensionWindowImplTest, GetWindow, TestSize.Level1)
70 {
71     sptr<Window> window = new (std::nothrow) Window();
72     ASSERT_NE(nullptr, window);
73     ExtensionWindowImpl extensionWindowImpl(window);
74 
75     EXPECT_EQ(window, extensionWindowImpl.GetWindow());
76 }
77 
78 /**
79  * @tc.name: HideNonSecureWindows
80  * @tc.desc: HideNonSecureWindows Test
81  * @tc.type: FUNC
82  */
83 HWTEST_F(ExtensionWindowImplTest, HideNonSecureWindows, TestSize.Level1)
84 {
85     sptr<WindowOption> option = new (std::nothrow) WindowOption();
86     ASSERT_NE(nullptr, option);
87     sptr<MockWindowExtensionSessionImpl> window = new (std::nothrow) MockWindowExtensionSessionImpl(option);
88     ASSERT_NE(nullptr, window);
89     ExtensionWindowImpl extensionWindowImpl(window);
90 
91     EXPECT_EQ(WMError::WM_OK, extensionWindowImpl.HideNonSecureWindows(true));
92     EXPECT_TRUE(window->extensionWindowFlags_.hideNonSecureWindowsFlag);
93 
94     EXPECT_EQ(WMError::WM_OK, extensionWindowImpl.HideNonSecureWindows(false));
95     EXPECT_FALSE(window->extensionWindowFlags_.hideNonSecureWindowsFlag);
96 }
97 
98 /**
99  * @tc.name: SetWaterMarkFlag
100  * @tc.desc: SetWaterMarkFlag Test
101  * @tc.type: FUNC
102  */
103 HWTEST_F(ExtensionWindowImplTest, SetWaterMarkFlag, TestSize.Level1)
104 {
105     sptr<WindowOption> option = new (std::nothrow) WindowOption();
106     ASSERT_NE(nullptr, option);
107     sptr<MockWindowExtensionSessionImpl> window = new (std::nothrow) MockWindowExtensionSessionImpl(option);
108     ASSERT_NE(nullptr, window);
109     ExtensionWindowImpl extensionWindowImpl(window);
110 
111     EXPECT_EQ(WMError::WM_OK, extensionWindowImpl.SetWaterMarkFlag(true));
112     EXPECT_TRUE(window->extensionWindowFlags_.waterMarkFlag);
113 
114     EXPECT_EQ(WMError::WM_OK, extensionWindowImpl.SetWaterMarkFlag(false));
115     EXPECT_FALSE(window->extensionWindowFlags_.waterMarkFlag);
116 }
117 
118 /**
119  * @tc.name: IsPcWindow
120  * @tc.desc: IsPcWindow Test
121  * @tc.type: FUNC
122  */
123 HWTEST_F(ExtensionWindowImplTest, IsPcWindow, TestSize.Level1)
124 {
125     sptr<WindowOption> option = sptr<WindowOption>::MakeSptr();
126     sptr<MockWindowExtensionSessionImpl> window = sptr<MockWindowExtensionSessionImpl>::MakeSptr(option);
127     ExtensionWindowImpl extensionWindowImpl(window);
128 
129     EXPECT_EQ(extensionWindowImpl.IsPcWindow(), window->IsPcWindow());
130 }
131 
132 /**
133  * @tc.name: IsPcOrPadFreeMultiWindowMode
134  * @tc.desc: IsPcOrPadFreeMultiWindowMode Test
135  * @tc.type: FUNC
136  */
137 HWTEST_F(ExtensionWindowImplTest, IsPcOrPadFreeMultiWindowMode, TestSize.Level1)
138 {
139     sptr<WindowOption> option = new (std::nothrow) WindowOption();
140     ASSERT_NE(nullptr, option);
141     sptr<MockWindowExtensionSessionImpl> window = new (std::nothrow) MockWindowExtensionSessionImpl(option);
142     ASSERT_NE(nullptr, window);
143     ExtensionWindowImpl extensionWindowImpl(window);
144 
145     EXPECT_EQ(extensionWindowImpl.IsPcOrPadFreeMultiWindowMode(), window->IsPcOrPadFreeMultiWindowMode());
146 }
147 
148 /**
149  * @tc.name: HidePrivacyContentForHost
150  * @tc.desc: HidePrivacyContentForHost Test
151  * @tc.type: FUNC
152  */
153 HWTEST_F(ExtensionWindowImplTest, HidePrivacyContentForHost, TestSize.Level1)
154 {
155     sptr<WindowOption> option = new (std::nothrow) WindowOption();
156     ASSERT_NE(nullptr, option);
157     sptr<MockWindowExtensionSessionImpl> window = new (std::nothrow) MockWindowExtensionSessionImpl(option);
158     ASSERT_NE(nullptr, window);
159     ExtensionWindowImpl extensionWindowImpl(window);
160 
161     EXPECT_EQ(WMError::WM_OK, extensionWindowImpl.HidePrivacyContentForHost(true));
162     EXPECT_EQ(WMError::WM_OK, extensionWindowImpl.HidePrivacyContentForHost(false));
163 }
164 
165 /**
166  * @tc.name: OccupyEvents
167  * @tc.desc: OccupyEvents Test
168  * @tc.type: FUNC
169  */
170 HWTEST_F(ExtensionWindowImplTest, OccupyEvents, TestSize.Level1)
171 {
172     auto option = sptr<WindowOption>::MakeSptr();
173     auto window = sptr<MockWindowExtensionSessionImpl>::MakeSptr(option);
174     ExtensionWindowImpl extensionWindowImpl(window);
175 
176     EXPECT_EQ(WMError::WM_ERROR_NULLPTR, extensionWindowImpl.OccupyEvents(0));
177     window->mockHandler_ = std::make_shared<MockDataHandler>();
178     EXPECT_EQ(WMError::WM_OK, extensionWindowImpl.OccupyEvents(0));
179 }
180 } // namespace
181 } // namespace Rosen
182 } // namespace OHOS