• 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 #include <ui/rs_surface_node.h>
18 
19 #include "session/host/include/session.h"
20 #include "session/host/include/main_session.h"
21 #include "session/host/include/sub_session.h"
22 #include "session/screen/include/screen_session.h"
23 #include "window_helper.h"
24 #include "window_manager_hilog.h"
25 #include "window_property.h"
26 #include "window_session_property.h"
27 
28 using namespace testing;
29 using namespace testing::ext;
30 
31 namespace OHOS {
32 namespace Rosen {
33 class SubSessionLayoutTest : public testing::Test {
34 public:
35     static void SetUpTestCase();
36     static void TearDownTestCase();
37     void SetUp() override;
38     void TearDown() override;
39 
40 private:
41     RSSurfaceNode::SharedPtr CreateRSSurfaceNode();
42 };
43 
SetUpTestCase()44 void SubSessionLayoutTest::SetUpTestCase() {}
45 
TearDownTestCase()46 void SubSessionLayoutTest::TearDownTestCase() {}
47 
SetUp()48 void SubSessionLayoutTest::SetUp() {}
49 
TearDown()50 void SubSessionLayoutTest::TearDown() {}
51 
CreateRSSurfaceNode()52 RSSurfaceNode::SharedPtr SubSessionLayoutTest::CreateRSSurfaceNode()
53 {
54     struct RSSurfaceNodeConfig rsSurfaceNodeConfig;
55     rsSurfaceNodeConfig.SurfaceNodeName = "WindowSessionTestSurfaceNode";
56     auto surfaceNode = RSSurfaceNode::Create(rsSurfaceNodeConfig);
57     return surfaceNode;
58 }
59 
60 namespace {
61 /**
62  * @tc.name: HandleCrossSurfaceNodeByWindowAnchor
63  * @tc.desc: Check cloneNodeDuringCross when handleCrossSurfaceNodeByWindowAnchor
64  * @tc.type: FUNC
65  */
66 HWTEST_F(SubSessionLayoutTest, HandleCrossSurfaceNodeByWindowAnchor, TestSize.Level1)
67 {
68     SessionInfo info;
69     info.abilityName_ = "HandleCrossSurfaceNodeByWindowAnchor";
70     info.bundleName_ = "HandleCrossSurfaceNodeByWindowAnchor";
71     sptr<SubSession> sceneSession = sptr<SubSession>::MakeSptr(info, nullptr);
72     sceneSession->GetSessionProperty()->SetWindowType(WindowType::WINDOW_TYPE_APP_SUB_WINDOW);
73     sceneSession->HandleCrossSurfaceNodeByWindowAnchor(SizeChangeReason::UNDEFINED, nullptr);
74     ScreenSessionConfig config = {
75         .screenId = 100,
76         .rsId = 101,
77         .name = "OpenHarmony",
78     };
79     sptr<ScreenSession> screenSession =
80         sptr<ScreenSession>::MakeSptr(config, ScreenSessionReason::CREATE_SESSION_FOR_VIRTUAL);
81     sceneSession->HandleCrossSurfaceNodeByWindowAnchor(SizeChangeReason::UNDEFINED, screenSession);
82     struct RSSurfaceNodeConfig rsSurfaceNodeConfig;
83     rsSurfaceNodeConfig.SurfaceNodeName = info.abilityName_;
84     RSSurfaceNodeType rsSurfaceNodeType = RSSurfaceNodeType::DEFAULT;
85     std::shared_ptr<RSSurfaceNode> surfaceNode = RSSurfaceNode::Create(rsSurfaceNodeConfig, rsSurfaceNodeType);
86     ASSERT_NE(surfaceNode, nullptr);
87     sceneSession->SetSurfaceNode(surfaceNode);
88 
89     sceneSession->cloneNodeCountDuringCross_.store(0);
90     sceneSession->HandleCrossSurfaceNodeByWindowAnchor(SizeChangeReason::DRAG, screenSession);
91     EXPECT_EQ(1, sceneSession->cloneNodeCountDuringCross_.load());
92     sceneSession->HandleCrossSurfaceNodeByWindowAnchor(SizeChangeReason::DRAG_MOVE, screenSession);
93     EXPECT_EQ(2, sceneSession->cloneNodeCountDuringCross_.load());
94     sceneSession->HandleCrossSurfaceNodeByWindowAnchor(SizeChangeReason::DRAG_END, screenSession);
95     EXPECT_EQ(1, sceneSession->cloneNodeCountDuringCross_.load());
96     sceneSession->HandleCrossSurfaceNodeByWindowAnchor(SizeChangeReason::UNDEFINED, screenSession);
97     EXPECT_EQ(1, sceneSession->cloneNodeCountDuringCross_.load());
98 }
99 } // namespace
100 } // namespace Rosen
101 } // namespace OHOS