add tdd of extension_connection

Signed-off-by: lijie176 <lijie176@huawei.com>
This commit is contained in:
lijie176 2024-07-02 16:28:59 +08:00
parent f6d7a8647e
commit 101ae245c6
2 changed files with 232 additions and 9 deletions

View File

@ -26,8 +26,12 @@ group("systemtest") {
config("we_systemtest_common_public_config") {
include_dirs = [
"../../../extension/extension_connection/include",
"../../../extension/extension_connection/include/zidl",
"../../../extension/extension_connection/src",
"../../../extension/window_extension/include/zidl",
"../../../interfaces/innerkits/extension",
"../../../interfaces/innerkits/wm",
"../../common/mock",
"//third_party/googletest/googlemock/include",
]
}
@ -81,10 +85,15 @@ ohos_systemtest("window_extension_connection_test") {
]
external_deps = [
"ability_base:session_info",
"ability_base:want",
"ability_runtime:ability_manager",
"c_utils:utils",
"graphic_2d:librender_service_client",
"hilog:libhilog",
"hitrace:hitrace_meter",
"input:libmmi-client",
"ipc:ipc_single",
]
}

View File

@ -14,15 +14,32 @@
*/
#include <gtest/gtest.h>
#include <gmock/gmock.h>
#include "window_extension_connection.h"
#include "window_extension_connection.cpp"
#include "wm_common.h"
#include "iremote_object_mocker.h"
using namespace testing;
using namespace testing::ext;
namespace OHOS {
namespace Rosen {
class MockWindowExtensionProxy : public IRemoteProxy<IWindowExtension> {
public:
explicit MockWindowExtensionProxy(const sptr<IRemoteObject>& impl)
: IRemoteProxy<IWindowExtension>(impl) {};
~MockWindowExtensionProxy() {};
MOCK_METHOD(void, SetBounds, (const Rect& rect), (override));
MOCK_METHOD(void, Hide, (), (override));
MOCK_METHOD(void, Show, (), (override));
MOCK_METHOD(void, RequestFocus, (), (override));
MOCK_METHOD(void, GetExtensionWindow, (sptr<IWindowExtensionClient>& token), (override));
};
class ExtensionCallback : public Rosen::IWindowExtensionCallback {
public:
ExtensionCallback() = default;
@ -62,6 +79,8 @@ public:
static void TearDownTestCase();
virtual void SetUp() override;
virtual void TearDown() override;
private:
sptr<WindowExtensionConnection> connection_ = nullptr;
};
void ExtensionConnectionTest::SetUpTestCase()
@ -74,10 +93,13 @@ void ExtensionConnectionTest::TearDownTestCase()
void ExtensionConnectionTest::SetUp()
{
connection_ = new(std::nothrow)WindowExtensionConnection();
ASSERT_NE(nullptr, connection_);
}
void ExtensionConnectionTest::TearDown()
{
connection_ = nullptr;
}
namespace {
@ -88,19 +110,211 @@ namespace {
*/
HWTEST_F(ExtensionConnectionTest, WindowExtensionConnection01, Function | SmallTest | Level2)
{
sptr<WindowExtensionConnection> 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, INVALID_WINDOW_ID, nullptr) != ERR_OK);
connection->Show();
connection->RequestFocus();
connection->SetBounds(rect);
connection->Hide();
ASSERT_TRUE(connection_->ConnectExtension(element, rect, 100, INVALID_WINDOW_ID, nullptr) != ERR_OK);
connection_->Show();
connection_->RequestFocus();
connection_->SetBounds(rect);
connection_->Hide();
}
/**
* @tc.name: Show
* @tc.desc: Show Test
* @tc.type: FUNC
*/
HWTEST_F(ExtensionConnectionTest, Show, Function | SmallTest | Level2)
{
sptr<IRemoteObject> remoteObject = new(std::nothrow) IRemoteObjectMocker();
ASSERT_NE(nullptr, remoteObject);
auto mockProxy = new(std::nothrow) MockWindowExtensionProxy(remoteObject);
ASSERT_NE(nullptr, mockProxy);
ASSERT_NE(nullptr, connection_->pImpl_);
connection_->pImpl_->proxy_ = mockProxy;
EXPECT_CALL(*mockProxy, Show());
connection_->Show();
}
/**
* @tc.name: Hide
* @tc.desc: Hide Test
* @tc.type: FUNC
*/
HWTEST_F(ExtensionConnectionTest, Hide, Function | SmallTest | Level2)
{
sptr<IRemoteObject> remoteObject = new(std::nothrow) IRemoteObjectMocker();
ASSERT_NE(nullptr, remoteObject);
auto mockProxy = new(std::nothrow) MockWindowExtensionProxy(remoteObject);
ASSERT_NE(nullptr, mockProxy);
ASSERT_NE(nullptr, connection_->pImpl_);
connection_->pImpl_->proxy_ = mockProxy;
EXPECT_CALL(*mockProxy, Hide());
connection_->Hide();
}
/**
* @tc.name: RequestFocus
* @tc.desc: RequestFocus Test
* @tc.type: FUNC
*/
HWTEST_F(ExtensionConnectionTest, RequestFocus, Function | SmallTest | Level2)
{
sptr<IRemoteObject> remoteObject = new(std::nothrow) IRemoteObjectMocker();
ASSERT_NE(nullptr, remoteObject);
auto mockProxy = new(std::nothrow) MockWindowExtensionProxy(remoteObject);
ASSERT_NE(nullptr, mockProxy);
ASSERT_NE(nullptr, connection_->pImpl_);
connection_->pImpl_->proxy_ = mockProxy;
EXPECT_CALL(*mockProxy, RequestFocus());
connection_->RequestFocus();
}
/**
* @tc.name: SetBounds
* @tc.desc: SetBounds Test
* @tc.type: FUNC
*/
HWTEST_F(ExtensionConnectionTest, SetBounds, Function | SmallTest | Level2)
{
sptr<IRemoteObject> remoteObject = new(std::nothrow) IRemoteObjectMocker();
ASSERT_NE(nullptr, remoteObject);
auto mockProxy = new(std::nothrow) MockWindowExtensionProxy(remoteObject);
ASSERT_NE(nullptr, mockProxy);
ASSERT_NE(nullptr, connection_->pImpl_);
connection_->pImpl_->proxy_ = mockProxy;
Rect rect;
EXPECT_CALL(*mockProxy, SetBounds(rect));
connection_->SetBounds(rect);
}
/**
* @tc.name: OnRemoteDied01
* @tc.desc: OnRemoteDied Test
* @tc.type: FUNC
*/
HWTEST_F(ExtensionConnectionTest, OnRemoteDied01, Function | SmallTest | Level2)
{
sptr<IRemoteObject> remoteObject = nullptr;
ASSERT_NE(nullptr, connection_->pImpl_);
connection_->pImpl_->deathRecipient_ =
new(std::nothrow) WindowExtensionConnection::Impl::WindowExtensionClientRecipient(nullptr);
ASSERT_NE(nullptr, connection_->pImpl_->deathRecipient_);
connection_->pImpl_->deathRecipient_->OnRemoteDied(remoteObject);
}
/**
* @tc.name: OnRemoteDied02
* @tc.desc: OnRemoteDied Test
* @tc.type: FUNC
*/
HWTEST_F(ExtensionConnectionTest, OnRemoteDied02, Function | SmallTest | Level2)
{
sptr<IRemoteObject> remoteObject = new(std::nothrow) IRemoteObjectMocker();
ASSERT_NE(nullptr, remoteObject);
ASSERT_NE(nullptr, connection_->pImpl_);
connection_->pImpl_->deathRecipient_ =
new(std::nothrow) WindowExtensionConnection::Impl::WindowExtensionClientRecipient(nullptr);
ASSERT_NE(nullptr, connection_->pImpl_->deathRecipient_);
connection_->pImpl_->deathRecipient_->OnRemoteDied(remoteObject);
}
/**
* @tc.name: OnRemoteDied03
* @tc.desc: OnRemoteDied Test
* @tc.type: FUNC
*/
HWTEST_F(ExtensionConnectionTest, OnRemoteDied03, Function | SmallTest | Level2)
{
sptr<IRemoteObject> remoteObject = new(std::nothrow) IRemoteObjectMocker();
ASSERT_NE(nullptr, remoteObject);
ASSERT_NE(nullptr, connection_->pImpl_);
connection_->pImpl_->deathRecipient_ =
new(std::nothrow) WindowExtensionConnection::Impl::WindowExtensionClientRecipient(nullptr);
ASSERT_NE(nullptr, connection_->pImpl_->deathRecipient_);
connection_->pImpl_->deathRecipient_->callback_ = new(std::nothrow) ExtensionCallback();
ASSERT_NE(nullptr, connection_->pImpl_->deathRecipient_->callback_);
connection_->pImpl_->deathRecipient_->OnRemoteDied(remoteObject);
}
/**
* @tc.name: OnAbilityConnectDone01
* @tc.desc: OnAbilityConnectDone Test
* @tc.type: FUNC
*/
HWTEST_F(ExtensionConnectionTest, OnAbilityConnectDone01, Function | SmallTest | Level2)
{
AppExecFwk::ElementName element;
sptr<IRemoteObject> remoteObject = nullptr;
int resultCode = 0;
ASSERT_NE(nullptr, connection_->pImpl_);
connection_->pImpl_->OnAbilityConnectDone(element, remoteObject, resultCode);
}
/**
* @tc.name: OnAbilityConnectDone02
* @tc.desc: OnAbilityConnectDone Test
* @tc.type: FUNC
*/
HWTEST_F(ExtensionConnectionTest, OnAbilityConnectDone02, Function | SmallTest | Level2)
{
AppExecFwk::ElementName element;
sptr<IRemoteObject> remoteObject = new(std::nothrow) IRemoteObjectMocker();
ASSERT_NE(nullptr, remoteObject);
int resultCode = 0;
ASSERT_NE(nullptr, connection_->pImpl_);
connection_->pImpl_->OnAbilityConnectDone(element, remoteObject, resultCode);
}
/**
* @tc.name: OnAbilityConnectDone03
* @tc.desc: OnAbilityConnectDone Test
* @tc.type: FUNC
*/
HWTEST_F(ExtensionConnectionTest, OnAbilityConnectDone03, Function | SmallTest | Level2)
{
AppExecFwk::ElementName element;
sptr<IRemoteObject> remoteObject = new(std::nothrow) IRemoteObjectMocker();
ASSERT_NE(nullptr, remoteObject);
auto mockProxy = new(std::nothrow) MockWindowExtensionProxy(remoteObject);
ASSERT_NE(nullptr, mockProxy);
ASSERT_NE(nullptr, connection_->pImpl_);
connection_->pImpl_->deathRecipient_ =
new(std::nothrow) WindowExtensionConnection::Impl::WindowExtensionClientRecipient(nullptr);
ASSERT_NE(nullptr, connection_->pImpl_->deathRecipient_);
connection_->pImpl_->proxy_ = mockProxy;
int resultCode = 0;
connection_->pImpl_->OnAbilityConnectDone(element, remoteObject, resultCode);
}
/**
* @tc.name: OnAbilityDisconnectDone01
* @tc.desc: OnAbilityConnectDone Test
* @tc.type: FUNC
*/
HWTEST_F(ExtensionConnectionTest, OnAbilityDisconnectDone01, Function | SmallTest | Level2)
{
AppExecFwk::ElementName element;
int resultCode = 0;
ASSERT_NE(nullptr, connection_->pImpl_);
connection_->pImpl_->OnAbilityDisconnectDone(element, resultCode);
}
/**
* @tc.name: OnAbilityDisconnectDone02
* @tc.desc: OnAbilityConnectDone Test
* @tc.type: FUNC
*/
HWTEST_F(ExtensionConnectionTest, OnAbilityDisconnectDone02, Function | SmallTest | Level2)
{
AppExecFwk::ElementName element;
int resultCode = 0;
ASSERT_NE(nullptr, connection_->pImpl_);
connection_->pImpl_->componentCallback_ = new(std::nothrow) ExtensionCallback();
ASSERT_NE(nullptr, connection_->pImpl_->componentCallback_);
connection_->pImpl_->OnAbilityDisconnectDone(element, resultCode);
}
}
} // Rosen