• 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 
18 #include "window_extension_connection.h"
19 #include "wm_common.h"
20 
21 using namespace testing;
22 using namespace testing::ext;
23 
24 namespace OHOS {
25 namespace Rosen {
26 class ExtensionCallback : public Rosen::IWindowExtensionCallback {
27 public:
28     ExtensionCallback() = default;
29     ~ExtensionCallback()  = default;
30     void OnWindowReady(const std::shared_ptr<Rosen::RSSurfaceNode>& rsSurfaceNode) override;
31     void OnExtensionDisconnected() override;
32     void OnKeyEvent(const std::shared_ptr<MMI::KeyEvent>& event) override;
33     void OnPointerEvent(const std::shared_ptr<MMI::PointerEvent>& event) override;
34     void OnBackPress() override;
35     bool isWindowReady_ = false;
36 };
37 
OnWindowReady(const std::shared_ptr<Rosen::RSSurfaceNode> & rsSurfaceNode)38 void ExtensionCallback::OnWindowReady(const std::shared_ptr<Rosen::RSSurfaceNode>& rsSurfaceNode)
39 {
40     isWindowReady_ = true;
41 }
42 
OnExtensionDisconnected()43 void ExtensionCallback::OnExtensionDisconnected()
44 {
45 }
46 
OnKeyEvent(const std::shared_ptr<MMI::KeyEvent> & event)47 void ExtensionCallback::OnKeyEvent(const std::shared_ptr<MMI::KeyEvent>& event)
48 {
49 }
50 
OnPointerEvent(const std::shared_ptr<MMI::PointerEvent> & event)51 void ExtensionCallback::OnPointerEvent(const std::shared_ptr<MMI::PointerEvent>& event)
52 {
53 }
54 
OnBackPress()55 void ExtensionCallback::OnBackPress()
56 {
57 }
58 
59 class ExtensionConnectionTest : public testing::Test {
60 public:
61     static void SetUpTestCase();
62     static void TearDownTestCase();
63     virtual void SetUp() override;
64     virtual void TearDown() override;
65 };
66 
SetUpTestCase()67 void ExtensionConnectionTest::SetUpTestCase()
68 {
69 }
70 
TearDownTestCase()71 void ExtensionConnectionTest::TearDownTestCase()
72 {
73 }
74 
SetUp()75 void ExtensionConnectionTest::SetUp()
76 {
77 }
78 
TearDown()79 void ExtensionConnectionTest::TearDown()
80 {
81 }
82 
83 namespace {
84 /**
85  * @tc.name: WindowExtensionConnection01
86  * @tc.desc: connect window extension
87  * @tc.type: FUNC
88  */
89 HWTEST_F(ExtensionConnectionTest, WindowExtensionConnection01, Function | SmallTest | Level2)
90 {
91     sptr<WindowExtensionConnection> connection = new(std::nothrow)WindowExtensionConnection();
92     if (connection == nullptr) {
93         return;
94     }
95     AppExecFwk::ElementName element;
96     element.SetBundleName("com.test.windowextension");
97     element.SetAbilityName("WindowExtAbility");
98     Rosen::Rect rect {100, 100, 60, 60};
99     ASSERT_TRUE(connection->ConnectExtension(element, rect, 100, INVALID_WINDOW_ID, nullptr) != ERR_OK);
100     connection->Show();
101     connection->RequestFocus();
102     connection->SetBounds(rect);
103     connection->Hide();
104 }
105 }
106 } // Rosen
107 } // OHOS