uiextension add tdd 0813

Signed-off-by: zhaocong <zhaocong33@h-partners.com>
This commit is contained in:
zhaocong 2024-08-13 20:52:42 +08:00
parent f82a7e79c7
commit 47c97b806b
3 changed files with 104 additions and 18 deletions

View File

@ -79,15 +79,40 @@ ohos_unittest("extension_window_extension_context_test") {
## Build window_extension_unittest_common.a {{{
config("window_extension_unittest_common_public_config") {
include_dirs = [
"../../../../interfaces/innerkits/wm",
"../../../../window_scene/session/host/include",
"../../../../wm/include",
"../../include",
"../../include/zidl",
"../../../extension_connection/include",
"../../../extension_connection/include/zidl",
"../../../../interfaces/innerkits/extension",
"${window_base_path}/test/common/mock",
"${window_base_path}/dm/include",
"${window_base_path}/dmserver/include",
"${window_base_path}/wm/include",
"${window_base_path}/wm/include/zidl",
"${window_base_path}/wm/test/mock",
"${window_base_path}/wmserver/include",
"${window_base_path}/wmserver/include/window_snapshot",
"${window_base_path}/interfaces/innerkits/wm",
"${window_base_path}/utils/include",
"${window_base_path}/window_scene",
"${window_base_path}/window_scene/test/mock",
"${window_base_path}/window_scene/session/host/include/zidl",
"//commonlibrary/c_utils/base/include",
"//foundation/communication/ipc/interfaces/innerkits/ipc_core/include",
"//base/hiviewdfx/hilog/interfaces/native/innerkits/include",
"//third_party/googletest/googlemock/include",
# for abilityContext
"${ability_runtime_path}/interfaces/kits/native/ability/ability_runtime",
"${ability_runtime_path}/interfaces/kits/native/appkit/ability_runtime/context",
"//base/global/resource_management/interfaces/inner_api/include",
"//third_party/node/deps/icu-small/source/common",
"${ability_runtime_inner_api_path}/ability_manager/include",
"//foundation/ability/ability_base/interfaces/kits/native/configuration/include/",
# abilityContext end
"${accessibility_path}/interfaces/innerkits/common/include/",
]
}
@ -102,11 +127,25 @@ ohos_static_library("window_extension_unittest_common") {
]
public_deps = [
# need delete it for abilitycontext
"${ability_runtime_inner_api_path}/ability_manager:ability_manager",
"${window_base_path}/dm:libdm",
"${window_base_path}/dmserver:libdms",
"${window_base_path}/utils:libwmutil",
"${window_base_path}/utils:libwmutil_base",
"${window_base_path}/window_scene/common:window_scene_common",
"${window_base_path}/window_scene/session:scene_session",
"${window_base_path}/window_scene/session_manager:scene_session_manager",
"${window_base_path}/wm:libwm",
"${window_base_path}/wm:libwm_lite",
"${window_base_path}/wmserver:libwms",
"//commonlibrary/c_utils/base:utils",
"//foundation/arkui/ace_engine/interfaces/inner_api/ace:ace_uicontent",
"//foundation/arkui/napi:ace_napi",
"//foundation/graphic/graphic_2d/rosen/modules/animation/window_animation:window_animation",
"//foundation/graphic/graphic_2d/rosen/modules/render_service_client:librender_service_client",
"//foundation/multimedia/image_framework/interfaces/innerkits:image_native",
"//foundation/multimodalinput/input/frameworks/proxy:libmmi-client",
"//foundation/systemabilitymgr/safwk/interfaces/innerkits/safwk:system_ability_fwk",
"//third_party/googletest:gmock",
"//third_party/googletest:gtest_main",
]
@ -120,6 +159,10 @@ ohos_static_library("window_extension_unittest_common") {
]
external_deps = [
"ability_base:configuration",
"ability_base:want",
"ability_runtime:ability_context_native",
"accessibility:accessibility_common",
"c_utils:utils",
"hilog:libhilog",
"input:libmmi-client",

View File

@ -21,6 +21,7 @@
#include "window_extension_client_interface.h"
#include "window_extension_client_stub_impl.h"
#include "mock_message_parcel.h"
#include "iremote_object_mocker.h"
using namespace testing;
using namespace testing::ext;
@ -51,6 +52,8 @@ void WindowExtensionProxyTest::SetUp()
{
mockWindowExtensionStub_ = new WindowExtensionStubImpl("name");
windowExtensionProxy_ = new WindowExtensionProxy(mockWindowExtensionStub_);
impl = new IRemoteObjectMocker();
ASSERT_NE(nullptr, impl);
impl = nullptr;
windowExtensionClientProxy_ = new WindowExtensionClientProxy(impl);
}
@ -90,6 +93,10 @@ HWTEST_F(WindowExtensionProxyTest, OnWindowReady, Function | SmallTest | Level2)
MockMessageParcel::SetWriteInterfaceTokenErrorFlag(false);
windowExtensionClientProxy_->OnWindowReady(nullptr);
struct RSSurfaceNodeConfig config;
auto surfaceNode = RSSurfaceNode::Create(config);
windowExtensionClientProxy_->OnWindowReady(surfaceNode);
}
/**
@ -102,6 +109,8 @@ HWTEST_F(WindowExtensionProxyTest, OnBackPress, Function | SmallTest | Level2)
ASSERT_NE(nullptr, windowExtensionClientProxy_);
MockMessageParcel::SetWriteInterfaceTokenErrorFlag(true);
windowExtensionClientProxy_->OnBackPress();
MockMessageParcel::SetWriteInterfaceTokenErrorFlag(false);
windowExtensionClientProxy_->OnBackPress();
}
/**
@ -116,6 +125,9 @@ HWTEST_F(WindowExtensionProxyTest, OnKeyEvent, Function | SmallTest | Level2)
ASSERT_NE(nullptr, keyEvent);
MockMessageParcel::SetWriteInterfaceTokenErrorFlag(true);
windowExtensionClientProxy_->OnKeyEvent(keyEvent);
MockMessageParcel::SetWriteInterfaceTokenErrorFlag(false);
windowExtensionClientProxy_->OnKeyEvent(keyEvent);
}
/**
@ -130,6 +142,9 @@ HWTEST_F(WindowExtensionProxyTest, OnPointerEvent, Function | SmallTest | Level2
ASSERT_NE(nullptr, pointerEvent);
MockMessageParcel::SetWriteInterfaceTokenErrorFlag(true);
windowExtensionClientProxy_->OnPointerEvent(pointerEvent);
MockMessageParcel::SetWriteInterfaceTokenErrorFlag(false);
windowExtensionClientProxy_->OnPointerEvent(pointerEvent);
}
/**

View File

@ -20,6 +20,7 @@
#include "window_extension_client_interface.h"
#include "window_extension_client_stub_impl.h"
#include "iremote_object_mocker.h"
#include "window_extension_session_impl.h"
using namespace testing;
using namespace testing::ext;
@ -85,16 +86,28 @@ HWTEST_F(WindowExtensionStubImplTest, CreateWindow, Function | SmallTest | Level
*/
HWTEST_F(WindowExtensionStubImplTest, SetBounds, Function | SmallTest | Level2)
{
WindowExtensionStubImpl windowExtensionStubImpl("WindowExtensionStubImplTest_SetBounds");
sptr<WindowOption> option = new WindowOption();
WindowExtensionStubImpl windowExtensionStubImpl("windowName");
Rect rect = { 150, 150, 400, 600 };
windowExtensionStubImpl.SetBounds(rect);
sptr<WindowOption> option = new(std::nothrow) WindowOption();
ASSERT_NE(nullptr, option);
option->SetWindowType(WindowType::WINDOW_TYPE_FLOAT);
option->SetWindowMode(WindowMode::WINDOW_MODE_FLOATING);
Rect baseWindowRect = { 150, 150, 400, 600 };
option->SetWindowRect(baseWindowRect);
sptr<Window> window = Window::Create("WindowExtensionStubImplTest_SetBounds", option, nullptr);
option->SetWindowRect(rect);
sptr<WindowExtensionSessionImpl> window = new(std::nothrow) WindowExtensionSessionImpl(option);
ASSERT_NE(nullptr, window);
windowExtensionStubImpl.SetBounds(baseWindowRect);
window->property_->SetWindowRect(rect);
windowExtensionStubImpl.window_ = window;
windowExtensionStubImpl.SetBounds(rect);
Rect rect2 = { 100, 100, 200, 300 };
windowExtensionStubImpl.SetBounds(rect2);
rect2 = { 100, 150, 200, 600 };
windowExtensionStubImpl.SetBounds(rect2);
rect2 = { 150, 100, 400, 300 };
windowExtensionStubImpl.SetBounds(rect2);
}
/**
@ -105,9 +118,14 @@ HWTEST_F(WindowExtensionStubImplTest, SetBounds, Function | SmallTest | Level2)
HWTEST_F(WindowExtensionStubImplTest, Hide, Function | SmallTest | Level2)
{
WindowExtensionStubImpl windowExtensionStubImpl("windowName");
auto window = windowExtensionStubImpl.window_.promote();
windowExtensionStubImpl.Hide();
ASSERT_EQ(windowExtensionStubImpl.window_.promote(), windowExtensionStubImpl.GetWindow());
sptr<WindowOption> option = new(std::nothrow) WindowOption();
ASSERT_NE(nullptr, option);
sptr<WindowExtensionSessionImpl> window = new(std::nothrow) WindowExtensionSessionImpl(option);
ASSERT_NE(nullptr, window);
windowExtensionStubImpl.window_ = window;
windowExtensionStubImpl.Hide();
}
/**
@ -118,9 +136,14 @@ HWTEST_F(WindowExtensionStubImplTest, Hide, Function | SmallTest | Level2)
HWTEST_F(WindowExtensionStubImplTest, Show, Function | SmallTest | Level2)
{
WindowExtensionStubImpl windowExtensionStubImpl("windowName");
auto window = windowExtensionStubImpl.window_.promote();
windowExtensionStubImpl.Show();
ASSERT_EQ(windowExtensionStubImpl.window_.promote(), windowExtensionStubImpl.GetWindow());
sptr<WindowOption> option = new(std::nothrow) WindowOption();
ASSERT_NE(nullptr, option);
sptr<WindowExtensionSessionImpl> window = new(std::nothrow) WindowExtensionSessionImpl(option);
ASSERT_NE(nullptr, window);
windowExtensionStubImpl.window_ = window;
windowExtensionStubImpl.Show();
}
/**
@ -131,9 +154,14 @@ HWTEST_F(WindowExtensionStubImplTest, Show, Function | SmallTest | Level2)
HWTEST_F(WindowExtensionStubImplTest, RequestFocus, Function | SmallTest | Level2)
{
WindowExtensionStubImpl windowExtensionStubImpl("windowName");
auto window = windowExtensionStubImpl.window_.promote();
windowExtensionStubImpl.RequestFocus();
ASSERT_EQ(windowExtensionStubImpl.window_.promote(), windowExtensionStubImpl.GetWindow());
sptr<WindowOption> option = new(std::nothrow) WindowOption();
ASSERT_NE(nullptr, option);
sptr<WindowExtensionSessionImpl> window = new(std::nothrow) WindowExtensionSessionImpl(option);
ASSERT_NE(nullptr, window);
windowExtensionStubImpl.window_ = window;
windowExtensionStubImpl.RequestFocus();
}
/**