• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2025 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 <ability_context_impl.h>
19 #include <context_impl.h>
20 #include <int_wrapper.h>
21 #include <transaction/rs_transaction.h>
22 #include <want_params_wrapper.h>
23 
24 #include "display_info.h"
25 #include "extension/extension_business_info.h"
26 #include "extension_data_handler.h"
27 #include "iremote_object_mocker.h"
28 #include "mock_session.h"
29 #include "mock_uicontent.h"
30 #include "window_extension_session_impl.h"
31 
32 using namespace testing;
33 using namespace testing::ext;
34 using namespace std;
35 namespace OHOS {
36 namespace Rosen {
37 class WindowExtensionSessionImplRotationTest : public testing::Test {
38 public:
39     static void SetUpTestCase();
40     static void TearDownTestCase();
41     void SetUp() override;
42     void TearDown() override;
43 private:
44     sptr<WindowExtensionSessionImpl> window_ = nullptr;
45     std::shared_ptr<AppExecFwk::EventHandler> handler_ = nullptr;
46     static constexpr uint32_t WAIT_SYNC_IN_NS = 200000;
47 };
48 
SetUpTestCase()49 void WindowExtensionSessionImplRotationTest::SetUpTestCase()
50 {
51 }
52 
TearDownTestCase()53 void WindowExtensionSessionImplRotationTest::TearDownTestCase()
54 {
55 }
56 
SetUp()57 void WindowExtensionSessionImplRotationTest::SetUp()
58 {
59     sptr<WindowOption> option = new(std::nothrow) WindowOption();
60     ASSERT_NE(nullptr, option);
61     option->SetWindowName("WindowExtensionSessionImplRotationTest");
62     window_ = new(std::nothrow) WindowExtensionSessionImpl(option);
63     ASSERT_NE(nullptr, window_);
64     if (!handler_) {
65         auto runner = AppExecFwk::EventRunner::Create("WindowExtensionSessionImplRotationTest");
66         handler_ = std::make_shared<AppExecFwk::EventHandler>(runner);
67     }
68     window_->handler_ = handler_;
69 }
70 
TearDown()71 void WindowExtensionSessionImplRotationTest::TearDown()
72 {
73     window_ = nullptr;
74 }
75 
76 namespace {
77 /**
78  * @tc.name: UpdateRectForRotation
79  * @tc.desc: UpdateRect Test
80  * @tc.type: FUNC
81  */
82 HWTEST_F(WindowExtensionSessionImplRotationTest, UpdateRectForRotation, TestSize.Level1)
83 {
84     Rect rect;
85     WindowSizeChangeReason wmReason = WindowSizeChangeReason{0};
86     std::shared_ptr<RSTransaction> rsTransaction = std::make_shared<RSTransaction>();
87     rsTransaction->syncId_ = 1;
88     rsTransaction->isOpenSyncTransaction_ = true;
89     ASSERT_NE(nullptr, window_);
90     window_->UpdateRectForRotation(rect, rect, wmReason, rsTransaction);
91 
92     Rect preRect;
93     window_->UpdateRectForRotation(rect, preRect, wmReason, rsTransaction);
94 
95     rsTransaction->isOpenSyncTransaction_ = false;
96     window_->UpdateRectForRotation(rect, rect, wmReason, rsTransaction);
97 
98     rsTransaction->syncId_ = -1;
99     window_->UpdateRectForRotation(rect, rect, wmReason, rsTransaction);
100 
101     rsTransaction = nullptr;
102     window_->UpdateRectForRotation(rect, rect, wmReason, rsTransaction);
103     window_->UpdateRectForOtherReason(rect, wmReason);
104 
105     window_->handler_ = nullptr;
106     window_->UpdateRectForRotation(rect, rect, wmReason, rsTransaction);
107     usleep(WAIT_SYNC_IN_NS);
108 }
109 
110 /**
111  * @tc.name: UpdateRectForRotation02
112  * @tc.desc: UpdateRectForRotation02 Test
113  * @tc.type: FUNC
114  */
115 HWTEST_F(WindowExtensionSessionImplRotationTest, UpdateRectForRotation02, TestSize.Level2)
116 {
117     EXPECT_NE(nullptr, window_);
118     auto runner = AppExecFwk::EventRunner::Create("ExtensionUpdateRectForRotation02");
119     std::shared_ptr<AppExecFwk::EventHandler> handler = std::make_shared<AppExecFwk::EventHandler>(runner);
120     runner->Run();
121     window_->handler_ = handler;
122     std::shared_ptr<RSTransaction> rsTransaction = std::make_shared<RSTransaction>();
123     rsTransaction->syncId_ = 1;
124     rsTransaction->isOpenSyncTransaction_ = true;
125 
126     Rect wmRect;
127     wmRect.posX_ = 0;
128     wmRect.posY_ = 0;
129     wmRect.height_ = 50;
130     wmRect.width_ = 50;
131 
132     Rect preRect;
133     preRect.posX_ = 0;
134     preRect.posY_ = 0;
135     preRect.height_ = 200;
136     preRect.width_ = 200;
137 
138     window_->property_->SetWindowRect(preRect);
139     WindowSizeChangeReason wmReason = WindowSizeChangeReason::SNAPSHOT_ROTATION;
140     window_->UpdateRectForRotation(wmRect, preRect, wmReason, rsTransaction);
141     usleep(WAIT_SYNC_IN_NS);
142 
143     WSRect wsRect;
144     wsRect.posX_ = 0;
145     wsRect.posY_ = 0;
146     wsRect.height_ = 50;
147     wsRect.width_ = 50;
148     window_->property_->SetUIExtensionUsage(UIExtensionUsage::CONSTRAINED_EMBEDDED);
149     SizeChangeReason reason = SizeChangeReason::SNAPSHOT_ROTATION;
150     SceneAnimationConfig config { .rsTransaction_ = rsTransaction };
151     WSError res = window_->UpdateRect(wsRect, reason, config);
152     EXPECT_EQ(res, WSError::WS_OK);
153 }
154 }
155 } // namespace Rosen
156 } // namespace OHOS