• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2022 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 #include "window_extension_proxy.h"
18 #include "window_extension_stub.h"
19 #include "window_extension_stub_impl.h"
20 #include "window_extension_client_interface.h"
21 #include "window_extension_client_stub_impl.h"
22 #include "iremote_object_mocker.h"
23 #include "window_extension_session_impl.h"
24 #include "modifier_render_thread/rs_modifiers_draw_thread.h"
25 
26 using namespace testing;
27 using namespace testing::ext;
28 
29 namespace OHOS {
30 namespace Rosen {
31 class WindowExtensionStubImplTest : public testing::Test {
32 public:
33     static void SetUpTestCase();
34     static void TearDownTestCase();
35     void SetUp() override;
36     void TearDown() override;
37     sptr<WindowExtensionStub> mockWindowExtensionStub_;
38     sptr<WindowExtensionProxy> windowExtensionProxy_;
39     wptr<Window> window_ = nullptr;
40 };
41 
SetUpTestCase()42 void WindowExtensionStubImplTest::SetUpTestCase()
43 {
44 }
45 
TearDownTestCase()46 void WindowExtensionStubImplTest::TearDownTestCase()
47 {
48 #ifdef RS_ENABLE_VK
49     RSModifiersDrawThread::Destroy();
50 #endif
51 }
52 
SetUp()53 void WindowExtensionStubImplTest::SetUp()
54 {
55 }
56 
TearDown()57 void WindowExtensionStubImplTest::TearDown()
58 {
59 }
60 
61 namespace {
62 /**
63  * @tc.name: CreateWindow
64  * @tc.desc: test success
65  * @tc.type: FUNC
66  */
67 HWTEST_F(WindowExtensionStubImplTest, CreateWindow, TestSize.Level1)
68 {
69     Rect rect;
70     uint32_t parentWindowId = 0;
71     std::shared_ptr<AbilityRuntime::Context> context;
72     sptr<IRemoteObject> iSession;
73     sptr<WindowOption> option;
74     WindowExtensionStubImpl windowExtensionStubImpl("windowName");
75     auto res = windowExtensionStubImpl.CreateWindow(rect, parentWindowId, context, iSession);
76     ASSERT_EQ(nullptr, res);
77 
78     iSession = new IRemoteObjectMocker();
79     ASSERT_NE(nullptr, iSession);
80     option = new(std::nothrow) WindowOption();
81     ASSERT_NE(nullptr, option);
82     res = windowExtensionStubImpl.CreateWindow(rect, parentWindowId, context, iSession);
83     ASSERT_EQ(nullptr, res);
84 }
85 
86 /**
87  * @tc.name: CreateWindow
88  * @tc.desc: test success
89  * @tc.type: FUNC
90  */
91 HWTEST_F(WindowExtensionStubImplTest, SetBounds, TestSize.Level1)
92 {
93     WindowExtensionStubImpl windowExtensionStubImpl("windowName");
94     Rect rect = { 150, 150, 400, 600 };
95     windowExtensionStubImpl.SetBounds(rect);
96 
97     sptr<WindowOption> option = new(std::nothrow) WindowOption();
98     ASSERT_NE(nullptr, option);
99     option->SetWindowRect(rect);
100     sptr<WindowExtensionSessionImpl> window = new(std::nothrow) WindowExtensionSessionImpl(option);
101     ASSERT_NE(nullptr, window);
102     window->property_->SetWindowRect(rect);
103     windowExtensionStubImpl.window_ = window;
104     windowExtensionStubImpl.SetBounds(rect);
105 
106     Rect rect2 = { 100, 100, 200, 300 };
107     windowExtensionStubImpl.SetBounds(rect2);
108 
109     rect2 = { 100, 150, 200, 600 };
110     windowExtensionStubImpl.SetBounds(rect2);
111 
112     rect2 = { 150, 100, 400, 300 };
113     windowExtensionStubImpl.SetBounds(rect2);
114 }
115 
116 /**
117  * @tc.name: Hide
118  * @tc.desc: test success
119  * @tc.type: FUNC
120  */
121 HWTEST_F(WindowExtensionStubImplTest, Hide, TestSize.Level1)
122 {
123     WindowExtensionStubImpl windowExtensionStubImpl("windowName");
124     windowExtensionStubImpl.Hide();
125 
126     sptr<WindowOption> option = new(std::nothrow) WindowOption();
127     ASSERT_NE(nullptr, option);
128     sptr<WindowExtensionSessionImpl> window = new(std::nothrow) WindowExtensionSessionImpl(option);
129     ASSERT_NE(nullptr, window);
130     windowExtensionStubImpl.window_ = window;
131     windowExtensionStubImpl.Hide();
132 }
133 
134 /**
135  * @tc.name: Show
136  * @tc.desc: test success
137  * @tc.type: FUNC
138  */
139 HWTEST_F(WindowExtensionStubImplTest, Show, TestSize.Level1)
140 {
141     WindowExtensionStubImpl windowExtensionStubImpl("windowName");
142     windowExtensionStubImpl.Show();
143 
144     sptr<WindowOption> option = new(std::nothrow) WindowOption();
145     ASSERT_NE(nullptr, option);
146     sptr<WindowExtensionSessionImpl> window = new(std::nothrow) WindowExtensionSessionImpl(option);
147     ASSERT_NE(nullptr, window);
148     windowExtensionStubImpl.window_ = window;
149     windowExtensionStubImpl.Show();
150 }
151 
152 /**
153  * @tc.name: RequestFocus
154  * @tc.desc: test success
155  * @tc.type: FUNC
156  */
157 HWTEST_F(WindowExtensionStubImplTest, RequestFocus, TestSize.Level1)
158 {
159     WindowExtensionStubImpl windowExtensionStubImpl("windowName");
160     windowExtensionStubImpl.RequestFocus();
161 
162     sptr<WindowOption> option = new(std::nothrow) WindowOption();
163     ASSERT_NE(nullptr, option);
164     sptr<WindowExtensionSessionImpl> window = new(std::nothrow) WindowExtensionSessionImpl(option);
165     ASSERT_NE(nullptr, window);
166     windowExtensionStubImpl.window_ = window;
167     windowExtensionStubImpl.RequestFocus();
168 }
169 
170 /**
171  * @tc.name: GetExtensionWindow
172  * @tc.desc: test success
173  * @tc.type: FUNC
174  */
175 HWTEST_F(WindowExtensionStubImplTest, GetExtensionWindow, TestSize.Level1)
176 {
177     sptr<IWindowExtensionClient> token;
178     WindowExtensionStubImpl windowExtensionStubImpl("windowName");
179     auto window = windowExtensionStubImpl.window_.promote();
180     windowExtensionStubImpl.GetExtensionWindow(token);
181     sptr<IWindowExtensionCallback> componentCallback;
182     WindowExtensionClientStubImpl windowExtensionClientStubImpl(componentCallback);
183     sptr<IWindowExtensionClient> clientToken(new WindowExtensionClientStubImpl(
184         windowExtensionClientStubImpl.componentCallback_));
185     windowExtensionStubImpl.GetExtensionWindow(clientToken);
186     ASSERT_EQ(windowExtensionStubImpl.window_.promote(), windowExtensionStubImpl.GetWindow());
187 }
188 
189 /**
190  * @tc.name: GetWindow
191  * @tc.desc: test success
192  * @tc.type: FUNC
193  */
194 HWTEST_F(WindowExtensionStubImplTest, GetWindow, TestSize.Level1)
195 {
196     WindowExtensionStubImpl windowExtensionStubImpl("windowName");
197     auto window = windowExtensionStubImpl.window_.promote();
198     windowExtensionStubImpl.GetWindow();
199     ASSERT_EQ(windowExtensionStubImpl.window_.promote(), windowExtensionStubImpl.GetWindow());
200 }
201 }
202 }
203 }