diff --git a/bundle.json b/bundle.json index d5788fee..f079a7b8 100644 --- a/bundle.json +++ b/bundle.json @@ -105,7 +105,8 @@ ], "test": [ "//foundation/windowmanager/wm:test", - "//foundation/windowmanager/dm:test" + "//foundation/windowmanager/dm:test", + "//foundation/windowmanager/extension:test" ] } } diff --git a/extension/BUILD.gn b/extension/BUILD.gn new file mode 100644 index 00000000..c4476268 --- /dev/null +++ b/extension/BUILD.gn @@ -0,0 +1,17 @@ +# Copyright (c) 2022-2022 Huawei Device Co., Ltd. +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +group("test") { + testonly = true + deps = [ "test/systemtest:systemtest" ] +} diff --git a/extension/extension_connection/src/window_extension_connection.cpp b/extension/extension_connection/src/window_extension_connection.cpp index 5173ca1b..212645c6 100644 --- a/extension/extension_connection/src/window_extension_connection.cpp +++ b/extension/extension_connection/src/window_extension_connection.cpp @@ -39,7 +39,7 @@ public: const sptr& remoteObject, int resultCode) override; void OnAbilityDisconnectDone(const AppExecFwk::ElementName& element, int resultCode) override; - void ConnectExtension(const AppExecFwk::ElementName& element, const Rect& rect, + int ConnectExtension(const AppExecFwk::ElementName& element, const Rect& rect, uint32_t uid, const sptr& callback); void DisconnectExtension(); void Show() const; @@ -96,8 +96,9 @@ void WindowExtensionConnection::Impl::WindowExtensionClientRecipient::OnRemoteDi } WLOGFI("Remote died"); } -void WindowExtensionConnection::Impl::ConnectExtension(const AppExecFwk::ElementName& element, const Rect& rect, - uint32_t uid, const sptr& callback) + +int WindowExtensionConnection::Impl::ConnectExtension(const AppExecFwk::ElementName& element, + const Rect& rect, uint32_t uid, const sptr& callback) { AAFwk::Want want; want.SetElement(element); @@ -107,13 +108,12 @@ void WindowExtensionConnection::Impl::ConnectExtension(const AppExecFwk::Element want.SetParam(RECT_FORM_KEY_WIDTH, static_cast(rect.width_)); want.SetParam(RECT_FORM_KEY_HEIGHT, static_cast(rect.height_)); - if (AAFwk::AbilityManagerClient::GetInstance()->ConnectAbility( - want, this, nullptr, 100) != ERR_OK) { // 100 default userId - WLOGFE("ConnectAbility failed!"); - return; + auto ret = AAFwk::AbilityManagerClient::GetInstance()->ConnectAbility(want, this, nullptr, 100); + if (ret == ERR_OK) { // 100 default userId + componentCallback_ = callback; } - WLOGFI("Connection extension end"); - componentCallback_ = callback; + WLOGFI("Connection extension end ret = %{public}d", ret); + return ret; } void WindowExtensionConnection::Impl::Show() const @@ -195,10 +195,10 @@ void WindowExtensionConnection::Impl::OnAbilityDisconnectDone(const AppExecFwk:: } // WindowExtensionConnection -void WindowExtensionConnection::ConnectExtension(const AppExecFwk::ElementName& element, const Rect& rect, - uint32_t uid, const sptr& callback) const +int WindowExtensionConnection::ConnectExtension(const AppExecFwk::ElementName& element, + const Rect& rect, uint32_t uid, const sptr& callback) const { - pImpl_->ConnectExtension(element, rect, uid, callback); + return pImpl_->ConnectExtension(element, rect, uid, callback); } void WindowExtensionConnection::Show() const diff --git a/extension/test/systemtest/BUILD.gn b/extension/test/systemtest/BUILD.gn new file mode 100644 index 00000000..45b75e14 --- /dev/null +++ b/extension/test/systemtest/BUILD.gn @@ -0,0 +1,61 @@ +# Copyright (c) 2022-2022 Huawei Device Co., Ltd. +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +import("//build/test.gni") + +module_out_path = "window_manager/extension" + +group("systemtest") { + testonly = true + deps = [ ":window_extension_connection_test" ] +} + +config("we_systemtest_common_public_config") { + include_dirs = [ + "//foundation/windowmanager/extension/extension_connection/include", + "//foundation/windowmanager/interfaces/innerkits/extension", + "//foundation/windowmanager/interfaces/innerkits/wm", + "//third_party/googletest/googlemock/include", + ] + + cflags = [ + "-Wall", + "-Werror", + "-g3", + "-Dprivate=public", + "-Dprotected=public", + ] +} + +## SystemTest window_extension_connection_test {{{ +ohos_systemtest("window_extension_connection_test") { + module_out_path = module_out_path + + sources = [ "extension_connection_test.cpp" ] + public_configs = [ ":we_systemtest_common_public_config" ] + + public_deps = [ + "//foundation/windowmanager/extension/extension_connection:libwindow_extension_client", + "//third_party/googletest:gmock", + "//third_party/googletest:gtest_main", + ] + + external_deps = [ + "ability_base:want", + "input:libmmi-client", + "utils_base:utils", + ] +} + +## SystemTest window_extension_connection_test }}} + diff --git a/extension/test/systemtest/extension_connection_test.cpp b/extension/test/systemtest/extension_connection_test.cpp new file mode 100644 index 00000000..c050a34f --- /dev/null +++ b/extension/test/systemtest/extension_connection_test.cpp @@ -0,0 +1,102 @@ +/* + * Copyright (c) 2022-2022 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include + +#include "window_extension_connection.h" + +using namespace testing; +using namespace testing::ext; + +namespace OHOS { +namespace Rosen { +class ExtensionCallback : public Rosen::IWindowExtensionCallback { +public: + ExtensionCallback() = default; + ~ExtensionCallback() = default; + void OnWindowReady(const std::shared_ptr& rsSurfaceNode) override; + void OnExtensionDisconnected() override; + void OnKeyEvent(const std::shared_ptr& event) override; + void OnPointerEvent(const std::shared_ptr& event) override; + void OnBackPress() override; + bool isWindowReady_ = false; +}; + +void ExtensionCallback::OnWindowReady(const std::shared_ptr& rsSurfaceNode) +{ + isWindowReady_ = true; +} + +void ExtensionCallback::OnExtensionDisconnected() +{ +} + +void ExtensionCallback::OnKeyEvent(const std::shared_ptr& event) +{ +} + +void ExtensionCallback::OnPointerEvent(const std::shared_ptr& event) +{ +} + +void ExtensionCallback::OnBackPress() +{ +} + +class ExtensionConnectionTest : public testing::Test { +public: + static void SetUpTestCase(); + static void TearDownTestCase(); + virtual void SetUp() override; + virtual void TearDown() override; +}; + +void ExtensionConnectionTest::SetUpTestCase() +{ +} + +void ExtensionConnectionTest::TearDownTestCase() +{ +} + +void ExtensionConnectionTest::SetUp() +{ +} + +void ExtensionConnectionTest::TearDown() +{ +} + +namespace { +/** + * @tc.name: WindowExtensionConnection01 + * @tc.desc: connect window extension + * @tc.type: FUNC + */ +HWTEST_F(ExtensionConnectionTest, WindowExtensionConnection01, Function | SmallTest | Level2) +{ + sptr connection = new(std::nothrow)WindowExtensionConnection(); + if (connection == nullptr) { + return; + } + AppExecFwk::ElementName element; + element.SetBundleName("com.test.windowextension"); + element.SetAbilityName("WindowExtAbility"); + Rosen::Rect rect {100, 100, 60, 60}; + ASSERT_TRUE(connection->ConnectExtension(element, rect, 100, nullptr) != ERR_OK); +} +} +} // Rosen +} // OHOS \ No newline at end of file diff --git a/interfaces/innerkits/extension/window_extension_connection.h b/interfaces/innerkits/extension/window_extension_connection.h index f33ad604..50d917bf 100644 --- a/interfaces/innerkits/extension/window_extension_connection.h +++ b/interfaces/innerkits/extension/window_extension_connection.h @@ -49,7 +49,7 @@ class WindowExtensionConnection : public RefBase { public: WindowExtensionConnection(); ~WindowExtensionConnection(); - void ConnectExtension(const AppExecFwk::ElementName& element, const Rect& rect, + int ConnectExtension(const AppExecFwk::ElementName& element, const Rect& rect, uint32_t uid, const sptr& callback) const; void DisconnectExtension() const; void Show() const;