• 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 
21 using namespace testing;
22 using namespace testing::ext;
23 
24 namespace OHOS {
25 namespace Rosen {
26 class ExtensionWindowImplTest : public testing::Test {};
27 
28 namespace {
29 /**
30  * @tc.name: GetAvoidAreaByType
31  * @tc.desc: GetAvoidAreaByType Test
32  * @tc.type: FUNC
33  */
34 HWTEST_F(ExtensionWindowImplTest, GetAvoidAreaByType, Function | SmallTest | Level2)
35 {
36     sptr<Window> window = new Window();
37     ExtensionWindowImpl extensionWindowImpl(window);
38     AvoidAreaType type = AvoidAreaType::TYPE_SYSTEM;
39     AvoidArea avoidArea;
40     ASSERT_EQ(WMError::WM_OK, extensionWindowImpl.GetAvoidAreaByType(type, avoidArea));
41     ASSERT_EQ(WMError::WM_OK, window->Destroy());
42 }
43 
44 /**
45  * @tc.name: GetWindow
46  * @tc.desc: GetWindow Test
47  * @tc.type: FUNC
48  */
49 HWTEST_F(ExtensionWindowImplTest, GetWindow, Function | SmallTest | Level2)
50 {
51     sptr<Window> window = new (std::nothrow) Window();
52     ASSERT_NE(nullptr, window);
53     ExtensionWindowImpl extensionWindowImpl(window);
54 
55     EXPECT_EQ(window, extensionWindowImpl.GetWindow());
56 }
57 
58 /**
59  * @tc.name: HideNonSecureWindows
60  * @tc.desc: HideNonSecureWindows Test
61  * @tc.type: FUNC
62  */
63 HWTEST_F(ExtensionWindowImplTest, HideNonSecureWindows, Function | SmallTest | Level2)
64 {
65     sptr<WindowOption> option = new (std::nothrow) WindowOption();
66     ASSERT_NE(nullptr, option);
67     sptr<MockWindowExtensionSessionImpl> window = new (std::nothrow) MockWindowExtensionSessionImpl(option);
68     ASSERT_NE(nullptr, window);
69     ExtensionWindowImpl extensionWindowImpl(window);
70 
71     EXPECT_EQ(WMError::WM_OK, extensionWindowImpl.HideNonSecureWindows(true));
72     EXPECT_TRUE(window->extensionWindowFlags_.hideNonSecureWindowsFlag);
73 
74     EXPECT_EQ(WMError::WM_OK, extensionWindowImpl.HideNonSecureWindows(false));
75     EXPECT_FALSE(window->extensionWindowFlags_.hideNonSecureWindowsFlag);
76 }
77 
78 /**
79  * @tc.name: SetWaterMarkFlag
80  * @tc.desc: SetWaterMarkFlag Test
81  * @tc.type: FUNC
82  */
83 HWTEST_F(ExtensionWindowImplTest, SetWaterMarkFlag, Function | SmallTest | Level2)
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.SetWaterMarkFlag(true));
92     EXPECT_TRUE(window->extensionWindowFlags_.waterMarkFlag);
93 
94     EXPECT_EQ(WMError::WM_OK, extensionWindowImpl.SetWaterMarkFlag(false));
95     EXPECT_FALSE(window->extensionWindowFlags_.waterMarkFlag);
96 }
97 
98 /**
99  * @tc.name: IsPcWindow
100  * @tc.desc: IsPcWindow Test
101  * @tc.type: FUNC
102  */
103 HWTEST_F(ExtensionWindowImplTest, IsPcWindow, Function | SmallTest | Level2)
104 {
105     sptr<WindowOption> option = sptr<WindowOption>::MakeSptr();
106     sptr<MockWindowExtensionSessionImpl> window = sptr<MockWindowExtensionSessionImpl>::MakeSptr(option);
107     ExtensionWindowImpl extensionWindowImpl(window);
108 
109     EXPECT_EQ(extensionWindowImpl.IsPcWindow(), window->IsPcWindow());
110 }
111 
112 /**
113  * @tc.name: IsPcOrPadFreeMultiWindowMode
114  * @tc.desc: IsPcOrPadFreeMultiWindowMode Test
115  * @tc.type: FUNC
116  */
117 HWTEST_F(ExtensionWindowImplTest, IsPcOrPadFreeMultiWindowMode, Function | SmallTest | Level2)
118 {
119     sptr<WindowOption> option = new (std::nothrow) WindowOption();
120     ASSERT_NE(nullptr, option);
121     sptr<MockWindowExtensionSessionImpl> window = new (std::nothrow) MockWindowExtensionSessionImpl(option);
122     ASSERT_NE(nullptr, window);
123     ExtensionWindowImpl extensionWindowImpl(window);
124 
125     EXPECT_EQ(extensionWindowImpl.IsPcOrPadFreeMultiWindowMode(), window->IsPcOrPadFreeMultiWindowMode());
126 }
127 
128 /**
129  * @tc.name: HidePrivacyContentForHost
130  * @tc.desc: HidePrivacyContentForHost Test
131  * @tc.type: FUNC
132  */
133 HWTEST_F(ExtensionWindowImplTest, HidePrivacyContentForHost, Function | SmallTest | Level2)
134 {
135     sptr<WindowOption> option = new (std::nothrow) WindowOption();
136     ASSERT_NE(nullptr, option);
137     sptr<MockWindowExtensionSessionImpl> window = new (std::nothrow) MockWindowExtensionSessionImpl(option);
138     ASSERT_NE(nullptr, window);
139     ExtensionWindowImpl extensionWindowImpl(window);
140 
141     EXPECT_EQ(WMError::WM_OK, extensionWindowImpl.HidePrivacyContentForHost(true));
142     EXPECT_EQ(WMError::WM_OK, extensionWindowImpl.HidePrivacyContentForHost(false));
143 }
144 
145 /**
146  * @tc.name: OccupyEvents
147  * @tc.desc: OccupyEvents Test
148  * @tc.type: FUNC
149  */
150 HWTEST_F(ExtensionWindowImplTest, OccupyEvents, Function | SmallTest | Level2)
151 {
152     auto option = sptr<WindowOption>::MakeSptr();
153     auto window = sptr<MockWindowExtensionSessionImpl>::MakeSptr(option);
154     ExtensionWindowImpl extensionWindowImpl(window);
155 
156     EXPECT_EQ(WMError::WM_ERROR_NULLPTR, extensionWindowImpl.OccupyEvents(0));
157     window->mockHandler_ = std::make_shared<MockDataHandler>();
158     EXPECT_EQ(WMError::WM_OK, extensionWindowImpl.OccupyEvents(0));
159 }
160 } // namespace
161 } // namespace Rosen
162 } // namespace OHOS