Merge branch 'master' of gitee.com:openharmony/windowmanager

Change-Id: I07ab471efda8ec57f16f338d5bcecf82efa11af7
Signed-off-by: xingyanan <xingyanan2@huawei.com>
This commit is contained in:
xingyanan
2022-01-13 21:25:47 +08:00
67 changed files with 3108 additions and 432 deletions
+2
View File
@@ -24,6 +24,7 @@
"//foundation/windowmanager/wm:libwm",
"//foundation/windowmanager/wmserver:libwms",
"//foundation/windowmanager/wm:libwmutil",
"//foundation/windowmanager/snapshot:snapshot_display",
"//foundation/windowmanager/interfaces/kits/napi:windowstage",
"//foundation/windowmanager/interfaces/kits/napi:napi_packages"
],
@@ -61,6 +62,7 @@
}
],
"test": [
"//foundation/windowmanager/wm:test"
]
}
}
-6
View File
@@ -45,11 +45,6 @@ public:
virtual void OnSizeChange(Rect rect) = 0;
};
class IWindowSystemBarChangeListener : public RefBase {
public:
virtual void OnSystemBarPropertyChange(uint32_t displayId, WindowType type, const SystemBarProperty& prop) = 0;
};
class Window : public RefBase {
public:
static sptr<Window> Create(const std::string& windowName,
@@ -89,7 +84,6 @@ public:
virtual void RegisterLifeCycleListener(sptr<IWindowLifeCycle>& listener) = 0;
virtual void RegisterWindowChangeListener(sptr<IWindowChangeListener>& listener) = 0;
virtual void RegisterWindowSystemBarChangeListener(sptr<IWindowSystemBarChangeListener>& listener) = 0;
virtual WMError SetUIContent(std::shared_ptr<AbilityRuntime::AbilityContext> context,
std::string& contentInfo, NativeEngine* engine, NativeValue* storage, bool isdistributed = false) = 0;
virtual const std::string& GetContentInfo() = 0;
+8
View File
@@ -34,12 +34,19 @@ public:
WindowType windowType, int32_t displayId) = 0;
};
class ISystemBarChangedListener : public RefBase {
public:
virtual void OnSystemBarPropertyChange(uint64_t displayId, const SystemBarProps& props) = 0;
};
class WindowManager : public RefBase {
WM_DECLARE_SINGLE_INSTANCE_BASE(WindowManager);
friend class WindowManagerAgent;
public:
void RegisterFocusChangedListener(const sptr<IFocusChangedListener>& listener);
void UnregisterFocusChangedListener(const sptr<IFocusChangedListener>& listener);
void RegisterSystemBarChangedListener(const sptr<ISystemBarChangedListener>& listener);
void UnregisterSystemBarChangedListener(const sptr<ISystemBarChangedListener>& listener);
private:
WindowManager();
@@ -49,6 +56,7 @@ private:
void UpdateFocusStatus(uint32_t windowId, const sptr<IRemoteObject>& abilityToken, WindowType windowType,
int32_t displayId, bool focused) const;
void UpdateSystemBarProperties(uint64_t displayId, const SystemBarProps& props) const;
};
} // namespace Rosen
} // namespace OHOS
+8 -6
View File
@@ -93,6 +93,13 @@ enum class WindowFlag : uint32_t {
WINDOW_FLAG_END = 1 << 2,
};
struct Rect {
int32_t posX_;
int32_t posY_;
uint32_t width_;
uint32_t height_;
};
namespace {
constexpr uint32_t SYSTEM_COLOR_WHITE = 0xE5FFFFFF;
constexpr uint32_t SYSTEM_COLOR_BLACK = 0x66000000;
@@ -111,12 +118,7 @@ struct SystemBarProperty {
}
};
struct Rect {
int32_t posX_;
int32_t posY_;
uint32_t width_;
uint32_t height_;
};
using SystemBarProps = std::vector<std::pair<WindowType, SystemBarProperty>>;
}
}
#endif // OHOS_ROSEN_WM_COMMON_H
+45
View File
@@ -0,0 +1,45 @@
# Copyright (c) 2021 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/ohos.gni")
## Build snapshot {{{
config("snapshot_config") {
visibility = [ ":*" ]
}
ohos_executable("snapshot_display") {
install_enable = false
sources = [
"snapshot_display.cpp",
"snapshot_utils.cpp",
]
configs = [ ":snapshot_config" ]
deps = [
"//foundation/multimedia/image_standard/interfaces/innerkits:image_native", # PixelMap
"//foundation/windowmanager/dm:libdm",
"//foundation/windowmanager/wm:libwm",
"//third_party/libpng:libpng", # png
]
part_name = "window_manager"
subsystem_name = "window"
}
## Build snapshot }}}
group("test") {
testonly = true
}
+48
View File
@@ -0,0 +1,48 @@
/*
* Copyright (c) 2021 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 <cstdio>
#include "snapshot_utils.h"
using namespace OHOS;
using namespace OHOS::Media;
using namespace OHOS::Rosen;
int main(int argc, char *argv[])
{
CmdArgments cmdArgments;
cmdArgments.fileName = "/data/snapshot_display_1.png";
if (!SnapShotUtils::ProcessArgs(argc, argv, cmdArgments)) {
return 0;
}
// get PixelMap from DisplayManager API
auto pixelMap = DisplayManager::GetInstance().GetScreenshot(cmdArgments.displayId);
bool ret = false;
if (pixelMap != nullptr) {
ret = SnapShotUtils::WriteToPngWithPixelMap(cmdArgments.fileName, *pixelMap);
}
if (!ret) {
printf("error: snapshot display %" PRIu64 ", write to %s as png failed!\n",
cmdArgments.displayId, cmdArgments.fileName.c_str());
return -1;
}
printf("success: snapshot display %" PRIu64 ", write to %s as png\n",
cmdArgments.displayId, cmdArgments.fileName.c_str());
return 0;
}
+178
View File
@@ -0,0 +1,178 @@
/*
* Copyright (c) 2021 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 "snapshot_utils.h"
#include <cstdio>
#include <getopt.h>
#include <png.h>
using namespace OHOS::Media;
using namespace OHOS::Rosen;
namespace OHOS {
constexpr int BITMAP_DEPTH = 8;
void SnapShotUtils::PrintUsage(const std::string &cmdLine)
{
printf("usage: %s [-i displayId] [-f output_file]\n", cmdLine.c_str());
}
bool SnapShotUtils::CheckFileNameValid(const std::string &fileName)
{
std::string fileDir = fileName;
auto pos = fileDir.find_last_of("/");
if (pos != std::string::npos) {
fileDir.erase(pos + 1);
} else {
fileDir = ".";
}
char resolvedPath[PATH_MAX] = { 0 };
char *realPath = realpath(fileDir.c_str(), resolvedPath);
if (realPath == nullptr) {
printf("error: fileName %s invalid, nullptr!\n", fileName.c_str());
return false;
}
std::string realPathString = realPath;
if (realPathString.find("/data") != 0) {
printf("error: fileName %s invalid, %s must dump at dir: /data \n", fileName.c_str(), realPathString.c_str());
return false;
}
return true;
}
bool SnapShotUtils::WriteToPng(const std::string &fileName, const WriteToPngParam &param)
{
if (!CheckFileNameValid(fileName)) {
return false;
}
png_structp pngStruct = png_create_write_struct(PNG_LIBPNG_VER_STRING, nullptr, nullptr, nullptr);
if (pngStruct == nullptr) {
printf("error: png_create_write_struct nullptr!\n");
return false;
}
png_infop pngInfo = png_create_info_struct(pngStruct);
if (pngInfo == nullptr) {
printf("error: png_create_info_struct error nullptr!\n");
png_destroy_write_struct(&pngStruct, nullptr);
return false;
}
FILE *fp = fopen(fileName.c_str(), "wb");
if (fp == nullptr) {
printf("error: open file [%s] error, %d [%s]!\n", fileName.c_str(), errno, strerror(errno));
png_destroy_write_struct(&pngStruct, &pngInfo);
return false;
}
png_init_io(pngStruct, fp);
// set png header
png_set_IHDR(pngStruct, pngInfo,
param.width, param.height,
param.bitDepth,
PNG_COLOR_TYPE_RGBA,
PNG_INTERLACE_NONE,
PNG_COMPRESSION_TYPE_BASE,
PNG_FILTER_TYPE_BASE);
png_set_packing(pngStruct); // set packing info
png_write_info(pngStruct, pngInfo); // write to header
for (uint32_t i = 0; i < param.height; i++) {
png_write_row(pngStruct, param.data + (i * param.stride));
}
png_write_end(pngStruct, pngInfo);
// free
png_destroy_write_struct(&pngStruct, &pngInfo);
if (fclose(fp) != 0) {
return false;
}
return true;
}
bool SnapShotUtils::WriteToPngWithPixelMap(const std::string &fileName, PixelMap &pixelMap)
{
WriteToPngParam param;
param.width = pixelMap.GetWidth();
param.height = pixelMap.GetHeight();
param.data = pixelMap.GetPixels();
param.stride = pixelMap.GetRowBytes();
param.bitDepth = BITMAP_DEPTH;
return SnapShotUtils::WriteToPng(fileName, param);
}
static bool ProcessDisplayId(DisplayId &displayId)
{
if (displayId == DISPLAY_ID_INVALD) {
displayId = DisplayManager::GetInstance().GetDefaultDisplayId();
} else {
bool validFlag = false;
auto displayIds = DisplayManager::GetInstance().GetAllDisplayIds();
for (auto id: displayIds) {
if (displayId == id) {
validFlag = true;
break;
}
}
if (!validFlag) {
printf("error: displayId %" PRIu64 " invalid!\n", displayId);
printf("tips: supported displayIds:\n");
for (auto id: displayIds) {
printf("\t%" PRIu64 "\n", id);
}
return false;
}
}
return true;
}
bool SnapShotUtils::ProcessArgs(int argc, char * const argv[], CmdArgments &cmdArgments)
{
int opt = 0;
const struct option longOption[] = {
{ "id", required_argument, nullptr, 'i' },
{ "file", required_argument, nullptr, 'f' },
{ "help", required_argument, nullptr, 'h' },
{ nullptr, 0, nullptr, 0 }
};
while ((opt = getopt_long(argc, argv, "i:f:h", longOption, nullptr)) != -1) {
switch (opt) {
case 'i': // display id
cmdArgments.displayId = atoll(optarg);
break;
case 'f': // output file name
cmdArgments.fileName = optarg;
break;
case 'h': // help
SnapShotUtils::PrintUsage(argv[0]);
return false;
default:
SnapShotUtils::PrintUsage(argv[0]);
return false;
}
}
if (!ProcessDisplayId(cmdArgments.displayId)) {
return false;
}
// check fileName
if (!SnapShotUtils::CheckFileNameValid(cmdArgments.fileName)) {
printf("error: filename %s invalid!\n", cmdArgments.fileName.c_str());
return false;
}
return true;
}
}
+53
View File
@@ -0,0 +1,53 @@
/*
* Copyright (c) 2021 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.
*/
#ifndef SNAPSHOT_UTILS_H
#define SNAPSHOT_UTILS_H
#include <cstdint>
#include <string>
#include <pixel_map.h>
#include "display_manager.h"
namespace OHOS {
using WriteToPngParam = struct {
uint32_t width;
uint32_t height;
uint32_t stride;
uint32_t bitDepth;
const uint8_t *data;
};
using CmdArgments = struct {
Rosen::DisplayId displayId = Rosen::DISPLAY_ID_INVALD;
std::string fileName;
};
class SnapShotUtils {
public:
SnapShotUtils() = default;
~SnapShotUtils() = default;
static void PrintUsage(const std::string &cmdLine);
static bool CheckFileNameValid(const std::string &fileName);
static bool WriteToPng(const std::string &fileName, const WriteToPngParam &param);
static bool WriteToPngWithPixelMap(const std::string &fileName, Media::PixelMap &pixelMap);
static bool ProcessArgs(int argc, char * const argv[], CmdArgments& cmdArgments);
private:
};
}
#endif // SNAPSHOT_UTILS_H
+5
View File
@@ -177,3 +177,8 @@ ohos_shared_library("libwm") {
part_name = "window_manager"
subsystem_name = "window"
}
group("test") {
testonly = true
deps = [ "test:test" ]
}
+4 -2
View File
@@ -49,8 +49,10 @@ public:
virtual WMError SetWindowMode(uint32_t windowId, WindowMode mode);
virtual WMError MinimizeAllAppNodeAbility(uint32_t windowId);
virtual void RegisterFocusChangedListener(const sptr<IWindowManagerAgent>& windowManagerAgent);
virtual void UnregisterFocusChangedListener(const sptr<IWindowManagerAgent>& windowManagerAgent);
virtual void RegisterWindowManagerAgent(WindowManagerAgentType type,
const sptr<IWindowManagerAgent>& windowManagerAgent);
virtual void UnregisterWindowManagerAgent(WindowManagerAgentType type,
const sptr<IWindowManagerAgent>& windowManagerAgent);
virtual void ClearWindowAdapter();
private:
-1
View File
@@ -30,7 +30,6 @@ public:
void UpdateWindowRect(const struct Rect& rect) override;
void UpdateWindowMode(WindowMode mode) override;
void UpdateFocusStatus(bool focused) override;
void UpdateSystemBarProperty(const SystemBarProperty& prop) override;
private:
sptr<WindowImpl> window_;
-3
View File
@@ -71,7 +71,6 @@ public:
virtual void RegisterLifeCycleListener(sptr<IWindowLifeCycle>& listener) override;
virtual void RegisterWindowChangeListener(sptr<IWindowChangeListener>& listener) override;
virtual void RegisterWindowSystemBarChangeListener(sptr<IWindowSystemBarChangeListener>& listener) override;
void UpdateRect(const struct Rect& rect);
void UpdateMode(WindowMode mode);
@@ -79,7 +78,6 @@ public:
virtual void ConsumePointerEvent(std::shared_ptr<MMI::PointerEvent>& inputEvent) override;
virtual void RequestFrame() override;
void UpdateFocusStatus(bool focused);
void UpdateSystemBarProperty(const SystemBarProperty& prop);
virtual void UpdateConfiguration(const std::shared_ptr<AppExecFwk::Configuration>& configuration) override;
virtual WMError SetUIContent(std::shared_ptr<AbilityRuntime::AbilityContext> context,
@@ -130,7 +128,6 @@ private:
WindowState state_ { STATE_INITIAL };
sptr<IWindowLifeCycle> lifecycleListener_;
sptr<IWindowChangeListener> windowChangeListener_;
sptr<IWindowSystemBarChangeListener> systemBarChangeListener_;
std::shared_ptr<RSSurfaceNode> surfaceNode_;
std::string name_;
std::unique_ptr<Ace::UIContent> uiContent_;
-2
View File
@@ -30,14 +30,12 @@ public:
TRANS_ID_UPDATE_WINDOW_RECT,
TRANS_ID_UPDATE_WINDOW_MODE,
TRANS_ID_UPDATE_FOCUS_STATUS,
TRANS_ID_UPDATE_SYSTEM_BAR_PROPERTY,
};
virtual void UpdateWindowProperty(const WindowProperty& windowProperty) = 0;
virtual void UpdateWindowRect(const struct Rect& rect) = 0;
virtual void UpdateWindowMode(WindowMode mode) = 0;
virtual void UpdateFocusStatus(bool focused) = 0;
virtual void UpdateSystemBarProperty(const SystemBarProperty& prop) = 0;
};
} // namespace Rosen
} // namespace OHOS
+1
View File
@@ -27,6 +27,7 @@ public:
void UpdateFocusStatus(uint32_t windowId, const sptr<IRemoteObject>& abilityToken, WindowType windowType,
int32_t displayId, bool focused) override;
void UpdateSystemBarProperties(uint64_t displayId, const SystemBarProps& props) override;
};
} // namespace Rosen
} // namespace OHOS
-1
View File
@@ -31,7 +31,6 @@ public:
void UpdateWindowRect(const struct Rect& rect) override;
void UpdateWindowMode(WindowMode mode) override;
void UpdateFocusStatus(bool focused) override;
void UpdateSystemBarProperty(const SystemBarProperty& prop) override;
private:
static inline BrokerDelegator<WindowProxy> delegator_;
@@ -21,16 +21,23 @@
namespace OHOS {
namespace Rosen {
enum class WindowManagerAgentType : uint32_t {
WINDOW_MANAGER_AGENT_TYPE_FOCUS,
WINDOW_MANAGER_AGENT_TYPE_SYSTEM_BAR,
};
class IWindowManagerAgent : public IRemoteBroker {
public:
DECLARE_INTERFACE_DESCRIPTOR(u"OHOS.IWindowManagerAgent");
enum {
TRANS_ID_UPDATE_FOCUS_STATUS = 1,
TRANS_ID_UPDATE_SYSTEM_BAR_PROPS = 2,
};
virtual void UpdateFocusStatus(uint32_t windowId, const sptr<IRemoteObject>& abilityToken, WindowType windowType,
int32_t displayId, bool focused) = 0;
virtual void UpdateSystemBarProperties(uint64_t displayId, const SystemBarProps& props) = 0;
};
} // namespace Rosen
} // namespace OHOS
@@ -29,6 +29,7 @@ public:
void UpdateFocusStatus(uint32_t windowId, const sptr<IRemoteObject>& abilityToken, WindowType windowType,
int32_t displayId, bool focused) override;
void UpdateSystemBarProperties(uint64_t displayId, const SystemBarProps& props) override;
private:
static inline BrokerDelegator<WindowManagerAgentProxy> delegator_;
+6 -4
View File
@@ -126,24 +126,26 @@ WMError WindowAdapter::SetSystemBarProperty(uint32_t windowId, WindowType type,
return windowManagerServiceProxy_->SetSystemBarProperty(windowId, type, property);
}
void WindowAdapter::RegisterFocusChangedListener(const sptr<IWindowManagerAgent>& windowManagerAgent)
void WindowAdapter::RegisterWindowManagerAgent(WindowManagerAgentType type,
const sptr<IWindowManagerAgent>& windowManagerAgent)
{
std::lock_guard<std::mutex> lock(mutex_);
if (!InitWMSProxyLocked()) {
return;
}
return windowManagerServiceProxy_->RegisterFocusChangedListener(windowManagerAgent);
return windowManagerServiceProxy_->RegisterWindowManagerAgent(type, windowManagerAgent);
}
void WindowAdapter::UnregisterFocusChangedListener(const sptr<IWindowManagerAgent>& windowManagerAgent)
void WindowAdapter::UnregisterWindowManagerAgent(WindowManagerAgentType type,
const sptr<IWindowManagerAgent>& windowManagerAgent)
{
std::lock_guard<std::mutex> lock(mutex_);
if (!InitWMSProxyLocked()) {
return;
}
return windowManagerServiceProxy_->UnregisterFocusChangedListener(windowManagerAgent);
return windowManagerServiceProxy_->UnregisterWindowManagerAgent(type, windowManagerAgent);
}
WMError WindowAdapter::SetWindowMode(uint32_t windowId, WindowMode mode)
-9
View File
@@ -57,14 +57,5 @@ void WindowAgent::UpdateFocusStatus(bool focused)
}
window_->UpdateFocusStatus(focused);
}
void WindowAgent::UpdateSystemBarProperty(const SystemBarProperty& prop)
{
if (window_ == nullptr) {
WLOGFE("window_ is nullptr");
return;
}
window_->UpdateSystemBarProperty(prop);
}
} // namespace Rosen
} // namespace OHOS
-14
View File
@@ -468,10 +468,6 @@ void WindowImpl::RegisterWindowChangeListener(sptr<IWindowChangeListener>& liste
windowChangeListener_ = listener;
}
void WindowImpl::RegisterWindowSystemBarChangeListener(sptr<IWindowSystemBarChangeListener>& listener)
{
systemBarChangeListener_ = listener;
}
void WindowImpl::UpdateRect(const struct Rect& rect)
{
WLOGFI("winId:%{public}d, rect[%{public}d, %{public}d, %{public}d, %{public}d]", GetWindowId(), rect.posX_,
@@ -552,16 +548,6 @@ void WindowImpl::UpdateFocusStatus(bool focused)
}
}
void WindowImpl::UpdateSystemBarProperty(const SystemBarProperty& prop)
{
WLOGFI("winId:%{public}d, enable:%{public}d, backgroundColor:%{public}x, contentColor:%{public}x", GetWindowId(),
prop.enable_, prop.backgroundColor_, prop.contentColor_);
if (systemBarChangeListener_ != nullptr) {
systemBarChangeListener_->OnSystemBarPropertyChange(property_->GetDisplayId(),
property_->GetWindowType(), prop);
}
}
void WindowImpl::UpdateConfiguration(const std::shared_ptr<AppExecFwk::Configuration>& configuration)
{
if (uiContent_ != nullptr) {
+62 -3
View File
@@ -32,12 +32,14 @@ public:
WindowType windowType, int32_t displayId) const;
void NotifyUnfocused(uint32_t windowId, const sptr<IRemoteObject>& abilityToken,
WindowType windowType, int32_t displayId) const;
void NotifySystemBarChanged(uint64_t displayId, const SystemBarProps& props) const;
static inline SingletonDelegator<WindowManager> delegator_;
std::mutex mutex_;
std::vector<sptr<IFocusChangedListener>> focusChangedListeners_;
sptr<WindowManagerAgent> focusChangedListenerAgent_;
std::vector<sptr<ISystemBarChangedListener>> systemBarChangedListeners_;
sptr<WindowManagerAgent> systemBarChangedListenerAgent_;
};
void WindowManager::Impl::NotifyFocused(uint32_t windowId, const sptr<IRemoteObject>& abilityToken,
@@ -60,6 +62,18 @@ void WindowManager::Impl::NotifyUnfocused(uint32_t windowId, const sptr<IRemoteO
}
}
void WindowManager::Impl::NotifySystemBarChanged(uint64_t displayId, const SystemBarProps& props) const
{
for (auto prop : props) {
WLOGFI("type:%{public}d, enable:%{public}d," \
"backgroundColor:%{public}x, contentColor:%{public}x",
prop.first, prop.second.enable_, prop.second.backgroundColor_, prop.second.contentColor_);
}
for (auto& listener : systemBarChangedListeners_) {
listener->OnSystemBarPropertyChange(displayId, props);
}
}
WindowManager::WindowManager() : pImpl_(std::make_unique<Impl>())
{
}
@@ -79,7 +93,8 @@ void WindowManager::RegisterFocusChangedListener(const sptr<IFocusChangedListene
pImpl_->focusChangedListeners_.push_back(listener);
if (pImpl_->focusChangedListenerAgent_ == nullptr) {
pImpl_->focusChangedListenerAgent_ = new WindowManagerAgent();
SingletonContainer::Get<WindowAdapter>().RegisterFocusChangedListener(pImpl_->focusChangedListenerAgent_);
SingletonContainer::Get<WindowAdapter>().RegisterWindowManagerAgent(
WindowManagerAgentType::WINDOW_MANAGER_AGENT_TYPE_FOCUS, pImpl_->focusChangedListenerAgent_);
}
}
@@ -98,7 +113,45 @@ void WindowManager::UnregisterFocusChangedListener(const sptr<IFocusChangedListe
}
pImpl_->focusChangedListeners_.erase(iter);
if (pImpl_->focusChangedListeners_.empty() && pImpl_->focusChangedListenerAgent_ != nullptr) {
SingletonContainer::Get<WindowAdapter>().UnregisterFocusChangedListener(pImpl_->focusChangedListenerAgent_);
SingletonContainer::Get<WindowAdapter>().UnregisterWindowManagerAgent(
WindowManagerAgentType::WINDOW_MANAGER_AGENT_TYPE_FOCUS, pImpl_->focusChangedListenerAgent_);
}
}
void WindowManager::RegisterSystemBarChangedListener(const sptr<ISystemBarChangedListener>& listener)
{
if (listener == nullptr) {
WLOGFE("listener could not be null");
return;
}
std::lock_guard<std::mutex> lock(pImpl_->mutex_);
pImpl_->systemBarChangedListeners_.push_back(listener);
if (pImpl_->systemBarChangedListenerAgent_ == nullptr) {
pImpl_->systemBarChangedListenerAgent_ = new WindowManagerAgent();
SingletonContainer::Get<WindowAdapter>().RegisterWindowManagerAgent(
WindowManagerAgentType::WINDOW_MANAGER_AGENT_TYPE_SYSTEM_BAR, pImpl_->systemBarChangedListenerAgent_);
}
}
void WindowManager::UnregisterSystemBarChangedListener(const sptr<ISystemBarChangedListener>& listener)
{
if (listener == nullptr) {
WLOGFE("listener could not be null");
return;
}
std::lock_guard<std::mutex> lock(pImpl_->mutex_);
auto iter = std::find(pImpl_->systemBarChangedListeners_.begin(), pImpl_->systemBarChangedListeners_.end(),
listener);
if (iter == pImpl_->systemBarChangedListeners_.end()) {
WLOGFE("could not find this listener");
return;
}
pImpl_->systemBarChangedListeners_.erase(iter);
if (pImpl_->systemBarChangedListeners_.empty() && pImpl_->systemBarChangedListenerAgent_ != nullptr) {
SingletonContainer::Get<WindowAdapter>().UnregisterWindowManagerAgent(
WindowManagerAgentType::WINDOW_MANAGER_AGENT_TYPE_SYSTEM_BAR, pImpl_->systemBarChangedListenerAgent_);
}
}
@@ -112,5 +165,11 @@ void WindowManager::UpdateFocusStatus(uint32_t windowId, const sptr<IRemoteObjec
pImpl_->NotifyUnfocused(windowId, abilityToken, windowType, displayId);
}
}
void WindowManager::UpdateSystemBarProperties(uint64_t displayId,
const SystemBarProps& props) const
{
pImpl_->NotifySystemBarChanged(displayId, props);
}
} // namespace Rosen
} // namespace OHOS
+5
View File
@@ -24,5 +24,10 @@ void WindowManagerAgent::UpdateFocusStatus(uint32_t windowId, const sptr<IRemote
{
SingletonContainer::Get<WindowManager>().UpdateFocusStatus(windowId, abilityToken, windowType, displayId, focused);
}
void WindowManagerAgent::UpdateSystemBarProperties(uint64_t displayId, const SystemBarProps& props)
{
SingletonContainer::Get<WindowManager>().UpdateSystemBarProperties(displayId, props);
}
} // namespace Rosen
} // namespace OHOS
+1 -1
View File
@@ -182,7 +182,7 @@ bool WindowProperty::MapMarshalling(Parcel& parcel) const
if (!parcel.WriteUint32(static_cast<uint32_t>(it.first))) {
return false;
}
// write val(UIState)
// write val(sysBarProps)
if (!(parcel.WriteBool(it.second.enable_) && parcel.WriteUint32(it.second.backgroundColor_) &&
parcel.WriteUint32(it.second.contentColor_))) {
return false;
-20
View File
@@ -53,26 +53,6 @@ void WindowProxy::UpdateWindowRect(const struct Rect& rect)
return;
}
void WindowProxy::UpdateSystemBarProperty(const SystemBarProperty& prop)
{
MessageParcel data;
MessageParcel reply;
MessageOption option;
if (!data.WriteInterfaceToken(GetDescriptor())) {
WLOGFE("WriteInterfaceToken failed");
return;
}
if (!(data.WriteBool(prop.enable_) && data.WriteUint32(prop.backgroundColor_) &&
data.WriteUint32(prop.contentColor_))) {
WLOGFE("Write property failed");
return;
}
if (Remote()->SendRequest(TRANS_ID_UPDATE_SYSTEM_BAR_PROPERTY, data, reply, option) != ERR_NONE) {
WLOGFE("SendRequest failed");
}
return;
}
void WindowProxy::UpdateWindowMode(WindowMode mode)
{
MessageParcel data;
-5
View File
@@ -49,11 +49,6 @@ int WindowStub::OnRemoteRequest(uint32_t code, MessageParcel &data, MessageParce
UpdateFocusStatus(focused);
break;
}
case TRANS_ID_UPDATE_SYSTEM_BAR_PROPERTY: {
SystemBarProperty property = { data.ReadBool(), data.ReadUint32(), data.ReadUint32() };
UpdateSystemBarProperty(property);
break;
}
default:
break;
}
@@ -62,6 +62,44 @@ void WindowManagerAgentProxy::UpdateFocusStatus(uint32_t windowId, const sptr<IR
WLOGFE("SendRequest failed");
}
}
void WindowManagerAgentProxy::UpdateSystemBarProperties(uint64_t displayId, const SystemBarProps& props)
{
MessageParcel data;
MessageParcel reply;
MessageOption option(MessageOption::TF_ASYNC);
if (!data.WriteInterfaceToken(GetDescriptor())) {
WLOGFE("WriteInterfaceToken failed");
return;
}
if (!data.WriteUint64(displayId)) {
WLOGFE("Write displayId failed");
return;
}
auto size = props.size();
if (!data.WriteUint32(static_cast<uint32_t>(size))) {
WLOGFE("Write vector size failed");
return;
}
for (auto it : props) {
// write key(type)
if (!data.WriteUint32(static_cast<uint32_t>(it.first))) {
WLOGFE("Write type failed");
return;
}
// write val(sysBarProps)
if (!(data.WriteBool(it.second.enable_) && data.WriteUint32(it.second.backgroundColor_) &&
data.WriteUint32(it.second.contentColor_))) {
WLOGFE("Write sysBarProp failed");
return;
}
}
if (Remote()->SendRequest(TRANS_ID_UPDATE_SYSTEM_BAR_PROPS, data, reply, option) != ERR_NONE) {
WLOGFE("SendRequest failed");
}
}
} // namespace Rosen
} // namespace OHOS
+13
View File
@@ -42,6 +42,19 @@ int WindowManagerAgentStub::OnRemoteRequest(uint32_t code, MessageParcel& data,
UpdateFocusStatus(windowId, abilityToken, windowType, displayId, focused);
break;
}
case TRANS_ID_UPDATE_SYSTEM_BAR_PROPS: {
uint64_t displayId = data.ReadUint64();
SystemBarProps props;
uint32_t size = data.ReadUint32();
for (uint32_t i = 0; i < size; i++) {
WindowType type = static_cast<WindowType>(data.ReadUint32());
SystemBarProperty prop = { data.ReadBool(), data.ReadUint32(), data.ReadUint32() };
std::pair<WindowType, SystemBarProperty> item = { type, prop };
props.emplace_back(item);
}
UpdateSystemBarProperties(displayId, props);
break;
}
default:
break;
}
+20
View File
@@ -0,0 +1,20 @@
# Copyright (c) 2021 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 = [
"systemtest:systemtest",
"unittest:unittest",
]
}
+117
View File
@@ -0,0 +1,117 @@
# Copyright (c) 2021 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/wm"
group("systemtest") {
testonly = true
deps = [
":wm_window_layout_test",
":wm_window_multi_ability_test",
":wm_window_subwindow_test",
]
}
## SystemTest wm_window_layout_test {{{
ohos_systemtest("wm_window_layout_test") {
module_out_path = module_out_path
sources = [ "window_layout_test.cpp" ]
deps = [ ":wm_systemtest_common" ]
}
## SystemTest wm_window_layout_test }}}
## SystemTest wm_window_multi_ability_test {{{
ohos_systemtest("wm_window_multi_ability_test") {
module_out_path = module_out_path
sources = [ "window_multi_ability_test.cpp" ]
deps = [ ":wm_systemtest_common" ]
}
## SystemTest wm_window_multi_ability_test }}}
## SystemTest wm_window_subwindow_test {{{
ohos_systemtest("wm_window_subwindow_test") {
module_out_path = module_out_path
sources = [ "window_subwindow_test.cpp" ]
deps = [ ":wm_systemtest_common" ]
}
## SystemTest wm_window_subwindow_test }}}
## Build wm_systemtest_common.a {{{
config("wm_systemtest_common_public_config") {
include_dirs = [
"//foundation/windowmanager/wm/include",
"//foundation/windowmanager/wmserver/include",
"//foundation/windowmanager/interfaces/innerkits/wm",
"//foundation/windowmanager/utils/include",
"//utils/native/base/include",
"//foundation/communication/ipc/interfaces/innerkits/ipc_core/include",
"//base/hiviewdfx/hilog/interfaces/native/innerkits/include",
"//third_party/googletest/googlemock/include",
# for abilityContext
"//foundation/aafwk/standard/frameworks/kits/ability/ability_runtime/include",
"//foundation/appexecfwk/standard/interfaces/innerkits/appexecfwk_base/include",
"//foundation/appexecfwk/standard/kits/appkit/native/ability_runtime/context",
"//base/global/resmgr_standard/interfaces/innerkits/include",
"//third_party/node/deps/icu-small/source/common",
"//foundation/aafwk/standard/interfaces/innerkits/ability_manager/include",
"//foundation/aafwk/standard/interfaces/innerkits/want/include/ohos/aafwk/content",
"//foundation/distributedschedule/dmsfwk/services/dtbschedmgr/include",
"//foundation/aafwk/standard/interfaces/innerkits/base/include",
# abilityContext end
]
cflags = [
"-Wall",
"-Werror",
"-g3",
"-Dprivate=public",
"-Dprotected=public",
]
}
ohos_static_library("wm_systemtest_common") {
visibility = [ ":*" ]
testonly = true
sources = [ "window_test_utils.cpp" ]
public_configs = [ ":wm_systemtest_common_public_config" ]
public_deps = [
"//foundation/ace/ace_engine/interfaces/innerkits/ace:ace_uicontent",
"//foundation/multimodalinput/input/frameworks/proxy:libmmi-client",
"//foundation/windowmanager/wm:libwm",
"//foundation/windowmanager/wm:libwmutil",
"//foundation/windowmanager/wmserver:libwms",
"//third_party/googletest:gmock",
"//third_party/googletest:gtest_main",
"//utils/native/base:utils",
]
external_deps = [ "aafwk_standard:ability_context_native" ]
}
## Build wm_systemtest_common.a }}}
+229
View File
@@ -0,0 +1,229 @@
/*
* Copyright (c) 2021 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.
*/
// gtest
#include <gtest/gtest.h>
#include "window_test_utils.h"
using namespace testing;
using namespace testing::ext;
namespace OHOS {
namespace Rosen {
using utils = WindowTestUtils;
class WindowLayoutTest : public testing::Test {
public:
static void SetUpTestCase();
static void TearDownTestCase();
virtual void SetUp() override;
virtual void TearDown() override;
int displayId_ = 0;
std::vector<sptr<Window>> activeWindows_;
static vector<Rect> fullScreenExpecteds_;
};
vector<Rect> WindowLayoutTest::fullScreenExpecteds_;
void WindowLayoutTest::SetUpTestCase()
{
auto display = DisplayManager::GetInstance().GetDisplayById(0);
if (display == nullptr) {
printf("GetDefaultDisplay: failed!\n");
} else {
printf("GetDefaultDisplay: id %llu, w %d, h %d, fps %u\n", display->GetId(), display->GetWidth(),
display->GetHeight(), display->GetFreshRate());
}
Rect screenRect = {0, 0, display->GetWidth(), display->GetHeight()};
utils::InitByScreenRect(screenRect);
// calc expected rects
Rect expected = { // 0. only statusBar
0,
utils::statusBarRect_.height_,
utils::screenRect_.width_,
utils::screenRect_.height_ - utils::statusBarRect_.height_,
};
fullScreenExpecteds_.push_back(expected);
expected = { // 1. both statusBar and naviBar
0,
utils::statusBarRect_.height_,
utils::screenRect_.width_,
utils::screenRect_.height_ - utils::statusBarRect_.height_ - utils::naviBarRect_.height_,
};
fullScreenExpecteds_.push_back(expected);
expected = { // 2. only naviBar
0,
0,
utils::screenRect_.width_,
utils::screenRect_.height_ - utils::naviBarRect_.height_,
};
fullScreenExpecteds_.push_back(expected);
}
void WindowLayoutTest::TearDownTestCase()
{
}
void WindowLayoutTest::SetUp()
{
activeWindows_.clear();
}
void WindowLayoutTest::TearDown()
{
while (!activeWindows_.empty()) {
ASSERT_EQ(WMError::WM_OK, activeWindows_.back()->Destroy());
activeWindows_.pop_back();
}
}
namespace {
/**
* @tc.name: LayoutWindow02
* @tc.desc: One FLOATING APP Window
* @tc.type: FUNC
* @tc.require: AR000GGTVJ
*/
HWTEST_F(WindowLayoutTest, LayoutWindow02, Function | MediumTest | Level3)
{
utils::TestWindowInfo info = {
.name = "main",
.rect = utils::defaultAppRect_,
.type = WindowType::WINDOW_TYPE_APP_MAIN_WINDOW,
.mode = WindowMode::WINDOW_MODE_FLOATING,
.needAvoid = true,
.parentLimit = false,
.parentName = "",
};
const sptr<Window>& window = utils::CreateTestWindow(info);
activeWindows_.push_back(window);
ASSERT_EQ(WMError::WM_OK, window->Show());
ASSERT_TRUE(utils::RectEqualTo(window, utils::defaultAppRect_));
ASSERT_EQ(WMError::WM_OK, window->Hide());
}
/**
* @tc.name: LayoutWindow04
* @tc.desc: One FLOATING APP Window & One StatusBar Window
* @tc.type: FUNC
* @tc.require: AR000GGTVJ
*/
HWTEST_F(WindowLayoutTest, LayoutWindow04, Function | MediumTest | Level3)
{
// app window
utils::TestWindowInfo info = {
.name = "main",
.rect = utils::defaultAppRect_,
.type = WindowType::WINDOW_TYPE_APP_MAIN_WINDOW,
.mode = WindowMode::WINDOW_MODE_FLOATING,
.needAvoid = true,
.parentLimit = false,
.parentName = "",
};
sptr<Window> appWin = utils::CreateTestWindow(info);
activeWindows_.push_back(appWin);
// statusBar window
sptr<Window> statBar = utils::CreateStatusBarWindow();
activeWindows_.push_back(statBar);
ASSERT_EQ(WMError::WM_OK, appWin->Show());
ASSERT_TRUE(utils::RectEqualTo(appWin, utils::defaultAppRect_));
ASSERT_EQ(WMError::WM_OK, statBar->Show());
ASSERT_TRUE(utils::RectEqualTo(appWin, utils::defaultAppRect_));
ASSERT_TRUE(utils::RectEqualTo(statBar, utils::statusBarRect_));
ASSERT_EQ(WMError::WM_OK, statBar->Hide());
ASSERT_TRUE(utils::RectEqualTo(appWin, utils::defaultAppRect_));
}
/**
* @tc.name: LayoutWindow06
* @tc.desc: StatusBar Window and NaviBar & Sys Window FULLSCRENN,NOT NEEDVOID,PARENTLIMIT
* @tc.type: FUNC
* @tc.require: AR000GGTVJ
*/
HWTEST_F(WindowLayoutTest, LayoutWindow06, Function | MediumTest | Level3)
{
// statusBar window
sptr<Window> statBar = utils::CreateStatusBarWindow();
activeWindows_.push_back(statBar);
// naviBar window
sptr<Window> naviBar = utils::CreateNavigationBarWindow();
activeWindows_.push_back(naviBar);
// sys window
utils::TestWindowInfo info = {
.name = "main",
.rect = utils::defaultAppRect_,
.type = WindowType::WINDOW_TYPE_PANEL,
.mode = WindowMode::WINDOW_MODE_FULLSCREEN,
.needAvoid = false,
.parentLimit = true,
.parentName = "",
};
sptr<Window> sysWin = utils::CreateTestWindow(info);
activeWindows_.push_back(sysWin);
ASSERT_EQ(WMError::WM_OK, statBar->Show());
ASSERT_TRUE(utils::RectEqualTo(statBar, utils::statusBarRect_));
ASSERT_EQ(WMError::WM_OK, sysWin->Show());
ASSERT_TRUE(utils::RectEqualTo(sysWin, utils::screenRect_));
ASSERT_EQ(WMError::WM_OK, naviBar->Show());
ASSERT_TRUE(utils::RectEqualTo(sysWin, utils::screenRect_));
ASSERT_EQ(WMError::WM_OK, statBar->Hide());
ASSERT_TRUE(utils::RectEqualTo(sysWin, utils::screenRect_));
}
/**
* @tc.name: LayoutWindow07
* @tc.desc: StatusBar Window and NaviBar & One Floating Sys Window
* @tc.type: FUNC
* @tc.require: AR000GGTVJ
*/
HWTEST_F(WindowLayoutTest, LayoutWindow07, Function | MediumTest | Level3)
{
// statusBar window
sptr<Window> statBar = utils::CreateStatusBarWindow();
activeWindows_.push_back(statBar);
// naviBar window
sptr<Window> naviBar = utils::CreateNavigationBarWindow();
activeWindows_.push_back(naviBar);
// sys window
utils::TestWindowInfo info = {
.name = "main",
.rect = utils::defaultAppRect_,
.type = WindowType::WINDOW_TYPE_PANEL,
.mode = WindowMode::WINDOW_MODE_FLOATING,
.needAvoid = false,
.parentLimit = true,
.parentName = "",
};
sptr<Window> sysWin = utils::CreateTestWindow(info);
activeWindows_.push_back(sysWin);
ASSERT_EQ(WMError::WM_OK, statBar->Show());
ASSERT_TRUE(utils::RectEqualTo(statBar, utils::statusBarRect_));
ASSERT_EQ(WMError::WM_OK, sysWin->Show());
ASSERT_TRUE(utils::RectEqualTo(sysWin, utils::defaultAppRect_));
ASSERT_EQ(WMError::WM_OK, naviBar->Show());
ASSERT_TRUE(utils::RectEqualTo(sysWin, utils::defaultAppRect_));
ASSERT_EQ(WMError::WM_OK, statBar->Hide());
ASSERT_TRUE(utils::RectEqualTo(sysWin, utils::defaultAppRect_));
}
}
} // namespace Rosen
} // namespace OHOS
@@ -0,0 +1,153 @@
/*
* Copyright (c) 2021 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.
*/
// gtest
#include <gtest/gtest.h>
#include <thread>
#include "window_test_utils.h"
using namespace testing;
using namespace testing::ext;
namespace OHOS {
namespace Rosen {
using utils = WindowTestUtils;
class WindowMultiAbilityTest : public testing::Test {
public:
static void SetUpTestCase();
static void TearDownTestCase();
virtual void SetUp() override;
virtual void TearDown() override;
};
void WindowMultiAbilityTest::SetUpTestCase()
{
}
void WindowMultiAbilityTest::TearDownTestCase()
{
}
void WindowMultiAbilityTest::SetUp()
{
}
void WindowMultiAbilityTest::TearDown()
{
}
const int SLEEP_MS = 20;
static void ShowHideWindowSceneCallable(int i)
{
int sleepTimeMs = i * SLEEP_MS;
usleep(sleepTimeMs);
sptr<WindowScene> scene = utils::CreateWindowScene();
const int loop = 10;
int j = 0;
for (; j < loop; j++) {
usleep(sleepTimeMs);
ASSERT_EQ(WMError::WM_OK, scene->GoForeground());
usleep(sleepTimeMs);
ASSERT_EQ(WMError::WM_OK, scene->GoBackground());
usleep(sleepTimeMs);
}
}
static void CreateDestroyWindowSceneCallable(int i)
{
int sleepTimeMs = i * SLEEP_MS;
const int loop = 10;
int j = 0;
for (; j < loop; j++) {
usleep(sleepTimeMs);
sptr<WindowScene> scene = utils::CreateWindowScene();
usleep(sleepTimeMs);
ASSERT_EQ(WMError::WM_OK, scene->GoForeground());
usleep(sleepTimeMs);
ASSERT_EQ(WMError::WM_OK, scene->GoBackground());
usleep(sleepTimeMs);
scene.clear();
usleep(sleepTimeMs);
}
}
/**
* @tc.name: MultiAbilityWindow01
* @tc.desc: Five scene process in one thread
* @tc.type: FUNC
* @tc.require: AR000GGTVJ
*/
HWTEST_F(WindowMultiAbilityTest, MultiAbilityWindow01, Function | MediumTest | Level2)
{
sptr<WindowScene> scene1 = utils::CreateWindowScene();
sptr<WindowScene> scene2 = utils::CreateWindowScene();
sptr<WindowScene> scene3 = utils::CreateWindowScene();
sptr<WindowScene> scene4 = utils::CreateWindowScene();
sptr<WindowScene> scene5 = utils::CreateWindowScene();
ASSERT_EQ(WMError::WM_OK, scene1->GoForeground());
ASSERT_EQ(WMError::WM_OK, scene2->GoForeground());
ASSERT_EQ(WMError::WM_OK, scene3->GoForeground());
ASSERT_EQ(WMError::WM_OK, scene4->GoForeground());
ASSERT_EQ(WMError::WM_OK, scene5->GoForeground());
ASSERT_EQ(WMError::WM_OK, scene5->GoBackground());
ASSERT_EQ(WMError::WM_OK, scene4->GoBackground());
ASSERT_EQ(WMError::WM_OK, scene3->GoBackground());
ASSERT_EQ(WMError::WM_OK, scene2->GoBackground());
ASSERT_EQ(WMError::WM_OK, scene1->GoBackground());
}
/**
* @tc.name: MultiAbilityWindow02
* @tc.desc: Five scene process show/hide in five threads
* @tc.type: FUNC
* @tc.require: AR000GGTVJ
*/
HWTEST_F(WindowMultiAbilityTest, MultiAbilityWindow02, Function | MediumTest | Level2)
{
std::thread th1(ShowHideWindowSceneCallable, 1);
std::thread th2(ShowHideWindowSceneCallable, 2);
std::thread th3(ShowHideWindowSceneCallable, 3);
std::thread th4(ShowHideWindowSceneCallable, 4);
std::thread th5(ShowHideWindowSceneCallable, 5);
th1.join();
th2.join();
th3.join();
th4.join();
th5.join();
}
/**
* @tc.name: MultiAbilityWindow03
* @tc.desc: Five scene process create/destroy in five threads
* @tc.type: FUNC
* @tc.require: AR000GGTVJ
*/
HWTEST_F(WindowMultiAbilityTest, MultiAbilityWindow03, Function | MediumTest | Level2)
{
std::thread th1(CreateDestroyWindowSceneCallable, 1);
std::thread th2(CreateDestroyWindowSceneCallable, 2);
std::thread th3(CreateDestroyWindowSceneCallable, 3);
std::thread th4(CreateDestroyWindowSceneCallable, 4);
std::thread th5(CreateDestroyWindowSceneCallable, 5);
th1.join();
th2.join();
th3.join();
th4.join();
th5.join();
}
} // namespace Rosen
} // namespace OHOS
@@ -0,0 +1,312 @@
/*
* Copyright (c) 2021 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.
*/
// gtest
#include <gtest/gtest.h>
#include "window.h"
#include "window_life_cycle_interface.h"
#include "window_option.h"
#include "window_scene.h"
#include "wm_common.h"
using namespace testing;
using namespace testing::ext;
namespace OHOS {
namespace Rosen {
class WindowSubWindowTest : public testing::Test {
public:
static void SetUpTestCase();
static void TearDownTestCase();
virtual void SetUp() override;
virtual void TearDown() override;
};
void WindowSubWindowTest::SetUpTestCase()
{
}
void WindowSubWindowTest::TearDownTestCase()
{
}
void WindowSubWindowTest::SetUp()
{
}
void WindowSubWindowTest::TearDown()
{
}
static sptr<WindowScene> CreateWindowScene()
{
sptr<IWindowLifeCycle> listener = nullptr;
std::shared_ptr<AbilityRuntime::AbilityContext> abilityContext = nullptr;
sptr<WindowScene> scene = new WindowScene();
scene->Init(0, abilityContext, listener);
return scene;
}
static sptr<Window> CreateSubWindow(sptr<WindowScene> scene, WindowType type,
WindowMode mode, struct Rect rect, uint32_t flags)
{
sptr<WindowOption> subOp = new WindowOption();
subOp->SetWindowType(type);
subOp->SetWindowMode(mode);
subOp->SetWindowRect(rect);
subOp->SetWindowFlags(flags);
static int cnt = 0;
return scene->CreateWindow("SubWindow" + std::to_string(cnt++), subOp);
}
/**
* @tc.name: SubWindow01
* @tc.desc: FullScreen Main Window + Floating SubWindow
* @tc.type: FUNC
* @tc.require: AR000GGTVJ
*/
HWTEST_F(WindowSubWindowTest, SubWindow01, Function | MediumTest | Level2)
{
sptr<WindowScene> scene = CreateWindowScene();
struct Rect rect = {0, 0, 100, 200};
uint32_t flags = 0;
sptr<Window> subWindow = CreateSubWindow(scene, WindowType::WINDOW_TYPE_APP_SUB_WINDOW,
WindowMode::WINDOW_MODE_FLOATING, rect, flags);
ASSERT_NE(nullptr, subWindow);
ASSERT_EQ(WMError::WM_OK, scene->GoForeground());
ASSERT_EQ(WMError::WM_OK, subWindow->Show());
ASSERT_EQ(WMError::WM_OK, subWindow->Hide());
ASSERT_EQ(WMError::WM_OK, scene->GoBackground());
}
/**
* @tc.name: SubWindow02
* @tc.desc: FullScreen Main Window + Floating SubWindow & Parent Limit work
* @tc.type: FUNC
* @tc.require: AR000GGTVJ
*/
HWTEST_F(WindowSubWindowTest, SubWindow02, Function | MediumTest | Level2)
{
sptr<WindowScene> scene = CreateWindowScene();
struct Rect rect = {0, 0, 100, 200};
uint32_t flags = static_cast<uint32_t>(WindowFlag::WINDOW_FLAG_PARENT_LIMIT);
sptr<Window> subWindow = CreateSubWindow(scene, WindowType::WINDOW_TYPE_APP_SUB_WINDOW,
WindowMode::WINDOW_MODE_FLOATING, rect, flags);
ASSERT_NE(nullptr, subWindow);
ASSERT_EQ(WMError::WM_OK, scene->GoForeground());
ASSERT_EQ(WMError::WM_OK, subWindow->Show());
ASSERT_EQ(WMError::WM_OK, subWindow->Hide());
ASSERT_EQ(WMError::WM_OK, scene->GoBackground());
}
/**
* @tc.name: SubWindow03
* @tc.desc: FullScreen Main Window + Floating MediaWindow
* @tc.type: FUNC
* @tc.require: AR000GGTVJ
*/
HWTEST_F(WindowSubWindowTest, SubWindow03, Function | MediumTest | Level2)
{
sptr<WindowScene> scene = CreateWindowScene();
struct Rect rect = {0, 2000, 100, 200};
uint32_t flags = static_cast<uint32_t>(WindowFlag::WINDOW_FLAG_PARENT_LIMIT);
sptr<Window> subWindow = CreateSubWindow(scene, WindowType::WINDOW_TYPE_MEDIA,
WindowMode::WINDOW_MODE_FLOATING, rect, flags);
ASSERT_NE(nullptr, subWindow);
ASSERT_EQ(WMError::WM_OK, scene->GoForeground());
ASSERT_EQ(WMError::WM_OK, subWindow->Show());
ASSERT_EQ(WMError::WM_OK, subWindow->Hide());
ASSERT_EQ(WMError::WM_OK, scene->GoBackground());
}
/**
* @tc.name: SubWindow04
* @tc.desc: FullScreen Main Window + Floating MediaWindow
* @tc.type: FUNC
* @tc.require: AR000GGTVJ
*/
HWTEST_F(WindowSubWindowTest, SubWindow04, Function | MediumTest | Level2)
{
sptr<WindowScene> scene = CreateWindowScene();
struct Rect rect = {0, 2000, 3000, 2000};
uint32_t flags = static_cast<uint32_t>(WindowFlag::WINDOW_FLAG_PARENT_LIMIT);
sptr<Window> subWindow = CreateSubWindow(scene, WindowType::WINDOW_TYPE_MEDIA,
WindowMode::WINDOW_MODE_FLOATING, rect, flags);
ASSERT_NE(nullptr, subWindow);
ASSERT_EQ(WMError::WM_OK, scene->GoForeground());
ASSERT_EQ(WMError::WM_OK, subWindow->Show());
ASSERT_EQ(WMError::WM_OK, subWindow->Hide());
ASSERT_EQ(WMError::WM_OK, scene->GoBackground());
}
/**
* @tc.name: SubWindow05
* @tc.desc: FullScreen Main Window + Floating MediaWindow + Floating SubWindow
* @tc.type: FUNC
* @tc.require: AR000GGTVJ
*/
HWTEST_F(WindowSubWindowTest, SubWindow05, Function | MediumTest | Level3)
{
sptr<WindowScene> scene = CreateWindowScene();
struct Rect rect = {0, 0, 100, 200};
uint32_t flags = static_cast<uint32_t>(WindowFlag::WINDOW_FLAG_PARENT_LIMIT);
sptr<Window> subWindow = CreateSubWindow(scene, WindowType::WINDOW_TYPE_MEDIA,
WindowMode::WINDOW_MODE_FLOATING, rect, flags);
ASSERT_NE(nullptr, subWindow);
sptr<Window> subWindow2 = CreateSubWindow(scene, WindowType::WINDOW_TYPE_APP_SUB_WINDOW,
WindowMode::WINDOW_MODE_FLOATING, rect, flags);
ASSERT_NE(nullptr, subWindow2);
ASSERT_EQ(WMError::WM_OK, scene->GoForeground());
ASSERT_EQ(WMError::WM_OK, subWindow->Show());
ASSERT_EQ(WMError::WM_OK, subWindow2->Show());
ASSERT_EQ(WMError::WM_OK, subWindow->Hide());
ASSERT_EQ(WMError::WM_OK, subWindow2->Hide());
ASSERT_EQ(WMError::WM_OK, scene->GoBackground());
}
/**
* @tc.name: SubWindow06
* @tc.desc: FullScreen Main Window + FullScreen SubWindow
* @tc.type: FUNC
* @tc.require: AR000GGTVJ
*/
HWTEST_F(WindowSubWindowTest, SubWindow06, Function | MediumTest | Level3)
{
sptr<WindowScene> scene = CreateWindowScene();
struct Rect rect = {0, 0, 100, 200};
uint32_t flags = static_cast<uint32_t>(WindowFlag::WINDOW_FLAG_PARENT_LIMIT);
sptr<Window> subWindow = CreateSubWindow(scene, WindowType::WINDOW_TYPE_APP_SUB_WINDOW,
WindowMode::WINDOW_MODE_FULLSCREEN, rect, flags);
ASSERT_NE(nullptr, subWindow);
ASSERT_EQ(WMError::WM_OK, scene->GoForeground());
ASSERT_EQ(WMError::WM_OK, subWindow->Show());
ASSERT_EQ(WMError::WM_OK, subWindow->Hide());
ASSERT_EQ(WMError::WM_OK, scene->GoBackground());
}
/**
* @tc.name: SubWindow07
* @tc.desc: FullScreen Main Window + Floating SubWindow & MainWindow Fisrt GoBackground
* @tc.type: FUNC
* @tc.require: AR000GGTVJ
*/
HWTEST_F(WindowSubWindowTest, SubWindow07, Function | MediumTest | Level4)
{
sptr<WindowScene> scene = CreateWindowScene();
struct Rect rect = {0, 0, 100, 200};
uint32_t flags = static_cast<uint32_t>(WindowFlag::WINDOW_FLAG_PARENT_LIMIT);
sptr<Window> subWindow = CreateSubWindow(scene, WindowType::WINDOW_TYPE_APP_SUB_WINDOW,
WindowMode::WINDOW_MODE_FLOATING, rect, flags);
ASSERT_NE(nullptr, subWindow);
ASSERT_EQ(WMError::WM_OK, scene->GoForeground());
ASSERT_EQ(WMError::WM_OK, subWindow->Show());
ASSERT_EQ(WMError::WM_OK, scene->GoBackground());
ASSERT_EQ(WMError::WM_OK, subWindow->Hide());
}
/**
* @tc.name: SubWindow08
* @tc.desc: FullScreen Main Window + Floating SubWindow & only show SubWindow
* @tc.type: FUNC
* @tc.require: AR000GGTVJ
*/
HWTEST_F(WindowSubWindowTest, SubWindow08, Function | MediumTest | Level4)
{
sptr<WindowScene> scene = CreateWindowScene();
struct Rect rect = {0, 0, 100, 200};
uint32_t flags = static_cast<uint32_t>(WindowFlag::WINDOW_FLAG_PARENT_LIMIT);
sptr<Window> subWindow = CreateSubWindow(scene, WindowType::WINDOW_TYPE_APP_SUB_WINDOW,
WindowMode::WINDOW_MODE_FLOATING, rect, flags);
ASSERT_NE(nullptr, subWindow);
ASSERT_EQ(WMError::WM_ERROR_INVALID_PARAM, subWindow->Show());
}
/**
* @tc.name: SubWindow09
* @tc.desc: FullScreen Main Window + Floating SubWindow & first destroy SubWindow, then destroy MainWindow
* @tc.type: FUNC
* @tc.require: AR000GGTVJ
*/
HWTEST_F(WindowSubWindowTest, SubWindow09, Function | MediumTest | Level2)
{
sptr<WindowScene> scene = CreateWindowScene();
struct Rect rect = {0, 0, 100, 200};
uint32_t flags = static_cast<uint32_t>(WindowFlag::WINDOW_FLAG_PARENT_LIMIT);
sptr<Window> subWindow = CreateSubWindow(scene, WindowType::WINDOW_TYPE_APP_SUB_WINDOW,
WindowMode::WINDOW_MODE_FLOATING, rect, flags);
ASSERT_NE(nullptr, subWindow);
ASSERT_EQ(WMError::WM_OK, scene->GoForeground());
ASSERT_EQ(WMError::WM_OK, subWindow->Show());
ASSERT_EQ(WMError::WM_OK, subWindow->Hide());
ASSERT_EQ(WMError::WM_OK, scene->GoBackground());
ASSERT_EQ(WMError::WM_OK, subWindow->Destroy());
}
/**
* @tc.name: SubWindow10
* @tc.desc: FullScreen Main Window + Floating SubWindow & first destroy MainWindow, then destroy SubWindow
* @tc.type: FUNC
* @tc.require: AR000GGTVJ
*/
HWTEST_F(WindowSubWindowTest, SubWindow10, Function | MediumTest | Level2)
{
sptr<WindowScene> scene = CreateWindowScene();
struct Rect rect = {0, 0, 100, 200};
uint32_t flags = static_cast<uint32_t>(WindowFlag::WINDOW_FLAG_PARENT_LIMIT);
sptr<Window> subWindow = CreateSubWindow(scene, WindowType::WINDOW_TYPE_APP_SUB_WINDOW,
WindowMode::WINDOW_MODE_FLOATING, rect, flags);
ASSERT_NE(nullptr, subWindow);
ASSERT_EQ(WMError::WM_OK, scene->GoForeground());
ASSERT_EQ(WMError::WM_OK, subWindow->Show());
sptr<Window> mainWindow = scene->GetMainWindow();
ASSERT_EQ(WMError::WM_OK, mainWindow->Destroy());
ASSERT_EQ(WMError::WM_ERROR_DESTROYED_OBJECT, subWindow->Destroy());
}
} // namespace Rosen
} // namespace OHOS
+107
View File
@@ -0,0 +1,107 @@
/*
* Copyright (c) 2021 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 "window_test_utils.h"
namespace OHOS {
namespace Rosen {
Rect WindowTestUtils::screenRect_ = {0, 0, 0, 0};
Rect WindowTestUtils::statusBarRect_ = {0, 0, 0, 0};
Rect WindowTestUtils::naviBarRect_ = {0, 0, 0, 0};
Rect WindowTestUtils::defaultAppRect_ = {0, 0, 0, 0};
sptr<Window> WindowTestUtils::CreateTestWindow(const TestWindowInfo& info)
{
sptr<WindowOption> option = new WindowOption();
option->SetWindowRect(info.rect);
option->SetWindowType(info.type);
option->SetWindowMode(info.mode);
if (info.parentName != "") {
option->SetParentName(info.parentName);
}
if (info.needAvoid) {
option->AddWindowFlag(WindowFlag::WINDOW_FLAG_NEED_AVOID);
} else {
option->RemoveWindowFlag(WindowFlag::WINDOW_FLAG_NEED_AVOID);
}
if (info.parentLimit) {
option->AddWindowFlag(WindowFlag::WINDOW_FLAG_PARENT_LIMIT);
} else {
option->RemoveWindowFlag(WindowFlag::WINDOW_FLAG_PARENT_LIMIT);
}
sptr<Window> window = Window::Create(info.name, option);
return window;
}
sptr<Window> WindowTestUtils::CreateStatusBarWindow()
{
TestWindowInfo info = {
.name = "statusBar",
.rect = statusBarRect_,
.type = WindowType::WINDOW_TYPE_STATUS_BAR,
.mode = WindowMode::WINDOW_MODE_FLOATING,
.needAvoid = false,
.parentLimit = false,
.parentName = "",
};
return CreateTestWindow(info);
}
sptr<Window> WindowTestUtils::CreateNavigationBarWindow()
{
TestWindowInfo info = {
.name = "naviBar",
.rect = naviBarRect_,
.type = WindowType::WINDOW_TYPE_NAVIGATION_BAR,
.mode = WindowMode::WINDOW_MODE_FLOATING,
.needAvoid = false,
.parentLimit = false,
.parentName = "",
};
return CreateTestWindow(info);
}
sptr<WindowScene> WindowTestUtils::CreateWindowScene()
{
sptr<IWindowLifeCycle> listener = nullptr;
std::shared_ptr<AbilityRuntime::AbilityContext> abilityContext = nullptr;
sptr<WindowScene> scene = new WindowScene();
scene->Init(0, abilityContext, listener);
return scene;
}
void WindowTestUtils::InitByScreenRect(const Rect& screenRect)
{
const float barRatio = 0.07;
const float appRation = 0.4;
screenRect_ = screenRect;
statusBarRect_ = {0, 0, screenRect_.width_, screenRect_.height_ * barRatio};
naviBarRect_ = {0, screenRect_.height_ * (1 - barRatio), screenRect_.width_, screenRect_.height_ * barRatio};
defaultAppRect_ = {0, 0, screenRect_.width_ * appRation, screenRect_.height_ * appRation};
}
bool WindowTestUtils::RectEqualTo(const sptr<Window>& window, const Rect& r)
{
Rect l = window->GetRect();
bool res = ((l.posX_ == r.posX_) && (l.posY_ == r.posY_) && (l.width_ == r.width_) && (l.height_ == r.height_));
if (!res) {
printf("GetLayoutRect: %d %d %d %d, Expect: %d %d %d %d\n", l.posX_, l.posY_, l.width_, l.height_,
r.posX_, r.posY_, r.width_, r.height_);
}
return res;
}
} // namespace ROSEN
} // namespace OHOS
+52
View File
@@ -0,0 +1,52 @@
/*
* Copyright (c) 2021 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.
*/
#ifndef FRAMEWORKS_WM_TEST_ST_WINDOW_TEST_UTILS_H
#define FRAMEWORKS_WM_TEST_ST_WINDOW_TEST_UTILS_H
#include "display_manager.h"
#include "window.h"
#include "window_life_cycle_interface.h"
#include "window_option.h"
#include "window_scene.h"
#include "wm_common.h"
namespace OHOS {
namespace Rosen {
class WindowTestUtils {
public:
struct TestWindowInfo {
std::string name;
Rect rect;
WindowType type;
WindowMode mode;
bool needAvoid;
bool parentLimit;
std::string parentName;
};
static Rect screenRect_;
static Rect statusBarRect_;
static Rect naviBarRect_;
static Rect defaultAppRect_;
static void InitByScreenRect(const Rect& screenRect);
static sptr<Window> CreateTestWindow(const TestWindowInfo& info);
static sptr<Window> CreateStatusBarWindow();
static sptr<Window> CreateNavigationBarWindow();
static sptr<WindowScene> CreateWindowScene();
static bool RectEqualTo(const sptr<Window>& window, const Rect& r);
};
} // namespace ROSEN
} // namespace OHOS
#endif // FRAMEWORKS_WM_TEST_ST_WINDOW_TEST_UTILS_H
+150
View File
@@ -0,0 +1,150 @@
# Copyright (c) 2021 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/wm"
group("unittest") {
testonly = true
deps = [
":wm_input_transfer_station_test",
":wm_window_impl_test",
":wm_window_input_channel_test",
":wm_window_option_test",
":wm_window_scene_test",
":wm_window_test",
]
}
## UnitTest wm_window_impl_test {{{
ohos_unittest("wm_window_impl_test") {
module_out_path = module_out_path
sources = [ "window_impl_test.cpp" ]
deps = [ ":wm_unittest_common" ]
}
## UnitTest wm_window_impl_test }}}
## UnitTest wm_input_transfer_station_test {{{
ohos_unittest("wm_input_transfer_station_test") {
module_out_path = module_out_path
sources = [ "input_transfer_station_test.cpp" ]
deps = [ ":wm_unittest_common" ]
}
## UnitTest wm_input_transfer_station_test }}}
## UnitTest wm_window_input_channel_test {{{
ohos_unittest("wm_window_input_channel_test") {
module_out_path = module_out_path
sources = [ "window_input_channel_test.cpp" ]
deps = [ ":wm_unittest_common" ]
}
## UnitTest wm_window_input_channel_test }}}
## UnitTest wm_window_option_test {{{
ohos_unittest("wm_window_option_test") {
module_out_path = module_out_path
sources = [ "window_option_test.cpp" ]
deps = [ ":wm_unittest_common" ]
}
## UnitTest wm_window_option_test }}}
## UnitTest wm_window_scene_test {{{
ohos_unittest("wm_window_scene_test") {
module_out_path = module_out_path
sources = [ "window_scene_test.cpp" ]
deps = [ ":wm_unittest_common" ]
}
## UnitTest wm_window_scene_test }}}
## UnitTest wm_window_test {{{
ohos_unittest("wm_window_test") {
module_out_path = module_out_path
sources = [ "window_test.cpp" ]
deps = [ ":wm_unittest_common" ]
}
## UnitTest wm_window_test }}}
## Build wm_unittest_common.a {{{
config("wm_unittest_common_public_config") {
include_dirs = [
"//foundation/windowmanager/wm/include",
"//foundation/windowmanager/wmserver/include",
"//foundation/windowmanager/interfaces/innerkits/wm",
"//foundation/windowmanager/utils/include",
"//utils/native/base/include",
"//foundation/communication/ipc/interfaces/innerkits/ipc_core/include",
"//base/hiviewdfx/hilog/interfaces/native/innerkits/include",
"//third_party/googletest/googlemock/include",
# for abilityContext
"//foundation/aafwk/standard/frameworks/kits/ability/ability_runtime/include",
"//foundation/appexecfwk/standard/interfaces/innerkits/appexecfwk_base/include",
"//foundation/appexecfwk/standard/kits/appkit/native/ability_runtime/context",
"//base/global/resmgr_standard/interfaces/innerkits/include",
"//third_party/node/deps/icu-small/source/common",
"//foundation/aafwk/standard/interfaces/innerkits/ability_manager/include",
"//foundation/aafwk/standard/interfaces/innerkits/want/include/ohos/aafwk/content",
"//foundation/distributedschedule/dmsfwk/services/dtbschedmgr/include",
"//foundation/aafwk/standard/interfaces/innerkits/base/include",
# abilityContext end
]
cflags = [
"-Wall",
"-Werror",
"-g3",
"-Dprivate=public",
"-Dprotected=public",
]
}
ohos_static_library("wm_unittest_common") {
visibility = [ ":*" ]
testonly = true
public_configs = [ ":wm_unittest_common_public_config" ]
public_deps = [
"//foundation/ace/ace_engine/interfaces/innerkits/ace:ace_uicontent",
"//foundation/multimodalinput/input/frameworks/proxy:libmmi-client",
"//foundation/windowmanager/wm:libwm",
"//foundation/windowmanager/wm:libwmutil",
"//foundation/windowmanager/wmserver:libwms",
"//third_party/googletest:gmock",
"//third_party/googletest:gtest_main",
"//utils/native/base:utils",
]
external_deps = [ "aafwk_standard:ability_context_native" ]
}
## Build wm_unittest_common.a }}}
@@ -0,0 +1,87 @@
/*
* Copyright (c) 2021 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 "input_transfer_station_test.h"
#include "mock_window_adapter.h"
#include "singleton_mocker.h"
using namespace testing;
using namespace testing::ext;
namespace OHOS {
namespace Rosen {
using WindowMocker = SingletonMocker<WindowAdapter, MockWindowAdapter>;
void InputTransferStationTest::SetUpTestCase()
{
std::unique_ptr<WindowMocker> m = std::make_unique<WindowMocker>();
sptr<WindowOption> option = new WindowOption();
option->SetWindowName("inputwindow");
window_ = new WindowImpl(option);
EXPECT_CALL(m->Mock(), CreateWindow(_, _, _, _)).Times(1).WillOnce(Return(WMError::WM_OK));
window_->Create("");
}
void InputTransferStationTest::TearDownTestCase()
{
}
void InputTransferStationTest::SetUp()
{
}
void InputTransferStationTest::TearDown()
{
}
namespace {
/**
* @tc.name: AddInputWindow
* @tc.desc: add input window in station.
* @tc.type: FUNC
* @tc.require: AR000GGTUV
*/
HWTEST_F(InputTransferStationTest, AddInputWindow, Function | SmallTest | Level2)
{
std::shared_ptr<MMI::IInputEventConsumer> listener = std::make_shared<InputEventListener>(InputEventListener());
MMI::InputManager::GetInstance()->SetWindowInputEventConsumer(listener);
InputTransferStation::GetInstance().AddInputWindow(window_);
}
/**
* @tc.name: RemoveInputWindow
* @tc.desc: remove input window in station.
* @tc.type: FUNC
* @tc.require: AR000GGTUV
*/
HWTEST_F(InputTransferStationTest, RemoveInputWindow, Function | SmallTest | Level2)
{
InputTransferStation::GetInstance().RemoveInputWindow(window_);
}
/**
* @tc.name: SetInputListener
* @tc.desc: set input listener for inner window
* @tc.type: FUNC
* @tc.require: AR000GGTUV
*/
HWTEST_F(InputTransferStationTest, SetInputListener, Function | SmallTest | Level2)
{
int32_t windowId = 1;
std::shared_ptr<MMI::IInputEventConsumer> listener = std::make_shared<InputEventListener>(InputEventListener());
InputTransferStation::GetInstance().SetInputListener(windowId, listener);
}
}
} // namespace Rosen
} // namespace OHOS
@@ -0,0 +1,37 @@
/*
* Copyright (c) 2021 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.
*/
#ifndef FRAMEWORKS_WM_TEST_UT_INPUT_TRANSFER_STATION_TEST_H
#define FRAMEWORKS_WM_TEST_UT_INPUT_TRANSFER_STATION_TEST_H
#include <gtest/gtest.h>
#include "input_manager.h"
#include "input_transfer_station.h"
#include "window_impl.h"
namespace OHOS {
namespace Rosen {
class InputTransferStationTest : public testing::Test {
public:
static void SetUpTestCase();
static void TearDownTestCase();
virtual void SetUp() override;
virtual void TearDown() override;
static inline sptr<WindowImpl> window_;
};
} // namespace ROSEN
} // namespace OHOS
#endif // FRAMEWORKS_WM_TEST_UT_INPUT_TRANSFER_STATION_TEST_H
+33
View File
@@ -0,0 +1,33 @@
/*
* Copyright (c) 2021 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.
*/
#ifndef FRAMEWORKS_WM_TEST_UT_MOCK_STATIC_CALL_H
#define FRAMEWORKS_WM_TEST_UT_MOCK_STATIC_CALL_H
#include <gmock/gmock.h>
#include "ability_context_impl.h"
#include "static_call.h"
namespace OHOS {
namespace Rosen {
class MockStaticCall : public StaticCall {
public:
MOCK_METHOD3(CreateWindow, sptr<Window>(const std::string& windowName,
sptr<WindowOption>& option, std::shared_ptr<AbilityRuntime::AbilityContext> abilityContext));
};
}
} // namespace OHOS
#endif // FRAMEWORKS_WM_TEST_UT_MOCK_STATIC_CALL_H+
@@ -13,9 +13,8 @@
* limitations under the License.
*/
#ifndef UNITTEST_MOCK_WINDOW_ADAPTER_H
#define UNITTEST_MOCK_WINDOW_ADAPTER_H
#ifndef FRAMEWORKS_WM_TEST_UT_MOCK_WINDOW_ADAPTER_H
#define FRAMEWORKS_WM_TEST_UT_MOCK_WINDOW_ADAPTER_H
#include <gmock/gmock.h>
#include "window_adapter.h"
@@ -24,12 +23,15 @@ namespace OHOS {
namespace Rosen {
class MockWindowAdapter : public WindowAdapter {
public:
MOCK_METHOD4(CreateWindow, WMError(sptr<IWindow>& window, sptr<WindowProperty>& windowProperty,
std::shared_ptr<RSSurfaceNode> surfaceNode, uint32_t& windowId));
MOCK_METHOD1(AddWindow, WMError(sptr<WindowProperty>& windowProperty));
MOCK_METHOD1(RemoveWindow, WMError(uint32_t windowId));
MOCK_METHOD0(ClearWindowAdapter, void());
MOCK_METHOD1(DestroyWindow, WMError(uint32_t windowId));
MOCK_METHOD2(SaveAbilityToken, WMError(const sptr<IRemoteObject>& abilityToken, uint32_t windowId));
};
}
} // namespace OHOS
#endif
#endif // FRAMEWORKS_WM_TEST_UT_MOCK_WINDOW_ADAPTER_H
@@ -13,8 +13,8 @@
* limitations under the License.
*/
#ifndef UNITTEST_MOCK_SINGLETON_MOCKER_H
#define UNITTEST_MOCK_SINGLETON_MOCKER_H
#ifndef FRAMEWORKS_WM_TEST_UT_SINGLETON_MOCKER_H
#define FRAMEWORKS_WM_TEST_UT_SINGLETON_MOCKER_H
#include "singleton_container.h"
namespace OHOS {
@@ -43,4 +43,4 @@ private:
} // namespace Rosen
} // namespace OHOS
#endif // FRAMEWORKS_WM_TEST_UNITTEST_MOCK_SINGLETON_MOCKER_H
#endif // FRAMEWORKS_WM_TEST_UT_SINGLETON_MOCKER_H
+392
View File
@@ -0,0 +1,392 @@
/*
* Copyright (c) 2021 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 "window_impl_test.h"
#include "mock_window_adapter.h"
#include "singleton_mocker.h"
using namespace testing;
using namespace testing::ext;
namespace OHOS {
namespace Rosen {
using Mocker = SingletonMocker<WindowAdapter, MockWindowAdapter>;
void WindowImplTest::SetUpTestCase()
{
option_ = new WindowOption();
option_->SetWindowName("WindowImplTest");
window_ = new WindowImpl(option_);
abilityContext_ = std::make_shared<AbilityRuntime::AbilityContextImpl>();
std::unique_ptr<Mocker> m = std::make_unique<Mocker>();
EXPECT_CALL(m->Mock(), CreateWindow(_, _, _, _)).Times(1).WillOnce(Return(WMError::WM_OK));
window_->Create("");
}
void WindowImplTest::TearDownTestCase()
{
std::unique_ptr<Mocker> m = std::make_unique<Mocker>();
EXPECT_CALL(m->Mock(), DestroyWindow(_)).Times(1).WillOnce(Return(WMError::WM_OK));
window_->Destroy();
}
void WindowImplTest::SetUp()
{
}
void WindowImplTest::TearDown()
{
}
namespace {
/**
* @tc.name: CreateWindow01
* @tc.desc: Create window with no parentName
* @tc.type: FUNC
* @tc.require: AR000GGTVJ
*/
HWTEST_F(WindowImplTest, CreateWindow01, Function | SmallTest | Level2)
{
std::unique_ptr<Mocker> m = std::make_unique<Mocker>();
sptr<WindowOption> option = new WindowOption();
option->SetWindowName("CreateWindow01");
sptr<WindowImpl> window = new WindowImpl(option);
EXPECT_CALL(m->Mock(), CreateWindow(_, _, _, _)).Times(1).WillOnce(Return(WMError::WM_OK));
ASSERT_EQ(WMError::WM_OK, window->Create(""));
EXPECT_CALL(m->Mock(), DestroyWindow(_)).Times(1).WillOnce(Return(WMError::WM_OK));
ASSERT_EQ(WMError::WM_OK, window->Destroy());
}
/**
* @tc.name: CreateWindow02
* @tc.desc: Create window with no parentName and no abilityContext
* @tc.type: FUNC
* @tc.require: AR000GGTVJ
*/
HWTEST_F(WindowImplTest, CreateWindow02, Function | SmallTest | Level2)
{
std::unique_ptr<Mocker> m = std::make_unique<Mocker>();
sptr<WindowOption> option = new WindowOption();
option->SetWindowName("CreateWindow02");
sptr<WindowImpl> window = new WindowImpl(option);
EXPECT_CALL(m->Mock(), CreateWindow(_, _, _, _)).Times(1).WillOnce(Return(WMError::WM_ERROR_SAMGR));
ASSERT_EQ(WMError::WM_ERROR_SAMGR, window->Create(""));
}
/**
* @tc.name: CreateWindow03
* @tc.desc: Create window with illegal parentName
* @tc.type: FUNC
* @tc.require: AR000GGTVJ
*/
HWTEST_F(WindowImplTest, CreateWindow03, Function | SmallTest | Level2)
{
sptr<WindowOption> option = new WindowOption();
option->SetWindowName("CreateWindow03");
sptr<WindowImpl> window = new WindowImpl(option);
ASSERT_EQ(WMError::WM_ERROR_INVALID_PARAM, window->Create("illegal"));
}
/**
* @tc.name: CreateWindow04
* @tc.desc: Create window with repeated windowName
* @tc.type: FUNC
* @tc.require: AR000GGTVJ
*/
HWTEST_F(WindowImplTest, CreateWindow04, Function | SmallTest | Level2)
{
sptr<WindowOption> option = new WindowOption();
option->SetWindowName("WindowImplTest");
sptr<WindowImpl> window = new WindowImpl(option);
ASSERT_EQ(WMError::WM_ERROR_INVALID_PARAM, window->Create(""));
}
/**
* @tc.name: CreateWindow05
* @tc.desc: Create window with exist parentName
* @tc.type: FUNC
* @tc.require: AR000GGTVJ
*/
HWTEST_F(WindowImplTest, CreateWindow05, Function | SmallTest | Level2)
{
std::unique_ptr<Mocker> m = std::make_unique<Mocker>();
sptr<WindowOption> option = new WindowOption();
option->SetWindowName("CreateWindow05");
sptr<WindowImpl> window = new WindowImpl(option);
EXPECT_CALL(m->Mock(), CreateWindow(_, _, _, _)).Times(1).WillOnce(Return(WMError::WM_OK));
ASSERT_EQ(WMError::WM_OK, window->Create("WindowImplTest"));
EXPECT_CALL(m->Mock(), DestroyWindow(_)).Times(1).WillOnce(Return(WMError::WM_OK));
ASSERT_EQ(WMError::WM_OK, window->Destroy());
}
/**
* @tc.name: CreateWindow06
* @tc.desc: Create window with no default option, get and check Property
* @tc.type: FUNC
* @tc.require: AR000GGTVJ
*/
HWTEST_F(WindowImplTest, CreateWindow06, Function | SmallTest | Level2)
{
std::unique_ptr<Mocker> m = std::make_unique<Mocker>();
sptr<WindowOption> option = new WindowOption();
option->SetWindowName("CreateWindow06");
struct Rect rect = {1, 2, 3u, 4u};
option->SetWindowRect(rect);
option->SetWindowType(WindowType::WINDOW_TYPE_APP_MAIN_WINDOW);
option->SetWindowMode(WindowMode::WINDOW_MODE_FULLSCREEN);
sptr<WindowImpl> window = new WindowImpl(option);
EXPECT_CALL(m->Mock(), CreateWindow(_, _, _, _)).Times(1).WillOnce(Return(WMError::WM_OK));
ASSERT_EQ(WMError::WM_OK, window->Create(""));
ASSERT_EQ(1, window->GetRect().posX_);
ASSERT_EQ(2, window->GetRect().posY_);
ASSERT_EQ(3u, window->GetRect().width_);
ASSERT_EQ(4u, window->GetRect().height_);
ASSERT_EQ(WindowType::WINDOW_TYPE_APP_MAIN_WINDOW, window->GetType());
ASSERT_EQ(WindowMode::WINDOW_MODE_FULLSCREEN, window->GetMode());
ASSERT_EQ("CreateWindow06", window->GetWindowName());
EXPECT_CALL(m->Mock(), DestroyWindow(_)).Times(1).WillOnce(Return(WMError::WM_OK));
ASSERT_EQ(WMError::WM_OK, window->Destroy());
}
/**
* @tc.name: CreateWindow07
* @tc.desc: Create window with no parentName and abilityContext
* @tc.type: FUNC
* @tc.require: AR000GGTVJ
*/
HWTEST_F(WindowImplTest, CreateWindow07, Function | SmallTest | Level2)
{
std::unique_ptr<Mocker> m = std::make_unique<Mocker>();
sptr<WindowOption> option = new WindowOption();
option->SetWindowName("CreateWindow07");
sptr<WindowImpl> window = new WindowImpl(option);
EXPECT_CALL(m->Mock(), SaveAbilityToken(_, _)).Times(1).WillOnce(Return(WMError::WM_OK));
EXPECT_CALL(m->Mock(), CreateWindow(_, _, _, _)).Times(1).WillOnce(Return(WMError::WM_OK));
ASSERT_EQ(WMError::WM_OK, window->Create("", abilityContext_));
}
/**
* @tc.name: CreateWindow08
* @tc.desc: Mock SaveAbilityToken return WM_ERROR_NULLPTR, create window with no parentName and abilityContext
* @tc.type: FUNC
* @tc.require: AR000GGTVJ
*/
HWTEST_F(WindowImplTest, CreateWindow08, Function | SmallTest | Level2)
{
std::unique_ptr<Mocker> m = std::make_unique<Mocker>();
sptr<WindowOption> option = new WindowOption();
option->SetWindowName("CreateWindow08");
sptr<WindowImpl> window = new WindowImpl(option);
EXPECT_CALL(m->Mock(), SaveAbilityToken(_, _)).Times(1).WillOnce(Return(WMError::WM_ERROR_NULLPTR));
EXPECT_CALL(m->Mock(), CreateWindow(_, _, _, _)).Times(1).WillOnce(Return(WMError::WM_OK));
ASSERT_EQ(WMError::WM_ERROR_NULLPTR, window->Create("", abilityContext_));
}
/**
* @tc.name: FindWindow01
* @tc.desc: Find one exit window
* @tc.type: FUNC
* @tc.require: AR000GGTVJ
*/
HWTEST_F(WindowImplTest, FindWindow01, Function | SmallTest | Level2)
{
ASSERT_NE(nullptr, WindowImpl::Find("WindowImplTest"));
}
/**
* @tc.name: FindWindow02
* @tc.desc: Add another window, find both two windows
* @tc.type: FUNC
* @tc.require: AR000GGTVJ
*/
HWTEST_F(WindowImplTest, FindWindow02, Function | SmallTest | Level2)
{
std::unique_ptr<Mocker> m = std::make_unique<Mocker>();
sptr<WindowOption> option = new WindowOption();
option->SetWindowName("FindWindow02");
sptr<WindowImpl> window = new WindowImpl(option);
EXPECT_CALL(m->Mock(), CreateWindow(_, _, _, _)).Times(1).WillOnce(Return(WMError::WM_OK));
ASSERT_EQ(WMError::WM_OK, window->Create(""));
ASSERT_NE(nullptr, WindowImpl::Find("WindowImplTest"));
ASSERT_NE(nullptr, WindowImpl::Find("FindWindow02"));
EXPECT_CALL(m->Mock(), DestroyWindow(_)).Times(1).WillOnce(Return(WMError::WM_OK));
ASSERT_EQ(WMError::WM_OK, window->Destroy());
}
/**
* @tc.name: FindWindow03
* @tc.desc: Find one no exit window
* @tc.type: FUNC
* @tc.require: AR000GGTVJ
*/
HWTEST_F(WindowImplTest, FindWindow03, Function | SmallTest | Level2)
{
ASSERT_EQ(nullptr, WindowImpl::Find("FindWindow03"));
}
/**
* @tc.name: FindWindow04
* @tc.desc: Find window with empty name
* @tc.type: FUNC
* @tc.require: AR000GGTVJ
*/
HWTEST_F(WindowImplTest, FindWindow04, Function | SmallTest | Level2)
{
ASSERT_EQ(nullptr, WindowImpl::Find(""));
}
/**
* @tc.name: FindWindow05
* @tc.desc: Find one destroyed window
* @tc.type: FUNC
* @tc.require: AR000GGTVJ
*/
HWTEST_F(WindowImplTest, FindWindow05, Function | SmallTest | Level2)
{
ASSERT_EQ(nullptr, WindowImpl::Find("FindWindow02"));
}
/**
* @tc.name: SetWindowType01
* @tc.desc: SetWindowType
* @tc.type: FUNC
* @tc.require: AR000GGTVJ
*/
HWTEST_F(WindowImplTest, SetWindowType01, Function | SmallTest | Level2)
{
ASSERT_EQ(WMError::WM_OK, window_->SetWindowType(WindowType::WINDOW_TYPE_APP_MAIN_WINDOW));
}
/**
* @tc.name: SetWindowMode01
* @tc.desc: SetWindowMode
* @tc.type: FUNC
* @tc.require: AR000GGTVJ
*/
HWTEST_F(WindowImplTest, SetWindowMode01, Function | SmallTest | Level2)
{
ASSERT_EQ(WMError::WM_OK, window_->SetWindowMode(WindowMode::WINDOW_MODE_FULLSCREEN));
}
/**
* @tc.name: ShowHideWindow01
* @tc.desc: Show and hide window with add and remove window ok
* @tc.type: FUNC
* @tc.require: AR000GGTVJ
*/
HWTEST_F(WindowImplTest, ShowHideWindow01, Function | SmallTest | Level2)
{
std::unique_ptr<Mocker> m = std::make_unique<Mocker>();
EXPECT_CALL(m->Mock(), AddWindow(_)).Times(1).WillOnce(Return(WMError::WM_OK));
ASSERT_EQ(WMError::WM_OK, window_->Show());
EXPECT_CALL(m->Mock(), RemoveWindow(_)).Times(1).WillOnce(Return(WMError::WM_OK));
ASSERT_EQ(WMError::WM_OK, window_->Hide());
}
/**
* @tc.name: ShowHideWindow02
* @tc.desc: Show window with add window WM_ERROR_SAMGR
* @tc.type: FUNC
* @tc.require: AR000GGTVJ
*/
HWTEST_F(WindowImplTest, ShowHideWindow02, Function | SmallTest | Level2)
{
std::unique_ptr<Mocker> m = std::make_unique<Mocker>();
EXPECT_CALL(m->Mock(), AddWindow(_)).Times(1).WillOnce(Return(WMError::WM_ERROR_SAMGR));
ASSERT_EQ(WMError::WM_ERROR_SAMGR, window_->Show());
}
/**
* @tc.name: ShowHideWindow03
* @tc.desc: Show window with add window WM_ERROR_IPC_FAILED
* @tc.type: FUNC
* @tc.require: AR000GGTVJ
*/
HWTEST_F(WindowImplTest, ShowHideWindow03, Function | SmallTest | Level3)
{
std::unique_ptr<Mocker> m = std::make_unique<Mocker>();
EXPECT_CALL(m->Mock(), AddWindow(_)).Times(1).WillOnce(Return(WMError::WM_ERROR_IPC_FAILED));
ASSERT_EQ(WMError::WM_ERROR_IPC_FAILED, window_->Show());
}
/**
* @tc.name: ShowHideWindow04
* @tc.desc: Show window with add window OK & Hide window with remove window WM_ERROR_SAMGR
* @tc.type: FUNC
* @tc.require: AR000GGTVJ
*/
HWTEST_F(WindowImplTest, ShowHideWindow04, Function | SmallTest | Level3)
{
std::unique_ptr<Mocker> m = std::make_unique<Mocker>();
EXPECT_CALL(m->Mock(), AddWindow(_)).Times(1).WillOnce(Return(WMError::WM_OK));
ASSERT_EQ(WMError::WM_OK, window_->Show());
EXPECT_CALL(m->Mock(), RemoveWindow(_)).Times(1).WillOnce(Return(WMError::WM_ERROR_SAMGR));
ASSERT_EQ(WMError::WM_ERROR_SAMGR, window_->Hide());
}
/**
* @tc.name: ShowHideWindow05
* @tc.desc: Hide window with remove window WM_ERROR_IPC_FAILED
* @tc.type: FUNC
* @tc.require: AR000GGTVJ
*/
HWTEST_F(WindowImplTest, ShowHideWindow05, Function | SmallTest | Level3)
{
std::unique_ptr<Mocker> m = std::make_unique<Mocker>();
EXPECT_CALL(m->Mock(), RemoveWindow(_)).Times(1).WillOnce(Return(WMError::WM_ERROR_IPC_FAILED));
ASSERT_EQ(WMError::WM_ERROR_IPC_FAILED, window_->Hide());
}
/**
* @tc.name: ShowHideWindow06
* @tc.desc: Hide window with remove window OK
* @tc.type: FUNC
* @tc.require: AR000GGTVJ
*/
HWTEST_F(WindowImplTest, ShowHideWindow06, Function | SmallTest | Level3)
{
std::unique_ptr<Mocker> m = std::make_unique<Mocker>();
EXPECT_CALL(m->Mock(), RemoveWindow(_)).Times(1).WillOnce(Return(WMError::WM_OK));
ASSERT_EQ(WMError::WM_OK, window_->Hide());
}
}
} // namespace Rosen
} // namespace OHOS
+39
View File
@@ -0,0 +1,39 @@
/*
* Copyright (c) 2021 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.
*/
#ifndef FRAMEWORKS_WM_TEST_UT_WINDOW_IMPL_TEST_H
#define FRAMEWORKS_WM_TEST_UT_WINDOW_IMPL_TEST_H
#include <gtest/gtest.h>
#include "ability_context_impl.h"
#include "window_impl.h"
namespace OHOS {
namespace Rosen {
class WindowImplTest : public testing::Test {
public:
static void SetUpTestCase();
static void TearDownTestCase();
virtual void SetUp() override;
virtual void TearDown() override;
static inline sptr<WindowImpl> window_ = nullptr;
static inline sptr<WindowOption> option_ = nullptr;
static inline std::shared_ptr<AbilityRuntime::AbilityContext> abilityContext_;
};
} // namespace ROSEN
} // namespace OHOS
#endif // FRAMEWORKS_WM_TEST_UT_WINDOW_IMPL_TEST_H
@@ -0,0 +1,91 @@
/*
* Copyright (c) 2021 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 "window_input_channel_test.h"
#include "mock_window_adapter.h"
#include "singleton_mocker.h"
using namespace testing;
using namespace testing::ext;
namespace OHOS {
namespace Rosen {
using WindowMocker = SingletonMocker<WindowAdapter, MockWindowAdapter>;
void WindowInputChannelTest::SetUpTestCase()
{
std::unique_ptr<WindowMocker> m = std::make_unique<WindowMocker>();
sptr<WindowOption> option = new WindowOption();
option->SetWindowName("window");
window_ = new WindowImpl(option);
EXPECT_CALL(m->Mock(), CreateWindow(_, _, _, _)).Times(1).WillOnce(Return(WMError::WM_OK));
window_->Create("");
}
void WindowInputChannelTest::TearDownTestCase()
{
}
void WindowInputChannelTest::SetUp()
{
}
void WindowInputChannelTest::TearDown()
{
}
namespace {
/**
* @tc.name: HandlePointerEvent
* @tc.desc: consume pointer event when receive callback from input
* @tc.type: FUNC
* @tc.require: AR000GGTUV
*/
HWTEST_F(WindowInputChannelTest, HandlePointerEvent, Function | SmallTest | Level2)
{
auto pointerEvent = MMI::PointerEvent::Create();
sptr<WindowInputChannel> inputChannel = new WindowInputChannel(window_);
window_->ConsumePointerEvent(pointerEvent);
inputChannel->HandlePointerEvent(pointerEvent);
}
/**
* @tc.name: HandleKeyEvent
* @tc.desc: consume key event when receive callback from input
* @tc.type: FUNC
* @tc.require: AR000GGTUV
*/
HWTEST_F(WindowInputChannelTest, HandleKeyEvent, Function | SmallTest | Level2)
{
auto keyEvent = MMI::KeyEvent::Create();
sptr<WindowInputChannel> inputChannel = new WindowInputChannel(window_);
window_->ConsumeKeyEvent(keyEvent);
inputChannel->HandleKeyEvent(keyEvent);
}
/**
* @tc.name: SetInputListener
* @tc.desc: set input listener when create window
* @tc.type: FUNC
* @tc.require: AR000GGTUV
*/
HWTEST_F(WindowInputChannelTest, SetInputListener, Function | SmallTest | Level2)
{
sptr<WindowInputChannel> inputChannel = new WindowInputChannel(window_);
std::shared_ptr<MMI::IInputEventConsumer> listener = std::make_shared<InputEventListener>(InputEventListener());
inputChannel->SetInputListener(listener);
}
}
} // namespace Rosen
} // namespace OHOS
@@ -13,25 +13,24 @@
* limitations under the License.
*/
#ifndef UNITTEST_WINDOW_IMPL_TEST_H
#define UNITTEST_WINDOW_IMPL_TEST_H
#ifndef FRAMEWORKS_WM_TEST_UT_WINDOW_INPUT_CHANNEL_TEST_H
#define FRAMEWORKS_WM_TEST_UT_WINDOW_INPUT_CHANNEL_TEST_H
#include <gtest/gtest.h>
#include "window_impl.h"
#include "window_input_channel.h"
namespace OHOS {
namespace Rosen {
class WindowImplTest : public testing::Test {
class WindowInputChannelTest : public testing::Test {
public:
static void SetUpTestCase();
static void TearDownTestCase();
virtual void SetUp() override;
virtual void TearDown() override;
static inline sptr<Window> window_ = nullptr;
static inline sptr<WindowProperty> property_ = nullptr;
static inline sptr<WindowImpl> window_;
};
} // namespace ROSEN
} // namespace OHOS
#endif // FRAMEWORKS_WM_TEST_UNITTEST_WINDOW_IMPL_TEST_H
#endif // FRAMEWORKS_WM_TEST_UT_WINDOW_INPUT_CHANNEL_TEST_H
+191
View File
@@ -0,0 +1,191 @@
/*
* Copyright (c) 2021 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 "window_option_test.h"
using namespace testing;
using namespace testing::ext;
namespace OHOS {
namespace Rosen {
void WindowOptionTest::SetUpTestCase()
{
}
void WindowOptionTest::TearDownTestCase()
{
}
void WindowOptionTest::SetUp()
{
}
void WindowOptionTest::TearDown()
{
}
namespace {
/**
* @tc.name: WindowRect01
* @tc.desc: SetWindowRect/GetWindowRect
* @tc.type: FUNC
* @tc.require: AR000GGTVJ
*/
HWTEST_F(WindowOptionTest, WindowRect01, Function | SmallTest | Level2)
{
sptr<WindowOption> option = new WindowOption();
struct Rect rect = {1, 2, 3u, 4u};
option->SetWindowRect(rect);
ASSERT_EQ(1, option->GetWindowRect().posX_);
ASSERT_EQ(2, option->GetWindowRect().posY_);
ASSERT_EQ(3u, option->GetWindowRect().width_);
ASSERT_EQ(4u, option->GetWindowRect().height_);
}
/**
* @tc.name: WindowType01
* @tc.desc: SetWindowType/GetWindowType
* @tc.type: FUNC
* @tc.require: AR000GGTVJ
*/
HWTEST_F(WindowOptionTest, WindowType01, Function | SmallTest | Level2)
{
sptr<WindowOption> option = new WindowOption();
option->SetWindowType(WindowType::WINDOW_TYPE_APP_MAIN_WINDOW);
ASSERT_EQ(WindowType::WINDOW_TYPE_APP_MAIN_WINDOW, option->GetWindowType());
}
/**
* @tc.name: WindowMode01
* @tc.desc: SetWindowMode/GetWindowMode
* @tc.type: FUNC
* @tc.require: AR000GGTVJ
*/
HWTEST_F(WindowOptionTest, WindowMode01, Function | SmallTest | Level2)
{
sptr<WindowOption> option = new WindowOption();
option->SetWindowMode(WindowMode::WINDOW_MODE_FULLSCREEN);
ASSERT_EQ(WindowMode::WINDOW_MODE_FULLSCREEN, option->GetWindowMode());
}
/**
* @tc.name: Focusable01
* @tc.desc: SetFocusable/GetFocusable
* @tc.type: FUNC
* @tc.require: AR000GGTVJ
*/
HWTEST_F(WindowOptionTest, Focusable01, Function | SmallTest | Level2)
{
sptr<WindowOption> option = new WindowOption();
option->SetFocusable(true);
ASSERT_EQ(true, option->GetFocusable());
}
/**
* @tc.name: Touchable01
* @tc.desc: SetTouchable/GetTouchable
* @tc.type: FUNC
* @tc.require: AR000GGTVJ
*/
HWTEST_F(WindowOptionTest, Touchable01, Function | SmallTest | Level2)
{
sptr<WindowOption> option = new WindowOption();
option->SetTouchable(true);
ASSERT_EQ(true, option->GetTouchable());
}
/**
* @tc.name: DisplayId01
* @tc.desc: SetDisplayId/GetDisplayId
* @tc.type: FUNC
* @tc.require: AR000GGTVJ
*/
HWTEST_F(WindowOptionTest, DisplayId01, Function | SmallTest | Level2)
{
sptr<WindowOption> option = new WindowOption();
option->SetDisplayId(1);
ASSERT_EQ(1, option->GetDisplayId());
}
/**
* @tc.name: ParentName01
* @tc.desc: SetParentName/GetParentName
* @tc.type: FUNC
* @tc.require: AR000GGTVJ
*/
HWTEST_F(WindowOptionTest, ParentName01, Function | SmallTest | Level2)
{
sptr<WindowOption> option = new WindowOption();
option->SetParentName("Main Window");
ASSERT_EQ("Main Window", option->GetParentName());
}
/**
* @tc.name: WindowName01
* @tc.desc: SetWindowName/GetWindowName
* @tc.type: FUNC
* @tc.require: AR000GGTVJ
*/
HWTEST_F(WindowOptionTest, WindowName01, Function | SmallTest | Level2)
{
sptr<WindowOption> option = new WindowOption();
option->SetWindowName("Sub Window");
ASSERT_EQ("Sub Window", option->GetWindowName());
}
/**
* @tc.name: WindowFlag01
* @tc.desc: SetWindowFlags/GetWindowFlags
* @tc.type: FUNC
* @tc.require: AR000GGTVJ
*/
HWTEST_F(WindowOptionTest, WindowFlag01, Function | SmallTest | Level2)
{
sptr<WindowOption> option = new WindowOption();
option->SetWindowFlags(1u);
ASSERT_EQ(1u, option->GetWindowFlags());
}
/**
* @tc.name: WindowFlag02
* @tc.desc: AddWindowFlag/GetWindowFlags
* @tc.type: FUNC
* @tc.require: AR000GGTVJ
*/
HWTEST_F(WindowOptionTest, WindowFlag02, Function | SmallTest | Level2)
{
sptr<WindowOption> option = new WindowOption();
option->AddWindowFlag(WindowFlag::WINDOW_FLAG_NEED_AVOID);
ASSERT_EQ(static_cast<uint32_t>(WindowFlag::WINDOW_FLAG_NEED_AVOID), option->GetWindowFlags());
}
/**
* @tc.name: WindowFlag03
* @tc.desc: AddWindowFlag/RemoveWindowFlag/GetWindowFlags
* @tc.type: FUNC
* @tc.require: AR000GGTVJ
*/
HWTEST_F(WindowOptionTest, WindowFlag03, Function | SmallTest | Level2)
{
sptr<WindowOption> option = new WindowOption();
option->AddWindowFlag(WindowFlag::WINDOW_FLAG_NEED_AVOID);
option->AddWindowFlag(WindowFlag::WINDOW_FLAG_PARENT_LIMIT);
option->RemoveWindowFlag(WindowFlag::WINDOW_FLAG_NEED_AVOID);
ASSERT_EQ(static_cast<uint32_t>(WindowFlag::WINDOW_FLAG_PARENT_LIMIT), option->GetWindowFlags());
}
}
} // namespace Rosen
} // namespace OHOS
+33
View File
@@ -0,0 +1,33 @@
/*
* Copyright (c) 2021 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.
*/
#ifndef FRAMEWORKS_WM_TEST_UT_WINDOW_OPTION_TEST_H
#define FRAMEWORKS_WM_TEST_UT_WINDOW_OPTION_TEST_H
#include <gtest/gtest.h>
#include "window_option.h"
namespace OHOS {
namespace Rosen {
class WindowOptionTest : public testing::Test {
public:
static void SetUpTestCase();
static void TearDownTestCase();
virtual void SetUp() override;
virtual void TearDown() override;
};
} // namespace ROSEN
} // namespace OHOS
#endif // FRAMEWORKS_WM_TEST_UT_WINDOW_OPTION_TEST_H
+231
View File
@@ -0,0 +1,231 @@
/*
* Copyright (c) 2021 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 "window_scene_test.h"
#include "ability_context_impl.h"
#include "mock_static_call.h"
#include "singleton_mocker.h"
#include "window_impl.h"
using namespace testing;
using namespace testing::ext;
namespace OHOS {
namespace Rosen {
using Mocker = SingletonMocker<StaticCall, MockStaticCall>;
void WindowSceneTest::SetUpTestCase()
{
int displayId = 0;
sptr<IWindowLifeCycle> listener = nullptr;
scene_ = new WindowScene();
abilityContext_ = std::make_shared<AbilityRuntime::AbilityContextImpl>();
std::unique_ptr<Mocker> m = std::make_unique<Mocker>();
sptr<WindowOption> option = new WindowOption();
EXPECT_CALL(m->Mock(), CreateWindow(_, _, _)).Times(1).WillOnce(Return(new WindowImpl(option)));
ASSERT_EQ(WMError::WM_OK, scene_->Init(displayId, abilityContext_, listener));
}
void WindowSceneTest::TearDownTestCase()
{
}
void WindowSceneTest::SetUp()
{
}
void WindowSceneTest::TearDown()
{
}
namespace {
/**
* @tc.name: Init01
* @tc.desc: Init Scene with null abilityContext, null listener
* @tc.type: FUNC
* @tc.require: AR000GGTVJ
*/
HWTEST_F(WindowSceneTest, Init01, Function | SmallTest | Level2)
{
std::unique_ptr<Mocker> m = std::make_unique<Mocker>();
sptr<WindowOption> optionTest = new WindowOption();
EXPECT_CALL(m->Mock(), CreateWindow(_, _, _)).Times(1).WillOnce(Return(new WindowImpl(optionTest)));
int displayId = 0;
sptr<IWindowLifeCycle> listener = nullptr;
sptr<WindowScene> scene = new WindowScene();
std::shared_ptr<AbilityRuntime::AbilityContext> abilityContext = nullptr;
ASSERT_EQ(WMError::WM_OK, scene->Init(displayId, abilityContext, listener));
}
/**
* @tc.name: Init02
* @tc.desc: Mock window Create Static Method return nullptr, init Scene with null abilityContext, null listener
* @tc.type: FUNC
* @tc.require: AR000GGTVJ
*/
HWTEST_F(WindowSceneTest, Init02, Function | SmallTest | Level2)
{
std::unique_ptr<Mocker> m = std::make_unique<Mocker>();
sptr<WindowOption> optionTest = new WindowOption();
EXPECT_CALL(m->Mock(), CreateWindow(_, _, _)).Times(1).WillOnce(Return(nullptr));
int displayId = 0;
sptr<IWindowLifeCycle> listener = nullptr;
sptr<WindowScene> scene = new WindowScene();
std::shared_ptr<AbilityRuntime::AbilityContext> abilityContext = nullptr;
ASSERT_EQ(WMError::WM_ERROR_NULLPTR, scene->Init(displayId, abilityContext, listener));
}
/**
* @tc.name: Init03
* @tc.desc: Init Scene with abilityContext, null listener
* @tc.type: FUNC
* @tc.require: AR000GGTVJ
*/
HWTEST_F(WindowSceneTest, Init03, Function | SmallTest | Level2)
{
std::unique_ptr<Mocker> m = std::make_unique<Mocker>();
sptr<WindowOption> optionTest = new WindowOption();
EXPECT_CALL(m->Mock(), CreateWindow(_, _, _)).Times(1).WillOnce(Return(new WindowImpl(optionTest)));
int displayId = 0;
sptr<IWindowLifeCycle> listener = nullptr;
sptr<WindowScene> scene = new WindowScene();
ASSERT_EQ(WMError::WM_OK, scene->Init(displayId, abilityContext_, listener));
}
/**
* @tc.name: Create01
* @tc.desc: CreateWindow without windowName
* @tc.type: FUNC
* @tc.require: AR000GGTVJ
*/
HWTEST_F(WindowSceneTest, Create01, Function | SmallTest | Level2)
{
sptr<WindowOption> optionTest = new WindowOption();
sptr<WindowScene> scene = new WindowScene();
ASSERT_EQ(nullptr, scene->CreateWindow("", optionTest));
}
/**
* @tc.name: Create02
* @tc.desc: CreateWindow with windowName and without mainWindow
* @tc.type: FUNC
* @tc.require: AR000GGTVJ
*/
HWTEST_F(WindowSceneTest, Create02, Function | SmallTest | Level2)
{
sptr<WindowOption> optionTest = new WindowOption();
sptr<WindowScene> scene = new WindowScene();
ASSERT_EQ(nullptr, scene->CreateWindow("WindowSceneTest02", optionTest));
}
/**
* @tc.name: Create03
* @tc.desc: CreateWindow with windowName and mainWindow
* @tc.type: FUNC
* @tc.require: AR000GGTVJ
*/
HWTEST_F(WindowSceneTest, Create03, Function | SmallTest | Level2)
{
std::unique_ptr<Mocker> m = std::make_unique<Mocker>();
sptr<WindowOption> optionTest = new WindowOption();
EXPECT_CALL(m->Mock(), CreateWindow(_, _, _)).Times(1).WillOnce(Return(new WindowImpl(optionTest)));
ASSERT_NE(nullptr, scene_->CreateWindow("WindowSceneTest03", optionTest));
}
/**
* @tc.name: Create04
* @tc.desc: Mock window Create Static Method return nullptr, createWindow with windowName and mainWindow
* @tc.type: FUNC
* @tc.require: AR000GGTVJ
*/
HWTEST_F(WindowSceneTest, Create04, Function | SmallTest | Level2)
{
sptr<WindowOption> optionTest = new WindowOption();
std::unique_ptr<Mocker> m = std::make_unique<Mocker>();
EXPECT_CALL(m->Mock(), CreateWindow(_, _, _)).Times(1).WillOnce(Return(nullptr));
ASSERT_EQ(nullptr, scene_->CreateWindow("WindowSceneTest04", optionTest));
}
/**
* @tc.name: Create05
* @tc.desc: createWindow with windowName and null option
* @tc.type: FUNC
* @tc.require: AR000GGTVJ
*/
HWTEST_F(WindowSceneTest, Create05, Function | SmallTest | Level2)
{
sptr<WindowOption> optionTest = nullptr;
ASSERT_EQ(nullptr, scene_->CreateWindow("WindowSceneTest05", optionTest));
}
/**
* @tc.name: GetMainWindow01
* @tc.desc: GetMainWindow without scene init
* @tc.type: FUNC
* @tc.require: AR000GGTVJ
*/
HWTEST_F(WindowSceneTest, GetMainWindow01, Function | SmallTest | Level2)
{
sptr<WindowScene> scene = new WindowScene();
ASSERT_EQ(nullptr, scene->GetMainWindow());
}
/**
* @tc.name: GetMainWindow02
* @tc.desc: GetMainWindow01 with scene init success
* @tc.type: FUNC
* @tc.require: AR000GGTVJ
*/
HWTEST_F(WindowSceneTest, GetMainWindow02, Function | SmallTest | Level2)
{
ASSERT_NE(nullptr, scene_->GetMainWindow());
}
/**
* @tc.name: GoForeground01
* @tc.desc: GoForeground01 without mainWindow
* @tc.type: FUNC
* @tc.require: AR000GGTVJ
*/
HWTEST_F(WindowSceneTest, GoForeground01, Function | SmallTest | Level2)
{
sptr<WindowScene> scene = new WindowScene();
ASSERT_EQ(WMError::WM_ERROR_NULLPTR, scene->GoForeground());
}
/**
* @tc.name: GoBackground01
* @tc.desc: GoBackground01 without mainWindow
* @tc.type: FUNC
* @tc.require: AR000GGTVJ
*/
HWTEST_F(WindowSceneTest, GoBackground01, Function | SmallTest | Level2)
{
sptr<WindowScene> scene = new WindowScene();
ASSERT_EQ(WMError::WM_ERROR_NULLPTR, scene->GoBackground());
}
/**
* @tc.name: RequestFocus01
* @tc.desc: RequestFocus01 without mainWindow
* @tc.type: FUNC
* @tc.require: AR000GGTVJ
*/
HWTEST_F(WindowSceneTest, RequestFocus01, Function | SmallTest | Level2)
{
sptr<WindowScene> scene = new WindowScene();
ASSERT_EQ(WMError::WM_ERROR_NULLPTR, scene->RequestFocus());
}
}
} // namespace Rosen
} // namespace OHOS
+37
View File
@@ -0,0 +1,37 @@
/*
* Copyright (c) 2021 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.
*/
#ifndef FRAMEWORKS_WM_TEST_UT_WINDOW_SCENE_TEST_H
#define FRAMEWORKS_WM_TEST_UT_WINDOW_SCENE_TEST_H
#include <gtest/gtest.h>
#include "window_scene.h"
namespace OHOS {
namespace Rosen {
class WindowSceneTest : public testing::Test {
public:
static void SetUpTestCase();
static void TearDownTestCase();
virtual void SetUp() override;
virtual void TearDown() override;
static inline sptr<WindowScene> scene_ = nullptr;
static inline std::shared_ptr<AbilityRuntime::AbilityContext> abilityContext_;
};
} // namespace ROSEN
} // namespace OHOS
#endif // FRAMEWORKS_WM_TEST_UT_WINDOW_SCENE_TEST_H
+138
View File
@@ -0,0 +1,138 @@
/*
* Copyright (c) 2021 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 "window_test.h"
#include "mock_window_adapter.h"
#include "singleton_mocker.h"
using namespace testing;
using namespace testing::ext;
namespace OHOS {
namespace Rosen {
using Mocker = SingletonMocker<WindowAdapter, MockWindowAdapter>;
void WindowTest::SetUpTestCase()
{
abilityContext_ = std::make_shared<AbilityRuntime::AbilityContextImpl>();
}
void WindowTest::TearDownTestCase()
{
}
void WindowTest::SetUp()
{
}
void WindowTest::TearDown()
{
}
namespace {
/**
* @tc.name: Create01
* @tc.desc: Create window with no WindowName and no abilityToken
* @tc.type: FUNC
* @tc.require: AR000GGTVJ
*/
HWTEST_F(WindowTest, Create01, Function | SmallTest | Level2)
{
sptr<WindowOption> option = new WindowOption();
ASSERT_EQ(nullptr, Window::Create("", option));
}
/**
* @tc.name: Create02
* @tc.desc: Create window with WindowName and no abilityToken
* @tc.type: FUNC
* @tc.require: AR000GGTVJ
*/
HWTEST_F(WindowTest, Create02, Function | SmallTest | Level2)
{
std::unique_ptr<Mocker> m = std::make_unique<Mocker>();
sptr<WindowOption> option = new WindowOption();
EXPECT_CALL(m->Mock(), CreateWindow(_, _, _, _)).Times(1).WillOnce(Return(WMError::WM_OK));
ASSERT_NE(nullptr, Window::Create("WindowTest02", option));
}
/**
* @tc.name: Create03
* @tc.desc: Mock CreateWindow return WM_ERROR_SAMGR, create window with WindowName and no abilityToken
* @tc.type: FUNC
* @tc.require: AR000GGTVJ
*/
HWTEST_F(WindowTest, Create03, Function | SmallTest | Level2)
{
std::unique_ptr<Mocker> m = std::make_unique<Mocker>();
sptr<WindowOption> option = new WindowOption();
EXPECT_CALL(m->Mock(), CreateWindow(_, _, _, _)).Times(1).WillOnce(Return(WMError::WM_ERROR_SAMGR));
ASSERT_EQ(nullptr, Window::Create("WindowTest03", option));
}
/**
* @tc.name: Create04
* @tc.desc: Create window with WindowName and abilityContext
* @tc.type: FUNC
* @tc.require: AR000GGTVJ
*/
HWTEST_F(WindowTest, Create04, Function | SmallTest | Level2)
{
std::unique_ptr<Mocker> m = std::make_unique<Mocker>();
sptr<WindowOption> option = new WindowOption();
EXPECT_CALL(m->Mock(), CreateWindow(_, _, _, _)).Times(1).WillOnce(Return(WMError::WM_OK));
EXPECT_CALL(m->Mock(), SaveAbilityToken(_, _)).Times(1).WillOnce(Return(WMError::WM_OK));
ASSERT_NE(nullptr, Window::Create("WindowTest04", option, abilityContext_));
}
/**
* @tc.name: Create06
* @tc.desc: Create window with WindowName and no option
* @tc.type: FUNC
* @tc.require: AR000GGTVJ
*/
HWTEST_F(WindowTest, Create06, Function | SmallTest | Level2)
{
sptr<WindowOption> option = nullptr;
ASSERT_EQ(nullptr, Window::Create("", option));
}
/**
* @tc.name: Find01
* @tc.desc: Find with no name
* @tc.type: FUNC
* @tc.require: AR000GGTVJ
*/
HWTEST_F(WindowTest, Find01, Function | SmallTest | Level2)
{
ASSERT_EQ(nullptr, Window::Find(""));
}
/**
* @tc.name: Find02
* @tc.desc: Find with name
* @tc.type: FUNC
* @tc.require: AR000GGTVJ
*/
HWTEST_F(WindowTest, Find02, Function | SmallTest | Level2)
{
std::unique_ptr<Mocker> m = std::make_unique<Mocker>();
sptr<WindowOption> option = new WindowOption();
EXPECT_CALL(m->Mock(), CreateWindow(_, _, _, _)).Times(1).WillOnce(Return(WMError::WM_OK));
ASSERT_NE(nullptr, Window::Create("WindowTest03", option));
ASSERT_NE(nullptr, Window::Find("WindowTest03"));
}
}
} // namespace Rosen
} // namespace OHOS
+36
View File
@@ -0,0 +1,36 @@
/*
* Copyright (c) 2021 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.
*/
#ifndef FRAMEWORKS_WM_TEST_UT_WINDOW_TEST_H
#define FRAMEWORKS_WM_TEST_UT_WINDOW_TEST_H
#include <gtest/gtest.h>
#include "ability_context_impl.h"
#include "window.h"
namespace OHOS {
namespace Rosen {
class WindowTest : public testing::Test {
public:
static void SetUpTestCase();
static void TearDownTestCase();
virtual void SetUp() override;
virtual void TearDown() override;
static inline std::shared_ptr<AbilityRuntime::AbilityContext> abilityContext_;
};
} // namespace ROSEN
} // namespace OHOS
#endif // FRAMEWORKS_WM_TEST_UT_WINDOW_TEST_H
+4 -2
View File
@@ -42,8 +42,10 @@ public:
WMError SetSystemBarProperty(uint32_t windowId, WindowType type, const SystemBarProperty& property);
WMError MinimizeAllAppNodeAbility(uint32_t windowId);
void RegisterFocusChangedListener(const sptr<IWindowManagerAgent>& windowManagerAgent);
void UnregisterFocusChangedListener(const sptr<IWindowManagerAgent>& windowManagerAgent);
void RegisterWindowManagerAgent(WindowManagerAgentType type,
const sptr<IWindowManagerAgent>& windowManagerAgent);
void UnregisterWindowManagerAgent(WindowManagerAgentType type,
const sptr<IWindowManagerAgent>& windowManagerAgent);
private:
uint32_t GenWindowId();
-2
View File
@@ -50,13 +50,11 @@ private:
sptr<WindowNode> appWindowNode_ = new WindowNode();
sptr<WindowNode> aboveAppWindowNode_ = new WindowNode();
Rect limitRect_ = {0, 0, 0, 0};
std::map<uint32_t, sptr<WindowNode>> avoidNodes_;
const std::set<WindowType> avoidTypes_ {
WindowType::WINDOW_TYPE_STATUS_BAR,
WindowType::WINDOW_TYPE_NAVIGATION_BAR,
};
void UpdateLimitRect(const sptr<WindowNode>& node);
void RecordAvoidRect(const sptr<WindowNode>& node);
void UpdateLayoutRect(sptr<WindowNode>& node);
void LayoutWindowTree();
void LayoutWindowNode(sptr<WindowNode>& node);
+6 -2
View File
@@ -44,6 +44,8 @@ public:
TRANS_ID_REGISTER_FOCUS_CHANGED_LISTENER,
TRANS_ID_UNREGISTER_FOCUS_CHANGED_LISTENER,
TRANS_ID_MINIMIZE_ALL_APP_WINDOW,
TRANS_ID_REGISTER_WINDOW_MANAGER_AGENT,
TRANS_ID_UNREGISTER_WINDOW_MANAGER_AGENT,
};
virtual WMError CreateWindow(sptr<IWindow>& window, sptr<WindowProperty>& property,
const std::shared_ptr<RSSurfaceNode>& surfaceNode, uint32_t& windowId) = 0;
@@ -60,8 +62,10 @@ public:
virtual WMError SaveAbilityToken(const sptr<IRemoteObject>& abilityToken, uint32_t windowId) = 0;
virtual WMError MinimizeAllAppNodeAbility(uint32_t windowId) = 0;
virtual void RegisterFocusChangedListener(const sptr<IWindowManagerAgent>& windowManagerAgent) = 0;
virtual void UnregisterFocusChangedListener(const sptr<IWindowManagerAgent>& windowManagerAgent) = 0;
virtual void RegisterWindowManagerAgent(WindowManagerAgentType type,
const sptr<IWindowManagerAgent>& windowManagerAgent) = 0;
virtual void UnregisterWindowManagerAgent(WindowManagerAgentType type,
const sptr<IWindowManagerAgent>& windowManagerAgent) = 0;
};
}
}
+4 -2
View File
@@ -42,8 +42,10 @@ public:
WMError SetSystemBarProperty(uint32_t windowId, WindowType type, const SystemBarProperty& prop) override;
WMError MinimizeAllAppNodeAbility(uint32_t windowId) override;
void RegisterFocusChangedListener(const sptr<IWindowManagerAgent>& windowManagerAgent) override;
void UnregisterFocusChangedListener(const sptr<IWindowManagerAgent>& windowManagerAgent) override;
void RegisterWindowManagerAgent(WindowManagerAgentType type,
const sptr<IWindowManagerAgent>& windowManagerAgent) override;
void UnregisterWindowManagerAgent(WindowManagerAgentType type,
const sptr<IWindowManagerAgent>& windowManagerAgent) override;
private:
static inline BrokerDelegator<WindowManagerProxy> delegator_;
+4 -2
View File
@@ -55,8 +55,10 @@ public:
WMError SetSystemBarProperty(uint32_t windowId, WindowType type, const SystemBarProperty& prop) override;
WMError MinimizeAllAppNodeAbility(uint32_t windowId) override;
void RegisterFocusChangedListener(const sptr<IWindowManagerAgent>& windowManagerAgent) override;
void UnregisterFocusChangedListener(const sptr<IWindowManagerAgent>& windowManagerAgent) override;
void RegisterWindowManagerAgent(WindowManagerAgentType type,
const sptr<IWindowManagerAgent>& windowManagerAgent) override;
void UnregisterWindowManagerAgent(WindowManagerAgentType type,
const sptr<IWindowManagerAgent>& windowManagerAgent) override;
// Inner interfaces
WMError NotifyDisplaySuspend();
+8 -1
View File
@@ -26,10 +26,16 @@ namespace OHOS {
namespace Rosen {
using UpdateFocusStatusFunc = std::function<void (uint32_t windowId, const sptr<IRemoteObject>& abilityToken,
WindowType windowType, int32_t displayId, bool focused)>;
using UpdateSystemBarPropsFunc = std::function<void (uint64_t displayId, const SystemBarProps& props)>;
struct WindowNodeContainerCallbacks {
UpdateFocusStatusFunc focusStatusCallBack_;
UpdateSystemBarPropsFunc systemBarChangedCallBack_;
};
class WindowNodeContainer : public RefBase {
public:
WindowNodeContainer(uint64_t screenId, uint32_t width, uint32_t height, UpdateFocusStatusFunc callback);
WindowNodeContainer(uint64_t screenId, uint32_t width, uint32_t height, WindowNodeContainerCallbacks callbacks);
~WindowNodeContainer();
WMError AddWindowNode(sptr<WindowNode>& node, sptr<WindowNode>& parentNode);
WMError RemoveWindowNode(sptr<WindowNode>& node);
@@ -86,6 +92,7 @@ private:
uint64_t screenId_ = 0;
const float DEFAULT_WINDOW_SPLIT_RATIO = 0.5; // default split ratio
UpdateFocusStatusFunc focusStatusCallBack_;
WindowNodeContainerCallbacks callbacks_;
void DumpScreenWindowTree();
struct WindowPairInfo {
+7 -4
View File
@@ -70,17 +70,20 @@ public:
WMError MinimizeAllAppNodeAbility(sptr<WindowNode>& node);
WMError HandleSplitWindowModeChange(sptr<WindowNode>& node, bool isChangeToSplit);
void RegisterFocusChangedListener(const sptr<IWindowManagerAgent>& windowManagerAgent);
void UnregisterFocusChangedListener(const sptr<IWindowManagerAgent>& windowManagerAgent);
void RegisterWindowManagerAgent(WindowManagerAgentType type,
const sptr<IWindowManagerAgent>& windowManagerAgent);
void UnregisterWindowManagerAgent(WindowManagerAgentType type,
const sptr<IWindowManagerAgent>& windowManagerAgent);
std::shared_ptr<RSSurfaceNode> GetSurfaceNodeByAbilityToken(const sptr<IRemoteObject>& abilityToken) const;
private:
void OnRemoteDied(const sptr<IRemoteObject>& remoteObject);
void ClearWindowManagerAgent(const sptr<IRemoteObject>& remoteObject);
void UnregisterFocusChangedListener(const sptr<IRemoteObject>& windowManagerAgent);
void UnregisterWindowManagerAgent(const sptr<IRemoteObject>& object);
void UpdateFocusStatus(uint32_t windowId, const sptr<IRemoteObject>& abilityToken, WindowType windowType,
int32_t displayId, bool focused);
void UpdateSystemBarProperties(uint64_t displayId, const SystemBarProps& props);
WMError DestroyWindowInner(sptr<WindowNode>& node);
std::recursive_mutex& mutex_;
@@ -88,7 +91,7 @@ private:
std::map<uint32_t, sptr<WindowNode>> windowNodeMap_;
std::map<sptr<IRemoteObject>, uint32_t> windowIdMap_;
std::vector<sptr<IWindowManagerAgent>> focusChangedListenerAgents_;
std::map<WindowManagerAgentType, std::vector<sptr<IWindowManagerAgent>>> windowManagerAgents_;
sptr<WindowDeathRecipient> windowDeath_ = new WindowDeathRecipient(std::bind(&WindowRoot::OnRemoteDied,
this, std::placeholders::_1));
+6 -4
View File
@@ -240,14 +240,16 @@ WMError WindowController::SetSystemBarProperty(uint32_t windowId, WindowType typ
return res;
}
void WindowController::RegisterFocusChangedListener(const sptr<IWindowManagerAgent>& windowManagerAgent)
void WindowController::RegisterWindowManagerAgent(WindowManagerAgentType type,
const sptr<IWindowManagerAgent>& windowManagerAgent)
{
windowRoot_->RegisterFocusChangedListener(windowManagerAgent);
windowRoot_->RegisterWindowManagerAgent(type, windowManagerAgent);
}
void WindowController::UnregisterFocusChangedListener(const sptr<IWindowManagerAgent>& windowManagerAgent)
void WindowController::UnregisterWindowManagerAgent(WindowManagerAgentType type,
const sptr<IWindowManagerAgent>& windowManagerAgent)
{
windowRoot_->UnregisterFocusChangedListener(windowManagerAgent);
windowRoot_->UnregisterWindowManagerAgent(type, windowManagerAgent);
}
}
}
+3 -20
View File
@@ -36,13 +36,11 @@ void WindowLayoutPolicy::UpdateDisplayInfo(const Rect& displayRect)
{
displayRect_ = displayRect;
limitRect_ = displayRect_;
avoidNodes_.clear();
}
void WindowLayoutPolicy::LayoutWindowTree()
{
limitRect_ = displayRect_;
avoidNodes_.clear();
std::vector<sptr<WindowNode>> rootNodes = { aboveAppWindowNode_, appWindowNode_, belowAppWindowNode_ };
for (auto& node : rootNodes) { // ensure that the avoid area windows are traversed first
LayoutWindowNode(node);
@@ -61,7 +59,7 @@ void WindowLayoutPolicy::LayoutWindowNode(sptr<WindowNode>& node)
}
UpdateLayoutRect(node);
if (avoidTypes_.find(node->GetWindowType()) != avoidTypes_.end()) {
RecordAvoidRect(node);
UpdateLimitRect(node);
}
}
for (auto& childNode : node->children_) {
@@ -80,7 +78,7 @@ void WindowLayoutPolicy::RemoveWindowNode(sptr<WindowNode>& node)
WM_FUNCTION_TRACE();
auto type = node->GetWindowType();
// affect other windows, trigger off global layout
if (type == WindowType::WINDOW_TYPE_STATUS_BAR || type == WindowType::WINDOW_TYPE_NAVIGATION_BAR) {
if (avoidTypes_.find(type) != avoidTypes_.end()) {
LayoutWindowTree();
} else if (type == WindowType::WINDOW_TYPE_DOCK_SLICE) { // split screen mode
// TODO: change split screen
@@ -93,7 +91,7 @@ void WindowLayoutPolicy::UpdateWindowNode(sptr<WindowNode>& node)
WM_FUNCTION_TRACE();
auto type = node->GetWindowType();
// affect other windows, trigger off global layout
if (type == WindowType::WINDOW_TYPE_STATUS_BAR || type == WindowType::WINDOW_TYPE_NAVIGATION_BAR) {
if (avoidTypes_.find(type) != avoidTypes_.end()) {
LayoutWindowTree();
} else if (type == WindowType::WINDOW_TYPE_DOCK_SLICE) { // split screen mode
// TODO: change split screen
@@ -210,20 +208,5 @@ void WindowLayoutPolicy::UpdateLimitRect(const sptr<WindowNode>& node)
WLOGFI("Type: %{public}d, limitRect: %{public}d %{public}d %{public}d %{public}d",
node->GetWindowType(), limitRect_.posX_, limitRect_.posY_, limitRect_.width_, limitRect_.height_);
}
void WindowLayoutPolicy::RecordAvoidRect(const sptr<WindowNode>& node)
{
uint32_t id = node->GetWindowId();
if (avoidNodes_.find(id) == avoidNodes_.end()) { // new avoid rect
avoidNodes_.insert(std::pair<uint32_t, sptr<WindowNode>>(id, node));
UpdateLimitRect(node);
} else { // update existing avoid rect
limitRect_ = displayRect_;
avoidNodes_[id] = node;
for (auto item : avoidNodes_) {
UpdateLimitRect(item.second);
}
}
}
}
}
+16 -4
View File
@@ -348,7 +348,8 @@ WMError WindowManagerProxy::SaveAbilityToken(const sptr<IRemoteObject>& abilityT
return static_cast<WMError>(ret);
}
void WindowManagerProxy::RegisterFocusChangedListener(const sptr<IWindowManagerAgent>& windowManagerAgent)
void WindowManagerProxy::RegisterWindowManagerAgent(WindowManagerAgentType type,
const sptr<IWindowManagerAgent>& windowManagerAgent)
{
MessageParcel data;
MessageParcel reply;
@@ -358,17 +359,23 @@ void WindowManagerProxy::RegisterFocusChangedListener(const sptr<IWindowManagerA
return;
}
if (!data.WriteUint32(static_cast<uint32_t>(type))) {
WLOGFE("Write type failed");
return;
}
if (!data.WriteRemoteObject(windowManagerAgent->AsObject())) {
WLOGFE("Write IWindowManagerAgent failed");
return;
}
if (Remote()->SendRequest(TRANS_ID_REGISTER_FOCUS_CHANGED_LISTENER, data, reply, option) != ERR_NONE) {
if (Remote()->SendRequest(TRANS_ID_REGISTER_WINDOW_MANAGER_AGENT, data, reply, option) != ERR_NONE) {
WLOGFE("SendRequest failed");
}
}
void WindowManagerProxy::UnregisterFocusChangedListener(const sptr<IWindowManagerAgent>& windowManagerAgent)
void WindowManagerProxy::UnregisterWindowManagerAgent(WindowManagerAgentType type,
const sptr<IWindowManagerAgent>& windowManagerAgent)
{
MessageParcel data;
MessageParcel reply;
@@ -378,12 +385,17 @@ void WindowManagerProxy::UnregisterFocusChangedListener(const sptr<IWindowManage
return;
}
if (!data.WriteUint32(static_cast<uint32_t>(type))) {
WLOGFE("Write type failed");
return;
}
if (!data.WriteRemoteObject(windowManagerAgent->AsObject())) {
WLOGFE("Write IWindowManagerAgent failed");
return;
}
if (Remote()->SendRequest(TRANS_ID_UNREGISTER_FOCUS_CHANGED_LISTENER, data, reply, option) != ERR_NONE) {
if (Remote()->SendRequest(TRANS_ID_UNREGISTER_WINDOW_MANAGER_AGENT, data, reply, option) != ERR_NONE) {
WLOGFE("SendRequest failed");
}
}
+13 -12
View File
@@ -209,24 +209,25 @@ WMError WindowManagerService::SaveAbilityToken(const sptr<IRemoteObject>& abilit
return windowController_->SaveAbilityToken(abilityToken, windowId);
}
void WindowManagerService::RegisterFocusChangedListener(const sptr<IWindowManagerAgent>& windowManagerAgent)
{
if ((windowManagerAgent == nullptr) || (windowManagerAgent->AsObject() == nullptr)) {
WLOGFE("failed to get window manager agent");
return;
}
std::lock_guard<std::recursive_mutex> lock(mutex_);
windowController_->RegisterFocusChangedListener(windowManagerAgent);
}
void WindowManagerService::UnregisterFocusChangedListener(const sptr<IWindowManagerAgent>& windowManagerAgent)
void WindowManagerService::RegisterWindowManagerAgent(WindowManagerAgentType type,
const sptr<IWindowManagerAgent>& windowManagerAgent)
{
if ((windowManagerAgent == nullptr) || (windowManagerAgent->AsObject() == nullptr)) {
WLOGFE("windowManagerAgent is null");
return;
}
std::lock_guard<std::recursive_mutex> lock(mutex_);
windowController_->UnregisterFocusChangedListener(windowManagerAgent);
windowController_->RegisterWindowManagerAgent(type, windowManagerAgent);
}
void WindowManagerService::UnregisterWindowManagerAgent(WindowManagerAgentType type,
const sptr<IWindowManagerAgent>& windowManagerAgent)
{
if ((windowManagerAgent == nullptr) || (windowManagerAgent->AsObject() == nullptr)) {
WLOGFE("windowManagerAgent is null");
return;
}
std::lock_guard<std::recursive_mutex> lock(mutex_);
windowController_->UnregisterWindowManagerAgent(type, windowManagerAgent);
}
void WindowManagerService::OnWindowEvent(Event event, uint32_t windowId)
+6 -4
View File
@@ -118,18 +118,20 @@ int32_t WindowManagerStub::OnRemoteRequest(uint32_t code, MessageParcel &data, M
reply.WriteInt32(static_cast<int32_t>(errCode));
break;
}
case TRANS_ID_REGISTER_FOCUS_CHANGED_LISTENER: {
case TRANS_ID_REGISTER_WINDOW_MANAGER_AGENT: {
sptr<IRemoteObject> windowManagerAgentObject = data.ReadRemoteObject();
WindowManagerAgentType type = static_cast<WindowManagerAgentType>(data.ReadUint32());
sptr<IWindowManagerAgent> windowManagerAgentProxy =
iface_cast<IWindowManagerAgent>(windowManagerAgentObject);
RegisterFocusChangedListener(windowManagerAgentProxy);
RegisterWindowManagerAgent(type, windowManagerAgentProxy);
break;
}
case TRANS_ID_UNREGISTER_FOCUS_CHANGED_LISTENER: {
case TRANS_ID_UNREGISTER_WINDOW_MANAGER_AGENT: {
sptr<IRemoteObject> windowManagerAgentObject = data.ReadRemoteObject();
WindowManagerAgentType type = static_cast<WindowManagerAgentType>(data.ReadUint32());
sptr<IWindowManagerAgent> windowManagerAgentProxy =
iface_cast<IWindowManagerAgent>(windowManagerAgentObject);
UnregisterFocusChangedListener(windowManagerAgentProxy);
UnregisterWindowManagerAgent(type, windowManagerAgentProxy);
break;
}
case TRANS_ID_MINIMIZE_ALL_APP_WINDOW: {
+12 -10
View File
@@ -31,7 +31,8 @@ namespace {
}
WindowNodeContainer::WindowNodeContainer(uint64_t screenId, uint32_t width, uint32_t height,
UpdateFocusStatusFunc callback) : screenId_(screenId), focusStatusCallBack_(callback)
WindowNodeContainerCallbacks callbacks)
: screenId_(screenId), callbacks_(callbacks)
{
struct RSDisplayNodeConfig config = {screenId};
displayNode_ = RSDisplayNode::Create(config);
@@ -303,7 +304,7 @@ void WindowNodeContainer::UpdateFocusStatus(uint32_t id, bool focused) const
if (node->abilityToken_ == nullptr) {
WLOGFI("abilityToken is null, window : %{public}d", id);
}
focusStatusCallBack_(node->GetWindowId(), node->abilityToken_, node->GetWindowType(),
callbacks_.focusStatusCallBack_(node->GetWindowId(), node->abilityToken_, node->GetWindowType(),
node->GetDisplayId(), focused);
}
}
@@ -388,17 +389,19 @@ void WindowNodeContainer::NotifySystemBarIfChanged()
{
DumpScreenWindowTree();
auto node = GetTopImmersiveNode();
SystemBarProps props;
if (node == nullptr) { // use default system bar
WLOGFI("no immersive window on top");
for (auto it : sysBarPropMap_) {
if (it.second == SystemBarProperty()) {
continue;
}
sysBarPropMap_[it.first] = SystemBarProperty();
if (sysBarNodeMap_[it.first] != nullptr) {
sysBarNodeMap_[it.first]->GetWindowToken()->UpdateSystemBarProperty(SystemBarProperty());
}
std::pair<WindowType, SystemBarProperty> item = { it.first, SystemBarProperty() };
props.emplace_back(item);
}
} else { // use node-defined system bar
WLOGFI("top immersive window id: %{public}d", node->GetWindowId());
auto& sysBarPropMap = node->GetSystemBarProperty();
for (auto it : sysBarPropMap_) {
if (sysBarPropMap.find(it.first) == sysBarPropMap.end()) {
@@ -413,11 +416,11 @@ void WindowNodeContainer::NotifySystemBarIfChanged()
node->GetWindowId(), static_cast<int32_t>(it.first),
prop.enable_, prop.backgroundColor_, prop.contentColor_);
sysBarPropMap_[it.first] = prop;
if (sysBarNodeMap_[it.first] != nullptr) {
sysBarNodeMap_[it.first]->GetWindowToken()->UpdateSystemBarProperty(prop);
}
std::pair<WindowType, SystemBarProperty> item = { it.first, prop };
props.emplace_back(item);
}
}
callbacks_.systemBarChangedCallBack_(screenId_, props);
}
void WindowNodeContainer::TraverseContainer(std::vector<sptr<WindowNode>>& windowNodes)
@@ -513,11 +516,11 @@ sptr<WindowNode> WindowNodeContainer::FindSplitPairNode(sptr<WindowNode>& trigge
}
}
return nullptr;
}
void WindowNodeContainer::HandleModeChangeToSplit(sptr<WindowNode>& triggerNode)
{
WM_FUNCTION_TRACE();
WLOGFI("HandleModeChangeToSplit %{public}d", triggerNode->GetWindowId());
auto pairNode = FindSplitPairNode(triggerNode);
if (pairNode != nullptr) {
@@ -598,6 +601,5 @@ void WindowNodeContainer::UpdateWindowPairInfo(sptr<WindowNode>& triggerNode, sp
// Rect dividerRect = displayRects_->GetDividerRect();
// SingletonContainer::Get<WindowInnerManager>().SendMessage(INNER_WM_CREATE_DIVIDER, screenId_, dividerRect);
}
}
}
+33 -13
View File
@@ -41,9 +41,15 @@ sptr<WindowNodeContainer> WindowRoot::GetOrCreateWindowNodeContainer(int32_t dis
UpdateFocusStatusFunc focusStatusFunc = std::bind(&WindowRoot::UpdateFocusStatus, this, std::placeholders::_1,
std::placeholders::_2, std::placeholders::_3, std::placeholders::_4, std::placeholders::_5);
UpdateSystemBarPropsFunc sysBarUpdateFunc = std::bind(&WindowRoot::UpdateSystemBarProperties, this,
std::placeholders::_1, std::placeholders::_2);
WindowNodeContainerCallbacks callbacks = {
focusStatusFunc,
sysBarUpdateFunc
};
sptr<WindowNodeContainer> container = new WindowNodeContainer(abstractDisplay->GetId(),
static_cast<uint32_t>(abstractDisplay->GetWidth()), static_cast<uint32_t>(abstractDisplay->GetHeight()),
focusStatusFunc);
callbacks);
windowNodeContainerMap_.insert({ displayId, container });
return container;
}
@@ -236,9 +242,10 @@ WMError WindowRoot::RequestFocus(uint32_t windowId)
return container->SetFocusWindow(windowId);
}
void WindowRoot::RegisterFocusChangedListener(const sptr<IWindowManagerAgent>& windowManagerAgent)
void WindowRoot::RegisterWindowManagerAgent(WindowManagerAgentType type,
const sptr<IWindowManagerAgent>& windowManagerAgent)
{
focusChangedListenerAgents_.push_back(windowManagerAgent);
windowManagerAgents_[type].push_back(windowManagerAgent);
if (windowManagerAgentDeath_ == nullptr) {
WLOGFI("failed to create death Recipient ptr WindowManagerAgentDeathRecipient");
return;
@@ -248,21 +255,24 @@ void WindowRoot::RegisterFocusChangedListener(const sptr<IWindowManagerAgent>& w
}
}
void WindowRoot::UnregisterFocusChangedListener(const sptr<IWindowManagerAgent>& windowManagerAgent)
void WindowRoot::UnregisterWindowManagerAgent(WindowManagerAgentType type,
const sptr<IWindowManagerAgent>& windowManagerAgent)
{
auto iter = std::find(focusChangedListenerAgents_.begin(), focusChangedListenerAgents_.end(), windowManagerAgent);
if (iter == focusChangedListenerAgents_.end()) {
auto iter = std::find(windowManagerAgents_[type].begin(), windowManagerAgents_[type].end(), windowManagerAgent);
if (iter == windowManagerAgents_[type].end()) {
WLOGFE("could not find this listener");
return;
}
focusChangedListenerAgents_.erase(iter);
windowManagerAgents_[type].erase(iter);
}
void WindowRoot::UnregisterFocusChangedListener(const sptr<IRemoteObject>& object)
void WindowRoot::UnregisterWindowManagerAgent(const sptr<IRemoteObject>& object)
{
for (auto iter = focusChangedListenerAgents_.begin(); iter < focusChangedListenerAgents_.end(); ++iter) {
if ((*iter)->AsObject() != nullptr && (*iter)->AsObject() == object) {
iter = focusChangedListenerAgents_.erase(iter);
for (auto agents : windowManagerAgents_) {
for (auto iter = agents.second.begin(); iter < agents.second.end(); ++iter) {
if ((*iter)->AsObject() != nullptr && (*iter)->AsObject() == object) {
iter = agents.second.erase(iter);
}
}
}
}
@@ -270,7 +280,7 @@ void WindowRoot::UnregisterFocusChangedListener(const sptr<IRemoteObject>& objec
void WindowRoot::UpdateFocusStatus(uint32_t windowId, const sptr<IRemoteObject>& abilityToken, WindowType windowType,
int32_t displayId, bool focused)
{
for (auto& windowManagerAgent : focusChangedListenerAgents_) {
for (auto& windowManagerAgent : windowManagerAgents_[WindowManagerAgentType::WINDOW_MANAGER_AGENT_TYPE_FOCUS]) {
windowManagerAgent->UpdateFocusStatus(windowId, abilityToken, windowType, displayId, focused);
}
}
@@ -287,6 +297,16 @@ std::shared_ptr<RSSurfaceNode> WindowRoot::GetSurfaceNodeByAbilityToken(const sp
return nullptr;
}
void WindowRoot::UpdateSystemBarProperties(uint64_t displayId, const SystemBarProps& props)
{
if (props.empty()) {
return;
}
for (auto& agent : windowManagerAgents_[WindowManagerAgentType::WINDOW_MANAGER_AGENT_TYPE_SYSTEM_BAR]) {
agent->UpdateSystemBarProperties(displayId, props);
}
}
void WindowRoot::OnRemoteDied(const sptr<IRemoteObject>& remoteObject)
{
std::lock_guard<std::recursive_mutex> lock(mutex_);
@@ -306,7 +326,7 @@ void WindowRoot::ClearWindowManagerAgent(const sptr<IRemoteObject>& remoteObject
return;
}
std::lock_guard<std::recursive_mutex> lock(mutex_);
UnregisterFocusChangedListener(remoteObject);
UnregisterWindowManagerAgent(remoteObject);
remoteObject->RemoveDeathRecipient(windowManagerAgentDeath_);
}
-85
View File
@@ -1,85 +0,0 @@
# Copyright (c) 2021 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/"
group("unittest") {
testonly = true
deps = [ ":ut_window_impl_test" ]
}
## UnitTest ut_window_impl_test {{{
ohos_unittest("ut_window_impl_test") {
module_out_path = module_out_path
sources = [ "src/window_impl_test.cpp" ]
deps = [ ":unittest_wmtest_common" ]
}
## UnitTest ut_window_impl_test }}}
## Build unittest_wmtest_common.a {{{
config("unittest_wmtest_common_public_config") {
include_dirs = [
"//foundation/windowmanager/wm/include",
"//foundation/windowmanager/wmserver/include",
"include",
"//foundation/windowmanager/interfaces/innerkits/wm",
"//utils/native/base/include",
"//foundation/communication/ipc/interfaces/innerkits/ipc_core/include",
"//base/hiviewdfx/hilog/interfaces/native/innerkits/include",
"//foundation/windowmanager/utils/include",
"//third_party/googletest/googlemock/include",
#RSSurface
"//foundation/graphic/standard/rosen/modules/render_service_client/core",
"//foundation/graphic/standard/rosen/modules/render_service_base/include",
"//third_party/flutter/skia",
]
cflags = [
"-Wall",
"-Werror",
"-g3",
"-Dprivate=public",
"-Dprotected=public",
]
}
ohos_static_library("unittest_wmtest_common") {
visibility = [ ":*" ]
testonly = true
public_configs = [ ":unittest_wmtest_common_public_config" ]
deps = [
"//foundation/windowmanager/wm:libwm",
"//foundation/windowmanager/wm:libwmutil",
"//foundation/windowmanager/wmserver:libwms",
"//third_party/googletest:gmock",
"//utils/native/base:utils",
# RSSurface
"//foundation/graphic/standard/rosen/modules/render_service_base:librender_service_base",
"//foundation/graphic/standard/rosen/modules/render_service_client:librender_service_client",
]
external_deps = [
"hiviewdfx_hilog_native:libhilog",
"ipc:ipc_core",
]
}
## Build unittest_wmtest_common.a }}}
-43
View File
@@ -1,43 +0,0 @@
/*
* Copyright (c) 2021 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.
*/
#ifndef UNITTEST_TEST_HEADER_H
#define UNITTEST_TEST_HEADER_H
#include "window_manager_hilog.h"
namespace OHOS {
namespace Rosen {
#define _WMT_CPRINTF(color, func, fmt, ...) \
func({LOG_CORE, 0, "WM_UINTTEST"}, "\033[" #color "m" "<%{public}d>" fmt "\033[0m", __LINE__, ##__VA_ARGS__)
#define WMTLOGI(color, fmt, ...) \
_WMT_CPRINTF(color, HiviewDFX::HiLog::Info, "%{public}s: " fmt, __func__, ##__VA_ARGS__)
#define PART(part) WMTLOGI(33, part); if (const char *strPart = part)
#define STEP(desc) WMTLOGI(34, desc); if (const char *strDesc = desc)
#define STEP_CONDITION(condition) strPart << ": " << strDesc << " (" << condition << ")"
#define STEP_ASSERT_(l, r, func, opstr) ASSERT_##func(l, r) << STEP_CONDITION(#l " " opstr " " #r)
#define STEP_ASSERT_EQ(l, r) STEP_ASSERT_(l, r, EQ, "==")
#define STEP_ASSERT_NE(l, r) STEP_ASSERT_(l, r, NE, "!=")
#define STEP_ASSERT_GE(l, r) STEP_ASSERT_(l, r, GE, ">=")
#define STEP_ASSERT_LE(l, r) STEP_ASSERT_(l, r, LE, "<=")
#define STEP_ASSERT_GT(l, r) STEP_ASSERT_(l, r, GT, ">")
#define STEP_ASSERT_LT(l, r) STEP_ASSERT_(l, r, LT, "<")
} // namespace Rosen
} // namespace OHOS
#endif // UNITTEST_TEST_HEADER_H
-130
View File
@@ -1,130 +0,0 @@
/*
* Copyright (c) 2021 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 "window_impl_test.h"
#include "mock/mock_window_adapter.h"
#include "mock/singleton_mocker.h"
#include "test_header.h"
#include "window_property.h"
namespace OHOS {
namespace Rosen {
using namespace testing;
void WindowImplTest::SetUpTestCase()
{
property_ = sptr<WindowProperty>(new WindowProperty());
property_->SetWindowId(0);
window_ = sptr<Window>(new WindowImpl(property_));
}
void WindowImplTest::TearDownTestCase()
{
}
void WindowImplTest::SetUp()
{
}
void WindowImplTest::TearDown()
{
}
namespace {
/*
* Function: Show
* Type: Reliability
* Rank: Important(2)
* EnvConditions: N/A
* CaseDescription: 1. mock WindowAdapter
* 2. mock AddWindow return WM_OK
* 3. call Show to AddWindow and check return is WM_OK
* 4. call Show with isAdded_=true and check return is WM_OK
* 5. mock RemoveWindow return WM_OK
* 6. call Destroy check return is WM_OK
*/
HWTEST_F(WindowImplTest, ShowWindow01, testing::ext::TestSize.Level0)
{
PART("CaseShow01") {
#ifdef _NEW_RENDERSERVER_
using Mocker = SingletonMocker<WindowAdapter, MockWindowAdapter>;
std::unique_ptr<Mocker> m = nullptr;
STEP("1. mock WindowAdapter") {
m = std::make_unique<Mocker>();
}
STEP("2. mock AddWindow return WM_OK") {
EXPECT_CALL(m->Mock(), AddWindow(_)).Times(1).WillOnce(Return(WMError::WM_OK));
}
STEP("3. call Show and check return is WM_OK") {
STEP_ASSERT_EQ(WMError::WM_OK, window_->Show());
}
STEP("4. mock RemoveWindow return WM_OK") {
EXPECT_CALL(m->Mock(), RemoveWindow(_)).Times(1).WillOnce(Return(WMError::WM_OK));
}
STEP("5. call Destroy check return is WM_OK") {
STEP_ASSERT_EQ(WMError::WM_OK, window_->Destroy());
}
#endif
}
}
/*
* Function: Show
* Type: Reliability
* Rank: Important(2)
* EnvConditions: N/A
* CaseDescription: 1. mock WindowAdapter
* 2. mock AddWindow return WM_ERROR_DEATH_RECIPIENT
* 3. call Show to AddWindow and check return is WM_ERROR_DEATH_RECIPIENT
* 4. call Show with isAdded_=true and check return is WM_ERROR_DEATH_RECIPIENT
* 5. mock RemoveWindow return WM_OK
* 6. call Destroy check return is WM_OK
*/
HWTEST_F(WindowImplTest, ShowWindow02, testing::ext::TestSize.Level0)
{
PART("CaseShow02") {
#ifdef _NEW_RENDERSERVER_
using Mocker = SingletonMocker<WindowAdapter, MockWindowAdapter>;
std::unique_ptr<Mocker> m = nullptr;
STEP("1. mock WindowAdapter") {
m = std::make_unique<Mocker>();
}
STEP("2. mock AddWindow return WM_ERROR_DEATH_RECIPIENT") {
EXPECT_CALL(m->Mock(), AddWindow(_)).Times(1).WillOnce(Return(WMError::WM_ERROR_DEATH_RECIPIENT));
}
STEP("3. call Show and check return is WM_ERROR_DEATH_RECIPIENT") {
STEP_ASSERT_EQ(WMError::WM_ERROR_DEATH_RECIPIENT, window_->Show());
}
STEP("4. mock RemoveWindow return WM_OK") {
EXPECT_CALL(m->Mock(), RemoveWindow(_)).Times(1).WillOnce(Return(WMError::WM_OK));
}
STEP("5. call Destroy check return is WM_OK") {
STEP_ASSERT_EQ(WMError::WM_OK, window_->Destroy());
}
#endif
}
}
}
} // namespace Rosen
} // namespace OHOS